// File: /workspace/github_cpp_makefile_star2_O1/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 0x35d7(%rip), %rsi      # 0x5cc0
leaq -0x1a0(%rbp), %r15
movl $0xe0, %edx
movq %r15, %rdi
callq 0x20f0
movq (%rbx), %rsi
leaq -0xa0(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x2090
movq $0x0, -0x38(%rbp)
leaq 0x19d7(%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 0x21f0
cmpl $0x65, %eax
jle 0x2758
cmpl $0x66, %eax
je 0x276a
cmpl $0x73, %eax
je 0x2770
cmpl $0x74, %eax
jne 0x277c
orb $0x1, %r13b
jmp 0x277c
cmpl $0x61, %eax
je 0x2778
cmpl $0x64, %eax
jne 0x277c
movb $0x1, %cl
movq %rcx, -0x40(%rbp)
jmp 0x277c
orb $0x2, %r13b
jmp 0x277c
movb $0x1, %cl
movq %rcx, -0x38(%rbp)
jmp 0x277c
orb $0x4, %r13b
cmpl $-0x1, %eax
jne 0x272a
movq 0x3848(%rip), %r12      # 0x5fd0
cmpl %r14d, (%r12)
jge 0x27ef
movzbl -0x40(%rbp), %esi
andl $0x1, %esi
leaq -0x60(%rbp), %rdi
callq 0x2a28
movsbl %r13b, %esi
leaq -0x60(%rbp), %rdi
callq 0x2a50
movq 0x3816(%rip), %r14      # 0x5fc8
leaq 0x1944(%rip), %rsi      # 0x40fd
movl $0xc, %edx
movq %r14, %rdi
callq 0x2180
movslq (%r12), %rax
movq (%rbx,%rax,8), %r15
testq %r15, %r15
je 0x2836
movq %r15, %rdi
callq 0x20a0
movq 0x37e6(%rip), %rdi      # 0x5fc8
movq %r15, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x284e
leaq -0x70(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
addq %rsi, %rdx
leaq -0x80(%rbp), %rdi
callq 0x2950
leaq -0x80(%rbp), %rdi
callq 0x241c
movq -0x80(%rbp), %rdi
movl $0x1, %ebx
cmpq %r14, %rdi
je 0x28c8
callq 0x2120
jmp 0x28c8
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x2200
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x375c(%rip), %rdi      # 0x5fc8
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movslq (%r12), %rax
movq (%rbx,%rax,8), %rsi
leaq -0xc0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2090
movzbl -0x38(%rbp), %edx
andl $0x1, %edx
leaq -0x60(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x2e94
leaq -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x28bd
callq 0x2120
leaq -0x60(%rbp), %rdi
callq 0x2a3c
xorl %ebx, %ebx
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x28dd
callq 0x2120
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 -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x292a
callq 0x2120
jmp 0x292a
jmp 0x2927
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x2933
callq 0x2120
jmp 0x2933
jmp 0x2922
movq %rax, %rbx
jmp 0x2933
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x2a3c
leaq -0x90(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2948
callq 0x2120
movq %rbx, %rdi
callq 0x2230