#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 atoi(char *);
int /*<<< orphan*/ putchar(int);
int round(int);
int sin(double);
int main(int argc, char **argv) {
  int period, i, out;
  double stepRad;
  if (argc == 2) {
    period = atoi(argv[1]);
  } else {
    period = 400;
  }
  stepRad = (2 * 3.14159265358979323846264338327) / period;
  i = 0;
  while (1) {
    if (i == period) {
      i = 0;
    }
    out = round(sin(stepRad * i) * ((255 - 1) / 2));
    putchar(out + 127);
    i += 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1175 <main+0x35>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    117c <main+0x3c>
movl   $0x190,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe77(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11ac <main+0x6c>
movl   $0x0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <sin@plt>
imul   $0x7f,%eax,%edi
call   1050 <round@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x7f,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1199 <main+0x59>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x190,%ebx
cmp    $0x2,%edi
jne    115d <main+0x1d>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
cvtsi2sd %ebx,%xmm0
movsd  0xe97(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %r14d,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
cmp    %ebx,%ebp
cmove  %r14d,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
mov    %eax,%edi
shl    $0x7,%edi
sub    %eax,%edi
call   1050 <round@plt>
lea    0x7f(%rax),%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
jmp    1180 <main+0x40>

LLVM IR (-O0):
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
%9 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
br label %18
17: ; preds = %2
store i32 400, i32* %6
br label %18
18: ; preds = %17, %12
%19 = load i32, i32* %6
%20 = sitofp i32 %19 to double
%21 = fdiv double 0x401921FB54442D18, %20
store double %21, double* %9
store i32 0, i32* %7
br label %22
22: ; preds = %18, %27
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 0, i32* %7
br label %27
27: ; preds = %26, %22
%28 = load double, double* %9
%29 = load i32, i32* %7
%30 = sitofp i32 %29 to double
%31 = fmul double %28, %30
%32 = call i32 @sin(double %31)
%33 = mul nsw i32 %32, 127
%34 = call i32 @round(i32 %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 127
%37 = call i32 @putchar(i32 %36)
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %22
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 400, %2 ]
%10 = sitofp i32 %9 to double
%11 = fdiv double 0x401921FB54442D18, %10
br label %12
12: ; preds = %12, %8
%13 = phi i32 [ 0, %8 ], [ %23, %12 ]
%14 = icmp eq i32 %13, %9
%15 = select i1 %14, i32 0, i32 %13
%16 = sitofp i32 %15 to double
%17 = fmul double %11, %16
%18 = tail call i32 @sin(double %17)
%19 = mul nsw i32 %18, 127
%20 = tail call i32 @round(i32 %19)
%21 = add nsw i32 %20, 127
%22 = tail call i32 @putchar(i32 %21)
%23 = add nsw i32 %15, 1
br label %12
}