#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double fabs(double);
bool double_equals(double a, double b) {
  double r, diff, max = fabs(a);
  if (fabs(b) > max)
    max = fabs(b);
  if (max == 0)
    return true;
  diff = b - a;
  r = diff / max;
  if (fabs(r) < 0.0001)
    return true;
  return false;
}


x86 assembly (clang, -O0):
<double_equals>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xee6(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xed1(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1153 <double_equals+0x53>
movsd  -0x18(%rbp),%xmm0
movaps 0xeb6(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1177 <double_equals+0x77>
jp     1177 <double_equals+0x77>
movl   $0x1,-0x4(%rbp)
jmp    11ca <double_equals+0xca>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movaps 0xe5f(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe63(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c3 <double_equals+0xc3>
movl   $0x1,-0x4(%rbp)
jmp    11ca <double_equals+0xca>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<double_equals>:
movapd 0xef8(%rip),%xmm2
movapd %xmm0,%xmm3
andpd  %xmm2,%xmm3
andpd  %xmm1,%xmm2
maxsd  %xmm3,%xmm2
mov    $0x1,%eax
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm2
jne    112a <double_equals+0x2a>
jp     112a <double_equals+0x2a>
ret
subsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
andpd  0xec6(%rip),%xmm1
movsd  0xece(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
seta   %al
ret

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

LLVM IR (-O2):
define i32 @double_equals(double %0, double %1) {
%3 = tail call double @llvm.fabs.f64(double %0)
%4 = tail call double @llvm.fabs.f64(double %1)
%5 = fcmp ogt double %4, %3
%6 = select i1 %5, double %4, double %3
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = fsub double %1, %0
%10 = fdiv double %9, %6
%11 = tail call double @llvm.fabs.f64(double %10)
%12 = fcmp olt double %11, 1.000000e-04
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %8, %2
%15 = phi i32 [ 1, %2 ], [ %13, %8 ]
ret i32 %15
}