#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 */
int /*<<< orphan*/ printf(char *, char, ...);
void half_print(unsigned short h) {
  unsigned s = h >> 15;
  unsigned short e = (h >> 10) & 0x1F;
  unsigned short m = h & 0x3FF;
  char sign = s ? '-' : '+';
  if (e == 0) {
    if (m == 0)
      printf("zero: %c0", sign);
    else
      printf("subnormal: %c%f 2^%d", sign, m / 1024.0, -14);
  } else if (e == 31) {
    if (m == 0)
      printf("infinity: %cinf", sign);
    else
      printf("not a number: %cNaN", sign);
  } else
    printf("normal: %c%f 2^%d", sign, 1.0 + m / 1024.0, e - 15);
}


x86 assembly (clang, -O0):
<half_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
sar    $0xf,%eax
mov    %eax,-0x8(%rbp)
movzwl -0x2(%rbp),%eax
sar    $0xa,%eax
and    $0x1f,%eax
mov    %ax,-0xa(%rbp)
movzwl -0x2(%rbp),%eax
and    $0x3ff,%eax
mov    %ax,-0xc(%rbp)
mov    -0x8(%rbp),%edx
mov    $0x2b,%eax
mov    $0x2d,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0xd(%rbp)
movzwl -0xa(%rbp),%eax
cmp    $0x0,%eax
jne    11bd <half_print+0xad>
movzwl -0xc(%rbp),%eax
cmp    $0x0,%eax
jne    118b <half_print+0x7b>
lea    0xe95(%rip),%rdi
movsbl -0xd(%rbp),%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b8 <half_print+0xa8>
mov    -0xd(%rbp),%al
movzwl -0xc(%rbp),%ecx
cvtsi2sd %ecx,%xmm0
movsd  0xe6a(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe71(%rip),%rdi
mov    $0xfffffff2,%edx
movsbl %al,%esi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1245 <half_print+0x135>
movzwl -0xa(%rbp),%eax
cmp    $0x1f,%eax
jne    1205 <half_print+0xf5>
movzwl -0xc(%rbp),%eax
cmp    $0x0,%eax
jne    11ee <half_print+0xde>
lea    0xe51(%rip),%rdi
movsbl -0xd(%rbp),%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1200 <half_print+0xf0>
lea    0xe4a(%rip),%rdi
movsbl -0xd(%rbp),%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1240 <half_print+0x130>
mov    -0xd(%rbp),%al
movzwl -0xc(%rbp),%ecx
cvtsi2sd %ecx,%xmm1
movsd  0xdf0(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xddc(%rip),%xmm0
addsd  %xmm1,%xmm0
movzwl -0xa(%rbp),%edx
sub    $0xf,%edx
lea    0xde7(%rip),%rdi
movsbl %al,%esi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1245 <half_print+0x135>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<half_print>:
mov    %edi,%ecx
shr    $0xa,%ecx
and    $0x1f,%ecx
mov    %edi,%eax
and    $0x3ff,%eax
shr    $0xf,%edi
add    %dil,%dil
add    $0x2b,%dil
cmp    $0x1f,%cx
je     115f <half_print+0x4f>
test   %cx,%cx
jne    1176 <half_print+0x66>
test   %ax,%ax
je     11a5 <half_print+0x95>
movzwl %ax,%eax
cvtsi2sd %eax,%xmm0
mulsd  0xeb8(%rip),%xmm0
movzbl %dil,%esi
lea    0xec7(%rip),%rdi
mov    $0xfffffff2,%edx
mov    $0x1,%al
jmp    1030 <printf@plt>
movzbl %dil,%esi
test   %ax,%ax
je     11b7 <half_print+0xa7>
lea    0xed0(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
movzwl %cx,%edx
movzwl %ax,%eax
cvtsi2sd %eax,%xmm0
mulsd  0xe78(%rip),%xmm0
addsd  0xe78(%rip),%xmm0
add    $0xfffffff1,%edx
movzbl %dil,%esi
lea    0xe7f(%rip),%rdi
mov    $0x1,%al
jmp    1030 <printf@plt>
movzbl %dil,%esi
lea    0xe60(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
lea    0xe71(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"zero: %c0\00"
@.str.1 = [21 x i8] c"subnormal: %c%f 2^%d\00"
@.str.2 = [16 x i8] c"infinity: %cinf\00"
@.str.3 = [20 x i8] c"not a number: %cNaN\00"
@.str.4 = [18 x i8] c"normal: %c%f 2^%d\00"
define void @half_print(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i32
%4 = alloca i16
%5 = alloca i16
%6 = alloca i8
store i16 %0, i16* %2
%7 = load i16, i16* %2
%8 = zext i16 %7 to i32
%9 = ashr i32 %8, 15
store i32 %9, i32* %3
%10 = load i16, i16* %2
%11 = zext i16 %10 to i32
%12 = ashr i32 %11, 10
%13 = and i32 %12, 31
%14 = trunc i32 %13 to i16
store i16 %14, i16* %4
%15 = load i16, i16* %2
%16 = zext i16 %15 to i32
%17 = and i32 %16, 1023
%18 = trunc i32 %17 to i16
store i16 %18, i16* %5
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i32 45, i32 43
%23 = trunc i32 %22 to i8
store i8 %23, i8* %6
%24 = load i16, i16* %4
%25 = zext i16 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %1
%28 = load i16, i16* %5
%29 = zext i16 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i8, i8* %6
%33 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8 signext %32)
br label %41
34: ; preds = %27
%35 = load i8, i8* %6
%36 = load i16, i16* %5
%37 = zext i16 %36 to i32
%38 = sitofp i32 %37 to double
%39 = fdiv double %38, 1.024000e+03
%40 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8 signext %35, double %39, i32 -14)
br label %41
41: ; preds = %34, %31
br label %69
42: ; preds = %1
%43 = load i16, i16* %4
%44 = zext i16 %43 to i32
%45 = icmp eq i32 %44, 31
br i1 %45, label %46, label %57
46: ; preds = %42
%47 = load i16, i16* %5
%48 = zext i16 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = load i8, i8* %6
%52 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8 signext %51)
br label %56
53: ; preds = %46
%54 = load i8, i8* %6
%55 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8 signext %54)
br label %56
56: ; preds = %53, %50
br label %68
57: ; preds = %42
%58 = load i8, i8* %6
%59 = load i16, i16* %5
%60 = zext i16 %59 to i32
%61 = sitofp i32 %60 to double
%62 = fdiv double %61, 1.024000e+03
%63 = fadd double 1.000000e+00, %62
%64 = load i16, i16* %4
%65 = zext i16 %64 to i32
%66 = sub nsw i32 %65, 15
%67 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8 signext %58, double %63, i32 %66)
br label %68
68: ; preds = %57, %56
br label %69
69: ; preds = %68, %41
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"zero: %c0\00"
@.str.1 = [21 x i8] c"subnormal: %c%f 2^%d\00"
@.str.2 = [16 x i8] c"infinity: %cinf\00"
@.str.3 = [20 x i8] c"not a number: %cNaN\00"
@.str.4 = [18 x i8] c"normal: %c%f 2^%d\00"
define void @half_print(i16 zeroext %0) {
%2 = lshr i16 %0, 10
%3 = and i16 %2, 31
%4 = and i16 %0, 1023
%5 = icmp sgt i16 %0, -1
%6 = select i1 %5, i8 43, i8 45
switch i16 %3, label %21 [
i16 0, label %7
i16 31, label %15
]
7: ; preds = %1
%8 = icmp eq i16 %4, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8 signext %6)
br label %28
11: ; preds = %7
%12 = uitofp i16 %4 to double
%13 = fmul double %12, 0x3F50000000000000
%14 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8 signext %6, double %13, i32 -14)
br label %28
15: ; preds = %1
%16 = icmp eq i16 %4, 0
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8 signext %6)
br label %28
19: ; preds = %15
%20 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8 signext %6)
br label %28
21: ; preds = %1
%22 = zext i16 %3 to i32
%23 = uitofp i16 %4 to double
%24 = fmul double %23, 0x3F50000000000000
%25 = fadd double %24, 1.000000e+00
%26 = add nsw i32 %22, -15
%27 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8 signext %6, double %25, i32 %26)
br label %28
28: ; preds = %21, %19, %17, %9, %11
ret void
}