#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);
int /*<<< orphan*/ printf(char *, ...);
double sin(double);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int i, j;
  int do_sin = argc == 2 && !strcmp(argv[1], "sin");
  double (*func)(double) = do_sin ? sin : cos;
  printf("/* This file was generated by libavcodec/costablegen */\n");
  printf("#include \"libavcodec/%s\"\n", do_sin ? "rdft.h" : "fft.h");
  for (i = 4; i <= 16; i++) {
    int m = 1 << i;
    double freq = 2 * 3.14159265358979323846 / m;
    printf("%s(%i) = {\n   ", do_sin ? "SINTABLE" : "COSTABLE", m);
    for (j = 0; j < m / 2 - 1; j++) {
      int idx = j > m / 4 ? m / 2 - j : j;
      if (do_sin && j >= m / 4)
        idx = m / 4 - j;
      printf(" "
             "%.18e"
             ",",
             func(idx * freq));
      if ((j & 3) == 3)
        printf("\n   ");
    }
    printf(" "
           "%.18e"
           "\n};\n",
           func(do_sin ? -(m / 4 - 1) * freq : freq));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x2,-0x8(%rbp)
mov    %al,-0x3d(%rbp)
jne    1164 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeb4(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edx
mov    0x2e6f(%rip),%rax
mov    0x2e60(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x28(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%ecx
lea    0xec3(%rip),%rsi
lea    0xeb5(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x4,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jg     1375 <main+0x255>
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xe16(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x1c(%rbp),%ecx
lea    0xe87(%rip),%rsi
lea    0xe77(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x2c(%rbp),%edx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    130b <main+0x1eb>
mov    -0x18(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
cmp    %ecx,%eax
jle    1278 <main+0x158>
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    -0x18(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    127e <main+0x15e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12bd <main+0x19d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
cmp    %ecx,%eax
jl     12bd <main+0x19d>
mov    -0x2c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
sub    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
cvtsi2sdl -0x3c(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
call   *%rax
lea    0xdb9(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
and    $0x3,%eax
cmp    $0x3,%eax
jne    12f8 <main+0x1d8>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12fd <main+0x1dd>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1223 <main+0x103>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1344 <main+0x224>
mov    -0x2c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
sub    $0x1,%ecx
xor    %eax,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    134e <main+0x22e>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x58(%rbp),%rax
movsd  -0x60(%rbp),%xmm0
call   *%rax
lea    0xd35(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c6 <main+0xa6>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xf06(%rip),%rax
mov    %rax,0x28(%rsp)
mov    0x2e97(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xed0(%rip),%rbx
cmp    $0x2,%edi
jne    1176 <main+0x46>
mov    0x8(%rsi),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     117a <main+0x4a>
xor    %ebp,%ebp
jmp    119c <main+0x6c>
lea    0xec1(%rip),%rax
mov    %rax,0x28(%rsp)
mov    0x2e53(%rip),%rax
mov    %rax,0x10(%rsp)
mov    $0x1,%bpl
lea    0xe8a(%rip),%rbx
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%r15d
xor    $0x1,%r15b
mov    $0x4,%ebx
mov    %ebp,0x24(%rsp)
jmp    121e <main+0xee>
nopl   0x0(%rax,%rax,1)
mov    0x30(%rsp),%rcx
lea    0x3(%rcx),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
sar    $0x2,%eax
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mov    0xc(%rsp),%ebx
call   *0x10(%rsp)
lea    0xe51(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    $0x11,%ebx
je     131c <main+0x1ec>
mov    $0x1,%ebp
mov    %ebx,0xc(%rsp)
mov    %ebx,%ecx
shl    %cl,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  0xdc6(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
lea    0xde8(%rip),%rdi
mov    0x28(%rsp),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,0x30(%rsp)
cmp    $0x4,%ebp
jl     1300 <main+0x1d0>
mov    0x30(%rsp),%rax
mov    %eax,%r12d
shr    $0x1f,%r12d
add    %eax,%r12d
sar    %r12d
mov    %eax,%r13d
shr    $0x2,%r13d
cmp    $0x3,%r12d
mov    $0x2,%ebx
cmovge %r12d,%ebx
add    $0xffffffff,%ebx
xor    %r14d,%r14d
mov    %r13d,%ebp
jmp    12b0 <main+0x180>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
add    $0xffffffff,%r12d
add    $0xffffffff,%ebp
cmp    %r14d,%ebx
je     1300 <main+0x1d0>
cmp    %r14d,%r13d
mov    %r14d,%eax
cmovb  %r12d,%eax
mov    %ebp,%ecx
cmova  %eax,%ecx
test   %r15b,%r15b
cmovne %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0x18(%rsp),%xmm0
call   *0x10(%rsp)
lea    0xd77(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r14d,%eax
not    %eax
test   $0x3,%al
jne    12a0 <main+0x170>
lea    0xd49(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12a0 <main+0x170>
nopl   (%rax)
mov    0x24(%rsp),%ebp
test   %bpl,%bpl
jne    11d0 <main+0xa0>
mov    0xc(%rsp),%ebx
movsd  0x18(%rsp),%xmm0
jmp    1200 <main+0xd0>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"sin\00"
@.str.1 = [57 x i8] c"/* This file was generated by libavcodec/costablegen */\0A\00"
@.str.2 = [26 x i8] c"#include \22libavcodec/%s\22\0A\00"
@.str.3 = [7 x i8] c"rdft.h\00"
@.str.4 = [6 x i8] c"fft.h\00"
@.str.5 = [15 x i8] c"%s(%i) = {\0A \00"
@.str.6 = [9 x i8] c"SINTABLE\00"
@.str.7 = [9 x i8] c"COSTABLE\00"
@.str.8 = [8 x i8] c" %.18e,\00"
@.str.9 = [5 x i8] c"\0A \00"
@.str.10 = [11 x i8] c" %.18e\0A};\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 double (double)*
%10 = alloca i32
%11 = alloca double
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br label %22
22: ; preds = %15, %2
%23 = phi i1 [ false, %2 ], [ %21, %15 ]
%24 = zext i1 %23 to i32
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, double (double)* @sin, double (double)* @cos
store double (double)* %28, double (double)** %9
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* %8
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %33)
store i32 4, i32* %6
br label %35
35: ; preds = %117, %22
%36 = load i32, i32* %6
%37 = icmp sle i32 %36, 16
br i1 %37, label %38, label %120
38: ; preds = %35
%39 = load i32, i32* %6
%40 = shl i32 1, %39
store i32 %40, i32* %10
%41 = load i32, i32* %10
%42 = sitofp i32 %41 to double
%43 = fdiv double 0x401921FB54442D18, %42
store double %43, double* %11
%44 = load i32, i32* %8
%45 = icmp ne i32 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0)
%48 = load i32, i32* %10
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %47, i32 %48)
store i32 0, i32* %7
br label %50
50: ; preds = %96, %38
%51 = load i32, i32* %7
%52 = load i32, i32* %10
%53 = sdiv i32 %52, 2
%54 = sub nsw i32 %53, 1
%55 = icmp slt i32 %51, %54
br i1 %55, label %56, label %99
56: ; preds = %50
%57 = load i32, i32* %7
%58 = load i32, i32* %10
%59 = sdiv i32 %58, 4
%60 = icmp sgt i32 %57, %59
br i1 %60, label %61, label %66
61: ; preds = %56
%62 = load i32, i32* %10
%63 = sdiv i32 %62, 2
%64 = load i32, i32* %7
%65 = sub nsw i32 %63, %64
br label %68
66: ; preds = %56
%67 = load i32, i32* %7
br label %68
68: ; preds = %66, %61
%69 = phi i32 [ %65, %61 ], [ %67, %66 ]
store i32 %69, i32* %12
%70 = load i32, i32* %8
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %82
72: ; preds = %68
%73 = load i32, i32* %7
%74 = load i32, i32* %10
%75 = sdiv i32 %74, 4
%76 = icmp sge i32 %73, %75
br i1 %76, label %77, label %82
77: ; preds = %72
%78 = load i32, i32* %10
%79 = sdiv i32 %78, 4
%80 = load i32, i32* %7
%81 = sub nsw i32 %79, %80
store i32 %81, i32* %12
br label %82
82: ; preds = %77, %72, %68
%83 = load double (double)*, double (double)** %9
%84 = load i32, i32* %12
%85 = sitofp i32 %84 to double
%86 = load double, double* %11
%87 = fmul double %85, %86
%88 = call double %83(double %87)
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), double %88)
%90 = load i32, i32* %7
%91 = and i32 %90, 3
%92 = icmp eq i32 %91, 3
br i1 %92, label %93, label %95
93: ; preds = %82
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %95
95: ; preds = %93, %82
br label %96
96: ; preds = %95
%97 = load i32, i32* %7
%98 = add nsw i32 %97, 1
store i32 %98, i32* %7
br label %50
99: ; preds = %50
%100 = load double (double)*, double (double)** %9
%101 = load i32, i32* %8
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %111
103: ; preds = %99
%104 = load i32, i32* %10
%105 = sdiv i32 %104, 4
%106 = sub nsw i32 %105, 1
%107 = sub nsw i32 0, %106
%108 = sitofp i32 %107 to double
%109 = load double, double* %11
%110 = fmul double %108, %109
br label %113
111: ; preds = %99
%112 = load double, double* %11
br label %113
113: ; preds = %111, %103
%114 = phi double [ %110, %103 ], [ %112, %111 ]
%115 = call double %100(double %114)
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), double %115)
br label %117
117: ; preds = %113
%118 = load i32, i32* %6
%119 = add nsw i32 %118, 1
store i32 %119, i32* %6
br label %35
120: ; preds = %35
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"sin\00"
@.str.2 = [26 x i8] c"#include \22libavcodec/%s\22\0A\00"
@.str.3 = [7 x i8] c"rdft.h\00"
@.str.4 = [6 x i8] c"fft.h\00"
@.str.5 = [15 x i8] c"%s(%i) = {\0A \00"
@.str.6 = [9 x i8] c"SINTABLE\00"
@.str.7 = [9 x i8] c"COSTABLE\00"
@.str.8 = [8 x i8] c" %.18e,\00"
@.str.9 = [5 x i8] c"\0A \00"
@.str.10 = [11 x i8] c" %.18e\0A};\0A\00"
@str = [56 x i8] c"/* This file was generated by libavcodec/costablegen */\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %4
br label %10
10: ; preds = %4, %2, %9
%11 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %9 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), %2 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), %4 ]
%12 = phi i1 [ true, %9 ], [ false, %2 ], [ false, %4 ]
%13 = phi double (double)* [ @sin, %9 ], [ @cos, %2 ], [ @cos, %4 ]
%14 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), %9 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), %2 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), %4 ]
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%17 = xor i1 %12, true
br label %18
18: ; preds = %10, %56
%19 = phi i32 [ 4, %10 ], [ %60, %56 ]
%20 = shl nuw nsw i32 1, %19
%21 = sitofp i32 %20 to double
%22 = fdiv double 0x401921FB54442D18, %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %14, i32 %20)
%24 = sdiv i32 %20, 2
%25 = icmp sgt i32 %20, 3
br i1 %25, label %26, label %50
26: ; preds = %18
%27 = lshr i32 %20, 2
%28 = call i32 @llvm.smax.i32(i32 %24, i32 2)
%29 = add nsw i32 %28, -1
br label %30
30: ; preds = %26, %47
%31 = phi i32 [ 0, %26 ], [ %48, %47 ]
%32 = icmp ult i32 %27, %31
%33 = sub nsw i32 %24, %31
%34 = select i1 %32, i32 %33, i32 %31
%35 = icmp ugt i32 %27, %31
%36 = select i1 %17, i1 true, i1 %35
%37 = sub nsw i32 %27, %31
%38 = select i1 %36, i32 %34, i32 %37
%39 = sitofp i32 %38 to double
%40 = fmul double %22, %39
%41 = tail call double %13(double %40)
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), double %41)
%43 = and i32 %31, 3
%44 = icmp eq i32 %43, 3
br i1 %44, label %45, label %47
45: ; preds = %30
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %47
47: ; preds = %45, %30
%48 = add nuw nsw i32 %31, 1
%49 = icmp eq i32 %48, %29
br i1 %49, label %50, label %30
50: ; preds = %47, %18
br i1 %12, label %51, label %56
51: ; preds = %50
%52 = sdiv i32 %20, -4
%53 = add nsw i32 %52, 1
%54 = sitofp i32 %53 to double
%55 = fmul double %22, %54
br label %56
56: ; preds = %50, %51
%57 = phi double [ %55, %51 ], [ %22, %50 ]
%58 = tail call double %13(double %57)
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), double %58)
%60 = add nuw nsw i32 %19, 1
%61 = icmp eq i32 %60, 17
br i1 %61, label %62, label %18
62: ; preds = %56
ret i32 0
}