unsigned float_half(unsigned uf) {
  unsigned sign_exp = uf & 0xFF800000;
  unsigned frac;
  unsigned mask = 0x7FFFFF;
  unsigned shift = 1;
  switch (sign_exp) {
  case 0x7F800000:
  case 0xFF800000:
    return uf;
  case 0:
  case 0x80000000:
    break;
  default:
    switch (sign_exp -= 0x800000) {
    case 0:
    case 0x80000000:
      mask = 0xFFFFFF;
      break;
    default:
      shift = 0;
    }
  }
  frac = uf & mask;
  frac = frac >> shift;
  switch (uf & 3) {
  case 3:
    frac += shift;
  }
  return sign_exp | frac;
}


x86 assembly (clang, -O0):
<float_half>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff800000,%eax
mov    %eax,-0xc(%rbp)
movl   $0x7fffff,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x80000000,%eax
je     1177 <float_half+0x77>
jmp    1136 <float_half+0x36>
mov    -0x1c(%rbp),%eax
sub    $0xff800000,%eax
je     116c <float_half+0x6c>
jmp    1149 <float_half+0x49>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     1177 <float_half+0x77>
jmp    1159 <float_half+0x59>
mov    -0x1c(%rbp),%eax
sub    $0x7f800000,%eax
jne    117c <float_half+0x7c>
jmp    116c <float_half+0x6c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e9 <float_half+0xe9>
jmp    11af <float_half+0xaf>
mov    -0xc(%rbp),%eax
add    $0xff800000,%eax
mov    %eax,-0xc(%rbp)
test   $0x7fffffff,%eax
je     1197 <float_half+0x97>
jmp    11a3 <float_half+0xa3>
movl   $0xffffff,-0x14(%rbp)
jmp    11aa <float_half+0xaa>
movl   $0x0,-0x18(%rbp)
jmp    11af <float_half+0xaf>
mov    -0x8(%rbp),%eax
mov    -0x14(%rbp),%ecx
and    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%cl
shr    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
not    %eax
test   $0x3,%al
jne    11e0 <float_half+0xe0>
jmp    11d7 <float_half+0xd7>
mov    -0x18(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_half>:
mov    %edi,%eax
mov    $0x1,%ecx
mov    $0x7fffff,%edx
and    $0xff800000,%edi
jns    1125 <float_half+0x25>
cmp    $0x80000000,%edi
je     114a <float_half+0x4a>
cmp    $0xff800000,%edi
jne    112f <float_half+0x2f>
ret
je     114a <float_half+0x4a>
cmp    $0x7f800000,%edi
je     1124 <float_half+0x24>
lea    -0x800000(%rdi),%esi
or     $0x80000000,%edi
cmp    $0x80800000,%edi
jne    1160 <float_half+0x60>
mov    $0xffffff,%edx
jmp    114c <float_half+0x4c>
mov    %edi,%esi
and    %eax,%edx
shr    %cl,%edx
not    %eax
xor    %edi,%edi
test   $0x3,%al
cmove  %ecx,%edi
add    %edx,%edi
or     %esi,%edi
mov    %edi,%eax
ret
xor    %ecx,%ecx
jmp    114c <float_half+0x4c>

LLVM IR (-O0):
define i32 @float_half(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = and i32 %8, -8388608
store i32 %9, i32* %4
store i32 8388607, i32* %6
store i32 1, i32* %7
%10 = load i32, i32* %4
switch i32 %10, label %14 [
i32 2139095040, label %11
i32 -8388608, label %11
i32 0, label %13
i32 -2147483648, label %13
]
11: ; preds = %1, %1
%12 = load i32, i32* %3
store i32 %12, i32* %2
br label %37
13: ; preds = %1, %1
br label %20
14: ; preds = %1
%15 = load i32, i32* %4
%16 = sub i32 %15, 8388608
store i32 %16, i32* %4
switch i32 %16, label %18 [
i32 0, label %17
i32 -2147483648, label %17
]
17: ; preds = %14, %14
store i32 16777215, i32* %6
br label %19
18: ; preds = %14
store i32 0, i32* %7
br label %19
19: ; preds = %18, %17
br label %20
20: ; preds = %19, %13
%21 = load i32, i32* %3
%22 = load i32, i32* %6
%23 = and i32 %21, %22
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = load i32, i32* %7
%26 = lshr i32 %24, %25
store i32 %26, i32* %5
%27 = load i32, i32* %3
%28 = and i32 %27, 3
switch i32 %28, label %33 [
i32 3, label %29
]
29: ; preds = %20
%30 = load i32, i32* %7
%31 = load i32, i32* %5
%32 = add i32 %31, %30
store i32 %32, i32* %5
br label %33
33: ; preds = %29, %20
%34 = load i32, i32* %4
%35 = load i32, i32* %5
%36 = or i32 %34, %35
store i32 %36, i32* %2
br label %37
37: ; preds = %33, %11
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @float_half(i32 %0) {
%2 = and i32 %0, -8388608
switch i32 %2, label %3 [
i32 2139095040, label %17
i32 -8388608, label %17
i32 0, label %6
i32 -2147483648, label %6
]
3: ; preds = %1
%4 = add i32 %2, -8388608
switch i32 %2, label %5 [
i32 8388608, label %6
i32 -2139095040, label %6
]
5: ; preds = %3
br label %6
6: ; preds = %3, %3, %5, %1, %1
%7 = phi i32 [ %4, %5 ], [ %2, %1 ], [ %2, %1 ], [ %4, %3 ], [ %4, %3 ]
%8 = phi i32 [ 8388607, %5 ], [ 8388607, %1 ], [ 8388607, %1 ], [ 16777215, %3 ], [ 16777215, %3 ]
%9 = phi i32 [ 0, %5 ], [ 1, %1 ], [ 1, %1 ], [ 1, %3 ], [ 1, %3 ]
%10 = and i32 %8, %0
%11 = lshr i32 %10, %9
%12 = and i32 %0, 3
%13 = icmp eq i32 %12, 3
%14 = select i1 %13, i32 %9, i32 0
%15 = add nuw nsw i32 %11, %14
%16 = or i32 %15, %7
br label %17
17: ; preds = %1, %1, %6
%18 = phi i32 [ %16, %6 ], [ %0, %1 ], [ %0, %1 ]
ret i32 %18
}