#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 */
float cos_52s(double);
float fmod(float, double);
float approxCos(float x) {
  int quad;
  x = fmod(x, 6.283185307179586476925286766559);
  if (x < 0)
    x = -x;
  quad = (int)(x / 1.5707963267948966192313216916398);
  switch (quad) {
  case 0:
    return cos_52s(x);
  case 1:
    return -cos_52s(3.1415926535897932384626433832795 - x);
  case 2:
    return -cos_52s(x - 3.1415926535897932384626433832795);
  case 3:
    return cos_52s(6.283185307179586476925286766559 - x);
  }
}


x86 assembly (clang, -O0):
<approxCos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movsd  0xec6(%rip),%xmm1
call   1030 <fmod@plt>
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    1168 <approxCos+0x48>
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe8f(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x3,%rax
ja     1242 <approxCos+0x122>
mov    -0x18(%rbp),%rax
lea    0xe78(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
call   1040 <cos_52s@plt>
movss  %xmm0,-0x4(%rbp)
jmp    1242 <approxCos+0x122>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe3e(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1040 <cos_52s@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1242 <approxCos+0x122>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe0d(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1040 <cos_52s@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1242 <approxCos+0x122>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdcc(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1040 <cos_52s@plt>
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<approxCos>:
push   %rax
movsd  0xed7(%rip),%xmm1
call   1030 <fmod@plt>
movaps 0xeeb(%rip),%xmm1
xorps  %xmm0,%xmm1
xorps  %xmm2,%xmm2
movaps %xmm0,%xmm3
cmpltss %xmm2,%xmm3
andps  %xmm3,%xmm1
andnps %xmm0,%xmm3
orps   %xmm1,%xmm3
xorps  %xmm0,%xmm0
cvtss2sd %xmm3,%xmm0
movaps %xmm0,%xmm1
divsd  0xeaa(%rip),%xmm1
cvttsd2si %xmm1,%eax
cmp    $0x3,%eax
ja     117d <approxCos+0x5d>
lea    0xec2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
pop    %rax
jmp    1040 <cos_52s@plt>
pop    %rax
ret
movsd  0xe91(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    1199 <approxCos+0x79>
addsd  0xe77(%rip),%xmm0
call   1040 <cos_52s@plt>
xorpd  0xe7a(%rip),%xmm0
pop    %rax
ret
movsd  0xe50(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
pop    %rax
jmp    1040 <cos_52s@plt>

LLVM IR (-O0):
define float @approxCos(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca i32
store float %0, float* %3
%5 = load float, float* %3
%6 = call float @fmod(float %5, double 0x401921FB54442D18)
store float %6, float* %3
%7 = load float, float* %3
%8 = fcmp olt float %7, 0.000000e+00
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load float, float* %3
%11 = fneg float %10
store float %11, float* %3
br label %12
12: ; preds = %9, %1
%13 = load float, float* %3
%14 = fpext float %13 to double
%15 = fdiv double %14, 0x3FF921FB54442D18
%16 = fptosi double %15 to i32
store i32 %16, i32* %4
%17 = load i32, i32* %4
switch i32 %17, label %39 [
i32 0, label %18
i32 1, label %22
i32 2, label %28
i32 3, label %34
]
18: ; preds = %12
%19 = load float, float* %3
%20 = fpext float %19 to double
%21 = call float @cos_52s(double %20)
store float %21, float* %2
br label %39
22: ; preds = %12
%23 = load float, float* %3
%24 = fpext float %23 to double
%25 = fsub double 0x400921FB54442D18, %24
%26 = call float @cos_52s(double %25)
%27 = fneg float %26
store float %27, float* %2
br label %39
28: ; preds = %12
%29 = load float, float* %3
%30 = fpext float %29 to double
%31 = fsub double %30, 0x400921FB54442D18
%32 = call float @cos_52s(double %31)
%33 = fneg float %32
store float %33, float* %2
br label %39
34: ; preds = %12
%35 = load float, float* %3
%36 = fpext float %35 to double
%37 = fsub double 0x401921FB54442D18, %36
%38 = call float @cos_52s(double %37)
store float %38, float* %2
br label %39
39: ; preds = %18, %22, %28, %34, %12
%40 = load float, float* %2
ret float %40
}

LLVM IR (-O2):
define float @approxCos(float %0) {
%2 = tail call float @fmod(float %0, double 0x401921FB54442D18)
%3 = fcmp olt float %2, 0.000000e+00
%4 = fneg float %2
%5 = select i1 %3, float %4, float %2
%6 = fpext float %5 to double
%7 = fdiv double %6, 0x3FF921FB54442D18
%8 = fptosi double %7 to i32
switch i32 %8, label %22 [
i32 0, label %9
i32 1, label %11
i32 2, label %15
i32 3, label %19
]
9: ; preds = %1
%10 = tail call float @cos_52s(double %6)
br label %22
11: ; preds = %1
%12 = fsub double 0x400921FB54442D18, %6
%13 = tail call float @cos_52s(double %12)
%14 = fneg float %13
br label %22
15: ; preds = %1
%16 = fadd double %6, 0xC00921FB54442D18
%17 = tail call float @cos_52s(double %16)
%18 = fneg float %17
br label %22
19: ; preds = %1
%20 = fsub double 0x401921FB54442D18, %6
%21 = tail call float @cos_52s(double %20)
br label %22
22: ; preds = %1, %19, %15, %11, %9
%23 = phi float [ %21, %19 ], [ %18, %15 ], [ %14, %11 ], [ %10, %9 ], [ undef, %1 ]
ret float %23
}