// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movl %edi, %ebp
movl $0x48, %edi
callq 0x21a0
movq %rax, %rbx
movq %rax, %rdi
callq 0x3e30
leaq 0x98(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
cmpl $0x1, %ebp
jle 0x2b19
movq %rbx, 0x8(%rsp)
leaq 0xb8(%rsp), %rcx
movl %ebp, 0x34(%rsp)
movl %ebp, %eax
movq %rax, 0x58(%rsp)
movl $0x1, %r12d
leaq 0x38(%rsp), %rbx
leaq 0x10(%rsp), %r13
movq %r14, 0x60(%rsp)
movq %rcx, %r15
movq (%r14,%r12,8), %rbp
leaq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %rbx, %rdi
leaq 0x386e(%rip), %rsi      # 0x60b4
leaq 0x3869(%rip), %rdx      # 0x60b6
callq 0x2d4c
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x2090
testl %eax, %eax
je 0x293a
movq %r14, %rbx
movq (%r14,%r12,8), %rbp
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r13, %r14
movq %r13, %rdi
leaq 0x3835(%rip), %rsi      # 0x60b8
leaq 0x3833(%rip), %rdx      # 0x60bd
callq 0x2d4c
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2090
testl %eax, %eax
je 0x293f
movq %rbx, %r14
movq (%rbx,%r12,8), %rbp
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
leaq 0x37f5(%rip), %rsi      # 0x60b7
leaq 0x37f4(%rip), %rdx      # 0x60bd
callq 0x2d4c
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x2090
testl %eax, %eax
je 0x294f
movq (%r14,%r12,8), %rbp
movq %r15, %rbx
movq %r15, 0xa8(%rsp)
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
leaq 0x37c0(%rip), %rsi      # 0x60be
leaq 0x37bb(%rip), %rdx      # 0x60c0
callq 0x2d4c
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2090
testl %eax, %eax
sete %bpl
movq 0xa8(%rsp), %rdi
cmpq %rbx, %rdi
movq %rbx, %rcx
je 0x2933
callq 0x2180
movq %r15, %rcx
movq 0x60(%rsp), %r14
jmp 0x2955
movb $0x1, %bpl
jmp 0x2985
movb $0x1, %bpl
movq %r15, %rcx
movq %rbx, %r14
leaq 0x38(%rsp), %rbx
jmp 0x2971
movb $0x1, %bpl
movq %r15, %rcx
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
leaq 0x38(%rsp), %rbx
je 0x2971
callq 0x2180
movq %r15, %rcx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2988
callq 0x2180
movq %r15, %rcx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x299f
callq 0x2180
movq %r15, %rcx
testb %bpl, %bpl
jne 0x2b31
incq %r12
cmpq %r12, 0x58(%rsp)
jne 0x282b
xorl %r15d, %r15d
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpl $0x2, 0x34(%rsp)
jl 0x2b57
movl $0x1, %r13d
leaq 0x38(%rsp), %r12
movq (%r14,%r13,8), %rsi
movq %r12, %rdi
leaq 0x68(%rsp), %rdx
callq 0x20d0
movl $0x2, %ecx
movq %r12, %rdi
leaq 0x36c1(%rip), %rsi      # 0x60c1
xorl %edx, %edx
callq 0x2290
testq %rax, %rax
je 0x2a21
movb $0x1, %bpl
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2cba
jmp 0x2ad7
movl $0x7, %ecx
movq %r12, %rdi
leaq 0x3694(%rip), %rsi      # 0x60c4
xorl %edx, %edx
callq 0x2290
movq %r12, %rdi
testq %rax, %rax
jne 0x2b00
leaq 0x3682(%rip), %rsi      # 0x60cc
callq 0x2090
testl %eax, %eax
je 0x2a94
movq %r12, %rdi
leaq 0x367a(%rip), %rsi      # 0x60d7
callq 0x2090
testl %eax, %eax
je 0x2aab
movq %r12, %rdi
leaq 0x3670(%rip), %rsi      # 0x60e0
callq 0x2090
testl %eax, %eax
jne 0x2b07
movl $0x48, %edi
callq 0x21a0
movq %rax, %rbx
movq %rax, %rdi
callq 0x48d4
jmp 0x2ac0
movl $0x20, %edi
callq 0x21a0
movq %rax, %rbx
movq %rax, %rdi
callq 0x3878
jmp 0x2ac0
movl $0x48, %edi
callq 0x21a0
movq %rax, %rbx
movq %rax, %rdi
callq 0x3e30
movb $0x1, %bpl
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2ad2
callq 0x2180
movq %rbx, 0x8(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2aeb
callq 0x2180
testb %bpl, %bpl
je 0x2b5b
incq %r13
cmpq %r13, 0x58(%rsp)
jne 0x29e0
jmp 0x2b6a
callq 0x240c
jmp 0x2b0f
movq %r12, %rdi
callq 0x2430
movl $0x1, %r15d
xorl %ebp, %ebp
jmp 0x2ad7
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r15d, %r15d
xorl %eax, %eax
jmp 0x2b81
movq (%r14), %rdx
leaq 0x3655(%rip), %rdi      # 0x6190
xorl %r15d, %r15d
movq %rdx, %rsi
xorl %eax, %eax
callq 0x2050
movq 0x8(%rsp), %rbx
leaq 0x98(%rsp), %r12
jmp 0x2ba2
xorl %eax, %eax
jmp 0x2b74
movq 0x8(%rsp), %rbx
leaq 0x98(%rsp), %r12
jmp 0x2b98
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rax
movq 0x8(%rsp), %rbx
leaq 0x98(%rsp), %r12
subq %r15, %rax
cmpq $0x20, %rax
jne 0x2bd6
movq %rbx, %rdi
movq %r15, %rsi
callq 0x260c
movl %eax, %r15d
leaq 0x10(%rsp), %rdi
callq 0x2cf8
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x2bb4
callq 0x2180
testq %rbx, %rbx
je 0x2bc1
movq %rbx, %rdi
callq 0x2180
movl %r15d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x2454
movl $0x1, %r15d
jmp 0x2b98
jmp 0x2bee
jmp 0x2c0f
jmp 0x2bee
jmp 0x2c0f
movq %rax, %r14
movq %rbx, %rdi
callq 0x2180
jmp 0x2c12
jmp 0x2c0f
movq %rbx, 0x8(%rsp)
jmp 0x2c41
movq %rax, %r14
movq %rbx, %rdi
jmp 0x2cac
movq %rax, %r14
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2c44
callq 0x2180
jmp 0x2c44
movq %rax, %r14
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x2c53
callq 0x2180
jmp 0x2c53
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x2cf8
jmp 0x2c85
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2c6c
callq 0x2180
jmp 0x2c6c
movq %rax, %r14
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2c85
callq 0x2180
jmp 0x2c85
movq %rax, %r14
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x2c9f
callq 0x2180
cmpq $0x0, 0x8(%rsp)
je 0x2cb1
movq 0x8(%rsp), %rdi
callq 0x2180
movq %r14, %rdi
callq 0x22a0
nop