#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 */
int /*<<< orphan*/ printf(char *, int);
void fft(double real[128], double img[128], double real_twid[128 / 2],
         double img_twid[128 / 2]) {
  int even, odd, span, log, rootindex;
  double temp;
  log = 0;
  for (span = 128 >> 1; span; span >>= 1, log++) {
    int counter = 0;
    for (odd = span; odd < 128; odd++) {
#pragma HLS loop_tripcount min = 64 max = 64 avg = 64
#pragma HLS pipeline
      counter++;
      odd |= span;
      even = odd ^ span;
      temp = real[even] + real[odd];
      real[odd] = real[even] - real[odd];
      real[even] = temp;
      temp = img[even] + img[odd];
      img[odd] = img[even] - img[odd];
      img[even] = temp;
      rootindex = (even << log) & (128 - 1);
      if (rootindex) {
        temp =
            real_twid[rootindex] * real[odd] - img_twid[rootindex] * img[odd];
        img[odd] =
            real_twid[rootindex] * img[odd] + img_twid[rootindex] * real[odd];
        real[odd] = temp;
      }
    }
    printf("counter = %d\n", counter);
  }
}


x86 assembly (clang, -O0):
<fft>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x40,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1329 <fft+0x219>
movl   $0x0,-0x44(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x80,-0x28(%rbp)
jge    1303 <fft+0x1f3>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x2c(%rbp),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
xor    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
mov    -0x30(%rbp),%ecx
shl    %cl,%eax
and    $0x7f,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12f0 <fft+0x1e0>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    12f5 <fft+0x1e5>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    114d <fft+0x3d>
mov    -0x44(%rbp),%esi
lea    0xcf3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1136 <fft+0x26>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fft>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    $0x40,%r13d
xor    %ebp,%ebp
jmp    115b <fft+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
shr    %r13d
add    $0x1,%ebp
cmp    $0x7,%ebp
je     121d <fft+0x10d>
xor    %esi,%esi
mov    %r13d,%eax
jmp    117d <fft+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rax),%ecx
add    $0x1,%esi
cmp    $0x7f,%eax
mov    %ecx,%eax
jge    1140 <fft+0x30>
or     %r13d,%eax
mov    %eax,%ecx
xor    %r13d,%ecx
movslq %ecx,%rdi
movsd  (%rbx,%rdi,8),%xmm0
movslq %eax,%rdx
movsd  (%rbx,%rdx,8),%xmm1
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rdx,8)
movsd  %xmm2,(%rbx,%rdi,8)
movsd  (%r12,%rdi,8),%xmm0
movsd  (%r12,%rdx,8),%xmm1
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
subsd  %xmm1,%xmm0
movsd  %xmm0,(%r12,%rdx,8)
movsd  %xmm2,(%r12,%rdi,8)
mov    %ebp,%ecx
shl    %cl,%edi
and    $0x7f,%edi
je     1170 <fft+0x60>
mov    %edi,%ecx
movsd  (%r15,%rcx,8),%xmm0
movsd  (%rbx,%rdx,8),%xmm1
movsd  (%r14,%rcx,8),%xmm2
movsd  (%r12,%rdx,8),%xmm3
movapd %xmm0,%xmm4
mulsd  %xmm3,%xmm0
mulsd  %xmm2,%xmm3
mulsd  %xmm1,%xmm4
subsd  %xmm3,%xmm4
mulsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r12,%rdx,8)
movsd  %xmm4,(%rbx,%rdx,8)
jmp    1170 <fft+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"counter = %d\0A\00"
define void @fft(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
store i32 0, i32* %12
store i32 64, i32* %11
br label %16
16: ; preds = %163, %4
%17 = load i32, i32* %11
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %168
19: ; preds = %16
store i32 0, i32* %15
%20 = load i32, i32* %11
store i32 %20, i32* %10
br label %21
21: ; preds = %157, %19
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 128
br i1 %23, label %24, label %160
24: ; preds = %21
%25 = load i32, i32* %15
%26 = add nsw i32 %25, 1
store i32 %26, i32* %15
%27 = load i32, i32* %11
%28 = load i32, i32* %10
%29 = or i32 %28, %27
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = load i32, i32* %11
%32 = xor i32 %30, %31
store i32 %32, i32* %9
%33 = load double*, double** %5
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = load double*, double** %5
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = fadd double %37, %42
store double %43, double* %14
%44 = load double*, double** %5
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = load double*, double** %5
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
%54 = fsub double %48, %53
%55 = load double*, double** %5
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
store double %54, double* %58
%59 = load double, double* %14
%60 = load double*, double** %5
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
store double %59, double* %63
%64 = load double*, double** %6
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
%68 = load double, double* %67
%69 = load double*, double** %6
%70 = load i32, i32* %10
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
%73 = load double, double* %72
%74 = fadd double %68, %73
store double %74, double* %14
%75 = load double*, double** %6
%76 = load i32, i32* %9
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %75, i64 %77
%79 = load double, double* %78
%80 = load double*, double** %6
%81 = load i32, i32* %10
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %80, i64 %82
%84 = load double, double* %83
%85 = fsub double %79, %84
%86 = load double*, double** %6
%87 = load i32, i32* %10
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double, double* %86, i64 %88
store double %85, double* %89
%90 = load double, double* %14
%91 = load double*, double** %6
%92 = load i32, i32* %9
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds double, double* %91, i64 %93
store double %90, double* %94
%95 = load i32, i32* %9
%96 = load i32, i32* %12
%97 = shl i32 %95, %96
%98 = and i32 %97, 127
store i32 %98, i32* %13
%99 = load i32, i32* %13
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %156
101: ; preds = %24
%102 = load double*, double** %7
%103 = load i32, i32* %13
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds double, double* %102, i64 %104
%106 = load double, double* %105
%107 = load double*, double** %5
%108 = load i32, i32* %10
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %107, i64 %109
%111 = load double, double* %110
%112 = load double*, double** %8
%113 = load i32, i32* %13
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds double, double* %112, i64 %114
%116 = load double, double* %115
%117 = load double*, double** %6
%118 = load i32, i32* %10
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds double, double* %117, i64 %119
%121 = load double, double* %120
%122 = fmul double %116, %121
%123 = fneg double %122
%124 = call double @llvm.fmuladd.f64(double %106, double %111, double %123)
store double %124, double* %14
%125 = load double*, double** %7
%126 = load i32, i32* %13
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds double, double* %125, i64 %127
%129 = load double, double* %128
%130 = load double*, double** %6
%131 = load i32, i32* %10
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds double, double* %130, i64 %132
%134 = load double, double* %133
%135 = load double*, double** %8
%136 = load i32, i32* %13
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds double, double* %135, i64 %137
%139 = load double, double* %138
%140 = load double*, double** %5
%141 = load i32, i32* %10
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds double, double* %140, i64 %142
%144 = load double, double* %143
%145 = fmul double %139, %144
%146 = call double @llvm.fmuladd.f64(double %129, double %134, double %145)
%147 = load double*, double** %6
%148 = load i32, i32* %10
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds double, double* %147, i64 %149
store double %146, double* %150
%151 = load double, double* %14
%152 = load double*, double** %5
%153 = load i32, i32* %10
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds double, double* %152, i64 %154
store double %151, double* %155
br label %156
156: ; preds = %101, %24
br label %157
157: ; preds = %156
%158 = load i32, i32* %10
%159 = add nsw i32 %158, 1
store i32 %159, i32* %10
br label %21
160: ; preds = %21
%161 = load i32, i32* %15
%162 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %161)
br label %163
163: ; preds = %160
%164 = load i32, i32* %11
%165 = ashr i32 %164, 1
store i32 %165, i32* %11
%166 = load i32, i32* %12
%167 = add nsw i32 %166, 1
store i32 %167, i32* %12
br label %16
168: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"counter = %d\0A\00"
define void @fft(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3) {
br label %5
5: ; preds = %47, %4
%6 = phi i32 [ 0, %4 ], [ %50, %47 ]
%7 = phi i32 [ 64, %4 ], [ %49, %47 ]
br label %8
8: ; preds = %5, %44
%9 = phi i32 [ %11, %44 ], [ 0, %5 ]
%10 = phi i32 [ %45, %44 ], [ %7, %5 ]
%11 = add nuw nsw i32 %9, 1
%12 = or i32 %10, %7
%13 = xor i32 %12, %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = load double, double* %15
%17 = sext i32 %12 to i64
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = load double, double* %18
%20 = fadd double %16, %19
%21 = fsub double %16, %19
store double %21, double* %18
store double %20, double* %15
%22 = getelementptr inbounds double, double* %1, i64 %14
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %1, i64 %17
%25 = load double, double* %24
%26 = fadd double %23, %25
%27 = fsub double %23, %25
store double %27, double* %24
store double %26, double* %22
%28 = shl i32 %13, %6
%29 = and i32 %28, 127
%30 = icmp eq i32 %29, 0
br i1 %30, label %44, label %31
31: ; preds = %8
%32 = zext i32 %29 to i64
%33 = getelementptr inbounds double, double* %2, i64 %32
%34 = load double, double* %33
%35 = load double, double* %18
%36 = getelementptr inbounds double, double* %3, i64 %32
%37 = load double, double* %36
%38 = load double, double* %24
%39 = fneg double %37
%40 = fmul double %38, %39
%41 = tail call double @llvm.fmuladd.f64(double %34, double %35, double %40)
%42 = fmul double %35, %37
%43 = tail call double @llvm.fmuladd.f64(double %34, double %38, double %42)
store double %43, double* %24
store double %41, double* %18
br label %44
44: ; preds = %8, %31
%45 = add nsw i32 %12, 1
%46 = icmp slt i32 %12, 127
br i1 %46, label %8, label %47
47: ; preds = %44
%48 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %11)
%49 = lshr i32 %7, 1
%50 = add nuw nsw i32 %6, 1
%51 = icmp eq i32 %50, 7
br i1 %51, label %52, label %5
52: ; preds = %47
ret void
}