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


x86 assembly (clang, -O0):
<BsplnDWght1>:
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
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1146 <BsplnDWght1+0x46>
jp     1146 <BsplnDWght1+0x46>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120d <BsplnDWght1+0x10d>
movsd  -0x18(%rbp),%xmm0
movaps 0xece(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe9d(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1180 <BsplnDWght1+0x80>
movsd  0xe9a(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11c1 <BsplnDWght1+0xc1>
movsd  -0x20(%rbp),%xmm0
movsd  0xe73(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11af <BsplnDWght1+0xaf>
jp     11af <BsplnDWght1+0xaf>
movsd  0xe63(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11bc <BsplnDWght1+0xbc>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120d <BsplnDWght1+0x10d>
jmp    11c1 <BsplnDWght1+0xc1>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11e2 <BsplnDWght1+0xe2>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1203 <BsplnDWght1+0x103>
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):
<BsplnDWght1>:
cvtsi2sd %rdi,%xmm1
subsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    111a <BsplnDWght1+0x1a>
jp     111a <BsplnDWght1+0x1a>
movapd %xmm1,%xmm0
ret
movapd 0xede(%rip),%xmm2
andpd  %xmm0,%xmm2
movsd  0xefa(%rip),%xmm3
ucomisd %xmm2,%xmm3
jbe    113e <BsplnDWght1+0x3e>
movsd  0xee4(%rip),%xmm2
jmp    1152 <BsplnDWght1+0x52>
ucomisd 0xee2(%rip),%xmm2
jne    1115 <BsplnDWght1+0x15>
jp     1115 <BsplnDWght1+0x15>
movsd  0xede(%rip),%xmm2
movapd 0xeb6(%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 @BsplnDWght1(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 = fcmp oeq double %11, 0.000000e+00
br i1 %12, label %13, label %14
13: ; preds = %2
store double 0.000000e+00, double* %3
br label %36
14: ; preds = %2
%15 = load double, double* %5
%16 = call double @llvm.fabs.f64(double %15)
store double %16, double* %6
%17 = load double, double* %6
%18 = fcmp olt double %17, 1.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %14
store double -1.000000e+00, double* %6
br label %26
20: ; preds = %14
%21 = load double, double* %6
%22 = fcmp oeq double %21, 1.000000e+00
br i1 %22, label %23, label %24
23: ; preds = %20
store double -5.000000e-01, double* %6
br label %25
24: ; preds = %20
store double 0.000000e+00, double* %3
br label %36
25: ; preds = %23
br label %26
26: ; preds = %25, %19
%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, %13
%37 = load double, double* %3
ret double %37
}

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