int _fix(f)
double f;
{
  int r;
  if (f < -32768.0 || f > 32767.0)
    error(4);
  r = _sgn(f) * _fcint((f > 0.0 ? f : -f));
  return (r);
}


x86 assembly (clang, -O0):
<_fix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xebb(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
ja     1167 <_fix+0x37>
movsd  -0x8(%rbp),%xmm0
movsd  0xeab(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1173 <_fix+0x43>
mov    $0x4,%edi
mov    $0x0,%al
call   1050 <error@plt>
movsd  -0x8(%rbp),%xmm0
mov    $0x1,%al
call   1030 <_sgn@plt>
mov    %eax,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11a3 <_fix+0x73>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11c4 <_fix+0x94>
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    $0x1,%al
call   1040 <_fcint@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fix>:
push   %rbx
sub    $0x10,%rsp
movsd  0xec3(%rip),%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm0,(%rsp)
ja     1152 <_fix+0x22>
ucomisd 0xeb8(%rip),%xmm0
jbe    1163 <_fix+0x33>
mov    $0x4,%edi
xor    %eax,%eax
call   1050 <error@plt>
movapd (%rsp),%xmm0
mov    $0x1,%al
call   1030 <_sgn@plt>
mov    %eax,%ebx
movapd 0xe9c(%rip),%xmm1
movapd (%rsp),%xmm2
xorpd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
mov    $0x1,%al
call   1040 <_fcint@plt>
imul   %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @_fix(double %0) {
%2 = alloca double
%3 = alloca i32
store double %0, double* %2
%4 = load double, double* %2
%5 = fcmp olt double %4, -3.276800e+04
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load double, double* %2
%8 = fcmp ogt double %7, 3.276700e+04
br i1 %8, label %9, label %11
9: ; preds = %6, %1
%10 = call i32 (i32, ...) bitcast (i32 (...)* @error to i32 (i32, ...)*)(i32 4)
br label %11
11: ; preds = %9, %6
%12 = load double, double* %2
%13 = call i32 (double, ...) bitcast (i32 (...)* @_sgn to i32 (double, ...)*)(double %12)
%14 = load double, double* %2
%15 = fcmp ogt double %14, 0.000000e+00
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load double, double* %2
br label %21
18: ; preds = %11
%19 = load double, double* %2
%20 = fneg double %19
br label %21
21: ; preds = %18, %16
%22 = phi double [ %17, %16 ], [ %20, %18 ]
%23 = call i32 (double, ...) bitcast (i32 (...)* @_fcint to i32 (double, ...)*)(double %22)
%24 = mul nsw i32 %13, %23
store i32 %24, i32* %3
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @_fix(double %0) {
%2 = fcmp olt double %0, -3.276800e+04
%3 = fcmp ogt double %0, 3.276700e+04
%4 = or i1 %2, %3
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @error to i32 (i32, ...)*)(i32 4)
br label %7
7: ; preds = %1, %5
%8 = tail call i32 (double, ...) bitcast (i32 (...)* @_sgn to i32 (double, ...)*)(double %0)
%9 = fcmp ogt double %0, 0.000000e+00
%10 = fneg double %0
%11 = select i1 %9, double %0, double %10
%12 = tail call i32 (double, ...) bitcast (i32 (...)* @_fcint to i32 (double, ...)*)(double %11)
%13 = mul nsw i32 %12, %8
ret i32 %13
}