#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 /*<<< orphan*/ delay(long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int sin(double);
int main() {
  int n;
  double waveTable[256];
  for (int i = 0; i < 256; i++) {
    double rad = (i * 2 * 3.14159265) / 256;
    waveTable[i] = (sin(rad) + 1) * 128;
  }
  printf("Please enter a frequency: ");
  scanf("%d", &n);
  printf("You entered: %d\n", n);
  long delayTime = 1000 / n;
  while (1) {
    for (int i = 0; i < 256; i++) {
      printf("%lf\n", waveTable[i]);
      delay(delayTime);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x814(%rbp)
cmpl   $0x100,-0x814(%rbp)
jge    11d4 <main+0x94>
mov    -0x814(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe87(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe73(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x820(%rbp)
ff
movsd  -0x820(%rbp),%xmm0
ff
call   1050 <sin@plt>
add    $0x1,%eax
shl    $0x7,%eax
cvtsi2sd %eax,%xmm0
movslq -0x814(%rbp),%rax
movsd  %xmm0,-0x810(%rbp,%rax,8)
ff ff
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    115c <main+0x1c>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe42(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3e8,%eax
cltd
idivl  -0x8(%rbp)
cltq
mov    %rax,-0x828(%rbp)
movl   $0x0,-0x82c(%rbp)
cmpl   $0x100,-0x82c(%rbp)
jge    126d <main+0x12d>
movslq -0x82c(%rbp),%rax
movsd  -0x810(%rbp,%rax,8),%xmm0
ff ff
lea    0xdf9(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x828(%rbp),%rdi
call   1040 <delay@plt>
mov    -0x82c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x82c(%rbp)
jmp    121f <main+0xdf>
jmp    1215 <main+0xd5>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x810,%rsp
xor    %ebx,%ebx
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xea1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe9d(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1050 <sin@plt>
shl    $0x7,%eax
sub    $0xffffff80,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp,%rbx,4)
lea    0x2(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe67(%rip),%xmm0
mulsd  0xe67(%rip),%xmm0
call   1050 <sin@plt>
shl    $0x7,%eax
sub    $0xffffff80,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x18(%rsp,%rbx,4)
add    $0x4,%rbx
cmp    $0x200,%rbx
jne    1150 <main+0x10>
lea    0xe43(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe50(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x3e8,%eax
xor    %edx,%edx
idivl  0xc(%rsp)
movslq %eax,%r15
lea    0xe33(%rip),%r14
nopl   0x0(%rax)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  0x10(%rsp,%rbx,8),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    %r15,%rdi
call   1040 <delay@plt>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    1220 <main+0xe0>
jmp    1210 <main+0xd0>

LLVM IR (-O0):
@.str = [27 x i8] c"Please enter a frequency: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"You entered: %d\0A\00"
@.str.3 = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x double]
%4 = alloca i32
%5 = alloca double
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 256
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = load i32, i32* %4
%13 = mul nsw i32 %12, 2
%14 = sitofp i32 %13 to double
%15 = fmul double %14, 0x400921FB53C8D4F1
%16 = fdiv double %15, 2.560000e+02
store double %16, double* %5
%17 = load double, double* %5
%18 = call i32 @sin(double %17)
%19 = add nsw i32 %18, 1
%20 = mul nsw i32 %19, 128
%21 = sitofp i32 %20 to double
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [256 x double], [256 x double]* %3, i64 0, i64 %23
store double %21, double* %24
br label %25
25: ; preds = %11
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %8
28: ; preds = %8
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%31 = load i32, i32* %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %2
%34 = sdiv i32 1000, %33
%35 = sext i32 %34 to i64
store i64 %35, i64* %6
br label %36
36: ; preds = %28, %51
store i32 0, i32* %7
br label %37
37: ; preds = %48, %36
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 256
br i1 %39, label %40, label %51
40: ; preds = %37
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [256 x double], [256 x double]* %3, i64 0, i64 %42
%44 = load double, double* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %44)
%46 = load i64, i64* %6
%47 = call i32 @delay(i64 %46)
br label %48
48: ; preds = %40
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %37
51: ; preds = %37
br label %36
}

LLVM IR (-O2):
@.str = [27 x i8] c"Please enter a frequency: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"You entered: %d\0A\00"
@.str.3 = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x double]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [256 x double]* %2 to i8*
br label %13
5: ; preds = %13
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %1
%11 = sdiv i32 1000, %10
%12 = sext i32 %11 to i64
br label %38
13: ; preds = %13, %0
%14 = phi i64 [ 0, %0 ], [ %36, %13 ]
%15 = trunc i64 %14 to i32
%16 = shl i32 %15, 1
%17 = sitofp i32 %16 to double
%18 = fmul double %17, 0x400921FB53C8D4F1
%19 = fmul double %18, 3.906250e-03
%20 = tail call i32 @sin(double %19)
%21 = shl i32 %20, 7
%22 = add i32 %21, 128
%23 = sitofp i32 %22 to double
%24 = getelementptr inbounds [256 x double], [256 x double]* %2, i64 0, i64 %14
store double %23, double* %24
%25 = or i64 %14, 1
%26 = trunc i64 %25 to i32
%27 = shl i32 %26, 1
%28 = sitofp i32 %27 to double
%29 = fmul double %28, 0x400921FB53C8D4F1
%30 = fmul double %29, 3.906250e-03
%31 = tail call i32 @sin(double %30)
%32 = shl i32 %31, 7
%33 = add i32 %32, 128
%34 = sitofp i32 %33 to double
%35 = getelementptr inbounds [256 x double], [256 x double]* %2, i64 0, i64 %25
store double %34, double* %35
%36 = add nuw nsw i64 %14, 2
%37 = icmp eq i64 %36, 256
br i1 %37, label %5, label %13
38: ; preds = %39, %5
br label %39
39: ; preds = %38, %39
%40 = phi i64 [ 0, %38 ], [ %45, %39 ]
%41 = getelementptr inbounds [256 x double], [256 x double]* %2, i64 0, i64 %40
%42 = load double, double* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %42)
%44 = call i32 @delay(i64 %12)
%45 = add nuw nsw i64 %40, 1
%46 = icmp eq i64 %45, 256
br i1 %46, label %38, label %39
}