double double_comparison(const double a, const double b) {
  const double epsilon = 1e-14;
  if (a == b)
    return 1;
  else if ((a > b) && ((a - b) < epsilon))
    return 1;
  else if ((b > a) && ((b - a) < epsilon))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<double_comparison>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  0xeea(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    1143 <double_comparison+0x43>
jp     1143 <double_comparison+0x43>
movsd  0xecf(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d1 <double_comparison+0xd1>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1181 <double_comparison+0x81>
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xe9b(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1181 <double_comparison+0x81>
movsd  0xe91(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d1 <double_comparison+0xd1>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11bf <double_comparison+0xbf>
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movsd  0xe5d(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11bf <double_comparison+0xbf>
movsd  0xe53(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d1 <double_comparison+0xd1>
jmp    11c4 <double_comparison+0xc4>
jmp    11c9 <double_comparison+0xc9>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<double_comparison>:
movapd %xmm0,%xmm2
movsd  0xef4(%rip),%xmm0
ucomisd %xmm1,%xmm2
jne    1115 <double_comparison+0x15>
jp     1115 <double_comparison+0x15>
ret
jbe    112d <double_comparison+0x2d>
movapd %xmm2,%xmm3
subsd  %xmm1,%xmm3
movsd  0xee1(%rip),%xmm4
ucomisd %xmm3,%xmm4
ja     1114 <double_comparison+0x14>
movapd %xmm1,%xmm3
subsd  %xmm2,%xmm3
cmpltsd 0xeca(%rip),%xmm3
cmpltsd %xmm1,%xmm2
movsd  0xeb5(%rip),%xmm0
andpd  %xmm3,%xmm0
andpd  %xmm2,%xmm0
ret

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

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