#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 modf(double, double *);
long Round_MGRS(double value) {
  double ivalue;
  long ival;
  double fraction = modf(value, &ivalue);
  ival = (long)(ivalue);
  if ((fraction > 0.5) || ((fraction == 0.5) && (ival % 2 == 1)))
    ival++;
  return (ival);
}


x86 assembly (clang, -O0):
<Round_MGRS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    -0x10(%rbp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xeb9(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1186 <Round_MGRS+0x76>
movsd  -0x20(%rbp),%xmm0
movsd  0xea2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1192 <Round_MGRS+0x82>
jp     1192 <Round_MGRS+0x82>
mov    -0x18(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x1,%rdx
jne    1192 <Round_MGRS+0x82>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Round_MGRS>:
push   %rax
mov    %rsp,%rdi
call   1030 <modf@plt>
cvttsd2si (%rsp),%rax
ucomisd 0xed9(%rip),%xmm0
ja     114f <Round_MGRS+0x3f>
ucomisd 0xecf(%rip),%xmm0
jne    1153 <Round_MGRS+0x43>
jp     1153 <Round_MGRS+0x43>
mov    %rax,%rcx
shr    $0x3f,%rcx
add    %rax,%rcx
and    $0xfffffffffffffffe,%rcx
mov    %rax,%rdx
sub    %rcx,%rdx
cmp    $0x1,%rdx
jne    1153 <Round_MGRS+0x43>
add    $0x1,%rax
pop    %rcx
ret

LLVM IR (-O0):
define i64 @Round_MGRS(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i64
%5 = alloca double
store double %0, double* %2
%6 = load double, double* %2
%7 = call double @modf(double %6, double* %3)
store double %7, double* %5
%8 = load double, double* %3
%9 = fptosi double %8 to i64
store i64 %9, i64* %4
%10 = load double, double* %5
%11 = fcmp ogt double %10, 5.000000e-01
br i1 %11, label %19, label %12
12: ; preds = %1
%13 = load double, double* %5
%14 = fcmp oeq double %13, 5.000000e-01
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i64, i64* %4
%17 = srem i64 %16, 2
%18 = icmp eq i64 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %15, %1
%20 = load i64, i64* %4
%21 = add nsw i64 %20, 1
store i64 %21, i64* %4
br label %22
22: ; preds = %19, %15, %12
%23 = load i64, i64* %4
ret i64 %23
}

LLVM IR (-O2):
define i64 @Round_MGRS(double %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
%4 = call double @modf(double %0, double* %2)
%5 = load double, double* %2
%6 = fptosi double %5 to i64
%7 = fcmp ogt double %4, 5.000000e-01
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = fcmp oeq double %4, 5.000000e-01
%10 = srem i64 %6, 2
%11 = icmp eq i64 %10, 1
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %13, label %15
13: ; preds = %8, %1
%14 = add nsw i64 %6, 1
br label %15
15: ; preds = %13, %8
%16 = phi i64 [ %14, %13 ], [ %6, %8 ]
ret i64 %16
}