#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 */
double M_PI;
int /*<<< orphan*/ printf(char *, ...);
double sin(double);
int main(int argc, char **argv) {
  int i, n, ch;
  n = 512 + 256;
  printf("#define TABLE_SIZE %i\n", n);
  printf("#define OFFSET_0 0\n");
  printf("#define OFFSET_1 %i\n", n / 3);
  printf("#define OFFSET_2 %i\n", 2 * n / 3);
  printf("\n\nbyte pwmSin[] = {\n");
  for (i = 0; i < n; i++) {
    if ((i % 16) == 0) {
      printf("\n  ");
    }
    if (i < (n - 1)) {
      ch = ',';
    } else {
      ch = '\n';
    }
    printf(
        "%4i%c",
        (int)(255.0 * ((sin(-2.0 * M_PI * (double)i / (double)n) + 1.0) / 2.0)),
        ch);
  }
  printf("\n};\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x300,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1270 <main+0x150>
mov    -0x14(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d8 <main+0xb8>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11f5 <main+0xd5>
movl   $0x2c,-0x1c(%rbp)
jmp    11fc <main+0xdc>
movl   $0xa,-0x1c(%rbp)
movsd  0xe14(%rip),%xmm0
mov    0x2ddd(%rip),%rax
mulsd  (%rax),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  0xddf(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xdcb(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xdb7(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
mov    -0x1c(%rbp),%edx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11aa <main+0x8a>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xee6(%rip),%rdi
mov    $0x300,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf1e(%rip),%rdi
call   1030 <puts@plt>
lea    0xede(%rip),%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee0(%rip),%rdi
mov    $0x200,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeff(%rip),%rdi
call   1030 <puts@plt>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
lea    0xecd(%rip),%r14
mov    $0x2c,%r15d
mov    0x2e3f(%rip),%r12
lea    0xebd(%rip),%r13
xor    %ebx,%ebx
jmp    1238 <main+0x108>
nopw   0x0(%rax,%rax,1)
cmp    $0x2ff,%ebx
mov    $0xa,%ebp
cmovb  %r15d,%ebp
movsd  (%r12),%xmm0
mulsd  0xe23(%rip),%xmm0
mulsd  (%rsp),%xmm0
divsd  0xe1e(%rip),%xmm0
call   1050 <sin@plt>
movsd  0xe19(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  0xe15(%rip),%xmm0
mulsd  0xe15(%rip),%xmm0
cvttsd2si %xmm0,%esi
mov    %r13,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
addsd  0xde8(%rip),%xmm0
movsd  %xmm0,(%rsp)
add    $0x1,%ebx
cmp    $0x300,%ebx
je     124c <main+0x11c>
test   $0xf,%bl
jne    11c0 <main+0x90>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <main+0x90>
lea    0xe47(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"#define TABLE_SIZE %i\0A\00"
@.str.1 = [20 x i8] c"#define OFFSET_0 0\0A\00"
@.str.2 = [21 x i8] c"#define OFFSET_1 %i\0A\00"
@.str.3 = [21 x i8] c"#define OFFSET_2 %i\0A\00"
@.str.4 = [21 x i8] c"\0A\0Abyte pwmSin[] = {\0A\00"
@.str.5 = [4 x i8] c"\0A \00"
@.str.6 = [6 x i8] c"%4i%c\00"
@M_PI = global double 0.000000e+00
@.str.7 = [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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 768, i32* %7
%9 = load i32, i32* %7
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %7
%13 = sdiv i32 %12, 3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %7
%16 = mul nsw i32 2, %15
%17 = sdiv i32 %16, 3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %20
20: ; preds = %53, %2
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %56
24: ; preds = %20
%25 = load i32, i32* %6
%26 = srem i32 %25, 16
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = sub nsw i32 %32, 1
%34 = icmp slt i32 %31, %33
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 44, i32* %8
br label %37
36: ; preds = %30
store i32 10, i32* %8
br label %37
37: ; preds = %36, %35
%38 = load double, double* @M_PI
%39 = fmul double -2.000000e+00, %38
%40 = load i32, i32* %6
%41 = sitofp i32 %40 to double
%42 = fmul double %39, %41
%43 = load i32, i32* %7
%44 = sitofp i32 %43 to double
%45 = fdiv double %42, %44
%46 = call double @sin(double %45)
%47 = fadd double %46, 1.000000e+00
%48 = fdiv double %47, 2.000000e+00
%49 = fmul double 2.550000e+02, %48
%50 = fptosi double %49 to i32
%51 = load i32, i32* %8
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %50, i32 %51)
br label %53
53: ; preds = %37
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
br label %20
56: ; preds = %20
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [23 x i8] c"#define TABLE_SIZE %i\0A\00"
@.str.2 = [21 x i8] c"#define OFFSET_1 %i\0A\00"
@.str.3 = [21 x i8] c"#define OFFSET_2 %i\0A\00"
@.str.5 = [4 x i8] c"\0A \00"
@.str.6 = [6 x i8] c"%4i%c\00"
@M_PI = global double 0.000000e+00
@str = [19 x i8] c"#define OFFSET_0 0\00"
@str.8 = [20 x i8] c"\0A\0Abyte pwmSin[] = {\00"
@str.9 = [4 x i8] c"\0A};\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 768)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 256)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 512)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
br label %8
8: ; preds = %2, %14
%9 = phi i32 [ 0, %2 ], [ %28, %14 ]
%10 = and i32 %9, 15
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = icmp ult i32 %9, 767
%16 = select i1 %15, i32 44, i32 10
%17 = load double, double* @M_PI
%18 = fmul double %17, -2.000000e+00
%19 = sitofp i32 %9 to double
%20 = fmul double %18, %19
%21 = fdiv double %20, 7.680000e+02
%22 = tail call double @sin(double %21)
%23 = fadd double %22, 1.000000e+00
%24 = fmul double %23, 5.000000e-01
%25 = fmul double %24, 2.550000e+02
%26 = fptosi double %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %26, i32 %16)
%28 = add nuw nsw i32 %9, 1
%29 = icmp eq i32 %28, 768
br i1 %29, label %30, label %8
30: ; preds = %14
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.9, i64 0, i64 0))
ret i32 0
}