#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 */

/* Variables and functions */
double INFINITY;
double NAN;
double ldexp(int, int);
double decode_half(int half) {
  int exp = (half >> 10) & 0x1f;
  int mant = half & 0x3ff;
  double val;
  if (exp == 0)
    val = ldexp(mant, -24);
  else if (exp != 31)
    val = ldexp(mant + 1024, exp - 25);
  else
    val = mant == 0 ? INFINITY : NAN;
  return half & 0x8000 ? -val : val;
}


x86 assembly (clang, -O0):
<decode_half>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0xa,%eax
and    $0x1f,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x3ff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1153 <decode_half+0x43>
mov    -0xc(%rbp),%edi
mov    $0xffffffe8,%esi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11b9 <decode_half+0xa9>
cmpl   $0x1f,-0x8(%rbp)
je     117b <decode_half+0x6b>
mov    -0xc(%rbp),%edi
add    $0x400,%edi
mov    -0x8(%rbp),%esi
sub    $0x19,%esi
call   1030 <ldexp@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11b4 <decode_half+0xa4>
cmpl   $0x0,-0xc(%rbp)
jne    119a <decode_half+0x8a>
mov    0x2e54(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11aa <decode_half+0x9a>
mov    0x2e57(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11b9 <decode_half+0xa9>
mov    -0x4(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     11f0 <decode_half+0xe0>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11fa <decode_half+0xea>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_half>:
push   %rbx
mov    %edi,%ebx
mov    %edi,%esi
shr    $0xa,%esi
and    $0x1f,%esi
and    $0x3ff,%edi
cmp    $0x1f,%esi
je     1131 <decode_half+0x21>
test   %esi,%esi
jne    113e <decode_half+0x2e>
mov    $0xffffffe8,%esi
jmp    1147 <decode_half+0x37>
test   %edi,%edi
jne    115d <decode_half+0x4d>
mov    0x2ea4(%rip),%rax
jmp    1164 <decode_half+0x54>
or     $0x400,%edi
add    $0xffffffe7,%esi
call   1030 <ldexp@plt>
test   $0x8000,%ebx
je     115b <decode_half+0x4b>
xorps  0xea5(%rip),%xmm0
pop    %rbx
ret
mov    0x2e94(%rip),%rax
movsd  (%rax),%xmm0
test   $0x8000,%ebx
je     115b <decode_half+0x4b>
jmp    1154 <decode_half+0x44>

LLVM IR (-O0):
@INFINITY = global double 0.000000e+00
@NAN = global double 0.000000e+00
define double @decode_half(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = ashr i32 %6, 10
%8 = and i32 %7, 31
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = and i32 %9, 1023
store i32 %10, i32* %4
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* %4
%15 = call double @ldexp(i32 %14, i32 -24)
store double %15, double* %5
br label %35
16: ; preds = %1
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 31
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1024
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, 25
%24 = call double @ldexp(i32 %21, i32 %23)
store double %24, double* %5
br label %34
25: ; preds = %16
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load double, double* @INFINITY
br label %32
30: ; preds = %25
%31 = load double, double* @NAN
br label %32
32: ; preds = %30, %28
%33 = phi double [ %29, %28 ], [ %31, %30 ]
store double %33, double* %5
br label %34
34: ; preds = %32, %19
br label %35
35: ; preds = %34, %13
%36 = load i32, i32* %2
%37 = and i32 %36, 32768
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load double, double* %5
%41 = fneg double %40
br label %44
42: ; preds = %35
%43 = load double, double* %5
br label %44
44: ; preds = %42, %39
%45 = phi double [ %41, %39 ], [ %43, %42 ]
ret double %45
}

LLVM IR (-O2):
@INFINITY = global double 0.000000e+00
@NAN = global double 0.000000e+00
define double @decode_half(i32 %0) {
%2 = lshr i32 %0, 10
%3 = and i32 %2, 31
%4 = and i32 %0, 1023
switch i32 %3, label %7 [
i32 0, label %5
i32 31, label %11
]
5: ; preds = %1
%6 = tail call double @ldexp(i32 %4, i32 -24)
br label %16
7: ; preds = %1
%8 = or i32 %4, 1024
%9 = add nsw i32 %3, -25
%10 = tail call double @ldexp(i32 %8, i32 %9)
br label %16
11: ; preds = %1
%12 = icmp eq i32 %4, 0
%13 = load double, double* @INFINITY
%14 = load double, double* @NAN
%15 = select i1 %12, double %13, double %14
br label %16
16: ; preds = %7, %11, %5
%17 = phi double [ %6, %5 ], [ %10, %7 ], [ %15, %11 ]
%18 = and i32 %0, 32768
%19 = icmp eq i32 %18, 0
%20 = fneg double %17
%21 = select i1 %19, double %17, double %20
ret double %21
}