#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*/ EXIT_FAILURE;
int /*<<< orphan*/ decodeFile(char *, int);
int /*<<< orphan*/ encodeFile(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ getchar();
int getopt(int, char **, char *);
char *optarg;
char optopt;
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *fileName = "";
  if (argc > 1) {
    int c;
    int decodeFlag = 0, encodeFlag = 0, binaryFlag = 0;
    while ((c = getopt(argc, argv, "d:be:")) != -1) {
      switch (c) {
      case 'd':
        decodeFlag = 1;
        fileName = optarg;
        break;
      case 'e':
        encodeFlag = 1;
        fileName = optarg;
        break;
      case 'b':
        binaryFlag = 1;
        break;
      case '?':
        if (optopt == 'e') {
          fileName = "rawText.bin";
          fprintf(stderr, "Option -e requires a filename. Set to default.\n");
        } else if (optopt == 'd') {
          fileName = "Battletoads & Double Dragon - The Ultimate Team (U).nes";
          fprintf(stderr, "Option -d requires a filename. Set to default.\n");
        } else
          fprintf(stderr, "Unknown option character: %c.\n", optopt);
      default:;
      }
    }
    if (decodeFlag)
      decodeFile(fileName, binaryFlag);
    else if (encodeFlag)
      encodeFile(fileName);
    else {
      fprintf(stderr, "Cannot find encode/decode flags in arguments.");
      getchar();
      exit(EXIT_FAILURE);
    }
  } else {
    fprintf(stderr, "Usage: aBsenTminDeD -d fileName [-b] [-e fileName]");
    getchar();
    exit(EXIT_FAILURE);
  }
  return 0;
}


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)
lea    0xfe7(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    133a <main+0x1da>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeee(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     12d1 <main+0x171>
mov    -0x1c(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x26,%eax
ja     12c7 <main+0x167>
mov    -0x30(%rbp),%rax
lea    0xe21(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x20(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    12cc <main+0x16c>
movl   $0x1,-0x24(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    12cc <main+0x16c>
movl   $0x1,-0x28(%rbp)
jmp    12cc <main+0x16c>
mov    0x2db1(%rip),%rax
movsbl (%rax),%eax
cmp    $0x65,%eax
jne    1262 <main+0x102>
lea    0xe60(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12c2 <main+0x162>
mov    0x2d77(%rip),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
jne    129c <main+0x13c>
lea    0xe62(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12bd <main+0x15d>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
mov    0x2d34(%rip),%rax
movsbl (%rax),%edx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12c2 <main+0x162>
jmp    12c7 <main+0x167>
jmp    12cc <main+0x16c>
jmp    11a0 <main+0x40>
cmpl   $0x0,-0x20(%rbp)
je     12ec <main+0x18c>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1030 <decodeFile@plt>
jmp    1335 <main+0x1d5>
cmpl   $0x0,-0x24(%rbp)
je     1304 <main+0x1a4>
mov    -0x18(%rbp),%rdi
call   1060 <encodeFile@plt>
jmp    1330 <main+0x1d0>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1335 <main+0x1d5>
jmp    1366 <main+0x206>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     12bc <main+0x15c>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%al
mov    %eax,0x14(%rsp)
lea    0xfdb(%rip),%rax
mov    %rax,(%rsp)
lea    0xf08(%rip),%r14
lea    0xe65(%rip),%r12
mov    0x2e3e(%rip),%r13
lea    0xf9d(%rip),%r15
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
jmp    11c9 <main+0x69>
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     1285 <main+0x125>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <getopt@plt>
lea    -0x3f(%rax),%ecx
cmp    $0x26,%ecx
ja     11c0 <main+0x60>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
movsbl 0x0(%r13),%edx
mov    0x2ddd(%rip),%rax
cmp    $0x64,%edx
je     1245 <main+0xe5>
cmp    $0x65,%dl
je     1265 <main+0x105>
mov    (%rax),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11c9 <main+0x69>
movl   $0x1,0x10(%rsp)
jmp    11c9 <main+0x69>
mov    0x2ddc(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
movl   $0x0,0x14(%rsp)
jmp    11c9 <main+0x69>
mov    0x2dc4(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
movl   $0x1,0xc(%rsp)
jmp    11c9 <main+0x69>
mov    (%rax),%edi
lea    0xec8(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe82(%rip),%rax
mov    %rax,(%rsp)
jmp    11c9 <main+0x69>
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe26(%rip),%rax
mov    %rax,(%rsp)
jmp    11c9 <main+0x69>
testb  $0x1,0x14(%rsp)
je     129e <main+0x13e>
cmpl   $0x0,0xc(%rsp)
je     12ce <main+0x16e>
mov    (%rsp),%rdi
call   1060 <encodeFile@plt>
jmp    12ab <main+0x14b>
mov    (%rsp),%rdi
mov    0x10(%rsp),%esi
call   1030 <decodeFile@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xec7(%rip),%rsi
jmp    12de <main+0x17e>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"d:be:\00"
@optarg = global i8* null
@optopt = global i8 0
@.str.2 = [12 x i8] c"rawText.bin\00"
@stderr = global i32 0
@.str.3 = [48 x i8] c"Option -e requires a filename. Set to default.\0A\00"
@.str.4 = [56 x i8] c"Battletoads & Double Dragon - The Ultimate Team (U).nes\00"
@.str.5 = [48 x i8] c"Option -d requires a filename. Set to default.\0A\00"
@.str.6 = [31 x i8] c"Unknown option character: %c.\0A\00"
@.str.7 = [46 x i8] c"Cannot find encode/decode flags in arguments.\00"
@EXIT_FAILURE = global i32 0
@.str.8 = [51 x i8] c"Usage: aBsenTminDeD -d fileName [-b] [-e fileName]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %70
13: ; preds = %2
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %14
14: ; preds = %48, %13
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %17, i32* %7
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %49
19: ; preds = %14
%20 = load i32, i32* %7
switch i32 %20, label %47 [
i32 100, label %21
i32 101, label %23
i32 98, label %25
i32 63, label %26
]
21: ; preds = %19
store i32 1, i32* %8
%22 = load i8*, i8** @optarg
store i8* %22, i8** %6
br label %48
23: ; preds = %19
store i32 1, i32* %9
%24 = load i8*, i8** @optarg
store i8* %24, i8** %6
br label %48
25: ; preds = %19
store i32 1, i32* %10
br label %48
26: ; preds = %19
%27 = load i8, i8* @optopt
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 101
br i1 %29, label %30, label %33
30: ; preds = %26
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %6
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
br label %46
33: ; preds = %26
%34 = load i8, i8* @optopt
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 100
br i1 %36, label %37, label %40
37: ; preds = %33
store i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i8** %6
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
br label %45
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = load i8, i8* @optopt
%43 = sext i8 %42 to i32
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %40, %37
br label %46
46: ; preds = %45, %30
br label %47
47: ; preds = %19, %46
br label %48
48: ; preds = %47, %25, %23, %21
br label %14
49: ; preds = %14
%50 = load i32, i32* %8
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i8*, i8** %6
%54 = load i32, i32* %10
%55 = call i32 @decodeFile(i8* %53, i32 %54)
br label %69
56: ; preds = %49
%57 = load i32, i32* %9
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i8*, i8** %6
%61 = call i32 @encodeFile(i8* %60)
br label %68
62: ; preds = %56
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0))
%65 = call i32 (...) @getchar()
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %59
br label %69
69: ; preds = %68, %52
br label %76
70: ; preds = %2
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0))
%73 = call i32 (...) @getchar()
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %69
ret i32 0
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [6 x i8] c"d:be:\00"
@optarg = global i8* null
@optopt = global i8 0
@.str.2 = [12 x i8] c"rawText.bin\00"
@stderr = global i32 0
@.str.3 = [48 x i8] c"Option -e requires a filename. Set to default.\0A\00"
@.str.4 = [56 x i8] c"Battletoads & Double Dragon - The Ultimate Team (U).nes\00"
@.str.5 = [48 x i8] c"Option -d requires a filename. Set to default.\0A\00"
@.str.6 = [31 x i8] c"Unknown option character: %c.\0A\00"
@.str.7 = [46 x i8] c"Cannot find encode/decode flags in arguments.\00"
@EXIT_FAILURE = global i32 0
@.str.8 = [51 x i8] c"Usage: aBsenTminDeD -d fileName [-b] [-e fileName]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %53
4: ; preds = %2, %21
%5 = phi i8* [ %22, %21 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%6 = phi i1 [ false, %21 ], [ true, %2 ]
%7 = phi i32 [ %11, %21 ], [ 0, %2 ]
%8 = phi i32 [ %17, %21 ], [ 0, %2 ]
br label %9
9: ; preds = %4, %23
%10 = phi i8* [ %5, %4 ], [ %24, %23 ]
%11 = phi i32 [ %7, %4 ], [ 1, %23 ]
%12 = phi i32 [ %8, %4 ], [ %17, %23 ]
br label %13
13: ; preds = %30, %9
%14 = phi i8* [ %10, %9 ], [ %31, %30 ]
%15 = phi i32 [ %12, %9 ], [ %17, %30 ]
br label %16
16: ; preds = %18, %13
%17 = phi i32 [ %15, %13 ], [ 1, %18 ]
br label %18
18: ; preds = %20, %16
%19 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
switch i32 %19, label %20 [
i32 -1, label %39
i32 100, label %21
i32 101, label %23
i32 98, label %16
i32 63, label %25
]
20: ; preds = %18, %35
br label %18
21: ; preds = %18
%22 = load i8*, i8** @optarg
br label %4
23: ; preds = %18
%24 = load i8*, i8** @optarg
br label %9
25: ; preds = %18
%26 = load i8, i8* @optopt
switch i8 %26, label %35 [
i8 101, label %27
i8 100, label %32
]
27: ; preds = %25
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %27, %32
%31 = phi i8* [ getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), %32 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %27 ]
br label %13
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
br label %30
35: ; preds = %25
%36 = sext i8 %26 to i32
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %36)
br label %20
39: ; preds = %18
br i1 %6, label %42, label %40
40: ; preds = %39
%41 = tail call i32 @decodeFile(i8* %14, i32 %17)
br label %52
42: ; preds = %39
%43 = icmp eq i32 %11, 0
br i1 %43, label %46, label %44
44: ; preds = %42
%45 = tail call i32 @encodeFile(i8* %14)
br label %52
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0))
%49 = tail call i32 (...) @getchar()
%50 = load i32, i32* @EXIT_FAILURE
%51 = tail call i32 @exit(i32 %50)
unreachable
52: ; preds = %44, %40
ret i32 0
53: ; preds = %2
%54 = load i32, i32* @stderr
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0))
%56 = tail call i32 (...) @getchar()
%57 = load i32, i32* @EXIT_FAILURE
%58 = tail call i32 @exit(i32 %57)
unreachable
}