#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 */
unsigned long ReadLong(unsigned char const *);
int /*<<< orphan*/ UnsignedToFloat(unsigned long);
double ldexp(int /*<<< orphan*/, int);
double ReadExtended(const unsigned char *bytes) {
  double f;
  int expon;
  unsigned long hiMant, loMant;
  expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
  hiMant = ReadLong(bytes + 2);
  loMant = ReadLong(bytes + 6);
  if (expon == 0 && hiMant == 0 && loMant == 0)
    f = 0;
  else {
    if (expon == 0x7FFF)
      f = -1;
    else {
      expon -= 16383;
      f = ldexp(UnsignedToFloat(hiMant), expon -= 31);
      f += ldexp(UnsignedToFloat(loMant), expon -= 32);
    }
  }
  if (bytes[0] & 0x80)
    return -f;
  return f;
}


x86 assembly (clang, -O0):
<ReadExtended>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0x7f,%eax
shl    $0x8,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
call   1040 <ReadLong@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x6,%rdi
call   1040 <ReadLong@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11ab <ReadExtended+0x7b>
cmpq   $0x0,-0x28(%rbp)
jne    11ab <ReadExtended+0x7b>
cmpq   $0x0,-0x30(%rbp)
jne    11ab <ReadExtended+0x7b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    121b <ReadExtended+0xeb>
cmpl   $0x7fff,-0x1c(%rbp)
jne    11ca <ReadExtended+0x9a>
movsd  0xe40(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1216 <ReadExtended+0xe6>
mov    -0x1c(%rbp),%eax
sub    $0x3fff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <UnsignedToFloat@plt>
mov    %eax,%edi
mov    -0x1c(%rbp),%esi
sub    $0x1f,%esi
mov    %esi,-0x1c(%rbp)
call   1030 <ldexp@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <UnsignedToFloat@plt>
mov    %eax,%edi
mov    -0x1c(%rbp),%esi
sub    $0x20,%esi
mov    %esi,-0x1c(%rbp)
call   1030 <ldexp@plt>
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    121b <ReadExtended+0xeb>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1256 <ReadExtended+0x126>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1260 <ReadExtended+0x130>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadExtended>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movzbl (%rdi),%ebp
and    $0x7f,%ebp
shl    $0x8,%ebp
movzbl 0x1(%rdi),%r14d
add    $0x2,%rdi
call   1040 <ReadLong@plt>
mov    %rax,%r12
lea    0x6(%rbx),%rdi
call   1040 <ReadLong@plt>
mov    %rax,%r15
or     %ebp,%r14d
jne    1178 <ReadExtended+0x48>
test   %r12,%r12
jne    1178 <ReadExtended+0x48>
xorpd  %xmm0,%xmm0
test   %r15,%r15
je     1189 <ReadExtended+0x59>
cmp    $0x7fff,%r14d
jne    11a3 <ReadExtended+0x73>
movsd  0xe77(%rip),%xmm0
cmpb   $0x0,(%rbx)
jns    1196 <ReadExtended+0x66>
xorpd  0xe7a(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
call   1050 <UnsignedToFloat@plt>
lea    -0x401e(%r14),%esi
mov    %eax,%edi
call   1030 <ldexp@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
call   1050 <UnsignedToFloat@plt>
add    $0xffffbfc2,%r14d
mov    %eax,%edi
mov    %r14d,%esi
call   1030 <ldexp@plt>
addsd  0x8(%rsp),%xmm0
cmpb   $0x0,(%rbx)
js     118e <ReadExtended+0x5e>
jmp    1196 <ReadExtended+0x66>

LLVM IR (-O0):
define double @ReadExtended(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca double
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = and i32 %11, 127
%13 = shl i32 %12, 8
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = and i32 %17, 255
%19 = or i32 %13, %18
store i32 %19, i32* %5
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 2
%22 = call i64 @ReadLong(i8* %21)
store i64 %22, i64* %6
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 6
%25 = call i64 @ReadLong(i8* %24)
store i64 %25, i64* %7
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %1
%29 = load i64, i64* %6
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i64, i64* %7
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store double 0.000000e+00, double* %4
br label %55
35: ; preds = %31, %28, %1
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 32767
br i1 %37, label %38, label %39
38: ; preds = %35
store double -1.000000e+00, double* %4
br label %54
39: ; preds = %35
%40 = load i32, i32* %5
%41 = sub nsw i32 %40, 16383
store i32 %41, i32* %5
%42 = load i64, i64* %6
%43 = call i32 @UnsignedToFloat(i64 %42)
%44 = load i32, i32* %5
%45 = sub nsw i32 %44, 31
store i32 %45, i32* %5
%46 = call double @ldexp(i32 %43, i32 %45)
store double %46, double* %4
%47 = load i64, i64* %7
%48 = call i32 @UnsignedToFloat(i64 %47)
%49 = load i32, i32* %5
%50 = sub nsw i32 %49, 32
store i32 %50, i32* %5
%51 = call double @ldexp(i32 %48, i32 %50)
%52 = load double, double* %4
%53 = fadd double %52, %51
store double %53, double* %4
br label %54
54: ; preds = %39, %38
br label %55
55: ; preds = %54, %34
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i64 0
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = and i32 %59, 128
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %55
%63 = load double, double* %4
%64 = fneg double %63
store double %64, double* %2
br label %67
65: ; preds = %55
%66 = load double, double* %4
store double %66, double* %2
br label %67
67: ; preds = %65, %62
%68 = load double, double* %2
ret double %68
}

LLVM IR (-O2):
define double @ReadExtended(i8* %0) {
%2 = load i8, i8* %0
%3 = and i8 %2, 127
%4 = zext i8 %3 to i32
%5 = shl nuw nsw i32 %4, 8
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = or i32 %5, %8
%10 = getelementptr inbounds i8, i8* %0, i64 2
%11 = tail call i64 @ReadLong(i8* %10)
%12 = getelementptr inbounds i8, i8* %0, i64 6
%13 = tail call i64 @ReadLong(i8* %12)
%14 = icmp eq i32 %9, 0
%15 = icmp eq i64 %11, 0
%16 = select i1 %14, i1 %15, i1 false
%17 = icmp eq i64 %13, 0
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %29, label %19
19: ; preds = %1
%20 = icmp eq i32 %9, 32767
br i1 %20, label %29, label %21
21: ; preds = %19
%22 = tail call i32 @UnsignedToFloat(i64 %11)
%23 = add nsw i32 %9, -16414
%24 = tail call double @ldexp(i32 %22, i32 %23)
%25 = tail call i32 @UnsignedToFloat(i64 %13)
%26 = add nsw i32 %9, -16446
%27 = tail call double @ldexp(i32 %25, i32 %26)
%28 = fadd double %24, %27
br label %29
29: ; preds = %19, %1, %21
%30 = phi double [ %28, %21 ], [ 0.000000e+00, %1 ], [ -1.000000e+00, %19 ]
%31 = load i8, i8* %0
%32 = icmp sgt i8 %31, -1
%33 = fneg double %30
%34 = select i1 %32, double %30, double %33
ret double %34
}