#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 int /*<<< orphan*/ jmp_buf;

/* Variables and functions */
int /*<<< orphan*/ set_float_handler(int /*<<< orphan*/ *);
scalar_t__ setjmp(int /*<<< orphan*/);
int compare_float(double a, double b) {
  jmp_buf handler;
  int result;
  a += 1.0;
  if (setjmp(handler)) {
    set_float_handler(0);
    return 0;
  }
  set_float_handler(&handler);
  if (a == b)
    result = 0x01;
  else if (a > b)
    result = 0x02;
  else if (a < b)
    result = 0x04;
  else
    result = 0;
  set_float_handler(0);
  return result;
}


x86 assembly (clang, -O0):
<compare_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  0xec6(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <setjmp@plt>
cmp    $0x0,%rax
je     116b <compare_float+0x4b>
xor    %eax,%eax
mov    %eax,%edi
call   1030 <set_float_handler@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f2 <compare_float+0xd2>
lea    -0x1c(%rbp),%rdi
call   1030 <set_float_handler@plt>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    1196 <compare_float+0x76>
jp     1196 <compare_float+0x76>
movl   $0x1,-0x20(%rbp)
jmp    11e3 <compare_float+0xc3>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11b2 <compare_float+0x92>
movl   $0x2,-0x20(%rbp)
jmp    11de <compare_float+0xbe>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d2 <compare_float+0xb2>
movl   $0x4,-0x20(%rbp)
jmp    11d9 <compare_float+0xb9>
movl   $0x0,-0x20(%rbp)
jmp    11de <compare_float+0xbe>
jmp    11e3 <compare_float+0xc3>
xor    %eax,%eax
mov    %eax,%edi
call   1030 <set_float_handler@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_float>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1040 <setjmp@plt>
test   %rax,%rax
je     113f <compare_float+0x1f>
xor    %ebx,%ebx
jmp    1189 <compare_float+0x69>
movsd  0x8(%rsp),%xmm0
addsd  0xeb3(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x1c(%rsp),%rdi
call   1030 <set_float_handler@plt>
mov    $0x1,%ebx
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    1176 <compare_float+0x56>
jnp    1189 <compare_float+0x69>
mov    $0x2,%ebx
ja     1189 <compare_float+0x69>
xor    %ebx,%ebx
ucomisd %xmm1,%xmm0
seta   %bl
shl    $0x2,%ebx
xor    %edi,%edi
call   1030 <set_float_handler@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @compare_float(double %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store double %0, double* %4
store double %1, double* %5
%8 = load double, double* %4
%9 = fadd double %8, 1.000000e+00
store double %9, double* %4
%10 = load i32, i32* %6
%11 = call i64 @setjmp(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @set_float_handler(i32* null)
store i32 0, i32* %3
br label %37
15: ; preds = %2
%16 = call i32 @set_float_handler(i32* %6)
%17 = load double, double* %4
%18 = load double, double* %5
%19 = fcmp oeq double %17, %18
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %7
br label %34
21: ; preds = %15
%22 = load double, double* %4
%23 = load double, double* %5
%24 = fcmp ogt double %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 2, i32* %7
br label %33
26: ; preds = %21
%27 = load double, double* %4
%28 = load double, double* %5
%29 = fcmp olt double %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 4, i32* %7
br label %32
31: ; preds = %26
store i32 0, i32* %7
br label %32
32: ; preds = %31, %30
br label %33
33: ; preds = %32, %25
br label %34
34: ; preds = %33, %20
%35 = call i32 @set_float_handler(i32* null)
%36 = load i32, i32* %7
store i32 %36, i32* %3
br label %37
37: ; preds = %34, %13
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @compare_float(double %0, double %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = fadd double %0, 1.000000e+00
%6 = tail call i64 @setjmp(i32 undef)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @set_float_handler(i32* null)
br label %21
10: ; preds = %2
%11 = call i32 @set_float_handler(i32* %3)
%12 = fcmp oeq double %5, %1
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = fcmp ogt double %5, %1
br i1 %14, label %18, label %15
15: ; preds = %13
%16 = fcmp olt double %5, %1
%17 = select i1 %16, i32 4, i32 0
br label %18
18: ; preds = %15, %13, %10
%19 = phi i32 [ 1, %10 ], [ 2, %13 ], [ %17, %15 ]
%20 = call i32 @set_float_handler(i32* null)
br label %21
21: ; preds = %18, %8
%22 = phi i32 [ 0, %8 ], [ %19, %18 ]
ret i32 %22
}