#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 */
scalar_t__ isnan(double);
int my_compare_double(double da, double db) {
  if (isnan(da))
    return isnan(db) ? 0 : 1;
  else if (isnan(db))
    return -1;
  else
    return (da == db) ? 0 : (da > db ? 1 : -1);
}


x86 assembly (clang, -O0):
<my_compare_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1159 <my_compare_double+0x49>
movsd  -0x18(%rbp),%xmm0
call   1030 <isnan@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <my_compare_double+0xad>
movsd  -0x18(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1179 <my_compare_double+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <my_compare_double+0xad>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    1199 <my_compare_double+0x89>
jp     1199 <my_compare_double+0x89>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b7 <my_compare_double+0xa7>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    $0xffffffff,%eax
mov    $0x1,%ecx
ucomisd %xmm1,%xmm0
cmova  %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_compare_double>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1030 <isnan@plt>
mov    %rax,%rbx
movsd  (%rsp),%xmm0
call   1030 <isnan@plt>
mov    %rax,%rcx
test   %rbx,%rbx
je     1144 <my_compare_double+0x34>
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    116e <my_compare_double+0x5e>
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm0
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    116e <my_compare_double+0x5e>
xor    %eax,%eax
xor    %ecx,%ecx
ucomisd %xmm0,%xmm1
seta   %cl
lea    -0x1(%rcx,%rcx,1),%ecx
cmovne %ecx,%eax
cmovp  %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @my_compare_double(double %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = call i64 @isnan(double %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load double, double* %5
%11 = call i64 @isnan(double %10)
%12 = icmp ne i64 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i32 0, i32 1
store i32 %14, i32* %3
br label %33
15: ; preds = %2
%16 = load double, double* %5
%17 = call i64 @isnan(double %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %3
br label %33
20: ; preds = %15
%21 = load double, double* %4
%22 = load double, double* %5
%23 = fcmp oeq double %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
br label %31
25: ; preds = %20
%26 = load double, double* %4
%27 = load double, double* %5
%28 = fcmp ogt double %26, %27
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 1, i32 -1
br label %31
31: ; preds = %25, %24
%32 = phi i32 [ 0, %24 ], [ %30, %25 ]
store i32 %32, i32* %3
br label %33
33: ; preds = %31, %19, %9
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @my_compare_double(double %0, double %1) {
%3 = tail call i64 @isnan(double %0)
%4 = icmp eq i64 %3, 0
%5 = tail call i64 @isnan(double %1)
%6 = icmp eq i64 %5, 0
br i1 %4, label %9, label %7
7: ; preds = %2
%8 = zext i1 %6 to i32
br label %15
9: ; preds = %2
br i1 %6, label %10, label %15
10: ; preds = %9
%11 = fcmp oeq double %0, %1
%12 = fcmp ogt double %0, %1
%13 = select i1 %12, i32 1, i32 -1
%14 = select i1 %11, i32 0, i32 %13
br label %15
15: ; preds = %9, %10, %7
%16 = phi i32 [ %8, %7 ], [ %14, %10 ], [ -1, %9 ]
ret i32 %16
}