#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 fabs(double);
double fmod(double, double);
double cos(double x) {
  double t, s;
  int p;
  p = 0;
  s = 1.0;
  t = 1.0;
  x = fmod(x + 3.14159265358979323846, 3.14159265358979323846 * 2) -
      3.14159265358979323846;
  double xsqr = x * x;
  double ab = 1;
  while ((ab > 1e-16) && (p < 15)) {
    p++;
    t = (-t * xsqr) / (((p << 1) - 1) * (p << 1));
    s += t;
    ab = (s == 0) ? 1 : fabs(t / s);
  }
  return s;
}


x86 assembly (clang, -O0):
<cos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
movsd  0xec4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb7(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xeb2(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  0xead(%rip),%xmm1
call   1030 <fmod@plt>
movsd  0xe98(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe70(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xor    %eax,%eax
movsd  0xe74(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jbe    11bb <cos+0x9b>
cmpl   $0xf,-0x1c(%rbp)
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11cb <cos+0xab>
jmp    126b <cos+0x14b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x28(%rbp),%xmm0
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
sub    $0x1,%eax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1248 <cos+0x128>
jp     1248 <cos+0x128>
mov    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    125a <cos+0x13a>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1195 <cos+0x75>
movsd  -0x18(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cos>:
push   %r14
push   %rbx
sub    $0x28,%rsp
addsd  0xed1(%rip),%xmm0
movsd  0xed1(%rip),%xmm1
call   1030 <fmod@plt>
movapd %xmm0,%xmm1
addsd  0xec8(%rip),%xmm1
mulsd  %xmm1,%xmm1
xor    %r14d,%r14d
movsd  0xec1(%rip),%xmm2
mov    $0x1,%ebx
movapd 0xebc(%rip),%xmm3
xorpd  %xmm4,%xmm4
movapd %xmm2,%xmm5
movsd  %xmm1,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorpd  %xmm3,%xmm2
mulsd  %xmm1,%xmm2
lea    0x1(%rbx),%eax
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm2
addsd  %xmm2,%xmm5
ucomisd %xmm4,%xmm5
mov    $0x1,%eax
jne    11aa <cos+0x8a>
jnp    11e0 <cos+0xc0>
movapd %xmm2,%xmm0
divsd  %xmm5,%xmm0
movapd %xmm2,0x10(%rsp)
movsd  %xmm5,0x8(%rsp)
call   1040 <fabs@plt>
movsd  0x8(%rsp),%xmm5
xorpd  %xmm4,%xmm4
movapd 0xe4b(%rip),%xmm3
movapd 0x10(%rsp),%xmm2
movsd  (%rsp),%xmm1
test   %eax,%eax
jle    11f4 <cos+0xd4>
add    $0x2,%ebx
lea    0x1(%r14),%eax
cmp    $0xe,%r14d
mov    %eax,%r14d
jb     1180 <cos+0x60>
movapd %xmm5,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @cos(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
%7 = alloca double
store double %0, double* %2
store i32 0, i32* %5
store double 1.000000e+00, double* %4
store double 1.000000e+00, double* %3
%8 = load double, double* %2
%9 = fadd double %8, 0x400921FB54442D18
%10 = call double @fmod(double %9, double 0x401921FB54442D18)
%11 = fsub double %10, 0x400921FB54442D18
store double %11, double* %2
%12 = load double, double* %2
%13 = load double, double* %2
%14 = fmul double %12, %13
store double %14, double* %6
store double 1.000000e+00, double* %7
br label %15
15: ; preds = %49, %1
%16 = load double, double* %7
%17 = fcmp ogt double %16, 0x3C9CD2B297D889BC
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 15
br label %21
21: ; preds = %18, %15
%22 = phi i1 [ false, %15 ], [ %20, %18 ]
br i1 %22, label %23, label %52
23: ; preds = %21
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
%26 = load double, double* %3
%27 = fneg double %26
%28 = load double, double* %6
%29 = fmul double %27, %28
%30 = load i32, i32* %5
%31 = shl i32 %30, 1
%32 = sub nsw i32 %31, 1
%33 = load i32, i32* %5
%34 = shl i32 %33, 1
%35 = mul nsw i32 %32, %34
%36 = sitofp i32 %35 to double
%37 = fdiv double %29, %36
store double %37, double* %3
%38 = load double, double* %3
%39 = load double, double* %4
%40 = fadd double %39, %38
store double %40, double* %4
%41 = load double, double* %4
%42 = fcmp oeq double %41, 0.000000e+00
br i1 %42, label %43, label %44
43: ; preds = %23
br label %49
44: ; preds = %23
%45 = load double, double* %3
%46 = load double, double* %4
%47 = fdiv double %45, %46
%48 = call i32 @fabs(double %47)
br label %49
49: ; preds = %44, %43
%50 = phi i32 [ 1, %43 ], [ %48, %44 ]
%51 = sitofp i32 %50 to double
store double %51, double* %7
br label %15
52: ; preds = %21
%53 = load double, double* %4
ret double %53
}

LLVM IR (-O2):
define double @cos(double %0) {
%2 = fadd double %0, 0x400921FB54442D18
%3 = tail call double @fmod(double %2, double 0x401921FB54442D18)
%4 = fadd double %3, 0xC00921FB54442D18
%5 = fmul double %4, %4
br label %6
6: ; preds = %1, %23
%7 = phi double [ 1.000000e+00, %1 ], [ %17, %23 ]
%8 = phi i32 [ 0, %1 ], [ %10, %23 ]
%9 = phi double [ 1.000000e+00, %1 ], [ %18, %23 ]
%10 = add nuw nsw i32 %8, 1
%11 = fneg double %7
%12 = fmul double %5, %11
%13 = shl nuw nsw i32 %10, 1
%14 = add nsw i32 %13, -1
%15 = mul nuw nsw i32 %14, %13
%16 = sitofp i32 %15 to double
%17 = fdiv double %12, %16
%18 = fadd double %9, %17
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %23, label %20
20: ; preds = %6
%21 = fdiv double %17, %18
%22 = tail call i32 @fabs(double %21)
br label %23
23: ; preds = %6, %20
%24 = phi i32 [ %22, %20 ], [ 1, %6 ]
%25 = icmp sgt i32 %24, 0
%26 = icmp ult i32 %8, 14
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %6, label %28
28: ; preds = %23
ret double %18
}