#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__ LLONG_MAX;
scalar_t__ LLONG_MIN;
long double ceill(long double);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ isfinite(long double);
long long llroundl(long double x) {
  long double res;
  if (x >= 0.0L) {
    res = ceill(x);
    if (res - x > 0.5L)
      res -= 1.0L;
  } else {
    res = ceill(-x);
    if (res + x > 0.5L)
      res -= 1.0L;
    res = -res;
  }
  if (!isfinite(res) || res > (double)LLONG_MAX || res < (double)LLONG_MIN) {
    errno = ERANGE;
  }
  return (long long)res;
}


x86 assembly (clang, -O0):
<llroundl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     1184 <llroundl+0x64>
jmp    1144 <llroundl+0x24>
fldt   -0x10(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <ceill@plt>
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fldt   -0x10(%rbp)
fsubrp %st,%st(1)
flds   0xe9e(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    117f <llroundl+0x5f>
jmp    1173 <llroundl+0x53>
fldt   -0x20(%rbp)
fld1
fchs
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
jmp    11c9 <llroundl+0xa9>
fldt   -0x10(%rbp)
fchs
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <ceill@plt>
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fldt   -0x10(%rbp)
faddp  %st,%st(1)
flds   0xe5c(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    11c1 <llroundl+0xa1>
jmp    11b5 <llroundl+0x95>
fldt   -0x20(%rbp)
fld1
fchs
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fchs
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <isfinite@plt>
cmp    $0x0,%eax
je     122d <llroundl+0x10d>
fldt   -0x20(%rbp)
mov    0x2df7(%rip),%rax
cvtsi2sdq (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
fldl   -0x28(%rbp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
ja     122d <llroundl+0x10d>
jmp    1207 <llroundl+0xe7>
fldt   -0x20(%rbp)
mov    0x2dbf(%rip),%rax
cvtsi2sdq (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
fldl   -0x30(%rbp)
fucomip %st(1),%st
fstp   %st(0)
jbe    123f <llroundl+0x11f>
jmp    122d <llroundl+0x10d>
mov    0x2db4(%rip),%rax
mov    (%rax),%ecx
mov    0x2d8b(%rip),%rax
mov    %ecx,(%rax)
fldt   -0x20(%rbp)
fnstcw -0x3a(%rbp)
movzwl -0x3a(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x3c(%rbp)
fldcw  -0x3c(%rbp)
fistpll -0x38(%rbp)
fldcw  -0x3a(%rbp)
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<llroundl>:
sub    $0x38,%rsp
fldt   0x40(%rsp)
fldz
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
fld    %st(0)
fstpt  0x14(%rsp)
jae    1164 <llroundl+0x44>
fchs
fstpt  (%rsp)
call   1040 <ceill@plt>
fldt   0x14(%rsp)
fadd   %st(1),%st
flds   0xeb2(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
fld1
fchs
fadd   %st(1),%st
fxch   %st(1)
fcmovnbe %st(1),%st
fstp   %st(1)
fchs
jmp    1186 <llroundl+0x66>
fstpt  (%rsp)
call   1040 <ceill@plt>
fldt   0x14(%rsp)
fsubr  %st(1),%st
flds   0xe88(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1186 <llroundl+0x66>
fld1
fchs
faddp  %st,%st(1)
fld    %st(0)
fstpt  0x14(%rsp)
fstpt  (%rsp)
call   1030 <isfinite@plt>
fldt   0x14(%rsp)
test   %eax,%eax
je     11d7 <llroundl+0xb7>
mov    0x2e3d(%rip),%rax
cvtsi2sdq (%rax),%xmm0
movsd  %xmm0,0x30(%rsp)
fldl   0x30(%rsp)
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
ja     11d7 <llroundl+0xb7>
mov    0x2e0f(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdq (%rax),%xmm0
movsd  %xmm0,0x28(%rsp)
fldl   0x28(%rsp)
fucomip %st(1),%st
jbe    11e9 <llroundl+0xc9>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    0x2de1(%rip),%rcx
mov    %eax,(%rcx)
fnstcw 0x10(%rsp)
movzwl 0x10(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x12(%rsp)
fldcw  0x12(%rsp)
fistpll 0x20(%rsp)
fldcw  0x10(%rsp)
mov    0x20(%rsp),%rax
add    $0x38,%rsp
ret

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

LLVM IR (-O2):
@LLONG_MAX = global i64 0
@LLONG_MIN = global i64 0
@ERANGE = global i32 0
@errno = global i32 0
define i64 @llroundl(x86_fp80 %0) {
%2 = fcmp ult x86_fp80 %0, 0xK00000000000000000000
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = tail call x86_fp80 @llvm.ceil.f80(x86_fp80 %0)
%5 = fsub x86_fp80 %4, %0
%6 = fcmp ogt x86_fp80 %5, 0xK3FFE8000000000000000
br i1 %6, label %7, label %17
7: ; preds = %3
%8 = fadd x86_fp80 %4, 0xKBFFF8000000000000000
br label %17
9: ; preds = %1
%10 = fneg x86_fp80 %0
%11 = tail call x86_fp80 @llvm.ceil.f80(x86_fp80 %10)
%12 = fadd x86_fp80 %11, %0
%13 = fcmp ogt x86_fp80 %12, 0xK3FFE8000000000000000
%14 = fadd x86_fp80 %11, 0xKBFFF8000000000000000
%15 = select i1 %13, x86_fp80 %14, x86_fp80 %11
%16 = fneg x86_fp80 %15
br label %17
17: ; preds = %3, %7, %9
%18 = phi x86_fp80 [ %8, %7 ], [ %4, %3 ], [ %16, %9 ]
%19 = tail call i32 @isfinite(x86_fp80 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %31, label %21
21: ; preds = %17
%22 = load i64, i64* @LLONG_MAX
%23 = sitofp i64 %22 to double
%24 = fpext double %23 to x86_fp80
%25 = fcmp ogt x86_fp80 %18, %24
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = load i64, i64* @LLONG_MIN
%28 = sitofp i64 %27 to double
%29 = fpext double %28 to x86_fp80
%30 = fcmp olt x86_fp80 %18, %29
br i1 %30, label %31, label %33
31: ; preds = %26, %21, %17
%32 = load i32, i32* @ERANGE
store i32 %32, i32* @errno
br label %33
33: ; preds = %31, %26
%34 = fptosi x86_fp80 %18 to i64
ret i64 %34
}