#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 float_compare(const void *a, const void *b, size_t size) {
  if (!size)
    return 0;
  const float esp = 0.0001;
  const float *p = (const float *)a;
  const float *q = (const float *)b;
  float d = *p - *q;
  if (d < esp && d > -esp)
    return 0;
  if (d < 0)
    return -1;
  return 1;
}


x86 assembly (clang, -O0):
<float_compare>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1127 <float_compare+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11ad <float_compare+0xad>
movss  0xed1(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x38(%rbp),%rax
subss  (%rax),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  0xe9f(%rip),%xmm0
ucomiss -0x3c(%rbp),%xmm0
jbe    118d <float_compare+0x8d>
movss  -0x3c(%rbp),%xmm0
movss  0xe8c(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    118d <float_compare+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    11ad <float_compare+0xad>
xorps  %xmm0,%xmm0
ucomiss -0x3c(%rbp),%xmm0
jbe    11a6 <float_compare+0xa6>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <float_compare+0xad>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_compare>:
test   %rdx,%rdx
je     1137 <float_compare+0x37>
movss  (%rdi),%xmm0
subss  (%rsi),%xmm0
xorps  %xmm1,%xmm1
xor    %ecx,%ecx
ucomiss %xmm0,%xmm1
setbe  %cl
xor    %eax,%eax
ucomiss 0xedf(%rip),%xmm0
lea    -0x1(%rcx,%rcx,1),%ecx
cmovbe %ecx,%eax
movss  0xed4(%rip),%xmm1
ucomiss %xmm0,%xmm1
cmovbe %ecx,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @float_compare(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca float
%9 = alloca float*
%10 = alloca float*
%11 = alloca float
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%12 = load i64, i64* %7
%13 = icmp ne i64 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %3
store i32 0, i32* %4
br label %36
15: ; preds = %3
store float 0x3F1A36E2E0000000, float* %8
%16 = load i8*, i8** %5
%17 = bitcast i8* %16 to float*
store float* %17, float** %9
%18 = load i8*, i8** %6
%19 = bitcast i8* %18 to float*
store float* %19, float** %10
%20 = load float*, float** %9
%21 = load float, float* %20
%22 = load float*, float** %10
%23 = load float, float* %22
%24 = fsub float %21, %23
store float %24, float* %11
%25 = load float, float* %11
%26 = fcmp olt float %25, 0x3F1A36E2E0000000
br i1 %26, label %27, label %31
27: ; preds = %15
%28 = load float, float* %11
%29 = fcmp ogt float %28, 0xBF1A36E2E0000000
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 0, i32* %4
br label %36
31: ; preds = %27, %15
%32 = load float, float* %11
%33 = fcmp olt float %32, 0.000000e+00
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 -1, i32* %4
br label %36
35: ; preds = %31
store i32 1, i32* %4
br label %36
36: ; preds = %35, %34, %30, %14
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @float_compare(i8* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %17, label %5
5: ; preds = %3
%6 = bitcast i8* %0 to float*
%7 = bitcast i8* %1 to float*
%8 = load float, float* %6
%9 = load float, float* %7
%10 = fsub float %8, %9
%11 = fcmp olt float %10, 0x3F1A36E2E0000000
%12 = fcmp ogt float %10, 0xBF1A36E2E0000000
%13 = and i1 %11, %12
%14 = fcmp olt float %10, 0.000000e+00
%15 = select i1 %14, i32 -1, i32 1
%16 = select i1 %13, i32 0, i32 %15
br label %17
17: ; preds = %3, %5
%18 = phi i32 [ %16, %5 ], [ 0, %3 ]
ret i32 %18
}