double round(x)
double x;
{
  double y, r;
  y = floor(x);
  r = x - y;
  if (r > 0.5)
    goto rndup;
  if (r == 0.5) {
    r = y - 2.0 * floor(0.5 * y);
    if (r == 1.0) {
    rndup:
      y += 1.0;
    }
  }
  return (y);
}


x86 assembly (clang, -O0):
<round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <floor@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xeb8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1157 <round+0x47>
jmp    11c7 <round+0xb7>
movsd  -0x18(%rbp),%xmm0
movsd  0xe9c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11de <round+0xce>
jp     11de <round+0xce>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe7a(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1030 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe56(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11d9 <round+0xc9>
jp     11d9 <round+0xc9>
jmp    11c7 <round+0xb7>
movsd  0xe39(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11de <round+0xce>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round>:
push   %rax
movsd  %xmm0,(%rsp)
call   1030 <floor@plt>
movapd %xmm0,%xmm2
movsd  (%rsp),%xmm0
subsd  %xmm2,%xmm0
ucomisd 0xed0(%rip),%xmm0
ja     1169 <round+0x59>
jne    1171 <round+0x61>
jp     1171 <round+0x61>
movsd  0xec2(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm2,(%rsp)
call   1030 <floor@plt>
movsd  (%rsp),%xmm2
addsd  %xmm0,%xmm0
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
ucomisd 0xea3(%rip),%xmm1
jne    1171 <round+0x61>
jp     1171 <round+0x61>
addsd  0xe97(%rip),%xmm2
movapd %xmm2,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @round(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %2
%5 = load double, double* %2
%6 = call double @llvm.floor.f64(double %5)
store double %6, double* %3
%7 = load double, double* %2
%8 = load double, double* %3
%9 = fsub double %7, %8
store double %9, double* %4
%10 = load double, double* %4
%11 = fcmp ogt double %10, 5.000000e-01
br i1 %11, label %12, label %13
12: ; preds = %1
br label %25
13: ; preds = %1
%14 = load double, double* %4
%15 = fcmp oeq double %14, 5.000000e-01
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load double, double* %3
%18 = load double, double* %3
%19 = fmul double 5.000000e-01, %18
%20 = call double @llvm.floor.f64(double %19)
%21 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %20, double %17)
store double %21, double* %4
%22 = load double, double* %4
%23 = fcmp oeq double %22, 1.000000e+00
br i1 %23, label %24, label %28
24: ; preds = %16
br label %25
25: ; preds = %24, %12
%26 = load double, double* %3
%27 = fadd double %26, 1.000000e+00
store double %27, double* %3
br label %28
28: ; preds = %25, %16
br label %29
29: ; preds = %28, %13
%30 = load double, double* %3
ret double %30
}

LLVM IR (-O2):
define double @round(double %0) {
%2 = tail call double @llvm.floor.f64(double %0)
%3 = fsub double %0, %2
%4 = fcmp ogt double %3, 5.000000e-01
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = fcmp oeq double %3, 5.000000e-01
br i1 %6, label %7, label %14
7: ; preds = %5
%8 = fmul double %2, 5.000000e-01
%9 = tail call double @llvm.floor.f64(double %8)
%10 = tail call double @llvm.fmuladd.f64(double %9, double -2.000000e+00, double %2)
%11 = fcmp oeq double %10, 1.000000e+00
br i1 %11, label %12, label %14
12: ; preds = %7, %1
%13 = fadd double %2, 1.000000e+00
br label %14
14: ; preds = %7, %12, %5
%15 = phi double [ %13, %12 ], [ %2, %7 ], [ %2, %5 ]
ret double %15
}