#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 */
float fabsf(float const);
int cmpfloats(const float *i_a, const float *i_b, size_t i_n) {
  do {
    const float d = *i_a++ - *i_b++;
    if (fabsf(d) > 0.00001f)
      return d < 0 ? -1 : 1;
  } while (--i_n);
  return 0;
}


x86 assembly (clang, -O0):
<cmpfloats>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movss  (%rax),%xmm0
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
subss  (%rax),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movaps 0xec9(%rip),%xmm1
pand   %xmm1,%xmm0
movss  0xead(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    117c <cmpfloats+0x7c>
movss  -0x24(%rbp),%xmm1
xorps  %xmm0,%xmm0
mov    $0x1,%eax
mov    $0xffffffff,%ecx
ucomiss %xmm1,%xmm0
cmova  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    119e <cmpfloats+0x9e>
jmp    1181 <cmpfloats+0x81>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1110 <cmpfloats+0x10>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmpfloats>:
xor    %eax,%eax
movaps 0xef7(%rip),%xmm0
movss  0xeff(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  (%rdi,%rax,4),%xmm2
subss  (%rsi,%rax,4),%xmm2
movaps %xmm2,%xmm3
andps  %xmm0,%xmm3
ucomiss %xmm1,%xmm3
ja     1141 <cmpfloats+0x41>
add    $0x1,%rax
cmp    %rax,%rdx
jne    1120 <cmpfloats+0x20>
xor    %eax,%eax
ret
xorps  %xmm0,%xmm0
xor    %eax,%eax
ucomiss %xmm2,%xmm0
setbe  %al
add    %eax,%eax
add    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @cmpfloats(float* %0, float* %1, i64 %2) {
%4 = alloca i32
%5 = alloca float*
%6 = alloca float*
%7 = alloca i64
%8 = alloca float
store float* %0, float** %5
store float* %1, float** %6
store i64 %2, i64* %7
br label %9
9: ; preds = %26, %3
%10 = load float*, float** %5
%11 = getelementptr inbounds float, float* %10, i32 1
store float* %11, float** %5
%12 = load float, float* %10
%13 = load float*, float** %6
%14 = getelementptr inbounds float, float* %13, i32 1
store float* %14, float** %6
%15 = load float, float* %13
%16 = fsub float %12, %15
store float %16, float* %8
%17 = load float, float* %8
%18 = call float @llvm.fabs.f32(float %17)
%19 = fcmp ogt float %18, 0x3EE4F8B580000000
br i1 %19, label %20, label %25
20: ; preds = %9
%21 = load float, float* %8
%22 = fcmp olt float %21, 0.000000e+00
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 -1, i32 1
store i32 %24, i32* %4
br label %31
25: ; preds = %9
br label %26
26: ; preds = %25
%27 = load i64, i64* %7
%28 = add i64 %27, -1
store i64 %28, i64* %7
%29 = icmp ne i64 %28, 0
br i1 %29, label %9, label %30
30: ; preds = %26
store i32 0, i32* %4
br label %31
31: ; preds = %30, %20
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
define i32 @cmpfloats(float* nocapture %0, float* nocapture %1, i64 %2) {
br label %4
4: ; preds = %13, %3
%5 = phi float* [ %0, %3 ], [ %15, %13 ]
%6 = phi float* [ %1, %3 ], [ %14, %13 ]
%7 = phi i64 [ %2, %3 ], [ %16, %13 ]
%8 = load float, float* %5
%9 = load float, float* %6
%10 = fsub float %8, %9
%11 = tail call float @llvm.fabs.f32(float %10)
%12 = fcmp ule float %11, 0x3EE4F8B580000000
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = getelementptr inbounds float, float* %6, i64 1
%15 = getelementptr inbounds float, float* %5, i64 1
%16 = add i64 %7, -1
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %4
18: ; preds = %4
%19 = fcmp olt float %10, 0.000000e+00
%20 = select i1 %19, i32 -1, i32 1
br label %21
21: ; preds = %13, %18
%22 = phi i32 [ %20, %18 ], [ 0, %13 ]
ret i32 %22
}