#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 powerOf(int /*<<< orphan*/, int);
int round(double);
int /*<<< orphan*/ sin(double);
char **graph_sin(char **g, int width, int height, double x_scale,
                 double y_scale, int power) {
  double x_offset = ((double)width) / 2.0;
  int y_offset = height / 2;
  for (int x = 0; x < width; x++) {
    double adjusted_x = (((double)x) - x_offset) * x_scale;
    double raw_y = powerOf(sin(adjusted_x), power);
    int y = round((-raw_y) * y_scale) + y_offset;
    if (y >= 0 && y < height) {
      g[y][x] = '*';
    }
  }
  return g;
}


x86 assembly (clang, -O0):
<graph_sin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xea4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121c <graph_sin+0xec>
cvtsi2sdl -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <sin@plt>
mov    %eax,%edi
mov    -0x24(%rbp),%esi
call   1050 <powerOf@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1040 <round@plt>
add    -0x34(%rbp),%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jl     1209 <graph_sin+0xd9>
mov    -0x4c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1209 <graph_sin+0xd9>
mov    -0x8(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movb   $0x2a,(%rax,%rcx,1)
jmp    120e <graph_sin+0xde>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    117a <graph_sin+0x4a>
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<graph_sin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%r14
test   %esi,%esi
jle    11d2 <graph_sin+0xa2>
mov    %ecx,%r12d
mov    %edx,%r15d
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
mulsd  0xe96(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    %edx,%ebp
shr    $0x1f,%ebp
add    %edx,%ebp
sar    %ebp
mov    %esi,%r13d
xor    %ebx,%ebx
jmp    1189 <graph_sin+0x59>
nop
add    $0x1,%rbx
cmp    %rbx,%r13
je     11d2 <graph_sin+0xa2>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
subsd  (%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
mov    %eax,%edi
mov    %r12d,%esi
call   1050 <powerOf@plt>
xorpd  0xe5e(%rip),%xmm0
mulsd  0x10(%rsp),%xmm0
call   1040 <round@plt>
add    %ebp,%eax
js     1180 <graph_sin+0x50>
cmp    %r15d,%eax
jge    1180 <graph_sin+0x50>
mov    %eax,%eax
mov    (%r14,%rax,8),%rax
movb   $0x2a,(%rax,%rbx,1)
jmp    1180 <graph_sin+0x50>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @graph_sin(i8** %0, i32 %1, i32 %2, double %3, double %4, i32 %5) {
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca i32
%15 = alloca i32
%16 = alloca double
%17 = alloca double
%18 = alloca i32
store i8** %0, i8*** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double %3, double* %10
store double %4, double* %11
store i32 %5, i32* %12
%19 = load i32, i32* %8
%20 = sitofp i32 %19 to double
%21 = fdiv double %20, 2.000000e+00
store double %21, double* %13
%22 = load i32, i32* %9
%23 = sdiv i32 %22, 2
store i32 %23, i32* %14
store i32 0, i32* %15
br label %24
24: ; preds = %62, %6
%25 = load i32, i32* %15
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %65
28: ; preds = %24
%29 = load i32, i32* %15
%30 = sitofp i32 %29 to double
%31 = load double, double* %13
%32 = fsub double %30, %31
%33 = load double, double* %10
%34 = fmul double %32, %33
store double %34, double* %16
%35 = load double, double* %16
%36 = call i32 @sin(double %35)
%37 = load i32, i32* %12
%38 = call double @powerOf(i32 %36, i32 %37)
store double %38, double* %17
%39 = load double, double* %17
%40 = fneg double %39
%41 = load double, double* %11
%42 = fmul double %40, %41
%43 = call i32 @round(double %42)
%44 = load i32, i32* %14
%45 = add nsw i32 %43, %44
store i32 %45, i32* %18
%46 = load i32, i32* %18
%47 = icmp sge i32 %46, 0
br i1 %47, label %48, label %61
48: ; preds = %28
%49 = load i32, i32* %18
%50 = load i32, i32* %9
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %61
52: ; preds = %48
%53 = load i8**, i8*** %7
%54 = load i32, i32* %18
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = load i32, i32* %15
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 42, i8* %60
br label %61
61: ; preds = %52, %48, %28
br label %62
62: ; preds = %61
%63 = load i32, i32* %15
%64 = add nsw i32 %63, 1
store i32 %64, i32* %15
br label %24
65: ; preds = %24
%66 = load i8**, i8*** %7
ret i8** %66
}

LLVM IR (-O2):
define i8** @graph_sin(i8** returned %0, i32 %1, i32 %2, double %3, double %4, i32 %5) {
%7 = sitofp i32 %1 to double
%8 = fmul double %7, 5.000000e-01
%9 = sdiv i32 %2, 2
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = zext i32 %1 to i64
br label %14
13: ; preds = %34, %6
ret i8** %0
14: ; preds = %11, %34
%15 = phi i64 [ 0, %11 ], [ %35, %34 ]
%16 = trunc i64 %15 to i32
%17 = sitofp i32 %16 to double
%18 = fsub double %17, %8
%19 = fmul double %18, %3
%20 = tail call i32 @sin(double %19)
%21 = tail call double @powerOf(i32 %20, i32 %5)
%22 = fneg double %21
%23 = fmul double %22, %4
%24 = tail call i32 @round(double %23)
%25 = add nsw i32 %24, %9
%26 = icmp sgt i32 %25, -1
%27 = icmp slt i32 %25, %2
%28 = and i1 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %14
%30 = zext i32 %25 to i64
%31 = getelementptr inbounds i8*, i8** %0, i64 %30
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i64 %15
store i8 42, i8* %33
br label %34
34: ; preds = %29, %14
%35 = add nuw nsw i64 %15, 1
%36 = icmp eq i64 %35, %12
br i1 %36, label %13, label %14
}