#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 BsplnDWght2(long i, double x) {
  double f;
  x -= (double)i;
  f = fabs(x);
  if (f < 0.5)
    f *= -2.0;
  else if (f < 1.5)
    f -= 1.5;
  else
    return (0.0);
  return ((x > 0.0) ? (f) : (-f));
}


x86 assembly (clang, -O0):
<BsplnDWght2>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdq -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xef3(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xec2(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1160 <BsplnDWght2+0x60>
movsd  0xebf(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11a0 <BsplnDWght2+0xa0>
movsd  0xea0(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    118e <BsplnDWght2+0x8e>
movsd  -0x20(%rbp),%xmm0
movsd  0xe88(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    119b <BsplnDWght2+0x9b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ec <BsplnDWght2+0xec>
jmp    11a0 <BsplnDWght2+0xa0>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11c1 <BsplnDWght2+0xc1>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11e2 <BsplnDWght2+0xe2>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<BsplnDWght2>:
cvtsi2sd %rdi,%xmm1
subsd  %xmm1,%xmm0
movapd 0xeef(%rip),%xmm3
andpd  %xmm0,%xmm3
movsd  0xf03(%rip),%xmm1
ucomisd %xmm3,%xmm1
jbe    1131 <BsplnDWght2+0x31>
movsd  0xf0d(%rip),%xmm2
mulsd  %xmm3,%xmm2
jmp    114f <BsplnDWght2+0x4f>
xorpd  %xmm1,%xmm1
movsd  0xeeb(%rip),%xmm2
ucomisd %xmm3,%xmm2
jbe    1170 <BsplnDWght2+0x70>
movsd  0xee5(%rip),%xmm2
addsd  %xmm3,%xmm2
movapd 0xeb9(%rip),%xmm3
xorpd  %xmm2,%xmm3
xorpd  %xmm1,%xmm1
cmpltsd %xmm0,%xmm1
andpd  %xmm1,%xmm2
andnpd %xmm3,%xmm1
orpd   %xmm2,%xmm1
movapd %xmm1,%xmm0
ret

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

LLVM IR (-O2):
define double @BsplnDWght2(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, 5.000000e-01
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = fmul double %5, -2.000000e+00
br label %13
9: ; preds = %2
%10 = fcmp olt double %5, 1.500000e+00
br i1 %10, label %11, label %18
11: ; preds = %9
%12 = fadd double %5, -1.500000e+00
br label %13
13: ; preds = %11, %7
%14 = phi double [ %8, %7 ], [ %12, %11 ]
%15 = fcmp ogt double %4, 0.000000e+00
%16 = fneg double %14
%17 = select i1 %15, double %14, double %16
br label %18
18: ; preds = %9, %13
%19 = phi double [ %17, %13 ], [ 0.000000e+00, %9 ]
ret double %19
}