#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 floor(double);
int /*<<< orphan*/ is_fraction_a_half(double);
double round(double);
double lr_round_half_even(double value, double rf) {
  double tmp;
  value *= rf;
  if (!is_fraction_a_half(value))
    return round(value) / rf;
  tmp = floor(value);
  if ((int)tmp & 1)
    return (tmp + 1) / rf;
  return tmp / rf;
}


x86 assembly (clang, -O0):
<lr_round_half_even>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <is_fraction_a_half@plt>
cmp    $0x0,%eax
jne    117d <lr_round_half_even+0x4d>
movsd  -0x10(%rbp),%xmm0
call   1040 <round@plt>
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c8 <lr_round_half_even+0x98>
movsd  -0x10(%rbp),%xmm0
call   1050 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x20(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11b9 <lr_round_half_even+0x89>
movsd  0xe5b(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c8 <lr_round_half_even+0x98>
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lr_round_half_even>:
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <is_fraction_a_half@plt>
test   %eax,%eax
je     116a <lr_round_half_even+0x3a>
movsd  0x8(%rsp),%xmm0
call   1050 <floor@plt>
cvttsd2si %xmm0,%eax
test   $0x1,%al
je     1175 <lr_round_half_even+0x45>
addsd  0xe98(%rip),%xmm0
jmp    1175 <lr_round_half_even+0x45>
movsd  0x8(%rsp),%xmm0
call   1040 <round@plt>
divsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @lr_round_half_even(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %4
store double %1, double* %5
%7 = load double, double* %5
%8 = load double, double* %4
%9 = fmul double %8, %7
store double %9, double* %4
%10 = load double, double* %4
%11 = call i32 @is_fraction_a_half(double %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = load double, double* %4
%15 = call double @llvm.round.f64(double %14)
%16 = load double, double* %5
%17 = fdiv double %15, %16
store double %17, double* %3
br label %34
18: ; preds = %2
%19 = load double, double* %4
%20 = call double @llvm.floor.f64(double %19)
store double %20, double* %6
%21 = load double, double* %6
%22 = fptosi double %21 to i32
%23 = and i32 %22, 1
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load double, double* %6
%27 = fadd double %26, 1.000000e+00
%28 = load double, double* %5
%29 = fdiv double %27, %28
store double %29, double* %3
br label %34
30: ; preds = %18
%31 = load double, double* %6
%32 = load double, double* %5
%33 = fdiv double %31, %32
store double %33, double* %3
br label %34
34: ; preds = %30, %25, %13
%35 = load double, double* %3
ret double %35
}

LLVM IR (-O2):
define double @lr_round_half_even(double %0, double %1) {
%3 = fmul double %0, %1
%4 = tail call i32 @is_fraction_a_half(double %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call double @llvm.round.f64(double %3)
br label %15
8: ; preds = %2
%9 = tail call double @llvm.floor.f64(double %3)
%10 = fptosi double %9 to i32
%11 = and i32 %10, 1
%12 = icmp eq i32 %11, 0
%13 = fadd double %9, 1.000000e+00
%14 = select i1 %12, double %9, double %13
br label %15
15: ; preds = %8, %6
%16 = phi double [ %7, %6 ], [ %14, %8 ]
%17 = fdiv double %16, %1
ret double %17
}