#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 *);
int Round_MGRS(double value) {
  double ivalue;
  int ival;
  double fraction = modf(value, &ivalue);
  ival = (int)(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),%eax
mov    %eax,-0x14(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xebb(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1180 <Round_MGRS+0x70>
movsd  -0x20(%rbp),%xmm0
movsd  0xea4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1189 <Round_MGRS+0x79>
jp     1189 <Round_MGRS+0x79>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1189 <Round_MGRS+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Round_MGRS>:
push   %rax
mov    %rsp,%rdi
call   1030 <modf@plt>
cvttsd2si (%rsp),%eax
ucomisd 0xeda(%rip),%xmm0
ja     1147 <Round_MGRS+0x37>
ucomisd 0xed0(%rip),%xmm0
jne    114a <Round_MGRS+0x3a>
jp     114a <Round_MGRS+0x3a>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
mov    %eax,%edx
sub    %ecx,%edx
cmp    $0x1,%edx
jne    114a <Round_MGRS+0x3a>
add    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @Round_MGRS(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%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 i32
store i32 %9, i32* %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 i32, i32* %4
%17 = srem i32 %16, 2
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %15, %1
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %22
22: ; preds = %19, %15, %12
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
define i32 @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 i32
%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 i32 %6, 2
%11 = icmp eq i32 %10, 1
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %13, label %15
13: ; preds = %8, %1
%14 = add nsw i32 %6, 1
br label %15
15: ; preds = %13, %8
%16 = phi i32 [ %14, %13 ], [ %6, %8 ]
ret i32 %16
}