#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 fabs(double);
double sin(double rad) {
  double app;
  double diff;
  int inc = 1;
  while (rad > 2 * 3.14159265358979323846)
    rad -= 2 * 3.14159265358979323846;
  while (rad < -2 * 3.14159265358979323846)
    rad += 2 * 3.14159265358979323846;
  app = diff = rad;
  diff = (diff * (-(rad * rad))) / ((2.0 * inc) * (2.0 * inc + 1.0));
  app = app + diff;
  inc++;
  while (fabs(diff) >= 0.00001) {
    diff = (diff * (-(rad * rad))) / ((2.0 * inc) * (2.0 * inc + 1.0));
    app = app + diff;
    inc++;
  }
  return app;
}


x86 assembly (clang, -O0):
<sin>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movl   $0x1,-0x1c(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xee3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1142 <sin+0x42>
movsd  -0x8(%rbp),%xmm0
movsd  0xecc(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1110 <sin+0x10>
jmp    1147 <sin+0x47>
movsd  0xeb9(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1171 <sin+0x71>
movsd  0xe9e(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1147 <sin+0x47>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm2
movsd  0xe61(%rip),%xmm1
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm2
addsd  %xmm2,%xmm2
movsd  0xe44(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xe2f(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe13(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1291 <sin+0x191>
movsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm2
movsd  0xdca(%rip),%xmm1
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm2
addsd  %xmm2,%xmm2
movsd  0xdad(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f5 <sin+0xf5>
movsd  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<sin>:
ucomisd 0xef8(%rip),%xmm0
jbe    112a <sin+0x2a>
movsd  0xef6(%rip),%xmm1
movsd  0xee6(%rip),%xmm2
nopw   0x0(%rax,%rax,1)
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
ja     1120 <sin+0x20>
movsd  0xed6(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    114a <sin+0x4a>
movsd  0xec0(%rip),%xmm2
addsd  %xmm2,%xmm0
ucomisd %xmm0,%xmm1
ja     1140 <sin+0x40>
movapd 0xede(%rip),%xmm1
xorpd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm1,%xmm2
divsd  0xea6(%rip),%xmm2
addsd  %xmm2,%xmm0
movapd 0xeca(%rip),%xmm3
andpd  %xmm2,%xmm3
ucomisd 0xe96(%rip),%xmm3
jb     11e4 <sin+0xe4>
mov    $0x2,%eax
movsd  0xe8f(%rip),%xmm3
movapd 0xea7(%rip),%xmm4
movsd  0xe77(%rip),%xmm5
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mulsd  %xmm1,%xmm2
xorps  %xmm6,%xmm6
cvtsi2sd %eax,%xmm6
addsd  %xmm6,%xmm6
movapd %xmm6,%xmm7
addsd  %xmm3,%xmm7
mulsd  %xmm6,%xmm7
divsd  %xmm7,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%eax
movapd %xmm2,%xmm6
andpd  %xmm4,%xmm6
ucomisd %xmm5,%xmm6
jae    11b0 <sin+0xb0>
ret

LLVM IR (-O0):
define double @sin(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %2
store i32 1, i32* %5
br label %6
6: ; preds = %9, %1
%7 = load double, double* %2
%8 = fcmp ogt double %7, 0x401921FB54442D18
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load double, double* %2
%11 = fsub double %10, 0x401921FB54442D18
store double %11, double* %2
br label %6
12: ; preds = %6
br label %13
13: ; preds = %16, %12
%14 = load double, double* %2
%15 = fcmp olt double %14, 0xC01921FB54442D18
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load double, double* %2
%18 = fadd double %17, 0x401921FB54442D18
store double %18, double* %2
br label %13
19: ; preds = %13
%20 = load double, double* %2
store double %20, double* %4
store double %20, double* %3
%21 = load double, double* %4
%22 = load double, double* %2
%23 = load double, double* %2
%24 = fmul double %22, %23
%25 = fneg double %24
%26 = fmul double %21, %25
%27 = load i32, i32* %5
%28 = sitofp i32 %27 to double
%29 = fmul double 2.000000e+00, %28
%30 = load i32, i32* %5
%31 = sitofp i32 %30 to double
%32 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %31, double 1.000000e+00)
%33 = fmul double %29, %32
%34 = fdiv double %26, %33
store double %34, double* %4
%35 = load double, double* %3
%36 = load double, double* %4
%37 = fadd double %35, %36
store double %37, double* %3
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %40
40: ; preds = %44, %19
%41 = load double, double* %4
%42 = call double @llvm.fabs.f64(double %41)
%43 = fcmp oge double %42, 1.000000e-05
br i1 %43, label %44, label %64
44: ; preds = %40
%45 = load double, double* %4
%46 = load double, double* %2
%47 = load double, double* %2
%48 = fmul double %46, %47
%49 = fneg double %48
%50 = fmul double %45, %49
%51 = load i32, i32* %5
%52 = sitofp i32 %51 to double
%53 = fmul double 2.000000e+00, %52
%54 = load i32, i32* %5
%55 = sitofp i32 %54 to double
%56 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %55, double 1.000000e+00)
%57 = fmul double %53, %56
%58 = fdiv double %50, %57
store double %58, double* %4
%59 = load double, double* %3
%60 = load double, double* %4
%61 = fadd double %59, %60
store double %61, double* %3
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
store i32 %63, i32* %5
br label %40
64: ; preds = %40
%65 = load double, double* %3
ret double %65
}

LLVM IR (-O2):
define double @sin(double %0) {
%2 = fcmp ogt double %0, 0x401921FB54442D18
br i1 %2, label %6, label %3
3: ; preds = %6, %1
%4 = phi double [ %0, %1 ], [ %8, %6 ]
%5 = fcmp olt double %4, 0xC01921FB54442D18
br i1 %5, label %10, label %14
6: ; preds = %1, %6
%7 = phi double [ %8, %6 ], [ %0, %1 ]
%8 = fadd double %7, 0xC01921FB54442D18
%9 = fcmp ogt double %8, 0x401921FB54442D18
br i1 %9, label %6, label %3
10: ; preds = %3, %10
%11 = phi double [ %12, %10 ], [ %4, %3 ]
%12 = fadd double %11, 0x401921FB54442D18
%13 = fcmp olt double %12, 0xC01921FB54442D18
br i1 %13, label %10, label %14
14: ; preds = %10, %3
%15 = phi double [ %4, %3 ], [ %12, %10 ]
%16 = fneg double %15
%17 = fmul double %15, %16
%18 = fmul double %15, %17
%19 = fdiv double %18, 6.000000e+00
%20 = fadd double %15, %19
%21 = tail call double @llvm.fabs.f64(double %19)
%22 = fcmp ult double %21, 1.000000e-05
br i1 %22, label %37, label %23
23: ; preds = %14, %23
%24 = phi i32 [ %34, %23 ], [ 2, %14 ]
%25 = phi double [ %32, %23 ], [ %19, %14 ]
%26 = phi double [ %33, %23 ], [ %20, %14 ]
%27 = fmul double %17, %25
%28 = sitofp i32 %24 to double
%29 = fmul double %28, 2.000000e+00
%30 = tail call double @llvm.fmuladd.f64(double %28, double 2.000000e+00, double 1.000000e+00)
%31 = fmul double %29, %30
%32 = fdiv double %27, %31
%33 = fadd double %26, %32
%34 = add nuw nsw i32 %24, 1
%35 = tail call double @llvm.fabs.f64(double %32)
%36 = fcmp ult double %35, 1.000000e-05
br i1 %36, label %37, label %23
37: ; preds = %23, %14
%38 = phi double [ %20, %14 ], [ %33, %23 ]
ret double %38
}