int cond_lub_poly(const double *x1, const double *x2, double a1, double a2,
                  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 {
    double s2 = r2 * 4.0 / (a1 + a2) / (a1 + a2);
    if (s2 < lubmax2) {
      return 0;
    } else {
      return 1;
    }
  }
}


x86 assembly (clang, -O0):
<cond_lub_poly>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
movsd  %xmm2,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b5 <cond_lub_poly+0xb5>
jp     11b5 <cond_lub_poly+0xb5>
movl   $0x1,-0x4(%rbp)
jmp    1224 <cond_lub_poly+0x124>
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jb     11cf <cond_lub_poly+0xcf>
movl   $0x0,-0x4(%rbp)
jmp    1224 <cond_lub_poly+0x124>
movsd  0xe29(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
addsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
addsd  -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    121d <cond_lub_poly+0x11d>
movl   $0x0,-0x4(%rbp)
jmp    1224 <cond_lub_poly+0x124>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

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

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

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