#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 dump_tdb(char *, char *);
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
char *optarg;
size_t optind;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  char *fname, *keyname = NULL;
  int c;
  if (argc < 2) {
    printf("Usage: tdbdump <fname>\n");
    exit(1);
  }
  while ((c = getopt(argc, argv, "hk:")) != -1) {
    switch (c) {
    case 'h':
      usage();
      exit(0);
    case 'k':
      keyname = optarg;
      break;
    default:
      usage();
      exit(1);
    }
  }
  fname = argv[optind];
  return dump_tdb(fname, keyname);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118e <main+0x3e>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1193 <main+0x43>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe77(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     120e <main+0xbe>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x68,%eax
je     11d7 <main+0x87>
jmp    11c6 <main+0x76>
mov    -0x28(%rbp),%eax
sub    $0x6b,%eax
je     11e5 <main+0x95>
jmp    11f8 <main+0xa8>
mov    $0x0,%al
call   1040 <usage@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1209 <main+0xb9>
mov    $0x0,%al
call   1040 <usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1193 <main+0x43>
mov    -0x10(%rbp),%rax
mov    0x2dc7(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <dump_tdb@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jl     11df <main+0x8f>
mov    %rsi,%r14
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0xe91(%rip),%r15
mov    0x2e82(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <getopt@plt>
cmp    $0x6b,%eax
jne    1198 <main+0x48>
mov    (%r12),%rbx
jmp    1180 <main+0x30>
cmp    $0xffffffff,%eax
jne    11bb <main+0x6b>
mov    0x2e3c(%rip),%rax
mov    (%rax),%rax
mov    (%r14,%rax,8),%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <dump_tdb@plt>
cmp    $0x68,%eax
jne    11ce <main+0x7e>
xor    %eax,%eax
call   1040 <usage@plt>
xor    %edi,%edi
call   1070 <exit@plt>
xor    %eax,%eax
call   1040 <usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe1e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Usage: tdbdump <fname>\0A\00"
@.str.1 = [4 x i8] c"hk:\00"
@optarg = global i8* null
@optind = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
br label %15
15: ; preds = %30, %14
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32 %18, i32* %8
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %31
20: ; preds = %15
%21 = load i32, i32* %8
switch i32 %21, label %27 [
i32 104, label %22
i32 107, label %25
]
22: ; preds = %20
%23 = call i32 (...) @usage()
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %20
%26 = load i8*, i8** @optarg
store i8* %26, i8** %7
br label %30
27: ; preds = %20
%28 = call i32 (...) @usage()
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %25
br label %15
31: ; preds = %15
%32 = load i8**, i8*** %5
%33 = load i64, i64* @optind
%34 = getelementptr inbounds i8*, i8** %32, i64 %33
%35 = load i8*, i8** %34
store i8* %35, i8** %6
%36 = load i8*, i8** %6
%37 = load i8*, i8** %7
%38 = call i32 @dump_tdb(i8* %36, i8* %37)
ret i32 %38
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"hk:\00"
@optarg = global i8* null
@optind = global i64 0
@str = [23 x i8] c"Usage: tdbdump <fname>\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2, %13
%8 = phi i8* [ %14, %13 ], [ null, %2 ]
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
switch i32 %9, label %15 [
i32 -1, label %18
i32 104, label %10
i32 107, label %13
]
10: ; preds = %7
%11 = tail call i32 (...) @usage()
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %7
%14 = load i8*, i8** @optarg
br label %7
15: ; preds = %7
%16 = tail call i32 (...) @usage()
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %7
%19 = load i64, i64* @optind
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = tail call i32 @dump_tdb(i8* %21, i8* %8)
ret i32 %22
}