#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);
int AlmostEqualRelative(double A, double B, double maxRelDiff) {
  double diff = fabs(A - B);
  A = fabs(A);
  B = fabs(B);
  float largest = (B > A) ? B : A;
  if (diff <= largest * maxRelDiff)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<AlmostEqualRelative>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xedc(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xec7(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xeb2(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1176 <AlmostEqualRelative+0x76>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1180 <AlmostEqualRelative+0x80>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movsd  -0x28(%rbp),%xmm1
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11b7 <AlmostEqualRelative+0xb7>
movl   $0x1,-0x4(%rbp)
jmp    11be <AlmostEqualRelative+0xbe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<AlmostEqualRelative>:
movapd %xmm0,%xmm3
subsd  %xmm1,%xmm3
movapd 0xef0(%rip),%xmm4
andpd  %xmm4,%xmm3
andpd  %xmm4,%xmm0
andpd  %xmm4,%xmm1
maxsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm2,%xmm0
xor    %eax,%eax
ucomisd %xmm3,%xmm0
setae  %al
ret

LLVM IR (-O0):
define i32 @AlmostEqualRelative(double %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca float
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%10 = load double, double* %5
%11 = load double, double* %6
%12 = fsub double %10, %11
%13 = call double @llvm.fabs.f64(double %12)
store double %13, double* %8
%14 = load double, double* %5
%15 = call double @llvm.fabs.f64(double %14)
store double %15, double* %5
%16 = load double, double* %6
%17 = call double @llvm.fabs.f64(double %16)
store double %17, double* %6
%18 = load double, double* %6
%19 = load double, double* %5
%20 = fcmp ogt double %18, %19
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = load double, double* %6
br label %25
23: ; preds = %3
%24 = load double, double* %5
br label %25
25: ; preds = %23, %21
%26 = phi double [ %22, %21 ], [ %24, %23 ]
%27 = fptrunc double %26 to float
store float %27, float* %9
%28 = load double, double* %8
%29 = load float, float* %9
%30 = fpext float %29 to double
%31 = load double, double* %7
%32 = fmul double %30, %31
%33 = fcmp ole double %28, %32
br i1 %33, label %34, label %35
34: ; preds = %25
store i32 1, i32* %4
br label %36
35: ; preds = %25
store i32 0, i32* %4
br label %36
36: ; preds = %35, %34
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @AlmostEqualRelative(double %0, double %1, double %2) {
%4 = fsub double %0, %1
%5 = tail call double @llvm.fabs.f64(double %4)
%6 = tail call double @llvm.fabs.f64(double %0)
%7 = tail call double @llvm.fabs.f64(double %1)
%8 = fcmp ogt double %7, %6
%9 = select i1 %8, double %7, double %6
%10 = fptrunc double %9 to float
%11 = fpext float %10 to double
%12 = fmul double %11, %2
%13 = fcmp ole double %5, %12
%14 = zext i1 %13 to i32
ret i32 %14
}