#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 */
typedef int ushort;

/* Variables and functions */
int /*<<< orphan*/ COLOR_PAIR(int);
short COLS;
double LINES;
double M_PI;
int /*<<< orphan*/ attron(int /*<<< orphan*/);
int /*<<< orphan*/ mvprintw(int, int, char *);
double sin(double);
ushort printwave(double amplitude, double period, short phase_shift,
                 ushort color_index) {
  double x;
  for (x = 0.0; x < (COLS + phase_shift); x += 1.0) {
    color_index += 1;
    attron(COLOR_PAIR((color_index % 6) + 1));
    double ratio = (2.0 * M_PI) / LINES;
    double y = sin(period * x * ratio);
    y *= amplitude;
    y += LINES / 2;
    mvprintw((int)(y), (int)(x - phase_shift), " ");
  }
  return color_index;
}


x86 assembly (clang, -O0):
<printwave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    %esi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
mov    0x2e68(%rip),%rax
movswl (%rax),%eax
movswl -0x12(%rbp),%ecx
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
ucomisd %xmm1,%xmm0
jbe    1255 <printwave+0x115>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x1,%edi
call   1050 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attron@plt>
movsd  0xe4c(%rip),%xmm0
mov    0x2e2d(%rip),%rax
mulsd  (%rax),%xmm0
mov    0x2e1a(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    0x2de2(%rip),%rax
movsd  (%rax),%xmm0
movsd  0xdf6(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvttsd2si -0x30(%rbp),%edi
movsd  -0x20(%rbp),%xmm0
movswl -0x12(%rbp),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
lea    0xdd7(%rip),%rdx
call   1060 <mvprintw@plt>
movsd  0xdc2(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1164 <printwave+0x24>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printwave>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    0x2e81(%rip),%r15
movswl (%r15),%eax
add    %edi,%eax
jle    1253 <printwave+0x113>
mov    %edi,%r13d
movswl %r13w,%eax
cvtsi2sd %eax,%xmm2
movsd  %xmm2,0x20(%rsp)
xorpd  %xmm2,%xmm2
movsd  %xmm2,0x8(%rsp)
mov    0x2e63(%rip),%r12
mov    0x2e54(%rip),%rbp
lea    0xe7d(%rip),%r14
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
nop
add    $0x1,%ebx
movslq %ebx,%rdi
imul   $0x2aaaaaab,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%edi
add    $0x1,%edi
call   1050 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attron@plt>
movsd  (%r12),%xmm1
addsd  %xmm1,%xmm1
divsd  0x0(%rbp),%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  0x18(%rsp),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <sin@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x0(%rbp),%xmm1
mulsd  0xdf9(%rip),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
movsd  0x8(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
cvttsd2si %xmm0,%esi
mov    %r14,%rdx
call   1060 <mvprintw@plt>
movsd  0x8(%rsp),%xmm1
addsd  0xdd3(%rip),%xmm1
movswl (%r15),%eax
add    %r13d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm1,0x8(%rsp)
ucomisd %xmm1,%xmm0
ja     11a0 <printwave+0x60>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@COLS = global i16 0
@M_PI = global double 0.000000e+00
@LINES = global double 0.000000e+00
@.str = [2 x i8] c" \00"
define i32 @printwave(double %0, double %1, i16 signext %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca i16
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %5
store double %1, double* %6
store i16 %2, i16* %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %9
br label %12
12: ; preds = %55, %4
%13 = load double, double* %9
%14 = load i16, i16* @COLS
%15 = sext i16 %14 to i32
%16 = load i16, i16* %7
%17 = sext i16 %16 to i32
%18 = add nsw i32 %15, %17
%19 = sitofp i32 %18 to double
%20 = fcmp olt double %13, %19
br i1 %20, label %21, label %58
21: ; preds = %12
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = srem i32 %24, 6
%26 = add nsw i32 %25, 1
%27 = call i32 @COLOR_PAIR(i32 %26)
%28 = call i32 @attron(i32 %27)
%29 = load double, double* @M_PI
%30 = fmul double 2.000000e+00, %29
%31 = load double, double* @LINES
%32 = fdiv double %30, %31
store double %32, double* %10
%33 = load double, double* %6
%34 = load double, double* %9
%35 = fmul double %33, %34
%36 = load double, double* %10
%37 = fmul double %35, %36
%38 = call double @sin(double %37)
store double %38, double* %11
%39 = load double, double* %5
%40 = load double, double* %11
%41 = fmul double %40, %39
store double %41, double* %11
%42 = load double, double* @LINES
%43 = fdiv double %42, 2.000000e+00
%44 = load double, double* %11
%45 = fadd double %44, %43
store double %45, double* %11
%46 = load double, double* %11
%47 = fptosi double %46 to i32
%48 = load double, double* %9
%49 = load i16, i16* %7
%50 = sext i16 %49 to i32
%51 = sitofp i32 %50 to double
%52 = fsub double %48, %51
%53 = fptosi double %52 to i32
%54 = call i32 @mvprintw(i32 %47, i32 %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %55
55: ; preds = %21
%56 = load double, double* %9
%57 = fadd double %56, 1.000000e+00
store double %57, double* %9
br label %12
58: ; preds = %12
%59 = load i32, i32* %8
ret i32 %59
}

LLVM IR (-O2):
@COLS = global i16 0
@M_PI = global double 0.000000e+00
@LINES = global double 0.000000e+00
@.str = [2 x i8] c" \00"
define i32 @printwave(double %0, double %1, i16 signext %2, i32 %3) {
%5 = sext i16 %2 to i32
%6 = load i16, i16* @COLS
%7 = sext i16 %6 to i32
%8 = add nsw i32 %7, %5
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %41
10: ; preds = %4
%11 = sitofp i16 %2 to double
br label %12
12: ; preds = %10, %12
%13 = phi i32 [ %3, %10 ], [ %15, %12 ]
%14 = phi double [ 0.000000e+00, %10 ], [ %35, %12 ]
%15 = add nsw i32 %13, 1
%16 = srem i32 %15, 6
%17 = add nsw i32 %16, 1
%18 = tail call i32 @COLOR_PAIR(i32 %17)
%19 = tail call i32 @attron(i32 %18)
%20 = load double, double* @M_PI
%21 = fmul double %20, 2.000000e+00
%22 = load double, double* @LINES
%23 = fdiv double %21, %22
%24 = fmul double %14, %1
%25 = fmul double %24, %23
%26 = tail call double @sin(double %25)
%27 = fmul double %26, %0
%28 = load double, double* @LINES
%29 = fmul double %28, 5.000000e-01
%30 = fadd double %27, %29
%31 = fptosi double %30 to i32
%32 = fsub double %14, %11
%33 = fptosi double %32 to i32
%34 = tail call i32 @mvprintw(i32 %31, i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = fadd double %14, 1.000000e+00
%36 = load i16, i16* @COLS
%37 = sext i16 %36 to i32
%38 = add nsw i32 %37, %5
%39 = sitofp i32 %38 to double
%40 = fcmp olt double %35, %39
br i1 %40, label %12, label %41
41: ; preds = %12, %4
%42 = phi i32 [ %3, %4 ], [ %15, %12 ]
ret i32 %42
}