#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 __ieee754_rem_pio2(double, double *);
double __kernel_cos(double, double);
double __kernel_sin(double, double, int);
double cos(double x) {
  double y[2], z = 0.0;
  int n, ix;
  ix = *(1 + (int *)&x);
  ix &= 0x7fffffff;
  if (ix <= 0x3fe921fb)
    return __kernel_cos(x, z);
  else if (ix >= 0x7ff00000)
    return x - x;
  else {
    n = __ieee754_rem_pio2(x, y);
    switch (n & 3) {
    case 0:
      return __kernel_cos(y[0], y[1]);
    case 1:
      return -__kernel_sin(y[0], y[1], 1);
    case 2:
      return -__kernel_cos(y[0], y[1]);
    default:
      return __kernel_sin(y[0], y[1], 1);
    }
  }
}


x86 assembly (clang, -O0):
<cos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
and    $0x7fffffff,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x3fe921fb,-0x30(%rbp)
jg     117c <cos+0x4c>
movsd  -0x10(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1050 <__kernel_cos@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127b <cos+0x14b>
cmpl   $0x7ff00000,-0x30(%rbp)
jl     119d <cos+0x6d>
movsd  -0x10(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127b <cos+0x14b>
movsd  -0x10(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1040 <__ieee754_rem_pio2@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x34(%rbp)
je     11e4 <cos+0xb4>
jmp    11c2 <cos+0x92>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     11fd <cos+0xcd>
jmp    11d3 <cos+0xa3>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     1232 <cos+0x102>
jmp    1262 <cos+0x132>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1050 <__kernel_cos@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127b <cos+0x14b>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127b <cos+0x14b>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1050 <__kernel_cos@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127b <cos+0x14b>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cos>:
movq   %xmm0,%rax
shr    $0x20,%rax
and    $0x7fffffff,%eax
cmp    $0x3fe921fb,%eax
ja     114d <cos+0x1d>
xorps  %xmm1,%xmm1
jmp    1050 <__kernel_cos@plt>
sub    $0x18,%rsp
cmp    $0x7ff00000,%eax
jb     1161 <cos+0x31>
subsd  %xmm0,%xmm0
add    $0x18,%rsp
ret
mov    %rsp,%rdi
call   1040 <__ieee754_rem_pio2@plt>
and    $0x3,%eax
cmp    $0x2,%eax
je     118f <cos+0x5f>
cmp    $0x1,%eax
je     11a1 <cos+0x71>
test   %eax,%eax
jne    11c2 <cos+0x92>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1050 <__kernel_cos@plt>
add    $0x18,%rsp
ret
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1050 <__kernel_cos@plt>
jmp    11b6 <cos+0x86>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
xorps  0xe43(%rip),%xmm0
add    $0x18,%rsp
ret
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @cos(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca [2 x double]
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store double %0, double* %3
store double 0.000000e+00, double* %5
%8 = bitcast double* %3 to i32*
%9 = getelementptr inbounds i32, i32* %8, i64 1
%10 = load i32, i32* %9
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = and i32 %11, 2147483647
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp sle i32 %13, 1072243195
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load double, double* %3
%17 = load double, double* %5
%18 = call double @__kernel_cos(double %16, double %17)
store double %18, double* %2
br label %58
19: ; preds = %1
%20 = load i32, i32* %7
%21 = icmp sge i32 %20, 2146435072
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load double, double* %3
%24 = load double, double* %3
%25 = fsub double %23, %24
store double %25, double* %2
br label %58
26: ; preds = %19
%27 = load double, double* %3
%28 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%29 = call i32 @__ieee754_rem_pio2(double %27, double* %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = and i32 %30, 3
switch i32 %31, label %52 [
i32 0, label %32
i32 1, label %38
i32 2, label %45
]
32: ; preds = %26
%33 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%34 = load double, double* %33
%35 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%36 = load double, double* %35
%37 = call double @__kernel_cos(double %34, double %36)
store double %37, double* %2
br label %58
38: ; preds = %26
%39 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%40 = load double, double* %39
%41 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%42 = load double, double* %41
%43 = call double @__kernel_sin(double %40, double %42, i32 1)
%44 = fneg double %43
store double %44, double* %2
br label %58
45: ; preds = %26
%46 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%47 = load double, double* %46
%48 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%49 = load double, double* %48
%50 = call double @__kernel_cos(double %47, double %49)
%51 = fneg double %50
store double %51, double* %2
br label %58
52: ; preds = %26
%53 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%54 = load double, double* %53
%55 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%56 = load double, double* %55
%57 = call double @__kernel_sin(double %54, double %56, i32 1)
store double %57, double* %2
br label %58
58: ; preds = %52, %45, %38, %32, %22, %15
%59 = load double, double* %2
ret double %59
}

LLVM IR (-O2):
define double @cos(double %0) {
%2 = alloca [2 x double]
%3 = bitcast [2 x double]* %2 to i8*
%4 = bitcast double %0 to i64
%5 = lshr i64 %4, 32
%6 = trunc i64 %5 to i32
%7 = and i32 %6, 2147483647
%8 = icmp ult i32 %7, 1072243196
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call double @__kernel_cos(double %0, double 0.000000e+00)
br label %41
11: ; preds = %1
%12 = icmp ugt i32 %7, 2146435071
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = fsub double %0, %0
br label %41
15: ; preds = %11
%16 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%17 = call i32 @__ieee754_rem_pio2(double %0, double* %16)
%18 = and i32 %17, 3
switch i32 %18, label %36 [
i32 0, label %19
i32 1, label %24
i32 2, label %30
]
19: ; preds = %15
%20 = load double, double* %16
%21 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 1
%22 = load double, double* %21
%23 = call double @__kernel_cos(double %20, double %22)
br label %41
24: ; preds = %15
%25 = load double, double* %16
%26 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 1
%27 = load double, double* %26
%28 = call double @__kernel_sin(double %25, double %27, i32 1)
%29 = fneg double %28
br label %41
30: ; preds = %15
%31 = load double, double* %16
%32 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 1
%33 = load double, double* %32
%34 = call double @__kernel_cos(double %31, double %33)
%35 = fneg double %34
br label %41
36: ; preds = %15
%37 = load double, double* %16
%38 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 1
%39 = load double, double* %38
%40 = call double @__kernel_sin(double %37, double %39, i32 1)
br label %41
41: ; preds = %36, %30, %24, %19, %13, %9
%42 = phi double [ %10, %9 ], [ %14, %13 ], [ %40, %36 ], [ %35, %30 ], [ %29, %24 ], [ %23, %19 ]
ret double %42
}