#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 */
typedef unsigned int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ INFINITY;
unsigned int UINT32_MAX;
unsigned int eh_float32_to_uint32(float);
scalar_t__ isinf(float);
scalar_t__ isnan(float);
float nextafter(double, int /*<<< orphan*/);
uint32_t _float32_distance(float l, float r) {
  uint32_t u32a, u32b;
  float tmp;
  if (l == r) {
    return 0;
  }
  if (isnan(l) || isnan(r) || isinf(l) || isinf(r)) {
    return UINT32_MAX;
  }
  if (r > l) {
    tmp = l;
    l = r;
    r = tmp;
  }
  if (nextafter(r, INFINITY) == l) {
    return 1U;
  }
  if (l > 0.0 && r < 0.0) {
    u32a = _float32_distance(l, 0.0);
    u32b = 1U + _float32_distance(r, nextafter(0.0, -INFINITY));
    return u32a + u32b;
  }
  u32a = eh_float32_to_uint32(l);
  u32b = eh_float32_to_uint32(r);
  if (u32b > u32a) {
    do {
      if (&(u32a) != &(u32b)) {
        (u32a) ^= (u32b);
        (u32b) ^= (u32a);
        (u32a) ^= (u32b);
      }
    } while (0);
  }
  return u32a - u32b;
}


x86 assembly (clang, -O0):
<_float32_distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
ucomiss -0xc(%rbp),%xmm0
jne    1183 <_float32_distance+0x33>
jp     1183 <_float32_distance+0x33>
movl   $0x0,-0x4(%rbp)
jmp    1312 <_float32_distance+0x1c2>
movss  -0x8(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
jne    11d3 <_float32_distance+0x83>
movss  -0xc(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
jne    11d3 <_float32_distance+0x83>
movss  -0x8(%rbp),%xmm0
call   1070 <isinf@plt>
cmp    $0x0,%rax
jne    11d3 <_float32_distance+0x83>
movss  -0xc(%rbp),%xmm0
call   1070 <isinf@plt>
cmp    $0x0,%rax
je     11e4 <_float32_distance+0x94>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1312 <_float32_distance+0x1c2>
movss  -0xc(%rbp),%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    1211 <_float32_distance+0xc1>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1050 <nextafter@plt>
ucomiss -0x8(%rbp),%xmm0
jne    1244 <_float32_distance+0xf4>
jp     1244 <_float32_distance+0xf4>
movl   $0x1,-0x4(%rbp)
jmp    1312 <_float32_distance+0x1c2>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12be <_float32_distance+0x16e>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    12be <_float32_distance+0x16e>
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
call   1030 <_float32_distance@plt>
mov    %eax,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
xor    %edi,%edi
mov    0x2d4d(%rip),%rax
sub    (%rax),%edi
xorps  %xmm0,%xmm0
call   1050 <nextafter@plt>
movaps %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
call   1030 <_float32_distance@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1312 <_float32_distance+0x1c2>
movss  -0x8(%rbp),%xmm0
call   1060 <eh_float32_to_uint32@plt>
mov    %eax,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
call   1060 <eh_float32_to_uint32@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jbe    1309 <_float32_distance+0x1b9>
jmp    12e9 <_float32_distance+0x199>
mov    -0x14(%rbp),%eax
xor    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
xor    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
xor    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1309 <_float32_distance+0x1b9>
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_float32_distance>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
ucomiss %xmm1,%xmm0
jne    1160 <_float32_distance+0x10>
jnp    11af <_float32_distance+0x5f>
movss  %xmm1,0x10(%rsp)
movss  %xmm0,0xc(%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
jne    11a6 <_float32_distance+0x56>
movss  0x10(%rsp),%xmm0
call   1040 <isnan@plt>
test   %rax,%rax
jne    11a6 <_float32_distance+0x56>
movss  0xc(%rsp),%xmm0
call   1070 <isinf@plt>
test   %rax,%rax
jne    11a6 <_float32_distance+0x56>
movss  0x10(%rsp),%xmm0
call   1070 <isinf@plt>
test   %rax,%rax
je     11b7 <_float32_distance+0x67>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
movss  0x10(%rsp),%xmm0
movaps %xmm0,%xmm1
movss  0xc(%rsp),%xmm2
maxss  %xmm2,%xmm1
movss  %xmm1,0x14(%rsp)
minss  %xmm0,%xmm2
movss  %xmm2,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
mov    0x2df8(%rip),%rbx
mov    (%rbx),%edi
call   1050 <nextafter@plt>
movss  0x14(%rsp),%xmm2
movss  0xc(%rsp),%xmm1
mov    $0x1,%eax
ucomiss %xmm2,%xmm0
jne    1207 <_float32_distance+0xb7>
jnp    11af <_float32_distance+0x5f>
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm2
jbe    1247 <_float32_distance+0xf7>
ucomiss %xmm1,%xmm0
jbe    1247 <_float32_distance+0xf7>
xorps  %xmm1,%xmm1
movaps %xmm2,%xmm0
call   1030 <_float32_distance@plt>
mov    %eax,%r14d
xor    %edi,%edi
sub    (%rbx),%edi
xorps  %xmm0,%xmm0
call   1050 <nextafter@plt>
movaps %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
call   1030 <_float32_distance@plt>
add    %r14d,%eax
add    $0x1,%eax
jmp    11af <_float32_distance+0x5f>
movaps %xmm2,%xmm0
call   1060 <eh_float32_to_uint32@plt>
mov    %eax,%ebx
movss  0xc(%rsp),%xmm0
call   1060 <eh_float32_to_uint32@plt>
mov    %eax,%ecx
cmp    %ebx,%eax
mov    %ebx,%eax
cmova  %ecx,%eax
cmova  %ebx,%ecx
sub    %ecx,%eax
jmp    11af <_float32_distance+0x5f>

LLVM IR (-O0):
@UINT32_MAX = global i32 0
@INFINITY = global i32 0
define i32 @_float32_distance(float %0, float %1) {
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
store float %0, float* %4
store float %1, float* %5
%9 = load float, float* %4
%10 = load float, float* %5
%11 = fcmp oeq float %9, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %91
13: ; preds = %2
%14 = load float, float* %4
%15 = call i64 @isnan(float %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %13
%18 = load float, float* %5
%19 = call i64 @isnan(float %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %17
%22 = load float, float* %4
%23 = call i64 @isinf(float %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load float, float* %5
%27 = call i64 @isinf(float %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25, %21, %17, %13
%30 = load i32, i32* @UINT32_MAX
store i32 %30, i32* %3
br label %91
31: ; preds = %25
%32 = load float, float* %5
%33 = load float, float* %4
%34 = fcmp ogt float %32, %33
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load float, float* %4
store float %36, float* %8
%37 = load float, float* %5
store float %37, float* %4
%38 = load float, float* %8
store float %38, float* %5
br label %39
39: ; preds = %35, %31
%40 = load float, float* %5
%41 = fpext float %40 to double
%42 = load i32, i32* @INFINITY
%43 = call float @nextafter(double %41, i32 %42)
%44 = load float, float* %4
%45 = fcmp oeq float %43, %44
br i1 %45, label %46, label %47
46: ; preds = %39
store i32 1, i32* %3
br label %91
47: ; preds = %39
%48 = load float, float* %4
%49 = fpext float %48 to double
%50 = fcmp ogt double %49, 0.000000e+00
br i1 %50, label %51, label %67
51: ; preds = %47
%52 = load float, float* %5
%53 = fpext float %52 to double
%54 = fcmp olt double %53, 0.000000e+00
br i1 %54, label %55, label %67
55: ; preds = %51
%56 = load float, float* %4
%57 = call i32 @_float32_distance(float %56, float 0.000000e+00)
store i32 %57, i32* %6
%58 = load float, float* %5
%59 = load i32, i32* @INFINITY
%60 = sub nsw i32 0, %59
%61 = call float @nextafter(double 0.000000e+00, i32 %60)
%62 = call i32 @_float32_distance(float %58, float %61)
%63 = add i32 1, %62
store i32 %63, i32* %7
%64 = load i32, i32* %6
%65 = load i32, i32* %7
%66 = add i32 %64, %65
store i32 %66, i32* %3
br label %91
67: ; preds = %51, %47
%68 = load float, float* %4
%69 = call i32 @eh_float32_to_uint32(float %68)
store i32 %69, i32* %6
%70 = load float, float* %5
%71 = call i32 @eh_float32_to_uint32(float %70)
store i32 %71, i32* %7
%72 = load i32, i32* %7
%73 = load i32, i32* %6
%74 = icmp ugt i32 %72, %73
br i1 %74, label %75, label %87
75: ; preds = %67
br label %76
76: ; preds = %75
%77 = load i32, i32* %7
%78 = load i32, i32* %6
%79 = xor i32 %78, %77
store i32 %79, i32* %6
%80 = load i32, i32* %6
%81 = load i32, i32* %7
%82 = xor i32 %81, %80
store i32 %82, i32* %7
%83 = load i32, i32* %7
%84 = load i32, i32* %6
%85 = xor i32 %84, %83
store i32 %85, i32* %6
br label %86
86: ; preds = %76
br label %87
87: ; preds = %86, %67
%88 = load i32, i32* %6
%89 = load i32, i32* %7
%90 = sub i32 %88, %89
store i32 %90, i32* %3
br label %91
91: ; preds = %87, %55, %46, %29, %12
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
@UINT32_MAX = global i32 0
@INFINITY = global i32 0
define i32 @_float32_distance(float %0, float %1) {
%3 = fcmp oeq float %0, %1
br i1 %3, label %30, label %4
4: ; preds = %2
%5 = tail call i64 @isnan(float %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = tail call i64 @isnan(float %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = tail call i64 @isinf(float %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i64 @isinf(float %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13, %10, %7, %4
%17 = load i32, i32* @UINT32_MAX
br label %30
18: ; preds = %13
%19 = fcmp ogt float %1, %0
%20 = select i1 %19, float %1, float %0
%21 = select i1 %19, float %0, float %1
%22 = fpext float %21 to double
%23 = load i32, i32* @INFINITY
%24 = tail call float @nextafter(double %22, i32 %23)
%25 = fcmp oeq float %24, %20
br i1 %25, label %30, label %26
26: ; preds = %18
%27 = fcmp ogt float %20, 0.000000e+00
%28 = fcmp olt float %21, 0.000000e+00
%29 = and i1 %27, %28
br i1 %29, label %32, label %40
30: ; preds = %16, %40, %2, %18, %32
%31 = phi i32 [ %39, %32 ], [ %17, %16 ], [ %46, %40 ], [ 0, %2 ], [ 1, %18 ]
ret i32 %31
32: ; preds = %26
%33 = tail call i32 @_float32_distance(float %20, float 0.000000e+00)
%34 = load i32, i32* @INFINITY
%35 = sub nsw i32 0, %34
%36 = tail call float @nextafter(double 0.000000e+00, i32 %35)
%37 = tail call i32 @_float32_distance(float %21, float %36)
%38 = add i32 %33, 1
%39 = add i32 %38, %37
br label %30
40: ; preds = %26
%41 = tail call i32 @eh_float32_to_uint32(float %20)
%42 = tail call i32 @eh_float32_to_uint32(float %21)
%43 = icmp ugt i32 %42, %41
%44 = select i1 %43, i32 %42, i32 %41
%45 = select i1 %43, i32 %41, i32 %42
%46 = sub i32 %44, %45
br label %30
}