#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 M_1_PI;
double mla(double, double, double);
scalar_t__ xrint(double);
double xcos(double d) {
  int q;
  double u, s;
  q = 1 + 2 * (int)xrint(d * M_1_PI - 0.5);
  d = mla(q, -0.78539816290140151978 * 2, d);
  d = mla(q, -4.9604678871439933374e-10 * 2, d);
  d = mla(q, -1.1258708853173288931e-18 * 2, d);
  d = mla(q, -1.7607799325916000908e-27 * 2, d);
  s = d * d;
  if ((q & 2) == 0)
    d = -d;
  u = -7.97255955009037868891952e-18;
  u = mla(u, s, 2.81009972710863200091251e-15);
  u = mla(u, s, -7.64712219118158833288484e-13);
  u = mla(u, s, 1.60590430605664501629054e-10);
  u = mla(u, s, -2.50521083763502045810755e-08);
  u = mla(u, s, 2.75573192239198747630416e-06);
  u = mla(u, s, -0.000198412698412696162806809);
  u = mla(u, s, 0.00833333333333332974823815);
  u = mla(u, s, -0.166666666666666657414808);
  u = mla(s, u * d, d);
  return u;
}


x86 assembly (clang, -O0):
<xcos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2ea7(%rip),%rax
movsd  (%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xed7(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <xrint@plt>
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  0xeab(%rip),%xmm1
call   1040 <mla@plt>
movsd  %xmm0,-0x8(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  0xe87(%rip),%xmm1
call   1040 <mla@plt>
movsd  %xmm0,-0x8(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  0xe63(%rip),%xmm1
call   1040 <mla@plt>
movsd  %xmm0,-0x8(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  0xe3f(%rip),%xmm1
call   1040 <mla@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    120a <xcos+0xea>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xe56(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xe37(%rip),%xmm2
call   1040 <mla@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xe13(%rip),%xmm2
call   1040 <mla@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xdef(%rip),%xmm2
call   1040 <mla@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xdcb(%rip),%xmm2
call   1040 <mla@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xda7(%rip),%xmm2
call   1040 <mla@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xd83(%rip),%xmm2
call   1040 <mla@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xd5f(%rip),%xmm2
call   1040 <mla@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xd3b(%rip),%xmm2
call   1040 <mla@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
call   1040 <mla@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcos>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,%xmm1
movsd  %xmm0,0x10(%rsp)
mov    0x2eaa(%rip),%rax
movsd  (%rax),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xeba(%rip),%xmm0
call   1030 <xrint@plt>
mov    %rax,%rbx
add    %eax,%eax
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
movsd  0xea1(%rip),%xmm1
movsd  0x10(%rsp),%xmm2
call   1040 <mla@plt>
movapd %xmm0,%xmm2
movsd  0xe92(%rip),%xmm1
movsd  (%rsp),%xmm0
call   1040 <mla@plt>
movaps %xmm0,%xmm2
movsd  0xe85(%rip),%xmm1
movsd  (%rsp),%xmm0
call   1040 <mla@plt>
movaps %xmm0,%xmm2
movsd  0xe78(%rip),%xmm1
movsd  (%rsp),%xmm0
call   1040 <mla@plt>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
test   $0x1,%bl
jne    11c7 <xcos+0xa7>
xorpd  0xea9(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
movsd  0xe53(%rip),%xmm0
movsd  0xe53(%rip),%xmm2
movapd %xmm1,(%rsp)
call   1040 <mla@plt>
movsd  0xe49(%rip),%xmm2
movaps (%rsp),%xmm1
call   1040 <mla@plt>
movsd  0xe40(%rip),%xmm2
movaps (%rsp),%xmm1
call   1040 <mla@plt>
movsd  0xe37(%rip),%xmm2
movaps (%rsp),%xmm1
call   1040 <mla@plt>
movsd  0xe2e(%rip),%xmm2
movaps (%rsp),%xmm1
call   1040 <mla@plt>
movsd  0xe25(%rip),%xmm2
movaps (%rsp),%xmm1
call   1040 <mla@plt>
movsd  0xe1c(%rip),%xmm2
movaps (%rsp),%xmm1
call   1040 <mla@plt>
movsd  0xe13(%rip),%xmm2
movaps (%rsp),%xmm1
call   1040 <mla@plt>
movapd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm1
movaps (%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
jmp    1040 <mla@plt>

LLVM IR (-O0):
@M_1_PI = global double 0.000000e+00
define double @xcos(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store double %0, double* %2
%6 = load double, double* %2
%7 = load double, double* @M_1_PI
%8 = call double @llvm.fmuladd.f64(double %6, double %7, double -5.000000e-01)
%9 = call i64 @xrint(double %8)
%10 = trunc i64 %9 to i32
%11 = mul nsw i32 2, %10
%12 = add nsw i32 1, %11
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = sitofp i32 %13 to double
%15 = load double, double* %2
%16 = call double @mla(double %14, double 0xBFF921FB54000000, double %15)
store double %16, double* %2
%17 = load i32, i32* %3
%18 = sitofp i32 %17 to double
%19 = load double, double* %2
%20 = call double @mla(double %18, double 0xBE110B4611000000, double %19)
store double %20, double* %2
%21 = load i32, i32* %3
%22 = sitofp i32 %21 to double
%23 = load double, double* %2
%24 = call double @mla(double %22, double 0xBC44C4C662000000, double %23)
store double %24, double* %2
%25 = load i32, i32* %3
%26 = sitofp i32 %25 to double
%27 = load double, double* %2
%28 = call double @mla(double %26, double 0xBA71701B839A2520, double %27)
store double %28, double* %2
%29 = load double, double* %2
%30 = load double, double* %2
%31 = fmul double %29, %30
store double %31, double* %5
%32 = load i32, i32* %3
%33 = and i32 %32, 2
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %1
%36 = load double, double* %2
%37 = fneg double %36
store double %37, double* %2
br label %38
38: ; preds = %35, %1
store double 0xBC62622B22D526BE, double* %4
%39 = load double, double* %4
%40 = load double, double* %5
%41 = call double @mla(double %39, double %40, double 0x3CE94FA618796592)
store double %41, double* %4
%42 = load double, double* %4
%43 = load double, double* %5
%44 = call double @mla(double %42, double %43, double 0xBD6AE7EA531357BF)
store double %44, double* %4
%45 = load double, double* %4
%46 = load double, double* %5
%47 = call double @mla(double %45, double %46, double 0x3DE6124601C23966)
store double %47, double* %4
%48 = load double, double* %4
%49 = load double, double* %5
%50 = call double @mla(double %48, double %49, double 0xBE5AE64567CB5786)
store double %50, double* %4
%51 = load double, double* %4
%52 = load double, double* %5
%53 = call double @mla(double %51, double %52, double 0x3EC71DE3A5568A50)
store double %53, double* %4
%54 = load double, double* %4
%55 = load double, double* %5
%56 = call double @mla(double %54, double %55, double 0xBF2A01A01A019FC7)
store double %56, double* %4
%57 = load double, double* %4
%58 = load double, double* %5
%59 = call double @mla(double %57, double %58, double 0x3F8111111111110F)
store double %59, double* %4
%60 = load double, double* %4
%61 = load double, double* %5
%62 = call double @mla(double %60, double %61, double 0xBFC5555555555555)
store double %62, double* %4
%63 = load double, double* %5
%64 = load double, double* %4
%65 = load double, double* %2
%66 = fmul double %64, %65
%67 = load double, double* %2
%68 = call double @mla(double %63, double %66, double %67)
store double %68, double* %4
%69 = load double, double* %4
ret double %69
}

LLVM IR (-O2):
@M_1_PI = global double 0.000000e+00
define double @xcos(double %0) {
%2 = load double, double* @M_1_PI
%3 = tail call double @llvm.fmuladd.f64(double %0, double %2, double -5.000000e-01)
%4 = tail call i64 @xrint(double %3)
%5 = trunc i64 %4 to i32
%6 = shl nsw i32 %5, 1
%7 = or i32 %6, 1
%8 = sitofp i32 %7 to double
%9 = tail call double @mla(double %8, double 0xBFF921FB54000000, double %0)
%10 = tail call double @mla(double %8, double 0xBE110B4611000000, double %9)
%11 = tail call double @mla(double %8, double 0xBC44C4C662000000, double %10)
%12 = tail call double @mla(double %8, double 0xBA71701B839A2520, double %11)
%13 = fmul double %12, %12
%14 = and i32 %5, 1
%15 = icmp eq i32 %14, 0
%16 = fneg double %12
%17 = select i1 %15, double %16, double %12
%18 = tail call double @mla(double 0xBC62622B22D526BE, double %13, double 0x3CE94FA618796592)
%19 = tail call double @mla(double %18, double %13, double 0xBD6AE7EA531357BF)
%20 = tail call double @mla(double %19, double %13, double 0x3DE6124601C23966)
%21 = tail call double @mla(double %20, double %13, double 0xBE5AE64567CB5786)
%22 = tail call double @mla(double %21, double %13, double 0x3EC71DE3A5568A50)
%23 = tail call double @mla(double %22, double %13, double 0xBF2A01A01A019FC7)
%24 = tail call double @mla(double %23, double %13, double 0x3F8111111111110F)
%25 = tail call double @mla(double %24, double %13, double 0xBFC5555555555555)
%26 = fmul double %17, %25
%27 = tail call double @mla(double %13, double %26, double %17)
ret double %27
}