#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*/ describeCell(unsigned char, unsigned char *, char **);
int /*<<< orphan*/ print_decode_line(unsigned char *, int, int, char const *);
int /*<<< orphan*/ printf(char *, int, ...);
void decode_btree_page(unsigned char *a, int pgno, int hdrSize) {
  const char *zType = "unknown";
  int nCell;
  int i;
  int iCellPtr;
  switch (a[0]) {
  case 2:
    zType = "index interior node";
    break;
  case 5:
    zType = "table interior node";
    break;
  case 10:
    zType = "index leaf";
    break;
  case 13:
    zType = "table leaf";
    break;
  }
  printf("Decode of btree page %d:\n", pgno);
  print_decode_line(a, 0, 1, zType);
  print_decode_line(a, 1, 2, "Offset to first freeblock");
  print_decode_line(a, 3, 2, "Number of cells on this page");
  nCell = a[3] * 256 + a[4];
  print_decode_line(a, 5, 2, "Offset to cell content area");
  print_decode_line(a, 7, 1, "Fragmented byte count");
  if (a[0] == 2 || a[0] == 5) {
    print_decode_line(a, 8, 4, "Right child");
    iCellPtr = 12;
  } else {
    iCellPtr = 8;
  }
  for (i = 0; i < nCell; i++) {
    int cofst = iCellPtr + i * 2;
    char *zDesc;
    cofst = a[cofst] * 256 + a[cofst + 1];
    describeCell(a[0], &a[cofst - hdrSize], &zDesc);
    printf(" %03x: cell[%d] %s\n", cofst, i, zDesc);
  }
}


x86 assembly (clang, -O0):
<decode_btree_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xee7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
add    $0xfffffffe,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0xb,%eax
ja     11b5 <decode_btree_page+0x85>
mov    -0x38(%rbp),%rax
lea    0xe8f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11b5 <decode_btree_page+0x85>
lea    0xebb(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11b5 <decode_btree_page+0x85>
lea    0xebf(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11b5 <decode_btree_page+0x85>
lea    0xeba(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
xor    %esi,%esi
mov    $0x1,%edx
call   1050 <print_decode_line@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
lea    0xea1(%rip),%rcx
call   1050 <print_decode_line@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3,%esi
mov    $0x2,%edx
lea    0xea1(%rip),%rcx
call   1050 <print_decode_line@plt>
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x4(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5,%esi
mov    $0x2,%edx
lea    0xe8c(%rip),%rcx
call   1050 <print_decode_line@plt>
mov    -0x8(%rbp),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
lea    0xe8e(%rip),%rcx
call   1050 <print_decode_line@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2,%eax
je     127a <decode_btree_page+0x14a>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5,%eax
jne    12a0 <decode_btree_page+0x170>
mov    -0x8(%rbp),%rdi
mov    $0x8,%esi
mov    $0x4,%edx
lea    0xe6a(%rip),%rcx
call   1050 <print_decode_line@plt>
movl   $0xc,-0x24(%rbp)
jmp    12a7 <decode_btree_page+0x177>
movl   $0x8,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1335 <decode_btree_page+0x205>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%ecx
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rsi
lea    -0x30(%rbp),%rdx
movzbl %al,%edi
call   1030 <describeCell@plt>
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%rcx
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12ae <decode_btree_page+0x17e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_btree_page>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rdi,%r13
mov    (%rdi),%al
lea    0xee6(%rip),%r14
add    $0xfe,%al
cmp    $0xb,%al
ja     1185 <decode_btree_page+0x55>
movzbl %al,%eax
lea    0xea6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xece(%rip),%r14
jmp    1185 <decode_btree_page+0x55>
lea    0xed9(%rip),%r14
jmp    1185 <decode_btree_page+0x55>
lea    0xee4(%rip),%r14
jmp    1185 <decode_btree_page+0x55>
lea    0xee6(%rip),%r14
lea    0xeea(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <print_decode_line@plt>
lea    0xee4(%rip),%rcx
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1050 <print_decode_line@plt>
lea    0xee5(%rip),%rcx
mov    %r13,%rdi
mov    $0x3,%esi
mov    $0x2,%edx
call   1050 <print_decode_line@plt>
movzwl 0x3(%r13),%r15d
shl    $0x30,%r15
bswap  %r15
lea    0xedd(%rip),%rcx
mov    %r13,%rdi
mov    $0x5,%esi
mov    $0x2,%edx
call   1050 <print_decode_line@plt>
lea    0xee0(%rip),%rcx
mov    %r13,%rdi
mov    $0x7,%esi
mov    $0x1,%edx
call   1050 <print_decode_line@plt>
mov    0x0(%r13),%cl
cmp    $0x5,%cl
je     1228 <decode_btree_page+0xf8>
mov    $0x8,%eax
cmp    $0x2,%cl
jne    1246 <decode_btree_page+0x116>
lea    0xeca(%rip),%rcx
mov    %r13,%rdi
mov    $0x8,%esi
mov    $0x4,%edx
call   1050 <print_decode_line@plt>
mov    $0xc,%eax
test   %r15d,%r15d
je     12a2 <decode_btree_page+0x172>
lea    (%rax,%r13,1),%r14
add    $0x1,%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movzwl -0x1(%r14,%rbp,2),%ebx
shl    $0x10,%ebx
bswap  %ebx
movzbl 0x0(%r13),%edi
mov    %ebx,%eax
sub    %r12d,%eax
movslq %eax,%rsi
add    %r13,%rsi
mov    %rsp,%rdx
call   1030 <describeCell@plt>
mov    (%rsp),%rcx
lea    0xe77(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1260 <decode_btree_page+0x130>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"unknown\00"
@.str.1 = [20 x i8] c"index interior node\00"
@.str.2 = [20 x i8] c"table interior node\00"
@.str.3 = [11 x i8] c"index leaf\00"
@.str.4 = [11 x i8] c"table leaf\00"
@.str.5 = [26 x i8] c"Decode of btree page %d:\0A\00"
@.str.6 = [26 x i8] c"Offset to first freeblock\00"
@.str.7 = [29 x i8] c"Number of cells on this page\00"
@.str.8 = [28 x i8] c"Offset to cell content area\00"
@.str.9 = [22 x i8] c"Fragmented byte count\00"
@.str.10 = [12 x i8] c"Right child\00"
@.str.11 = [20 x i8] c" %03x: cell[%d] %s\0A\00"
define void @decode_btree_page(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %7
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
switch i32 %16, label %21 [
i32 2, label %17
i32 5, label %18
i32 10, label %19
i32 13, label %20
]
17: ; preds = %3
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %21
18: ; preds = %3
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %21
19: ; preds = %3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %21
20: ; preds = %3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %21
21: ; preds = %3, %20, %19, %18, %17
%22 = load i32, i32* %5
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = load i8*, i8** %4
%25 = load i8*, i8** %7
%26 = call i32 @print_decode_line(i8* %24, i32 0, i32 1, i8* %25)
%27 = load i8*, i8** %4
%28 = call i32 @print_decode_line(i8* %27, i32 1, i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%29 = load i8*, i8** %4
%30 = call i32 @print_decode_line(i8* %29, i32 3, i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 3
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = mul nsw i32 %34, 256
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 4
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = add nsw i32 %35, %39
store i32 %40, i32* %8
%41 = load i8*, i8** %4
%42 = call i32 @print_decode_line(i8* %41, i32 5, i32 2, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%43 = load i8*, i8** %4
%44 = call i32 @print_decode_line(i8* %43, i32 7, i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp eq i32 %48, 2
br i1 %49, label %56, label %50
50: ; preds = %21
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i64 0
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = icmp eq i32 %54, 5
br i1 %55, label %56, label %59
56: ; preds = %50, %21
%57 = load i8*, i8** %4
%58 = call i32 @print_decode_line(i8* %57, i32 8, i32 4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
store i32 12, i32* %10
br label %60
59: ; preds = %50
store i32 8, i32* %10
br label %60
60: ; preds = %59, %56
store i32 0, i32* %9
br label %61
61: ; preds = %99, %60
%62 = load i32, i32* %9
%63 = load i32, i32* %8
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %102
65: ; preds = %61
%66 = load i32, i32* %10
%67 = load i32, i32* %9
%68 = mul nsw i32 %67, 2
%69 = add nsw i32 %66, %68
store i32 %69, i32* %11
%70 = load i8*, i8** %4
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = mul nsw i32 %75, 256
%77 = load i8*, i8** %4
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %77, i64 %80
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = add nsw i32 %76, %83
store i32 %84, i32* %11
%85 = load i8*, i8** %4
%86 = getelementptr inbounds i8, i8* %85, i64 0
%87 = load i8, i8* %86
%88 = load i8*, i8** %4
%89 = load i32, i32* %11
%90 = load i32, i32* %6
%91 = sub nsw i32 %89, %90
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %88, i64 %92
%94 = call i32 @describeCell(i8 zeroext %87, i8* %93, i8** %12)
%95 = load i32, i32* %11
%96 = load i32, i32* %9
%97 = load i8*, i8** %12
%98 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i32 %95, i32 %96, i8* %97)
br label %99
99: ; preds = %65
%100 = load i32, i32* %9
%101 = add nsw i32 %100, 1
store i32 %101, i32* %9
br label %61
102: ; preds = %61
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"unknown\00"
@.str.1 = [20 x i8] c"index interior node\00"
@.str.2 = [20 x i8] c"table interior node\00"
@.str.3 = [11 x i8] c"index leaf\00"
@.str.4 = [11 x i8] c"table leaf\00"
@.str.5 = [26 x i8] c"Decode of btree page %d:\0A\00"
@.str.6 = [26 x i8] c"Offset to first freeblock\00"
@.str.7 = [29 x i8] c"Number of cells on this page\00"
@.str.8 = [28 x i8] c"Offset to cell content area\00"
@.str.9 = [22 x i8] c"Fragmented byte count\00"
@.str.10 = [12 x i8] c"Right child\00"
@.str.11 = [20 x i8] c" %03x: cell[%d] %s\0A\00"
define void @decode_btree_page(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = load i8, i8* %0
switch i8 %5, label %10 [
i8 2, label %6
i8 5, label %7
i8 10, label %8
i8 13, label %9
]
6: ; preds = %3
br label %10
7: ; preds = %3
br label %10
8: ; preds = %3
br label %10
9: ; preds = %3
br label %10
10: ; preds = %3, %9, %8, %7, %6
%11 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), %9 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %6 ]
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %1)
%13 = tail call i32 @print_decode_line(i8* %0, i32 0, i32 1, i8* %11)
%14 = tail call i32 @print_decode_line(i8* %0, i32 1, i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%15 = tail call i32 @print_decode_line(i8* %0, i32 3, i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%16 = getelementptr inbounds i8, i8* %0, i64 3
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = shl nuw nsw i32 %18, 8
%20 = getelementptr inbounds i8, i8* %0, i64 4
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = or i32 %19, %22
%24 = tail call i32 @print_decode_line(i8* %0, i32 5, i32 2, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%25 = tail call i32 @print_decode_line(i8* %0, i32 7, i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%26 = load i8, i8* %0
switch i8 %26, label %29 [
i8 2, label %27
i8 5, label %27
]
27: ; preds = %10, %10
%28 = tail call i32 @print_decode_line(i8* %0, i32 8, i32 4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
br label %29
29: ; preds = %10, %27
%30 = phi i64 [ 12, %27 ], [ 8, %10 ]
%31 = icmp eq i32 %23, 0
br i1 %31, label %58, label %32
32: ; preds = %29
%33 = bitcast i8** %4 to i8*
%34 = zext i32 %23 to i64
br label %35
35: ; preds = %32, %35
%36 = phi i64 [ 0, %32 ], [ %56, %35 ]
%37 = shl nuw nsw i64 %36, 1
%38 = add nuw nsw i64 %37, %30
%39 = getelementptr inbounds i8, i8* %0, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = shl nuw nsw i32 %41, 8
%43 = or i64 %38, 1
%44 = getelementptr inbounds i8, i8* %0, i64 %43
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = or i32 %42, %46
%48 = load i8, i8* %0
%49 = sub nsw i32 %47, %2
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %0, i64 %50
%52 = call i32 @describeCell(i8 zeroext %48, i8* %51, i8** %4)
%53 = load i8*, i8** %4
%54 = trunc i64 %36 to i32
%55 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.11, i64 0, i64 0), i32 %47, i32 %54, i8* %53)
%56 = add nuw nsw i64 %36, 1
%57 = icmp eq i64 %56, %34
br i1 %57, label %58, label %35
58: ; preds = %35, %29
ret void
}