// File: /workspace/github_cpp_makefile_star2_O1/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 $0xe8, %rsp
movq %rsi, 0x8(%rsp)
movl %edi, %ebx
movl $0x48, %edi
callq 0x21a0
movq %rax, (%rsp)
movq %rax, %rdi
callq 0x3e98
leaq 0xd8(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl %ebx, 0x20(%rsp)
cmpl $0x2, %ebx
jl 0x29d0
leaq 0x40(%rsp), %rbx
leaq 0x98(%rsp), %rax
movq %rax, 0x18(%rsp)
movl 0x20(%rsp), %eax
movq %rax, 0x28(%rsp)
movl $0x1, %r12d
leaq 0x30(%rsp), %r14
leaq 0x88(%rsp), %r13
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %rbp
movq %rbx, 0x30(%rsp)
movq %r14, %rdi
leaq 0x386d(%rip), %rsi      # 0x60b4
leaq 0x3868(%rip), %rdx      # 0x60b6
callq 0x2d6e
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2090
movl %eax, %ebp
movb $0x1, %r14b
testl %eax, %eax
je 0x293c
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %r15
leaq 0x98(%rsp), %rax
movq %rax, 0x88(%rsp)
movq %r13, %r14
movq %r13, %rdi
leaq 0x3827(%rip), %rsi      # 0x60b8
leaq 0x3825(%rip), %rdx      # 0x60bd
callq 0x2d6e
movq %r14, %rdi
movq %r15, %rsi
callq 0x2090
testl %eax, %eax
je 0x2943
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %r15
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x68(%rsp), %r14
movq %r14, %rdi
leaq 0x37e5(%rip), %rsi      # 0x60b7
leaq 0x37e4(%rip), %rdx      # 0x60bd
callq 0x2d6e
movq %r14, %rdi
movq %r15, %rsi
callq 0x2090
testl %eax, %eax
je 0x2948
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %r15
leaq 0xb8(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
leaq 0x37a6(%rip), %rsi      # 0x60be
leaq 0x37a1(%rip), %rdx      # 0x60c0
callq 0x2d6e
movq %r14, %rdi
movq %r15, %rsi
callq 0x2090
testl %eax, %eax
sete %r14b
movb $0x1, %r15b
movb $0x1, %al
jmp 0x2950
xorl %r15d, %r15d
xorl %eax, %eax
jmp 0x2950
xorl %r15d, %r15d
jmp 0x294b
movb $0x1, %r15b
xorl %eax, %eax
movb $0x1, %r14b
testb %al, %al
je 0x296e
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x296e
callq 0x2180
testb %r15b, %r15b
je 0x2987
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x2987
callq 0x2180
testl %ebp, %ebp
je 0x29a5
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x29a5
callq 0x2180
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x29b4
callq 0x2180
testb %r14b, %r14b
jne 0x2bb0
incq %r12
cmpq %r12, 0x28(%rsp)
leaq 0x30(%rsp), %r14
jne 0x282f
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movl 0x20(%rsp), %eax
cmpl $0x2, %eax
setge %r15b
jl 0x2b6e
movl %eax, %eax
movl $0x1, %ecx
movq %rax, 0x28(%rsp)
subq %rax, %rcx
movq %rcx, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movl $0x2, %r13d
leaq 0x30(%rsp), %r12
movq 0x8(%rsp), %rax
movq -0x8(%rax,%r13,8), %rsi
movq %r12, %rdi
leaq 0x17(%rsp), %rdx
callq 0x20d0
movl $0x2, %ecx
movq %r12, %rdi
leaq 0x3681(%rip), %rsi      # 0x60c1
xorl %edx, %edx
callq 0x2290
testq %rax, %rax
je 0x2a61
movb $0x1, %bpl
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x2ce2
jmp 0x2b15
movl $0x7, %ecx
movq %r12, %rdi
leaq 0x3654(%rip), %rsi      # 0x60c4
xorl %edx, %edx
callq 0x2290
movq %r12, %rdi
testq %rax, %rax
jne 0x2b51
leaq 0x3642(%rip), %rsi      # 0x60cc
callq 0x2090
testl %eax, %eax
je 0x2ad4
movq %r12, %rdi
leaq 0x363a(%rip), %rsi      # 0x60d7
callq 0x2090
testl %eax, %eax
je 0x2aeb
movq %r12, %rdi
leaq 0x3630(%rip), %rsi      # 0x60e0
callq 0x2090
testl %eax, %eax
jne 0x2b58
movl $0x48, %edi
callq 0x21a0
movq %rax, %rbx
movq %rax, %rdi
callq 0x492c
jmp 0x2b00
movl $0x20, %edi
callq 0x21a0
movq %rax, %rbx
movq %rax, %rdi
callq 0x38e6
jmp 0x2b00
movl $0x48, %edi
callq 0x21a0
movq %rax, %rbx
movq %rax, %rdi
callq 0x3e98
movb $0x1, %bpl
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2b11
callq 0x2180
movq %rbx, (%rsp)
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2b29
callq 0x2180
testb %bpl, %bpl
je 0x2b77
cmpq 0x28(%rsp), %r13
setb %r15b
movq 0x20(%rsp), %rax
addq %r13, %rax
incq %rax
incq %r13
cmpq $0x2, %rax
jne 0x2a1a
jmp 0x2b77
callq 0x240c
jmp 0x2b60
movq %r12, %rdi
callq 0x2430
movl $0x1, %eax
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
jmp 0x2b15
movq $0x0, 0x18(%rsp)
testb $0x1, %r15b
movq (%rsp), %rbx
movq 0x18(%rsp), %r15
jne 0x2ba4
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rax
subq %rsi, %rax
cmpq $0x20, %rax
jne 0x2c0c
movq %rbx, %rdi
callq 0x260c
movl %eax, %r15d
leaq 0x50(%rsp), %rdi
callq 0x2d20
jmp 0x2bd0
movq 0x8(%rsp), %rax
movq (%rax), %rdx
leaq 0x35d1(%rip), %rdi      # 0x6190
xorl %r15d, %r15d
movq %rdx, %rsi
xorl %eax, %eax
callq 0x2050
movq (%rsp), %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x2bea
callq 0x2180
testq %rbx, %rbx
je 0x2bf7
movq %rbx, %rdi
callq 0x2180
movl %r15d, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
callq 0x2454
movl $0x1, %r15d
jmp 0x2ba4
jmp 0x2c9e
jmp 0x2c28
jmp 0x2c71
jmp 0x2c28
jmp 0x2c71
movq %rax, %r14
movq %rbx, %rdi
callq 0x2180
jmp 0x2c74
jmp 0x2c71
movq %rax, %r14
jmp 0x2cd1
movq %rax, %r14
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x2c5b
callq 0x2180
jmp 0x2c5b
movq %rax, %r14
movq 0x88(%rsp), %rdi
cmpq 0x18(%rsp), %rdi
je 0x2c8d
callq 0x2180
jmp 0x2c8d
movq %rax, %r14
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2ca1
callq 0x2180
jmp 0x2ca1
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2cb0
callq 0x2180
jmp 0x2cb0
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x2d20
jmp 0x2cb0
movq %rax, %r14
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x2cca
callq 0x2180
cmpq $0x0, (%rsp)
je 0x2cda
movq (%rsp), %rdi
callq 0x2180
movq %r14, %rdi
callq 0x22a0