#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 */
scalar_t__ abs(short);
int fix_fftr(short *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ show_amp(int, int, int);
void do_fft_test() {
  int i, scale;
  unsigned diff;
  short x[(2 * 64)], fx[(2 * 64)];
  printf("Samples: \n");
  for (i = 0; i < (2 * 64); i++) {
    show_amp(i, x[i], 12288);
  }
  fix_fftr(fx, (6 + 1), 0);
  printf("----------------------------------------------\n");
  printf("-  Frequencies                               -\n");
  printf("----------------------------------------------\n");
  for (i = 0; i < (2 * 64) / 2; i++)
    show_amp(i, fx[i], 12288);
  printf("----------------------------------------------\n");
  printf("-  Scaled                                    -\n");
  printf("----------------------------------------------\n");
  scale = fix_fftr(fx, (6 + 1), 1);
  for (i = 0, diff = 0; i < (2 * 64); i++) {
    int sample;
    if (i & 0x01)
      sample = fx[((2 * 64) + i) >> 1] << scale;
    else
      sample = fx[i >> 1] << scale;
    show_amp(i, sample, 12288);
    diff += abs(x[i] - sample);
  }
  return;
}


x86 assembly (clang, -O0):
<do_fft_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
lea    0xeae(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x80,-0x4(%rbp)
jge    1192 <do_fft_test+0x52>
mov    -0x4(%rbp),%edi
movslq -0x4(%rbp),%rax
movswl -0x110(%rbp,%rax,2),%esi
ff
mov    $0x3000,%edx
call   1060 <show_amp@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    115e <do_fft_test+0x1e>
lea    -0x210(%rbp),%rdi
mov    $0x7,%esi
xor    %edx,%edx
call   1040 <fix_fftr@plt>
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
lea    0xe83(%rip),%rdi
call   1050 <printf@plt>
lea    0xe47(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x40,-0x4(%rbp)
jge    1201 <do_fft_test+0xc1>
mov    -0x4(%rbp),%edi
movslq -0x4(%rbp),%rax
movswl -0x210(%rbp,%rax,2),%esi
ff
mov    $0x3000,%edx
call   1060 <show_amp@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11d0 <do_fft_test+0x90>
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
lea    0xdeb(%rip),%rdi
call   1050 <printf@plt>
lea    -0x210(%rbp),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
call   1040 <fix_fftr@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x80,-0x4(%rbp)
jge    12ef <do_fft_test+0x1af>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     128d <do_fft_test+0x14d>
mov    -0x4(%rbp),%eax
add    $0x80,%eax
sar    $0x1,%eax
cltq
movswl -0x210(%rbp,%rax,2),%eax
ff
mov    -0x8(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x214(%rbp)
jmp    12a8 <do_fft_test+0x168>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
cltq
movswl -0x210(%rbp,%rax,2),%eax
ff
mov    -0x8(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x214(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x214(%rbp),%esi
mov    $0x3000,%edx
call   1060 <show_amp@plt>
movslq -0x4(%rbp),%rax
movswl -0x110(%rbp,%rax,2),%eax
ff
sub    -0x214(%rbp),%eax
movswl %ax,%edi
call   1030 <abs@plt>
mov    %rax,%rcx
mov    -0xc(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    124c <do_fft_test+0x10c>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_fft_test>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
movswl 0x100(%rsp,%rbx,2),%esi
mov    %ebx,%edi
mov    $0x3000,%edx
call   1060 <show_amp@plt>
add    $0x1,%rbx
cmp    $0x80,%rbx
jne    1160 <do_fft_test+0x20>
mov    %rsp,%rdi
xor    %ebx,%ebx
mov    $0x7,%esi
xor    %edx,%edx
call   1050 <fix_fftr@plt>
lea    0xecf(%rip),%rbp
mov    %rbp,%rdi
call   1030 <puts@plt>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nop
movswl (%rsp,%rbx,2),%esi
mov    %ebx,%edi
mov    $0x3000,%edx
call   1060 <show_amp@plt>
add    $0x1,%rbx
cmp    $0x40,%rbx
jne    11c0 <do_fft_test+0x80>
lea    0xe87(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x7,%esi
mov    $0x1,%edx
call   1050 <fix_fftr@plt>
mov    %eax,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x80(%rbx),%eax
test   $0x1,%bl
cmove  %ebx,%eax
and    $0xfffffffe,%eax
movswl (%rsp,%rax,1),%ebp
mov    %r14d,%ecx
shl    %cl,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x3000,%edx
call   1060 <show_amp@plt>
movzwl 0x100(%rsp,%rbx,2),%eax
sub    %ebp,%eax
movswl %ax,%edi
call   1040 <abs@plt>
add    $0x1,%rbx
cmp    $0x80,%rbx
jne    1220 <do_fft_test+0xe0>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Samples: \0A\00"
@.str.1 = [48 x i8] c"----------------------------------------------\0A\00"
@.str.2 = [48 x i8] c"- Frequencies -\0A\00"
@.str.3 = [48 x i8] c"- Scaled -\0A\00"
define void @do_fft_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i16]
%5 = alloca [128 x i16]
%6 = alloca i32
%7 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %8
8: ; preds = %19, %0
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 128
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load i32, i32* %1
%13 = load i32, i32* %1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [128 x i16], [128 x i16]* %4, i64 0, i64 %14
%16 = load i16, i16* %15
%17 = sext i16 %16 to i32
%18 = call i32 @show_amp(i32 %12, i32 %17, i32 12288)
br label %19
19: ; preds = %11
%20 = load i32, i32* %1
%21 = add nsw i32 %20, 1
store i32 %21, i32* %1
br label %8
22: ; preds = %8
%23 = getelementptr inbounds [128 x i16], [128 x i16]* %5, i64 0, i64 0
%24 = call i32 @fix_fftr(i16* %23, i32 7, i32 0)
%25 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %28
28: ; preds = %39, %22
%29 = load i32, i32* %1
%30 = icmp slt i32 %29, 64
br i1 %30, label %31, label %42
31: ; preds = %28
%32 = load i32, i32* %1
%33 = load i32, i32* %1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [128 x i16], [128 x i16]* %5, i64 0, i64 %34
%36 = load i16, i16* %35
%37 = sext i16 %36 to i32
%38 = call i32 @show_amp(i32 %32, i32 %37, i32 12288)
br label %39
39: ; preds = %31
%40 = load i32, i32* %1
%41 = add nsw i32 %40, 1
store i32 %41, i32* %1
br label %28
42: ; preds = %28
%43 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%46 = getelementptr inbounds [128 x i16], [128 x i16]* %5, i64 0, i64 0
%47 = call i32 @fix_fftr(i16* %46, i32 7, i32 1)
store i32 %47, i32* %2
store i32 0, i32* %1
store i32 0, i32* %3
br label %48
48: ; preds = %91, %42
%49 = load i32, i32* %1
%50 = icmp slt i32 %49, 128
br i1 %50, label %51, label %94
51: ; preds = %48
%52 = load i32, i32* %1
%53 = and i32 %52, 1
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %51
%56 = load i32, i32* %1
%57 = add nsw i32 128, %56
%58 = ashr i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [128 x i16], [128 x i16]* %5, i64 0, i64 %59
%61 = load i16, i16* %60
%62 = sext i16 %61 to i32
%63 = load i32, i32* %2
%64 = shl i32 %62, %63
store i32 %64, i32* %6
br label %74
65: ; preds = %51
%66 = load i32, i32* %1
%67 = ashr i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [128 x i16], [128 x i16]* %5, i64 0, i64 %68
%70 = load i16, i16* %69
%71 = sext i16 %70 to i32
%72 = load i32, i32* %2
%73 = shl i32 %71, %72
store i32 %73, i32* %6
br label %74
74: ; preds = %65, %55
%75 = load i32, i32* %1
%76 = load i32, i32* %6
%77 = call i32 @show_amp(i32 %75, i32 %76, i32 12288)
%78 = load i32, i32* %1
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [128 x i16], [128 x i16]* %4, i64 0, i64 %79
%81 = load i16, i16* %80
%82 = sext i16 %81 to i32
%83 = load i32, i32* %6
%84 = sub nsw i32 %82, %83
%85 = trunc i32 %84 to i16
%86 = call i64 @abs(i16 signext %85)
%87 = load i32, i32* %3
%88 = zext i32 %87 to i64
%89 = add nsw i64 %88, %86
%90 = trunc i64 %89 to i32
store i32 %90, i32* %3
br label %91
91: ; preds = %74
%92 = load i32, i32* %1
%93 = add nsw i32 %92, 1
store i32 %93, i32* %1
br label %48
94: ; preds = %48
ret void
}

LLVM IR (-O2):
@str = [10 x i8] c"Samples: \00"
@str.5 = [47 x i8] c"- Frequencies -\00"
@str.8 = [47 x i8] c"- Scaled -\00"
@str.9 = [47 x i8] c"----------------------------------------------\00"
define void @do_fft_test() {
%1 = alloca [128 x i16]
%2 = alloca [128 x i16]
%3 = bitcast [128 x i16]* %1 to i8*
%4 = bitcast [128 x i16]* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 0, %0 ], [ %13, %6 ]
%8 = getelementptr inbounds [128 x i16], [128 x i16]* %1, i64 0, i64 %7
%9 = load i16, i16* %8
%10 = sext i16 %9 to i32
%11 = trunc i64 %7 to i32
%12 = tail call i32 @show_amp(i32 %11, i32 %10, i32 12288)
%13 = add nuw nsw i64 %7, 1
%14 = icmp eq i64 %13, 128
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = getelementptr inbounds [128 x i16], [128 x i16]* %2, i64 0, i64 0
%17 = call i32 @fix_fftr(i16* %16, i32 7, i32 0)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.9, i64 0, i64 0))
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.5, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.9, i64 0, i64 0))
br label %21
21: ; preds = %15, %21
%22 = phi i64 [ 0, %15 ], [ %28, %21 ]
%23 = getelementptr inbounds [128 x i16], [128 x i16]* %2, i64 0, i64 %22
%24 = load i16, i16* %23
%25 = sext i16 %24 to i32
%26 = trunc i64 %22 to i32
%27 = call i32 @show_amp(i32 %26, i32 %25, i32 12288)
%28 = add nuw nsw i64 %22, 1
%29 = icmp eq i64 %28, 64
br i1 %29, label %30, label %21
30: ; preds = %21
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.9, i64 0, i64 0))
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.8, i64 0, i64 0))
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.9, i64 0, i64 0))
%34 = call i32 @fix_fftr(i16* %16, i32 7, i32 1)
br label %35
35: ; preds = %30, %35
%36 = phi i64 [ 0, %30 ], [ %54, %35 ]
%37 = trunc i64 %36 to i32
%38 = and i32 %37, 1
%39 = icmp eq i32 %38, 0
%40 = add nuw i64 %36, 128
%41 = select i1 %39, i64 %36, i64 %40
%42 = lshr i64 %41, 1
%43 = and i64 %42, 2147483647
%44 = getelementptr inbounds [128 x i16], [128 x i16]* %2, i64 0, i64 %43
%45 = load i16, i16* %44
%46 = sext i16 %45 to i32
%47 = shl i32 %46, %34
%48 = call i32 @show_amp(i32 %37, i32 %47, i32 12288)
%49 = getelementptr inbounds [128 x i16], [128 x i16]* %1, i64 0, i64 %36
%50 = load i16, i16* %49
%51 = trunc i32 %47 to i16
%52 = sub i16 %50, %51
%53 = call i64 @abs(i16 signext %52)
%54 = add nuw nsw i64 %36, 1
%55 = icmp eq i64 %54, 128
br i1 %55, label %56, label %35
56: ; preds = %35
ret void
}