// File: /workspace/github_cpp_makefile_star2_O2/brianquinlan[P]brainfuck-jit/bf_main.cpp
// Function: main
int main(int argc, char *argv[]) {
  unique_ptr<BrainfuckRunner> bf(new BrainfuckInterpreter());
  string bf_file;

  for (int i = 1; i < argc; ++i) {
    if (argv[i] == string("-h") ||
        argv[i] == string("-help") ||
        argv[i] == string("--help") ||
        argv[i] == string("-?")) {
      printf(USAGE, argv[0], argv[0]);
      return 0;
    }
  }

  vector<string> files;
  for (int i = 1; i < argc; ++i) {
    string arg(argv[i]);
    if (arg.find("--") == 0) {
      if (arg.find("--mode=") == 0) {
        if (arg == "--mode=cag") {
          unique_ptr<BrainfuckRunner> compile_and_go(
              new BrainfuckCompileAndGo());
          bf = std::move(compile_and_go);
        } else if (arg == "--mode=i") {
          unique_ptr<BrainfuckRunner> interpreter(new BrainfuckInterpreter());
          bf = std::move(interpreter);
        } else if (arg == "--mode=jit") {
          unique_ptr<BrainfuckRunner> jit(new BrainfuckJIT());
          bf = std::move(jit);
        } else {
          fprintf(stderr, "Unexpected mode: %s\n", arg.c_str());
          return 1;
        }
      } else {
        fprintf(stderr, "Unexpected argument: %s\n", arg.c_str());
        return 1;
      }
    } else {
      files.push_back(arg);
    }
  }

  if (files.size() != 1) {
    fputs("You need to specify exactly one Brainfuck file\n", stderr);
    printf(USAGE, argv[0], argv[0]);
    return 1;
  }

  return run_brainfuck_program(bf.get(), files[0]);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, (%rsp)
movl %edi, %ebp
pushq $0x48
popq %rdi
callq 0x21b0
movq %rax, %r14
movq %rax, %rdi
callq 0x3aa4
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %r14, 0x10(%rsp)
movb $0x0, (%rax)
movslq %ebp, %rax
movq %rax, 0x18(%rsp)
pushq $0x1
popq %rbx
leaq 0x48(%rsp), %r15
leaq 0x20(%rsp), %rbp
leaq 0x68(%rsp), %r14
leaq 0xa8(%rsp), %r13
cmpq 0x18(%rsp), %rbx
jge 0x2790
movq (%rsp), %rax
movq (%rax,%rbx,8), %r12
movq %r15, %rdi
leaq 0x29fa(%rip), %rsi      # 0x50b4
leaq 0xf(%rsp), %rdx
callq 0x20d0
movq %r12, %rdi
movq %r15, %rsi
callq 0x2a56
testb %al, %al
jne 0x2912
movq (%rsp), %rax
movq (%rax,%rbx,8), %r12
movq %rbp, %rdi
leaq 0x29cf(%rip), %rsi      # 0x50b8
leaq 0xe(%rsp), %rdx
callq 0x20d0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2a56
testb %al, %al
jne 0x2908
movq (%rsp), %rax
movq (%rax,%rbx,8), %r12
movq %r14, %rdi
leaq 0x299f(%rip), %rsi      # 0x50b7
leaq 0xd(%rsp), %rdx
callq 0x20d0
movq %r12, %rdi
movq %r14, %rsi
callq 0x2a56
testb %al, %al
jne 0x28fe
movq (%rsp), %rax
movq (%rax,%rbx,8), %r12
movq %r13, %rdi
leaq 0x2977(%rip), %rsi      # 0x50be
leaq 0xc(%rsp), %rdx
callq 0x20d0
movq %r12, %rdi
movq %r13, %rsi
callq 0x2a56
movl %eax, %r12d
movq %r13, %rdi
callq 0x20f0
movq %r14, %rdi
callq 0x20f0
movq %rbp, %rdi
callq 0x20f0
movq %r15, %rdi
callq 0x20f0
incq %rbx
testb %r12b, %r12b
je 0x269d
jmp 0x291c
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
xorl %r14d, %r14d
pushq $0x1
popq %rbp
leaq 0x48(%rsp), %r12
leaq 0x68(%rsp), %r13
cmpq 0x18(%rsp), %rbp
jge 0x2939
movq (%rsp), %rax
movq (%rax,%rbp,8), %rsi
movq %r12, %rdi
movq %r13, %rdx
callq 0x20d0
movq %r12, %rdi
leaq 0x28e9(%rip), %rsi      # 0x50c1
xorl %edx, %edx
callq 0x2310
testq %rax, %rax
je 0x27f8
movb $0x1, %bl
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x2a92
jmp 0x28a5
movq %r12, %rdi
leaq 0x28c2(%rip), %rsi      # 0x50c4
xorl %edx, %edx
callq 0x2310
testq %rax, %rax
jne 0x28bd
movq %r12, %rdi
leaq 0x28b0(%rip), %rsi      # 0x50cc
callq 0x2a6c
testb %al, %al
je 0x283a
pushq $0x20
popq %rdi
callq 0x21b0
movq %rax, %r15
movq %rax, %rdi
callq 0x34c2
jmp 0x2888
movq %r12, %rdi
leaq 0x2893(%rip), %rsi      # 0x50d7
callq 0x2a6c
testb %al, %al
je 0x2862
pushq $0x48
popq %rdi
callq 0x21b0
movq %rax, %r15
movq %rax, %rdi
callq 0x3aa4
jmp 0x2888
movq %r12, %rdi
leaq 0x2874(%rip), %rsi      # 0x50e0
callq 0x2a6c
testb %al, %al
je 0x28e4
pushq $0x48
popq %rdi
callq 0x21b0
movq %rax, %r15
movq %rax, %rdi
callq 0x451c
andq $0x0, 0x68(%rsp)
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x2ae0
movq %r13, %rdi
callq 0x2a7a
movb $0x1, %bl
movq %r12, %rdi
callq 0x20f0
incq %rbp
testb %bl, %bl
jne 0x27b0
jmp 0x2959
movq 0x671c(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
movq 0x48(%rsp), %rdx
xorl %ebx, %ebx
leaq 0x282b(%rip), %rsi      # 0x5100
xorl %eax, %eax
callq 0x2250
pushq $0x1
popq %rax
movl %eax, %r14d
jmp 0x28a5
movq 0x66f5(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
movq 0x48(%rsp), %rdx
xorl %ebx, %ebx
leaq 0x27ef(%rip), %rsi      # 0x50eb
jmp 0x28d5
leaq 0x68(%rsp), %rdi
callq 0x20f0
leaq 0x20(%rsp), %rdi
callq 0x20f0
leaq 0x48(%rsp), %rdi
callq 0x20f0
movq (%rsp), %rax
movq (%rax), %rdx
leaq 0x2866(%rip), %rdi      # 0x5190
xorl %r14d, %r14d
movq %rdx, %rsi
xorl %eax, %eax
callq 0x2050
jmp 0x2963
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
subq %rsi, %rax
cmpq $0x20, %rax
jne 0x298f
movq 0x10(%rsp), %rdi
callq 0x241c
movl %eax, %r14d
leaq 0x20(%rsp), %rdi
callq 0x2abe
leaq 0x88(%rsp), %rdi
callq 0x20f0
leaq 0x10(%rsp), %rdi
callq 0x2a7a
movl %r14d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x664a(%rip), %rax      # 0x8fe0
movq (%rax), %rsi
leaq 0x2779(%rip), %rdi      # 0x5119
callq 0x21e0
movq (%rsp), %rax
movq (%rax), %rdx
leaq 0x27dd(%rip), %rdi      # 0x5190
movq %rdx, %rsi
xorl %eax, %eax
callq 0x2050
pushq $0x1
popq %r14
jmp 0x2959
jmp 0x29f8
jmp 0x29cd
jmp 0x29e9
jmp 0x29cd
jmp 0x29e9
movq %rax, %rbx
movq %r15, %rdi
callq 0x2190
jmp 0x29ec
jmp 0x29e9
movq %rax, %rbx
movq %r14, %rdi
callq 0x2190
jmp 0x2a4e
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x20f0
jmp 0x29fb
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2abe
jmp 0x2a37
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x20f0
jmp 0x2a19
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20f0
jmp 0x2a28
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x20f0
jmp 0x2a37
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x20f0
leaq 0x10(%rsp), %rdi
callq 0x2a7a
movq %rbx, %rdi
callq 0x22b0