#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 */
typedef double int32_t;

/* Variables and functions */
double const copysignk(double, double);
double fabsk(double);
scalar_t__ xisinf(double);
__attribute__((visibility("default"))) const double xround(double d) {
  double x = d + 0.5;
  double fr = x - (double)(1LL << 31) * (int32_t)(x * (1.0 / (1LL << 31)));
  fr = fr - (int32_t)fr;
  if (fr == 0 && x <= 0)
    x--;
  fr = fr < 0 ? fr + 1.0 : fr;
  x = d == 0.49999999999999994449 ? 0 : x;
  return (xisinf(d) || fabsk(d) >= (double)(1LL << 52)) ? d
                                                        : copysignk(x - fr, d);
}


x86 assembly (clang, -O0):
<xround>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xecb(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  0xeac(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xe97(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11bd <xround+0x8d>
jp     11bd <xround+0x8d>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11bd <xround+0x8d>
movsd  0xe65(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11e2 <xround+0xb2>
movsd  0xe4d(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11ec <xround+0xbc>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe25(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1220 <xround+0xf0>
jp     1220 <xround+0xf0>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    122a <xround+0xfa>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <xisinf@plt>
cmp    $0x0,%rax
jne    1264 <xround+0x134>
movsd  -0x8(%rbp),%xmm0
call   1050 <fabsk@plt>
movsd  0xdd6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1273 <xround+0x143>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    128c <xround+0x15c>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
call   1030 <copysignk@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xround>:
push   %rax
movsd  %xmm0,(%rsp)
call   1040 <xisinf@plt>
test   %rax,%rax
jne    11ff <xround+0xcf>
movsd  (%rsp),%xmm0
call   1050 <fabsk@plt>
ucomisd 0xeda(%rip),%xmm0
jae    11ff <xround+0xcf>
movsd  0xe9c(%rip),%xmm0
movsd  (%rsp),%xmm6
addsd  %xmm6,%xmm0
movsd  0xe93(%rip),%xmm1
mulsd  %xmm0,%xmm1
mulsd  0xe8f(%rip),%xmm1
addsd  %xmm0,%xmm1
subsd  %xmm1,%xmm1
movsd  0xe87(%rip),%xmm2
addsd  %xmm0,%xmm2
xorpd  %xmm3,%xmm3
movsd  0xe7f(%rip),%xmm4
addsd  %xmm1,%xmm4
movapd %xmm1,%xmm5
cmpltsd %xmm3,%xmm5
andpd  %xmm5,%xmm4
andnpd %xmm1,%xmm5
cmpeqsd %xmm3,%xmm1
andpd  %xmm1,%xmm2
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
movapd %xmm0,%xmm2
cmplesd %xmm3,%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
orpd   %xmm4,%xmm5
movsd  0xe40(%rip),%xmm0
cmpeqsd %xmm6,%xmm0
andnpd %xmm2,%xmm0
subsd  %xmm5,%xmm0
movapd %xmm6,%xmm1
pop    %rax
jmp    1030 <copysignk@plt>
movsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @xround(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %2
%5 = load double, double* %2
%6 = fadd double %5, 5.000000e-01
store double %6, double* %3
%7 = load double, double* %3
%8 = load double, double* %3
%9 = fmul double %8, 0x3E00000000000000
%10 = call double @llvm.fmuladd.f64(double 0xC1E0000000000000, double %9, double %7)
store double %10, double* %4
%11 = load double, double* %4
%12 = load double, double* %4
%13 = fsub double %11, %12
store double %13, double* %4
%14 = load double, double* %4
%15 = fcmp oeq double %14, 0.000000e+00
br i1 %15, label %16, label %22
16: ; preds = %1
%17 = load double, double* %3
%18 = fcmp ole double %17, 0.000000e+00
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load double, double* %3
%21 = fadd double %20, -1.000000e+00
store double %21, double* %3
br label %22
22: ; preds = %19, %16, %1
%23 = load double, double* %4
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load double, double* %4
%27 = fadd double %26, 1.000000e+00
br label %30
28: ; preds = %22
%29 = load double, double* %4
br label %30
30: ; preds = %28, %25
%31 = phi double [ %27, %25 ], [ %29, %28 ]
store double %31, double* %4
%32 = load double, double* %2
%33 = fcmp oeq double %32, 0x3FDFFFFFFFFFFFFF
br i1 %33, label %34, label %35
34: ; preds = %30
br label %37
35: ; preds = %30
%36 = load double, double* %3
br label %37
37: ; preds = %35, %34
%38 = phi double [ 0.000000e+00, %34 ], [ %36, %35 ]
store double %38, double* %3
%39 = load double, double* %2
%40 = call i64 @xisinf(double %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %37
%43 = load double, double* %2
%44 = call double @fabsk(double %43)
%45 = fcmp oge double %44, 0x4330000000000000
br i1 %45, label %46, label %48
46: ; preds = %42, %37
%47 = load double, double* %2
br label %54
48: ; preds = %42
%49 = load double, double* %3
%50 = load double, double* %4
%51 = fsub double %49, %50
%52 = load double, double* %2
%53 = call double @copysignk(double %51, double %52)
br label %54
54: ; preds = %48, %46
%55 = phi double [ %47, %46 ], [ %53, %48 ]
ret double %55
}

LLVM IR (-O2):
define double @xround(double %0) {
%2 = fadd double %0, 5.000000e-01
%3 = fmul double %2, 0x3E00000000000000
%4 = tail call double @llvm.fmuladd.f64(double %3, double 0xC1E0000000000000, double %2)
%5 = fsub double %4, %4
%6 = fcmp oeq double %5, 0.000000e+00
%7 = fcmp ole double %2, 0.000000e+00
%8 = and i1 %7, %6
%9 = fadd double %2, -1.000000e+00
%10 = select i1 %8, double %9, double %2
%11 = fcmp olt double %5, 0.000000e+00
%12 = fadd double %5, 1.000000e+00
%13 = select i1 %11, double %12, double %5
%14 = fcmp oeq double %0, 0x3FDFFFFFFFFFFFFF
%15 = select i1 %14, double 0.000000e+00, double %10
%16 = tail call i64 @xisinf(double %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %1
%19 = tail call double @fabsk(double %0)
%20 = fcmp ult double %19, 0x4330000000000000
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = fsub double %15, %13
%23 = tail call double @copysignk(double %22, double %0)
br label %24
24: ; preds = %1, %18, %21
%25 = phi double [ %23, %21 ], [ %0, %18 ], [ %0, %1 ]
ret double %25
}