int cond_lub(const double *x1, const double *x2, double lubmax2) {
  double x = x1[0] - x2[0];
  double y = x1[1] - x2[1];
  double z = x1[2] - x2[2];
  double r2 = x * x + y * y + z * z;
  if (r2 == 0.0) {
    return 1;
  } else if (lubmax2 <= 0.0) {
    return 0;
  } else if (r2 < lubmax2) {
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<cond_lub>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ab <cond_lub+0xab>
jp     11ab <cond_lub+0xab>
movl   $0x1,-0x4(%rbp)
jmp    11ec <cond_lub+0xec>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     11c5 <cond_lub+0xc5>
movl   $0x0,-0x4(%rbp)
jmp    11ec <cond_lub+0xec>
movsd  -0x40(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e5 <cond_lub+0xe5>
movl   $0x0,-0x4(%rbp)
jmp    11ec <cond_lub+0xec>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cond_lub>:
movsd  (%rdi),%xmm2
movsd  0x8(%rdi),%xmm3
subsd  (%rsi),%xmm2
subsd  0x8(%rsi),%xmm3
movsd  0x10(%rdi),%xmm1
subsd  0x10(%rsi),%xmm1
mulsd  %xmm3,%xmm3
mulsd  %xmm2,%xmm2
addsd  %xmm3,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mov    $0x1,%eax
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    1142 <cond_lub+0x42>
jp     1142 <cond_lub+0x42>
ret
xor    %eax,%eax
ucomisd %xmm0,%xmm2
jae    1141 <cond_lub+0x41>
xor    %eax,%eax
ucomisd %xmm1,%xmm0
setbe  %al
ret

LLVM IR (-O0):
define i32 @cond_lub(double* %0, double* %1, double %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double %2, double* %7
%12 = load double*, double** %5
%13 = getelementptr inbounds double, double* %12, i64 0
%14 = load double, double* %13
%15 = load double*, double** %6
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
%18 = fsub double %14, %17
store double %18, double* %8
%19 = load double*, double** %5
%20 = getelementptr inbounds double, double* %19, i64 1
%21 = load double, double* %20
%22 = load double*, double** %6
%23 = getelementptr inbounds double, double* %22, i64 1
%24 = load double, double* %23
%25 = fsub double %21, %24
store double %25, double* %9
%26 = load double*, double** %5
%27 = getelementptr inbounds double, double* %26, i64 2
%28 = load double, double* %27
%29 = load double*, double** %6
%30 = getelementptr inbounds double, double* %29, i64 2
%31 = load double, double* %30
%32 = fsub double %28, %31
store double %32, double* %10
%33 = load double, double* %8
%34 = load double, double* %8
%35 = load double, double* %9
%36 = load double, double* %9
%37 = fmul double %35, %36
%38 = call double @llvm.fmuladd.f64(double %33, double %34, double %37)
%39 = load double, double* %10
%40 = load double, double* %10
%41 = call double @llvm.fmuladd.f64(double %39, double %40, double %38)
store double %41, double* %11
%42 = load double, double* %11
%43 = fcmp oeq double %42, 0.000000e+00
br i1 %43, label %44, label %45
44: ; preds = %3
store i32 1, i32* %4
br label %55
45: ; preds = %3
%46 = load double, double* %7
%47 = fcmp ole double %46, 0.000000e+00
br i1 %47, label %48, label %49
48: ; preds = %45
store i32 0, i32* %4
br label %55
49: ; preds = %45
%50 = load double, double* %11
%51 = load double, double* %7
%52 = fcmp olt double %50, %51
br i1 %52, label %53, label %54
53: ; preds = %49
store i32 0, i32* %4
br label %55
54: ; preds = %49
store i32 1, i32* %4
br label %55
55: ; preds = %54, %53, %48, %44
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
define i32 @cond_lub(double* nocapture %0, double* nocapture %1, double %2) {
%4 = load double, double* %0
%5 = load double, double* %1
%6 = fsub double %4, %5
%7 = getelementptr inbounds double, double* %0, i64 1
%8 = load double, double* %7
%9 = getelementptr inbounds double, double* %1, i64 1
%10 = load double, double* %9
%11 = fsub double %8, %10
%12 = getelementptr inbounds double, double* %0, i64 2
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %1, i64 2
%15 = load double, double* %14
%16 = fsub double %13, %15
%17 = fmul double %11, %11
%18 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %17)
%19 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %18)
%20 = fcmp oeq double %19, 0.000000e+00
br i1 %20, label %26, label %21
21: ; preds = %3
%22 = fcmp ugt double %2, 0.000000e+00
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = fcmp uge double %19, %2
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %23, %21, %3
%27 = phi i32 [ 1, %3 ], [ 0, %21 ], [ %25, %23 ]
ret i32 %27
}