#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 fabs(double);
double cos(double rad) {
  double app;
  double diff;
  int inc = 1;
  rad += 3.14159265358979323846 / 2.0;
  while (rad > 2 * 3.14159265358979323846)
    rad -= 2 * 3.14159265358979323846;
  while (rad < -2 * 3.14159265358979323846)
    rad += 2 * 3.14159265358979323846;
  app = diff = rad;
  diff = (diff * (-(rad * rad))) / ((2.0 * inc) * (2.0 * inc + 1.0));
  app = app + diff;
  inc++;
  while (fabs(diff) >= 0.00001) {
    diff = (diff * (-(rad * rad))) / ((2.0 * inc) * (2.0 * inc + 1.0));
    app = app + diff;
    inc++;
  }
  return app;
}


x86 assembly (clang, -O0):
<cos>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movl   $0x1,-0x1c(%rbp)
movsd  0xee8(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xed9(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1154 <cos+0x54>
movsd  -0x8(%rbp),%xmm0
movsd  0xec2(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1122 <cos+0x22>
jmp    1159 <cos+0x59>
movsd  0xeaf(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1183 <cos+0x83>
movsd  0xe94(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1159 <cos+0x59>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm2
movsd  0xe57(%rip),%xmm1
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm2
addsd  %xmm2,%xmm2
movsd  0xe3a(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xe1d(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe09(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     12a3 <cos+0x1a3>
movsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm2
movsd  0xdc0(%rip),%xmm1
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm2
addsd  %xmm2,%xmm2
movsd  0xda3(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1207 <cos+0x107>
movsd  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<cos>:
addsd  0xef8(%rip),%xmm0
ucomisd 0xef8(%rip),%xmm0
jbe    113a <cos+0x3a>
movsd  0xef6(%rip),%xmm1
movsd  0xee6(%rip),%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
ja     1130 <cos+0x30>
movsd  0xece(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    115a <cos+0x5a>
movsd  0xeb8(%rip),%xmm2
addsd  %xmm2,%xmm0
ucomisd %xmm0,%xmm1
ja     1150 <cos+0x50>
movapd 0xece(%rip),%xmm1
xorpd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm1,%xmm2
divsd  0xe9e(%rip),%xmm2
addsd  %xmm2,%xmm0
movapd 0xeba(%rip),%xmm3
andpd  %xmm2,%xmm3
ucomisd 0xe8e(%rip),%xmm3
jb     11f4 <cos+0xf4>
mov    $0x2,%eax
movsd  0xe87(%rip),%xmm3
movapd 0xe97(%rip),%xmm4
movsd  0xe6f(%rip),%xmm5
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mulsd  %xmm1,%xmm2
xorps  %xmm6,%xmm6
cvtsi2sd %eax,%xmm6
addsd  %xmm6,%xmm6
movapd %xmm6,%xmm7
addsd  %xmm3,%xmm7
mulsd  %xmm6,%xmm7
divsd  %xmm7,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%eax
movapd %xmm2,%xmm6
andpd  %xmm4,%xmm6
ucomisd %xmm5,%xmm6
jae    11c0 <cos+0xc0>
ret

LLVM IR (-O0):
define double @cos(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %2
store i32 1, i32* %5
%6 = load double, double* %2
%7 = fadd double %6, 0x3FF921FB54442D18
store double %7, double* %2
br label %8
8: ; preds = %11, %1
%9 = load double, double* %2
%10 = fcmp ogt double %9, 0x401921FB54442D18
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load double, double* %2
%13 = fsub double %12, 0x401921FB54442D18
store double %13, double* %2
br label %8
14: ; preds = %8
br label %15
15: ; preds = %18, %14
%16 = load double, double* %2
%17 = fcmp olt double %16, 0xC01921FB54442D18
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load double, double* %2
%20 = fadd double %19, 0x401921FB54442D18
store double %20, double* %2
br label %15
21: ; preds = %15
%22 = load double, double* %2
store double %22, double* %4
store double %22, double* %3
%23 = load double, double* %4
%24 = load double, double* %2
%25 = load double, double* %2
%26 = fmul double %24, %25
%27 = fneg double %26
%28 = fmul double %23, %27
%29 = load i32, i32* %5
%30 = sitofp i32 %29 to double
%31 = fmul double 2.000000e+00, %30
%32 = load i32, i32* %5
%33 = sitofp i32 %32 to double
%34 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %33, double 1.000000e+00)
%35 = fmul double %31, %34
%36 = fdiv double %28, %35
store double %36, double* %4
%37 = load double, double* %3
%38 = load double, double* %4
%39 = fadd double %37, %38
store double %39, double* %3
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %42
42: ; preds = %46, %21
%43 = load double, double* %4
%44 = call double @llvm.fabs.f64(double %43)
%45 = fcmp oge double %44, 1.000000e-05
br i1 %45, label %46, label %66
46: ; preds = %42
%47 = load double, double* %4
%48 = load double, double* %2
%49 = load double, double* %2
%50 = fmul double %48, %49
%51 = fneg double %50
%52 = fmul double %47, %51
%53 = load i32, i32* %5
%54 = sitofp i32 %53 to double
%55 = fmul double 2.000000e+00, %54
%56 = load i32, i32* %5
%57 = sitofp i32 %56 to double
%58 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %57, double 1.000000e+00)
%59 = fmul double %55, %58
%60 = fdiv double %52, %59
store double %60, double* %4
%61 = load double, double* %3
%62 = load double, double* %4
%63 = fadd double %61, %62
store double %63, double* %3
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
store i32 %65, i32* %5
br label %42
66: ; preds = %42
%67 = load double, double* %3
ret double %67
}

LLVM IR (-O2):
define double @cos(double %0) {
%2 = fadd double %0, 0x3FF921FB54442D18
%3 = fcmp ogt double %2, 0x401921FB54442D18
br i1 %3, label %7, label %4
4: ; preds = %7, %1
%5 = phi double [ %2, %1 ], [ %9, %7 ]
%6 = fcmp olt double %5, 0xC01921FB54442D18
br i1 %6, label %11, label %15
7: ; preds = %1, %7
%8 = phi double [ %9, %7 ], [ %2, %1 ]
%9 = fadd double %8, 0xC01921FB54442D18
%10 = fcmp ogt double %9, 0x401921FB54442D18
br i1 %10, label %7, label %4
11: ; preds = %4, %11
%12 = phi double [ %13, %11 ], [ %5, %4 ]
%13 = fadd double %12, 0x401921FB54442D18
%14 = fcmp olt double %13, 0xC01921FB54442D18
br i1 %14, label %11, label %15
15: ; preds = %11, %4
%16 = phi double [ %5, %4 ], [ %13, %11 ]
%17 = fneg double %16
%18 = fmul double %16, %17
%19 = fmul double %16, %18
%20 = fdiv double %19, 6.000000e+00
%21 = fadd double %16, %20
%22 = tail call double @llvm.fabs.f64(double %20)
%23 = fcmp ult double %22, 1.000000e-05
br i1 %23, label %38, label %24
24: ; preds = %15, %24
%25 = phi i32 [ %35, %24 ], [ 2, %15 ]
%26 = phi double [ %33, %24 ], [ %20, %15 ]
%27 = phi double [ %34, %24 ], [ %21, %15 ]
%28 = fmul double %18, %26
%29 = sitofp i32 %25 to double
%30 = fmul double %29, 2.000000e+00
%31 = tail call double @llvm.fmuladd.f64(double %29, double 2.000000e+00, double 1.000000e+00)
%32 = fmul double %30, %31
%33 = fdiv double %28, %32
%34 = fadd double %27, %33
%35 = add nuw nsw i32 %25, 1
%36 = tail call double @llvm.fabs.f64(double %33)
%37 = fcmp ult double %36, 1.000000e-05
br i1 %37, label %38, label %24
38: ; preds = %24, %15
%39 = phi double [ %21, %15 ], [ %34, %24 ]
ret double %39
}