#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 powerfact(double, int);
double sine(double x) {
  int i = 1, s = 1;
  double pf, sum = 0;
  while (1) {
    pf = powerfact(x, 2 * i - 1);
    if (-1e-16 < pf && pf < 1e-16)
      break;
    else
      sum += pf * s;
    i++;
    s *= -1;
  }
  return sum;
}


x86 assembly (clang, -O0):
<sine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%edi
shl    $0x1,%edi
sub    $0x1,%edi
call   1030 <powerfact@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xea8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    117a <sine+0x6a>
movsd  0xe9e(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    117a <sine+0x6a>
jmp    11ab <sine+0x9b>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
imul   $0xffffffff,-0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1133 <sine+0x23>
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sine>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%ebp
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%edi
call   1030 <powerfact@plt>
ucomisd 0xecd(%rip),%xmm0
jbe    1147 <sine+0x37>
xorpd  %xmm2,%xmm2
movsd  0xec7(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1195 <sine+0x85>
xorpd  %xmm2,%xmm2
mov    $0x3,%ebx
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rsp)
neg    %ebp
movsd  0x8(%rsp),%xmm0
mov    %ebx,%edi
call   1030 <powerfact@plt>
movsd  0x10(%rsp),%xmm2
add    $0x2,%ebx
ucomisd 0xe7b(%rip),%xmm0
jbe    1150 <sine+0x40>
movsd  0xe79(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1150 <sine+0x40>
movapd %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @sine(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
store double %0, double* %2
store i32 1, i32* %3
store i32 1, i32* %4
store double 0.000000e+00, double* %6
br label %7
7: ; preds = %1, %25
%8 = load double, double* %2
%9 = load i32, i32* %3
%10 = mul nsw i32 2, %9
%11 = sub nsw i32 %10, 1
%12 = call double @powerfact(double %8, i32 %11)
store double %12, double* %5
%13 = load double, double* %5
%14 = fcmp olt double 0xBC9CD2B297D889BC, %13
br i1 %14, label %15, label %19
15: ; preds = %7
%16 = load double, double* %5
%17 = fcmp olt double %16, 0x3C9CD2B297D889BC
br i1 %17, label %18, label %19
18: ; preds = %15
br label %30
19: ; preds = %15, %7
%20 = load double, double* %5
%21 = load i32, i32* %4
%22 = sitofp i32 %21 to double
%23 = load double, double* %6
%24 = call double @llvm.fmuladd.f64(double %20, double %22, double %23)
store double %24, double* %6
br label %25
25: ; preds = %19
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
%28 = load i32, i32* %4
%29 = mul nsw i32 %28, -1
store i32 %29, i32* %4
br label %7
30: ; preds = %18
%31 = load double, double* %6
ret double %31
}

LLVM IR (-O2):
define double @sine(double %0) {
%2 = tail call double @powerfact(double %0, i32 1)
%3 = fcmp ogt double %2, 0xBC9CD2B297D889BC
%4 = fcmp olt double %2, 0x3C9CD2B297D889BC
%5 = and i1 %3, %4
br i1 %5, label %21, label %6
6: ; preds = %1, %6
%7 = phi double [ %17, %6 ], [ %2, %1 ]
%8 = phi double [ %12, %6 ], [ 0.000000e+00, %1 ]
%9 = phi i32 [ %13, %6 ], [ 1, %1 ]
%10 = phi i32 [ %14, %6 ], [ 1, %1 ]
%11 = sitofp i32 %10 to double
%12 = tail call double @llvm.fmuladd.f64(double %7, double %11, double %8)
%13 = add nuw nsw i32 %9, 1
%14 = sub nsw i32 0, %10
%15 = shl nuw nsw i32 %13, 1
%16 = add nsw i32 %15, -1
%17 = tail call double @powerfact(double %0, i32 %16)
%18 = fcmp ogt double %17, 0xBC9CD2B297D889BC
%19 = fcmp olt double %17, 0x3C9CD2B297D889BC
%20 = and i1 %18, %19
br i1 %20, label %21, label %6
21: ; preds = %6, %1
%22 = phi double [ 0.000000e+00, %1 ], [ %12, %6 ]
ret double %22
}