#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 dft(double *in_real, double *in_im, double *out_real, double *out_im,
         int len, double sign) {
  int k, n;
  for (k = 0; k < len; k++) {
    out_real[k] = 0.;
    out_im[k] = 0.;
    for (n = 0; n < len; n++) {
      double a = in_real[n], b = in_im[n];
      double x = sign * (2 * 3.14159265 * k * n) / len;
      double cos_ = cos(x), sin_ = sin(x);
      out_real[k] += (a * cos_ - b * sin_);
      out_im[k] += (a * sin_ + b * cos_);
    }
  }
}


x86 assembly (clang, -O0):
<dft>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    128e <dft+0x16e>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    127b <dft+0x15b>
mov    -0x8(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm2
movsd  0xe43(%rip),%xmm1
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    117b <dft+0x5b>
jmp    1280 <dft+0x160>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1148 <dft+0x28>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dft>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
test   %r8d,%r8d
jle    1265 <dft+0x145>
mov    %rsi,%r12
mov    %rdi,%r13
cvtsi2sd %r8d,%xmm1
mov    %r8d,%r14d
xor    %ebp,%ebp
mov    %rbp,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rbp
movq   $0x0,(%rdx,%rbp,8)
movq   $0x0,(%rcx,%rbp,8)
xorps  %xmm2,%xmm2
cvtsi2sd %ebp,%xmm2
mulsd  0xe7c(%rip),%xmm2
movsd  %xmm2,0x20(%rsp)
xor    %r15d,%r15d
nopl   (%rax)
movsd  0x0(%r13,%r15,8),%xmm2
movsd  %xmm2,0x38(%rsp)
xorps  %xmm3,%xmm3
cvtsi2sd %r15d,%xmm3
movsd  (%r12,%r15,8),%xmm2
movsd  %xmm2,0x40(%rsp)
mulsd  0x20(%rsp),%xmm3
mulsd  %xmm0,%xmm3
divsd  %xmm1,%xmm3
movsd  %xmm3,0x28(%rsp)
movapd %xmm3,%xmm0
mov    %rcx,%rbx
mov    %rdx,%rbp
call   1040 <cos@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x28(%rsp),%xmm0
call   1030 <sin@plt>
mov    %rbp,%rdx
mov    %rbx,%rcx
movsd  0x38(%rsp),%xmm2
movapd %xmm2,%xmm1
mulsd  %xmm0,%xmm2
movsd  0x40(%rsp),%xmm3
mulsd  %xmm3,%xmm0
movsd  0x30(%rsp),%xmm4
mulsd  %xmm4,%xmm1
subsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
mov    0x8(%rsp),%rbp
addsd  (%rdx,%rbp,8),%xmm1
movsd  %xmm1,(%rdx,%rbp,8)
movsd  0x10(%rsp),%xmm1
mulsd  %xmm4,%xmm3
addsd  %xmm3,%xmm2
addsd  (%rbx,%rbp,8),%xmm2
movsd  %xmm2,(%rbx,%rbp,8)
add    $0x1,%r15
cmp    %r15,%r14
jne    1190 <dft+0x70>
mov    0x8(%rsp),%rbx
add    $0x1,%rbx
mov    %rbx,%rbp
mov    %rbx,0x8(%rsp)
cmp    %r14,%rbx
jne    1160 <dft+0x40>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @dft(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, i32 %4, double %5) {
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %45
8: ; preds = %6
%9 = sitofp i32 %4 to double
%10 = zext i32 %4 to i64
br label %11
11: ; preds = %42, %8
%12 = phi i64 [ 0, %8 ], [ %43, %42 ]
%13 = getelementptr inbounds double, double* %2, i64 %12
store double 0.000000e+00, double* %13
%14 = getelementptr inbounds double, double* %3, i64 %12
store double 0.000000e+00, double* %14
%15 = trunc i64 %12 to i32
%16 = sitofp i32 %15 to double
%17 = fmul double %16, 0x401921FB53C8D4F1
br label %18
18: ; preds = %11, %18
%19 = phi i64 [ 0, %11 ], [ %40, %18 ]
%20 = getelementptr inbounds double, double* %0, i64 %19
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %1, i64 %19
%23 = load double, double* %22
%24 = trunc i64 %19 to i32
%25 = sitofp i32 %24 to double
%26 = fmul double %17, %25
%27 = fmul double %26, %5
%28 = fdiv double %27, %9
%29 = tail call double @cos(double %28)
%30 = tail call double @sin(double %28)
%31 = fneg double %23
%32 = fmul double %30, %31
%33 = tail call double @llvm.fmuladd.f64(double %21, double %29, double %32)
%34 = load double, double* %13
%35 = fadd double %34, %33
store double %35, double* %13
%36 = fmul double %23, %29
%37 = tail call double @llvm.fmuladd.f64(double %21, double %30, double %36)
%38 = load double, double* %14
%39 = fadd double %37, %38
store double %39, double* %14
%40 = add nuw nsw i64 %19, 1
%41 = icmp eq i64 %40, %10
br i1 %41, label %42, label %18
42: ; preds = %18
%43 = add nuw nsw i64 %12, 1
%44 = icmp eq i64 %43, %10
br i1 %44, label %45, label %11
45: ; preds = %42, %6
ret void
}