#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 M_PI;
int /*<<< orphan*/ printf(char *, double, ...);
double sin(double);
void piecesOfPie(double n) {
  double i = 0;
  printf("Printing %f pieces of sin(0-2pi)\n(in radians)\n", n);
  while (i <= 2 * M_PI) {
    printf("sin(%f)=%f\n", i, sin(i));
    i = i + ((2 * M_PI) / n);
  }
}


x86 assembly (clang, -O0):
<piecesOfPie>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    0xebf(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm1
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
ucomisd %xmm1,%xmm0
jb     11b9 <piecesOfPie+0x99>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
lea    0xea5(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  -0x8(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1148 <piecesOfPie+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<piecesOfPie>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xed2(%rip),%rdi
movsd  %xmm0,0x10(%rsp)
mov    $0x1,%al
call   1030 <printf@plt>
mov    0x2ea6(%rip),%r14
cmpl   $0x0,(%r14)
js     11b8 <piecesOfPie+0x98>
xorps  %xmm0,%xmm0
lea    0xedd(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1030 <printf@plt>
mov    (%r14),%eax
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd %xmm0,%xmm1
divsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
ucomisd 0x8(%rsp),%xmm0
movsd  0x8(%rsp),%xmm0
jae    1160 <piecesOfPie+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Printing %f pieces of sin(0-2pi)\0A(in radians)\0A\00"
@M_PI = global i32 0
@.str.1 = [12 x i8] c"sin(%f)=%f\0A\00"
define void @piecesOfPie(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %2
store double 0.000000e+00, double* %3
%4 = load double, double* %2
%5 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), double %4)
br label %6
6: ; preds = %12, %1
%7 = load double, double* %3
%8 = load i32, i32* @M_PI
%9 = mul nsw i32 2, %8
%10 = sitofp i32 %9 to double
%11 = fcmp ole double %7, %10
br i1 %11, label %12, label %24
12: ; preds = %6
%13 = load double, double* %3
%14 = load double, double* %3
%15 = call double @sin(double %14)
%16 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %13, double %15)
%17 = load double, double* %3
%18 = load i32, i32* @M_PI
%19 = mul nsw i32 2, %18
%20 = sitofp i32 %19 to double
%21 = load double, double* %2
%22 = fdiv double %20, %21
%23 = fadd double %17, %22
store double %23, double* %3
br label %6
24: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"Printing %f pieces of sin(0-2pi)\0A(in radians)\0A\00"
@M_PI = global i32 0
@.str.1 = [12 x i8] c"sin(%f)=%f\0A\00"
define void @piecesOfPie(double %0) {
%2 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), double %0)
%3 = load i32, i32* @M_PI
%4 = icmp slt i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1, %5
%6 = phi double [ %13, %5 ], [ 0.000000e+00, %1 ]
%7 = tail call double @sin(double %6)
%8 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double %6, double %7)
%9 = load i32, i32* @M_PI
%10 = shl nsw i32 %9, 1
%11 = sitofp i32 %10 to double
%12 = fdiv double %11, %0
%13 = fadd double %6, %12
%14 = fcmp ugt double %13, %11
br i1 %14, label %15, label %5
15: ; preds = %5, %1
ret void
}