#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 */
long double ceill(long double);
long double roundl(long double x) {
  long double res = 0.0L;
  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;
  }
  return res;
}


x86 assembly (clang, -O0):
<roundl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
fldz
fld    %st(0)
fstpt  -0x20(%rbp)
fldt   -0x10(%rbp)
fucomip %st(1),%st
fstp   %st(0)
jb     1177 <roundl+0x67>
jmp    1137 <roundl+0x27>
fldt   -0x10(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <ceill@plt>
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fldt   -0x10(%rbp)
fsubrp %st,%st(1)
flds   0xeab(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1172 <roundl+0x62>
jmp    1166 <roundl+0x56>
fldt   -0x20(%rbp)
fld1
fchs
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
jmp    11bc <roundl+0xac>
fldt   -0x10(%rbp)
fchs
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <ceill@plt>
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fldt   -0x10(%rbp)
faddp  %st,%st(1)
flds   0xe69(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    11b4 <roundl+0xa4>
jmp    11a8 <roundl+0x98>
fldt   -0x20(%rbp)
fld1
fchs
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fchs
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roundl>:
sub    $0x28,%rsp
fldt   0x30(%rsp)
fldz
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
fld    %st(0)
fstpt  0x1c(%rsp)
jae    1157 <roundl+0x47>
fchs
fstpt  (%rsp)
call   1030 <ceill@plt>
fldt   0x1c(%rsp)
fadd   %st(1),%st
flds   0xec2(%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
add    $0x28,%rsp
ret
fstpt  (%rsp)
call   1030 <ceill@plt>
fldt   0x1c(%rsp)
fsubr  %st(1),%st
flds   0xe95(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1152 <roundl+0x42>
fld1
fchs
faddp  %st,%st(1)
add    $0x28,%rsp
ret

LLVM IR (-O0):
define x86_fp80 @roundl(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %2
store x86_fp80 0xK00000000000000000000, x86_fp80* %3
%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
ret x86_fp80 %32
}

LLVM IR (-O2):
define x86_fp80 @roundl(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 ]
ret x86_fp80 %18
}