#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 */
double fabs(double);
scalar_t__ isinf(double);
scalar_t__ isnan(double);
int cass_close_impl(double actual, double desired, double rel_tol,
                    double abs_tol) {
  if (actual == desired) {
    return 0;
  }
  if (isnan(actual) && isnan(desired)) {
    return 0;
  }
  if (isinf(actual) || isinf(desired)) {
    return 1;
  }
  double diff = fabs(desired - actual);
  return !(
      ((diff <= fabs(rel_tol * desired)) || (diff <= fabs(rel_tol * actual))) ||
      (diff <= abs_tol));
}


x86 assembly (clang, -O0):
<cass_close_impl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    115e <cass_close_impl+0x3e>
jp     115e <cass_close_impl+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    1253 <cass_close_impl+0x133>
movsd  -0x10(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1192 <cass_close_impl+0x72>
movsd  -0x18(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1192 <cass_close_impl+0x72>
movl   $0x0,-0x4(%rbp)
jmp    1253 <cass_close_impl+0x133>
movsd  -0x10(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
jne    11ba <cass_close_impl+0x9a>
movsd  -0x18(%rbp),%xmm0
call   1040 <isinf@plt>
cmp    $0x0,%rax
je     11c6 <cass_close_impl+0xa6>
movl   $0x1,-0x4(%rbp)
jmp    1253 <cass_close_impl+0x133>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movaps 0xe29(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movaps 0xe0a(%rip),%xmm2
pand   %xmm2,%xmm0
mov    $0x1,%al
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jae    1246 <cass_close_impl+0x126>
movsd  -0x30(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movaps 0xde1(%rip),%xmm2
pand   %xmm2,%xmm0
mov    $0x1,%al
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jae    1246 <cass_close_impl+0x126>
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cass_close_impl>:
push   %rbx
sub    $0x30,%rsp
ucomisd %xmm1,%xmm0
jne    1137 <cass_close_impl+0x17>
jp     1137 <cass_close_impl+0x17>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
ret
movapd %xmm1,(%rsp)
movsd  %xmm2,0x18(%rsp)
movsd  %xmm3,0x10(%rsp)
movapd %xmm0,0x20(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
je     1167 <cass_close_impl+0x47>
movapd (%rsp),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
jne    112d <cass_close_impl+0xd>
movapd 0x20(%rsp),%xmm0
call   1040 <isinf@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    112f <cass_close_impl+0xf>
movapd (%rsp),%xmm0
call   1040 <isinf@plt>
test   %rax,%rax
jne    112f <cass_close_impl+0xf>
movapd (%rsp),%xmm4
movapd %xmm4,%xmm0
movapd 0x20(%rsp),%xmm2
subsd  %xmm2,%xmm0
movapd 0xe5a(%rip),%xmm1
andpd  %xmm1,%xmm0
movsd  0x18(%rsp),%xmm3
mulsd  %xmm3,%xmm4
andpd  %xmm1,%xmm4
ucomisd %xmm0,%xmm4
jae    112d <cass_close_impl+0xd>
mulsd  %xmm3,%xmm2
andpd  0xe32(%rip),%xmm2
ucomisd %xmm0,%xmm2
mov    $0x0,%ebx
jae    112f <cass_close_impl+0xf>
xor    %ebx,%ebx
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
setb   %bl
jmp    112f <cass_close_impl+0xf>

LLVM IR (-O0):
define i32 @cass_close_impl(double %0, double %1, double %2, double %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%11 = load double, double* %6
%12 = load double, double* %7
%13 = fcmp oeq double %11, %12
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 0, i32* %5
br label %59
15: ; preds = %4
%16 = load double, double* %6
%17 = call i64 @isnan(double %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load double, double* %7
%21 = call i64 @isnan(double %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 0, i32* %5
br label %59
24: ; preds = %19, %15
%25 = load double, double* %6
%26 = call i64 @isinf(double %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load double, double* %7
%30 = call i64 @isinf(double %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28, %24
store i32 1, i32* %5
br label %59
33: ; preds = %28
%34 = load double, double* %7
%35 = load double, double* %6
%36 = fsub double %34, %35
%37 = call double @llvm.fabs.f64(double %36)
store double %37, double* %10
%38 = load double, double* %10
%39 = load double, double* %8
%40 = load double, double* %7
%41 = fmul double %39, %40
%42 = call double @llvm.fabs.f64(double %41)
%43 = fcmp ole double %38, %42
br i1 %43, label %55, label %44
44: ; preds = %33
%45 = load double, double* %10
%46 = load double, double* %8
%47 = load double, double* %6
%48 = fmul double %46, %47
%49 = call double @llvm.fabs.f64(double %48)
%50 = fcmp ole double %45, %49
br i1 %50, label %55, label %51
51: ; preds = %44
%52 = load double, double* %10
%53 = load double, double* %9
%54 = fcmp ole double %52, %53
br label %55
55: ; preds = %51, %44, %33
%56 = phi i1 [ true, %44 ], [ true, %33 ], [ %54, %51 ]
%57 = xor i1 %56, true
%58 = zext i1 %57 to i32
store i32 %58, i32* %5
br label %59
59: ; preds = %55, %32, %23, %14
%60 = load i32, i32* %5
ret i32 %60
}

LLVM IR (-O2):
define i32 @cass_close_impl(double %0, double %1, double %2, double %3) {
%5 = fcmp oeq double %0, %1
br i1 %5, label %31, label %6
6: ; preds = %4
%7 = tail call i64 @isnan(double %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i64 @isnan(double %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %9, %6
%13 = tail call i64 @isinf(double %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = tail call i64 @isinf(double %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %15
%19 = fsub double %1, %0
%20 = tail call double @llvm.fabs.f64(double %19)
%21 = fmul double %1, %2
%22 = tail call double @llvm.fabs.f64(double %21)
%23 = fcmp ugt double %20, %22
br i1 %23, label %24, label %31
24: ; preds = %18
%25 = fmul double %0, %2
%26 = tail call double @llvm.fabs.f64(double %25)
%27 = fcmp ugt double %20, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = fcmp ugt double %20, %3
%30 = zext i1 %29 to i32
br label %31
31: ; preds = %18, %24, %28, %12, %15, %9, %4
%32 = phi i32 [ 0, %4 ], [ 0, %9 ], [ 1, %15 ], [ 1, %12 ], [ 0, %24 ], [ 0, %18 ], [ %30, %28 ]
ret i32 %32
}