int main(int argc, char *argv[]) {
  unsigned MAXSIZE;
  unsigned MAXWAVES;
  unsigned i, j;
  double *RealIn;
  double *ImagIn;
  double *RealOut;
  double *ImagOut;
  double *coeff;
  double *amp;
  int invfft = 0;
  if (argc < 3) {
    printf("Usage: fft <waves> <length> -i\n");
    printf("-i performs an inverse fft\n");
    printf("make <waves> random sinusoids");
    printf("<length> is the number of samples\n");
    exit(-1);
  } else if (argc == 4)
    invfft = !strncmp(argv[3], "-i", 2);
  MAXSIZE = atoi(argv[2]);
  MAXWAVES = atoi(argv[1]);
  srand(1);
  for (int ind = 0; ind < 20; ++ind) {
    RealIn = (double *)malloc(sizeof(double) * MAXSIZE);
    ImagIn = (double *)malloc(sizeof(double) * MAXSIZE);
    RealOut = (double *)malloc(sizeof(double) * MAXSIZE);
    ImagOut = (double *)malloc(sizeof(double) * MAXSIZE);
    coeff = (double *)malloc(sizeof(double) * MAXWAVES);
    amp = (double *)malloc(sizeof(double) * MAXWAVES);
    for (i = 0; i < MAXWAVES; i++) {
      coeff[i] = rand() % 1000;
      amp[i] = rand() % 1000;
    }
    for (i = 0; i < MAXSIZE; i++) {
      RealIn[i] = 0;
      for (j = 0; j < MAXWAVES; j++) {
        if (rand() % 2) {
          RealIn[i] += coeff[j] * cos(amp[j] * i);
        } else {
          RealIn[i] += coeff[j] * sin(amp[j] * i);
        }
        ImagIn[i] = 0;
      }
    }
    fft_double(MAXSIZE, invfft, RealIn, ImagIn, RealOut, ImagOut);
    printf("RealOut:\n");
    for (i = 0; i < MAXSIZE; i++)
      printf("%d %lf \n", 0, RealOut[i]);
    printf("ImagOut:\n");
    for (i = 0; i < MAXSIZE; i++)
      printf("%d %lf \n", 0, ImagOut[i]);
    free(RealIn);
    free(ImagIn);
    free(RealOut);
    free(ImagOut);
    free(coeff);
    free(amp);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1219 <main+0x69>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
cmpl   $0x4,-0x8(%rbp)
jne    124c <main+0x9c>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x54(%rbp)
jmp    1251 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x0,%al
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x0,%al
call   10b0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    $0x1,%edi
mov    $0x0,%al
call   1070 <srand@plt>
movl   $0x0,-0x58(%rbp)
cmpl   $0x14,-0x58(%rbp)
jge    156e <main+0x3be>
mov    -0x14(%rbp),%eax
mov    %eax,%edi
shl    $0x3,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%edi
shl    $0x3,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%edi
shl    $0x3,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%edi
shl    $0x3,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%edi
shl    $0x3,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%edi
shl    $0x3,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    135d <main+0x1ad>
mov    $0x0,%al
call   10d0 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cvtsi2sd %edx,%xmm0
mov    -0x48(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   10d0 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cvtsi2sd %edx,%xmm0
mov    -0x50(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1305 <main+0x155>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1477 <main+0x2c7>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1464 <main+0x2b4>
mov    $0x0,%al
call   10d0 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     13fb <main+0x24b>
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x50(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
mov    -0x1c(%rbp),%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
call   10a0 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1447 <main+0x297>
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x50(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
mov    -0x1c(%rbp),%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
call   1080 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1386 <main+0x1d6>
jmp    1469 <main+0x2b9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1364 <main+0x1b4>
mov    -0x14(%rbp),%edi
mov    -0x54(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    $0x0,%al
call   1060 <fft_double@plt>
lea    0xbe5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    14df <main+0x32f>
mov    -0x38(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
lea    0xbc2(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    14a9 <main+0x2f9>
lea    0xbad(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    152a <main+0x37a>
mov    -0x40(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
lea    0xb77(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    14f4 <main+0x344>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1288 <main+0xd8>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
cmp    $0x2,%edi
jg     120f <main+0x4f>
lea    0xe5f(%rip),%rdi
call   1050 <puts@plt>
lea    0xe72(%rip),%rdi
call   1050 <puts@plt>
lea    0xe0e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe73(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    %rsi,%rbx
movl   $0x0,0xc(%rsp)
cmp    $0x4,%edi
jne    123f <main+0x7f>
mov    0x18(%rbx),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,0xc(%rsp)
mov    0x10(%rbx),%rdi
xor    %eax,%eax
call   10c0 <atoi@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
xor    %eax,%eax
call   10c0 <atoi@plt>
mov    %eax,%ebp
mov    $0x1,%edi
xor    %eax,%eax
call   1080 <srand@plt>
mov    %r14d,%r15d
lea    0x0(,%r15,8),%rax
mov    %rax,0x40(%rsp)
mov    %ebp,%eax
mov    %rax,0x20(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x38(%rsp)
xor    %eax,%eax
mov    %r15,0x48(%rsp)
jmp    131a <main+0x15a>
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    0xc(%rsp),%esi
mov    %r13,%rdx
mov    0x18(%rsp),%rcx
mov    0x10(%rsp),%r8
mov    %r14,%r9
xor    %eax,%eax
call   1070 <fft_double@plt>
lea    0xd62(%rip),%rdi
call   1050 <puts@plt>
lea    0xd5f(%rip),%rdi
call   1050 <puts@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x2c(%rsp),%eax
add    $0x1,%eax
cmp    $0x14,%eax
je     1554 <main+0x394>
mov    %eax,0x2c(%rsp)
mov    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <malloc@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   10a0 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %rbx,%rdi
call   10a0 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %rbx,%rdi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    0x38(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   10a0 <malloc@plt>
mov    %rax,%rbp
mov    0x20(%rsp),%rcx
test   %rcx,%rcx
je     13f2 <main+0x232>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10e0 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%r12,%rbx,8)
xor    %eax,%eax
call   10e0 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    0x20(%rsp),%rcx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rcx
jne    1380 <main+0x1c0>
test   %r15,%r15
je     12a0 <main+0xe0>
xor    %ebx,%ebx
mov    0x10(%rsp),%r8
mov    %r14,%r9
jmp    1422 <main+0x262>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    0x48(%rsp),%r15
cmp    %r15,%rbx
je     14c0 <main+0x300>
movq   $0x0,0x0(%r13,%rbx,8)
test   %rcx,%rcx
je     1410 <main+0x250>
mov    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x50(%rsp)
xor    %r15d,%r15d
jmp    1490 <main+0x2d0>
cs nopw 0x0(%rax,%rax,1)
nop
call   1090 <sin@plt>
movsd  0x30(%rsp),%xmm1
mov    0x20(%rsp),%rcx
mov    0x10(%rsp),%r8
mov    %r14,%r9
mulsd  %xmm0,%xmm1
addsd  0x0(%r13,%rbx,8),%xmm1
movsd  %xmm1,0x0(%r13,%rbx,8)
mov    0x18(%rsp),%rax
movq   $0x0,(%rax,%rbx,8)
add    $0x1,%r15
cmp    %r15,%rcx
je     1410 <main+0x250>
xor    %eax,%eax
call   10e0 <rand@plt>
movsd  (%r12,%r15,8),%xmm1
movsd  0x0(%rbp,%r15,8),%xmm0
mulsd  0x50(%rsp),%xmm0
test   $0x1,%al
movsd  %xmm1,0x30(%rsp)
je     1450 <main+0x290>
call   10b0 <cos@plt>
jmp    1455 <main+0x295>
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    0xc(%rsp),%esi
mov    %r13,%rdx
mov    0x18(%rsp),%rcx
xor    %eax,%eax
call   1070 <fft_double@plt>
lea    0xb4a(%rip),%rdi
call   1050 <puts@plt>
test   %r15,%r15
je     12ca <main+0x10a>
xor    %ebx,%ebx
nopl   (%rax)
mov    0x10(%rsp),%rax
movsd  (%rax,%rbx,8),%xmm0
lea    0xb1d(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%al
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    14f0 <main+0x330>
lea    0xb16(%rip),%rdi
call   1050 <puts@plt>
test   %r15,%r15
je     12d6 <main+0x116>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  (%r14,%rbx,8),%xmm0
lea    0xae1(%rip),%rdi
xor    %esi,%esi
mov    $0x1,%al
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1530 <main+0x370>
jmp    12d6 <main+0x116>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Usage: fft <waves> <length> -i\0A\00"
@.str.1 = [28 x i8] c"-i performs an inverse fft\0A\00"
@.str.2 = [30 x i8] c"make <waves> random sinusoids\00"
@.str.3 = [35 x i8] c"<length> is the number of samples\0A\00"
@.str.4 = [3 x i8] c"-i\00"
@.str.5 = [10 x i8] c"RealOut:\0A\00"
@.str.6 = [9 x i8] c"%d %lf \0A\00"
@.str.7 = [10 x i8] c"ImagOut:\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %16
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
unreachable
25: ; preds = %2
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 4
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = call i32 @strncmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2)
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
%35 = zext i1 %34 to i32
store i32 %35, i32* %16
br label %36
36: ; preds = %28, %25
br label %37
37: ; preds = %36
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %40)
store i32 %41, i32* %6
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %44)
store i32 %45, i32* %7
%46 = call i32 (i32, ...) bitcast (i32 (...)* @srand to i32 (i32, ...)*)(i32 1)
store i32 0, i32* %17
br label %47
47: ; preds = %227, %37
%48 = load i32, i32* %17
%49 = icmp slt i32 %48, 20
br i1 %49, label %50, label %230
50: ; preds = %47
%51 = load i32, i32* %6
%52 = zext i32 %51 to i64
%53 = mul i64 8, %52
%54 = call i8* @malloc(i64 %53)
%55 = bitcast i8* %54 to double*
store double* %55, double** %10
%56 = load i32, i32* %6
%57 = zext i32 %56 to i64
%58 = mul i64 8, %57
%59 = call i8* @malloc(i64 %58)
%60 = bitcast i8* %59 to double*
store double* %60, double** %11
%61 = load i32, i32* %6
%62 = zext i32 %61 to i64
%63 = mul i64 8, %62
%64 = call i8* @malloc(i64 %63)
%65 = bitcast i8* %64 to double*
store double* %65, double** %12
%66 = load i32, i32* %6
%67 = zext i32 %66 to i64
%68 = mul i64 8, %67
%69 = call i8* @malloc(i64 %68)
%70 = bitcast i8* %69 to double*
store double* %70, double** %13
%71 = load i32, i32* %7
%72 = zext i32 %71 to i64
%73 = mul i64 8, %72
%74 = call i8* @malloc(i64 %73)
%75 = bitcast i8* %74 to double*
store double* %75, double** %14
%76 = load i32, i32* %7
%77 = zext i32 %76 to i64
%78 = mul i64 8, %77
%79 = call i8* @malloc(i64 %78)
%80 = bitcast i8* %79 to double*
store double* %80, double** %15
store i32 0, i32* %8
br label %81
81: ; preds = %100, %50
%82 = load i32, i32* %8
%83 = load i32, i32* %7
%84 = icmp ult i32 %82, %83
br i1 %84, label %85, label %103
85: ; preds = %81
%86 = call i32 (...) @rand()
%87 = srem i32 %86, 1000
%88 = sitofp i32 %87 to double
%89 = load double*, double** %14
%90 = load i32, i32* %8
%91 = zext i32 %90 to i64
%92 = getelementptr inbounds double, double* %89, i64 %91
store double %88, double* %92
%93 = call i32 (...) @rand()
%94 = srem i32 %93, 1000
%95 = sitofp i32 %94 to double
%96 = load double*, double** %15
%97 = load i32, i32* %8
%98 = zext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
store double %95, double* %99
br label %100
100: ; preds = %85
%101 = load i32, i32* %8
%102 = add i32 %101, 1
store i32 %102, i32* %8
br label %81
103: ; preds = %81
store i32 0, i32* %8
br label %104
104: ; preds = %172, %103
%105 = load i32, i32* %8
%106 = load i32, i32* %6
%107 = icmp ult i32 %105, %106
br i1 %107, label %108, label %175
108: ; preds = %104
%109 = load double*, double** %10
%110 = load i32, i32* %8
%111 = zext i32 %110 to i64
%112 = getelementptr inbounds double, double* %109, i64 %111
store double 0.000000e+00, double* %112
store i32 0, i32* %9
br label %113
113: ; preds = %168, %108
%114 = load i32, i32* %9
%115 = load i32, i32* %7
%116 = icmp ult i32 %114, %115
br i1 %116, label %117, label %171
117: ; preds = %113
%118 = call i32 (...) @rand()
%119 = srem i32 %118, 2
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %142
121: ; preds = %117
%122 = load double*, double** %14
%123 = load i32, i32* %9
%124 = zext i32 %123 to i64
%125 = getelementptr inbounds double, double* %122, i64 %124
%126 = load double, double* %125
%127 = load double*, double** %15
%128 = load i32, i32* %9
%129 = zext i32 %128 to i64
%130 = getelementptr inbounds double, double* %127, i64 %129
%131 = load double, double* %130
%132 = load i32, i32* %8
%133 = uitofp i32 %132 to double
%134 = fmul double %131, %133
%135 = call double @cos(double %134)
%136 = load double*, double** %10
%137 = load i32, i32* %8
%138 = zext i32 %137 to i64
%139 = getelementptr inbounds double, double* %136, i64 %138
%140 = load double, double* %139
%141 = call double @llvm.fmuladd.f64(double %126, double %135, double %140)
store double %141, double* %139
br label %163
142: ; preds = %117
%143 = load double*, double** %14
%144 = load i32, i32* %9
%145 = zext i32 %144 to i64
%146 = getelementptr inbounds double, double* %143, i64 %145
%147 = load double, double* %146
%148 = load double*, double** %15
%149 = load i32, i32* %9
%150 = zext i32 %149 to i64
%151 = getelementptr inbounds double, double* %148, i64 %150
%152 = load double, double* %151
%153 = load i32, i32* %8
%154 = uitofp i32 %153 to double
%155 = fmul double %152, %154
%156 = call double @sin(double %155)
%157 = load double*, double** %10
%158 = load i32, i32* %8
%159 = zext i32 %158 to i64
%160 = getelementptr inbounds double, double* %157, i64 %159
%161 = load double, double* %160
%162 = call double @llvm.fmuladd.f64(double %147, double %156, double %161)
store double %162, double* %160
br label %163
163: ; preds = %142, %121
%164 = load double*, double** %11
%165 = load i32, i32* %8
%166 = zext i32 %165 to i64
%167 = getelementptr inbounds double, double* %164, i64 %166
store double 0.000000e+00, double* %167
br label %168
168: ; preds = %163
%169 = load i32, i32* %9
%170 = add i32 %169, 1
store i32 %170, i32* %9
br label %113
171: ; preds = %113
br label %172
172: ; preds = %171
%173 = load i32, i32* %8
%174 = add i32 %173, 1
store i32 %174, i32* %8
br label %104
175: ; preds = %104
%176 = load i32, i32* %6
%177 = load i32, i32* %16
%178 = load double*, double** %10
%179 = load double*, double** %11
%180 = load double*, double** %12
%181 = load double*, double** %13
%182 = call i32 (i32, i32, double*, double*, double*, double*, ...) bitcast (i32 (...)* @fft_double to i32 (i32, i32, double*, double*, double*, double*, ...)*)(i32 %176, i32 %177, double* %178, double* %179, double* %180, double* %181)
%183 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %8
br label %184
184: ; preds = %195, %175
%185 = load i32, i32* %8
%186 = load i32, i32* %6
%187 = icmp ult i32 %185, %186
br i1 %187, label %188, label %198
188: ; preds = %184
%189 = load double*, double** %12
%190 = load i32, i32* %8
%191 = zext i32 %190 to i64
%192 = getelementptr inbounds double, double* %189, i64 %191
%193 = load double, double* %192
%194 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 0, double %193)
br label %195
195: ; preds = %188
%196 = load i32, i32* %8
%197 = add i32 %196, 1
store i32 %197, i32* %8
br label %184
198: ; preds = %184
%199 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %8
br label %200
200: ; preds = %211, %198
%201 = load i32, i32* %8
%202 = load i32, i32* %6
%203 = icmp ult i32 %201, %202
br i1 %203, label %204, label %214
204: ; preds = %200
%205 = load double*, double** %13
%206 = load i32, i32* %8
%207 = zext i32 %206 to i64
%208 = getelementptr inbounds double, double* %205, i64 %207
%209 = load double, double* %208
%210 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 0, double %209)
br label %211
211: ; preds = %204
%212 = load i32, i32* %8
%213 = add i32 %212, 1
store i32 %213, i32* %8
br label %200
214: ; preds = %200
%215 = load double*, double** %10
%216 = bitcast double* %215 to i8*
%217 = load double*, double** %11
%218 = bitcast double* %217 to i8*
%219 = load double*, double** %12
%220 = bitcast double* %219 to i8*
%221 = load double*, double** %13
%222 = bitcast double* %221 to i8*
%223 = load double*, double** %14
%224 = bitcast double* %223 to i8*
%225 = load double*, double** %15
%226 = bitcast double* %225 to i8*
br label %227
227: ; preds = %214
%228 = load i32, i32* %17
%229 = add nsw i32 %228, 1
store i32 %229, i32* %17
br label %47
230: ; preds = %47
unreachable
}

LLVM IR (-O2):
@.str.2 = [30 x i8] c"make <waves> random sinusoids\00"
@.str.4 = [3 x i8] c"-i\00"
@.str.6 = [9 x i8] c"%d %lf \0A\00"
@str = [9 x i8] c"RealOut:\00"
@str.8 = [9 x i8] c"ImagOut:\00"
@str.9 = [31 x i8] c"Usage: fft <waves> <length> -i\00"
@str.10 = [27 x i8] c"-i performs an inverse fft\00"
@str.11 = [34 x i8] c"<length> is the number of samples\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.9, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.10, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.11, i64 0, i64 0))
tail call void @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = icmp eq i32 %0, 4
br i1 %10, label %11, label %17
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = tail call i32 @strncmp(i8* dereferenceable(1) %13, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2)
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %9, %11
%18 = phi i32 [ %16, %11 ], [ 0, %9 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %23)
%25 = tail call i32 (i32, ...) bitcast (i32 (...)* @srand to i32 (i32, ...)*)(i32 1)
%26 = zext i32 %21 to i64
%27 = shl nuw nsw i64 %26, 3
%28 = zext i32 %24 to i64
%29 = shl nuw nsw i64 %28, 3
%30 = icmp eq i32 %24, 0
%31 = icmp eq i32 %21, 0
br label %33
32: ; preds = %114
tail call void @exit(i32 0)
unreachable
33: ; preds = %17, %114
%34 = phi i32 [ 0, %17 ], [ %115, %114 ]
%35 = tail call i8* @malloc(i64 %27)
%36 = bitcast i8* %35 to double*
%37 = tail call i8* @malloc(i64 %27)
%38 = bitcast i8* %37 to double*
%39 = tail call i8* @malloc(i64 %27)
%40 = bitcast i8* %39 to double*
%41 = tail call i8* @malloc(i64 %27)
%42 = bitcast i8* %41 to double*
%43 = tail call i8* @malloc(i64 %29)
%44 = bitcast i8* %43 to double*
%45 = tail call i8* @malloc(i64 %29)
%46 = bitcast i8* %45 to double*
br i1 %30, label %47, label %48
47: ; preds = %48, %33
br i1 %31, label %93, label %60
48: ; preds = %33, %48
%49 = phi i64 [ %58, %48 ], [ 0, %33 ]
%50 = tail call i32 (...) @rand()
%51 = srem i32 %50, 1000
%52 = sitofp i32 %51 to double
%53 = getelementptr inbounds double, double* %44, i64 %49
store double %52, double* %53
%54 = tail call i32 (...) @rand()
%55 = srem i32 %54, 1000
%56 = sitofp i32 %55 to double
%57 = getelementptr inbounds double, double* %46, i64 %49
store double %56, double* %57
%58 = add nuw nsw i64 %49, 1
%59 = icmp eq i64 %58, %28
br i1 %59, label %47, label %48
60: ; preds = %47, %87
%61 = phi i64 [ %88, %87 ], [ 0, %47 ]
%62 = getelementptr inbounds double, double* %36, i64 %61
store double 0.000000e+00, double* %62
br i1 %30, label %87, label %63
63: ; preds = %60
%64 = trunc i64 %61 to i32
%65 = uitofp i32 %64 to double
%66 = getelementptr inbounds double, double* %38, i64 %61
br label %67
67: ; preds = %63, %81
%68 = phi i64 [ 0, %63 ], [ %85, %81 ]
%69 = tail call i32 (...) @rand()
%70 = and i32 %69, 1
%71 = icmp eq i32 %70, 0
%72 = getelementptr inbounds double, double* %44, i64 %68
%73 = load double, double* %72
%74 = getelementptr inbounds double, double* %46, i64 %68
%75 = load double, double* %74
%76 = fmul double %75, %65
br i1 %71, label %79, label %77
77: ; preds = %67
%78 = tail call double @cos(double %76)
br label %81
79: ; preds = %67
%80 = tail call double @sin(double %76)
br label %81
81: ; preds = %79, %77
%82 = phi double [ %80, %79 ], [ %78, %77 ]
%83 = load double, double* %62
%84 = tail call double @llvm.fmuladd.f64(double %73, double %82, double %83)
store double %84, double* %62
store double 0.000000e+00, double* %66
%85 = add nuw nsw i64 %68, 1
%86 = icmp eq i64 %85, %28
br i1 %86, label %87, label %67
87: ; preds = %81, %60
%88 = add nuw nsw i64 %61, 1
%89 = icmp eq i64 %88, %26
br i1 %89, label %90, label %60
90: ; preds = %87
%91 = tail call i32 (i32, i32, double*, double*, double*, double*, ...) bitcast (i32 (...)* @fft_double to i32 (i32, i32, double*, double*, double*, double*, ...)*)(i32 %21, i32 %18, double* %36, double* %38, double* %40, double* %42)
%92 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br i1 %31, label %96, label %98
93: ; preds = %47
%94 = tail call i32 (i32, i32, double*, double*, double*, double*, ...) bitcast (i32 (...)* @fft_double to i32 (i32, i32, double*, double*, double*, double*, ...)*)(i32 %21, i32 %18, double* %36, double* %38, double* %40, double* %42)
%95 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %96
96: ; preds = %93, %90
%97 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.8, i64 0, i64 0))
br label %114
98: ; preds = %90, %98
%99 = phi i64 [ %103, %98 ], [ 0, %90 ]
%100 = getelementptr inbounds double, double* %40, i64 %99
%101 = load double, double* %100
%102 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 0, double %101)
%103 = add nuw nsw i64 %99, 1
%104 = icmp eq i64 %103, %26
br i1 %104, label %105, label %98
105: ; preds = %98
%106 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.8, i64 0, i64 0))
br i1 %31, label %114, label %107
107: ; preds = %105, %107
%108 = phi i64 [ %112, %107 ], [ 0, %105 ]
%109 = getelementptr inbounds double, double* %42, i64 %108
%110 = load double, double* %109
%111 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 0, double %110)
%112 = add nuw nsw i64 %108, 1
%113 = icmp eq i64 %112, %26
br i1 %113, label %114, label %107
114: ; preds = %107, %96, %105
tail call void @free(i8* %35)
tail call void @free(i8* %37)
tail call void @free(i8* %39)
tail call void @free(i8* %41)
tail call void @free(i8* %43)
tail call void @free(i8* %45)
%115 = add nuw nsw i32 %34, 1
%116 = icmp eq i32 %115, 20
br i1 %116, label %32, label %33
}