#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double fabs(double);
double BsplnWght3(long i, double x) {
  x = fabs(x - (double)i);
  if (x < 1.0)
    return (0.5 * x * x * (x - 2.0) + 2.0 / 3.0);
  if (x < 2.0) {
    x -= 2.0;
    return (x * x * x * (-1.0 / 6.0));
  }
  return (0.0);
}


x86 assembly (clang, -O0):
<BsplnWght3>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
subsd  %xmm1,%xmm0
movaps 0xf0d(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xecc(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    117c <BsplnWght3+0x7c>
movsd  0xed9(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xeaa(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xeaa(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d2 <BsplnWght3+0xd2>
movsd  0xe84(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11ca <BsplnWght3+0xca>
movsd  -0x18(%rbp),%xmm0
movsd  0xe6c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xe54(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d2 <BsplnWght3+0xd2>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<BsplnWght3>:
cvtsi2sd %rdi,%xmm1
subsd  %xmm1,%xmm0
andpd  0xeef(%rip),%xmm0
movsd  0xef7(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    114c <BsplnWght3+0x4c>
movsd  0xf09(%rip),%xmm2
mulsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm2
movsd  0xee9(%rip),%xmm1
addsd  %xmm0,%xmm1
mulsd  %xmm2,%xmm1
addsd  0xef1(%rip),%xmm1
movapd %xmm1,%xmm0
ret
xorpd  %xmm1,%xmm1
movsd  0xec0(%rip),%xmm2
ucomisd %xmm0,%xmm2
jbe    117e <BsplnWght3+0x7e>
movsd  0xeba(%rip),%xmm2
addsd  %xmm0,%xmm2
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  0xeaa(%rip),%xmm1
movapd %xmm1,%xmm0
ret

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

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