#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 fmod(double, int);
double mycos(double x) {
  double EPS = 1e-08;
  double s = 1.0, e = 1.0, d;
  int k;
  x = fmod(x, 2 * 3.14159265358979);
  for (k = 1; k <= 200; k = k + 2) {
    d = s;
    e = -e * x * x / (k * (k + 1));
    s = s + e;
    if (fabs(s - d) < EPS * fabs(d)) {
      return s;
    }
  }
  return 9999.0;
}


x86 assembly (clang, -O0):
<mycos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xee3(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xece(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    $0x6,%edi
call   1030 <fmod@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x34(%rbp)
cmpl   $0xc8,-0x34(%rbp)
jg     121e <mycos+0x10e>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mov    -0x34(%rbp),%eax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
movaps 0xe4b(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movaps 0xe36(%rip),%xmm3
pand   %xmm3,%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    120b <mycos+0xfb>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122b <mycos+0x11b>
jmp    1210 <mycos+0x100>
mov    -0x34(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
jmp    115f <mycos+0x4f>
movsd  0xdea(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mycos>:
push   %rax
mov    $0x6,%edi
call   1030 <fmod@plt>
movsd  0xedd(%rip),%xmm2
mov    $0xffffffff,%eax
movapd 0xef0(%rip),%xmm3
movapd 0xef8(%rip),%xmm4
movsd  0xec8(%rip),%xmm6
movsd  0xec7(%rip),%xmm8
movapd %xmm2,%xmm1
nopl   (%rax)
movapd %xmm1,%xmm7
mov    %eax,%ecx
xorpd  %xmm3,%xmm2
lea    0x2(%rcx),%eax
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
add    $0x3,%ecx
imul   %eax,%ecx
xorps  %xmm5,%xmm5
cvtsi2sd %ecx,%xmm5
divsd  %xmm5,%xmm2
addsd  %xmm2,%xmm1
movapd %xmm1,%xmm5
subsd  %xmm7,%xmm5
andpd  %xmm4,%xmm5
andpd  %xmm4,%xmm7
mulsd  %xmm6,%xmm7
ucomisd %xmm5,%xmm7
ja     11a0 <mycos+0x90>
cmp    $0xc6,%eax
jbe    1150 <mycos+0x40>
movapd %xmm8,%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @mycos(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store double %0, double* %3
store double 1.000000e-08, double* %4
store double 1.000000e+00, double* %5
store double 1.000000e+00, double* %6
%9 = load double, double* %3
%10 = call double @fmod(double %9, i32 6)
store double %10, double* %3
store i32 1, i32* %8
br label %11
11: ; preds = %43, %1
%12 = load i32, i32* %8
%13 = icmp sle i32 %12, 200
br i1 %13, label %14, label %46
14: ; preds = %11
%15 = load double, double* %5
store double %15, double* %7
%16 = load double, double* %6
%17 = fneg double %16
%18 = load double, double* %3
%19 = fmul double %17, %18
%20 = load double, double* %3
%21 = fmul double %19, %20
%22 = load i32, i32* %8
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
%25 = mul nsw i32 %22, %24
%26 = sitofp i32 %25 to double
%27 = fdiv double %21, %26
store double %27, double* %6
%28 = load double, double* %5
%29 = load double, double* %6
%30 = fadd double %28, %29
store double %30, double* %5
%31 = load double, double* %5
%32 = load double, double* %7
%33 = fsub double %31, %32
%34 = call double @llvm.fabs.f64(double %33)
%35 = load double, double* %4
%36 = load double, double* %7
%37 = call double @llvm.fabs.f64(double %36)
%38 = fmul double %35, %37
%39 = fcmp olt double %34, %38
br i1 %39, label %40, label %42
40: ; preds = %14
%41 = load double, double* %5
store double %41, double* %2
br label %47
42: ; preds = %14
br label %43
43: ; preds = %42
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 2
store i32 %45, i32* %8
br label %11
46: ; preds = %11
store double 9.999000e+03, double* %2
br label %47
47: ; preds = %46, %40
%48 = load double, double* %2
ret double %48
}

LLVM IR (-O2):
define double @mycos(double %0) {
%2 = tail call double @fmod(double %0, i32 6)
br label %6
3: ; preds = %6
%4 = add nuw nsw i32 %7, 2
%5 = icmp ult i32 %7, 199
br i1 %5, label %6, label %23
6: ; preds = %1, %3
%7 = phi i32 [ 1, %1 ], [ %4, %3 ]
%8 = phi double [ 1.000000e+00, %1 ], [ %16, %3 ]
%9 = phi double [ 1.000000e+00, %1 ], [ %17, %3 ]
%10 = fneg double %8
%11 = fmul double %2, %10
%12 = fmul double %2, %11
%13 = add nuw nsw i32 %7, 1
%14 = mul nuw nsw i32 %13, %7
%15 = sitofp i32 %14 to double
%16 = fdiv double %12, %15
%17 = fadd double %9, %16
%18 = fsub double %17, %9
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = tail call double @llvm.fabs.f64(double %9)
%21 = fmul double %20, 1.000000e-08
%22 = fcmp olt double %19, %21
br i1 %22, label %23, label %3
23: ; preds = %3, %6
%24 = phi double [ %17, %6 ], [ 9.999000e+03, %3 ]
ret double %24
}