double cosapprox_d(double val) {
  double val2 = val * val;
  return 1. +
         val2 *
             (-0.4999999989854595 +
              val2 *
                  (4.1666664031946494e-2 +
                   val2 *
                       (-1.3888865732154298e-3 +
                        val2 *
                            (2.4800621164404954e-5 +
                             val2 *
                                 (-2.7535709220609759e-7 +
                                  val2 *
                                      (2.0609775337948301e-9 +
                                       val2 * (-9.7393350917248365e-12)))))));
}


x86 assembly (clang, -O0):
<cosapprox_d>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm4
movsd  -0x10(%rbp),%xmm5
movsd  -0x10(%rbp),%xmm6
movsd  0xeed(%rip),%xmm7
mulsd  %xmm7,%xmm6
movsd  0xee9(%rip),%xmm7
addsd  %xmm7,%xmm6
mulsd  %xmm6,%xmm5
movsd  0xec9(%rip),%xmm6
addsd  %xmm6,%xmm5
mulsd  %xmm5,%xmm4
movsd  0xeb1(%rip),%xmm5
addsd  %xmm5,%xmm4
mulsd  %xmm4,%xmm3
movsd  0xe99(%rip),%xmm4
addsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm2
movsd  0xe81(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe69(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe51(%rip),%xmm1
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<cosapprox_d>:
mulsd  %xmm0,%xmm0
movsd  0xef4(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xef0(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xeec(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xee8(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xee4(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xee0(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xedc(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  0xed8(%rip),%xmm0
ret

LLVM IR (-O0):
define double @cosapprox_d(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %2
%4 = load double, double* %2
%5 = load double, double* %2
%6 = fmul double %4, %5
store double %6, double* %3
%7 = load double, double* %3
%8 = load double, double* %3
%9 = load double, double* %3
%10 = load double, double* %3
%11 = load double, double* %3
%12 = load double, double* %3
%13 = load double, double* %3
%14 = call double @llvm.fmuladd.f64(double %13, double 0xBDA56AC21BC531EF, double 0x3E21B42334E72818)
%15 = call double @llvm.fmuladd.f64(double %12, double %14, double 0xBE927A994C769AE7)
%16 = call double @llvm.fmuladd.f64(double %11, double %15, double 0x3EFA015DB58A922C)
%17 = call double @llvm.fmuladd.f64(double %10, double %16, double 0xBF56C1699A3A6394)
%18 = call double @llvm.fmuladd.f64(double %9, double %17, double 0x3FA555553EB385BC)
%19 = call double @llvm.fmuladd.f64(double %8, double %18, double 0xBFDFFFFFFEE9200F)
%20 = call double @llvm.fmuladd.f64(double %7, double %19, double 1.000000e+00)
ret double %20
}

LLVM IR (-O2):
define double @cosapprox_d(double %0) {
%2 = fmul double %0, %0
%3 = tail call double @llvm.fmuladd.f64(double %2, double 0xBDA56AC21BC531EF, double 0x3E21B42334E72818)
%4 = tail call double @llvm.fmuladd.f64(double %2, double %3, double 0xBE927A994C769AE7)
%5 = tail call double @llvm.fmuladd.f64(double %2, double %4, double 0x3EFA015DB58A922C)
%6 = tail call double @llvm.fmuladd.f64(double %2, double %5, double 0xBF56C1699A3A6394)
%7 = tail call double @llvm.fmuladd.f64(double %2, double %6, double 0x3FA555553EB385BC)
%8 = tail call double @llvm.fmuladd.f64(double %2, double %7, double 0xBFDFFFFFFEE9200F)
%9 = tail call double @llvm.fmuladd.f64(double %2, double %8, double 1.000000e+00)
ret double %9
}