#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);
scalar_t__ signbit(double);
double __hsail_max_f64(double a, double b) {
  if (isnan(a))
    return b;
  else if (isnan(b))
    return a;
  else if (a == 0.0 && b == 0.0 && signbit(a))
    return b;
  else if (a < b)
    return b;
  else
    return a;
}


x86 assembly (clang, -O0):
<__hsail_max_f64>:
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     1155 <__hsail_max_f64+0x35>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f8 <__hsail_max_f64+0xd8>
movsd  -0x18(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1178 <__hsail_max_f64+0x58>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f8 <__hsail_max_f64+0xd8>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11cb <__hsail_max_f64+0xab>
jp     11cb <__hsail_max_f64+0xab>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11cb <__hsail_max_f64+0xab>
jp     11cb <__hsail_max_f64+0xab>
movsd  -0x10(%rbp),%xmm0
call   1040 <signbit@plt>
cmp    $0x0,%rax
je     11cb <__hsail_max_f64+0xab>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f8 <__hsail_max_f64+0xd8>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ee <__hsail_max_f64+0xce>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f8 <__hsail_max_f64+0xd8>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__hsail_max_f64>:
sub    $0x18,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
je     1142 <__hsail_max_f64+0x22>
movsd  0x8(%rsp),%xmm1
jmp    1194 <__hsail_max_f64+0x74>
movsd  0x8(%rsp),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
je     115a <__hsail_max_f64+0x3a>
movsd  0x10(%rsp),%xmm1
jmp    1194 <__hsail_max_f64+0x74>
xorpd  %xmm2,%xmm2
movsd  0x10(%rsp),%xmm0
ucomisd %xmm2,%xmm0
movsd  0x8(%rsp),%xmm1
jne    1190 <__hsail_max_f64+0x70>
jp     1190 <__hsail_max_f64+0x70>
ucomisd %xmm2,%xmm1
jne    1190 <__hsail_max_f64+0x70>
jp     1190 <__hsail_max_f64+0x70>
call   1040 <signbit@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
test   %rax,%rax
jne    1194 <__hsail_max_f64+0x74>
maxsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @__hsail_max_f64(double %0, double %1) {
%3 = alloca double
%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 %11
9: ; preds = %2
%10 = load double, double* %5
store double %10, double* %3
br label %37
11: ; preds = %2
%12 = load double, double* %5
%13 = call i64 @isnan(double %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load double, double* %4
store double %16, double* %3
br label %37
17: ; preds = %11
%18 = load double, double* %4
%19 = fcmp oeq double %18, 0.000000e+00
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = load double, double* %5
%22 = fcmp oeq double %21, 0.000000e+00
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load double, double* %4
%25 = call i64 @signbit(double %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load double, double* %5
store double %28, double* %3
br label %37
29: ; preds = %23, %20, %17
%30 = load double, double* %4
%31 = load double, double* %5
%32 = fcmp olt double %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = load double, double* %5
store double %34, double* %3
br label %37
35: ; preds = %29
%36 = load double, double* %4
store double %36, double* %3
br label %37
37: ; preds = %35, %33, %27, %15, %9
%38 = load double, double* %3
ret double %38
}

LLVM IR (-O2):
define double @__hsail_max_f64(double %0, double %1) {
%3 = tail call i64 @isnan(double %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %2
%6 = tail call i64 @isnan(double %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = fcmp oeq double %0, 0.000000e+00
%10 = fcmp oeq double %1, 0.000000e+00
%11 = and i1 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i64 @signbit(double %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12, %8
%16 = fcmp olt double %0, %1
%17 = select i1 %16, double %1, double %0
br label %18
18: ; preds = %15, %12, %5, %2
%19 = phi double [ %1, %2 ], [ %0, %5 ], [ %1, %12 ], [ %17, %15 ]
ret double %19
}