#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 atoi(char *);
int /*<<< orphan*/ putchar(int /*<<< orphan*/);
int /*<<< orphan*/ round(double);
int main(int argc, char **argv) {
  bool rising = false;
  double period, halfPeriod, step, amp = (255 / 2);
  if (argc == 2) {
    period = atoi(argv[1]);
  } else {
    period = 400;
  }
  halfPeriod = period / 2;
  step = 255 / halfPeriod;
  while (1) {
    if (rising) {
      amp += step;
    } else {
      amp -= step;
    }
    if (amp >= 255) {
      rising = false;
      amp = 255;
    }
    if (amp <= 0) {
      rising = true;
      amp = 0;
    }
    putchar(round(amp));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movsd  0xeab(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    117b <main+0x4b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    1188 <main+0x58>
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe83(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe6a(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ce <main+0x9e>
movsd  -0x30(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11e1 <main+0xb1>
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe22(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     120c <main+0xdc>
movl   $0x0,-0x14(%rbp)
movsd  0xe09(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     1229 <main+0xf9>
movl   $0x1,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <round@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    11b0 <main+0x80>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
cmp    $0x2,%edi
jne    1150 <main+0x20>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mulsd  0xeba(%rip),%xmm0
jmp    1158 <main+0x28>
movsd  0xea8(%rip),%xmm0
movsd  0xeb0(%rip),%xmm1
divsd  %xmm0,%xmm1
movapd 0xeb4(%rip),%xmm0
movapd %xmm1,0x10(%rsp)
xorpd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
movsd  0xe94(%rip),%xmm0
xor    %r14d,%r14d
mov    $0x1,%ebp
xor    %ebx,%ebx
jmp    11ac <main+0x7c>
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1040 <round@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
movsd  0x8(%rsp),%xmm0
movapd 0x20(%rsp),%xmm1
test   %ebx,%ebx
je     11bc <main+0x8c>
movapd 0x10(%rsp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe48(%rip),%xmm1
ucomisd %xmm1,%xmm0
cmovae %r14d,%ebx
minsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
cmovae %ebp,%ebx
jb     1190 <main+0x60>
xorpd  %xmm1,%xmm1
jmp    1190 <main+0x60>

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store double 1.270000e+02, double* %10
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call double @atoi(i8* %16)
store double %17, double* %7
br label %19
18: ; preds = %2
store double 4.000000e+02, double* %7
br label %19
19: ; preds = %18, %13
%20 = load double, double* %7
%21 = fdiv double %20, 2.000000e+00
store double %21, double* %8
%22 = load double, double* %8
%23 = fdiv double 2.550000e+02, %22
store double %23, double* %9
br label %24
24: ; preds = %19, %43
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load double, double* %9
%29 = load double, double* %10
%30 = fadd double %29, %28
store double %30, double* %10
br label %35
31: ; preds = %24
%32 = load double, double* %9
%33 = load double, double* %10
%34 = fsub double %33, %32
store double %34, double* %10
br label %35
35: ; preds = %31, %27
%36 = load double, double* %10
%37 = fcmp oge double %36, 2.550000e+02
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 0, i32* %6
store double 2.550000e+02, double* %10
br label %39
39: ; preds = %38, %35
%40 = load double, double* %10
%41 = fcmp ole double %40, 0.000000e+00
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 1, i32* %6
store double 0.000000e+00, double* %10
br label %43
43: ; preds = %42, %39
%44 = load double, double* %10
%45 = call i32 @round(double %44)
%46 = call i32 @putchar(i32 %45)
br label %24
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call double @atoi(i8* %6)
%8 = fmul double %7, 5.000000e-01
br label %9
9: ; preds = %2, %4
%10 = phi double [ %8, %4 ], [ 2.000000e+02, %2 ]
%11 = fdiv double 2.550000e+02, %10
%12 = fneg double %11
br label %13
13: ; preds = %13, %9
%14 = phi i32 [ 0, %9 ], [ %23, %13 ]
%15 = phi double [ 1.270000e+02, %9 ], [ %24, %13 ]
%16 = icmp eq i32 %14, 0
%17 = select i1 %16, double %12, double %11
%18 = fadd double %15, %17
%19 = fcmp ult double %18, 2.550000e+02
%20 = select i1 %19, i32 %14, i32 0
%21 = select i1 %19, double %18, double 2.550000e+02
%22 = fcmp ugt double %21, 0.000000e+00
%23 = select i1 %22, i32 %20, i32 1
%24 = select i1 %22, double %21, double 0.000000e+00
%25 = tail call i32 @round(double %24)
%26 = tail call i32 @putchar(i32 %25)
br label %13
}