#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 */
int abs(int);
float cosf(float);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  float deg, cos_deg;
  float biggestDeltaDegree = 0;
  int fxCos;
  int lastCos = -1;
  int biggestDelta = 0;
  printf("// cos table in 1.15 fixed point format in units of %f degrees\n",
         (1.0f));
  printf("static const int NvSFx_cos_fx_table[] = {\n");
  for (deg = 0.0f; deg <= 90.0f + (0.0001f); deg += (1.0f)) {
    cos_deg = cosf((float)(deg * 3.14159265358979323846 / 180.0f));
    fxCos = (int)(cos_deg * 65536.0f + 1.5f) >> 1;
    printf("  %8d, // 0x%04x, cos(%2.f)=%f\n", fxCos, fxCos, deg, cos_deg);
    if ((biggestDelta < abs(lastCos - fxCos)) && (lastCos != -1)) {
      biggestDelta = abs(lastCos - fxCos);
      biggestDeltaDegree = deg;
    }
    lastCos = fxCos;
  }
  printf("};\n");
  printf("// biggest delta is %d [0x%x] at degree %f\n", biggestDelta,
         biggestDelta, biggestDeltaDegree);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xecc(%rip),%rdi
movsd  0xe9c(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0xe8f(%rip),%xmm0
ucomiss -0x8(%rbp),%xmm0
jb     126c <main+0x13c>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe6c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe58(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <cosf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xe4d(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe45(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
sar    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe8b(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
sub    -0x14(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    124f <main+0x11f>
cmpl   $0xffffffff,-0x18(%rbp)
je     124f <main+0x11f>
mov    -0x18(%rbp),%edi
sub    -0x14(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movss  0xdc7(%rip),%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    1181 <main+0x51>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%edx
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe27(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xee7(%rip),%rdi
movsd  0xeb7(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xf5d(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
lea    0xefb(%rip),%r14
xorps  %xmm1,%xmm1
jmp    119f <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmovne %eax,%ebx
addss  0xe95(%rip),%xmm0
movss  0xe91(%rip),%xmm1
ucomiss %xmm0,%xmm1
movaps %xmm2,%xmm1
jb     1236 <main+0x106>
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
mov    %ebp,%r15d
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  0xe48(%rip),%xmm0
divsd  0xe48(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <cosf@plt>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mulss  0xe38(%rip),%xmm0
addss  0xe34(%rip),%xmm0
cvttss2si %xmm0,%ebp
sar    %ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
movsd  0x10(%rsp),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
movss  0x8(%rsp),%xmm0
mov    %r15d,%ecx
sub    %ebp,%ecx
mov    %ecx,%eax
neg    %eax
cmovs  %ecx,%eax
cmp    %eax,%ebx
setl   %cl
cmp    $0xffffffff,%r15d
setne  %dl
movaps %xmm0,%xmm2
test   %cl,%dl
jne    1180 <main+0x50>
movss  0xc(%rsp),%xmm2
jmp    1180 <main+0x50>
lea    0xea1(%rip),%rdi
movss  %xmm2,0x8(%rsp)
call   1030 <puts@plt>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe2f(%rip),%rdi
mov    %ebx,%esi
mov    %ebx,%edx
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [64 x i8] c"// cos table in 1.15 fixed point format in units of %f degrees\0A\00"
@.str.1 = [43 x i8] c"static const int NvSFx_cos_fx_table[] = {\0A\00"
@.str.2 = [32 x i8] c" %8d, // 0x%04x, cos(%2.f)=%f\0A\00"
@.str.3 = [4 x i8] c"};\0A\00"
@.str.4 = [44 x i8] c"// biggest delta is %d [0x%x] at degree %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store float 0.000000e+00, float* %4
store i32 -1, i32* %6
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), double 1.000000e+00)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store float 0.000000e+00, float* %2
br label %10
10: ; preds = %48, %0
%11 = load float, float* %2
%12 = fcmp ole float %11, 0x40568001A0000000
br i1 %12, label %13, label %51
13: ; preds = %10
%14 = load float, float* %2
%15 = fpext float %14 to double
%16 = fmul double %15, 0x400921FB54442D18
%17 = fdiv double %16, 1.800000e+02
%18 = fptrunc double %17 to float
%19 = call float @cosf(float %18)
store float %19, float* %3
%20 = load float, float* %3
%21 = call float @llvm.fmuladd.f32(float %20, float 6.553600e+04, float 1.500000e+00)
%22 = fptosi float %21 to i32
%23 = ashr i32 %22, 1
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = load i32, i32* %5
%26 = load float, float* %2
%27 = fpext float %26 to double
%28 = load float, float* %3
%29 = fpext float %28 to double
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %25, double %27, double %29)
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = sub nsw i32 %32, %33
%35 = call i32 @abs(i32 %34)
%36 = icmp slt i32 %31, %35
br i1 %36, label %37, label %46
37: ; preds = %13
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, -1
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = load i32, i32* %6
%42 = load i32, i32* %5
%43 = sub nsw i32 %41, %42
%44 = call i32 @abs(i32 %43)
store i32 %44, i32* %7
%45 = load float, float* %2
store float %45, float* %4
br label %46
46: ; preds = %40, %37, %13
%47 = load i32, i32* %5
store i32 %47, i32* %6
br label %48
48: ; preds = %46
%49 = load float, float* %2
%50 = fadd float %49, 1.000000e+00
store float %50, float* %2
br label %10
51: ; preds = %10
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* %7
%54 = load i32, i32* %7
%55 = load float, float* %4
%56 = fpext float %55 to double
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %53, i32 %54, double %56)
ret i32 0
}

LLVM IR (-O2):
@.str = [64 x i8] c"// cos table in 1.15 fixed point format in units of %f degrees\0A\00"
@.str.2 = [32 x i8] c" %8d, // 0x%04x, cos(%2.f)=%f\0A\00"
@.str.4 = [44 x i8] c"// biggest delta is %d [0x%x] at degree %f\0A\00"
@str = [42 x i8] c"static const int NvSFx_cos_fx_table[] = {\00"
@str.5 = [3 x i8] c"};\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), double 1.000000e+00)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 0, %0 ], [ %24, %3 ]
%5 = phi i32 [ -1, %0 ], [ %15, %3 ]
%6 = phi float [ 0.000000e+00, %0 ], [ %25, %3 ]
%7 = phi float [ 0.000000e+00, %0 ], [ %23, %3 ]
%8 = fpext float %6 to double
%9 = fmul double %8, 0x400921FB54442D18
%10 = fdiv double %9, 1.800000e+02
%11 = fptrunc double %10 to float
%12 = tail call float @cosf(float %11)
%13 = tail call float @llvm.fmuladd.f32(float %12, float 6.553600e+04, float 1.500000e+00)
%14 = fptosi float %13 to i32
%15 = ashr i32 %14, 1
%16 = fpext float %12 to double
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %15, double %8, double %16)
%18 = sub nsw i32 %5, %15
%19 = tail call i32 @llvm.abs.i32(i32 %18, i1 true)
%20 = icmp slt i32 %4, %19
%21 = icmp ne i32 %5, -1
%22 = and i1 %21, %20
%23 = select i1 %22, float %6, float %7
%24 = select i1 %22, i32 %19, i32 %4
%25 = fadd float %6, 1.000000e+00
%26 = fcmp ugt float %25, 0x40568001A0000000
br i1 %26, label %27, label %3
27: ; preds = %3
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
%29 = fpext float %23 to double
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %24, i32 %24, double %29)
ret i32 0
}