#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 */
int /*<<< orphan*/ ERANGE;
scalar_t__ LONG_MAX;
scalar_t__ LONG_MIN;
float ceilf(float);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ isfinite(float);
long lroundf(float x) {
  float res;
  if (x >= 0.0F) {
    res = ceilf(x);
    if (res - x > 0.5F)
      res -= 1.0F;
  } else {
    res = ceilf(-x);
    if (res + x > 0.5F)
      res -= 1.0F;
    res = -res;
  }
  if (!isfinite(res) || res > (float)LONG_MAX || res < (float)LONG_MIN) {
    errno = ERANGE;
  }
  return (long)res;
}


x86 assembly (clang, -O0):
<lroundf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1183 <lroundf+0x63>
movss  -0x4(%rbp),%xmm0
call   1040 <ceilf@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
subss  -0x4(%rbp),%xmm0
movss  0xea1(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    117e <lroundf+0x5e>
movss  -0x8(%rbp),%xmm0
movss  0xe8f(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11e7 <lroundf+0xc7>
movss  -0x4(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1040 <ceilf@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
addss  -0x4(%rbp),%xmm0
movss  0xe4f(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    11d0 <lroundf+0xb0>
movss  -0x8(%rbp),%xmm0
movss  0xe3d(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <isfinite@plt>
cmp    $0x0,%eax
je     122e <lroundf+0x10e>
movss  -0x8(%rbp),%xmm0
mov    0x2dca(%rip),%rax
cvtsi2ssq (%rax),%xmm1
ucomiss %xmm1,%xmm0
ja     122e <lroundf+0x10e>
movss  -0x8(%rbp),%xmm1
mov    0x2dc8(%rip),%rax
cvtsi2ssq (%rax),%xmm0
ucomiss %xmm1,%xmm0
jbe    1240 <lroundf+0x120>
mov    0x2dab(%rip),%rax
mov    (%rax),%ecx
mov    0x2d8a(%rip),%rax
mov    %ecx,(%rax)
cvttss2si -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lroundf>:
sub    $0x18,%rsp
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
movaps %xmm1,(%rsp)
movaps %xmm1,%xmm0
jae    1175 <lroundf+0x55>
xorps  0xed3(%rip),%xmm0
call   1040 <ceilf@plt>
movaps (%rsp),%xmm3
addss  %xmm0,%xmm3
movss  0xeb2(%rip),%xmm1
addss  %xmm0,%xmm1
movss  0xea2(%rip),%xmm2
cmpltss %xmm3,%xmm2
andps  %xmm2,%xmm1
andnps %xmm0,%xmm2
orps   %xmm1,%xmm2
xorps  0xe9d(%rip),%xmm2
jmp    1193 <lroundf+0x73>
call   1040 <ceilf@plt>
movaps %xmm0,%xmm2
subss  (%rsp),%xmm0
ucomiss 0xe77(%rip),%xmm0
jbe    1193 <lroundf+0x73>
addss  0xe71(%rip),%xmm2
movaps %xmm2,(%rsp)
movaps %xmm2,%xmm0
call   1030 <isfinite@plt>
movaps (%rsp),%xmm1
test   %eax,%eax
je     11cf <lroundf+0xaf>
mov    0x2e22(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2ssq (%rax),%xmm0
ucomiss %xmm0,%xmm1
ja     11cf <lroundf+0xaf>
mov    0x2e26(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2ssq (%rax),%xmm0
ucomiss %xmm1,%xmm0
jbe    11e1 <lroundf+0xc1>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    0x2de9(%rip),%rcx
mov    %eax,(%rcx)
cvttss2si %xmm1,%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@ERANGE = global i32 0
@errno = global i32 0
define i64 @lroundf(float %0) {
%2 = alloca float
%3 = alloca float
store float %0, float* %2
%4 = load float, float* %2
%5 = fcmp oge float %4, 0.000000e+00
br i1 %5, label %6, label %17
6: ; preds = %1
%7 = load float, float* %2
%8 = call float @llvm.ceil.f32(float %7)
store float %8, float* %3
%9 = load float, float* %3
%10 = load float, float* %2
%11 = fsub float %9, %10
%12 = fcmp ogt float %11, 5.000000e-01
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = load float, float* %3
%15 = fsub float %14, 1.000000e+00
store float %15, float* %3
br label %16
16: ; preds = %13, %6
br label %31
17: ; preds = %1
%18 = load float, float* %2
%19 = fneg float %18
%20 = call float @llvm.ceil.f32(float %19)
store float %20, float* %3
%21 = load float, float* %3
%22 = load float, float* %2
%23 = fadd float %21, %22
%24 = fcmp ogt float %23, 5.000000e-01
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load float, float* %3
%27 = fsub float %26, 1.000000e+00
store float %27, float* %3
br label %28
28: ; preds = %25, %17
%29 = load float, float* %3
%30 = fneg float %29
store float %30, float* %3
br label %31
31: ; preds = %28, %16
%32 = load float, float* %3
%33 = call i32 @isfinite(float %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %31
%36 = load float, float* %3
%37 = load i64, i64* @LONG_MAX
%38 = sitofp i64 %37 to float
%39 = fcmp ogt float %36, %38
br i1 %39, label %45, label %40
40: ; preds = %35
%41 = load float, float* %3
%42 = load i64, i64* @LONG_MIN
%43 = sitofp i64 %42 to float
%44 = fcmp olt float %41, %43
br i1 %44, label %45, label %47
45: ; preds = %40, %35, %31
%46 = load i32, i32* @ERANGE
store i32 %46, i32* @errno
br label %47
47: ; preds = %45, %40
%48 = load float, float* %3
%49 = fptosi float %48 to i64
ret i64 %49
}

LLVM IR (-O2):
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@ERANGE = global i32 0
@errno = global i32 0
define i64 @lroundf(float %0) {
%2 = fcmp ult float %0, 0.000000e+00
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = tail call float @llvm.ceil.f32(float %0)
%5 = fsub float %4, %0
%6 = fcmp ogt float %5, 5.000000e-01
br i1 %6, label %7, label %17
7: ; preds = %3
%8 = fadd float %4, -1.000000e+00
br label %17
9: ; preds = %1
%10 = fneg float %0
%11 = tail call float @llvm.ceil.f32(float %10)
%12 = fadd float %11, %0
%13 = fcmp ogt float %12, 5.000000e-01
%14 = fadd float %11, -1.000000e+00
%15 = select i1 %13, float %14, float %11
%16 = fneg float %15
br label %17
17: ; preds = %3, %7, %9
%18 = phi float [ %8, %7 ], [ %4, %3 ], [ %16, %9 ]
%19 = tail call i32 @isfinite(float %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %17
%22 = load i64, i64* @LONG_MAX
%23 = sitofp i64 %22 to float
%24 = fcmp ogt float %18, %23
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i64, i64* @LONG_MIN
%27 = sitofp i64 %26 to float
%28 = fcmp olt float %18, %27
br i1 %28, label %29, label %31
29: ; preds = %25, %21, %17
%30 = load i32, i32* @ERANGE
store i32 %30, i32* @errno
br label %31
31: ; preds = %29, %25
%32 = fptosi float %18 to i64
ret i64 %32
}