#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 cos(double);
double sin(double);
void twiddle(int n, double w[]) {
  double arg;
  double aw;
  int i;
  const double pi = 6.28318530718 / 2;
  aw = 2.0 * pi / ((double)n);
  for (i = 0; i < n / 2; i++) {
    arg = aw * ((double)i);
    w[i * 2 + 0] = cos(arg);
    w[i * 2 + 1] = sin(arg);
  }
  return;
}


x86 assembly (clang, -O0):
<twiddle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xed1(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  0xeb7(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    11d6 <twiddle+0xb6>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <cos@plt>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x18(%rbp),%xmm0
call   1030 <sin@plt>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1159 <twiddle+0x39>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twiddle>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jl     1218 <twiddle+0xf8>
mov    %rsi,%r14
mov    %edi,%r15d
cvtsi2sd %edi,%xmm0
movsd  0xeb8(%rip),%xmm1
divsd  %xmm0,%xmm1
shr    %r15d
cmp    $0x1,%r15d
jne    115d <twiddle+0x3d>
xor    %r13d,%r13d
jmp    11dd <twiddle+0xbd>
mov    %r15d,%r12d
and    $0xfffffffe,%r12d
lea    0x18(%r14),%rbx
xor    %r13d,%r13d
movsd  %xmm1,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <cos@plt>
movsd  %xmm0,-0x18(%rbx)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x10(%rbx)
lea    0x1(%r13),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <cos@plt>
movsd  %xmm0,-0x8(%rbx)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
movsd  (%rsp),%xmm1
movsd  %xmm0,(%rbx)
add    $0x2,%r13
add    $0x20,%rbx
cmp    %r12,%r13
jne    1170 <twiddle+0x50>
test   $0x1,%r15b
je     1218 <twiddle+0xf8>
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   1040 <cos@plt>
shl    $0x4,%r13
movsd  %xmm0,(%r14,%r13,1)
movsd  (%rsp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x8(%r14,%r13,1)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @twiddle(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
store i32 %0, i32* %3
store double* %1, double** %4
store double 0x400921FB54442EEA, double* %8
%9 = load i32, i32* %3
%10 = sitofp i32 %9 to double
%11 = fdiv double 0x401921FB54442EEA, %10
store double %11, double* %6
store i32 0, i32* %7
br label %12
12: ; preds = %38, %2
%13 = load i32, i32* %7
%14 = load i32, i32* %3
%15 = sdiv i32 %14, 2
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %41
17: ; preds = %12
%18 = load double, double* %6
%19 = load i32, i32* %7
%20 = sitofp i32 %19 to double
%21 = fmul double %18, %20
store double %21, double* %5
%22 = load double, double* %5
%23 = call double @cos(double %22)
%24 = load double*, double** %4
%25 = load i32, i32* %7
%26 = mul nsw i32 %25, 2
%27 = add nsw i32 %26, 0
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %24, i64 %28
store double %23, double* %29
%30 = load double, double* %5
%31 = call double @sin(double %30)
%32 = load double*, double** %4
%33 = load i32, i32* %7
%34 = mul nsw i32 %33, 2
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %32, i64 %36
store double %31, double* %37
br label %38
38: ; preds = %17
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %12
41: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @twiddle(i32 %0, double* nocapture writeonly %1) {
%3 = sitofp i32 %0 to double
%4 = fdiv double 0x401921FB54442EEA, %3
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %51
6: ; preds = %2
%7 = lshr i32 %0, 1
%8 = zext i32 %7 to i64
%9 = and i64 %8, 1
%10 = icmp eq i32 %7, 1
br i1 %10, label %38, label %11
11: ; preds = %6
%12 = and i64 %8, 2147483646
br label %13
13: ; preds = %13, %11
%14 = phi i64 [ 0, %11 ], [ %35, %13 ]
%15 = phi i64 [ 0, %11 ], [ %36, %13 ]
%16 = trunc i64 %14 to i32
%17 = sitofp i32 %16 to double
%18 = fmul double %4, %17
%19 = tail call double @cos(double %18)
%20 = shl nuw nsw i64 %14, 1
%21 = getelementptr inbounds double, double* %1, i64 %20
store double %19, double* %21
%22 = tail call double @sin(double %18)
%23 = or i64 %20, 1
%24 = getelementptr inbounds double, double* %1, i64 %23
store double %22, double* %24
%25 = or i64 %14, 1
%26 = trunc i64 %25 to i32
%27 = sitofp i32 %26 to double
%28 = fmul double %4, %27
%29 = tail call double @cos(double %28)
%30 = shl nuw nsw i64 %25, 1
%31 = getelementptr inbounds double, double* %1, i64 %30
store double %29, double* %31
%32 = tail call double @sin(double %28)
%33 = or i64 %30, 1
%34 = getelementptr inbounds double, double* %1, i64 %33
store double %32, double* %34
%35 = add nuw nsw i64 %14, 2
%36 = add nuw i64 %15, 2
%37 = icmp eq i64 %36, %12
br i1 %37, label %38, label %13
38: ; preds = %13, %6
%39 = phi i64 [ 0, %6 ], [ %35, %13 ]
%40 = icmp eq i64 %9, 0
br i1 %40, label %51, label %41
41: ; preds = %38
%42 = trunc i64 %39 to i32
%43 = sitofp i32 %42 to double
%44 = fmul double %4, %43
%45 = tail call double @cos(double %44)
%46 = shl nuw nsw i64 %39, 1
%47 = getelementptr inbounds double, double* %1, i64 %46
store double %45, double* %47
%48 = tail call double @sin(double %44)
%49 = or i64 %46, 1
%50 = getelementptr inbounds double, double* %1, i64 %49
store double %48, double* %50
br label %51
51: ; preds = %41, %38, %2
ret void
}