#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 */
double fastrand();
int /*<<< orphan*/ isnormal(double);
double modf(double, double *);
long long randround(double x) {
  double xint;
  double xfrac;
  if (!isnormal(x))
    return 0;
  xfrac = modf(x, &xint);
  if (xfrac > 0)
    if (fastrand() > xfrac)
      return (long long)xint + 1;
    else
      ;
  else if (xfrac < 0)
    if (fastrand() < -xfrac)
      return (long long)xint - 1;
  return (long long)xint;
}


x86 assembly (clang, -O0):
<randround>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <isnormal@plt>
cmp    $0x0,%eax
jne    115d <randround+0x2d>
movq   $0x0,-0x8(%rbp)
jmp    1216 <randround+0xe6>
movsd  -0x10(%rbp),%xmm0
lea    -0x18(%rbp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11b1 <randround+0x81>
mov    $0x0,%al
call   1050 <fastrand@plt>
ucomisd -0x20(%rbp),%xmm0
jbe    11a7 <randround+0x77>
cvttsd2si -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1216 <randround+0xe6>
jmp    11ac <randround+0x7c>
jmp    120c <randround+0xdc>
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1207 <randround+0xd7>
mov    $0x0,%al
call   1050 <fastrand@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    1202 <randround+0xd2>
cvttsd2si -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1216 <randround+0xe6>
jmp    1207 <randround+0xd7>
jmp    120c <randround+0xdc>
cvttsd2si -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randround>:
sub    $0x28,%rsp
movsd  %xmm0,0x10(%rsp)
call   1040 <isnormal@plt>
test   %eax,%eax
je     1182 <randround+0x52>
lea    0x8(%rsp),%rdi
movsd  0x10(%rsp),%xmm0
call   1030 <modf@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1189 <randround+0x59>
xor    %eax,%eax
movapd %xmm0,0x10(%rsp)
call   1050 <fastrand@plt>
ucomisd 0x10(%rsp),%xmm0
jbe    11c0 <randround+0x90>
cvttsd2si 0x8(%rsp),%rax
add    $0x1,%rax
add    $0x28,%rsp
ret
xor    %eax,%eax
add    $0x28,%rsp
ret
ucomisd %xmm0,%xmm1
jbe    11c0 <randround+0x90>
xor    %eax,%eax
movapd %xmm0,0x10(%rsp)
call   1050 <fastrand@plt>
movapd 0x10(%rsp),%xmm1
xorpd  0xe56(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11c0 <randround+0x90>
cvttsd2si 0x8(%rsp),%rax
add    $0xffffffffffffffff,%rax
add    $0x28,%rsp
ret
cvttsd2si 0x8(%rsp),%rax
add    $0x28,%rsp
ret

LLVM IR (-O0):
define i64 @randround(double %0) {
%2 = alloca i64
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
%6 = load double, double* %3
%7 = call i32 @isnormal(double %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %1
store i64 0, i64* %2
br label %42
10: ; preds = %1
%11 = load double, double* %3
%12 = call double @modf(double %11, double* %4)
store double %12, double* %5
%13 = load double, double* %5
%14 = fcmp ogt double %13, 0.000000e+00
br i1 %14, label %15, label %25
15: ; preds = %10
%16 = call double (...) @fastrand()
%17 = load double, double* %5
%18 = fcmp ogt double %16, %17
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load double, double* %4
%21 = fptosi double %20 to i64
%22 = add nsw i64 %21, 1
store i64 %22, i64* %2
br label %42
23: ; preds = %15
br label %24
24: ; preds = %23
br label %39
25: ; preds = %10
%26 = load double, double* %5
%27 = fcmp olt double %26, 0.000000e+00
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = call double (...) @fastrand()
%30 = load double, double* %5
%31 = fneg double %30
%32 = fcmp olt double %29, %31
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load double, double* %4
%35 = fptosi double %34 to i64
%36 = sub nsw i64 %35, 1
store i64 %36, i64* %2
br label %42
37: ; preds = %28
br label %38
38: ; preds = %37, %25
br label %39
39: ; preds = %38, %24
%40 = load double, double* %4
%41 = fptosi double %40 to i64
store i64 %41, i64* %2
br label %42
42: ; preds = %39, %33, %19, %9
%43 = load i64, i64* %2
ret i64 %43
}

LLVM IR (-O2):
define i64 @randround(double %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
%4 = tail call i32 @isnormal(double %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %29, label %6
6: ; preds = %1
%7 = call double @modf(double %0, double* %2)
%8 = fcmp ogt double %7, 0.000000e+00
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = tail call double (...) @fastrand()
%11 = fcmp ogt double %10, %7
br i1 %11, label %12, label %26
12: ; preds = %9
%13 = load double, double* %2
%14 = fptosi double %13 to i64
%15 = add nsw i64 %14, 1
br label %29
16: ; preds = %6
%17 = fcmp olt double %7, 0.000000e+00
br i1 %17, label %18, label %26
18: ; preds = %16
%19 = tail call double (...) @fastrand()
%20 = fneg double %7
%21 = fcmp olt double %19, %20
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load double, double* %2
%24 = fptosi double %23 to i64
%25 = add nsw i64 %24, -1
br label %29
26: ; preds = %16, %18, %9
%27 = load double, double* %2
%28 = fptosi double %27 to i64
br label %29
29: ; preds = %1, %26, %22, %12
%30 = phi i64 [ %15, %12 ], [ %28, %26 ], [ %25, %22 ], [ 0, %1 ]
ret i64 %30
}