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


x86 assembly (clang, -O0):
<_cubic>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xee7(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    114d <_cubic+0x4d>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xeab(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11d0 <_cubic+0xd0>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe84(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x8(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
movsd  0xe84(%rip),%xmm3
subsd  %xmm3,%xmm1
mulsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe3e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    127d <_cubic+0x17d>
movsd  0xe30(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1278 <_cubic+0x178>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x8(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  0xe0a(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xde3(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0xda5(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    127d <_cubic+0x17d>
movsd  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cubic>:
movapd %xmm0,%xmm1
movapd 0xef4(%rip),%xmm3
xorpd  %xmm0,%xmm3
xorpd  %xmm0,%xmm0
movapd %xmm1,%xmm2
cmpltsd %xmm0,%xmm2
andpd  %xmm2,%xmm3
andnpd %xmm1,%xmm2
orpd   %xmm3,%xmm2
movsd  0xedf(%rip),%xmm1
ucomisd %xmm2,%xmm1
jbe    1160 <_cubic+0x60>
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
movsd  0xef1(%rip),%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  0xeb1(%rip),%xmm0
ret
movsd  0xeb0(%rip),%xmm1
ucomisd %xmm2,%xmm1
jbe    11a6 <_cubic+0xa6>
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
movsd  0xea2(%rip),%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm0
subsd  %xmm0,%xmm1
movsd  0xe92(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  0xe8a(%rip),%xmm0
ret

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

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