#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 dpow(double, int);
scalar_t__ fact(int);
double mod(double, double);
double sin(double n) {
  int neg = 0;
  if (n < 0) {
    neg = 1;
    n *= -1;
  }
  if (n > 2 * 3.14159265358979323846) {
    n = mod(n, 2 * 3.14159265358979323846);
  }
  if (n > 3.14159265358979323846 / 2 && n < 3.14159265358979323846) {
    n = 3.14159265358979323846 / 2 - mod(n, 3.14159265358979323846 / 2);
  } else if (n >= 3.14159265358979323846 &&
             n < 3 * 3.14159265358979323846 / 2) {
    n = mod(n, 3.14159265358979323846 / 2);
    neg = 1;
  } else if (n >= 3 * 3.14159265358979323846 / 2) {
    n = 3.14159265358979323846 / 2 - mod(n, 3.14159265358979323846 / 2);
    neg = 1;
  }
  double sum = 0;
  int i;
  for (i = 1; i <= 30; i++) {
    sum += dpow(-1, i - 1) * (dpow(n, 2 * i - 1)) / ((double)fact(2 * i - 1));
  }
  if (neg) {
    return -1 * sum;
  }
  return sum;
}


x86 assembly (clang, -O0):
<sin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    116b <sin+0x3b>
movl   $0x1,-0x14(%rbp)
movsd  0xe9f(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe90(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1199 <sin+0x69>
movsd  -0x10(%rbp),%xmm0
movsd  0xe79(%rip),%xmm1
call   1030 <mod@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe6a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ee <sin+0xbe>
movsd  0xe60(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11ee <sin+0xbe>
movsd  -0x10(%rbp),%xmm0
movsd  0xe40(%rip),%xmm1
call   1030 <mod@plt>
movaps %xmm0,%xmm1
movsd  0xe30(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1289 <sin+0x159>
movsd  -0x10(%rbp),%xmm0
movsd  0xe1d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     123b <sin+0x10b>
movsd  0xe13(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    123b <sin+0x10b>
movsd  -0x10(%rbp),%xmm0
movsd  0xdeb(%rip),%xmm1
call   1030 <mod@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    1284 <sin+0x154>
movsd  -0x10(%rbp),%xmm0
movsd  0xdd8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     127f <sin+0x14f>
movsd  -0x10(%rbp),%xmm0
movsd  0xdb1(%rip),%xmm1
call   1030 <mod@plt>
movaps %xmm0,%xmm1
movsd  0xda1(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    1284 <sin+0x154>
jmp    1289 <sin+0x159>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x1e,-0x24(%rbp)
jg     1312 <sin+0x1e2>
mov    -0x24(%rbp),%edi
sub    $0x1,%edi
movsd  0xd50(%rip),%xmm0
call   1050 <dpow@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x24(%rbp),%edi
shl    $0x1,%edi
sub    $0x1,%edi
call   1050 <dpow@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%edi
shl    $0x1,%edi
sub    $0x1,%edi
call   1040 <fact@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1298 <sin+0x168>
cmpl   $0x0,-0x14(%rbp)
je     1333 <sin+0x203>
movsd  0xcdc(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133d <sin+0x20d>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sin>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
seta   %r14b
ja     115c <sin+0x2c>
ucomisd 0xec2(%rip),%xmm0
ja     116e <sin+0x3e>
ucomisd 0xec0(%rip),%xmm0
ja     1185 <sin+0x55>
jmp    11ae <sin+0x7e>
xorpd  0xe9c(%rip),%xmm0
ucomisd 0xea4(%rip),%xmm0
jbe    1150 <sin+0x20>
movsd  0xe9a(%rip),%xmm1
call   1030 <mod@plt>
ucomisd 0xe95(%rip),%xmm0
jbe    11ae <sin+0x7e>
movsd  0xe93(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11ae <sin+0x7e>
movsd  0xe7d(%rip),%xmm1
call   1030 <mod@plt>
movsd  0xe70(%rip),%xmm1
subsd  %xmm0,%xmm1
jmp    11fe <sin+0xce>
ucomisd 0xe6a(%rip),%xmm0
jb     11d8 <sin+0xa8>
movsd  0xe68(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11d8 <sin+0xa8>
movsd  0xe4a(%rip),%xmm1
call   1030 <mod@plt>
mov    $0x1,%r14b
jmp    1202 <sin+0xd2>
ucomisd 0xe48(%rip),%xmm0
jb     1202 <sin+0xd2>
movsd  0xe2e(%rip),%xmm1
call   1030 <mod@plt>
movsd  0xe21(%rip),%xmm1
subsd  %xmm0,%xmm1
mov    $0x1,%r14b
movapd %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
xorpd  %xmm1,%xmm1
mov    $0x1,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movapd %xmm1,0x20(%rsp)
movsd  0xe02(%rip),%xmm0
mov    %ebp,%edi
call   1050 <dpow@plt>
movsd  %xmm0,0x8(%rsp)
movapd 0x10(%rsp),%xmm0
mov    %ebx,%edi
call   1050 <dpow@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
call   1040 <fact@plt>
movapd 0x20(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm2
divsd  %xmm0,%xmm2
addsd  %xmm2,%xmm1
add    $0x2,%ebx
add    $0x1,%ebp
cmp    $0x3d,%ebx
jne    1220 <sin+0xf0>
test   %r14b,%r14b
je     128f <sin+0x15f>
xorpd  0xd71(%rip),%xmm1
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @sin(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store double %0, double* %3
store i32 0, i32* %4
%7 = load double, double* %3
%8 = fcmp olt double %7, 0.000000e+00
br i1 %8, label %9, label %12
9: ; preds = %1
store i32 1, i32* %4
%10 = load double, double* %3
%11 = fmul double %10, -1.000000e+00
store double %11, double* %3
br label %12
12: ; preds = %9, %1
%13 = load double, double* %3
%14 = fcmp ogt double %13, 0x401921FB54442D18
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load double, double* %3
%17 = call double @mod(double %16, double 0x401921FB54442D18)
store double %17, double* %3
br label %18
18: ; preds = %15, %12
%19 = load double, double* %3
%20 = fcmp ogt double %19, 0x3FF921FB54442D18
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load double, double* %3
%23 = fcmp olt double %22, 0x400921FB54442D18
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load double, double* %3
%26 = call double @mod(double %25, double 0x3FF921FB54442D18)
%27 = fsub double 0x3FF921FB54442D18, %26
store double %27, double* %3
br label %46
28: ; preds = %21, %18
%29 = load double, double* %3
%30 = fcmp oge double %29, 0x400921FB54442D18
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load double, double* %3
%33 = fcmp olt double %32, 0x4012D97C7F3321D2
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load double, double* %3
%36 = call double @mod(double %35, double 0x3FF921FB54442D18)
store double %36, double* %3
store i32 1, i32* %4
br label %45
37: ; preds = %31, %28
%38 = load double, double* %3
%39 = fcmp oge double %38, 0x4012D97C7F3321D2
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load double, double* %3
%42 = call double @mod(double %41, double 0x3FF921FB54442D18)
%43 = fsub double 0x3FF921FB54442D18, %42
store double %43, double* %3
store i32 1, i32* %4
br label %44
44: ; preds = %40, %37
br label %45
45: ; preds = %44, %34
br label %46
46: ; preds = %45, %24
store double 0.000000e+00, double* %5
store i32 1, i32* %6
br label %47
47: ; preds = %68, %46
%48 = load i32, i32* %6
%49 = icmp sle i32 %48, 30
br i1 %49, label %50, label %71
50: ; preds = %47
%51 = load i32, i32* %6
%52 = sub nsw i32 %51, 1
%53 = call double @dpow(double -1.000000e+00, i32 %52)
%54 = load double, double* %3
%55 = load i32, i32* %6
%56 = mul nsw i32 2, %55
%57 = sub nsw i32 %56, 1
%58 = call double @dpow(double %54, i32 %57)
%59 = fmul double %53, %58
%60 = load i32, i32* %6
%61 = mul nsw i32 2, %60
%62 = sub nsw i32 %61, 1
%63 = call i64 @fact(i32 %62)
%64 = sitofp i64 %63 to double
%65 = fdiv double %59, %64
%66 = load double, double* %5
%67 = fadd double %66, %65
store double %67, double* %5
br label %68
68: ; preds = %50
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %6
br label %47
71: ; preds = %47
%72 = load i32, i32* %4
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = load double, double* %5
%76 = fmul double -1.000000e+00, %75
store double %76, double* %2
br label %79
77: ; preds = %71
%78 = load double, double* %5
store double %78, double* %2
br label %79
79: ; preds = %77, %74
%80 = load double, double* %2
ret double %80
}

LLVM IR (-O2):
define double @sin(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = fneg double %0
%4 = select i1 %2, double %3, double %0
%5 = fcmp ogt double %4, 0x401921FB54442D18
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call double @mod(double %4, double 0x401921FB54442D18)
br label %8
8: ; preds = %6, %1
%9 = phi double [ %7, %6 ], [ %4, %1 ]
%10 = fcmp ogt double %9, 0x3FF921FB54442D18
%11 = fcmp olt double %9, 0x400921FB54442D18
%12 = and i1 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call double @mod(double %9, double 0x3FF921FB54442D18)
%15 = fsub double 0x3FF921FB54442D18, %14
br label %27
16: ; preds = %8
%17 = fcmp oge double %9, 0x400921FB54442D18
%18 = fcmp olt double %9, 0x4012D97C7F3321D2
%19 = and i1 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call double @mod(double %9, double 0x3FF921FB54442D18)
br label %27
22: ; preds = %16
%23 = fcmp ult double %9, 0x4012D97C7F3321D2
br i1 %23, label %27, label %24
24: ; preds = %22
%25 = tail call double @mod(double %9, double 0x3FF921FB54442D18)
%26 = fsub double 0x3FF921FB54442D18, %25
br label %27
27: ; preds = %20, %24, %22, %13
%28 = phi double [ %15, %13 ], [ %21, %20 ], [ %26, %24 ], [ %9, %22 ]
%29 = phi i1 [ %2, %13 ], [ true, %20 ], [ true, %24 ], [ %2, %22 ]
br label %30
30: ; preds = %27, %30
%31 = phi i32 [ 1, %27 ], [ %43, %30 ]
%32 = phi double [ 0.000000e+00, %27 ], [ %42, %30 ]
%33 = add nsw i32 %31, -1
%34 = tail call double @dpow(double -1.000000e+00, i32 %33)
%35 = shl nuw nsw i32 %31, 1
%36 = add nsw i32 %35, -1
%37 = tail call double @dpow(double %28, i32 %36)
%38 = fmul double %34, %37
%39 = tail call i64 @fact(i32 %36)
%40 = sitofp i64 %39 to double
%41 = fdiv double %38, %40
%42 = fadd double %32, %41
%43 = add nuw nsw i32 %31, 1
%44 = icmp eq i32 %43, 31
br i1 %44, label %45, label %30
45: ; preds = %30
%46 = fneg double %42
%47 = select i1 %29, double %46, double %42
ret double %47
}