#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__ uint64_t;

/* Variables and functions */
scalar_t__ UINT64_MAX;
scalar_t__ isnan(float);
uint64_t __hsail_cvt_zeroi_sat_u64_f32(float a) {
  if (isnan(a))
    return 0;
  if (a >= (float)UINT64_MAX)
    return UINT64_MAX;
  else if (a <= 0.0f)
    return 0;
  return (uint64_t)a;
}


x86 assembly (clang, -O0):
<__hsail_cvt_zeroi_sat_u64_f32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     113e <__hsail_cvt_zeroi_sat_u64_f32+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    1194 <__hsail_cvt_zeroi_sat_u64_f32+0x84>
movss  -0xc(%rbp),%xmm0
mov    0x2e8e(%rip),%rax
cvtsi2ssq (%rax),%xmm1
ucomiss %xmm1,%xmm0
jb     116b <__hsail_cvt_zeroi_sat_u64_f32+0x5b>
mov    0x2e79(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1194 <__hsail_cvt_zeroi_sat_u64_f32+0x84>
xorps  %xmm0,%xmm0
ucomiss -0xc(%rbp),%xmm0
jb     1185 <__hsail_cvt_zeroi_sat_u64_f32+0x75>
movq   $0x0,-0x8(%rbp)
jmp    1194 <__hsail_cvt_zeroi_sat_u64_f32+0x84>
jmp    118a <__hsail_cvt_zeroi_sat_u64_f32+0x7a>
cvttss2si -0xc(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__hsail_cvt_zeroi_sat_u64_f32>:
push   %rax
movss  %xmm0,0x4(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
je     1125 <__hsail_cvt_zeroi_sat_u64_f32+0x15>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2eac(%rip),%rax
mov    (%rax),%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jae    114f <__hsail_cvt_zeroi_sat_u64_f32+0x3f>
xorps  %xmm0,%xmm0
ucomiss %xmm1,%xmm0
jae    1121 <__hsail_cvt_zeroi_sat_u64_f32+0x11>
cvttss2si %xmm1,%rax
pop    %rcx
ret

LLVM IR (-O0):
@UINT64_MAX = global i64 0
define i64 @__hsail_cvt_zeroi_sat_u64_f32(float %0) {
%2 = alloca i64
%3 = alloca float
store float %0, float* %3
%4 = load float, float* %3
%5 = call i64 @isnan(float %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 float, float* %3
%10 = load i64, i64* @UINT64_MAX
%11 = sitofp i64 %10 to float
%12 = fcmp oge float %9, %11
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = load i64, i64* @UINT64_MAX
store i64 %14, i64* %2
br label %23
15: ; preds = %8
%16 = load float, float* %3
%17 = fcmp ole float %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 float, float* %3
%22 = fptosi float %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):
@UINT64_MAX = global i64 0
define i64 @__hsail_cvt_zeroi_sat_u64_f32(float %0) {
%2 = tail call i64 @isnan(float %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = load i64, i64* @UINT64_MAX
%6 = sitofp i64 %5 to float
%7 = fcmp ugt float %6, %0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = fcmp ugt float %0, 0.000000e+00
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = fptosi float %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
}