#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 */
int const abs(int);
scalar_t__ fabs(float);
int compare_ff_relative(float a, float b, const float max_diff,
                        const int max_ulps) {
  union {
    float f;
    int i;
  } ua, ub;
  if (((float)fabs(a - b)) <= max_diff) {
    return 1;
  }
  ua.f = a;
  ub.f = b;
  return ((ua.i < 0) != (ub.i < 0))       ? 0
         : (abs(ua.i - ub.i) <= max_ulps) ? 1
                                          : 0;
}


x86 assembly (clang, -O0):
<compare_ff_relative>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2ss %rax,%xmm1
movss  -0x10(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     1168 <compare_ff_relative+0x48>
movl   $0x1,-0x4(%rbp)
jmp    11cc <compare_ff_relative+0xac>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x0,-0x20(%rbp)
setl   %cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
je     11a7 <compare_ff_relative+0x87>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    11c6 <compare_ff_relative+0xa6>
mov    -0x18(%rbp),%edi
sub    -0x20(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,%edx
mov    -0x14(%rbp),%esi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmovle %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_ff_relative>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movss  %xmm2,0xc(%rsp)
movss  %xmm0,0x4(%rsp)
movss  %xmm1,0x8(%rsp)
subss  %xmm1,%xmm0
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mov    $0x1,%eax
movss  0xc(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jae    1178 <compare_ff_relative+0x68>
movd   0x4(%rsp),%xmm0
movd   %xmm0,%eax
movd   0x8(%rsp),%xmm0
movd   %xmm0,%ecx
mov    %ecx,%edx
xor    %eax,%edx
js     1176 <compare_ff_relative+0x66>
sub    %ecx,%eax
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
setle  %al
jmp    1178 <compare_ff_relative+0x68>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%union.anon = type { float }
define i32 @compare_ff_relative(float %0, float %1, float %2, i32 %3) {
%5 = alloca i32
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca %union.anon
%11 = alloca %union.anon
store float %0, float* %6
store float %1, float* %7
store float %2, float* %8
store i32 %3, i32* %9
%12 = load float, float* %6
%13 = load float, float* %7
%14 = fsub float %12, %13
%15 = call i64 @fabs(float %14)
%16 = sitofp i64 %15 to float
%17 = load float, float* %8
%18 = fcmp ole float %16, %17
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 1, i32* %5
br label %48
20: ; preds = %4
%21 = load float, float* %6
%22 = bitcast %union.anon* %10 to float*
store float %21, float* %22
%23 = load float, float* %7
%24 = bitcast %union.anon* %11 to float*
store float %23, float* %24
%25 = bitcast %union.anon* %10 to i32*
%26 = load i32, i32* %25
%27 = icmp slt i32 %26, 0
%28 = zext i1 %27 to i32
%29 = bitcast %union.anon* %11 to i32*
%30 = load i32, i32* %29
%31 = icmp slt i32 %30, 0
%32 = zext i1 %31 to i32
%33 = icmp ne i32 %28, %32
br i1 %33, label %34, label %35
34: ; preds = %20
br label %46
35: ; preds = %20
%36 = bitcast %union.anon* %10 to i32*
%37 = load i32, i32* %36
%38 = bitcast %union.anon* %11 to i32*
%39 = load i32, i32* %38
%40 = sub nsw i32 %37, %39
%41 = call i32 @abs(i32 %40)
%42 = load i32, i32* %9
%43 = icmp sle i32 %41, %42
%44 = zext i1 %43 to i64
%45 = select i1 %43, i32 1, i32 0
br label %46
46: ; preds = %35, %34
%47 = phi i32 [ 0, %34 ], [ %45, %35 ]
store i32 %47, i32* %5
br label %48
48: ; preds = %46, %19
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
define i32 @compare_ff_relative(float %0, float %1, float %2, i32 %3) {
%5 = fsub float %0, %1
%6 = tail call i64 @fabs(float %5)
%7 = sitofp i64 %6 to float
%8 = fcmp ugt float %7, %2
br i1 %8, label %9, label %19
9: ; preds = %4
%10 = bitcast float %0 to i32
%11 = bitcast float %1 to i32
%12 = xor i32 %11, %10
%13 = icmp sgt i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = sub nsw i32 %10, %11
%16 = tail call i32 @llvm.abs.i32(i32 %15, i1 true)
%17 = icmp sle i32 %16, %3
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %14, %9, %4
%20 = phi i32 [ 1, %4 ], [ %18, %14 ], [ 0, %9 ]
ret i32 %20
}