#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 const cos(double);
double const sin(double);
void lingot_fft_spd_diffs_eval(const double *in, unsigned int N, double w,
                               double *out_d0, double *out_d1, double *out_d2) {
  double x_cos_wn;
  double x_sin_wn;
  const double N2 = N * N;
  unsigned int n;
  double SUM_x_sin_wn = 0.0;
  double SUM_x_cos_wn = 0.0;
  double SUM_x_n_sin_wn = 0.0;
  double SUM_x_n_cos_wn = 0.0;
  double SUM_x_n2_sin_wn = 0.0;
  double SUM_x_n2_cos_wn = 0.0;
  for (n = 0; n < N; n++) {
    x_cos_wn = in[n] * cos(w * n);
    x_sin_wn = in[n] * sin(w * n);
    SUM_x_sin_wn += x_sin_wn;
    SUM_x_cos_wn += x_cos_wn;
    SUM_x_n_sin_wn += x_sin_wn * n;
    SUM_x_n_cos_wn += x_cos_wn * n;
    SUM_x_n2_sin_wn += x_sin_wn * n * n;
    SUM_x_n2_cos_wn += x_cos_wn * n * n;
  }
  double N_2 = N * N;
  *out_d0 = (SUM_x_cos_wn * SUM_x_cos_wn + SUM_x_sin_wn * SUM_x_sin_wn) / N2;
  *out_d1 = 2.0 *
            (SUM_x_sin_wn * SUM_x_n_cos_wn - SUM_x_cos_wn * SUM_x_n_sin_wn) /
            N_2;
  *out_d2 = 2.0 *
            (SUM_x_n_cos_wn * SUM_x_n_cos_wn - SUM_x_sin_wn * SUM_x_n2_sin_wn +
             SUM_x_n_sin_wn * SUM_x_n_sin_wn - SUM_x_cos_wn * SUM_x_n2_cos_wn) /
            N_2;
}


x86 assembly (clang, -O0):
<lingot_fft_spd_diffs_eval>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0xc(%rbp),%eax
imul   %eax,%eax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    12c4 <lingot_fft_spd_diffs_eval+0x1a4>
mov    -0x8(%rbp),%rcx
mov    -0x4c(%rbp),%eax
movsd  (%rcx,%rax,8),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x18(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x4c(%rbp),%eax
movsd  (%rcx,%rax,8),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x18(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x4c(%rbp),%eax
cvtsi2sd %rax,%xmm2
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x4c(%rbp),%eax
cvtsi2sd %rax,%xmm2
movsd  -0x70(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x4c(%rbp),%eax
cvtsi2sd %rax,%xmm2
mulsd  %xmm2,%xmm0
movsd  -0x78(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x4c(%rbp),%eax
cvtsi2sd %rax,%xmm2
mulsd  %xmm2,%xmm0
movsd  -0x80(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    118a <lingot_fft_spd_diffs_eval+0x6a>
mov    -0xc(%rbp),%eax
imul   %eax,%eax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x60(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x58(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xcc5(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x88(%rbp),%xmm0
ff
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x70(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm0
mulsd  -0x78(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x80(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xc3b(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x88(%rbp),%xmm0
ff
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lingot_fft_spd_diffs_eval>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %esi,%eax
imul   %eax,%eax
cvtsi2sd %rax,%xmm4
test   %esi,%esi
je     1259 <lingot_fft_spd_diffs_eval+0x139>
movapd %xmm0,%xmm8
mov    %rdi,%rbx
movsd  %xmm4,0x10(%rsp)
mov    %esi,%r13d
xorpd  %xmm1,%xmm1
xorpd  %xmm5,%xmm5
xor    %ebp,%ebp
xorpd  %xmm6,%xmm6
xorpd  %xmm2,%xmm2
movsd  %xmm0,0x18(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm6,0x20(%rsp)
movsd  %xmm5,0x28(%rsp)
movapd %xmm2,0x70(%rsp)
movapd %xmm1,0x60(%rsp)
mov    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd %xmm0,0x50(%rsp)
mulsd  %xmm8,%xmm0
movapd %xmm0,0x30(%rsp)
movsd  (%rbx,%rbp,8),%xmm1
movaps %xmm1,(%rsp)
call   1040 <cos@plt>
movapd %xmm0,0x40(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
unpcklpd (%rsp),%xmm0
movaps %xmm0,(%rsp)
movapd 0x30(%rsp),%xmm0
call   1030 <sin@plt>
movapd 0x60(%rsp),%xmm3
movapd 0x70(%rsp),%xmm4
movsd  0x18(%rsp),%xmm8
movapd 0x50(%rsp),%xmm7
movsd  0x20(%rsp),%xmm6
movsd  0x28(%rsp),%xmm5
unpcklpd 0x40(%rsp),%xmm0
mulpd  (%rsp),%xmm0
addsd  %xmm0,%xmm6
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm1,%xmm5
unpcklpd %xmm7,%xmm7
mulpd  %xmm7,%xmm0
movapd %xmm0,%xmm1
addpd  %xmm3,%xmm1
mulpd  %xmm0,%xmm7
movapd %xmm7,%xmm2
addpd  %xmm4,%xmm2
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1180 <lingot_fft_spd_diffs_eval+0x60>
addpd  %xmm3,%xmm0
addpd  %xmm4,%xmm7
movsd  0x10(%rsp),%xmm4
jmp    1269 <lingot_fft_spd_diffs_eval+0x149>
xorpd  %xmm0,%xmm0
xorpd  %xmm6,%xmm6
xorpd  %xmm5,%xmm5
xorpd  %xmm7,%xmm7
movapd %xmm6,%xmm1
mulsd  %xmm6,%xmm1
movapd %xmm5,%xmm2
mulsd  %xmm5,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm4,%xmm2
movsd  %xmm2,(%r12)
movapd %xmm0,%xmm1
mulsd  %xmm5,%xmm1
movapd %xmm0,%xmm2
unpckhpd %xmm0,%xmm2
movapd %xmm7,%xmm3
mulsd  %xmm6,%xmm3
mulsd  %xmm2,%xmm6
subsd  %xmm1,%xmm6
addsd  %xmm6,%xmm6
divsd  %xmm4,%xmm6
movsd  %xmm6,(%r15)
mulsd  %xmm2,%xmm2
subsd  %xmm3,%xmm2
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
unpckhpd %xmm7,%xmm7
mulsd  %xmm5,%xmm7
subsd  %xmm7,%xmm0
addsd  %xmm0,%xmm0
divsd  %xmm4,%xmm0
movsd  %xmm0,(%r14)
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @lingot_fft_spd_diffs_eval(double* %0, i32 %1, double %2, double* %3, double* %4, double* %5) {
%7 = alloca double*
%8 = alloca i32
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca i32
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
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 double* %5, double** %12
%24 = load i32, i32* %8
%25 = load i32, i32* %8
%26 = mul i32 %24, %25
%27 = uitofp i32 %26 to double
store double %27, double* %15
store double 0.000000e+00, double* %17
store double 0.000000e+00, double* %18
store double 0.000000e+00, double* %19
store double 0.000000e+00, double* %20
store double 0.000000e+00, double* %21
store double 0.000000e+00, double* %22
store i32 0, i32* %16
br label %28
28: ; preds = %87, %6
%29 = load i32, i32* %16
%30 = load i32, i32* %8
%31 = icmp ult i32 %29, %30
br i1 %31, label %32, label %90
32: ; preds = %28
%33 = load double*, double** %7
%34 = load i32, i32* %16
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = load double, double* %9
%39 = load i32, i32* %16
%40 = uitofp i32 %39 to double
%41 = fmul double %38, %40
%42 = call double @cos(double %41)
%43 = fmul double %37, %42
store double %43, double* %13
%44 = load double*, double** %7
%45 = load i32, i32* %16
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = load double, double* %9
%50 = load i32, i32* %16
%51 = uitofp i32 %50 to double
%52 = fmul double %49, %51
%53 = call double @sin(double %52)
%54 = fmul double %48, %53
store double %54, double* %14
%55 = load double, double* %14
%56 = load double, double* %17
%57 = fadd double %56, %55
store double %57, double* %17
%58 = load double, double* %13
%59 = load double, double* %18
%60 = fadd double %59, %58
store double %60, double* %18
%61 = load double, double* %14
%62 = load i32, i32* %16
%63 = uitofp i32 %62 to double
%64 = load double, double* %19
%65 = call double @llvm.fmuladd.f64(double %61, double %63, double %64)
store double %65, double* %19
%66 = load double, double* %13
%67 = load i32, i32* %16
%68 = uitofp i32 %67 to double
%69 = load double, double* %20
%70 = call double @llvm.fmuladd.f64(double %66, double %68, double %69)
store double %70, double* %20
%71 = load double, double* %14
%72 = load i32, i32* %16
%73 = uitofp i32 %72 to double
%74 = fmul double %71, %73
%75 = load i32, i32* %16
%76 = uitofp i32 %75 to double
%77 = load double, double* %21
%78 = call double @llvm.fmuladd.f64(double %74, double %76, double %77)
store double %78, double* %21
%79 = load double, double* %13
%80 = load i32, i32* %16
%81 = uitofp i32 %80 to double
%82 = fmul double %79, %81
%83 = load i32, i32* %16
%84 = uitofp i32 %83 to double
%85 = load double, double* %22
%86 = call double @llvm.fmuladd.f64(double %82, double %84, double %85)
store double %86, double* %22
br label %87
87: ; preds = %32
%88 = load i32, i32* %16
%89 = add i32 %88, 1
store i32 %89, i32* %16
br label %28
90: ; preds = %28
%91 = load i32, i32* %8
%92 = load i32, i32* %8
%93 = mul i32 %91, %92
%94 = uitofp i32 %93 to double
store double %94, double* %23
%95 = load double, double* %18
%96 = load double, double* %18
%97 = load double, double* %17
%98 = load double, double* %17
%99 = fmul double %97, %98
%100 = call double @llvm.fmuladd.f64(double %95, double %96, double %99)
%101 = load double, double* %15
%102 = fdiv double %100, %101
%103 = load double*, double** %10
store double %102, double* %103
%104 = load double, double* %17
%105 = load double, double* %20
%106 = load double, double* %18
%107 = load double, double* %19
%108 = fmul double %106, %107
%109 = fneg double %108
%110 = call double @llvm.fmuladd.f64(double %104, double %105, double %109)
%111 = fmul double 2.000000e+00, %110
%112 = load double, double* %23
%113 = fdiv double %111, %112
%114 = load double*, double** %11
store double %113, double* %114
%115 = load double, double* %20
%116 = load double, double* %20
%117 = load double, double* %17
%118 = load double, double* %21
%119 = fmul double %117, %118
%120 = fneg double %119
%121 = call double @llvm.fmuladd.f64(double %115, double %116, double %120)
%122 = load double, double* %19
%123 = load double, double* %19
%124 = call double @llvm.fmuladd.f64(double %122, double %123, double %121)
%125 = load double, double* %18
%126 = load double, double* %22
%127 = fneg double %125
%128 = call double @llvm.fmuladd.f64(double %127, double %126, double %124)
%129 = fmul double 2.000000e+00, %128
%130 = load double, double* %23
%131 = fdiv double %129, %130
%132 = load double*, double** %12
store double %131, double* %132
ret void
}

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