#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
double sin(int);
int sscanf(char *, char *, int *);
int main(int argc, char **argv) {
  int i;
  int fft_size;
  int table_size;
  unsigned int out;
  if (argc != 2) {
    printf("Usage: %s <size>\n", argv[0]);
    printf("  <size>: size of (complex) FFT\n");
    printf("\n");
    exit(1);
  }
  if (sscanf(argv[1], "%d", &fft_size) != 1) {
    printf("Error: Invalid size\n");
    exit(1);
  }
  if (fft_size <= 0) {
    printf("Error: Invalid size\n");
    exit(1);
  }
  table_size = (fft_size / 4);
  printf("// Table generated using gen_twiddle.\n");
  printf("// FFT size: %d.\n", fft_size);
  printf("const uint16_t twiddle_factor_lookup[%d] = {\n", table_size);
  for (i = 0; i < table_size; i++) {
    out = (unsigned int)(sin(i * (2.0 * 3.141592653589793238462643 /
                                  (double)fft_size)) *
                             (double)0x00010000 +
                         0.5);
    printf("0x%04x", out);
    if (i != (table_size - 1)) {
      printf(", ");
    }
    if ((i % 8) == (8 - 1)) {
      printf("\n");
    }
  }
  printf("};\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119b <main+0x5b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xea1(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11d4 <main+0x94>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jg     11f6 <main+0xb6>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12ef <main+0x1af>
cvtsi2sdl -0x14(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm2
movsd  0xda7(%rip),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sin@plt>
movsd  0xd96(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd92(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     12ba <main+0x17a>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x7,%edx
jne    12dc <main+0x19c>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12e1 <main+0x1a1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123b <main+0xfb>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    12b5 <main+0x155>
mov    0x8(%rsi),%rdi
lea    0xeb2(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    129f <main+0x13f>
mov    0x4(%rsp),%ebx
test   %ebx,%ebx
jle    129f <main+0x13f>
mov    %ebx,%r14d
shr    $0x2,%r14d
lea    0xed2(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%esi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7c(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x4,%ebx
jae    11f5 <main+0x95>
lea    0xec4(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    -0x1(%r14),%r12d
cmp    $0x2,%r14d
mov    $0x1,%ebx
cmovae %r14d,%ebx
xorpd  %xmm2,%xmm2
lea    0xe64(%rip),%r15
lea    0xe64(%rip),%r14
xor    %ebp,%ebp
jmp    1235 <main+0xd5>
nopl   0x0(%rax)
movsd  0x8(%rsp),%xmm2
addsd  0xdea(%rip),%xmm2
add    $0x1,%ebp
cmp    %ebp,%ebx
je     11da <main+0x7a>
xorps  %xmm0,%xmm0
cvtsi2sdl 0x4(%rsp),%xmm0
movsd  0xdba(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm2,0x8(%rsp)
mulsd  %xmm2,%xmm1
cvttsd2si %xmm1,%edi
call   1060 <sin@plt>
mulsd  0xda3(%rip),%xmm0
addsd  0xda3(%rip),%xmm0
cvttsd2si %xmm0,%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebp,%r12d
je     128b <main+0x12b>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
not    %eax
test   $0x7,%al
jne    1220 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1220 <main+0xc0>
lea    0xe02(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    (%rsi),%rsi
lea    0xd61(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdef(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s <size>\0A\00"
@.str.1 = [33 x i8] c" <size>: size of (complex) FFT\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [21 x i8] c"Error: Invalid size\0A\00"
@.str.5 = [39 x i8] c"// Table generated using gen_twiddle.\0A\00"
@.str.6 = [18 x i8] c"// FFT size: %d.\0A\00"
@.str.7 = [46 x i8] c"const uint16_t twiddle_factor_lookup[%d] = {\0A\00"
@.str.8 = [7 x i8] c"0x%04x\00"
@.str.9 = [3 x i8] c", \00"
@.str.10 = [4 x i8] c"};\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %20
%30 = load i32, i32* %7
%31 = icmp sle i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %29
%36 = load i32, i32* %7
%37 = sdiv i32 %36, 4
store i32 %37, i32* %8
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%39 = load i32, i32* %7
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %41)
store i32 0, i32* %6
br label %43
43: ; preds = %73, %35
%44 = load i32, i32* %6
%45 = load i32, i32* %8
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %76
47: ; preds = %43
%48 = load i32, i32* %6
%49 = sitofp i32 %48 to double
%50 = load i32, i32* %7
%51 = sitofp i32 %50 to double
%52 = fdiv double 0x401921FB54442D18, %51
%53 = fmul double %49, %52
%54 = fptosi double %53 to i32
%55 = call double @sin(i32 %54)
%56 = call double @llvm.fmuladd.f64(double %55, double 6.553600e+04, double 5.000000e-01)
%57 = fptoui double %56 to i32
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %6
%61 = load i32, i32* %8
%62 = sub nsw i32 %61, 1
%63 = icmp ne i32 %60, %62
br i1 %63, label %64, label %66
64: ; preds = %47
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
br label %66
66: ; preds = %64, %47
%67 = load i32, i32* %6
%68 = srem i32 %67, 8
%69 = icmp eq i32 %68, 7
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %72
72: ; preds = %70, %66
br label %73
73: ; preds = %72
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %43
76: ; preds = %43
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s <size>\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.6 = [18 x i8] c"// FFT size: %d.\0A\00"
@.str.7 = [46 x i8] c"const uint16_t twiddle_factor_lookup[%d] = {\0A\00"
@.str.8 = [7 x i8] c"0x%04x\00"
@.str.9 = [3 x i8] c", \00"
@str = [38 x i8] c"// Table generated using gen_twiddle.\00"
@str.11 = [3 x i8] c"};\00"
@str.13 = [20 x i8] c"Error: Invalid size\00"
@str.14 = [32 x i8] c" <size>: size of (complex) FFT\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.14, i64 0, i64 0))
%10 = tail call i32 @putchar(i32 10)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%16 = icmp eq i32 %15, 1
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.13, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.13, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = lshr i32 %21, 2
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %27)
%32 = icmp ult i32 %21, 4
br i1 %32, label %59, label %33
33: ; preds = %26
%34 = add nsw i32 %27, -1
%35 = call i32 @llvm.umax.i32(i32 %27, i32 1)
br label %36
36: ; preds = %33, %56
%37 = phi i32 [ 0, %33 ], [ %57, %56 ]
%38 = sitofp i32 %37 to double
%39 = load i32, i32* %3
%40 = sitofp i32 %39 to double
%41 = fdiv double 0x401921FB54442D18, %40
%42 = fmul double %41, %38
%43 = fptosi double %42 to i32
%44 = call double @sin(i32 %43)
%45 = call double @llvm.fmuladd.f64(double %44, double 6.553600e+04, double 5.000000e-01)
%46 = fptoui double %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i32 %46)
%48 = icmp eq i32 %37, %34
br i1 %48, label %51, label %49
49: ; preds = %36
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
br label %51
51: ; preds = %49, %36
%52 = and i32 %37, 7
%53 = icmp eq i32 %52, 7
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @putchar(i32 10)
br label %56
56: ; preds = %51, %54
%57 = add nuw nsw i32 %37, 1
%58 = icmp eq i32 %57, %35
br i1 %58, label %59, label %36
59: ; preds = %56, %26
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.11, i64 0, i64 0))
ret i32 0
}