#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 ieee_cos(double x) {
  double y[2], z = 0.0;
  int n, ix;
  ix = *(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):
<ieee_cos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
and    $0x7fffffff,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x3fe921fb,-0x30(%rbp)
jg     117c <ieee_cos+0x4c>
movsd  -0x10(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1050 <__kernel_cos@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127b <ieee_cos+0x14b>
cmpl   $0x7ff00000,-0x30(%rbp)
jl     119d <ieee_cos+0x6d>
movsd  -0x10(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127b <ieee_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 <ieee_cos+0xb4>
jmp    11c2 <ieee_cos+0x92>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     11fd <ieee_cos+0xcd>
jmp    11d3 <ieee_cos+0xa3>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     1232 <ieee_cos+0x102>
jmp    1262 <ieee_cos+0x132>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1050 <__kernel_cos@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127b <ieee_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 <ieee_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 <ieee_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):
<ieee_cos>:
movq   %xmm0,%rax
and    $0x7fffffff,%eax
cmp    $0x3fe921fb,%eax
ja     1149 <ieee_cos+0x19>
xorps  %xmm1,%xmm1
jmp    1050 <__kernel_cos@plt>
sub    $0x18,%rsp
cmp    $0x7ff00000,%eax
jb     115d <ieee_cos+0x2d>
subsd  %xmm0,%xmm0
add    $0x18,%rsp
ret
mov    %rsp,%rdi
call   1040 <__ieee754_rem_pio2@plt>
and    $0x3,%eax
cmp    $0x2,%eax
je     118b <ieee_cos+0x5b>
cmp    $0x1,%eax
je     119d <ieee_cos+0x6d>
test   %eax,%eax
jne    11be <ieee_cos+0x8e>
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    11b2 <ieee_cos+0x82>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
xorps  0xe47(%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 @ieee_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 = load i32, i32* %8
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = and i32 %10, 2147483647
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp sle i32 %12, 1072243195
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load double, double* %3
%16 = load double, double* %5
%17 = call double @__kernel_cos(double %15, double %16)
store double %17, double* %2
br label %57
18: ; preds = %1
%19 = load i32, i32* %7
%20 = icmp sge i32 %19, 2146435072
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load double, double* %3
%23 = load double, double* %3
%24 = fsub double %22, %23
store double %24, double* %2
br label %57
25: ; preds = %18
%26 = load double, double* %3
%27 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%28 = call i32 @__ieee754_rem_pio2(double %26, double* %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = and i32 %29, 3
switch i32 %30, label %51 [
i32 0, label %31
i32 1, label %37
i32 2, label %44
]
31: ; preds = %25
%32 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%33 = load double, double* %32
%34 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%35 = load double, double* %34
%36 = call double @__kernel_cos(double %33, double %35)
store double %36, double* %2
br label %57
37: ; preds = %25
%38 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%39 = load double, double* %38
%40 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%41 = load double, double* %40
%42 = call double @__kernel_sin(double %39, double %41, i32 1)
%43 = fneg double %42
store double %43, double* %2
br label %57
44: ; preds = %25
%45 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%46 = load double, double* %45
%47 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%48 = load double, double* %47
%49 = call double @__kernel_cos(double %46, double %48)
%50 = fneg double %49
store double %50, double* %2
br label %57
51: ; preds = %25
%52 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%53 = load double, double* %52
%54 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%55 = load double, double* %54
%56 = call double @__kernel_sin(double %53, double %55, i32 1)
store double %56, double* %2
br label %57
57: ; preds = %51, %44, %37, %31, %21, %14
%58 = load double, double* %2
ret double %58
}

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