#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int M_PI;
double cos(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void gentbl_costab(FILE *f, unsigned int nbits) {
  int i;
  fprintf(f,
          "\n/*\n * more accurate cosine table\n */\n\n"
          "static const short costab[%d] = {",
          (1 << nbits));
  for (i = 0; i < (1 << nbits); i++) {
    if (!(i & 7))
      fprintf(f, "\n\t");
    fprintf(f, "%6d", (int)(32767.0 * cos(i * 2.0 * M_PI / (1 << nbits))));
    if (i != ((1 << nbits) - 1))
      fprintf(f, ", ");
  }
  fprintf(f,
          "\n};\n\n#define COS(x) costab[((x)>>%d)&0x%x]\n"
          "#define SIN(x) COS((x)+0xc000)\n\n",
          16 - nbits, (1 << nbits) - 1);
}


x86 assembly (clang, -O0):
<gentbl_costab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
lea    0xecc(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jge    1231 <gentbl_costab+0x111>
mov    -0x10(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    118a <gentbl_costab+0x6a>
mov    -0x8(%rbp),%rdi
lea    0xed6(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xe69(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e3e(%rip),%rax
cvtsi2sdl (%rax),%xmm1
mulsd  %xmm1,%xmm0
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
mov    -0x18(%rbp),%rdi
movaps %xmm0,%xmm1
movsd  0xe24(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     121e <gentbl_costab+0xfe>
mov    -0x8(%rbp),%rdi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1223 <gentbl_costab+0x103>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1152 <gentbl_costab+0x32>
mov    -0x8(%rbp),%rdi
mov    $0x10,%edx
sub    -0xc(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
sub    $0x1,%ecx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gentbl_costab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r12d
mov    %rdi,%rbx
mov    $0x1,%r14d
mov    $0x1,%r15d
mov    %r12d,%ecx
shl    %cl,%r15d
lea    0xeb3(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0x1f,%r12d
jne    1179 <gentbl_costab+0x49>
add    $0xffffffff,%r15d
mov    %r15d,%ebp
jmp    125a <gentbl_costab+0x12a>
mov    %r12d,0x4(%rsp)
cvtsi2sd %r15d,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    -0x1(%r15),%ebp
cmp    $0x2,%r15d
cmovge %r15d,%r14d
xorpd  %xmm0,%xmm0
mov    0x2e48(%rip),%r15
lea    0xeb5(%rip),%r12
xor    %r13d,%r13d
jmp    11cb <gentbl_costab+0x9b>
nopl   0x0(%rax)
movsd  0x8(%rsp),%xmm0
addsd  0xe4a(%rip),%xmm0
add    $0x1,%r13d
cmp    %r13d,%r14d
je     1255 <gentbl_costab+0x125>
test   $0x7,%r13b
movsd  %xmm0,0x8(%rsp)
jne    11f6 <gentbl_costab+0xc6>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe71(%rip),%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl (%r15),%xmm1
mulsd  %xmm0,%xmm1
divsd  0x10(%rsp),%xmm1
cvttsd2si %xmm1,%edi
call   1040 <cos@plt>
mulsd  0xde3(%rip),%xmm0
cvttsd2si %xmm0,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    %r13d,%ebp
je     11b0 <gentbl_costab+0x80>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe18(%rip),%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
jmp    11b0 <gentbl_costab+0x80>
mov    0x4(%rsp),%r12d
mov    $0x10,%edx
sub    %r12d,%edx
lea    0xdfa(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%ecx
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@.str = [73 x i8] c"\0A/*\0A * more accurate cosine table\0A */\0A\0Astatic const short costab[%d] = {\00"
@.str.1 = [3 x i8] c"\0A\09\00"
@.str.2 = [4 x i8] c"%6d\00"
@M_PI = global i32 0
@.str.3 = [3 x i8] c", \00"
@.str.4 = [76 x i8] c"\0A};\0A\0A#define COS(x) costab[((x)>>%d)&0x%x]\0A#define SIN(x) COS((x)+0xc000)\0A\0A\00"
define void @gentbl_costab(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32*, i32** %3
%7 = load i32, i32* %4
%8 = shl i32 1, %7
%9 = call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 0, i32* %5
br label %10
10: ; preds = %48, %2
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = shl i32 1, %12
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %51
15: ; preds = %10
%16 = load i32, i32* %5
%17 = and i32 %16, 7
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32*, i32** %3
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %15
%23 = load i32*, i32** %3
%24 = load i32, i32* %5
%25 = sitofp i32 %24 to double
%26 = fmul double %25, 2.000000e+00
%27 = load i32, i32* @M_PI
%28 = sitofp i32 %27 to double
%29 = fmul double %26, %28
%30 = load i32, i32* %4
%31 = shl i32 1, %30
%32 = sitofp i32 %31 to double
%33 = fdiv double %29, %32
%34 = fptosi double %33 to i32
%35 = call double @cos(i32 %34)
%36 = fmul double 3.276700e+04, %35
%37 = fptosi double %36 to i32
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %5
%40 = load i32, i32* %4
%41 = shl i32 1, %40
%42 = sub nsw i32 %41, 1
%43 = icmp ne i32 %39, %42
br i1 %43, label %44, label %47
44: ; preds = %22
%45 = load i32*, i32** %3
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %44, %22
br label %48
48: ; preds = %47
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %10
51: ; preds = %10
%52 = load i32*, i32** %3
%53 = load i32, i32* %4
%54 = sub i32 16, %53
%55 = load i32, i32* %4
%56 = shl i32 1, %55
%57 = sub nsw i32 %56, 1
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.4, i64 0, i64 0), i32 %54, i32 %57)
ret void
}

LLVM IR (-O2):
@.str = [73 x i8] c"\0A/*\0A * more accurate cosine table\0A */\0A\0Astatic const short costab[%d] = {\00"
@.str.1 = [3 x i8] c"\0A\09\00"
@.str.2 = [4 x i8] c"%6d\00"
@M_PI = global i32 0
@.str.3 = [3 x i8] c", \00"
@.str.4 = [76 x i8] c"\0A};\0A\0A#define COS(x) costab[((x)>>%d)&0x%x]\0A#define SIN(x) COS((x)+0xc000)\0A\0A\00"
define void @gentbl_costab(i32* nocapture %0, i32 %1) {
%3 = shl nuw i32 1, %1
%4 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %1, 31
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = add nsw i32 %3, -1
br label %36
8: ; preds = %2
%9 = sitofp i32 %3 to double
%10 = add nsw i32 %3, -1
%11 = call i32 @llvm.smax.i32(i32 %3, i32 1)
br label %12
12: ; preds = %8, %33
%13 = phi i32 [ 0, %8 ], [ %34, %33 ]
%14 = and i32 %13, 7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %18
18: ; preds = %16, %12
%19 = sitofp i32 %13 to double
%20 = fmul double %19, 2.000000e+00
%21 = load i32, i32* @M_PI
%22 = sitofp i32 %21 to double
%23 = fmul double %20, %22
%24 = fdiv double %23, %9
%25 = fptosi double %24 to i32
%26 = tail call double @cos(i32 %25)
%27 = fmul double %26, 3.276700e+04
%28 = fptosi double %27 to i32
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = icmp eq i32 %13, %10
br i1 %30, label %33, label %31
31: ; preds = %18
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %33
33: ; preds = %18, %31
%34 = add nuw nsw i32 %13, 1
%35 = icmp eq i32 %34, %11
br i1 %35, label %36, label %12
36: ; preds = %33, %6
%37 = phi i32 [ %7, %6 ], [ %10, %33 ]
%38 = sub i32 16, %1
%39 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.4, i64 0, i64 0), i32 %38, i32 %37)
ret void
}