#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 rkw_info_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ banner();
int getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ rkrs_list_named_items(struct rkw_info_t *);
int /*<<< orphan*/ rkst_list_named_items(struct rkw_info_t *);
int /*<<< orphan*/ rkw_free(struct rkw_info_t *);
struct rkw_info_t *rkw_slurp(char *);
int /*<<< orphan*/ unpack_addfile(struct rkw_info_t *, char *);
int /*<<< orphan*/ unpack_bootloader(struct rkw_info_t *, char *);
int /*<<< orphan*/ unpack_rkst(struct rkw_info_t *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int opt;
  struct rkw_info_t *rkw_info = NULL;
  char *prefix = NULL;
  bool info = false;
  bool extract = false;
  bool bootloader = false;
  bool addfile = false;
  while ((opt = getopt(argc, argv, "iebo:aA")) != -1) {
    switch (opt) {
    case 'i':
      info = true;
      break;
    case 'e':
      extract = true;
      break;
    case 'b':
      bootloader = true;
      break;
    case 'o':
      prefix = optarg;
      break;
    case 'a':
      addfile = true;
      break;
    case 'A':
      extract = true;
      bootloader = true;
      addfile = true;
      break;
    default:
      usage(argv[0]);
      break;
    }
  }
  if ((argc - optind) != 1 || (!info && !extract && !bootloader && !addfile)) {
    usage(argv[0]);
    return -1;
  }
  banner();
  rkw_info = rkw_slurp(argv[optind]);
  if (rkw_info) {
    if (info) {
      rkrs_list_named_items(rkw_info);
      rkst_list_named_items(rkw_info);
    }
    if (extract)
      unpack_rkst(rkw_info, prefix);
    if (bootloader)
      unpack_bootloader(rkw_info, prefix);
    if (addfile)
      unpack_addfile(rkw_info, prefix);
    rkw_free(rkw_info);
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xecc(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1298 <main+0xf8>
mov    -0x14(%rbp),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x2e,%eax
ja     1287 <main+0xe7>
mov    -0x40(%rbp),%rax
lea    0xddf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x2c(%rbp)
jmp    1293 <main+0xf3>
movl   $0x1,-0x30(%rbp)
jmp    1293 <main+0xf3>
movl   $0x1,-0x34(%rbp)
jmp    1293 <main+0xf3>
mov    0x2da3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1293 <main+0xf3>
movl   $0x1,-0x38(%rbp)
jmp    1293 <main+0xf3>
movl   $0x1,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    1293 <main+0xf3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
jmp    11e2 <main+0x42>
mov    -0x8(%rbp),%eax
mov    0x2d3e(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jne    12d5 <main+0x135>
cmpl   $0x0,-0x2c(%rbp)
jne    12ed <main+0x14d>
cmpl   $0x0,-0x30(%rbp)
jne    12ed <main+0x14d>
cmpl   $0x0,-0x34(%rbp)
jne    12ed <main+0x14d>
cmpl   $0x0,-0x38(%rbp)
jne    12ed <main+0x14d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1397 <main+0x1f7>
mov    $0x0,%al
call   1040 <banner@plt>
mov    -0x10(%rbp),%rax
mov    0x2ce1(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   10c0 <rkw_slurp@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1390 <main+0x1f0>
cmpl   $0x0,-0x2c(%rbp)
je     1336 <main+0x196>
mov    -0x20(%rbp),%rdi
call   10b0 <rkrs_list_named_items@plt>
mov    -0x20(%rbp),%rdi
call   1030 <rkst_list_named_items@plt>
cmpl   $0x0,-0x30(%rbp)
je     134d <main+0x1ad>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <unpack_rkst@plt>
cmpl   $0x0,-0x34(%rbp)
je     1364 <main+0x1c4>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <unpack_bootloader@plt>
cmpl   $0x0,-0x38(%rbp)
je     137b <main+0x1db>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <unpack_addfile@plt>
mov    -0x20(%rbp),%rdi
call   1090 <rkw_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1397 <main+0x1f7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
mov    %rax,0x10(%rsp)
lea    0xefb(%rip),%r15
lea    0xe38(%rip),%r12
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
xor    %r14d,%r14d
movl   $0x0,0x4(%rsp)
jmp    11ed <main+0x4d>
nop
cmp    $0xffffffff,%eax
je     124e <main+0xae>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
lea    -0x41(%rax),%ecx
cmp    $0x2e,%ecx
ja     11e0 <main+0x40>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
mov    $0x1,%r13d
mov    $0x1,%r14d
movl   $0x1,0x4(%rsp)
jmp    11ed <main+0x4d>
mov    $0x1,%r13d
jmp    11ed <main+0x4d>
mov    $0x1,%r14d
jmp    11ed <main+0x4d>
mov    $0x1,%eax
mov    %rax,0x10(%rsp)
jmp    11ed <main+0x4d>
mov    0x2db4(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
jmp    11ed <main+0x4d>
mov    0x2d8b(%rip),%r15
sub    (%r15),%ebp
cmp    $0x1,%ebp
jne    1275 <main+0xd5>
cmpl   $0x0,0x10(%rsp)
jne    1291 <main+0xf1>
test   %r14d,%r14d
jne    1291 <main+0xf1>
test   %r13d,%r13d
jne    1291 <main+0xf1>
cmpl   $0x0,0x4(%rsp)
jne    1291 <main+0xf1>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1040 <banner@plt>
movslq (%r15),%rax
mov    (%rbx,%rax,8),%rdi
call   10c0 <rkw_slurp@plt>
test   %rax,%rax
je     127d <main+0xdd>
mov    %rax,%rbx
cmpl   $0x0,0x10(%rsp)
je     12c3 <main+0x123>
mov    %rbx,%rdi
call   10b0 <rkrs_list_named_items@plt>
mov    %rbx,%rdi
call   1030 <rkst_list_named_items@plt>
test   %r14d,%r14d
je     1309 <main+0x169>
mov    %rbx,%rdi
mov    0x8(%rsp),%rbp
mov    %rbp,%rsi
call   1050 <unpack_rkst@plt>
test   %r13d,%r13d
je     12e8 <main+0x148>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <unpack_bootloader@plt>
cmpl   $0x0,0x4(%rsp)
je     12fa <main+0x15a>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <unpack_addfile@plt>
mov    %rbx,%rdi
call   1090 <rkw_free@plt>
xor    %eax,%eax
jmp    1282 <main+0xe2>
mov    0x8(%rsp),%rbp
test   %r13d,%r13d
jne    12dd <main+0x13d>
jmp    12e8 <main+0x148>

LLVM IR (-O0):
%struct.rkw_info_t = type { i32 }
@.str = [8 x i8] c"iebo:aA\00"
@optarg = global i8* null
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.rkw_info_t*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.rkw_info_t* null, %struct.rkw_info_t** %7
store i8* null, i8** %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %13
13: ; preds = %32, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %6
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %33
18: ; preds = %13
%19 = load i32, i32* %6
switch i32 %19, label %27 [
i32 105, label %20
i32 101, label %21
i32 98, label %22
i32 111, label %23
i32 97, label %25
i32 65, label %26
]
20: ; preds = %18
store i32 1, i32* %9
br label %32
21: ; preds = %18
store i32 1, i32* %10
br label %32
22: ; preds = %18
store i32 1, i32* %11
br label %32
23: ; preds = %18
%24 = load i8*, i8** @optarg
store i8* %24, i8** %8
br label %32
25: ; preds = %18
store i32 1, i32* %12
br label %32
26: ; preds = %18
store i32 1, i32* %10
store i32 1, i32* %11
store i32 1, i32* %12
br label %32
27: ; preds = %18
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @usage(i8* %30)
br label %32
32: ; preds = %27, %26, %25, %23, %22, %21, %20
br label %13
33: ; preds = %13
%34 = load i32, i32* %4
%35 = load i32, i32* @optind
%36 = sub nsw i32 %34, %35
%37 = icmp ne i32 %36, 1
br i1 %37, label %50, label %38
38: ; preds = %33
%39 = load i32, i32* %9
%40 = icmp ne i32 %39, 0
br i1 %40, label %55, label %41
41: ; preds = %38
%42 = load i32, i32* %10
%43 = icmp ne i32 %42, 0
br i1 %43, label %55, label %44
44: ; preds = %41
%45 = load i32, i32* %11
%46 = icmp ne i32 %45, 0
br i1 %46, label %55, label %47
47: ; preds = %44
%48 = load i32, i32* %12
%49 = icmp ne i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %47, %33
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 0
%53 = load i8*, i8** %52
%54 = call i32 @usage(i8* %53)
store i32 -1, i32* %3
br label %98
55: ; preds = %47, %44, %41, %38
%56 = call i32 (...) @banner()
%57 = load i8**, i8*** %5
%58 = load i32, i32* @optind
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = call %struct.rkw_info_t* @rkw_slurp(i8* %61)
store %struct.rkw_info_t* %62, %struct.rkw_info_t** %7
%63 = load %struct.rkw_info_t*, %struct.rkw_info_t** %7
%64 = icmp ne %struct.rkw_info_t* %63, null
br i1 %64, label %65, label %97
65: ; preds = %55
%66 = load i32, i32* %9
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %65
%69 = load %struct.rkw_info_t*, %struct.rkw_info_t** %7
%70 = call i32 @rkrs_list_named_items(%struct.rkw_info_t* %69)
%71 = load %struct.rkw_info_t*, %struct.rkw_info_t** %7
%72 = call i32 @rkst_list_named_items(%struct.rkw_info_t* %71)
br label %73
73: ; preds = %68, %65
%74 = load i32, i32* %10
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %73
%77 = load %struct.rkw_info_t*, %struct.rkw_info_t** %7
%78 = load i8*, i8** %8
%79 = call i32 @unpack_rkst(%struct.rkw_info_t* %77, i8* %78)
br label %80
80: ; preds = %76, %73
%81 = load i32, i32* %11
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = load %struct.rkw_info_t*, %struct.rkw_info_t** %7
%85 = load i8*, i8** %8
%86 = call i32 @unpack_bootloader(%struct.rkw_info_t* %84, i8* %85)
br label %87
87: ; preds = %83, %80
%88 = load i32, i32* %12
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %94
90: ; preds = %87
%91 = load %struct.rkw_info_t*, %struct.rkw_info_t** %7
%92 = load i8*, i8** %8
%93 = call i32 @unpack_addfile(%struct.rkw_info_t* %91, i8* %92)
br label %94
94: ; preds = %90, %87
%95 = load %struct.rkw_info_t*, %struct.rkw_info_t** %7
%96 = call i32 @rkw_free(%struct.rkw_info_t* %95)
store i32 0, i32* %3
br label %98
97: ; preds = %55
store i32 -1, i32* %3
br label %98
98: ; preds = %97, %94, %50
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
%struct.rkw_info_t = type { i32 }
@.str = [8 x i8] c"iebo:aA\00"
@optarg = global i8* null
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %25, %2
%4 = phi i8* [ %26, %25 ], [ null, %2 ]
%5 = phi i32 [ %10, %25 ], [ 0, %2 ]
%6 = phi i32 [ %15, %25 ], [ 0, %2 ]
%7 = phi i32 [ %19, %25 ], [ 0, %2 ]
%8 = phi i32 [ %22, %25 ], [ 0, %2 ]
br label %9
9: ; preds = %23, %3
%10 = phi i32 [ %5, %3 ], [ 1, %23 ]
%11 = phi i32 [ %6, %3 ], [ %15, %23 ]
%12 = phi i32 [ %7, %3 ], [ %19, %23 ]
%13 = phi i32 [ %8, %3 ], [ %22, %23 ]
br label %14
14: ; preds = %28, %9
%15 = phi i32 [ %11, %9 ], [ 1, %28 ]
%16 = phi i32 [ %12, %9 ], [ %29, %28 ]
%17 = phi i32 [ %13, %9 ], [ %30, %28 ]
br label %18
18: ; preds = %23, %14
%19 = phi i32 [ %16, %14 ], [ 1, %23 ]
%20 = phi i32 [ %17, %14 ], [ %22, %23 ]
br label %21
21: ; preds = %23, %18
%22 = phi i32 [ %20, %18 ], [ 1, %23 ]
br label %23
23: ; preds = %21, %31
%24 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %24, label %31 [
i32 -1, label %34
i32 105, label %9
i32 101, label %28
i32 98, label %18
i32 111, label %25
i32 97, label %21
i32 65, label %27
]
25: ; preds = %23
%26 = load i8*, i8** @optarg
br label %3
27: ; preds = %23
br label %28
28: ; preds = %23, %27
%29 = phi i32 [ 1, %27 ], [ %19, %23 ]
%30 = phi i32 [ 1, %27 ], [ %22, %23 ]
br label %14
31: ; preds = %23
%32 = load i8*, i8** %1
%33 = tail call i32 @usage(i8* %32)
br label %23
34: ; preds = %23
%35 = load i32, i32* @optind
%36 = sub nsw i32 %0, %35
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %46
38: ; preds = %34
%39 = icmp ne i32 %10, 0
%40 = icmp ne i32 %15, 0
%41 = select i1 %39, i1 true, i1 %40
%42 = icmp ne i32 %19, 0
%43 = select i1 %41, i1 true, i1 %42
%44 = icmp ne i32 %22, 0
%45 = select i1 %43, i1 true, i1 %44
br i1 %45, label %49, label %46
46: ; preds = %38, %34
%47 = load i8*, i8** %1
%48 = tail call i32 @usage(i8* %47)
br label %72
49: ; preds = %38
%50 = tail call i32 (...) @banner()
%51 = load i32, i32* @optind
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %1, i64 %52
%54 = load i8*, i8** %53
%55 = tail call %struct.rkw_info_t* @rkw_slurp(i8* %54)
%56 = icmp eq %struct.rkw_info_t* %55, null
br i1 %56, label %72, label %57
57: ; preds = %49
br i1 %39, label %58, label %61
58: ; preds = %57
%59 = tail call i32 @rkrs_list_named_items(%struct.rkw_info_t* %55)
%60 = tail call i32 @rkst_list_named_items(%struct.rkw_info_t* %55)
br label %61
61: ; preds = %58, %57
br i1 %40, label %62, label %64
62: ; preds = %61
%63 = tail call i32 @unpack_rkst(%struct.rkw_info_t* %55, i8* %4)
br label %64
64: ; preds = %62, %61
br i1 %42, label %65, label %67
65: ; preds = %64
%66 = tail call i32 @unpack_bootloader(%struct.rkw_info_t* %55, i8* %4)
br label %67
67: ; preds = %65, %64
br i1 %44, label %68, label %70
68: ; preds = %67
%69 = tail call i32 @unpack_addfile(%struct.rkw_info_t* %55, i8* %4)
br label %70
70: ; preds = %68, %67
%71 = tail call i32 @rkw_free(%struct.rkw_info_t* %55)
br label %72
72: ; preds = %49, %70, %46
%73 = phi i32 [ -1, %46 ], [ 0, %70 ], [ -1, %49 ]
ret i32 %73
}