double get_nearest(double distance, double distance2) {
  if (distance > 0.00 && distance2 > 0.00)
    if (distance < distance2)
      return (distance);
    else
      return (distance2);
  else if (distance > 0.00)
    return (distance);
  else if (distance2 > 0.00)
    return (distance2);
  else
    return (-1.00);
}


x86 assembly (clang, -O0):
<get_nearest>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1164 <get_nearest+0x64>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1164 <get_nearest+0x64>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1155 <get_nearest+0x55>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <get_nearest+0xb3>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <get_nearest+0xb3>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1185 <get_nearest+0x85>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <get_nearest+0xb3>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11a6 <get_nearest+0xa6>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <get_nearest+0xb3>
movsd  0xe52(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nearest>:
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jbe    1115 <get_nearest+0x15>
ucomisd %xmm2,%xmm1
jbe    1115 <get_nearest+0x15>
minsd  %xmm1,%xmm0
ret
ucomisd %xmm2,%xmm0
ja     1138 <get_nearest+0x38>
xorpd  %xmm0,%xmm0
cmpltsd %xmm1,%xmm0
andpd  %xmm0,%xmm1
movsd  0xed0(%rip),%xmm2
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @get_nearest(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = fcmp ogt double %6, 0.000000e+00
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = load double, double* %5
%10 = fcmp ogt double %9, 0.000000e+00
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load double, double* %4
%13 = load double, double* %5
%14 = fcmp olt double %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load double, double* %4
store double %16, double* %3
br label %30
17: ; preds = %11
%18 = load double, double* %5
store double %18, double* %3
br label %30
19: ; preds = %8, %2
%20 = load double, double* %4
%21 = fcmp ogt double %20, 0.000000e+00
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load double, double* %4
store double %23, double* %3
br label %30
24: ; preds = %19
%25 = load double, double* %5
%26 = fcmp ogt double %25, 0.000000e+00
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load double, double* %5
store double %28, double* %3
br label %30
29: ; preds = %24
store double -1.000000e+00, double* %3
br label %30
30: ; preds = %29, %27, %22, %17, %15
%31 = load double, double* %3
ret double %31
}

LLVM IR (-O2):
define double @get_nearest(double %0, double %1) {
%3 = fcmp ogt double %0, 0.000000e+00
%4 = fcmp ogt double %1, 0.000000e+00
%5 = and i1 %3, %4
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = fcmp olt double %0, %1
%8 = select i1 %7, double %0, double %1
br label %12
9: ; preds = %2
br i1 %3, label %12, label %10
10: ; preds = %9
%11 = select i1 %4, double %1, double -1.000000e+00
br label %12
12: ; preds = %10, %9, %6
%13 = phi double [ %8, %6 ], [ %0, %9 ], [ %11, %10 ]
ret double %13
}