#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 cosf_fast(float);
float sinf_fast(float);
void ambe_fdft_fc(float *out_i, float *out_q, float *in, int N, int M) {
  int fb, ts;
  for (fb = 0; fb <= (N / 2); fb++) {
    float i = 0.0f, q = 0.0f;
    for (ts = 0; ts < M; ts++) {
      float angle = (-2.0f * (3.141592653589793f) / N) * fb * ts;
      i += in[ts] * cosf_fast(angle);
      q += in[ts] * sinf_fast(angle);
    }
    out_i[fb] = i;
    out_q[fb] = q;
  }
}


x86 assembly (clang, -O0):
<ambe_fdft_fc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jg     1257 <ambe_fdft_fc+0x137>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1225 <ambe_fdft_fc+0x105>
cvtsi2ssl -0x1c(%rbp),%xmm1
movss  0xe70(%rip),%xmm0
divss  %xmm1,%xmm0
cvtsi2ssl -0x24(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvtsi2ssl -0x28(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  -0x34(%rbp),%xmm0
call   1030 <cosf_fast@plt>
movaps %xmm0,%xmm2
movss  -0x40(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x34(%rbp),%xmm0
call   1040 <sinf_fast@plt>
movaps %xmm0,%xmm2
movss  -0x3c(%rbp),%xmm0
movss  -0x30(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1177 <ambe_fdft_fc+0x57>
movss  -0x2c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
movss  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1142 <ambe_fdft_fc+0x22>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ambe_fdft_fc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8d,(%rsp)
mov    %rsi,0x28(%rsp)
cmp    $0xffffffff,%ecx
jge    114b <ambe_fdft_fc+0x2b>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rdx,%rbx
mov    %rdi,%r12
mov    %ecx,%r13d
shr    $0x1f,%r13d
add    %ecx,%r13d
sar    %r13d
cvtsi2ss %ecx,%xmm0
movss  0xe96(%rip),%xmm1
divss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
add    $0x1,%r13d
mov    (%rsp),%ebp
xor    %r14d,%r14d
jmp    11a1 <ambe_fdft_fc+0x81>
xorps  %xmm1,%xmm1
movss  %xmm1,(%r12,%r14,4)
shufps $0x55,%xmm1,%xmm1
mov    0x28(%rsp),%rax
movss  %xmm1,(%rax,%r14,4)
add    $0x1,%r14
cmp    %r13,%r14
je     113c <ambe_fdft_fc+0x1c>
cmpl   $0x0,(%rsp)
jle    1180 <ambe_fdft_fc+0x60>
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
mulss  0x4(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2ss %r15d,%xmm1
movaps %xmm0,0x40(%rsp)
mulss  0x8(%rsp),%xmm1
movss  %xmm1,0xc(%rsp)
movss  (%rbx,%r15,4),%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm1,%xmm0
call   1030 <cosf_fast@plt>
movaps %xmm0,0x30(%rsp)
movss  (%rbx,%r15,4),%xmm0
movaps 0x10(%rsp),%xmm1
unpcklps %xmm0,%xmm1
movaps %xmm1,0x10(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <sinf_fast@plt>
movaps 0x40(%rsp),%xmm2
movaps 0x30(%rsp),%xmm1
unpcklps %xmm0,%xmm1
mulps  0x10(%rsp),%xmm1
movaps %xmm1,%xmm0
addps  %xmm2,%xmm0
add    $0x1,%r15
cmp    %r15,%rbp
jne    11d0 <ambe_fdft_fc+0xb0>
addps  %xmm2,%xmm1
jmp    1183 <ambe_fdft_fc+0x63>

LLVM IR (-O0):
define void @ambe_fdft_fc(float* %0, float* %1, float* %2, i32 %3, i32 %4) {
%6 = alloca float*
%7 = alloca float*
%8 = alloca float*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca float
%14 = alloca float
%15 = alloca float
store float* %0, float** %6
store float* %1, float** %7
store float* %2, float** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 0, i32* %11
br label %16
16: ; preds = %68, %5
%17 = load i32, i32* %11
%18 = load i32, i32* %9
%19 = sdiv i32 %18, 2
%20 = icmp sle i32 %17, %19
br i1 %20, label %21, label %71
21: ; preds = %16
store float 0.000000e+00, float* %13
store float 0.000000e+00, float* %14
store i32 0, i32* %12
br label %22
22: ; preds = %54, %21
%23 = load i32, i32* %12
%24 = load i32, i32* %10
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %57
26: ; preds = %22
%27 = load i32, i32* %9
%28 = sitofp i32 %27 to float
%29 = fdiv float 0xC01921FB60000000, %28
%30 = load i32, i32* %11
%31 = sitofp i32 %30 to float
%32 = fmul float %29, %31
%33 = load i32, i32* %12
%34 = sitofp i32 %33 to float
%35 = fmul float %32, %34
store float %35, float* %15
%36 = load float*, float** %8
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds float, float* %36, i64 %38
%40 = load float, float* %39
%41 = load float, float* %15
%42 = call float @cosf_fast(float %41)
%43 = load float, float* %13
%44 = call float @llvm.fmuladd.f32(float %40, float %42, float %43)
store float %44, float* %13
%45 = load float*, float** %8
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds float, float* %45, i64 %47
%49 = load float, float* %48
%50 = load float, float* %15
%51 = call float @sinf_fast(float %50)
%52 = load float, float* %14
%53 = call float @llvm.fmuladd.f32(float %49, float %51, float %52)
store float %53, float* %14
br label %54
54: ; preds = %26
%55 = load i32, i32* %12
%56 = add nsw i32 %55, 1
store i32 %56, i32* %12
br label %22
57: ; preds = %22
%58 = load float, float* %13
%59 = load float*, float** %6
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds float, float* %59, i64 %61
store float %58, float* %62
%63 = load float, float* %14
%64 = load float*, float** %7
%65 = load i32, i32* %11
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds float, float* %64, i64 %66
store float %63, float* %67
br label %68
68: ; preds = %57
%69 = load i32, i32* %11
%70 = add nsw i32 %69, 1
store i32 %70, i32* %11
br label %16
71: ; preds = %16
ret void
}

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