#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);
double max(double, double);
int approxEqual(double lhs, double rhs) {
  if (fabs(lhs - rhs) < 1e-6) {
    return 1;
  }
  if (fabs(lhs - rhs) / max(fabs(lhs), fabs(rhs)) < 0.001) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<approxEqual>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movaps 0xedd(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xec1(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1155 <approxEqual+0x45>
movl   $0x1,-0x4(%rbp)
jmp    11c2 <approxEqual+0xb2>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xeaa(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xe95(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movaps 0xe85(%rip),%xmm2
pand   %xmm2,%xmm1
call   1030 <max@plt>
movsd  -0x20(%rbp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe63(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11bb <approxEqual+0xab>
movl   $0x1,-0x4(%rbp)
jmp    11c2 <approxEqual+0xb2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<approxEqual>:
sub    $0x18,%rsp
movapd %xmm0,%xmm3
subsd  %xmm1,%xmm3
andpd  0xedc(%rip),%xmm3
mov    $0x1,%eax
movsd  0xedf(%rip),%xmm2
ucomisd %xmm3,%xmm2
ja     116b <approxEqual+0x5b>
movapd 0xec1(%rip),%xmm2
andpd  %xmm2,%xmm0
andpd  %xmm2,%xmm1
movapd %xmm3,(%rsp)
call   1030 <max@plt>
movapd (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0xeb6(%rip),%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
seta   %al
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @approxEqual(double %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = load double, double* %5
%8 = fsub double %6, %7
%9 = call double @llvm.fabs.f64(double %8)
%10 = fcmp olt double %9, 0x3EB0C6F7A0B5ED8D
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %26
12: ; preds = %2
%13 = load double, double* %4
%14 = load double, double* %5
%15 = fsub double %13, %14
%16 = call double @llvm.fabs.f64(double %15)
%17 = load double, double* %4
%18 = call double @llvm.fabs.f64(double %17)
%19 = load double, double* %5
%20 = call double @llvm.fabs.f64(double %19)
%21 = call double @max(double %18, double %20)
%22 = fdiv double %16, %21
%23 = fcmp olt double %22, 1.000000e-03
br i1 %23, label %24, label %25
24: ; preds = %12
store i32 1, i32* %3
br label %26
25: ; preds = %12
store i32 0, i32* %3
br label %26
26: ; preds = %25, %24, %11
%27 = load i32, i32* %3
ret i32 %27
}

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