#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 /*<<< orphan*/ int64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ dump(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, ...);
scalar_t__ strncmp(unsigned char *, char *, int);
size_t dump_header(FILE *fp, int64_t offset) {
  unsigned char header[8];
  fseek(fp, offset, SEEK_SET);
  size_t actual = fread(header, 1, 8, fp);
  if (strncmp(header, "AAAA", 4) != 0) {
    printf("Ref '0x%zx' does not point to an array\n", offset);
    dump(fp, offset, 64);
    return 0;
  }
  size_t size = (header[5] << 16) + (header[6] << 8) + header[7];
  unsigned flags = header[4];
  unsigned wtype = (flags & 0x18) >> 3;
  unsigned width = (1 << (flags & 0x07)) >> 1;
  int is_inner = (flags & 0x80) ? 1 : 0;
  int has_refs = (flags & 0x40) ? 1 : 0;
  int context = (flags & 0x20) ? 1 : 0;
  size_t num_bytes = 0;
  const char *type = "";
  switch (wtype) {
  case 0: {
    assert(size < 0x1000000);
    size_t num_bits = size * width;
    num_bytes = (num_bits + 7) >> 3;
    type = "bits";
    break;
  }
  case 1: {
    num_bytes = size * width;
    type = "bytes";
    break;
  }
  case 2:
    num_bytes = size;
    break;
  }
  if (is_inner && has_refs) {
    printf("Ref: %zx, Size: %zd, width: %d %s Inner B+tree node\n", offset,
           size, width, type);
  } else {
    printf("Ref: %zx, Size: %zd, width: %d %s, hasRefs: %d\n", offset, size,
           width, type, has_refs);
  }
  return num_bytes;
}


x86 assembly (clang, -O0):
<dump_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1040 <fread@plt>
mov    %rax,-0x28(%rbp)
lea    -0x1c(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11ed <dump_header+0x8d>
mov    -0x14(%rbp),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x40,%edx
call   1060 <dump@plt>
movq   $0x0,-0x8(%rbp)
jmp    135e <dump_header+0x1fe>
movzbl -0x17(%rbp),%eax
shl    $0x10,%eax
movzbl -0x16(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0x15(%rbp),%ecx
or     %ecx,%eax
mov    %rax,-0x30(%rbp)
movzbl -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
and    $0x18,%eax
shr    $0x3,%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%cl
and    $0x7,%cl
mov    $0x1,%eax
shl    %cl,%eax
shr    %eax
mov    %eax,-0x3c(%rbp)
movzbl -0x34(%rbp),%eax
shr    $0x7,%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
and    $0x40,%eax
shr    $0x6,%eax
mov    %eax,-0x44(%rbp)
mov    -0x34(%rbp),%eax
and    $0x20,%eax
shr    $0x5,%eax
mov    %eax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
lea    0xe3f(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x64(%rbp)
test   %eax,%eax
je     1296 <dump_header+0x136>
jmp    1274 <dump_header+0x114>
mov    -0x64(%rbp),%eax
sub    $0x1,%eax
je     12da <dump_header+0x17a>
jmp    1285 <dump_header+0x125>
mov    -0x64(%rbp),%eax
sub    $0x2,%eax
je     12f9 <dump_header+0x199>
jmp    1301 <dump_header+0x1a1>
cmpq   $0x1000000,-0x30(%rbp)
01
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
add    $0x7,%rax
shr    $0x3,%rax
mov    %rax,-0x50(%rbp)
lea    0xd5c(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1301 <dump_header+0x1a1>
mov    -0x30(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   %rcx,%rax
mov    %rax,-0x50(%rbp)
lea    0xd42(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1301 <dump_header+0x1a1>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpl   $0x0,-0x40(%rbp)
je     1336 <dump_header+0x1d6>
cmpl   $0x0,-0x44(%rbp)
je     1336 <dump_header+0x1d6>
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x58(%rbp),%r8
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1356 <dump_header+0x1f6>
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x58(%rbp),%r8
mov    -0x44(%rbp),%r9d
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
mov    %rdi,%rbp
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11db <dump_header+0x7b>
lea    0xe4b(%rip),%rdi
xor    %ebx,%ebx
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
mov    $0x40,%edx
call   1060 <dump@plt>
jmp    12a8 <dump_header+0x148>
movzbl 0xd(%rsp),%eax
shl    $0x10,%rax
movzbl 0xe(%rsp),%ecx
shl    $0x8,%rcx
or     %rax,%rcx
movzbl 0xf(%rsp),%r14d
or     %rcx,%r14
movzbl 0xc(%rsp),%r12d
mov    %r12d,%eax
shr    $0x3,%eax
mov    %r12d,%ecx
and    $0x7,%cl
mov    $0x1,%ebp
shl    %cl,%rbp
and    $0x3,%eax
shr    %rbp
lea    0xe7c(%rip),%r8
cmp    $0x2,%eax
je     1250 <dump_header+0xf0>
cmp    $0x1,%eax
je     1255 <dump_header+0xf5>
test   %eax,%eax
jne    1264 <dump_header+0x104>
mov    $0x1,%edi
call   1070 <assert@plt>
mov    %rbp,%rbx
imul   %r14,%rbx
add    $0x7,%rbx
shr    $0x3,%rbx
lea    0xddf(%rip),%r8
jmp    1266 <dump_header+0x106>
mov    %r14,%rbx
jmp    1266 <dump_header+0x106>
mov    %ebp,%ebx
imul   %r14,%rbx
lea    0xdd0(%rip),%r8
jmp    1266 <dump_header+0x106>
xor    %ebx,%ebx
mov    %r12d,%eax
not    %eax
test   $0xc0,%al
jne    1287 <dump_header+0x127>
lea    0xdc2(%rip),%rdi
mov    %r15d,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12a8 <dump_header+0x148>
shr    $0x6,%r12d
and    $0x1,%r12d
lea    0xdd7(%rip),%rdi
mov    %r15d,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %r12d,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [5 x i8] c"AAAA\00"
@.str.1 = [40 x i8] c"Ref '0x%zx' does not point to an array\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"bits\00"
@.str.4 = [6 x i8] c"bytes\00"
@.str.5 = [53 x i8] c"Ref: %zx, Size: %zd, width: %d %s Inner B+tree node\0A\00"
@.str.6 = [48 x i8] c"Ref: %zx, Size: %zd, width: %d %s, hasRefs: %d\0A\00"
define i64 @dump_header(i32* %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [8 x i8]
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i64
store i32* %0, i32** %4
store i32 %1, i32* %5
%18 = load i32*, i32** %4
%19 = load i32, i32* %5
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %18, i32 %19, i32 %20)
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%23 = load i32*, i32** %4
%24 = call i64 @fread(i8* %22, i32 1, i32 8, i32* %23)
store i64 %24, i64* %7
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%26 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %2
%29 = load i32, i32* %5
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %4
%32 = load i32, i32* %5
%33 = call i32 @dump(i32* %31, i32 %32, i32 64)
store i64 0, i64* %3
br label %115
34: ; preds = %2
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 5
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = shl i32 %37, 16
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 6
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = shl i32 %41, 8
%43 = add nsw i32 %38, %42
%44 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 7
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = add nsw i32 %43, %46
%48 = sext i32 %47 to i64
store i64 %48, i64* %8
%49 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 4
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
store i32 %51, i32* %9
%52 = load i32, i32* %9
%53 = and i32 %52, 24
%54 = lshr i32 %53, 3
store i32 %54, i32* %10
%55 = load i32, i32* %9
%56 = and i32 %55, 7
%57 = shl i32 1, %56
%58 = ashr i32 %57, 1
store i32 %58, i32* %11
%59 = load i32, i32* %9
%60 = and i32 %59, 128
%61 = icmp ne i32 %60, 0
%62 = zext i1 %61 to i64
%63 = select i1 %61, i32 1, i32 0
store i32 %63, i32* %12
%64 = load i32, i32* %9
%65 = and i32 %64, 64
%66 = icmp ne i32 %65, 0
%67 = zext i1 %66 to i64
%68 = select i1 %66, i32 1, i32 0
store i32 %68, i32* %13
%69 = load i32, i32* %9
%70 = and i32 %69, 32
%71 = icmp ne i32 %70, 0
%72 = zext i1 %71 to i64
%73 = select i1 %71, i32 1, i32 0
store i32 %73, i32* %14
store i64 0, i64* %15
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %16
%74 = load i32, i32* %10
switch i32 %74, label %94 [
i32 0, label %75
i32 1, label %87
i32 2, label %92
]
75: ; preds = %34
%76 = load i64, i64* %8
%77 = icmp ult i64 %76, 16777216
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = load i64, i64* %8
%81 = load i32, i32* %11
%82 = zext i32 %81 to i64
%83 = mul i64 %80, %82
store i64 %83, i64* %17
%84 = load i64, i64* %17
%85 = add i64 %84, 7
%86 = lshr i64 %85, 3
store i64 %86, i64* %15
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %16
br label %94
87: ; preds = %34
%88 = load i64, i64* %8
%89 = load i32, i32* %11
%90 = zext i32 %89 to i64
%91 = mul i64 %88, %90
store i64 %91, i64* %15
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %16
br label %94
92: ; preds = %34
%93 = load i64, i64* %8
store i64 %93, i64* %15
br label %94
94: ; preds = %34, %92, %87, %75
%95 = load i32, i32* %12
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %106
97: ; preds = %94
%98 = load i32, i32* %13
%99 = icmp ne i32 %98, 0
br i1 %99, label %100, label %106
100: ; preds = %97
%101 = load i32, i32* %5
%102 = load i64, i64* %8
%103 = load i32, i32* %11
%104 = load i8*, i8** %16
%105 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i32 %101, i64 %102, i32 %103, i8* %104)
br label %113
106: ; preds = %97, %94
%107 = load i32, i32* %5
%108 = load i64, i64* %8
%109 = load i32, i32* %11
%110 = load i8*, i8** %16
%111 = load i32, i32* %13
%112 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i32 %107, i64 %108, i32 %109, i8* %110, i32 %111)
br label %113
113: ; preds = %106, %100
%114 = load i64, i64* %15
store i64 %114, i64* %3
br label %115
115: ; preds = %113, %28
%116 = load i64, i64* %3
ret i64 %116
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [5 x i8] c"AAAA\00"
@.str.1 = [40 x i8] c"Ref '0x%zx' does not point to an array\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"bits\00"
@.str.4 = [6 x i8] c"bytes\00"
@.str.5 = [53 x i8] c"Ref: %zx, Size: %zd, width: %d %s Inner B+tree node\0A\00"
@.str.6 = [48 x i8] c"Ref: %zx, Size: %zd, width: %d %s, hasRefs: %d\0A\00"
define i64 @dump_header(i32* %0, i32 %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseek(i32* %0, i32 %1, i32 %5)
%7 = call i64 @fread(i8* %4, i32 1, i32 8, i32* %0)
%8 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%12 = call i32 @dump(i32* %0, i32 %1, i32 64)
br label %56
13: ; preds = %2
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
%15 = load i8, i8* %14
%16 = zext i8 %15 to i64
%17 = shl nuw nsw i64 %16, 16
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
%19 = load i8, i8* %18
%20 = zext i8 %19 to i64
%21 = shl nuw nsw i64 %20, 8
%22 = or i64 %21, %17
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
%24 = load i8, i8* %23
%25 = zext i8 %24 to i64
%26 = or i64 %22, %25
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = lshr i32 %29, 3
%31 = and i32 %30, 3
%32 = and i32 %29, 7
%33 = shl nuw nsw i32 1, %32
%34 = lshr i32 %33, 1
%35 = lshr i32 %29, 6
%36 = and i32 %35, 1
switch i32 %31, label %47 [
i32 0, label %37
i32 1, label %43
i32 2, label %46
]
37: ; preds = %13
%38 = call i32 @assert(i32 1)
%39 = zext i32 %34 to i64
%40 = mul nuw nsw i64 %26, %39
%41 = add nuw nsw i64 %40, 7
%42 = lshr i64 %41, 3
br label %47
43: ; preds = %13
%44 = zext i32 %34 to i64
%45 = mul nuw nsw i64 %26, %44
br label %47
46: ; preds = %13
br label %47
47: ; preds = %13, %46, %43, %37
%48 = phi i64 [ 0, %13 ], [ %26, %46 ], [ %45, %43 ], [ %42, %37 ]
%49 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %46 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), %43 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %37 ]
%50 = and i32 %29, 192
%51 = icmp eq i32 %50, 192
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i32 %1, i64 %26, i32 %34, i8* %49)
br label %56
54: ; preds = %47
%55 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i32 %1, i64 %26, i32 %34, i8* %49, i32 %36)
br label %56
56: ; preds = %52, %54, %10
%57 = phi i64 [ 0, %10 ], [ %48, %54 ], [ %48, %52 ]
ret i64 %57
}