double _cubic_diff(double x) {
  const double alpha = -0.5;
  double factor;
  if (x < 0) {
    factor = -1;
    x = -x;
  } else {
    factor = +1;
  }
  double xx = x * x;
  if (x < 1.0) {
    return factor * (3 * (alpha + 2) * xx - 2 * (alpha + 3) * x);
  }
  if (x < 2.0) {
    return factor * (3 * (alpha * xx) - 10 * alpha * x + 8 * alpha);
  }
  return 0;
}


x86 assembly (clang, -O0):
<_cubic_diff>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  0xeef(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1157 <_cubic_diff+0x57>
movsd  0xee4(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1164 <_cubic_diff+0x64>
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe8d(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11d2 <_cubic_diff+0xd2>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xea8(%rip),%xmm2
mulsd  -0x10(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
movsd  0xe7c(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    124d <_cubic_diff+0x14d>
movsd  0xe3e(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1245 <_cubic_diff+0x145>
movsd  -0x20(%rbp),%xmm0
movsd  0xe0e(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
movsd  0xe31(%rip),%xmm2
mulsd  -0x10(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
movsd  0xe05(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  0xded(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    124d <_cubic_diff+0x14d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cubic_diff>:
xorpd  %xmm1,%xmm1
xor    %eax,%eax
ucomisd %xmm0,%xmm1
seta   %cl
jbe    1117 <_cubic_diff+0x17>
xorpd  0xee9(%rip),%xmm0
mov    %cl,%al
lea    0xef0(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm2
movapd %xmm0,%xmm3
mulsd  %xmm0,%xmm3
movsd  0xeeb(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1151 <_cubic_diff+0x51>
mulsd  0xf0d(%rip),%xmm0
mulsd  0xf0d(%rip),%xmm3
addsd  %xmm0,%xmm3
jmp    1187 <_cubic_diff+0x87>
xorpd  %xmm1,%xmm1
movsd  0xecb(%rip),%xmm4
ucomisd %xmm0,%xmm4
jbe    118f <_cubic_diff+0x8f>
mulsd  0xec5(%rip),%xmm3
mulsd  0xec5(%rip),%xmm0
mulsd  0xec5(%rip),%xmm3
addsd  %xmm0,%xmm3
addsd  0xec1(%rip),%xmm3
mulsd  %xmm3,%xmm2
movapd %xmm2,%xmm1
movapd %xmm1,%xmm0
ret

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

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