double _libtcas_filter_cubic(double x, double a) {
  if (x < 0)
    x = -x;
  if (x < 1)
    return (a + 2) * x * x * x - (a + 3) * x * x + 1;
  else if (x < 2)
    return a * x * x * x - 5 * a * x * x + 8 * a * x - 4 * a;
  else
    return 0;
}


x86 assembly (clang, -O0):
<_libtcas_filter_cubic>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    113d <_libtcas_filter_cubic+0x3d>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xebb(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11b8 <_libtcas_filter_cubic+0xb8>
movsd  0xeb0(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xeb4(%rip),%xmm1
addsd  -0x18(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe56(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1256 <_libtcas_filter_cubic+0x156>
movsd  0xe48(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    124e <_libtcas_filter_cubic+0x14e>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xe39(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdfb(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0xdd4(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1256 <_libtcas_filter_cubic+0x156>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<_libtcas_filter_cubic>:
movapd %xmm0,%xmm2
movapd 0xef4(%rip),%xmm4
xorpd  %xmm0,%xmm4
xorpd  %xmm0,%xmm0
movapd %xmm2,%xmm3
cmpltsd %xmm0,%xmm3
andpd  %xmm3,%xmm4
andnpd %xmm2,%xmm3
orpd   %xmm4,%xmm3
movsd  0xedf(%rip),%xmm2
ucomisd %xmm3,%xmm2
jbe    116c <_libtcas_filter_cubic+0x6c>
movsd  0xed9(%rip),%xmm0
addsd  %xmm1,%xmm0
mulsd  %xmm3,%xmm0
mulsd  %xmm3,%xmm0
addsd  0xee5(%rip),%xmm1
mulsd  %xmm3,%xmm1
mulsd  %xmm3,%xmm1
mulsd  %xmm3,%xmm0
subsd  %xmm1,%xmm0
addsd  0xea5(%rip),%xmm0
ret
movsd  0xea4(%rip),%xmm2
ucomisd %xmm3,%xmm2
jbe    11c6 <_libtcas_filter_cubic+0xc6>
movapd %xmm3,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm3,%xmm0
movsd  0xe92(%rip),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm3,%xmm2
mulsd  %xmm3,%xmm2
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
movsd  0xe7e(%rip),%xmm2
mulsd  %xmm1,%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm0,%xmm2
mulsd  0xe72(%rip),%xmm1
addsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @_libtcas_filter_cubic(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load double, double* %4
%10 = fneg double %9
store double %10, double* %4
br label %11
11: ; preds = %8, %2
%12 = load double, double* %4
%13 = fcmp olt double %12, 1.000000e+00
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = load double, double* %5
%16 = fadd double %15, 2.000000e+00
%17 = load double, double* %4
%18 = fmul double %16, %17
%19 = load double, double* %4
%20 = fmul double %18, %19
%21 = load double, double* %4
%22 = load double, double* %5
%23 = fadd double %22, 3.000000e+00
%24 = load double, double* %4
%25 = fmul double %23, %24
%26 = load double, double* %4
%27 = fmul double %25, %26
%28 = fneg double %27
%29 = call double @llvm.fmuladd.f64(double %20, double %21, double %28)
%30 = fadd double %29, 1.000000e+00
store double %30, double* %3
br label %56
31: ; preds = %11
%32 = load double, double* %4
%33 = fcmp olt double %32, 2.000000e+00
br i1 %33, label %34, label %55
34: ; preds = %31
%35 = load double, double* %5
%36 = load double, double* %4
%37 = fmul double %35, %36
%38 = load double, double* %4
%39 = fmul double %37, %38
%40 = load double, double* %4
%41 = load double, double* %5
%42 = fmul double 5.000000e+00, %41
%43 = load double, double* %4
%44 = fmul double %42, %43
%45 = load double, double* %4
%46 = fmul double %44, %45
%47 = fneg double %46
%48 = call double @llvm.fmuladd.f64(double %39, double %40, double %47)
%49 = load double, double* %5
%50 = fmul double 8.000000e+00, %49
%51 = load double, double* %4
%52 = call double @llvm.fmuladd.f64(double %50, double %51, double %48)
%53 = load double, double* %5
%54 = call double @llvm.fmuladd.f64(double -4.000000e+00, double %53, double %52)
store double %54, double* %3
br label %56
55: ; preds = %31
store double 0.000000e+00, double* %3
br label %56
56: ; preds = %55, %34, %14
%57 = load double, double* %3
ret double %57
}

LLVM IR (-O2):
define double @_libtcas_filter_cubic(double %0, double %1) {
%3 = fcmp olt double %0, 0.000000e+00
%4 = fneg double %0
%5 = select i1 %3, double %4, double %0
%6 = fcmp olt double %5, 1.000000e+00
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = fadd double %1, 2.000000e+00
%9 = fmul double %8, %5
%10 = fmul double %5, %9
%11 = fadd double %1, 3.000000e+00
%12 = fneg double %11
%13 = fmul double %5, %12
%14 = fmul double %5, %13
%15 = tail call double @llvm.fmuladd.f64(double %10, double %5, double %14)
%16 = fadd double %15, 1.000000e+00
br label %29
17: ; preds = %2
%18 = fcmp olt double %5, 2.000000e+00
br i1 %18, label %19, label %29
19: ; preds = %17
%20 = fmul double %5, %1
%21 = fmul double %5, %20
%22 = fmul double %1, -5.000000e+00
%23 = fmul double %22, %5
%24 = fmul double %5, %23
%25 = tail call double @llvm.fmuladd.f64(double %21, double %5, double %24)
%26 = fmul double %1, 8.000000e+00
%27 = tail call double @llvm.fmuladd.f64(double %26, double %5, double %25)
%28 = tail call double @llvm.fmuladd.f64(double %1, double -4.000000e+00, double %27)
br label %29
29: ; preds = %17, %19, %7
%30 = phi double [ %16, %7 ], [ %28, %19 ], [ 0.000000e+00, %17 ]
ret double %30
}