#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;
int atan(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void gentbl_atantab(FILE *f) {
  int i;
  short x;
  fprintf(
      f,
      "\n/*\n"
      " * arctan table (indexed by i/q; should really be indexed by i/(i+q)\n"
      " */\n"
      "#define ATAN_TABLEN %d\n\n"
      "static const unsigned short atan_tab[ATAN_TABLEN+2] = {",
      1024);
  for (i = 0; i <= 1024; i++) {
    if (!(i & 7))
      fprintf(f, "\n\t");
    x = atan(i / (float)1024) / M_PI * 0x8000;
    fprintf(f, "%6d, ", x);
  }
  fprintf(f, "%6d\n};\n\n", x);
}


x86 assembly (clang, -O0):
<gentbl_atantab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xecd(%rip),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x400,-0xc(%rbp)
jg     11c7 <gentbl_atantab+0xa7>
mov    -0xc(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    1178 <gentbl_atantab+0x58>
mov    -0x8(%rbp),%rdi
lea    0xf30(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cvtsi2ssl -0xc(%rbp),%xmm0
movss  0xe7b(%rip),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%edi
call   1040 <atan@plt>
mov    0x2e4f(%rip),%rcx
cltd
idivl  (%rcx)
shl    $0xf,%eax
mov    %ax,-0xe(%rbp)
mov    -0x8(%rbp),%rdi
movswl -0xe(%rbp),%edx
lea    0xef2(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114a <gentbl_atantab+0x2a>
mov    -0x8(%rbp),%rdi
movswl -0xe(%rbp),%edx
lea    0xed4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gentbl_atantab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
lea    0xebf(%rip),%rsi
mov    $0x400,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xf49(%rip),%r14
mov    0x2e89(%rip),%r12
lea    0xf3e(%rip),%r15
xor    %ebx,%ebx
jmp    11ad <gentbl_atantab+0x7d>
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  0xe81(%rip),%xmm0
cvttss2si %xmm0,%edi
call   1040 <atan@plt>
cltd
idivl  (%r12)
mov    %eax,%ebp
shl    $0xf,%eax
movswl %ax,%edx
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%ebx
cmp    $0x401,%ebx
je     11c9 <gentbl_atantab+0x99>
test   $0x7,%bl
jne    1170 <gentbl_atantab+0x40>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rdi
mov    %r13,%rcx
call   1050 <fwrite@plt>
jmp    1170 <gentbl_atantab+0x40>
shl    $0x1f,%ebp
sar    $0x10,%ebp
lea    0xed4(%rip),%rsi
mov    %r13,%rdi
mov    %ebp,%edx
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 = [157 x i8] c"\0A/*\0A * arctan table (indexed by i/q; should really be indexed by i/(i+q)\0A */\0A#define ATAN_TABLEN %d\0A\0Astatic const unsigned short atan_tab[ATAN_TABLEN+2] = {\00"
@.str.1 = [3 x i8] c"\0A\09\00"
@M_PI = global i32 0
@.str.2 = [6 x i8] c"%6d, \00"
@.str.3 = [9 x i8] c"%6d\0A};\0A\0A\00"
define void @gentbl_atantab(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i16
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i32 1024)
store i32 0, i32* %3
br label %7
7: ; preds = %31, %1
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 1024
br i1 %9, label %10, label %34
10: ; preds = %7
%11 = load i32, i32* %3
%12 = and i32 %11, 7
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = load i32*, i32** %2
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %14, %10
%18 = load i32, i32* %3
%19 = sitofp i32 %18 to float
%20 = fdiv float %19, 1.024000e+03
%21 = fptosi float %20 to i32
%22 = call i32 @atan(i32 %21)
%23 = load i32, i32* @M_PI
%24 = sdiv i32 %22, %23
%25 = mul nsw i32 %24, 32768
%26 = trunc i32 %25 to i16
store i16 %26, i16* %4
%27 = load i32*, i32** %2
%28 = load i16, i16* %4
%29 = sext i16 %28 to i32
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %17
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %7
34: ; preds = %7
%35 = load i32*, i32** %2
%36 = load i16, i16* %4
%37 = sext i16 %36 to i32
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %37)
ret void
}

LLVM IR (-O2):
@.str = [157 x i8] c"\0A/*\0A * arctan table (indexed by i/q; should really be indexed by i/(i+q)\0A */\0A#define ATAN_TABLEN %d\0A\0Astatic const unsigned short atan_tab[ATAN_TABLEN+2] = {\00"
@.str.1 = [3 x i8] c"\0A\09\00"
@M_PI = global i32 0
@.str.2 = [6 x i8] c"%6d, \00"
@.str.3 = [9 x i8] c"%6d\0A};\0A\0A\00"
define void @gentbl_atantab(i32* nocapture %0) {
%2 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i32 1024)
br label %3
3: ; preds = %1, %9
%4 = phi i32 [ 0, %1 ], [ %20, %9 ]
%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 = sitofp i32 %4 to float
%11 = fmul float %10, 0x3F50000000000000
%12 = fptosi float %11 to i32
%13 = tail call i32 @atan(i32 %12)
%14 = load i32, i32* @M_PI
%15 = sdiv i32 %13, %14
%16 = trunc i32 %15 to i16
%17 = shl i16 %16, 15
%18 = sext i16 %17 to i32
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = add nuw nsw i32 %4, 1
%21 = icmp eq i32 %20, 1025
br i1 %21, label %22, label %3
22: ; preds = %9
%23 = shl i32 %15, 31
%24 = ashr exact i32 %23, 16
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %24)
ret void
}