#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 */
float cos(float);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  float pos = 0;
  float incr = (3.1415926535897932384626433832795028 * .5) / 128;
  float out = 0;
  int dif;
  int final;
  float data[128];
  int i = 0;
  printf(" uint16_t cos_table[] = {\r\n");
  while (i < 128) {
    out = cos(pos);
    data[i] = out;
    i++;
    pos = pos + incr;
    final = 30000.0 * out;
    printf("%i, \r\n", final);
  }
  printf("0\r\n};\r\n");
  i = 0;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  0xebe(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x224(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x80,-0x224(%rbp)
jge    11eb <main+0xcb>
movss  -0x8(%rbp),%xmm0
call   1040 <cos@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
movslq -0x224(%rbp),%rax
movss  %xmm0,-0x220(%rbp,%rax,4)
ff ff
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe3e(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1167 <main+0x47>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x224(%rbp)
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
xorpd  %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
mov    $0x80,%ebp
lea    0xebb(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movss  0x4(%rsp),%xmm0
call   1050 <cos@plt>
movss  0x4(%rsp),%xmm1
addss  0xe87(%rip),%xmm1
movss  %xmm1,0x4(%rsp)
cvtss2sd %xmm0,%xmm0
mulsd  0xe7d(%rip),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1160 <main+0x30>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c" uint16_t cos_table[] = {\0D\0A\00"
@.str.1 = [7 x i8] c"%i, \0D\0A\00"
@.str.2 = [8 x i8] c"0\0D\0A};\0D\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 [128 x float]
%8 = alloca i32
store i32 0, i32* %1
store float 0.000000e+00, float* %2
store float 0x3F8921FB60000000, float* %3
store float 0.000000e+00, float* %4
store i32 0, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 128
br i1 %12, label %13, label %31
13: ; preds = %10
%14 = load float, float* %2
%15 = call float @cos(float %14)
store float %15, float* %4
%16 = load float, float* %4
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [128 x float], [128 x float]* %7, i64 0, i64 %18
store float %16, float* %19
%20 = load i32, i32* %8
%21 = add nsw i32 %20, 1
store i32 %21, i32* %8
%22 = load float, float* %2
%23 = load float, float* %3
%24 = fadd float %22, %23
store float %24, float* %2
%25 = load float, float* %4
%26 = fpext float %25 to double
%27 = fmul double 3.000000e+04, %26
%28 = fptosi double %27 to i32
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %10
31: ; preds = %10
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%i, \0D\0A\00"
@str = [27 x i8] c" uint16_t cos_table[] = {\0D\00"
@str.3 = [7 x i8] c"0\0D\0A};\0D\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %6, %2 ]
%4 = phi float [ 0.000000e+00, %0 ], [ %7, %2 ]
%5 = tail call float @cos(float %4)
%6 = add nuw nsw i32 %3, 1
%7 = fadd float %4, 0x3F8921FB60000000
%8 = fpext float %5 to double
%9 = fmul double %8, 3.000000e+04
%10 = fptosi double %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %6, 128
br i1 %12, label %13, label %2
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}