#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 scalar_t__ uint8_t;

/* Variables and functions */
scalar_t__ UINT8_MAX;
scalar_t__ isnan(double);
uint8_t __hsail_cvt_zeroi_sat_u8_f64(double a) {
  if (isnan(a))
    return 0;
  if (a >= (double)UINT8_MAX)
    return UINT8_MAX;
  else if (a <= 0.0f)
    return 0;
  return (uint8_t)a;
}


x86 assembly (clang, -O0):
<__hsail_cvt_zeroi_sat_u8_f64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     113e <__hsail_cvt_zeroi_sat_u8_f64+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    1196 <__hsail_cvt_zeroi_sat_u8_f64+0x86>
movsd  -0x10(%rbp),%xmm0
mov    0x2e96(%rip),%rax
cvtsi2sdq (%rax),%xmm1
ucomisd %xmm1,%xmm0
jb     116c <__hsail_cvt_zeroi_sat_u8_f64+0x5c>
mov    0x2e80(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1196 <__hsail_cvt_zeroi_sat_u8_f64+0x86>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1187 <__hsail_cvt_zeroi_sat_u8_f64+0x77>
movq   $0x0,-0x8(%rbp)
jmp    1196 <__hsail_cvt_zeroi_sat_u8_f64+0x86>
jmp    118c <__hsail_cvt_zeroi_sat_u8_f64+0x7c>
cvttsd2si -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__hsail_cvt_zeroi_sat_u8_f64>:
push   %rax
movsd  %xmm0,(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
je     1124 <__hsail_cvt_zeroi_sat_u8_f64+0x14>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2eb5(%rip),%rax
mov    (%rax),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    1150 <__hsail_cvt_zeroi_sat_u8_f64+0x40>
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    1120 <__hsail_cvt_zeroi_sat_u8_f64+0x10>
cvttsd2si %xmm1,%rax
pop    %rcx
ret

LLVM IR (-O0):
@UINT8_MAX = global i64 0
define i64 @__hsail_cvt_zeroi_sat_u8_f64(double %0) {
%2 = alloca i64
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = call i64 @isnan(double %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i64 0, i64* %2
br label %23
8: ; preds = %1
%9 = load double, double* %3
%10 = load i64, i64* @UINT8_MAX
%11 = sitofp i64 %10 to double
%12 = fcmp oge double %9, %11
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = load i64, i64* @UINT8_MAX
store i64 %14, i64* %2
br label %23
15: ; preds = %8
%16 = load double, double* %3
%17 = fcmp ole double %16, 0.000000e+00
br i1 %17, label %18, label %19
18: ; preds = %15
store i64 0, i64* %2
br label %23
19: ; preds = %15
br label %20
20: ; preds = %19
%21 = load double, double* %3
%22 = fptosi double %21 to i64
store i64 %22, i64* %2
br label %23
23: ; preds = %20, %18, %13, %7
%24 = load i64, i64* %2
ret i64 %24
}

LLVM IR (-O2):
@UINT8_MAX = global i64 0
define i64 @__hsail_cvt_zeroi_sat_u8_f64(double %0) {
%2 = tail call i64 @isnan(double %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = load i64, i64* @UINT8_MAX
%6 = sitofp i64 %5 to double
%7 = fcmp ugt double %6, %0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = fcmp ugt double %0, 0.000000e+00
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = fptosi double %0 to i64
br label %12
12: ; preds = %8, %4, %1, %10
%13 = phi i64 [ %11, %10 ], [ 0, %1 ], [ %5, %4 ], [ 0, %8 ]
ret i64 %13
}