#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);
double sqrt(double);
void dft_magnitude(const double *data, double *spectrum) {
  static double cos_angle[(8192)] = {0.0};
  static double sin_angle[(8192)];
  double real_part, imag_part;
  int k, n;
  if (cos_angle[0] == 0.0)
    for (n = 0; n < (8192); n++) {
      cos_angle[n] = cos(2.0 * 3.14159265358979323846264338 * n / (8192));
      sin_angle[n] =
          -1.0 * sin(2.0 * 3.14159265358979323846264338 * n / (8192));
    };
  for (k = 1; k < ((8192) / 2); k++) {
    real_part = 0.0;
    imag_part = 0.0;
    for (n = 0; n < (8192); n++) {
      real_part += data[n] * cos_angle[(k * n) % (8192)];
      imag_part += data[n] * sin_angle[(k * n) % (8192)];
    };
    spectrum[k] = sqrt(real_part * real_part + imag_part * imag_part);
  };
  spectrum[((8192) / 2) - 1] = 0.0;
  spectrum[0] = spectrum[1] = spectrum[2] = 0.0;
  return;
}


x86 assembly (clang, -O0):
<dft_magnitude>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0x2f08(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11f5 <dft_magnitude+0xc5>
jp     11f5 <dft_magnitude+0xc5>
movl   $0x0,-0x28(%rbp)
cmpl   $0x2000,-0x28(%rbp)
jge    11f0 <dft_magnitude+0xc0>
cvtsi2sdl -0x28(%rbp),%xmm1
movsd  0xe94(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe80(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movslq -0x28(%rbp),%rcx
lea    0x2eb4(%rip),%rax
movsd  %xmm0,(%rax,%rcx,8)
cvtsi2sdl -0x28(%rbp),%xmm1
movsd  0xe62(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe4e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  0xe32(%rip),%xmm0
mulsd  %xmm1,%xmm0
movslq -0x28(%rbp),%rcx
lea    0x12e73(%rip),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1162 <dft_magnitude+0x32>
jmp    11f5 <dft_magnitude+0xc5>
movl   $0x1,-0x24(%rbp)
cmpl   $0x1000,-0x24(%rbp)
jge    12f1 <dft_magnitude+0x1c1>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x2000,-0x28(%rbp)
jge    12b5 <dft_magnitude+0x185>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x24(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    $0x2000,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0x2dfd(%rip),%rax
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x24(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    $0x2000,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0x12dc0(%rip),%rax
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1220 <dft_magnitude+0xf0>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fc <dft_magnitude+0xcc>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x7ff8(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dft_magnitude>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  0x2f07(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1214 <dft_magnitude+0xe4>
jp     1214 <dft_magnitude+0xe4>
xor    %ebp,%ebp
lea    0x2eea(%rip),%r15
lea    0x12ee3(%rip),%r12
nopl   (%rax)
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movsd  0xe81(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe7d(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,(%r15,%rbp,8)
movsd  (%rsp),%xmm0
call   1030 <sin@plt>
movapd 0xe6b(%rip),%xmm1
xorpd  %xmm1,%xmm0
movlpd %xmm0,(%r12,%rbp,8)
lea    0x1(%rbp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe2f(%rip),%xmm0
mulsd  0xe2f(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1040 <cos@plt>
movsd  %xmm0,0x8(%r15,%rbp,8)
movsd  (%rsp),%xmm0
call   1030 <sin@plt>
xorpd  0xe24(%rip),%xmm0
movlpd %xmm0,0x8(%r12,%rbp,8)
add    $0x2,%rbp
cmp    $0x2000,%rbp
jne    1170 <dft_magnitude+0x40>
mov    $0x1,%r15d
mov    $0x2,%r12d
lea    0x2e29(%rip),%r13
lea    0x12e22(%rip),%rbp
jmp    1250 <dft_magnitude+0x120>
call   1050 <sqrt@plt>
movsd  %xmm0,(%r14,%r15,8)
add    $0x1,%r15
add    $0x2,%r12
cmp    $0x1000,%r15
je     12ed <dft_magnitude+0x1bd>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
lea    0x0(,%rax,8),%edx
and    $0xfff0,%edx
movsd  (%rbx,%rcx,8),%xmm1
movsd  0x8(%rbx,%rcx,8),%xmm2
unpcklpd %xmm1,%xmm1
movsd  (%rdx,%rbp,1),%xmm3
movhpd (%rdx,%r13,1),%xmm3
mulpd  %xmm1,%xmm3
addpd  %xmm0,%xmm3
lea    (%r15,%rax,1),%edx
and    $0x1fff,%edx
unpcklpd %xmm2,%xmm2
movsd  0x0(%rbp,%rdx,8),%xmm0
movhpd 0x0(%r13,%rdx,8),%xmm0
mulpd  %xmm2,%xmm0
addpd  %xmm3,%xmm0
add    $0x2,%rcx
add    %r12,%rax
cmp    $0x2000,%rcx
jne    1260 <dft_magnitude+0x130>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd 0xd32(%rip),%xmm0
jb     1230 <dft_magnitude+0x100>
sqrtsd %xmm0,%xmm0
jmp    1235 <dft_magnitude+0x105>
movq   $0x0,0x7ff8(%r14)
xorpd  %xmm0,%xmm0
movupd %xmm0,(%r14)
movq   $0x0,0x10(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@dft_magnitude.cos_angle = internal global [8192 x double] zeroinitializer
@dft_magnitude.sin_angle = internal global [8192 x double] zeroinitializer
define void @dft_magnitude(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
store double* %0, double** %3
store double* %1, double** %4
%9 = load double, double* getelementptr inbounds ([8192 x double], [8192 x double]* @dft_magnitude.cos_angle, i64 0, i64 0)
%10 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %11, label %37
11: ; preds = %2
store i32 0, i32* %8
br label %12
12: ; preds = %33, %11
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 8192
br i1 %14, label %15, label %36
15: ; preds = %12
%16 = load i32, i32* %8
%17 = sitofp i32 %16 to double
%18 = fmul double 0x401921FB54442D18, %17
%19 = fdiv double %18, 8.192000e+03
%20 = call double @cos(double %19)
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.cos_angle, i64 0, i64 %22
store double %20, double* %23
%24 = load i32, i32* %8
%25 = sitofp i32 %24 to double
%26 = fmul double 0x401921FB54442D18, %25
%27 = fdiv double %26, 8.192000e+03
%28 = call double @sin(double %27)
%29 = fmul double -1.000000e+00, %28
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.sin_angle, i64 0, i64 %31
store double %29, double* %32
br label %33
33: ; preds = %15
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %12
36: ; preds = %12
br label %37
37: ; preds = %36, %2
store i32 1, i32* %7
br label %38
38: ; preds = %89, %37
%39 = load i32, i32* %7
%40 = icmp slt i32 %39, 4096
br i1 %40, label %41, label %92
41: ; preds = %38
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
store i32 0, i32* %8
br label %42
42: ; preds = %74, %41
%43 = load i32, i32* %8
%44 = icmp slt i32 %43, 8192
br i1 %44, label %45, label %77
45: ; preds = %42
%46 = load double*, double** %3
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = load i32, i32* %7
%52 = load i32, i32* %8
%53 = mul nsw i32 %51, %52
%54 = srem i32 %53, 8192
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.cos_angle, i64 0, i64 %55
%57 = load double, double* %56
%58 = load double, double* %5
%59 = call double @llvm.fmuladd.f64(double %50, double %57, double %58)
store double %59, double* %5
%60 = load double*, double** %3
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
%64 = load double, double* %63
%65 = load i32, i32* %7
%66 = load i32, i32* %8
%67 = mul nsw i32 %65, %66
%68 = srem i32 %67, 8192
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.sin_angle, i64 0, i64 %69
%71 = load double, double* %70
%72 = load double, double* %6
%73 = call double @llvm.fmuladd.f64(double %64, double %71, double %72)
store double %73, double* %6
br label %74
74: ; preds = %45
%75 = load i32, i32* %8
%76 = add nsw i32 %75, 1
store i32 %76, i32* %8
br label %42
77: ; preds = %42
%78 = load double, double* %5
%79 = load double, double* %5
%80 = load double, double* %6
%81 = load double, double* %6
%82 = fmul double %80, %81
%83 = call double @llvm.fmuladd.f64(double %78, double %79, double %82)
%84 = call double @sqrt(double %83)
%85 = load double*, double** %4
%86 = load i32, i32* %7
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %85, i64 %87
store double %84, double* %88
br label %89
89: ; preds = %77
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 1
store i32 %91, i32* %7
br label %38
92: ; preds = %38
%93 = load double*, double** %4
%94 = getelementptr inbounds double, double* %93, i64 4095
store double 0.000000e+00, double* %94
%95 = load double*, double** %4
%96 = getelementptr inbounds double, double* %95, i64 2
store double 0.000000e+00, double* %96
%97 = load double*, double** %4
%98 = getelementptr inbounds double, double* %97, i64 1
store double 0.000000e+00, double* %98
%99 = load double*, double** %4
%100 = getelementptr inbounds double, double* %99, i64 0
store double 0.000000e+00, double* %100
ret void
}

LLVM IR (-O2):
@dft_magnitude.cos_angle = internal unnamed_addr global [8192 x double] zeroinitializer
@dft_magnitude.sin_angle = internal unnamed_addr global [8192 x double] zeroinitializer
define void @dft_magnitude(double* nocapture %0, double* nocapture writeonly %1) {
%3 = load double, double* getelementptr inbounds ([8192 x double], [8192 x double]* @dft_magnitude.cos_angle, i64 0, i64 0)
%4 = fcmp oeq double %3, 0.000000e+00
br i1 %4, label %5, label %28
5: ; preds = %2, %5
%6 = phi i64 [ %26, %5 ], [ 0, %2 ]
%7 = trunc i64 %6 to i32
%8 = sitofp i32 %7 to double
%9 = fmul double %8, 0x401921FB54442D18
%10 = fmul double %9, 0x3F20000000000000
%11 = tail call double @cos(double %10)
%12 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.cos_angle, i64 0, i64 %6
store double %11, double* %12
%13 = tail call double @sin(double %10)
%14 = fneg double %13
%15 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.sin_angle, i64 0, i64 %6
store double %14, double* %15
%16 = or i64 %6, 1
%17 = trunc i64 %16 to i32
%18 = sitofp i32 %17 to double
%19 = fmul double %18, 0x401921FB54442D18
%20 = fmul double %19, 0x3F20000000000000
%21 = tail call double @cos(double %20)
%22 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.cos_angle, i64 0, i64 %16
store double %21, double* %22
%23 = tail call double @sin(double %20)
%24 = fneg double %23
%25 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.sin_angle, i64 0, i64 %16
store double %24, double* %25
%26 = add nuw nsw i64 %6, 2
%27 = icmp eq i64 %26, 8192
br i1 %27, label %28, label %5
28: ; preds = %5, %2
br label %29
29: ; preds = %28, %63
%30 = phi i64 [ %70, %63 ], [ 1, %28 ]
br label %31
31: ; preds = %31, %29
%32 = phi i64 [ 0, %29 ], [ %61, %31 ]
%33 = phi <2 x double> [ zeroinitializer, %29 ], [ %60, %31 ]
%34 = getelementptr inbounds double, double* %0, i64 %32
%35 = load double, double* %34
%36 = mul nuw nsw i64 %32, %30
%37 = and i64 %36, 8190
%38 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.cos_angle, i64 0, i64 %37
%39 = load double, double* %38
%40 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.sin_angle, i64 0, i64 %37
%41 = load double, double* %40
%42 = insertelement <2 x double> poison, double %35, i64 0
%43 = shufflevector <2 x double> %42, <2 x double> poison, <2 x i32> zeroinitializer
%44 = insertelement <2 x double> poison, double %41, i64 0
%45 = insertelement <2 x double> %44, double %39, i64 1
%46 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %43, <2 x double> %45, <2 x double> %33)
%47 = or i64 %32, 1
%48 = getelementptr inbounds double, double* %0, i64 %47
%49 = load double, double* %48
%50 = mul nuw nsw i64 %47, %30
%51 = and i64 %50, 8191
%52 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.cos_angle, i64 0, i64 %51
%53 = load double, double* %52
%54 = getelementptr inbounds [8192 x double], [8192 x double]* @dft_magnitude.sin_angle, i64 0, i64 %51
%55 = load double, double* %54
%56 = insertelement <2 x double> poison, double %49, i64 0
%57 = shufflevector <2 x double> %56, <2 x double> poison, <2 x i32> zeroinitializer
%58 = insertelement <2 x double> poison, double %55, i64 0
%59 = insertelement <2 x double> %58, double %53, i64 1
%60 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %57, <2 x double> %59, <2 x double> %46)
%61 = add nuw nsw i64 %32, 2
%62 = icmp eq i64 %61, 8192
br i1 %62, label %63, label %31
63: ; preds = %31
%64 = fmul <2 x double> %60, %60
%65 = extractelement <2 x double> %64, i64 0
%66 = extractelement <2 x double> %60, i64 1
%67 = tail call double @llvm.fmuladd.f64(double %66, double %66, double %65)
%68 = tail call double @sqrt(double %67)
%69 = getelementptr inbounds double, double* %1, i64 %30
store double %68, double* %69
%70 = add nuw nsw i64 %30, 1
%71 = icmp eq i64 %70, 4096
br i1 %71, label %72, label %29
72: ; preds = %63
%73 = getelementptr inbounds double, double* %1, i64 4095
store double 0.000000e+00, double* %73
%74 = bitcast double* %1 to i8*
ret void
}