#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 M_PI;
int /*<<< orphan*/ printf(char *, ...);
float sin(float);
void generate_sin_table(void) {
  int i;
  float v, k;
  printf("#include <stdint.h>\n");
  printf("#include <avr/pgmspace.h>\n");
  printf("#define NUM_SIN_TABLE_ENTRIES %d\n", 1000);
  printf("const PROGMEM int16_t sin_table[NUM_SIN_TABLE_ENTRIES] = {\n    ");
  for (i = 0; i < 1000; i++) {
    k = (float)i / 1000 * 2.0 * M_PI;
    v = sin(k);
    printf("%5d", (int)(v * 1000));
    if (i < 1000 - 1)
      printf(",");
    if (i && i % 20 == 0)
      printf("\n    ");
  }
  printf("\n};\n");
}


x86 assembly (clang, -O0):
<generate_sin_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef5(%rip),%rdi
mov    $0x3e8,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jge    123e <generate_sin_table+0x11e>
cvtsi2ssl -0x4(%rbp),%xmm0
movss  0xe7a(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe72(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e47(%rip),%rax
movss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,-0x8(%rbp)
movss  0xe33(%rip),%xmm0
mulss  -0x8(%rbp),%xmm0
cvttss2si %xmm0,%esi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x3e7,-0x4(%rbp)
jge    11ff <generate_sin_table+0xdf>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
je     122b <generate_sin_table+0x10b>
mov    -0x4(%rbp),%eax
mov    $0x14,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    122b <generate_sin_table+0x10b>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1230 <generate_sin_table+0x110>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    116c <generate_sin_table+0x4c>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_sin_table>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xf1c(%rip),%rdi
call   1040 <puts@plt>
lea    0xf24(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9e(%rip),%rdi
mov    $0x3e8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xead(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e61(%rip),%r15
lea    0xed8(%rip),%rbx
lea    0xecb(%rip),%r14
xor    %ebp,%ebp
jmp    11a3 <generate_sin_table+0x63>
nopl   0x0(%rax)
add    $0x1,%ebp
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
movss  0xe4e(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm0
movss  (%r15),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
call   1060 <sin@plt>
mulss  0xe21(%rip),%xmm0
cvttss2si %xmm0,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x3e7,%ebp
je     1234 <generate_sin_table+0xf4>
mov    $0x2c,%edi
call   1030 <putchar@plt>
test   %ebp,%ebp
je     11a0 <generate_sin_table+0x60>
movzwl %bp,%eax
imul   $0xcccd,%eax,%eax
shr    $0x12,%eax
and    $0xfffffffc,%eax
lea    (%rax,%rax,4),%eax
neg    %eax
movzwl %ax,%eax
add    %ebp,%eax
test   %ax,%ax
jne    11a0 <generate_sin_table+0x60>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a0 <generate_sin_table+0x60>
lea    0xe5d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"#include <stdint.h>\0A\00"
@.str.1 = [27 x i8] c"#include <avr/pgmspace.h>\0A\00"
@.str.2 = [34 x i8] c"#define NUM_SIN_TABLE_ENTRIES %d\0A\00"
@.str.3 = [64 x i8] c"const PROGMEM int16_t sin_table[NUM_SIN_TABLE_ENTRIES] = {\0A \00"
@M_PI = global float 0.000000e+00
@.str.4 = [4 x i8] c"%5d\00"
@.str.5 = [2 x i8] c",\00"
@.str.6 = [6 x i8] c"\0A \00"
@.str.7 = [5 x i8] c"\0A};\0A\00"
define void @generate_sin_table() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 1000)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %8
8: ; preds = %41, %0
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 1000
br i1 %10, label %11, label %44
11: ; preds = %8
%12 = load i32, i32* %1
%13 = sitofp i32 %12 to float
%14 = fdiv float %13, 1.000000e+03
%15 = fpext float %14 to double
%16 = fmul double %15, 2.000000e+00
%17 = load float, float* @M_PI
%18 = fpext float %17 to double
%19 = fmul double %16, %18
%20 = fptrunc double %19 to float
store float %20, float* %3
%21 = load float, float* %3
%22 = call float @sin(float %21)
store float %22, float* %2
%23 = load float, float* %2
%24 = fmul float %23, 1.000000e+03
%25 = fptosi float %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %1
%28 = icmp slt i32 %27, 999
br i1 %28, label %29, label %31
29: ; preds = %11
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %29, %11
%32 = load i32, i32* %1
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i32, i32* %1
%36 = srem i32 %35, 20
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %34, %31
br label %41
41: ; preds = %40
%42 = load i32, i32* %1
%43 = add nsw i32 %42, 1
store i32 %43, i32* %1
br label %8
44: ; preds = %8
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.2 = [34 x i8] c"#define NUM_SIN_TABLE_ENTRIES %d\0A\00"
@.str.3 = [64 x i8] c"const PROGMEM int16_t sin_table[NUM_SIN_TABLE_ENTRIES] = {\0A \00"
@M_PI = global float 0.000000e+00
@.str.4 = [4 x i8] c"%5d\00"
@.str.6 = [6 x i8] c"\0A \00"
@str = [20 x i8] c"#include <stdint.h>\00"
@str.8 = [26 x i8] c"#include <avr/pgmspace.h>\00"
@str.9 = [4 x i8] c"\0A};\00"
define void @generate_sin_table() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 1000)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
br label %5
5: ; preds = %29, %0
%6 = phi i32 [ 0, %0 ], [ %30, %29 ]
%7 = sitofp i32 %6 to float
%8 = fdiv float %7, 1.000000e+03
%9 = fpext float %8 to double
%10 = fmul double %9, 2.000000e+00
%11 = load float, float* @M_PI
%12 = fpext float %11 to double
%13 = fmul double %10, %12
%14 = fptrunc double %13 to float
%15 = tail call float @sin(float %14)
%16 = fmul float %15, 1.000000e+03
%17 = fptosi float %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = icmp eq i32 %6, 999
br i1 %19, label %31, label %20
20: ; preds = %5
%21 = tail call i32 @putchar(i32 44)
%22 = icmp ne i32 %6, 0
%23 = trunc i32 %6 to i16
%24 = urem i16 %23, 20
%25 = icmp eq i16 %24, 0
%26 = and i1 %22, %25
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %29
29: ; preds = %20, %27
%30 = add nuw nsw i32 %6, 1
br label %5
31: ; preds = %5
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.9, i64 0, i64 0))
ret void
}