#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 */
typedef int uint32_t;

/* Variables and functions */
float fp20(uint32_t value) {
  uint32_t sign, mantissa, exponent;
  union {
    uint32_t u;
    float f;
  } bits;
  sign = (value >> 19) & 0x1;
  exponent = (value >> 13) & 0x3f;
  mantissa = (value >> 0) & 0x1fff;
  if (exponent == 0x3f)
    exponent = 0xff;
  else
    exponent += 127 - 31;
  mantissa = mantissa << (23 - 13);
  bits.u = sign << 31 | (exponent << 23) | mantissa;
  return bits.f;
}


x86 assembly (clang, -O0):
<fp20>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x13,%eax
and    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0xd,%eax
and    $0x3f,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x0,%eax
and    $0x1fff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x3f,-0x10(%rbp)
jne    1143 <fp20+0x43>
movl   $0xff,-0x10(%rbp)
jmp    114c <fp20+0x4c>
mov    -0x10(%rbp),%eax
add    $0x60,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x1f,%eax
mov    -0x10(%rbp),%ecx
shl    $0x17,%ecx
or     %ecx,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp20>:
mov    %edi,%eax
shr    $0xd,%eax
and    $0x3f,%eax
mov    %eax,%ecx
shl    $0x17,%ecx
add    $0x30000000,%ecx
cmp    $0x3f,%eax
mov    $0x7f800000,%eax
cmovne %ecx,%eax
mov    %edi,%ecx
shl    $0xa,%ecx
and    $0x7ffc00,%ecx
shl    $0xc,%edi
and    $0x80000000,%edi
or     %ecx,%edi
or     %eax,%edi
movd   %edi,%xmm0
ret

LLVM IR (-O0):
%union.anon = type { i32 }
define float @fp20(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %union.anon
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = ashr i32 %7, 19
%9 = and i32 %8, 1
store i32 %9, i32* %3
%10 = load i32, i32* %2
%11 = ashr i32 %10, 13
%12 = and i32 %11, 63
store i32 %12, i32* %5
%13 = load i32, i32* %2
%14 = ashr i32 %13, 0
%15 = and i32 %14, 8191
store i32 %15, i32* %4
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 63
br i1 %17, label %18, label %19
18: ; preds = %1
store i32 255, i32* %5
br label %22
19: ; preds = %1
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 96
store i32 %21, i32* %5
br label %22
22: ; preds = %19, %18
%23 = load i32, i32* %4
%24 = shl i32 %23, 10
store i32 %24, i32* %4
%25 = load i32, i32* %3
%26 = shl i32 %25, 31
%27 = load i32, i32* %5
%28 = shl i32 %27, 23
%29 = or i32 %26, %28
%30 = load i32, i32* %4
%31 = or i32 %29, %30
%32 = bitcast %union.anon* %6 to i32*
store i32 %31, i32* %32
%33 = bitcast %union.anon* %6 to float*
%34 = load float, float* %33
ret float %34
}

LLVM IR (-O2):
define float @fp20(i32 %0) {
%2 = lshr i32 %0, 13
%3 = and i32 %2, 63
%4 = icmp eq i32 %3, 63
%5 = shl nuw nsw i32 %3, 23
%6 = add nuw nsw i32 %5, 805306368
%7 = select i1 %4, i32 2139095040, i32 %6
%8 = shl i32 %0, 10
%9 = and i32 %8, 8387584
%10 = shl i32 %0, 12
%11 = and i32 %10, -2147483648
%12 = or i32 %9, %11
%13 = or i32 %12, %7
%14 = bitcast i32 %13 to float
ret float %14
}