#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 lingot_fft_spd_eval(double *in, unsigned int N1, double wi, double dw,
                         double *out, unsigned int N2) {
  double Xr, Xi;
  double wn;
  const double _1_N2 = 1.0 / (N1 * N1);
  unsigned int i;
  unsigned int n;
  for (i = 0; i < N2; i++) {
    Xr = 0.0;
    Xi = 0.0;
    for (n = 0; n < N1; n++) {
      wn = (wi + dw * i) * n;
      Xr = Xr + cos(wn) * in[n];
      Xi = Xi - sin(wn) * in[n];
    }
    out[i] = (Xr * Xr + Xi * Xi) * _1_N2;
  }
}


x86 assembly (clang, -O0):
<lingot_fft_spd_eval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
imul   %eax,%eax
cvtsi2sd %rax,%xmm1
movsd  0xead(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jae    1281 <lingot_fft_spd_eval+0x161>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1246 <lingot_fft_spd_eval+0x126>
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
mov    -0x54(%rbp),%eax
cvtsi2sd %rax,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x58(%rbp),%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x68(%rbp),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x58(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <sin@plt>
movsd  -0x60(%rbp),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x58(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1186 <lingot_fft_spd_eval+0x66>
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mulsd  -0x50(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x54(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1163 <lingot_fft_spd_eval+0x43>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lingot_fft_spd_eval>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,0x18(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
test   %ecx,%ecx
je     1260 <lingot_fft_spd_eval+0x140>
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %esi,%eax
imul   %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0xe9f(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %ecx,%r12d
mov    %esi,%ebp
xor    %r13d,%r13d
jmp    11b6 <lingot_fft_spd_eval+0x96>
cs nopw 0x0(%rax,%rax,1)
nop
xorpd  %xmm1,%xmm1
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
mov    0x18(%rsp),%rax
movsd  %xmm1,(%rax,%r13,8)
add    $0x1,%r13
cmp    %r12,%r13
je     1260 <lingot_fft_spd_eval+0x140>
test   %r15d,%r15d
je     1180 <lingot_fft_spd_eval+0x60>
mov    %r13d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
xorpd  %xmm0,%xmm0
xor    %r14d,%r14d
xchg   %ax,%ax
movapd %xmm0,0x50(%rsp)
mov    %r14d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
call   1040 <cos@plt>
movapd %xmm0,0x30(%rsp)
movsd  (%rbx,%r14,8),%xmm0
movaps %xmm0,0x40(%rsp)
movsd  0x28(%rsp),%xmm0
call   1030 <sin@plt>
movapd 0x50(%rsp),%xmm2
movapd 0xde4(%rip),%xmm1
xorpd  %xmm1,%xmm0
unpcklpd 0x30(%rsp),%xmm0
movsd  (%rbx,%r14,8),%xmm1
unpcklpd 0x40(%rsp),%xmm1
mulpd  %xmm0,%xmm1
movapd %xmm1,%xmm0
addpd  %xmm2,%xmm0
add    $0x1,%r14
cmp    %r14,%rbp
jne    11e0 <lingot_fft_spd_eval+0xc0>
addpd  %xmm2,%xmm1
jmp    1184 <lingot_fft_spd_eval+0x64>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @lingot_fft_spd_eval(double* nocapture %0, i32 %1, double %2, double %3, double* nocapture writeonly %4, i32 %5) {
%7 = mul i32 %1, %1
%8 = uitofp i32 %7 to double
%9 = fdiv double 1.000000e+00, %8
%10 = icmp eq i32 %5, 0
br i1 %10, label %52, label %11
11: ; preds = %6
%12 = icmp eq i32 %1, 0
%13 = zext i32 %5 to i64
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %11, %42
%16 = phi i64 [ 0, %11 ], [ %50, %42 ]
br i1 %12, label %42, label %17
17: ; preds = %15
%18 = trunc i64 %16 to i32
%19 = uitofp i32 %18 to double
%20 = tail call double @llvm.fmuladd.f64(double %3, double %19, double %2)
br label %21
21: ; preds = %17, %21
%22 = phi i64 [ 0, %17 ], [ %38, %21 ]
%23 = phi <2 x double> [ zeroinitializer, %17 ], [ %37, %21 ]
%24 = trunc i64 %22 to i32
%25 = uitofp i32 %24 to double
%26 = fmul double %20, %25
%27 = tail call double @cos(double %26)
%28 = getelementptr inbounds double, double* %0, i64 %22
%29 = load double, double* %28
%30 = tail call double @sin(double %26)
%31 = load double, double* %28
%32 = fneg double %30
%33 = insertelement <2 x double> poison, double %32, i64 0
%34 = insertelement <2 x double> %33, double %27, i64 1
%35 = insertelement <2 x double> poison, double %31, i64 0
%36 = insertelement <2 x double> %35, double %29, i64 1
%37 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %34, <2 x double> %36, <2 x double> %23)
%38 = add nuw nsw i64 %22, 1
%39 = icmp eq i64 %38, %14
br i1 %39, label %40, label %21
40: ; preds = %21
%41 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %34, <2 x double> %36, <2 x double> %23)
br label %42
42: ; preds = %40, %15
%43 = phi <2 x double> [ zeroinitializer, %15 ], [ %41, %40 ]
%44 = fmul <2 x double> %43, %43
%45 = extractelement <2 x double> %44, i64 0
%46 = extractelement <2 x double> %43, i64 1
%47 = tail call double @llvm.fmuladd.f64(double %46, double %46, double %45)
%48 = fmul double %9, %47
%49 = getelementptr inbounds double, double* %4, i64 %16
store double %48, double* %49
%50 = add nuw nsw i64 %16, 1
%51 = icmp eq i64 %50, %13
br i1 %51, label %52, label %15
52: ; preds = %42, %6
ret void
}