#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 almost_equal_eps(double x, double y, double eps) {
  if (x == 0)
    return fabs(x) < eps;
  if (y == 0)
    return fabs(y) < eps;
  double max = (fabs(x) > fabs(y)) ? fabs(x) : fabs(y);
  return (fabs(x - y) / max) < eps;
}


x86 assembly (clang, -O0):
<almost_equal_eps>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1154 <almost_equal_eps+0x54>
jp     1154 <almost_equal_eps+0x54>
movsd  -0x10(%rbp),%xmm1
movaps 0xec9(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1226 <almost_equal_eps+0x126>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1195 <almost_equal_eps+0x95>
jp     1195 <almost_equal_eps+0x95>
movsd  -0x18(%rbp),%xmm1
movaps 0xe88(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1226 <almost_equal_eps+0x126>
movsd  -0x10(%rbp),%xmm0
movaps 0xe5f(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movaps 0xe4f(%rip),%xmm2
pand   %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    11d9 <almost_equal_eps+0xd9>
movsd  -0x10(%rbp),%xmm0
movaps 0xe35(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11ee <almost_equal_eps+0xee>
movsd  -0x18(%rbp),%xmm0
movaps 0xe1b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movaps 0xdf7(%rip),%xmm0
pand   %xmm0,%xmm1
divsd  -0x28(%rbp),%xmm1
movsd  -0x20(%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):
<almost_equal_eps>:
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jne    1116 <almost_equal_eps+0x16>
jp     1116 <almost_equal_eps+0x16>
andpd  0xeec(%rip),%xmm0
jmp    1150 <almost_equal_eps+0x50>
ucomisd %xmm3,%xmm1
jne    112c <almost_equal_eps+0x2c>
jp     112c <almost_equal_eps+0x2c>
andpd  0xeda(%rip),%xmm1
movapd %xmm1,%xmm0
jmp    1150 <almost_equal_eps+0x50>
movapd 0xecc(%rip),%xmm3
movapd %xmm0,%xmm4
andpd  %xmm3,%xmm4
subsd  %xmm1,%xmm0
andpd  %xmm3,%xmm1
maxsd  %xmm1,%xmm4
andpd  %xmm3,%xmm0
divsd  %xmm4,%xmm0
xor    %eax,%eax
ucomisd %xmm0,%xmm2
seta   %al
ret

LLVM IR (-O0):
define i32 @almost_equal_eps(double %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%9 = load double, double* %5
%10 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load double, double* %5
%13 = call double @llvm.fabs.f64(double %12)
%14 = load double, double* %7
%15 = fcmp olt double %13, %14
%16 = zext i1 %15 to i32
store i32 %16, i32* %4
br label %49
17: ; preds = %3
%18 = load double, double* %6
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load double, double* %6
%22 = call double @llvm.fabs.f64(double %21)
%23 = load double, double* %7
%24 = fcmp olt double %22, %23
%25 = zext i1 %24 to i32
store i32 %25, i32* %4
br label %49
26: ; preds = %17
%27 = load double, double* %5
%28 = call double @llvm.fabs.f64(double %27)
%29 = load double, double* %6
%30 = call double @llvm.fabs.f64(double %29)
%31 = fcmp ogt double %28, %30
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load double, double* %5
%34 = call double @llvm.fabs.f64(double %33)
br label %38
35: ; preds = %26
%36 = load double, double* %6
%37 = call double @llvm.fabs.f64(double %36)
br label %38
38: ; preds = %35, %32
%39 = phi double [ %34, %32 ], [ %37, %35 ]
store double %39, double* %8
%40 = load double, double* %5
%41 = load double, double* %6
%42 = fsub double %40, %41
%43 = call double @llvm.fabs.f64(double %42)
%44 = load double, double* %8
%45 = fdiv double %43, %44
%46 = load double, double* %7
%47 = fcmp olt double %45, %46
%48 = zext i1 %47 to i32
store i32 %48, i32* %4
br label %49
49: ; preds = %38, %20, %11
%50 = load i32, i32* %4
ret i32 %50
}

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