#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 fabsd(double);
double cosd(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 (fabsd(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):
<cosd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movl   $0x1,-0x1c(%rbp)
movsd  0xed4(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xec5(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1168 <cosd+0x58>
movsd  -0x8(%rbp),%xmm0
movsd  0xeae(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1136 <cosd+0x26>
jmp    116d <cosd+0x5d>
movsd  0xe9b(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1197 <cosd+0x87>
movsd  0xe80(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    116d <cosd+0x5d>
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  0xe43(%rip),%xmm1
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm2
addsd  %xmm2,%xmm2
movsd  0xe26(%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
call   1030 <fabsd@plt>
movsd  0xdfb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     12b1 <cosd+0x1a1>
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  0xdb2(%rip),%xmm1
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm2
addsd  %xmm2,%xmm2
movsd  0xd95(%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    121b <cosd+0x10b>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cosd>:
push   %rbx
sub    $0x30,%rsp
addsd  0xee3(%rip),%xmm0
ucomisd 0xee3(%rip),%xmm0
jbe    114a <cosd+0x3a>
movsd  0xee1(%rip),%xmm2
movsd  0xed1(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     1140 <cosd+0x30>
movsd  0xebe(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    116a <cosd+0x5a>
movsd  0xea8(%rip),%xmm1
addsd  %xmm1,%xmm0
ucomisd %xmm0,%xmm2
ja     1160 <cosd+0x50>
movapd 0xebe(%rip),%xmm1
xorpd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
movapd %xmm1,0x20(%rsp)
mulsd  %xmm1,%xmm2
divsd  0xe88(%rip),%xmm2
addsd  %xmm2,%xmm0
movapd %xmm0,(%rsp)
movapd %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
call   1030 <fabsd@plt>
ucomisd 0xe70(%rip),%xmm0
jae    11b9 <cosd+0xa9>
movapd (%rsp),%xmm2
jmp    1225 <cosd+0x115>
mov    $0x2,%ebx
movapd (%rsp),%xmm2
movapd 0x10(%rsp),%xmm3
nopl   0x0(%rax)
mulsd  0x20(%rsp),%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
addsd  %xmm0,%xmm0
movapd %xmm0,%xmm1
addsd  0xe3b(%rip),%xmm1
mulsd  %xmm0,%xmm1
divsd  %xmm1,%xmm3
movapd %xmm3,0x10(%rsp)
addsd  %xmm3,%xmm2
movapd %xmm2,(%rsp)
add    $0x1,%ebx
movapd %xmm3,%xmm0
call   1030 <fabsd@plt>
movapd 0x10(%rsp),%xmm3
movapd (%rsp),%xmm2
ucomisd 0xdfd(%rip),%xmm0
jae    11d0 <cosd+0xc0>
movapd %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @cosd(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 @fabsd(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 @cosd(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 @fabsd(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 @fabsd(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
}