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

/* Variables and functions */
scalar_t__ INT16_MAX;
scalar_t__ INT16_MIN;
scalar_t__ isnan(float);
int16_t __hsail_cvt_zeroi_sat_s16_f32(float a) {
  if (isnan(a))
    return 0;
  if (a >= (float)INT16_MAX)
    return INT16_MAX;
  if (a <= (float)INT16_MIN)
    return INT16_MIN;
  return (int16_t)a;
}


x86 assembly (clang, -O0):
<__hsail_cvt_zeroi_sat_s16_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_s16_f32+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <__hsail_cvt_zeroi_sat_s16_f32+0x92>
movss  -0xc(%rbp),%xmm0
mov    0x2e96(%rip),%rax
cvtsi2ssq (%rax),%xmm1
ucomiss %xmm1,%xmm0
jb     116b <__hsail_cvt_zeroi_sat_s16_f32+0x5b>
mov    0x2e81(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11a2 <__hsail_cvt_zeroi_sat_s16_f32+0x92>
movss  -0xc(%rbp),%xmm1
mov    0x2e61(%rip),%rax
cvtsi2ssq (%rax),%xmm0
ucomiss %xmm1,%xmm0
jb     1198 <__hsail_cvt_zeroi_sat_s16_f32+0x88>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11a2 <__hsail_cvt_zeroi_sat_s16_f32+0x92>
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_s16_f32>:
push   %rax
movss  %xmm0,0x4(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
je     1125 <__hsail_cvt_zeroi_sat_s16_f32+0x15>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2eb4(%rip),%rax
mov    (%rax),%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jae    115e <__hsail_cvt_zeroi_sat_s16_f32+0x4e>
mov    0x2e8f(%rip),%rax
mov    (%rax),%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
ucomiss %xmm1,%xmm0
jae    115e <__hsail_cvt_zeroi_sat_s16_f32+0x4e>
cvttss2si %xmm1,%rax
pop    %rcx
ret

LLVM IR (-O0):
@INT16_MAX = global i64 0
@INT16_MIN = global i64 0
define i64 @__hsail_cvt_zeroi_sat_s16_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 %25
8: ; preds = %1
%9 = load float, float* %3
%10 = load i64, i64* @INT16_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* @INT16_MAX
store i64 %14, i64* %2
br label %25
15: ; preds = %8
%16 = load float, float* %3
%17 = load i64, i64* @INT16_MIN
%18 = sitofp i64 %17 to float
%19 = fcmp ole float %16, %18
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i64, i64* @INT16_MIN
store i64 %21, i64* %2
br label %25
22: ; preds = %15
%23 = load float, float* %3
%24 = fptosi float %23 to i64
store i64 %24, i64* %2
br label %25
25: ; preds = %22, %20, %13, %7
%26 = load i64, i64* %2
ret i64 %26
}

LLVM IR (-O2):
@INT16_MAX = global i64 0
@INT16_MIN = global i64 0
define i64 @__hsail_cvt_zeroi_sat_s16_f32(float %0) {
%2 = tail call i64 @isnan(float %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = load i64, i64* @INT16_MAX
%6 = sitofp i64 %5 to float
%7 = fcmp ugt float %6, %0
br i1 %7, label %8, label %14
8: ; preds = %4
%9 = load i64, i64* @INT16_MIN
%10 = sitofp i64 %9 to float
%11 = fcmp ult float %10, %0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = fptosi float %0 to i64
br label %14
14: ; preds = %8, %4, %1, %12
%15 = phi i64 [ %13, %12 ], [ 0, %1 ], [ %5, %4 ], [ %9, %8 ]
ret i64 %15
}