double userint(f)
double f;
{
  double t;
  int u;
  if (f > 0.0) {
    u = (int)f;
    t = (double)u;
    return (f - t < 0.5 ? t : t + 1.0);
  } else {
    u = (int)f;
    t = (double)u;
    return (t - f < 0.5 ? t : t - 1.0);
  }
}


x86 assembly (clang, -O0):
<userint>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1179 <userint+0x79>
cvttsd2si -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xec1(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1158 <userint+0x58>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    116a <userint+0x6a>
movsd  0xea8(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d6 <userint+0xd6>
cvttsd2si -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movsd  0xe63(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b6 <userint+0xb6>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11cc <userint+0xcc>
movsd  -0x18(%rbp),%xmm0
movsd  0xe45(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<userint>:
xorpd  %xmm1,%xmm1
xor    %eax,%eax
ucomisd %xmm1,%xmm0
seta   %cl
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
ja     1125 <userint+0x25>
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
jmp    1129 <userint+0x29>
subsd  %xmm1,%xmm0
cmpltsd 0xece(%rip),%xmm0
movsd  0xece(%rip),%xmm2
andpd  %xmm0,%xmm2
mov    %cl,%al
lea    0xec9(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm3
andnpd %xmm3,%xmm0
orpd   %xmm2,%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @userint(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %3
%6 = load double, double* %3
%7 = fcmp ogt double %6, 0.000000e+00
br i1 %7, label %8, label %24
8: ; preds = %1
%9 = load double, double* %3
%10 = fptosi double %9 to i32
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = sitofp i32 %11 to double
store double %12, double* %4
%13 = load double, double* %3
%14 = load double, double* %4
%15 = fsub double %13, %14
%16 = fcmp olt double %15, 5.000000e-01
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = load double, double* %4
br label %22
19: ; preds = %8
%20 = load double, double* %4
%21 = fadd double %20, 1.000000e+00
br label %22
22: ; preds = %19, %17
%23 = phi double [ %18, %17 ], [ %21, %19 ]
store double %23, double* %2
br label %40
24: ; preds = %1
%25 = load double, double* %3
%26 = fptosi double %25 to i32
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = sitofp i32 %27 to double
store double %28, double* %4
%29 = load double, double* %4
%30 = load double, double* %3
%31 = fsub double %29, %30
%32 = fcmp olt double %31, 5.000000e-01
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = load double, double* %4
br label %38
35: ; preds = %24
%36 = load double, double* %4
%37 = fsub double %36, 1.000000e+00
br label %38
38: ; preds = %35, %33
%39 = phi double [ %34, %33 ], [ %37, %35 ]
store double %39, double* %2
br label %40
40: ; preds = %38, %22
%41 = load double, double* %2
ret double %41
}

LLVM IR (-O2):
define double @userint(double %0) {
%2 = fcmp ogt double %0, 0.000000e+00
%3 = fptosi double %0 to i32
%4 = sitofp i32 %3 to double
%5 = fsub double %4, %0
%6 = fsub double %0, %4
%7 = select i1 %2, double %6, double %5
%8 = select i1 %2, double 1.000000e+00, double -1.000000e+00
%9 = fcmp olt double %7, 5.000000e-01
%10 = select i1 %9, double -0.000000e+00, double %8
%11 = fadd double %10, %4
ret double %11
}