#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 */
long pop_signed_int(char *, int);
unsigned long pop_unsigned_int(char *, int);
double unpack_float(char *source, int num_bits, const double precision,
                    const long offset, int has_sign, void *nan_repr) {
  long sval;
  unsigned long uval;
  if (has_sign) {
    sval = pop_signed_int(source, num_bits);
    if (nan_repr && sval == *(long *)(nan_repr))
      return 0.0 / 0.0;
    else
      return (sval + offset) * precision;
  } else {
    uval = pop_unsigned_int(source, num_bits);
    if (nan_repr && uval == *(unsigned long *)(nan_repr))
      return 0.0 / 0.0;
    else
      return (uval + offset) * precision;
  }
}


x86 assembly (clang, -O0):
<unpack_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %r8,-0x38(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11a3 <unpack_float+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <pop_signed_int@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1187 <unpack_float+0x67>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
cmp    (%rcx),%rax
jne    1187 <unpack_float+0x67>
movsd  0xea3(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121d <unpack_float+0xfd>
mov    -0x40(%rbp),%rax
add    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121d <unpack_float+0xfd>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <pop_unsigned_int@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11e1 <unpack_float+0xc1>
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%rcx
cmp    (%rcx),%rax
jne    11e1 <unpack_float+0xc1>
movsd  0xe49(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121d <unpack_float+0xfd>
mov    -0x48(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    %rcx,%rax
movq   %rax,%xmm0
movaps 0xe08(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe0c(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack_float>:
push   %r14
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rdx,%r14
test   %ecx,%ecx
movsd  %xmm0,(%rsp)
je     114f <unpack_float+0x2f>
call   1040 <pop_signed_int@plt>
test   %rbx,%rbx
je     1142 <unpack_float+0x22>
cmp    (%rbx),%rax
je     115e <unpack_float+0x3e>
add    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
jmp    118c <unpack_float+0x6c>
call   1030 <pop_unsigned_int@plt>
test   %rbx,%rbx
je     1168 <unpack_float+0x48>
cmp    (%rbx),%rax
jne    1168 <unpack_float+0x48>
movsd  0xe9a(%rip),%xmm0
jmp    1191 <unpack_float+0x71>
add    %r14,%rax
movq   %rax,%xmm1
punpckldq 0xe98(%rip),%xmm1
subpd  0xea0(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
mulsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @unpack_float(i8* %0, i32 %1, double %2, i64 %3, i32 %4, i8* %5) {
%7 = alloca double
%8 = alloca i8*
%9 = alloca i32
%10 = alloca double
%11 = alloca i64
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64
store i8* %0, i8** %8
store i32 %1, i32* %9
store double %2, double* %10
store i64 %3, i64* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
%16 = load i32, i32* %12
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %6
%19 = load i8*, i8** %8
%20 = load i32, i32* %9
%21 = call i64 @pop_signed_int(i8* %19, i32 %20)
store i64 %21, i64* %14
%22 = load i8*, i8** %13
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %31
24: ; preds = %18
%25 = load i64, i64* %14
%26 = load i8*, i8** %13
%27 = bitcast i8* %26 to i64*
%28 = load i64, i64* %27
%29 = icmp eq i64 %25, %28
br i1 %29, label %30, label %31
30: ; preds = %24
store double 0x7FF8000000000000, double* %7
br label %58
31: ; preds = %24, %18
%32 = load i64, i64* %14
%33 = load i64, i64* %11
%34 = add nsw i64 %32, %33
%35 = sitofp i64 %34 to double
%36 = load double, double* %10
%37 = fmul double %35, %36
store double %37, double* %7
br label %58
38: ; preds = %6
%39 = load i8*, i8** %8
%40 = load i32, i32* %9
%41 = call i64 @pop_unsigned_int(i8* %39, i32 %40)
store i64 %41, i64* %15
%42 = load i8*, i8** %13
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %51
44: ; preds = %38
%45 = load i64, i64* %15
%46 = load i8*, i8** %13
%47 = bitcast i8* %46 to i64*
%48 = load i64, i64* %47
%49 = icmp eq i64 %45, %48
br i1 %49, label %50, label %51
50: ; preds = %44
store double 0x7FF8000000000000, double* %7
br label %58
51: ; preds = %44, %38
%52 = load i64, i64* %15
%53 = load i64, i64* %11
%54 = add i64 %52, %53
%55 = uitofp i64 %54 to double
%56 = load double, double* %10
%57 = fmul double %55, %56
store double %57, double* %7
br label %58
58: ; preds = %51, %50, %31, %30
%59 = load double, double* %7
ret double %59
}

LLVM IR (-O2):
define double @unpack_float(i8* %0, i32 %1, double %2, i64 %3, i32 %4, i8* %5) {
%7 = icmp eq i32 %4, 0
br i1 %7, label %19, label %8
8: ; preds = %6
%9 = tail call i64 @pop_signed_int(i8* %0, i32 %1)
%10 = icmp eq i8* %5, null
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = bitcast i8* %5 to i64*
%13 = load i64, i64* %12
%14 = icmp eq i64 %9, %13
br i1 %14, label %30, label %15
15: ; preds = %11, %8
%16 = add nsw i64 %9, %3
%17 = sitofp i64 %16 to double
%18 = fmul double %17, %2
br label %30
19: ; preds = %6
%20 = tail call i64 @pop_unsigned_int(i8* %0, i32 %1)
%21 = icmp eq i8* %5, null
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = bitcast i8* %5 to i64*
%24 = load i64, i64* %23
%25 = icmp eq i64 %20, %24
br i1 %25, label %30, label %26
26: ; preds = %22, %19
%27 = add i64 %20, %3
%28 = uitofp i64 %27 to double
%29 = fmul double %28, %2
br label %30
30: ; preds = %22, %11, %26, %15
%31 = phi double [ %18, %15 ], [ %29, %26 ], [ 0x7FF8000000000000, %11 ], [ 0x7FF8000000000000, %22 ]
ret double %31
}