double cubic_weight(double x) {
  double x_2 = x + 2.0;
  double x_1 = x + 1.0;
  double x_0 = x + 0.0;
  double x_minus1 = x - 1.0;
  if (x_2 < 0.0)
    x_2 = 0.0;
  if (x_1 < 0.0)
    x_1 = 0.0;
  if (x_0 < 0.0)
    x_0 = 0.0;
  if (x_minus1 < 0.0)
    x_minus1 = 0.0;
  return (x_2 * x_2 * x_2 - 4.0 * x_1 * x_1 * x_1 + 6.0 * x_0 * x_0 * x_0 -
          4.0 * x_minus1 * x_minus1 * x_minus1) /
         6.0;
}


x86 assembly (clang, -O0):
<cubic_weight>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  0xef7(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xedd(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xeb9(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1166 <cubic_weight+0x66>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    117c <cubic_weight+0x7c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1192 <cubic_weight+0x92>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11a8 <cubic_weight+0xa8>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xe59(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe1b(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe04(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdc6(%rip),%xmm1
divsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<cubic_weight>:
movsd  0xef8(%rip),%xmm2
addsd  %xmm0,%xmm2
movsd  0xef4(%rip),%xmm3
addsd  %xmm0,%xmm3
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm4
addsd  %xmm1,%xmm4
addsd  0xee4(%rip),%xmm0
xorpd  %xmm5,%xmm5
maxsd  %xmm2,%xmm5
xorpd  %xmm2,%xmm2
maxsd  %xmm3,%xmm2
xorpd  %xmm3,%xmm3
maxsd  %xmm4,%xmm3
maxsd  %xmm0,%xmm1
movapd %xmm5,%xmm4
mulsd  %xmm5,%xmm4
movsd  0xec0(%rip),%xmm0
movapd %xmm2,%xmm6
mulsd  %xmm0,%xmm6
mulsd  %xmm2,%xmm6
mulsd  %xmm2,%xmm6
mulsd  %xmm5,%xmm4
addsd  %xmm6,%xmm4
movsd  0xea8(%rip),%xmm2
movapd %xmm3,%xmm5
mulsd  %xmm2,%xmm5
mulsd  %xmm3,%xmm5
mulsd  %xmm3,%xmm5
addsd  %xmm4,%xmm5
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm5,%xmm0
divsd  %xmm2,%xmm0
ret

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

LLVM IR (-O2):
define double @cubic_weight(double %0) {
%2 = fadd double %0, 2.000000e+00
%3 = fadd double %0, 1.000000e+00
%4 = fadd double %0, 0.000000e+00
%5 = fadd double %0, -1.000000e+00
%6 = fcmp olt double %2, 0.000000e+00
%7 = select i1 %6, double 0.000000e+00, double %2
%8 = fcmp olt double %3, 0.000000e+00
%9 = select i1 %8, double 0.000000e+00, double %3
%10 = fcmp olt double %4, 0.000000e+00
%11 = select i1 %10, double 0.000000e+00, double %4
%12 = fcmp olt double %5, 0.000000e+00
%13 = select i1 %12, double 0.000000e+00, double %5
%14 = fmul double %7, %7
%15 = fmul double %9, -4.000000e+00
%16 = fmul double %9, %15
%17 = fmul double %9, %16
%18 = tail call double @llvm.fmuladd.f64(double %14, double %7, double %17)
%19 = fmul double %11, 6.000000e+00
%20 = fmul double %11, %19
%21 = tail call double @llvm.fmuladd.f64(double %20, double %11, double %18)
%22 = fmul double %13, -4.000000e+00
%23 = fmul double %13, %22
%24 = tail call double @llvm.fmuladd.f64(double %23, double %13, double %21)
%25 = fdiv double %24, 6.000000e+00
ret double %25
}