#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 my_abs(double);
int my_fact(int);
int my_pow(double, int);
double my_cos(double x) {
  int i = 1;
  double ans = 0;
  double calc = 1;
  x = my_abs(x);
  if (x > 3.14159265358979 * 2)
    x = x - (int)(x / (3.14159265358979 * 2)) * 3.14159265358979 * 2;
  while (my_abs(calc) > 0.000001) {
    ans += calc;
    calc = (1 - (i % 2) * 2) * my_pow(x, 2 * i) / my_fact(2 * i);
    ++i;
  }
  return ans;
}


x86 assembly (clang, -O0):
<my_cos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <my_abs@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe8b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11cd <my_cos+0x9d>
movsd  -0x8(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
movsd  0xe6f(%rip),%xmm2
divsd  %xmm2,%xmm0
cvttsd2si %xmm0,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe6b(%rip),%xmm2
mulsd  %xmm2,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d2 <my_cos+0xa2>
movsd  -0x20(%rbp),%xmm0
call   1030 <my_abs@plt>
movsd  0xe34(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    125a <my_cos+0x12a>
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
shl    $0x1,%edx
mov    $0x1,%eax
sub    %edx,%eax
mov    %eax,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%edi
shl    $0x1,%edi
call   1040 <my_pow@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%edi
shl    $0x1,%edi
call   1050 <my_fact@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d2 <my_cos+0xa2>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_cos>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
call   1030 <my_abs@plt>
ucomisd 0xebb(%rip),%xmm0
jbe    116b <my_cos+0x3b>
movapd %xmm0,%xmm1
divsd  0xead(%rip),%xmm1
cvttpd2dq %xmm1,%xmm1
cvtdq2pd %xmm1,%xmm1
mulsd  0xea5(%rip),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
movsd  0xe97(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1030 <my_abs@plt>
xorpd  %xmm1,%xmm1
ucomisd 0xe89(%rip),%xmm0
jbe    11fd <my_cos+0xcd>
xorpd  %xmm1,%xmm1
mov    $0x2,%ebx
nopw   0x0(%rax,%rax,1)
addsd  (%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %ebx,%eax
and    $0x2,%eax
mov    $0x1,%r14d
sub    %eax,%r14d
movaps 0x10(%rsp),%xmm0
mov    %ebx,%edi
call   1040 <my_pow@plt>
mov    %eax,%ebp
imul   %r14d,%ebp
mov    %ebx,%edi
call   1050 <my_fact@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
call   1030 <my_abs@plt>
movsd  0x8(%rsp),%xmm1
add    $0x2,%ebx
ucomisd 0xe1d(%rip),%xmm0
ja     11a0 <my_cos+0x70>
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @my_cos(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store double %0, double* %2
store i32 1, i32* %3
store double 0.000000e+00, double* %4
store double 1.000000e+00, double* %5
%6 = load double, double* %2
%7 = call double @my_abs(double %6)
store double %7, double* %2
%8 = load double, double* %2
%9 = fcmp ogt double %8, 0x401921FB54442D11
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = load double, double* %2
%12 = load double, double* %2
%13 = fdiv double %12, 0x401921FB54442D11
%14 = fptosi double %13 to i32
%15 = sitofp i32 %14 to double
%16 = fmul double %15, 0x400921FB54442D11
%17 = fneg double %16
%18 = call double @llvm.fmuladd.f64(double %17, double 2.000000e+00, double %11)
store double %18, double* %2
br label %19
19: ; preds = %10, %1
br label %20
20: ; preds = %24, %19
%21 = load double, double* %5
%22 = call double @my_abs(double %21)
%23 = fcmp ogt double %22, 0x3EB0C6F7A0B5ED8D
br i1 %23, label %24, label %44
24: ; preds = %20
%25 = load double, double* %5
%26 = load double, double* %4
%27 = fadd double %26, %25
store double %27, double* %4
%28 = load i32, i32* %3
%29 = srem i32 %28, 2
%30 = mul nsw i32 %29, 2
%31 = sub nsw i32 1, %30
%32 = load double, double* %2
%33 = load i32, i32* %3
%34 = mul nsw i32 2, %33
%35 = call i32 @my_pow(double %32, i32 %34)
%36 = mul nsw i32 %31, %35
%37 = load i32, i32* %3
%38 = mul nsw i32 2, %37
%39 = call i32 @my_fact(i32 %38)
%40 = sdiv i32 %36, %39
%41 = sitofp i32 %40 to double
store double %41, double* %5
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %20
44: ; preds = %20
%45 = load double, double* %4
ret double %45
}

LLVM IR (-O2):
define double @my_cos(double %0) {
%2 = tail call double @my_abs(double %0)
%3 = fcmp ogt double %2, 0x401921FB54442D11
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = fdiv double %2, 0x401921FB54442D11
%6 = fptosi double %5 to i32
%7 = sitofp i32 %6 to double
%8 = fmul double %7, 0xC00921FB54442D11
%9 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+00, double %2)
br label %10
10: ; preds = %4, %1
%11 = phi double [ %9, %4 ], [ %2, %1 ]
%12 = tail call double @my_abs(double 1.000000e+00)
%13 = fcmp ogt double %12, 0x3EB0C6F7A0B5ED8D
br i1 %13, label %14, label %30
14: ; preds = %10, %14
%15 = phi double [ %26, %14 ], [ 1.000000e+00, %10 ]
%16 = phi double [ %18, %14 ], [ 0.000000e+00, %10 ]
%17 = phi i32 [ %27, %14 ], [ 1, %10 ]
%18 = fadd double %16, %15
%19 = shl nuw i32 %17, 1
%20 = and i32 %19, 2
%21 = sub nsw i32 1, %20
%22 = tail call i32 @my_pow(double %11, i32 %19)
%23 = mul nsw i32 %22, %21
%24 = tail call i32 @my_fact(i32 %19)
%25 = sdiv i32 %23, %24
%26 = sitofp i32 %25 to double
%27 = add nuw nsw i32 %17, 1
%28 = tail call double @my_abs(double %26)
%29 = fcmp ogt double %28, 0x3EB0C6F7A0B5ED8D
br i1 %29, label %14, label %30
30: ; preds = %14, %10
%31 = phi double [ 0.000000e+00, %10 ], [ %18, %14 ]
ret double %31
}