double astCosd(angle) const double angle;
{
  double resid;
  resid = fabs(fmod(angle, 360.0));
  if (resid == 0.0) {
    return 1.0;
  } else if (resid == 90.0) {
    return 0.0;
  } else if (resid == 180.0) {
    return -1.0;
  } else if (resid == 270.0) {
    return 0.0;
  }
  return cos(angle * 3.141592653589793238462643 / 180.0);
}


x86 assembly (clang, -O0):
<astCosd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
call   1030 <fmod@plt>
movaps 0xeba(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1179 <astCosd+0x59>
jp     1179 <astCosd+0x59>
movsd  0xed1(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <astCosd+0x10e>
movsd  -0x18(%rbp),%xmm0
movsd  0xe92(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11a3 <astCosd+0x83>
jp     11a3 <astCosd+0x83>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <astCosd+0x10e>
movsd  -0x18(%rbp),%xmm0
movsd  0xe70(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11d2 <astCosd+0xb2>
jp     11d2 <astCosd+0xb2>
movsd  0xe70(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <astCosd+0x10e>
movsd  -0x18(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11fc <astCosd+0xdc>
jp     11fc <astCosd+0xdc>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <astCosd+0x10e>
jmp    1201 <astCosd+0xe1>
jmp    1206 <astCosd+0xe6>
jmp    120b <astCosd+0xeb>
movsd  0xe1d(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xe00(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astCosd>:
push   %rax
movsd  0xed7(%rip),%xmm1
movsd  %xmm0,(%rsp)
call   1030 <fmod@plt>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    114d <astCosd+0x2d>
jp     114d <astCosd+0x2d>
movsd  0xebd(%rip),%xmm0
pop    %rax
ret
movsd  (%rsp),%xmm2
andpd  0xee6(%rip),%xmm1
ucomisd 0xeae(%rip),%xmm1
jne    1168 <astCosd+0x48>
jp     1168 <astCosd+0x48>
pop    %rax
ret
ucomisd 0xeb0(%rip),%xmm1
jne    117e <astCosd+0x5e>
jp     117e <astCosd+0x5e>
movsd  0xe9c(%rip),%xmm0
pop    %rax
ret
ucomisd 0xea2(%rip),%xmm1
jne    118a <astCosd+0x6a>
jnp    1166 <astCosd+0x46>
movapd %xmm2,%xmm0
mulsd  0xe9a(%rip),%xmm0
divsd  0xe82(%rip),%xmm0
pop    %rax
jmp    1040 <cos@plt>

LLVM IR (-O0):
define double @astCosd(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %3
%5 = load double, double* %3
%6 = call double @fmod(double %5, double 3.600000e+02)
%7 = call double @llvm.fabs.f64(double %6)
store double %7, double* %4
%8 = load double, double* %4
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %1
store double 1.000000e+00, double* %2
br label %31
11: ; preds = %1
%12 = load double, double* %4
%13 = fcmp oeq double %12, 9.000000e+01
br i1 %13, label %14, label %15
14: ; preds = %11
store double 0.000000e+00, double* %2
br label %31
15: ; preds = %11
%16 = load double, double* %4
%17 = fcmp oeq double %16, 1.800000e+02
br i1 %17, label %18, label %19
18: ; preds = %15
store double -1.000000e+00, double* %2
br label %31
19: ; preds = %15
%20 = load double, double* %4
%21 = fcmp oeq double %20, 2.700000e+02
br i1 %21, label %22, label %23
22: ; preds = %19
store double 0.000000e+00, double* %2
br label %31
23: ; preds = %19
br label %24
24: ; preds = %23
br label %25
25: ; preds = %24
br label %26
26: ; preds = %25
%27 = load double, double* %3
%28 = fmul double %27, 0x400921FB54442D18
%29 = fdiv double %28, 1.800000e+02
%30 = call double @cos(double %29)
store double %30, double* %2
br label %31
31: ; preds = %26, %22, %18, %14, %10
%32 = load double, double* %2
ret double %32
}

LLVM IR (-O2):
define double @astCosd(double %0) {
%2 = tail call double @fmod(double %0, double 3.600000e+02)
%3 = tail call double @llvm.fabs.f64(double %2)
%4 = fcmp oeq double %2, 0.000000e+00
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = fcmp oeq double %3, 9.000000e+01
br i1 %6, label %15, label %7
7: ; preds = %5
%8 = fcmp oeq double %3, 1.800000e+02
br i1 %8, label %15, label %9
9: ; preds = %7
%10 = fcmp oeq double %3, 2.700000e+02
br i1 %10, label %15, label %11
11: ; preds = %9
%12 = fmul double %0, 0x400921FB54442D18
%13 = fdiv double %12, 1.800000e+02
%14 = tail call double @cos(double %13)
br label %15
15: ; preds = %9, %7, %5, %1, %11
%16 = phi double [ %14, %11 ], [ 1.000000e+00, %1 ], [ 0.000000e+00, %5 ], [ -1.000000e+00, %7 ], [ 0.000000e+00, %9 ]
ret double %16
}