double L0_diff(const double *x, const long new_pos, const long old_pos) {
  return (x[new_pos] < 1)                             ? 1
         : 0 - ((x[old_pos] > 0) && (x[old_pos] < 2)) ? 1
                                                      : 0;
}


x86 assembly (clang, -O0):
<L0_diff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsd  0xee0(%rip),%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    1138 <L0_diff+0x38>
mov    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118e <L0_diff+0x8e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x1d(%rbp)
jbe    1172 <L0_diff+0x72>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  0xea1(%rip),%xmm0
ucomisd (%rax,%rcx,8),%xmm0
seta   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
xor    %edx,%edx
sub    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cvtsi2sd %eax,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<L0_diff>:
movsd  0xef8(%rip),%xmm0
ucomisd (%rdi,%rsi,8),%xmm0
ja     113a <L0_diff+0x3a>
movsd  (%rdi,%rdx,8),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
movsd  0xee1(%rip),%xmm1
ucomisd %xmm0,%xmm1
seta   %cl
and    %al,%cl
movzbl %cl,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ret

LLVM IR (-O0):
define double @L0_diff(double* %0, i64 %1, i64 %2) {
%4 = alloca double*
%5 = alloca i64
%6 = alloca i64
store double* %0, double** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%7 = load double*, double** %4
%8 = load i64, i64* %5
%9 = getelementptr inbounds double, double* %7, i64 %8
%10 = load double, double* %9
%11 = fcmp olt double %10, 1.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %3
br label %32
13: ; preds = %3
%14 = load double*, double** %4
%15 = load i64, i64* %6
%16 = getelementptr inbounds double, double* %14, i64 %15
%17 = load double, double* %16
%18 = fcmp ogt double %17, 0.000000e+00
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load double*, double** %4
%21 = load i64, i64* %6
%22 = getelementptr inbounds double, double* %20, i64 %21
%23 = load double, double* %22
%24 = fcmp olt double %23, 2.000000e+00
br label %25
25: ; preds = %19, %13
%26 = phi i1 [ false, %13 ], [ %24, %19 ]
%27 = zext i1 %26 to i32
%28 = sub nsw i32 0, %27
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 1, i32 0
br label %32
32: ; preds = %25, %12
%33 = phi i32 [ 1, %12 ], [ %31, %25 ]
%34 = sitofp i32 %33 to double
ret double %34
}

LLVM IR (-O2):
define double @L0_diff(double* nocapture %0, i64 %1, i64 %2) {
%4 = getelementptr inbounds double, double* %0, i64 %1
%5 = load double, double* %4
%6 = fcmp olt double %5, 1.000000e+00
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = getelementptr inbounds double, double* %0, i64 %2
%9 = load double, double* %8
%10 = fcmp ogt double %9, 0.000000e+00
%11 = fcmp olt double %9, 2.000000e+00
%12 = and i1 %10, %11
%13 = uitofp i1 %12 to double
br label %14
14: ; preds = %3, %7
%15 = phi double [ %13, %7 ], [ 1.000000e+00, %3 ]
ret double %15
}