
let run_benchmark : int -> int = 
fun (_ : int) ->
	let n : int = read_int () in
	let data : vec[float] = vector n 0.0 in
	let twopi : float = 6.28318530717959 in
	let rec loop1 : int -> int -> int = 
		fun (i : int) (j : int) ->
			(if i < n then
				(if i < j then
					let temp : float = vector_get data i in
					vector_set data i (vector_get data j);
					vector_set data j temp;
					(let temp : float = vector_get data (i + 1) in
					vector_set data (i + 1) (vector_get data (j + 1));
					vector_set data (j + 1) temp);
					0
				else 0);
				loop2 (n / 2) j i
			else 0);
			0
	and
	loop2 : int -> int -> int -> int =
		fun (m: int) (j: int) (i: int) ->
			(if ((m >= 2) && (j >= m)) then
				loop2 (m / 2) (j - m) i
			else
				loop1 (i + 2) (j + m));
			0
	and
	loop3 : int -> int =
		fun (mmax : int) ->
			(if (mmax < n) then
				let theta : float = twopi /. (float_of_int mmax) in
				let wpr : float = 
					let x : float = sin (0.5 *. theta) in 
					-2.0 *. (x *. x) in
				let wpi : float = sin theta in
				loop4 1.0 0.0 0 mmax wpr wpi;
				loop3 (mmax * 2)
			else 0);
			0
	and
	loop4 : float -> float -> int -> int -> float -> float -> int =
		fun (wr : float) (wi : float) (m : int) (mmax : int) (wpr : float) (wpi : float) ->
			(if (m < mmax) then
				loop5 m mmax wr wi m wpr wpi
			else 0);
			0
	and
	loop5 : int -> int -> float -> float -> int -> float -> float -> int =
		fun (i : int) (mmax : int) (wr : float) (wi : float) (m : int) (wpr : float) (wpi : float) ->
			(if (i < n) then
				let j : int = i + mmax in
				let tempr : float = (wr *. (vector_get data j)) -. (wi *. (vector_get data (j + 1))) in
				let tempi : float = (wr *. (vector_get data (j + 1))) +. (wi *. (vector_get data j)) in
				vector_set data j ((vector_get data i) -. tempr);
				vector_set data (j + 1) ((vector_get data (i + 1)) -. tempi);
				vector_set data i ((vector_get data i) +. tempr);
				vector_set data (i + 1) ((vector_get data (i + 1)) +. tempi);
				loop5 (j + mmax) mmax wr wi m wpr wpi
			else 
				loop4 (((wr *. wpr) -. (wi *. wpi)) +. wr) (((wi *. wpr) +. (wr *. wpi)) +. wi) (m + 2) mmax wpr wpi);
			0
	in
	loop1 0 0;
	loop3 2;
	print_float (vector_get data 0);
	0
in

time run_benchmark
