#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 *dgetmem(int const);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ memcpy(double *, double *, int);
double sin(double);
int dft(double *pReal, double *pImag, const int nDFTLength) {
  int k, n;
  double *pTempReal, *pTempImag, TempReal, TempImag;
  pTempReal = dgetmem(nDFTLength);
  pTempImag = dgetmem(nDFTLength);
  memcpy(pTempReal, pReal, sizeof(double) * nDFTLength);
  memcpy(pTempImag, pImag, sizeof(double) * nDFTLength);
  for (k = 0; k < nDFTLength; k++) {
    TempReal = 0;
    TempImag = 0;
    for (n = 0; n < nDFTLength; n++) {
      TempReal +=
          pTempReal[n] *
              cos(2.0 * 3.14159265358979323846 * n * k / (double)nDFTLength) +
          pTempImag[n] *
              sin(2.0 * 3.14159265358979323846 * n * k / (double)nDFTLength);
      TempImag +=
          -pTempReal[n] *
              sin(2.0 * 3.14159265358979323846 * n * k / (double)nDFTLength) +
          pTempImag[n] *
              cos(2.0 * 3.14159265358979323846 * n * k / (double)nDFTLength);
    }
    pReal[k] = TempReal;
    pImag[k] = TempImag;
  }
  free(pTempReal);
  free(pTempImag);
  return (0);
}


x86 assembly (clang, -O0):
<dft>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <dgetmem@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <dgetmem@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1378 <dft+0x228>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1346 <dft+0x1f6>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xe02(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1060 <cos@plt>
movsd  %xmm0,-0x68(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x70(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xdc3(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  -0x70(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xd4a(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xd0b(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1060 <cos@plt>
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d3 <dft+0x83>
movsd  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b0 <dft+0x60>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dft>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %edx,%r13d
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%edi
call   1070 <dgetmem@plt>
mov    %rax,%r12
mov    %r13d,%edi
call   1070 <dgetmem@plt>
mov    %rax,%rbx
lea    0x0(,%r13,8),%ebp
mov    %r12,%rdi
mov    %r15,0x38(%rsp)
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %r14,%r15
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
test   %r13d,%r13d
jle    12f1 <dft+0x1a1>
cvtsi2sd %r13d,%xmm4
mov    %r13d,%ebp
xor    %r13d,%r13d
movsd  0xe3b(%rip),%xmm1
movsd  %xmm4,0x40(%rsp)
nopl   0x0(%rax,%rax,1)
xorps  %xmm2,%xmm2
cvtsi2sd %r13d,%xmm2
movsd  %xmm2,0x48(%rsp)
xorps  %xmm3,%xmm3
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movaps %xmm3,0x80(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0x48(%rsp),%xmm0
divsd  %xmm4,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%r12,%r14,8),%xmm1
movaps %xmm1,0x20(%rsp)
call   1060 <cos@plt>
movapd %xmm0,0x70(%rsp)
movsd  (%rbx,%r14,8),%xmm0
movaps %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,0x60(%rsp)
movsd  (%r12,%r14,8),%xmm0
xorps  0xdbe(%rip),%xmm0
unpcklpd 0x20(%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,0x50(%rsp)
movsd  (%rbx,%r14,8),%xmm0
unpcklpd 0x10(%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <cos@plt>
movapd 0x80(%rsp),%xmm3
movsd  0xd66(%rip),%xmm1
unpcklpd 0x60(%rsp),%xmm0
mulpd  0x10(%rsp),%xmm0
movapd 0x50(%rsp),%xmm2
unpcklpd 0x70(%rsp),%xmm2
mulpd  0x20(%rsp),%xmm2
addpd  %xmm0,%xmm2
movsd  0x40(%rsp),%xmm4
addpd  %xmm2,%xmm3
add    $0x1,%r14
cmp    %r14,%rbp
jne    11f0 <dft+0xa0>
mov    0x38(%rsp),%rax
movhpd %xmm3,(%rax,%r13,8)
movlpd %xmm3,(%r15,%r13,8)
add    $0x1,%r13
cmp    %rbp,%r13
jne    11d0 <dft+0x80>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @dft(double* %0, double* %1, i32 %2) {
%4 = tail call double* @dgetmem(i32 %2)
%5 = tail call double* @dgetmem(i32 %2)
%6 = shl i32 %2, 3
%7 = tail call i32 @memcpy(double* %4, double* %0, i32 %6)
%8 = tail call i32 @memcpy(double* %5, double* %1, i32 %6)
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %56
10: ; preds = %3
%11 = sitofp i32 %2 to double
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %49, %10
%14 = phi i64 [ 0, %10 ], [ %54, %49 ]
%15 = trunc i64 %14 to i32
%16 = sitofp i32 %15 to double
br label %17
17: ; preds = %13, %17
%18 = phi i64 [ 0, %13 ], [ %47, %17 ]
%19 = phi <2 x double> [ zeroinitializer, %13 ], [ %46, %17 ]
%20 = getelementptr inbounds double, double* %4, i64 %18
%21 = load double, double* %20
%22 = trunc i64 %18 to i32
%23 = sitofp i32 %22 to double
%24 = fmul double %23, 0x401921FB54442D18
%25 = fmul double %24, %16
%26 = fdiv double %25, %11
%27 = tail call double @cos(double %26)
%28 = getelementptr inbounds double, double* %5, i64 %18
%29 = load double, double* %28
%30 = tail call double @sin(double %26)
%31 = load double, double* %20
%32 = fneg double %31
%33 = tail call double @sin(double %26)
%34 = load double, double* %28
%35 = tail call double @cos(double %26)
%36 = insertelement <2 x double> poison, double %34, i64 0
%37 = insertelement <2 x double> %36, double %29, i64 1
%38 = insertelement <2 x double> poison, double %35, i64 0
%39 = insertelement <2 x double> %38, double %30, i64 1
%40 = fmul <2 x double> %37, %39
%41 = insertelement <2 x double> poison, double %32, i64 0
%42 = insertelement <2 x double> %41, double %21, i64 1
%43 = insertelement <2 x double> poison, double %33, i64 0
%44 = insertelement <2 x double> %43, double %27, i64 1
%45 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %42, <2 x double> %44, <2 x double> %40)
%46 = fadd <2 x double> %19, %45
%47 = add nuw nsw i64 %18, 1
%48 = icmp eq i64 %47, %12
br i1 %48, label %49, label %17
49: ; preds = %17
%50 = getelementptr inbounds double, double* %0, i64 %14
%51 = extractelement <2 x double> %46, i64 1
store double %51, double* %50
%52 = getelementptr inbounds double, double* %1, i64 %14
%53 = extractelement <2 x double> %46, i64 0
store double %53, double* %52
%54 = add nuw nsw i64 %14, 1
%55 = icmp eq i64 %54, %12
br i1 %55, label %56, label %13
56: ; preds = %49, %3
%57 = tail call i32 @free(double* %4)
%58 = tail call i32 @free(double* %5)
ret i32 0
}