#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 floorl(long double);
int /*<<< orphan*/ isfinite(long double);
long double roundl(long double x) {
  long double t;
  if (!isfinite(x))
    return x;
  if (x >= 0.0) {
    t = floorl(x);
    if (t - x <= -0.5)
      t += 1.0;
    return t;
  } else {
    t = floorl(-x);
    if (t + x <= -0.5)
      t += 1.0;
    return -t;
  }
}


x86 assembly (clang, -O0):
<roundl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <isfinite@plt>
cmp    $0x0,%eax
jne    114f <roundl+0x2f>
fldt   -0x20(%rbp)
fstpt  -0x10(%rbp)
jmp    11e8 <roundl+0xc8>
fldt   -0x20(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     11a7 <roundl+0x87>
jmp    1165 <roundl+0x45>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <floorl@plt>
fstpt  -0x30(%rbp)
fldt   -0x30(%rbp)
fldt   -0x20(%rbp)
fsubrp %st,%st(1)
flds   0xe7d(%rip)
fucomip %st(1),%st
fstp   %st(0)
jb     119c <roundl+0x7c>
jmp    1192 <roundl+0x72>
fldt   -0x30(%rbp)
fld1
faddp  %st,%st(1)
fstpt  -0x30(%rbp)
fldt   -0x30(%rbp)
fstpt  -0x10(%rbp)
jmp    11e8 <roundl+0xc8>
fldt   -0x20(%rbp)
fchs
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <floorl@plt>
fstpt  -0x30(%rbp)
fldt   -0x30(%rbp)
fldt   -0x20(%rbp)
faddp  %st,%st(1)
flds   0xe39(%rip)
fucomip %st(1),%st
fstp   %st(0)
jb     11e0 <roundl+0xc0>
jmp    11d6 <roundl+0xb6>
fldt   -0x30(%rbp)
fld1
faddp  %st,%st(1)
fstpt  -0x30(%rbp)
fldt   -0x30(%rbp)
fchs
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roundl>:
sub    $0x28,%rsp
fldt   0x30(%rsp)
fld    %st(0)
fstpt  0x1c(%rsp)
fstpt  (%rsp)
call   1030 <isfinite@plt>
test   %eax,%eax
je     116f <roundl+0x4f>
fldz
fldt   0x1c(%rsp)
fucomi %st(1),%st
fstp   %st(1)
jae    1178 <roundl+0x58>
fchs
fstpt  (%rsp)
call   1040 <floorl@plt>
fldt   0x1c(%rsp)
fadd   %st(1),%st
flds   0xea4(%rip)
fucomip %st(1),%st
fstp   %st(0)
fld1
fadd   %st(1),%st
fcmovb %st(1),%st
fstp   %st(1)
fchs
add    $0x28,%rsp
ret
fldt   0x1c(%rsp)
add    $0x28,%rsp
ret
fstpt  (%rsp)
call   1040 <floorl@plt>
fldt   0x1c(%rsp)
fsubr  %st(1),%st
flds   0xe74(%rip)
fucomip %st(1),%st
fstp   %st(0)
fld1
fadd   %st(1),%st
fcmovb %st(1),%st
fstp   %st(1)
add    $0x28,%rsp
ret

LLVM IR (-O0):
define x86_fp80 @roundl(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca x86_fp80
%4 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %3
%5 = load x86_fp80, x86_fp80* %3
%6 = call i32 @isfinite(x86_fp80 %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = load x86_fp80, x86_fp80* %3
store x86_fp80 %9, x86_fp80* %2
br label %39
10: ; preds = %1
%11 = load x86_fp80, x86_fp80* %3
%12 = fcmp oge x86_fp80 %11, 0xK00000000000000000000
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load x86_fp80, x86_fp80* %3
%15 = call x86_fp80 @llvm.floor.f80(x86_fp80 %14)
store x86_fp80 %15, x86_fp80* %4
%16 = load x86_fp80, x86_fp80* %4
%17 = load x86_fp80, x86_fp80* %3
%18 = fsub x86_fp80 %16, %17
%19 = fcmp ole x86_fp80 %18, 0xKBFFE8000000000000000
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load x86_fp80, x86_fp80* %4
%22 = fadd x86_fp80 %21, 0xK3FFF8000000000000000
store x86_fp80 %22, x86_fp80* %4
br label %23
23: ; preds = %20, %13
%24 = load x86_fp80, x86_fp80* %4
store x86_fp80 %24, x86_fp80* %2
br label %39
25: ; preds = %10
%26 = load x86_fp80, x86_fp80* %3
%27 = fneg x86_fp80 %26
%28 = call x86_fp80 @llvm.floor.f80(x86_fp80 %27)
store x86_fp80 %28, x86_fp80* %4
%29 = load x86_fp80, x86_fp80* %4
%30 = load x86_fp80, x86_fp80* %3
%31 = fadd x86_fp80 %29, %30
%32 = fcmp ole x86_fp80 %31, 0xKBFFE8000000000000000
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = load x86_fp80, x86_fp80* %4
%35 = fadd x86_fp80 %34, 0xK3FFF8000000000000000
store x86_fp80 %35, x86_fp80* %4
br label %36
36: ; preds = %33, %25
%37 = load x86_fp80, x86_fp80* %4
%38 = fneg x86_fp80 %37
store x86_fp80 %38, x86_fp80* %2
br label %39
39: ; preds = %36, %23, %8
%40 = load x86_fp80, x86_fp80* %2
ret x86_fp80 %40
}

LLVM IR (-O2):
define x86_fp80 @roundl(x86_fp80 %0) {
%2 = tail call i32 @isfinite(x86_fp80 %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = fcmp ult x86_fp80 %0, 0xK00000000000000000000
br i1 %5, label %12, label %6
6: ; preds = %4
%7 = tail call x86_fp80 @llvm.floor.f80(x86_fp80 %0)
%8 = fsub x86_fp80 %7, %0
%9 = fcmp ugt x86_fp80 %8, 0xKBFFE8000000000000000
%10 = fadd x86_fp80 %7, 0xK3FFF8000000000000000
%11 = select i1 %9, x86_fp80 %7, x86_fp80 %10
br label %20
12: ; preds = %4
%13 = fneg x86_fp80 %0
%14 = tail call x86_fp80 @llvm.floor.f80(x86_fp80 %13)
%15 = fadd x86_fp80 %14, %0
%16 = fcmp ugt x86_fp80 %15, 0xKBFFE8000000000000000
%17 = fadd x86_fp80 %14, 0xK3FFF8000000000000000
%18 = select i1 %16, x86_fp80 %14, x86_fp80 %17
%19 = fneg x86_fp80 %18
br label %20
20: ; preds = %1, %12, %6
%21 = phi x86_fp80 [ %11, %6 ], [ %19, %12 ], [ %0, %1 ]
ret x86_fp80 %21
}