#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double M_PI;
int bitrev(int, int);
double cos(double);
int log_2(int);
double sin(double);
void compute_W(int n, double *W_re, double *W_im) {
  int i, br;
  int log2n = log_2(n);
  for (i = 0; i < (n / 2); i++) {
    br = bitrev(i, log2n - 1);
    W_re[br] = cos(((double)i * 2.0 * M_PI) / ((double)n));
    W_im[br] = sin(((double)i * 2.0 * M_PI) / ((double)n));
  }
}


x86 assembly (clang, -O0):
<compute_W>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <log_2@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    1210 <compute_W+0xd0>
mov    -0x1c(%rbp),%edi
mov    -0x24(%rbp),%esi
sub    $0x1,%esi
call   1060 <bitrev@plt>
mov    %eax,-0x20(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe5f(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e3c(%rip),%rax
mulsd  (%rax),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1050 <cos@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe28(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e05(%rip),%rax
mulsd  (%rax),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <compute_W+0x25>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_W>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r15
mov    %rsi,0x18(%rsp)
mov    %edi,%ebx
call   1030 <log_2@plt>
cmp    $0x2,%ebx
jl     1215 <compute_W+0xd5>
mov    %eax,%r12d
mov    %ebx,%r13d
shr    $0x1f,%r13d
add    %ebx,%r13d
sar    %r13d
add    $0xffffffff,%r12d
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %ebx,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x2e51(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r12d,%esi
call   1060 <bitrev@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm1
movsd  %xmm1,0x20(%rsp)
movsd  (%r14),%xmm0
mulsd  %xmm1,%xmm0
divsd  0x10(%rsp),%xmm0
call   1050 <cos@plt>
movslq %ebp,%rbp
mov    0x18(%rsp),%rax
movsd  %xmm0,(%rax,%rbp,8)
movsd  0x20(%rsp),%xmm0
mulsd  (%r14),%xmm0
divsd  0x10(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,(%r15,%rbp,8)
movsd  0x8(%rsp),%xmm0
addsd  0xdf9(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebx
cmp    %ebx,%r13d
jne    11a0 <compute_W+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define void @compute_W(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
%10 = load i32, i32* %4
%11 = call i32 @log_2(i32 %10)
store i32 %11, i32* %9
store i32 0, i32* %7
br label %12
12: ; preds = %48, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %4
%15 = sdiv i32 %14, 2
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %51
17: ; preds = %12
%18 = load i32, i32* %7
%19 = load i32, i32* %9
%20 = sub nsw i32 %19, 1
%21 = call i32 @bitrev(i32 %18, i32 %20)
store i32 %21, i32* %8
%22 = load i32, i32* %7
%23 = sitofp i32 %22 to double
%24 = fmul double %23, 2.000000e+00
%25 = load double, double* @M_PI
%26 = fmul double %24, %25
%27 = load i32, i32* %4
%28 = sitofp i32 %27 to double
%29 = fdiv double %26, %28
%30 = call double @cos(double %29)
%31 = load double*, double** %5
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
store double %30, double* %34
%35 = load i32, i32* %7
%36 = sitofp i32 %35 to double
%37 = fmul double %36, 2.000000e+00
%38 = load double, double* @M_PI
%39 = fmul double %37, %38
%40 = load i32, i32* %4
%41 = sitofp i32 %40 to double
%42 = fdiv double %39, %41
%43 = call double @sin(double %42)
%44 = load double*, double** %6
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
store double %43, double* %47
br label %48
48: ; preds = %17
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %12
51: ; preds = %12
ret void
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define void @compute_W(i32 %0, double* nocapture writeonly %1, double* nocapture writeonly %2) {
%4 = tail call i32 @log_2(i32 %0)
%5 = sdiv i32 %0, 2
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %28
7: ; preds = %3
%8 = add nsw i32 %4, -1
%9 = sitofp i32 %0 to double
br label %10
10: ; preds = %7, %10
%11 = phi i32 [ 0, %7 ], [ %26, %10 ]
%12 = tail call i32 @bitrev(i32 %11, i32 %8)
%13 = sitofp i32 %11 to double
%14 = fmul double %13, 2.000000e+00
%15 = load double, double* @M_PI
%16 = fmul double %14, %15
%17 = fdiv double %16, %9
%18 = tail call double @cos(double %17)
%19 = sext i32 %12 to i64
%20 = getelementptr inbounds double, double* %1, i64 %19
store double %18, double* %20
%21 = load double, double* @M_PI
%22 = fmul double %14, %21
%23 = fdiv double %22, %9
%24 = tail call double @sin(double %23)
%25 = getelementptr inbounds double, double* %2, i64 %19
store double %24, double* %25
%26 = add nuw nsw i32 %11, 1
%27 = icmp eq i32 %26, %5
br i1 %27, label %28, label %10
28: ; preds = %10, %3
ret void
}