#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 */
double M_PI;
int cos(unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void gencos(FILE *f) {
  unsigned int i;
  fprintf(f, "static const short costab[%u] = {", (1 << (9)));
  for (i = 0;; i++) {
    if (!(i & 7))
      fprintf(f, "\n\t");
    fprintf(f, "%6d", (int)(32767 * cos(i * (2.0 * M_PI / (1 << (9))))));
    if (i >= (1 << (9)) - 1)
      break;
    fprintf(f, ", ");
  }
  fprintf(f,
          "\n};\n\n#define COS(x) (costab[(((x)>>%u)&0x%x)])\n#define SIN(x) "
          "COS((x)+0xc000)\n\n",
          16 - 9, (1 << (9)) - 1);
}


x86 assembly (clang, -O0):
<gencos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed1(%rip),%rsi
mov    $0x200,%edx
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    116b <gencos+0x4b>
mov    -0x8(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm0
mov    0x2e66(%rip),%rax
movsd  (%rax),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe6e(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%edi
call   1040 <cos@plt>
mov    -0x18(%rbp),%rdi
imul   $0x7fff,%eax,%edx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpl   $0x1ff,-0xc(%rbp)
jb     11d0 <gencos+0xb0>
jmp    11f0 <gencos+0xd0>
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <gencos+0x2a>
mov    -0x8(%rbp),%rdi
lea    0xe39(%rip),%rsi
mov    $0x7,%edx
mov    $0x1ff,%ecx
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gencos>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xecb(%rip),%rsi
mov    $0x200,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
xorpd  %xmm1,%xmm1
lea    0xed6(%rip),%r14
mov    0x2e85(%rip),%r13
lea    0xecb(%rip),%r15
lea    0xec8(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   $0x7,%bpl
movsd  %xmm1,(%rsp)
jne    11a5 <gencos+0x75>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
movsd  (%rsp),%xmm1
movsd  0x0(%r13),%xmm0
addsd  %xmm0,%xmm0
mulsd  0xe49(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <cos@plt>
mov    %eax,%edx
shl    $0xf,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0x1ff,%ebp
je     120f <gencos+0xdf>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
movsd  (%rsp),%xmm0
addsd  0xe05(%rip),%xmm0
add    $0x1,%ebp
movapd %xmm0,%xmm1
jmp    1180 <gencos+0x50>
lea    0xe26(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
mov    $0x1ff,%ecx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"static const short costab[%u] = {\00"
@.str.1 = [3 x i8] c"\0A\09\00"
@.str.2 = [4 x i8] c"%6d\00"
@M_PI = global double 0.000000e+00
@.str.3 = [3 x i8] c", \00"
@.str.4 = [80 x i8] c"\0A};\0A\0A#define COS(x) (costab[(((x)>>%u)&0x%x)])\0A#define SIN(x) COS((x)+0xc000)\0A\0A\00"
define void @gencos(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 512)
store i32 0, i32* %3
br label %6
6: ; preds = %31, %1
%7 = load i32, i32* %3
%8 = and i32 %7, 7
%9 = icmp ne i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i32*, i32** %2
%12 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %6
%14 = load i32*, i32** %2
%15 = load i32, i32* %3
%16 = uitofp i32 %15 to double
%17 = load double, double* @M_PI
%18 = fmul double 2.000000e+00, %17
%19 = fdiv double %18, 5.120000e+02
%20 = fmul double %16, %19
%21 = fptoui double %20 to i32
%22 = call i32 @cos(i32 %21)
%23 = mul nsw i32 32767, %22
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %3
%26 = icmp uge i32 %25, 511
br i1 %26, label %27, label %28
27: ; preds = %13
br label %34
28: ; preds = %13
%29 = load i32*, i32** %2
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %28
%32 = load i32, i32* %3
%33 = add i32 %32, 1
store i32 %33, i32* %3
br label %6
34: ; preds = %27
%35 = load i32*, i32** %2
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.4, i64 0, i64 0), i32 7, i32 511)
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"static const short costab[%u] = {\00"
@.str.1 = [3 x i8] c"\0A\09\00"
@.str.2 = [4 x i8] c"%6d\00"
@M_PI = global double 0.000000e+00
@.str.3 = [3 x i8] c", \00"
@.str.4 = [80 x i8] c"\0A};\0A\0A#define COS(x) (costab[(((x)>>%u)&0x%x)])\0A#define SIN(x) COS((x)+0xc000)\0A\0A\00"
define void @gencos(i32* nocapture %0) {
%2 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 512)
br label %3
3: ; preds = %20, %1
%4 = phi i32 [ 0, %1 ], [ %22, %20 ]
%5 = and i32 %4, 7
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = 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 %9
9: ; preds = %7, %3
%10 = uitofp i32 %4 to double
%11 = load double, double* @M_PI
%12 = fmul double %11, 2.000000e+00
%13 = fmul double %12, 0x3F60000000000000
%14 = fmul double %13, %10
%15 = fptoui double %14 to i32
%16 = tail call i32 @cos(i32 %15)
%17 = mul nsw i32 %16, 32767
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = icmp eq i32 %4, 511
br i1 %19, label %23, label %20
20: ; preds = %9
%21 = 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)
%22 = add nuw nsw i32 %4, 1
br label %3
23: ; preds = %9
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.4, i64 0, i64 0), i32 7, i32 511)
ret void
}