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

/* Variables and functions */
scalar_t__ isinf(float);
scalar_t__ isnan(float);
scalar_t__ signbit(float);
uint8_t cvt_neari_sat_u8_f32(float a) {
  if (isinf(a)) {
    if (signbit(a))
      return 0;
    else
      return 255;
  } else if (isnan(a))
    return 0;
  else if (a < 0.0)
    return 0;
  else if (a > 255.0)
    return 255;
  else
    return (uint8_t)a;
}


x86 assembly (clang, -O0):
<cvt_neari_sat_u8_f32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     117d <cvt_neari_sat_u8_f32+0x4d>
movss  -0x8(%rbp),%xmm0
call   1040 <signbit@plt>
cmp    $0x0,%rax
je     1171 <cvt_neari_sat_u8_f32+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11ee <cvt_neari_sat_u8_f32+0xbe>
movl   $0xff,-0x4(%rbp)
jmp    11ee <cvt_neari_sat_u8_f32+0xbe>
movss  -0x8(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     119d <cvt_neari_sat_u8_f32+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    11ee <cvt_neari_sat_u8_f32+0xbe>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11bf <cvt_neari_sat_u8_f32+0x8f>
movl   $0x0,-0x4(%rbp)
jmp    11ee <cvt_neari_sat_u8_f32+0xbe>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe30(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e6 <cvt_neari_sat_u8_f32+0xb6>
movl   $0xff,-0x4(%rbp)
jmp    11ee <cvt_neari_sat_u8_f32+0xbe>
cvttss2si -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cvt_neari_sat_u8_f32>:
push   %rax
movss  %xmm0,0x4(%rsp)
call   1050 <isinf@plt>
test   %rax,%rax
je     115b <cvt_neari_sat_u8_f32+0x2b>
movss  0x4(%rsp),%xmm0
call   1040 <signbit@plt>
xor    %ecx,%ecx
test   %rax,%rax
mov    $0xff,%eax
cmovne %ecx,%eax
pop    %rcx
ret
movss  0x4(%rsp),%xmm0
call   1030 <isnan@plt>
mov    %rax,%rcx
xor    %eax,%eax
xorps  %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm1,%xmm0
ja     1193 <cvt_neari_sat_u8_f32+0x63>
test   %rcx,%rcx
jne    1193 <cvt_neari_sat_u8_f32+0x63>
movaps %xmm1,%xmm0
mov    $0xff,%eax
ucomiss 0xe73(%rip),%xmm1
ja     1193 <cvt_neari_sat_u8_f32+0x63>
cvttss2si %xmm0,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @cvt_neari_sat_u8_f32(float %0) {
%2 = alloca i32
%3 = alloca float
store float %0, float* %3
%4 = load float, float* %3
%5 = call i64 @isinf(float %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load float, float* %3
%9 = call i64 @signbit(float %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %7
store i32 0, i32* %2
br label %31
12: ; preds = %7
store i32 255, i32* %2
br label %31
13: ; preds = %1
%14 = load float, float* %3
%15 = call i64 @isnan(float %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 0, i32* %2
br label %31
18: ; preds = %13
%19 = load float, float* %3
%20 = fpext float %19 to double
%21 = fcmp olt double %20, 0.000000e+00
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 0, i32* %2
br label %31
23: ; preds = %18
%24 = load float, float* %3
%25 = fpext float %24 to double
%26 = fcmp ogt double %25, 2.550000e+02
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 255, i32* %2
br label %31
28: ; preds = %23
%29 = load float, float* %3
%30 = fptosi float %29 to i32
store i32 %30, i32* %2
br label %31
31: ; preds = %28, %27, %22, %17, %12, %11
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
define i32 @cvt_neari_sat_u8_f32(float %0) {
%2 = tail call i64 @isinf(float %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i64 @signbit(float %0)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i32 255, i32 0
br label %17
8: ; preds = %1
%9 = tail call i64 @isnan(float %0)
%10 = icmp ne i64 %9, 0
%11 = fcmp olt float %0, 0.000000e+00
%12 = or i1 %11, %10
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = fcmp ogt float %0, 2.550000e+02
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = fptosi float %0 to i32
br label %17
17: ; preds = %13, %8, %4, %15
%18 = phi i32 [ %16, %15 ], [ %7, %4 ], [ 0, %8 ], [ 255, %13 ]
ret i32 %18
}