#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;
float cos(double);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int main(int argc, char *argv[]) {
  int i;
  FILE *fi, *ff;
  float f;
  if (!(fi = fopen("costabi.c", "w")))
    exit(1);
  if (!(ff = fopen("costabf.c", "w")))
    exit(1);
  fprintf(fi,
          "/*\n * This file is machine generated, DO NOT EDIT!\n */\n\n"
          "extern const int costabi[0x%x] = {",
          0x400);
  fprintf(ff,
          "/*\n * This file is machine generated, DO NOT EDIT!\n */\n\n"
          "extern const float costabf[0x%x] = {",
          0x400);
  for (i = 0; i < 0x400; i++) {
    if ((i & 3) == 0)
      fprintf(ff, "\n\t");
    if ((i & 7) == 0)
      fprintf(fi, "\n\t");
    f = cos(M_PI * 2.0 * i / 0x400);
    fprintf(ff, "%12.9f", f);
    fprintf(fi, "%6i", (int)(32767.0 * f));
    if (i < 0x400 - 1) {
      fprintf(ff, ", ");
      fprintf(fi, ", ");
    }
  }
  fprintf(ff, "\n};\n");
  fprintf(fi, "\n};\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xebb(%rip),%rdi
lea    0xebe(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1181 <main+0x41>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe9c(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ac <main+0x6c>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xebb(%rip),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
jge    12ec <main+0x1ac>
mov    -0x14(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    120f <main+0xcf>
mov    -0x28(%rbp),%rdi
lea    0xede(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    1230 <main+0xf0>
mov    -0x20(%rbp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movsd  0xdd8(%rip),%xmm0
mov    0x2da9(%rip),%rax
mulsd  (%rax),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb4(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movss  %xmm0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe73(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rdi
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd6e(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpl   $0x3ff,-0x14(%rbp)
jge    12d9 <main+0x199>
mov    -0x28(%rbp),%rdi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12de <main+0x19e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e1 <main+0xa1>
mov    -0x28(%rbp),%rdi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb3(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1191 <main+0x41>
mov    %rax,%r14
lea    0xea4(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
jne    119b <main+0x4b>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %rax,%rbx
lea    0xe89(%rip),%rsi
mov    %r14,%rdi
mov    $0x400,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xece(%rip),%rsi
mov    %rbx,%rdi
mov    $0x400,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
xorpd  %xmm1,%xmm1
lea    0xf14(%rip),%r12
lea    0xf14(%rip),%r13
lea    0xf11(%rip),%rbp
xor    %r15d,%r15d
jmp    1213 <main+0xc3>
nopl   0x0(%rax,%rax,1)
movsd  0x8(%rsp),%xmm0
addsd  0xe12(%rip),%xmm0
add    $0x1,%r15d
cmp    $0x400,%r15d
movapd %xmm0,%xmm1
je     130d <main+0x1bd>
test   $0x3,%r15b
movsd  %xmm1,0x8(%rsp)
je     12c0 <main+0x170>
test   $0x7,%r15b
je     12e9 <main+0x199>
mov    0x2db4(%rip),%rax
movsd  (%rax),%xmm0
addsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0xdb8(%rip),%xmm0
call   1040 <cos@plt>
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
movsd  0x10(%rsp),%xmm0
mulsd  0xd96(%rip),%xmm0
cvttsd2si %xmm0,%edx
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0x3fe,%r15d
ja     11f0 <main+0xa0>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r14,%rcx
call   1070 <fwrite@plt>
jmp    11f0 <main+0xa0>
nop
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe15(%rip),%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
movsd  0x8(%rsp),%xmm1
test   $0x7,%r15b
jne    122d <main+0xdd>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xdec(%rip),%rdi
mov    %r14,%rcx
call   1070 <fwrite@plt>
movsd  0x8(%rsp),%xmm1
jmp    122d <main+0xdd>
lea    0xde3(%rip),%rbp
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
mov    %r14,%rcx
call   1070 <fwrite@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"costabi.c\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [10 x i8] c"costabf.c\00"
@.str.3 = [91 x i8] c"/*\0A * This file is machine generated, DO NOT EDIT!\0A */\0A\0Aextern const int costabi[0x%x] = {\00"
@.str.4 = [93 x i8] c"/*\0A * This file is machine generated, DO NOT EDIT!\0A */\0A\0Aextern const float costabf[0x%x] = {\00"
@.str.5 = [3 x i8] c"\0A\09\00"
@M_PI = global double 0.000000e+00
@.str.6 = [7 x i8] c"%12.9f\00"
@.str.7 = [4 x i8] c"%6i\00"
@.str.8 = [3 x i8] c", \00"
@.str.9 = [5 x i8] c"\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 float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %14
%20 = load i32*, i32** %7
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.3, i64 0, i64 0), i32 1024)
%22 = load i32*, i32** %8
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.4, i64 0, i64 0), i32 1024)
store i32 0, i32* %6
br label %24
24: ; preds = %67, %19
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 1024
br i1 %26, label %27, label %70
27: ; preds = %24
%28 = load i32, i32* %6
%29 = and i32 %28, 3
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32*, i32** %8
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %31, %27
%35 = load i32, i32* %6
%36 = and i32 %35, 7
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32*, i32** %7
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %38, %34
%42 = load double, double* @M_PI
%43 = fmul double %42, 2.000000e+00
%44 = load i32, i32* %6
%45 = sitofp i32 %44 to double
%46 = fmul double %43, %45
%47 = fdiv double %46, 1.024000e+03
%48 = call float @cos(double %47)
store float %48, float* %9
%49 = load i32*, i32** %8
%50 = load float, float* %9
%51 = fpext float %50 to double
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), double %51)
%53 = load i32*, i32** %7
%54 = load float, float* %9
%55 = fpext float %54 to double
%56 = fmul double 3.276700e+04, %55
%57 = fptosi double %56 to i32
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %6
%60 = icmp slt i32 %59, 1023
br i1 %60, label %61, label %66
61: ; preds = %41
%62 = load i32*, i32** %8
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%64 = load i32*, i32** %7
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
br label %66
66: ; preds = %61, %41
br label %67
67: ; preds = %66
%68 = load i32, i32* %6
%69 = add nsw i32 %68, 1
store i32 %69, i32* %6
br label %24
70: ; preds = %24
%71 = load i32*, i32** %8
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%73 = load i32*, i32** %7
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%75 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"costabi.c\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [10 x i8] c"costabf.c\00"
@.str.3 = [91 x i8] c"/*\0A * This file is machine generated, DO NOT EDIT!\0A */\0A\0Aextern const int costabi[0x%x] = {\00"
@.str.4 = [93 x i8] c"/*\0A * This file is machine generated, DO NOT EDIT!\0A */\0A\0Aextern const float costabf[0x%x] = {\00"
@.str.5 = [3 x i8] c"\0A\09\00"
@M_PI = global double 0.000000e+00
@.str.6 = [7 x i8] c"%12.9f\00"
@.str.7 = [4 x i8] c"%6i\00"
@.str.8 = [3 x i8] c", \00"
@.str.9 = [5 x i8] c"\0A};\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %7
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.3, i64 0, i64 0), i32 1024)
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.4, i64 0, i64 0), i32 1024)
br label %15
15: ; preds = %12, %42
%16 = phi i32 [ 0, %12 ], [ %43, %42 ]
%17 = and i32 %16, 3
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %8)
br label %21
21: ; preds = %19, %15
%22 = and i32 %16, 7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %3)
br label %26
26: ; preds = %24, %21
%27 = load double, double* @M_PI
%28 = fmul double %27, 2.000000e+00
%29 = sitofp i32 %16 to double
%30 = fmul double %28, %29
%31 = fmul double %30, 0x3F50000000000000
%32 = tail call float @cos(double %31)
%33 = fpext float %32 to double
%34 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), double %33)
%35 = fmul double %33, 3.276700e+04
%36 = fptosi double %35 to i32
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %36)
%38 = icmp ult i32 %16, 1023
br i1 %38, label %39, label %42
39: ; preds = %26
%40 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i64 2, i64 1, i32* %8)
%41 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i64 2, i64 1, i32* %3)
br label %42
42: ; preds = %26, %39
%43 = add nuw nsw i32 %16, 1
%44 = icmp eq i32 %43, 1024
br i1 %44, label %45, label %15
45: ; preds = %42
%46 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i64 4, i64 1, i32* %8)
%47 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i64 4, i64 1, i32* %3)
%48 = tail call i32 @exit(i32 0)
unreachable
}