#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 */
float cos(float);
float sin(float);
float sqrtf(float);
void DoDFT(float *outbins, float *frequencies, int bins, float *databuffer,
           int place_in_data_buffer, int size_of_data_buffer, float q) {
  int i, j;
  for (i = 0; i < bins; i++) {
    float freq = frequencies[i];
    float phi = 0;
    int sampleplace = place_in_data_buffer;
    float advance = 3.14159 * 2.0 / freq;
    float binqtys = 0;
    float binqtyc = 0;
    for (j = 0; j <= freq * q; j++) {
      float sample = databuffer[sampleplace];
      sampleplace =
          (sampleplace - 1 + size_of_data_buffer) % size_of_data_buffer;
      float sv = sin(phi) * sample;
      float cv = cos(phi) * sample;
      binqtys += sv;
      binqtyc += cv;
      phi += advance;
    }
    float amp = sqrtf(binqtys * binqtys + binqtyc * binqtyc);
    outbins[i] = amp / freq / q;
  }
}


x86 assembly (clang, -O0):
<DoDFT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movss  %xmm0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a9 <DoDFT+0x179>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x3c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
movss  -0x38(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe68(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x44(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
movl   $0x0,-0x34(%rbp)
cvtsi2ssl -0x34(%rbp),%xmm1
movss  -0x38(%rbp),%xmm0
mulss  -0x2c(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     1259 <DoDFT+0x129>
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x50(%rbp)
mov    -0x40(%rbp),%eax
sub    $0x1,%eax
add    -0x28(%rbp),%eax
cltd
idivl  -0x28(%rbp)
mov    %edx,-0x40(%rbp)
movss  -0x3c(%rbp),%xmm0
call   1030 <sin@plt>
mulss  -0x50(%rbp),%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x3c(%rbp),%xmm0
call   1050 <cos@plt>
mulss  -0x50(%rbp),%xmm0
movss  %xmm0,-0x58(%rbp)
movss  -0x54(%rbp),%xmm0
addss  -0x48(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x58(%rbp),%xmm0
addss  -0x4c(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
movss  -0x44(%rbp),%xmm0
addss  -0x3c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11bc <DoDFT+0x8c>
movss  -0x48(%rbp),%xmm0
movss  -0x48(%rbp),%xmm2
movss  -0x4c(%rbp),%xmm1
mulss  -0x4c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1040 <sqrtf@plt>
movss  %xmm0,-0x5c(%rbp)
movss  -0x5c(%rbp),%xmm0
divss  -0x38(%rbp),%xmm0
divss  -0x2c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    115b <DoDFT+0x2b>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoDFT>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r8d,0xc(%rsp)
mov    %rsi,0x28(%rsp)
mov    %rdi,0x20(%rsp)
test   %edx,%edx
jle    12c5 <DoDFT+0x195>
movaps %xmm0,%xmm1
mov    %r9d,%r13d
mov    %rcx,%rbp
lea    -0x1(%r13),%r14d
mov    %edx,%eax
mov    %rax,0x18(%rsp)
xor    %r12d,%r12d
movss  %xmm0,(%rsp)
jmp    11b1 <DoDFT+0x81>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movaps %xmm1,%xmm0
call   1040 <sqrtf@plt>
movss  (%rsp),%xmm1
divss  0x4(%rsp),%xmm0
divss  %xmm1,%xmm0
mov    0x20(%rsp),%rax
movss  %xmm0,(%rax,%r12,4)
add    $0x1,%r12
cmp    0x18(%rsp),%r12
je     12c5 <DoDFT+0x195>
mov    0x28(%rsp),%rax
movss  (%rax,%r12,4),%xmm0
movss  %xmm0,0x4(%rsp)
movaps %xmm0,%xmm2
mulss  %xmm1,%xmm2
xorps  %xmm1,%xmm1
ucomiss 0xe35(%rip),%xmm2
jb     129a <DoDFT+0x16a>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe15(%rip),%xmm1
divsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x10(%rsp)
xorps  %xmm1,%xmm1
xorps  %xmm3,%xmm3
mov    $0x1,%r15d
mov    0xc(%rsp),%ebx
movss  %xmm2,0x14(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  %xmm3,0x8(%rsp)
movaps %xmm1,0x50(%rsp)
movslq %ebx,%rcx
lea    (%r14,%rcx,1),%eax
cltd
idiv   %r13d
movss  0x0(%rbp,%rcx,4),%xmm0
movaps %xmm0,0x40(%rsp)
mov    %edx,%ebx
movaps %xmm3,%xmm0
call   1030 <sin@plt>
movaps %xmm0,0x30(%rsp)
movss  0x8(%rsp),%xmm0
call   1050 <cos@plt>
movss  0x8(%rsp),%xmm3
movss  0x14(%rsp),%xmm2
movaps 0x50(%rsp),%xmm1
movaps 0x40(%rsp),%xmm4
shufps $0x0,%xmm4,%xmm4
movaps 0x30(%rsp),%xmm5
unpcklps %xmm0,%xmm5
mulps  %xmm4,%xmm5
addps  %xmm5,%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %r15d,%xmm0
addss  0x10(%rsp),%xmm3
add    $0x1,%r15d
ucomiss %xmm0,%xmm2
jae    1220 <DoDFT+0xf0>
movaps %xmm1,%xmm0
mulps  %xmm1,%xmm0
shufps $0x55,%xmm0,%xmm0
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
ucomiss 0xd55(%rip),%xmm1
jb     1180 <DoDFT+0x50>
xorps  %xmm0,%xmm0
sqrtss %xmm1,%xmm0
jmp    1188 <DoDFT+0x58>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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