double cosd(angle)
double angle;
{
  double resid;
  if (fmod(angle, 90.0) == 0.0) {
    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):
<cosd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xec6(%rip),%xmm1
call   1030 <fmod@plt>
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1235 <cosd+0x115>
jp     1235 <cosd+0x115>
movsd  -0x10(%rbp),%xmm0
movsd  0xea9(%rip),%xmm1
call   1030 <fmod@plt>
movaps 0xed5(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119e <cosd+0x7e>
jp     119e <cosd+0x7e>
movsd  0xe9c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1258 <cosd+0x138>
movsd  -0x18(%rbp),%xmm0
movsd  0xe55(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11c8 <cosd+0xa8>
jp     11c8 <cosd+0xa8>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1258 <cosd+0x138>
movsd  -0x18(%rbp),%xmm0
movsd  0xe3b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11f7 <cosd+0xd7>
jp     11f7 <cosd+0xd7>
movsd  0xe3b(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1258 <cosd+0x138>
movsd  -0x18(%rbp),%xmm0
movsd  0xe14(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1221 <cosd+0x101>
jp     1221 <cosd+0x101>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1258 <cosd+0x138>
jmp    1226 <cosd+0x106>
jmp    122b <cosd+0x10b>
jmp    1230 <cosd+0x110>
jmp    1235 <cosd+0x115>
movsd  0xde3(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xdc6(%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):
<cosd>:
push   %rax
movsd  0xed7(%rip),%xmm1
movsd  %xmm0,(%rsp)
call   1030 <fmod@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a7 <cosd+0x87>
jp     11a7 <cosd+0x87>
movsd  0xec1(%rip),%xmm1
movsd  (%rsp),%xmm0
call   1030 <fmod@plt>
ucomisd 0xedf(%rip),%xmm0
jne    1167 <cosd+0x47>
jp     1167 <cosd+0x47>
movsd  0xeab(%rip),%xmm0
pop    %rax
ret
movapd %xmm0,%xmm1
andpd  0xecd(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd 0xe81(%rip),%xmm1
jne    1185 <cosd+0x65>
jp     1185 <cosd+0x65>
pop    %rax
ret
ucomisd 0xe93(%rip),%xmm1
jne    119b <cosd+0x7b>
jp     119b <cosd+0x7b>
movsd  0xe7f(%rip),%xmm0
pop    %rax
ret
ucomisd 0xe85(%rip),%xmm1
jne    11a7 <cosd+0x87>
jnp    1183 <cosd+0x63>
movsd  (%rsp),%xmm0
mulsd  0xe7c(%rip),%xmm0
divsd  0xe64(%rip),%xmm0
pop    %rax
jmp    1040 <cos@plt>

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

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