#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 */
struct BTree {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ BTreeClose(struct BTree *);
struct BTree *BTreeOpen(char *);
int /*<<< orphan*/ BTreePrintNodeFromBlock(struct BTree *, int);
int /*<<< orphan*/ BTreePrintRoot(struct BTree *);
int /*<<< orphan*/ BTreeSetDebugMode(int);
int atoi(char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
void main(int argc, char *argv[]) {
  struct BTree *tree;
  int block, keyFormat;
  char input[20];
  if (argc != 3) {
    printf("Usage: DebugBTree <path> <key format>\n");
    printf("       key format is either 'string' or 'int'\n");
    return;
  }
  if (strcmp(argv[2], "string") == 0) {
    keyFormat = 1;
  } else if (strcmp(argv[2], "int") == 0) {
    keyFormat = 2;
  } else {
    printf("Invalid key format.\n");
    return;
  }
  if ((tree = BTreeOpen(argv[1])) == NULL) {
    printf("Can not open BTree at path '%s'\n", argv[1]);
    return;
  }
  BTreeSetDebugMode(keyFormat);
  BTreePrintRoot(tree);
  for (;;) {
    printf("Which node? ");
    gets(input);
    if (input[0] == 'q') {
      break;
    }
    block = atoi(input);
    printf("\nPrinting node %d\n", block);
    BTreePrintNodeFromBlock(tree, block);
  }
  printf("Bye bye!\n");
  BTreeClose(tree);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     11ca <main+0x3a>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12eb <main+0x15b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe7d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f4 <main+0x64>
movl   $0x1,-0x20(%rbp)
jmp    1236 <main+0xa6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    121e <main+0x8e>
movl   $0x2,-0x20(%rbp)
jmp    1231 <main+0xa1>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12eb <main+0x15b>
jmp    1236 <main+0xa6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <BTreeOpen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    126c <main+0xdc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12eb <main+0x15b>
mov    -0x20(%rbp),%edi
call   1050 <BTreeSetDebugMode@plt>
mov    -0x18(%rbp),%rdi
call   1070 <BTreePrintRoot@plt>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1060 <gets@plt>
movsbl -0x40(%rbp),%eax
cmp    $0x71,%eax
jne    12a6 <main+0x116>
jmp    12d4 <main+0x144>
lea    -0x40(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10b0 <BTreePrintNodeFromBlock@plt>
jmp    127d <main+0xed>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <BTreeClose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
cmp    $0x3,%edi
jne    11e7 <main+0x47>
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
lea    0xe41(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     120b <main+0x6b>
mov    0x10(%r14),%rdi
lea    0xe33(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1212 <main+0x72>
lea    0xe67(%rip),%rdi
jmp    11fa <main+0x5a>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe95(%rip),%rdi
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
mov    $0x1,%ebx
jmp    1217 <main+0x77>
mov    $0x2,%ebx
mov    0x8(%r14),%rdi
call   1090 <BTreeOpen@plt>
test   %rax,%rax
je     12c9 <main+0x129>
mov    %rax,%r15
mov    %ebx,%edi
call   1060 <BTreeSetDebugMode@plt>
mov    %r15,%rdi
call   1080 <BTreePrintRoot@plt>
lea    0xdea(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
call   1070 <gets@plt>
cmpb   $0x71,(%rsp)
je     12a8 <main+0x108>
mov    %rsp,%rbx
lea    0xdd8(%rip),%r14
lea    0xdc4(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   10c0 <BTreePrintNodeFromBlock@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <gets@plt>
cmpb   $0x71,(%rsp)
jne    1270 <main+0xd0>
lea    0xdb1(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   10a0 <BTreeClose@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r14),%rsi
lea    0xd37(%rip),%rdi
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
%struct.BTree = type { i32 }
@.str = [39 x i8] c"Usage: DebugBTree <path> <key format>\0A\00"
@.str.1 = [47 x i8] c" key format is either 'string' or 'int'\0A\00"
@.str.2 = [7 x i8] c"string\00"
@.str.3 = [4 x i8] c"int\00"
@.str.4 = [21 x i8] c"Invalid key format.\0A\00"
@.str.5 = [33 x i8] c"Can not open BTree at path '%s'\0A\00"
@.str.6 = [13 x i8] c"Which node? \00"
@.str.7 = [19 x i8] c"\0APrinting node %d\0A\00"
@.str.8 = [10 x i8] c"Bye bye!\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.BTree*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [20 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %68
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 1, i32* %7
br label %31
21: ; preds = %14
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 2, i32* %7
br label %30
28: ; preds = %21
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %68
30: ; preds = %27
br label %31
31: ; preds = %30, %20
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call %struct.BTree* @BTreeOpen(i8* %34)
store %struct.BTree* %35, %struct.BTree** %5
%36 = icmp eq %struct.BTree* %35, null
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i8**, i8*** %4
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %40)
br label %68
42: ; preds = %31
%43 = load i32, i32* %7
%44 = call i32 @BTreeSetDebugMode(i32 %43)
%45 = load %struct.BTree*, %struct.BTree** %5
%46 = call i32 @BTreePrintRoot(%struct.BTree* %45)
br label %47
47: ; preds = %56, %42
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%49 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%50 = call i32 @gets(i8* %49)
%51 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 113
br i1 %54, label %55, label %56
55: ; preds = %47
br label %64
56: ; preds = %47
%57 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%58 = call i32 @atoi(i8* %57)
store i32 %58, i32* %6
%59 = load i32, i32* %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %59)
%61 = load %struct.BTree*, %struct.BTree** %5
%62 = load i32, i32* %6
%63 = call i32 @BTreePrintNodeFromBlock(%struct.BTree* %61, i32 %62)
br label %47
64: ; preds = %55
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%66 = load %struct.BTree*, %struct.BTree** %5
%67 = call i32 @BTreeClose(%struct.BTree* %66)
br label %68
68: ; preds = %64, %37, %28, %11
ret void
}

LLVM IR (-O2):
%struct.BTree = type { i32 }
@.str.2 = [7 x i8] c"string\00"
@.str.3 = [4 x i8] c"int\00"
@.str.5 = [33 x i8] c"Can not open BTree at path '%s'\0A\00"
@.str.6 = [13 x i8] c"Which node? \00"
@.str.7 = [19 x i8] c"\0APrinting node %d\0A\00"
@str = [20 x i8] c"Invalid key format.\00"
@str.9 = [9 x i8] c"Bye bye!\00"
@str.10 = [38 x i8] c"Usage: DebugBTree <path> <key format>\00"
@str.11 = [46 x i8] c" key format is either 'string' or 'int'\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.10, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.11, i64 0, i64 0))
br label %47
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %47
20: ; preds = %14, %9
%21 = phi i32 [ 1, %9 ], [ 2, %14 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call %struct.BTree* @BTreeOpen(i8* %23)
%25 = icmp eq %struct.BTree* %24, null
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i8*, i8** %22
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %27)
br label %47
29: ; preds = %20
%30 = tail call i32 @BTreeSetDebugMode(i32 %21)
%31 = tail call i32 @BTreePrintRoot(%struct.BTree* %24)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 @gets(i8* %4)
%34 = load i8, i8* %4
%35 = icmp eq i8 %34, 113
br i1 %35, label %44, label %36
36: ; preds = %29, %36
%37 = call i32 @atoi(i8* %4)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %37)
%39 = call i32 @BTreePrintNodeFromBlock(%struct.BTree* %24, i32 %37)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @gets(i8* %4)
%42 = load i8, i8* %4
%43 = icmp eq i8 %42, 113
br i1 %43, label %44, label %36
44: ; preds = %36, %29
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.9, i64 0, i64 0))
%46 = call i32 @BTreeClose(%struct.BTree* %24)
br label %47
47: ; preds = %44, %26, %18, %6
ret void
}