#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 */
scalar_t__ DBL_MANT_DIG;
double ldexp(double, scalar_t__);
int doubles_equal_helper(double ref_frac, int ref_exp, double other,
                         unsigned fuzz_ulps) {
  double ref_int = ldexp(ref_frac, DBL_MANT_DIG);
  double window_min = ldexp(ref_int - fuzz_ulps, ref_exp - DBL_MANT_DIG);
  double window_max = ldexp(ref_int + fuzz_ulps, ref_exp - DBL_MANT_DIG);
  return ((window_min <= other) && (other <= window_max));
}


x86 assembly (clang, -O0):
<doubles_equal_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2eb4(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    (%rax),%rdi
call   1030 <ldexp@plt>
mov    -0x48(%rbp),%rax
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x1c(%rbp),%ecx
cvtsi2sd %rcx,%xmm1
subsd  %xmm1,%xmm0
movslq -0xc(%rbp),%rdi
mov    (%rax),%rax
sub    %rax,%rdi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x1c(%rbp),%eax
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
movslq -0xc(%rbp),%rdi
mov    0x2e5e(%rip),%rax
sub    (%rax),%rdi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
mov    %al,-0x39(%rbp)
jb     11c4 <doubles_equal_helper+0xb4>
movsd  -0x18(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubles_equal_helper>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
movsd  %xmm1,0x18(%rsp)
mov    %edi,%ebp
mov    0x2ebf(%rip),%r14
mov    (%r14),%rdi
call   1030 <ldexp@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  %xmm1,(%rsp)
subsd  %xmm1,%xmm0
movslq %ebp,%rbx
mov    %rbx,%rdi
sub    (%r14),%rdi
call   1030 <ldexp@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
sub    (%r14),%rbx
mov    %rbx,%rdi
call   1030 <ldexp@plt>
movsd  0x18(%rsp),%xmm1
ucomisd 0x10(%rsp),%xmm1
setae  %al
ucomisd %xmm1,%xmm0
setae  %cl
and    %al,%cl
movzbl %cl,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@DBL_MANT_DIG = global i64 0
define i32 @doubles_equal_helper(double %0, i32 %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %5
store i32 %1, i32* %6
store double %2, double* %7
store i32 %3, i32* %8
%12 = load double, double* %5
%13 = load i64, i64* @DBL_MANT_DIG
%14 = call double @ldexp(double %12, i64 %13)
store double %14, double* %9
%15 = load double, double* %9
%16 = load i32, i32* %8
%17 = uitofp i32 %16 to double
%18 = fsub double %15, %17
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = load i64, i64* @DBL_MANT_DIG
%22 = sub nsw i64 %20, %21
%23 = call double @ldexp(double %18, i64 %22)
store double %23, double* %10
%24 = load double, double* %9
%25 = load i32, i32* %8
%26 = uitofp i32 %25 to double
%27 = fadd double %24, %26
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = load i64, i64* @DBL_MANT_DIG
%31 = sub nsw i64 %29, %30
%32 = call double @ldexp(double %27, i64 %31)
store double %32, double* %11
%33 = load double, double* %10
%34 = load double, double* %7
%35 = fcmp ole double %33, %34
br i1 %35, label %36, label %40
36: ; preds = %4
%37 = load double, double* %7
%38 = load double, double* %11
%39 = fcmp ole double %37, %38
br label %40
40: ; preds = %36, %4
%41 = phi i1 [ false, %4 ], [ %39, %36 ]
%42 = zext i1 %41 to i32
ret i32 %42
}

LLVM IR (-O2):
@DBL_MANT_DIG = global i64 0
define i32 @doubles_equal_helper(double %0, i32 %1, double %2, i32 %3) {
%5 = load i64, i64* @DBL_MANT_DIG
%6 = tail call double @ldexp(double %0, i64 %5)
%7 = uitofp i32 %3 to double
%8 = fsub double %6, %7
%9 = sext i32 %1 to i64
%10 = load i64, i64* @DBL_MANT_DIG
%11 = sub nsw i64 %9, %10
%12 = tail call double @ldexp(double %8, i64 %11)
%13 = fadd double %6, %7
%14 = load i64, i64* @DBL_MANT_DIG
%15 = sub nsw i64 %9, %14
%16 = tail call double @ldexp(double %13, i64 %15)
%17 = fcmp ole double %12, %2
%18 = fcmp oge double %16, %2
%19 = select i1 %17, i1 %18, i1 false
%20 = zext i1 %19 to i32
ret i32 %20
}