#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 abs(int);
int /*<<< orphan*/ assert(int);
short float_almost_equal(float A, float B, int maxUlps) {
  assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024);
  int aInt = *(int *)&A;
  if (aInt < 0)
    aInt = 0x80000000 - aInt;
  int bInt = *(int *)&B;
  if (bInt < 0)
    bInt = 0x80000000 - bInt;
  int intDiff = abs(aInt - bInt);
  if (intDiff <= maxUlps)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<float_almost_equal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
mov    %edi,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x1d(%rbp)
jle    1151 <float_almost_equal+0x31>
cmpl   $0x400000,-0x10(%rbp)
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1179 <float_almost_equal+0x59>
mov    $0x80000000,%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1194 <float_almost_equal+0x74>
mov    $0x80000000,%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
sub    -0x18(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11b9 <float_almost_equal+0x99>
movw   $0x1,-0x2(%rbp)
jmp    11bf <float_almost_equal+0x9f>
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_almost_equal>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
lea    -0x1(%rbx),%eax
xor    %edi,%edi
cmp    $0x3fffff,%eax
setb   %dil
call   1030 <assert@plt>
movd   0x8(%rsp),%xmm0
movd   %xmm0,%eax
mov    $0x80000000,%ecx
mov    $0x80000000,%edx
sub    %eax,%edx
test   %eax,%eax
cmovns %eax,%edx
movd   0xc(%rsp),%xmm0
movd   %xmm0,%eax
sub    %eax,%ecx
test   %eax,%eax
cmovns %eax,%ecx
sub    %ecx,%edx
mov    %edx,%ecx
neg    %ecx
cmovs  %edx,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
setle  %al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define signext i16 @float_almost_equal(float %0, float %1, i32 %2) {
%4 = alloca i16
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store float %0, float* %5
store float %1, float* %6
store i32 %2, i32* %7
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 4194304
br label %16
16: ; preds = %13, %3
%17 = phi i1 [ false, %3 ], [ %15, %13 ]
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = bitcast float* %5 to i32*
%21 = load i32, i32* %20
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = load i32, i32* %8
%26 = sub i32 -2147483648, %25
store i32 %26, i32* %8
br label %27
27: ; preds = %24, %16
%28 = bitcast float* %6 to i32*
%29 = load i32, i32* %28
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* %9
%34 = sub i32 -2147483648, %33
store i32 %34, i32* %9
br label %35
35: ; preds = %32, %27
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = sub nsw i32 %36, %37
%39 = call i32 @abs(i32 %38)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = load i32, i32* %7
%42 = icmp sle i32 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %35
store i16 1, i16* %4
br label %45
44: ; preds = %35
store i16 0, i16* %4
br label %45
45: ; preds = %44, %43
%46 = load i16, i16* %4
ret i16 %46
}

LLVM IR (-O2):
define signext i16 @float_almost_equal(float %0, float %1, i32 %2) {
%4 = add i32 %2, -1
%5 = icmp ult i32 %4, 4194303
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = bitcast float %0 to i32
%9 = icmp slt i32 %8, 0
%10 = sub i32 -2147483648, %8
%11 = select i1 %9, i32 %10, i32 %8
%12 = bitcast float %1 to i32
%13 = icmp slt i32 %12, 0
%14 = sub i32 -2147483648, %12
%15 = select i1 %13, i32 %14, i32 %12
%16 = sub nsw i32 %11, %15
%17 = tail call i32 @llvm.abs.i32(i32 %16, i1 true)
%18 = icmp sle i32 %17, %2
%19 = zext i1 %18 to i16
ret i16 %19
}