#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/dsputil.h\"\n");
  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>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x4,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jg     135d <main+0x23d>
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xe2e(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x1c(%rbp),%ecx
lea    0xe99(%rip),%rsi
lea    0xe89(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x2c(%rbp),%edx
lea    0xe69(%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    12f3 <main+0x1d3>
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    1260 <main+0x140>
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    -0x18(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    1266 <main+0x146>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12a5 <main+0x185>
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     12a5 <main+0x185>
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    0xdcb(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
and    $0x3,%eax
cmp    $0x3,%eax
jne    12e0 <main+0x1c0>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12e5 <main+0x1c5>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    120b <main+0xeb>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     132c <main+0x20c>
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    1336 <main+0x216>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x58(%rbp),%rax
movsd  -0x60(%rbp),%xmm0
call   *%rax
lea    0xd47(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ae <main+0x8e>
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
cmp    $0x2,%edi
jne    1163 <main+0x33>
mov    0x8(%rsi),%rdi
lea    0xeba(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
sete   %bl
jne    1173 <main+0x43>
mov    0x2e7f(%rip),%rax
jmp    117a <main+0x4a>
mov    0x2e7e(%rip),%rax
mov    %rax,0x10(%rsp)
xor    %ebx,%ebx
jmp    117f <main+0x4f>
mov    0x2e6e(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7d(%rip),%rax
lea    0xe7f(%rip),%rcx
test   %bl,%bl
cmovne %rax,%rcx
mov    %rcx,0x30(%rsp)
mov    %ebx,%r15d
xor    $0x1,%r15b
mov    $0x4,%ebp
mov    %ebx,0x24(%rsp)
jmp    121e <main+0xee>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x28(%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),%ebp
call   *0x10(%rsp)
lea    0xe2a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    $0x11,%ebp
je     131b <main+0x1eb>
mov    $0x1,%ebx
mov    %ebp,0xc(%rsp)
mov    %ebp,%ecx
shl    %cl,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xdc6(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
lea    0xdc1(%rip),%rdi
mov    0x30(%rsp),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,0x28(%rsp)
cmp    $0x4,%ebx
jl     1300 <main+0x1d0>
mov    0x28(%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    0xd50(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r14d,%eax
not    %eax
test   $0x3,%al
jne    12a0 <main+0x170>
lea    0xd22(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12a0 <main+0x170>
nopl   (%rax)
mov    0x24(%rsp),%ebx
test   %bl,%bl
jne    11d0 <main+0xa0>
mov    0xc(%rsp),%ebp
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 = [33 x i8] c"#include \22libavcodec/dsputil.h\22\0A\00"
@.str.3 = [15 x i8] c"%s(%i) = {\0A \00"
@.str.4 = [9 x i8] c"SINTABLE\00"
@.str.5 = [9 x i8] c"COSTABLE\00"
@.str.6 = [8 x i8] c" %.18e,\00"
@.str.7 = [5 x i8] c"\0A \00"
@.str.8 = [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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 4, i32* %6
br label %31
31: ; preds = %113, %22
%32 = load i32, i32* %6
%33 = icmp sle i32 %32, 16
br i1 %33, label %34, label %116
34: ; preds = %31
%35 = load i32, i32* %6
%36 = shl i32 1, %35
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = sitofp i32 %37 to double
%39 = fdiv double 0x401921FB54442D18, %38
store double %39, double* %11
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 0
%42 = zext i1 %41 to i64
%43 = select i1 %41, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0)
%44 = load i32, i32* %10
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %43, i32 %44)
store i32 0, i32* %7
br label %46
46: ; preds = %92, %34
%47 = load i32, i32* %7
%48 = load i32, i32* %10
%49 = sdiv i32 %48, 2
%50 = sub nsw i32 %49, 1
%51 = icmp slt i32 %47, %50
br i1 %51, label %52, label %95
52: ; preds = %46
%53 = load i32, i32* %7
%54 = load i32, i32* %10
%55 = sdiv i32 %54, 4
%56 = icmp sgt i32 %53, %55
br i1 %56, label %57, label %62
57: ; preds = %52
%58 = load i32, i32* %10
%59 = sdiv i32 %58, 2
%60 = load i32, i32* %7
%61 = sub nsw i32 %59, %60
br label %64
62: ; preds = %52
%63 = load i32, i32* %7
br label %64
64: ; preds = %62, %57
%65 = phi i32 [ %61, %57 ], [ %63, %62 ]
store i32 %65, i32* %12
%66 = load i32, i32* %8
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %78
68: ; preds = %64
%69 = load i32, i32* %7
%70 = load i32, i32* %10
%71 = sdiv i32 %70, 4
%72 = icmp sge i32 %69, %71
br i1 %72, label %73, label %78
73: ; preds = %68
%74 = load i32, i32* %10
%75 = sdiv i32 %74, 4
%76 = load i32, i32* %7
%77 = sub nsw i32 %75, %76
store i32 %77, i32* %12
br label %78
78: ; preds = %73, %68, %64
%79 = load double (double)*, double (double)** %9
%80 = load i32, i32* %12
%81 = sitofp i32 %80 to double
%82 = load double, double* %11
%83 = fmul double %81, %82
%84 = call double %79(double %83)
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), double %84)
%86 = load i32, i32* %7
%87 = and i32 %86, 3
%88 = icmp eq i32 %87, 3
br i1 %88, label %89, label %91
89: ; preds = %78
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %91
91: ; preds = %89, %78
br label %92
92: ; preds = %91
%93 = load i32, i32* %7
%94 = add nsw i32 %93, 1
store i32 %94, i32* %7
br label %46
95: ; preds = %46
%96 = load double (double)*, double (double)** %9
%97 = load i32, i32* %8
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %107
99: ; preds = %95
%100 = load i32, i32* %10
%101 = sdiv i32 %100, 4
%102 = sub nsw i32 %101, 1
%103 = sub nsw i32 0, %102
%104 = sitofp i32 %103 to double
%105 = load double, double* %11
%106 = fmul double %104, %105
br label %109
107: ; preds = %95
%108 = load double, double* %11
br label %109
109: ; preds = %107, %99
%110 = phi double [ %106, %99 ], [ %108, %107 ]
%111 = call double %96(double %110)
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), double %111)
br label %113
113: ; preds = %109
%114 = load i32, i32* %6
%115 = add nsw i32 %114, 1
store i32 %115, i32* %6
br label %31
116: ; preds = %31
ret i32 0
}

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