double interp2_k_lagrange3(double x) {
  double result = 0.0;
  if ((x >= 0.0) & (x < 0.5)) {
    result = ((-1.0) * x * x) + 1.0;
  } else if ((x >= 0.5) & (x < 1.5)) {
    result = ((1.0 / 2.0) * x * x) + ((-3.0 / 2.0) * x) + 1.0;
  }
  return result;
}


x86 assembly (clang, -O0):
<interp2_k_lagrange3>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
movsd  0xed3(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
seta   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1172 <interp2_k_lagrange3+0x72>
movsd  0xed2(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xeac(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11e9 <interp2_k_lagrange3+0xe9>
movsd  -0x8(%rbp),%xmm0
movsd  0xe81(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%eax
movsd  0xe75(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
seta   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11e4 <interp2_k_lagrange3+0xe4>
movsd  0xe4c(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  0xe52(%rip),%xmm1
mulsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe35(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11e9 <interp2_k_lagrange3+0xe9>
movsd  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<interp2_k_lagrange3>:
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     112d <interp2_k_lagrange3+0x2d>
movsd  0xeee(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    112d <interp2_k_lagrange3+0x2d>
mulsd  %xmm0,%xmm0
movsd  0xef4(%rip),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
ret
ucomisd 0xecb(%rip),%xmm0
jb     116d <interp2_k_lagrange3+0x6d>
movsd  0xec9(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    116d <interp2_k_lagrange3+0x6d>
movsd  0xeb3(%rip),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  0xeb3(%rip),%xmm0
addsd  %xmm1,%xmm0
addsd  0xeaf(%rip),%xmm0
movapd %xmm0,%xmm1
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @interp2_k_lagrange3(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %2
store double 0.000000e+00, double* %3
%4 = load double, double* %2
%5 = fcmp oge double %4, 0.000000e+00
%6 = zext i1 %5 to i32
%7 = load double, double* %2
%8 = fcmp olt double %7, 5.000000e-01
%9 = zext i1 %8 to i32
%10 = and i32 %6, %9
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load double, double* %2
%14 = fmul double -1.000000e+00, %13
%15 = load double, double* %2
%16 = call double @llvm.fmuladd.f64(double %14, double %15, double 1.000000e+00)
store double %16, double* %3
br label %35
17: ; preds = %1
%18 = load double, double* %2
%19 = fcmp oge double %18, 5.000000e-01
%20 = zext i1 %19 to i32
%21 = load double, double* %2
%22 = fcmp olt double %21, 1.500000e+00
%23 = zext i1 %22 to i32
%24 = and i32 %20, %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %17
%27 = load double, double* %2
%28 = fmul double 5.000000e-01, %27
%29 = load double, double* %2
%30 = load double, double* %2
%31 = fmul double -1.500000e+00, %30
%32 = call double @llvm.fmuladd.f64(double %28, double %29, double %31)
%33 = fadd double %32, 1.000000e+00
store double %33, double* %3
br label %34
34: ; preds = %26, %17
br label %35
35: ; preds = %34, %12
%36 = load double, double* %3
ret double %36
}

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