#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 floorl(long double);
double fmodl(long double, int);
long double roundl(long double x) {
  if (x < 0.0)
    return fmodl(x, -1) <= -0.5 ? floorl(x) : ceill(x);
  else
    return fmodl(x, 1) < 0.5 ? floorl(x) : ceill(x);
}


x86 assembly (clang, -O0):
<roundl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
jbe    11a9 <roundl+0x79>
jmp    1152 <roundl+0x22>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
mov    $0xffffffff,%edi
call   1030 <fmodl@plt>
movaps %xmm0,%xmm1
movsd  0xe99(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     118e <roundl+0x5e>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1050 <floorl@plt>
fstpt  -0x2c(%rbp)
jmp    119e <roundl+0x6e>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <ceill@plt>
fstpt  -0x2c(%rbp)
fldt   -0x2c(%rbp)
fstpt  -0x10(%rbp)
jmp    11fb <roundl+0xcb>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
mov    $0x1,%edi
call   1030 <fmodl@plt>
movaps %xmm0,%xmm1
movsd  0xe3a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e5 <roundl+0xb5>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1050 <floorl@plt>
fstpt  -0x38(%rbp)
jmp    11f5 <roundl+0xc5>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <ceill@plt>
fstpt  -0x38(%rbp)
fldt   -0x38(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roundl>:
sub    $0x28,%rsp
fldt   0x30(%rsp)
fldz
fucomip %st(1),%st
fld    %st(0)
fstpt  0x1c(%rsp)
jbe    1170 <roundl+0x40>
fstpt  (%rsp)
mov    $0xffffffff,%edi
call   1030 <fmodl@plt>
movsd  0xeaf(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    118b <roundl+0x5b>
fldt   0x1c(%rsp)
fstpt  (%rsp)
call   1040 <ceill@plt>
add    $0x28,%rsp
ret
fstpt  (%rsp)
mov    $0x1,%edi
call   1030 <fmodl@plt>
movsd  0xe7b(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    115f <roundl+0x2f>
fldt   0x1c(%rsp)
fstpt  (%rsp)
call   1050 <floorl@plt>
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* %3
%4 = load x86_fp80, x86_fp80* %3
%5 = fcmp olt x86_fp80 %4, 0xK00000000000000000000
br i1 %5, label %6, label %18
6: ; preds = %1
%7 = load x86_fp80, x86_fp80* %3
%8 = call double @fmodl(x86_fp80 %7, i32 -1)
%9 = fcmp ole double %8, -5.000000e-01
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load x86_fp80, x86_fp80* %3
%12 = call x86_fp80 @llvm.floor.f80(x86_fp80 %11)
br label %16
13: ; preds = %6
%14 = load x86_fp80, x86_fp80* %3
%15 = call x86_fp80 @llvm.ceil.f80(x86_fp80 %14)
br label %16
16: ; preds = %13, %10
%17 = phi x86_fp80 [ %12, %10 ], [ %15, %13 ]
store x86_fp80 %17, x86_fp80* %2
br label %30
18: ; preds = %1
%19 = load x86_fp80, x86_fp80* %3
%20 = call double @fmodl(x86_fp80 %19, i32 1)
%21 = fcmp olt double %20, 5.000000e-01
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load x86_fp80, x86_fp80* %3
%24 = call x86_fp80 @llvm.floor.f80(x86_fp80 %23)
br label %28
25: ; preds = %18
%26 = load x86_fp80, x86_fp80* %3
%27 = call x86_fp80 @llvm.ceil.f80(x86_fp80 %26)
br label %28
28: ; preds = %25, %22
%29 = phi x86_fp80 [ %24, %22 ], [ %27, %25 ]
store x86_fp80 %29, x86_fp80* %2
br label %30
30: ; preds = %28, %16
%31 = load x86_fp80, x86_fp80* %2
ret x86_fp80 %31
}

LLVM IR (-O2):
define x86_fp80 @roundl(x86_fp80 %0) {
%2 = fcmp olt x86_fp80 %0, 0xK00000000000000000000
br i1 %2, label %3, label %10
3: ; preds = %1
%4 = tail call double @fmodl(x86_fp80 %0, i32 -1)
%5 = fcmp ugt double %4, -5.000000e-01
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call x86_fp80 @llvm.floor.f80(x86_fp80 %0)
br label %17
8: ; preds = %3
%9 = tail call x86_fp80 @llvm.ceil.f80(x86_fp80 %0)
br label %17
10: ; preds = %1
%11 = tail call double @fmodl(x86_fp80 %0, i32 1)
%12 = fcmp olt double %11, 5.000000e-01
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call x86_fp80 @llvm.floor.f80(x86_fp80 %0)
br label %17
15: ; preds = %10
%16 = tail call x86_fp80 @llvm.ceil.f80(x86_fp80 %0)
br label %17
17: ; preds = %13, %15, %6, %8
%18 = phi x86_fp80 [ %7, %6 ], [ %9, %8 ], [ %14, %13 ], [ %16, %15 ]
ret x86_fp80 %18
}