#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 DBL_EPSILON;
double DBL_MAX;
scalar_t__ M_PI_2;
double M_PI_4;
double NAN;
scalar_t__ _double_approx_eq(double, double, double);
double _factorial(int);
double _mod_unit_circle_radians(double);
double _pow(double, int);
scalar_t__ isfinite(double);
scalar_t__ isnan(double);
double sine_taylor(scalar_t__);
double cosine_taylor(double radians) {
  double x, y, s, t, b, v, last_y;
  size_t n;
  double tolerance;
  ((void)(0));
  if (isnan(radians)) {
    return radians;
  }
  if (isfinite(radians) == 0) {
    return NAN;
  }
  x = _mod_unit_circle_radians(radians);
  if (((x > (1.0 * M_PI_4)) && (x < (3.0 * M_PI_4))) ||
      ((x > (5.0 * M_PI_4)) && (x < (7.0 * M_PI_4)))) {
    return sine_taylor(M_PI_2 - x);
  }
  last_y = -DBL_MAX;
  y = 0;
  tolerance = (1.1 * DBL_EPSILON);
  for (n = 0; n <= 400U; ++n) {
    last_y = y;
    s = (n % 2 == 0) ? 1.0 : -1.0;
    t = _pow(x, (2 * n));
    b = _factorial((2 * n));
    v = ((s * t) / b);
    y = y + v;
    ((void)(0));
    ((void)(0));
    ((void)(0));
    ((void)(0));
    ((void)(0));
    ((void)(0));
    ((void)(0));
    ((void)(0));
    if (n >= 5U && _double_approx_eq(last_y, y, tolerance)) {
      break;
    }
  }
  ((void)(0));
  return y;
}


x86 assembly (clang, -O0):
<cosine_taylor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1090 <isnan@plt>
cmp    $0x0,%rax
je     11a0 <cosine_taylor+0x30>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13ca <cosine_taylor+0x25a>
movsd  -0x10(%rbp),%xmm0
call   1080 <isfinite@plt>
cmp    $0x0,%rax
jne    11c9 <cosine_taylor+0x59>
mov    0x2e3d(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13ca <cosine_taylor+0x25a>
movsd  -0x10(%rbp),%xmm0
call   1030 <_mod_unit_circle_radians@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
mov    0x2df4(%rip),%rax
mulsd  (%rax),%xmm1
ucomisd %xmm1,%xmm0
jbe    121c <cosine_taylor+0xac>
movsd  -0x18(%rbp),%xmm1
movsd  0xe01(%rip),%xmm0
mov    0x2dd2(%rip),%rax
mulsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
ja     1260 <cosine_taylor+0xf0>
movsd  -0x18(%rbp),%xmm0
movsd  0xde7(%rip),%xmm1
mov    0x2db0(%rip),%rax
mulsd  (%rax),%xmm1
ucomisd %xmm1,%xmm0
jbe    1285 <cosine_taylor+0x115>
movsd  -0x18(%rbp),%xmm1
movsd  0xdcd(%rip),%xmm0
mov    0x2d8e(%rip),%rax
mulsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    1285 <cosine_taylor+0x115>
mov    0x2d71(%rip),%rax
cvtsi2sdq (%rax),%xmm0
subsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%rdi
call   1060 <sine_taylor@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    13ca <cosine_taylor+0x25a>
mov    0x2d34(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xd64(%rip),%xmm0
mov    0x2d0d(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x190,-0x50(%rbp)
ja     13c0 <cosine_taylor+0x250>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x50(%rbp),%rax
and    $0x1,%rax
movsd  0xd04(%rip),%xmm0
movsd  0xd24(%rip),%xmm1
movsd  %xmm1,-0x68(%rbp)
cmp    $0x0,%rax
movsd  %xmm0,-0x60(%rbp)
je     1322 <cosine_taylor+0x1b2>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x50(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1050 <_pow@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x50(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1070 <_factorial@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpq   $0x5,-0x50(%rbp)
jb     13aa <cosine_taylor+0x23a>
movsd  -0x48(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm2
call   1040 <_double_approx_eq@plt>
cmp    $0x0,%rax
je     13aa <cosine_taylor+0x23a>
jmp    13c0 <cosine_taylor+0x250>
jmp    13af <cosine_taylor+0x23f>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    12d4 <cosine_taylor+0x164>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cosine_taylor>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movapd %xmm0,(%rsp)
call   1090 <isnan@plt>
test   %rax,%rax
je     1196 <cosine_taylor+0x26>
movaps (%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
movapd (%rsp),%xmm0
call   1080 <isfinite@plt>
test   %rax,%rax
je     1216 <cosine_taylor+0xa6>
movapd (%rsp),%xmm0
call   1030 <_mod_unit_circle_radians@plt>
mov    0x2e2a(%rip),%rax
movsd  (%rax),%xmm2
ucomisd %xmm2,%xmm0
jbe    11d2 <cosine_taylor+0x62>
movsd  0xe38(%rip),%xmm1
mulsd  %xmm2,%xmm1
ucomisd %xmm0,%xmm1
ja     11f2 <cosine_taylor+0x82>
movsd  0xe2e(%rip),%xmm1
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    1226 <cosine_taylor+0xb6>
mulsd  0xe24(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    1226 <cosine_taylor+0xb6>
mov    0x2ddf(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdq (%rax),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1060 <sine_taylor@plt>
mov    0x2ddb(%rip),%rax
movsd  (%rax),%xmm1
jmp    118a <cosine_taylor+0x1a>
mov    0x2da3(%rip),%rax
movsd  (%rax),%xmm1
mulsd  0xddf(%rip),%xmm1
movsd  %xmm1,0x18(%rsp)
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %r14d,%r14d
xor    %ebx,%ebx
movsd  %xmm0,0x20(%rsp)
jmp    1274 <cosine_taylor+0x104>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0x2,%r14d
movsd  %xmm1,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
mov    %r14d,%edi
call   1050 <_pow@plt>
movapd %xmm0,(%rsp)
mov    %r14d,%edi
call   1070 <_factorial@plt>
test   $0x1,%bl
je     12a0 <cosine_taylor+0x130>
movapd (%rsp),%xmm1
xorpd  0xd85(%rip),%xmm1
jmp    12a5 <cosine_taylor+0x135>
nopl   (%rax)
movapd (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm0,%xmm1
cmp    $0x5,%rbx
jb     1260 <cosine_taylor+0xf0>
movapd %xmm1,(%rsp)
movsd  0x18(%rsp),%xmm2
call   1040 <_double_approx_eq@plt>
test   %rax,%rax
jne    1186 <cosine_taylor+0x16>
cmp    $0x18f,%rbx
movapd (%rsp),%xmm1
jbe    1260 <cosine_taylor+0xf0>
jmp    118a <cosine_taylor+0x1a>

LLVM IR (-O0):
@NAN = global double 0.000000e+00
@M_PI_4 = global double 0.000000e+00
@M_PI_2 = global i64 0
@DBL_MAX = global double 0.000000e+00
@DBL_EPSILON = global double 0.000000e+00
define double @cosine_taylor(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i64
%12 = alloca double
store double %0, double* %3
%13 = load double, double* %3
%14 = call i64 @isnan(double %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = load double, double* %3
store double %17, double* %2
br label %100
18: ; preds = %1
%19 = load double, double* %3
%20 = call i64 @isfinite(double %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load double, double* @NAN
store double %23, double* %2
br label %100
24: ; preds = %18
%25 = load double, double* %3
%26 = call double @_mod_unit_circle_radians(double %25)
store double %26, double* %4
%27 = load double, double* %4
%28 = load double, double* @M_PI_4
%29 = fmul double 1.000000e+00, %28
%30 = fcmp ogt double %27, %29
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load double, double* %4
%33 = load double, double* @M_PI_4
%34 = fmul double 3.000000e+00, %33
%35 = fcmp olt double %32, %34
br i1 %35, label %46, label %36
36: ; preds = %31, %24
%37 = load double, double* %4
%38 = load double, double* @M_PI_4
%39 = fmul double 5.000000e+00, %38
%40 = fcmp ogt double %37, %39
br i1 %40, label %41, label %53
41: ; preds = %36
%42 = load double, double* %4
%43 = load double, double* @M_PI_4
%44 = fmul double 7.000000e+00, %43
%45 = fcmp olt double %42, %44
br i1 %45, label %46, label %53
46: ; preds = %41, %31
%47 = load i64, i64* @M_PI_2
%48 = sitofp i64 %47 to double
%49 = load double, double* %4
%50 = fsub double %48, %49
%51 = fptosi double %50 to i64
%52 = call double @sine_taylor(i64 %51)
store double %52, double* %2
br label %100
53: ; preds = %41, %36
%54 = load double, double* @DBL_MAX
%55 = fneg double %54
store double %55, double* %10
store double 0.000000e+00, double* %5
%56 = load double, double* @DBL_EPSILON
%57 = fmul double 1.100000e+00, %56
store double %57, double* %12
store i64 0, i64* %11
br label %58
58: ; preds = %95, %53
%59 = load i64, i64* %11
%60 = icmp ule i64 %59, 400
br i1 %60, label %61, label %98
61: ; preds = %58
%62 = load double, double* %5
store double %62, double* %10
%63 = load i64, i64* %11
%64 = urem i64 %63, 2
%65 = icmp eq i64 %64, 0
%66 = zext i1 %65 to i64
%67 = select i1 %65, double 1.000000e+00, double -1.000000e+00
store double %67, double* %6
%68 = load double, double* %4
%69 = load i64, i64* %11
%70 = mul i64 2, %69
%71 = trunc i64 %70 to i32
%72 = call double @_pow(double %68, i32 %71)
store double %72, double* %7
%73 = load i64, i64* %11
%74 = mul i64 2, %73
%75 = trunc i64 %74 to i32
%76 = call double @_factorial(i32 %75)
store double %76, double* %8
%77 = load double, double* %6
%78 = load double, double* %7
%79 = fmul double %77, %78
%80 = load double, double* %8
%81 = fdiv double %79, %80
store double %81, double* %9
%82 = load double, double* %5
%83 = load double, double* %9
%84 = fadd double %82, %83
store double %84, double* %5
%85 = load i64, i64* %11
%86 = icmp uge i64 %85, 5
br i1 %86, label %87, label %94
87: ; preds = %61
%88 = load double, double* %10
%89 = load double, double* %5
%90 = load double, double* %12
%91 = call i64 @_double_approx_eq(double %88, double %89, double %90)
%92 = icmp ne i64 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %87
br label %98
94: ; preds = %87, %61
br label %95
95: ; preds = %94
%96 = load i64, i64* %11
%97 = add i64 %96, 1
store i64 %97, i64* %11
br label %58
98: ; preds = %93, %58
%99 = load double, double* %5
store double %99, double* %2
br label %100
100: ; preds = %98, %46, %22, %16
%101 = load double, double* %2
ret double %101
}

LLVM IR (-O2):
@NAN = global double 0.000000e+00
@M_PI_4 = global double 0.000000e+00
@M_PI_2 = global i64 0
@DBL_MAX = global double 0.000000e+00
@DBL_EPSILON = global double 0.000000e+00
define double @cosine_taylor(double %0) {
%2 = tail call i64 @isnan(double %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %52
4: ; preds = %1
%5 = tail call i64 @isfinite(double %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = load double, double* @NAN
br label %52
9: ; preds = %4
%10 = tail call double @_mod_unit_circle_radians(double %0)
%11 = load double, double* @M_PI_4
%12 = fcmp ogt double %10, %11
%13 = fmul double %11, 3.000000e+00
%14 = fcmp olt double %10, %13
%15 = and i1 %12, %14
br i1 %15, label %22, label %16
16: ; preds = %9
%17 = fmul double %11, 5.000000e+00
%18 = fcmp ogt double %10, %17
%19 = fmul double %11, 7.000000e+00
%20 = fcmp olt double %10, %19
%21 = and i1 %18, %20
br i1 %21, label %22, label %28
22: ; preds = %16, %9
%23 = load i64, i64* @M_PI_2
%24 = sitofp i64 %23 to double
%25 = fsub double %24, %10
%26 = fptosi double %25 to i64
%27 = tail call double @sine_taylor(i64 %26)
br label %52
28: ; preds = %16
%29 = load double, double* @DBL_EPSILON
%30 = fmul double %29, 1.100000e+00
br label %31
31: ; preds = %50, %28
%32 = phi i64 [ 0, %28 ], [ %51, %50 ]
%33 = phi double [ 0.000000e+00, %28 ], [ %43, %50 ]
%34 = and i64 %32, 1
%35 = icmp eq i64 %34, 0
%36 = trunc i64 %32 to i32
%37 = shl nuw nsw i32 %36, 1
%38 = tail call double @_pow(double %10, i32 %37)
%39 = tail call double @_factorial(i32 %37)
%40 = fneg double %38
%41 = select i1 %35, double %38, double %40
%42 = fdiv double %41, %39
%43 = fadd double %33, %42
%44 = icmp ugt i64 %32, 4
br i1 %44, label %45, label %50
45: ; preds = %31
%46 = tail call i64 @_double_approx_eq(double %33, double %43, double %30)
%47 = icmp eq i64 %46, 0
%48 = icmp ult i64 %32, 400
%49 = select i1 %47, i1 %48, i1 false
br i1 %49, label %50, label %52
50: ; preds = %31, %45
%51 = add nuw nsw i64 %32, 1
br label %31
52: ; preds = %45, %1, %22, %7
%53 = phi double [ %8, %7 ], [ %27, %22 ], [ %0, %1 ], [ %43, %45 ]
ret double %53
}