#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 lrintf(float);
double mycos(double f) {
  double f2;
  double co;
  int i1;
  i1 = lrintf((float)(f * 0.63661977236758134308));
  if (i1 & 1)
    i1++;
  f -= i1 * 1.57079632679489661923;
  f2 = f * f;
  co = 1.0 + f2 * (-0.4999999963 +
                   f2 * (0.0416666418 +
                         f2 * (-0.0013888397 +
                               f2 * (0.0000247609 - f2 * 0.0000002605))));
  return ((i1 & 2) ? -co : co);
}


x86 assembly (clang, -O0):
<mycos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xedb(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <lrintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     114e <mycos+0x3e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xec1(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm4
movq   %xmm4,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm4
movsd  0xe5d(%rip),%xmm5
mulsd  %xmm5,%xmm4
movsd  0xe59(%rip),%xmm5
addsd  %xmm5,%xmm4
mulsd  %xmm4,%xmm3
movsd  0xe39(%rip),%xmm4
addsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm2
movsd  0xe21(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe09(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdf1(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1255 <mycos+0x145>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    125f <mycos+0x14f>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mycos>:
push   %rax
movsd  %xmm0,(%rsp)
movsd  0xee2(%rip),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
call   1030 <lrintf@plt>
mov    %eax,%ecx
and    $0x1,%ecx
add    %eax,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
mulsd  0xec4(%rip),%xmm1
addsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
movsd  0xebb(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xeb7(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xeb3(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xeaf(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xeab(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xea7(%rip),%xmm0
test   $0x2,%cl
je     119e <mycos+0x8e>
xorpd  0xea2(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @mycos(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %2
%6 = load double, double* %2
%7 = fmul double %6, 0x3FE45F306DC9C883
%8 = fptrunc double %7 to float
%9 = call i32 @lrintf(float %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = and i32 %10, 1
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
br label %16
16: ; preds = %13, %1
%17 = load i32, i32* %5
%18 = sitofp i32 %17 to double
%19 = load double, double* %2
%20 = fneg double %18
%21 = call double @llvm.fmuladd.f64(double %20, double 0x3FF921FB54442D18, double %19)
store double %21, double* %2
%22 = load double, double* %2
%23 = load double, double* %2
%24 = fmul double %22, %23
store double %24, double* %3
%25 = load double, double* %3
%26 = load double, double* %3
%27 = load double, double* %3
%28 = load double, double* %3
%29 = load double, double* %3
%30 = fneg double %29
%31 = call double @llvm.fmuladd.f64(double %30, double 2.605000e-07, double 2.476090e-05)
%32 = call double @llvm.fmuladd.f64(double %28, double %31, double 0xBF56C13745D11568)
%33 = call double @llvm.fmuladd.f64(double %27, double %32, double 0x3FA555547FBAF47E)
%34 = call double @llvm.fmuladd.f64(double %26, double %33, double 0xBFDFFFFFFC06F3A6)
%35 = call double @llvm.fmuladd.f64(double %25, double %34, double 1.000000e+00)
store double %35, double* %4
%36 = load i32, i32* %5
%37 = and i32 %36, 2
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %16
%40 = load double, double* %4
%41 = fneg double %40
br label %44
42: ; preds = %16
%43 = load double, double* %4
br label %44
44: ; preds = %42, %39
%45 = phi double [ %41, %39 ], [ %43, %42 ]
ret double %45
}

LLVM IR (-O2):
define double @mycos(double %0) {
%2 = fmul double %0, 0x3FE45F306DC9C883
%3 = fptrunc double %2 to float
%4 = tail call i32 @lrintf(float %3)
%5 = and i32 %4, 1
%6 = add nsw i32 %5, %4
%7 = sitofp i32 %6 to double
%8 = fneg double %7
%9 = tail call double @llvm.fmuladd.f64(double %8, double 0x3FF921FB54442D18, double %0)
%10 = fmul double %9, %9
%11 = fneg double %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double 2.605000e-07, double 2.476090e-05)
%13 = tail call double @llvm.fmuladd.f64(double %10, double %12, double 0xBF56C13745D11568)
%14 = tail call double @llvm.fmuladd.f64(double %10, double %13, double 0x3FA555547FBAF47E)
%15 = tail call double @llvm.fmuladd.f64(double %10, double %14, double 0xBFDFFFFFFC06F3A6)
%16 = tail call double @llvm.fmuladd.f64(double %10, double %15, double 1.000000e+00)
%17 = and i32 %6, 2
%18 = icmp eq i32 %17, 0
%19 = fneg double %16
%20 = select i1 %18, double %16, double %19
ret double %20
}