#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 */
int atan(double);
double cos(double);
double sin(double);
void twiddles(int n, double *w) {
  int i;
  double delta = atan(1.0) / n;
  w[0] = 1;
  w[1] = 0;
  w[n] = cos(delta * n);
  w[n + 1] = w[n];
#pragma mta assert no dependence
  for (i = 2; i < n; i += 2) {
    double x = cos(delta * i);
    double y = sin(delta * i);
    w[i] = x;
    w[i + 1] = y;
    w[2 * n - i] = y;
    w[2 * n - i + 1] = x;
  }
}


x86 assembly (clang, -O0):
<twiddles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xeb9(%rip),%xmm0
call   1040 <atan@plt>
cltd
idivl  -0x4(%rbp)
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0xe9b(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1050 <cos@plt>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1265 <twiddles+0x135>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
sub    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <twiddles+0x8b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twiddles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%r13d
movsd  0xeb4(%rip),%xmm0
call   1040 <atan@plt>
cltd
idiv   %r13d
cvtsi2sd %eax,%xmm1
movsd  0xe9f(%rip),%xmm0
movups %xmm0,(%r14)
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
movsd  %xmm1,(%rsp)
mulsd  %xmm1,%xmm0
call   1050 <cos@plt>
movslq %r13d,%r15
movsd  %xmm0,(%r14,%r15,8)
movsd  %xmm0,0x8(%r14,%r15,8)
cmp    $0x3,%r15d
jl     1220 <twiddles+0xf0>
movabs $0xfffffffe00000000,%r12
ff ff ff
lea    0x0(%r13,%r13,1),%eax
cltq
shl    $0x21,%r13
add    %r12,%r13
lea    (%r14,%rax,8),%rbx
add    $0xfffffffffffffff0,%rbx
mov    $0x2,%ebp
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
movsd  0x10(%rsp),%xmm1
movsd  %xmm1,(%r14,%rbp,8)
movsd  %xmm0,0x8(%r14,%rbp,8)
movsd  %xmm0,(%rbx)
mov    %r13,%rax
sar    $0x1d,%rax
or     $0x8,%rax
movsd  %xmm1,(%r14,%rax,1)
add    $0x2,%rbp
add    %r12,%r13
add    $0xfffffffffffffff0,%rbx
cmp    %r15,%rbp
jl     11c0 <twiddles+0x90>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @twiddles(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 %0, i32* %3
store double* %1, double** %4
%9 = call i32 @atan(double 1.000000e+00)
%10 = load i32, i32* %3
%11 = sdiv i32 %9, %10
%12 = sitofp i32 %11 to double
store double %12, double* %6
%13 = load double*, double** %4
%14 = getelementptr inbounds double, double* %13, i64 0
store double 1.000000e+00, double* %14
%15 = load double*, double** %4
%16 = getelementptr inbounds double, double* %15, i64 1
store double 0.000000e+00, double* %16
%17 = load double, double* %6
%18 = load i32, i32* %3
%19 = sitofp i32 %18 to double
%20 = fmul double %17, %19
%21 = call double @cos(double %20)
%22 = load double*, double** %4
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
store double %21, double* %25
%26 = load double*, double** %4
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %4
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %31, i64 %34
store double %30, double* %35
store i32 2, i32* %5
br label %36
36: ; preds = %79, %2
%37 = load i32, i32* %5
%38 = load i32, i32* %3
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %82
40: ; preds = %36
%41 = load double, double* %6
%42 = load i32, i32* %5
%43 = sitofp i32 %42 to double
%44 = fmul double %41, %43
%45 = call double @cos(double %44)
store double %45, double* %7
%46 = load double, double* %6
%47 = load i32, i32* %5
%48 = sitofp i32 %47 to double
%49 = fmul double %46, %48
%50 = call double @sin(double %49)
store double %50, double* %8
%51 = load double, double* %7
%52 = load double*, double** %4
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
store double %51, double* %55
%56 = load double, double* %8
%57 = load double*, double** %4
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %57, i64 %60
store double %56, double* %61
%62 = load double, double* %8
%63 = load double*, double** %4
%64 = load i32, i32* %3
%65 = mul nsw i32 2, %64
%66 = load i32, i32* %5
%67 = sub nsw i32 %65, %66
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %63, i64 %68
store double %62, double* %69
%70 = load double, double* %7
%71 = load double*, double** %4
%72 = load i32, i32* %3
%73 = mul nsw i32 2, %72
%74 = load i32, i32* %5
%75 = sub nsw i32 %73, %74
%76 = add nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %71, i64 %77
store double %70, double* %78
br label %79
79: ; preds = %40
%80 = load i32, i32* %5
%81 = add nsw i32 %80, 2
store i32 %81, i32* %5
br label %36
82: ; preds = %36
ret void
}

LLVM IR (-O2):
define void @twiddles(i32 %0, double* nocapture writeonly %1) {
%3 = tail call i32 @atan(double 1.000000e+00)
%4 = sdiv i32 %3, %0
%5 = sitofp i32 %4 to double
%6 = bitcast double* %1 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 0.000000e+00>, <2 x double>* %6
%7 = sitofp i32 %0 to double
%8 = fmul double %7, %5
%9 = tail call double @cos(double %8)
%10 = sext i32 %0 to i64
%11 = getelementptr inbounds double, double* %1, i64 %10
store double %9, double* %11
%12 = add nsw i32 %0, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %1, i64 %13
store double %9, double* %14
%15 = icmp sgt i32 %0, 2
br i1 %15, label %16, label %37
16: ; preds = %2
%17 = shl nuw nsw i32 %0, 1
%18 = sext i32 %17 to i64
br label %19
19: ; preds = %16, %19
%20 = phi i64 [ 2, %16 ], [ %35, %19 ]
%21 = trunc i64 %20 to i32
%22 = sitofp i32 %21 to double
%23 = fmul double %5, %22
%24 = tail call double @cos(double %23)
%25 = tail call double @sin(double %23)
%26 = getelementptr inbounds double, double* %1, i64 %20
store double %24, double* %26
%27 = or i64 %20, 1
%28 = getelementptr inbounds double, double* %1, i64 %27
store double %25, double* %28
%29 = sub nsw i64 %18, %20
%30 = getelementptr inbounds double, double* %1, i64 %29
store double %25, double* %30
%31 = shl i64 %29, 32
%32 = ashr exact i64 %31, 32
%33 = or i64 %32, 1
%34 = getelementptr inbounds double, double* %1, i64 %33
store double %24, double* %34
%35 = add nuw nsw i64 %20, 2
%36 = icmp slt i64 %35, %10
br i1 %36, label %19, label %37
37: ; preds = %19, %2
ret void
}