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


x86 assembly (clang, -O0):
<cubic_convolution>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xee5(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11c3 <cubic_convolution+0xc3>
movsd  0xedb(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11c3 <cubic_convolution+0xc3>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xede(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xea5(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xe83(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1252 <cubic_convolution+0x152>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     124a <cubic_convolution+0x14a>
movsd  0xe23(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    124a <cubic_convolution+0x14a>
movsd  0xe18(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xe0e(%rip),%xmm1
addsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdc4(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1252 <cubic_convolution+0x152>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<cubic_convolution>:
ucomisd 0xef8(%rip),%xmm0
jb     1159 <cubic_convolution+0x59>
movsd  0xef6(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    1159 <cubic_convolution+0x59>
movsd  0xef8(%rip),%xmm3
mulsd  %xmm1,%xmm3
movapd %xmm1,%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm3,%xmm2
movsd  0xee8(%rip),%xmm3
mulsd  %xmm1,%xmm3
mulsd  %xmm0,%xmm2
addsd  %xmm3,%xmm2
mulsd  0xedc(%rip),%xmm1
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
ret
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     11a2 <cubic_convolution+0xa2>
movsd  0xe95(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    11a2 <cubic_convolution+0xa2>
movsd  0xe8f(%rip),%xmm2
addsd  %xmm1,%xmm2
addsd  0xe8b(%rip),%xmm1
mulsd  %xmm0,%xmm2
subsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe63(%rip),%xmm2
movapd %xmm2,%xmm0
ret
xorpd  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @cubic_convolution(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 ole double 1.000000e+00, %6
br i1 %7, label %8, label %27
8: ; preds = %2
%9 = load double, double* %4
%10 = fcmp olt double %9, 2.000000e+00
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load double, double* %5
%13 = load double, double* %4
%14 = load double, double* %5
%15 = fmul double 5.000000e+00, %14
%16 = fneg double %15
%17 = call double @llvm.fmuladd.f64(double %12, double %13, double %16)
%18 = load double, double* %4
%19 = load double, double* %5
%20 = fmul double 8.000000e+00, %19
%21 = call double @llvm.fmuladd.f64(double %17, double %18, double %20)
%22 = load double, double* %4
%23 = load double, double* %5
%24 = fmul double 4.000000e+00, %23
%25 = fneg double %24
%26 = call double @llvm.fmuladd.f64(double %21, double %22, double %25)
store double %26, double* %3
br label %46
27: ; preds = %8, %2
%28 = load double, double* %4
%29 = fcmp ole double 0.000000e+00, %28
br i1 %29, label %30, label %45
30: ; preds = %27
%31 = load double, double* %4
%32 = fcmp olt double %31, 1.000000e+00
br i1 %32, label %33, label %45
33: ; preds = %30
%34 = load double, double* %5
%35 = fadd double %34, 2.000000e+00
%36 = load double, double* %4
%37 = load double, double* %5
%38 = fadd double %37, 3.000000e+00
%39 = fneg double %38
%40 = call double @llvm.fmuladd.f64(double %35, double %36, double %39)
%41 = load double, double* %4
%42 = fmul double %40, %41
%43 = load double, double* %4
%44 = call double @llvm.fmuladd.f64(double %42, double %43, double 1.000000e+00)
store double %44, double* %3
br label %46
45: ; preds = %30, %27
store double 0.000000e+00, double* %3
br label %46
46: ; preds = %45, %33, %11
%47 = load double, double* %3
ret double %47
}

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