// File: /workspace/github_cpp_makefile_star2_O2/bigtit[P]ps3patcher/tmain.cc
// Function: main
int main(int argc, char** argv){
  int next_op;
  const char* const short_op = "htfasd";
  const struct option long_op[] = {
    {"help", 0, NULL, 'h'},
    {"trvk", 0, NULL, 't'},
    {"force", 0, NULL, 'f'},
    {"autoexit", 0, NULL, 'a'},
    {"swap", 0, NULL, 's'},
    {"debug", 0, NULL, 'd'},
    {NULL, 0, NULL, 0}
  };

  bool is_swap = false;
  bool is_debug = false;
  char flag = 0;

  string appname = argv[0];
  do{
    next_op = getopt_long(argc, argv, short_op, long_op, NULL);
    switch(next_op){
      case 't':
        flag |= 0x1;
        break;
      case 'f':
        flag |= 0x2;
        break;
      case 'a':
        flag |= 0x4;
        break;
      case 's':
        is_swap = true;
        break;
      case 'd':
        is_debug = true;
        break;
      case 'h':
      case -1:
      default:
        break;
    }
  }while(next_op!=-1);

  if(optind >= argc){ 
    show_help(appname);
    return 1;
  }

  patcher p(is_debug);
  p.set_flag(flag);
  // cout << "flag: " << (int)p.get_flag() << endl;
  cout << "input file: " << argv[optind] << endl;

  // run
  p.do_patch(argv[optind], is_swap);

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %rbx
movl %edi, %r14d
leaq 0x3751(%rip), %rsi      # 0x5cd0
leaq -0x1a0(%rbp), %r15
movl $0xe0, %edx
movq %r15, %rdi
callq 0x20d0
movq (%rbx), %rsi
leaq -0xc0(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x2080
movq $0x0, -0x38(%rbp)
leaq 0x1b41(%rip), %r12      # 0x40f6
movq $0x0, -0x40(%rbp)
xorl %r13d, %r13d
movl %r14d, %edi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x21d0
cmpl $0x61, %eax
je 0x2609
cmpl $0x64, %eax
je 0x25f3
cmpl $0x66, %eax
je 0x2603
cmpl $0x73, %eax
je 0x25fb
cmpl $0x74, %eax
jne 0x260d
orb $0x1, %r13b
jmp 0x260d
movb $0x1, %cl
movq %rcx, -0x40(%rbp)
jmp 0x260d
movb $0x1, %cl
movq %rcx, -0x38(%rbp)
jmp 0x260d
orb $0x2, %r13b
jmp 0x260d
orb $0x4, %r13b
cmpl $-0x1, %eax
jne 0x25c0
movq 0x39bf(%rip), %r15      # 0x5fd8
cmpl %r14d, (%r15)
jge 0x26a7
movzbl -0x40(%rbp), %esi
andl $0x1, %esi
leaq -0x60(%rbp), %rdi
callq 0x277c
movsbl %r13b, %esi
leaq -0x60(%rbp), %rdi
callq 0x279a
movq 0x398a(%rip), %rdi      # 0x5fd0
leaq 0x1ab0(%rip), %rsi      # 0x40fd
callq 0x2110
movslq (%r15), %rcx
movq (%rbx,%rcx,8), %rsi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20a0
movslq (%r15), %rax
movq (%rbx,%rax,8), %rsi
leaq -0x80(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2080
movzbl -0x38(%rbp), %edx
andl $0x1, %edx
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2a02
leaq -0x80(%rbp), %rdi
callq 0x2090
leaq -0x60(%rbp), %rdi
callq 0x2790
xorl %ebx, %ebx
jmp 0x26d5
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x21a0
leaq -0xa0(%rbp), %rdi
callq 0x23dc
leaq -0xa0(%rbp), %rdi
callq 0x2090
pushq $0x1
popq %rbx
leaq -0xc0(%rbp), %rdi
callq 0x2090
movl %ebx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x2090
jmp 0x2720
jmp 0x271d
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x2090
jmp 0x2729
jmp 0x2718
movq %rax, %rbx
jmp 0x2729
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x2790
leaq -0xc0(%rbp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x2200
nopl (%rax)