int double_eq(double a, double b) {
  double diff = a - b;
  if (diff < 0)
    diff = -diff;
  if (a < 0) {
    if (b >= 0)
      return 0;
    a = -a;
    b = -b;
  } else if (b < 0) {
    return 0;
  }
  if (a >= b)
    a = b;
  return diff < a * 1e-8;
}


x86 assembly (clang, -O0):
<double_eq>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    114c <double_eq+0x4c>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11bf <double_eq+0xbf>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1178 <double_eq+0x78>
movl   $0x0,-0x4(%rbp)
jmp    1219 <double_eq+0x119>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11de <double_eq+0xde>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11d9 <double_eq+0xd9>
movl   $0x0,-0x4(%rbp)
jmp    1219 <double_eq+0x119>
jmp    11de <double_eq+0xde>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     11f8 <double_eq+0xf8>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  0xdfb(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<double_eq>:
xorpd  %xmm2,%xmm2
xor    %eax,%eax
ucomisd %xmm0,%xmm2
jbe    1128 <double_eq+0x28>
ucomisd %xmm2,%xmm1
jae    1181 <double_eq+0x81>
movapd 0xee6(%rip),%xmm3
movapd %xmm0,%xmm4
xorpd  %xmm3,%xmm4
xorpd  %xmm1,%xmm3
jmp    1136 <double_eq+0x36>
ucomisd %xmm1,%xmm2
movapd %xmm0,%xmm4
movapd %xmm1,%xmm3
ja     1181 <double_eq+0x81>
subsd  %xmm1,%xmm0
movapd 0xebe(%rip),%xmm1
xorpd  %xmm0,%xmm1
movapd %xmm0,%xmm5
cmpltsd %xmm2,%xmm5
andpd  %xmm5,%xmm1
andnpd %xmm0,%xmm5
orpd   %xmm1,%xmm5
movapd %xmm3,%xmm0
cmplesd %xmm4,%xmm0
andpd  %xmm0,%xmm3
andnpd %xmm4,%xmm0
orpd   %xmm3,%xmm0
mulsd  0xe98(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm5,%xmm0
seta   %al
ret

LLVM IR (-O0):
define i32 @double_eq(double %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %4
store double %1, double* %5
%7 = load double, double* %4
%8 = load double, double* %5
%9 = fsub double %7, %8
store double %9, double* %6
%10 = load double, double* %6
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load double, double* %6
%14 = fneg double %13
store double %14, double* %6
br label %15
15: ; preds = %12, %2
%16 = load double, double* %4
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load double, double* %5
%20 = fcmp oge double %19, 0.000000e+00
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 0, i32* %3
br label %44
22: ; preds = %18
%23 = load double, double* %4
%24 = fneg double %23
store double %24, double* %4
%25 = load double, double* %5
%26 = fneg double %25
store double %26, double* %5
br label %32
27: ; preds = %15
%28 = load double, double* %5
%29 = fcmp olt double %28, 0.000000e+00
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 0, i32* %3
br label %44
31: ; preds = %27
br label %32
32: ; preds = %31, %22
%33 = load double, double* %4
%34 = load double, double* %5
%35 = fcmp oge double %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load double, double* %5
store double %37, double* %4
br label %38
38: ; preds = %36, %32
%39 = load double, double* %6
%40 = load double, double* %4
%41 = fmul double %40, 1.000000e-08
%42 = fcmp olt double %39, %41
%43 = zext i1 %42 to i32
store i32 %43, i32* %3
br label %44
44: ; preds = %38, %30, %21
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
define i32 @double_eq(double %0, double %1) {
%3 = fsub double %0, %1
%4 = fcmp olt double %3, 0.000000e+00
%5 = fneg double %3
%6 = select i1 %4, double %5, double %3
%7 = fcmp olt double %0, 0.000000e+00
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = fcmp ult double %1, 0.000000e+00
br i1 %9, label %10, label %23
10: ; preds = %8
%11 = fneg double %0
%12 = fneg double %1
br label %15
13: ; preds = %2
%14 = fcmp olt double %1, 0.000000e+00
br i1 %14, label %23, label %15
15: ; preds = %13, %10
%16 = phi double [ %11, %10 ], [ %0, %13 ]
%17 = phi double [ %12, %10 ], [ %1, %13 ]
%18 = fcmp oge double %16, %17
%19 = select i1 %18, double %17, double %16
%20 = fmul double %19, 1.000000e-08
%21 = fcmp olt double %6, %20
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %13, %8, %15
%24 = phi i32 [ %22, %15 ], [ 0, %8 ], [ 0, %13 ]
ret i32 %24
}