// File: 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
subq $0x1f0, %rsp            # imm = 0x1F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x39b6(%rip), %rax      # 0x60f6
movq %rax, -0x20(%rbp)
leaq 0x6575(%rip), %rsi      # 0x8cc0
leaq -0x100(%rbp), %rdi
movl $0xe0, %edx
callq 0x2150
movb $0x0, -0x101(%rbp)
movb $0x0, -0x102(%rbp)
movb $0x0, -0x103(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1c0(%rbp)
leaq -0x129(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x22e0
movq -0x1c0(%rbp), %rsi
movq -0x1b8(%rbp), %rdx
leaq -0x128(%rbp), %rdi
callq 0x2230
jmp 0x27ae
leaq -0x129(%rbp), %rdi
callq 0x21d0
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x392e(%rip), %rdx      # 0x60f6
xorl %eax, %eax
movl %eax, %r8d
leaq -0x100(%rbp), %rcx
callq 0x2290
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1c4(%rbp)
subl $-0x1, %eax
je 0x28b5
jmp 0x27f0
movl -0x1c4(%rbp), %eax
subl $0x61, %eax
je 0x2891
jmp 0x2801
movl -0x1c4(%rbp), %eax
subl $0x64, %eax
je 0x28ac
jmp 0x2812
movl -0x1c4(%rbp), %eax
subl $0x66, %eax
je 0x287f
jmp 0x281f
movl -0x1c4(%rbp), %eax
subl $0x68, %eax
je 0x28b5
jmp 0x2830
movl -0x1c4(%rbp), %eax
subl $0x73, %eax
je 0x28a3
jmp 0x283d
movl -0x1c4(%rbp), %eax
subl $0x74, %eax
je 0x286d
jmp 0x28b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x138(%rbp)
movl %eax, -0x13c(%rbp)
leaq -0x129(%rbp), %rdi
callq 0x21d0
jmp 0x2af9
movsbl -0x103(%rbp), %eax
orl $0x1, %eax
movb %al, -0x103(%rbp)
jmp 0x28b9
movsbl -0x103(%rbp), %eax
orl $0x2, %eax
movb %al, -0x103(%rbp)
jmp 0x28b9
movsbl -0x103(%rbp), %eax
orl $0x4, %eax
movb %al, -0x103(%rbp)
jmp 0x28b9
movb $0x1, -0x101(%rbp)
jmp 0x28b9
movb $0x1, -0x102(%rbp)
jmp 0x28b9
jmp 0x28b7
jmp 0x28b9
jmp 0x28bb
cmpl $-0x1, -0x14(%rbp)
jne 0x27ba
movq 0x6704(%rip), %rax      # 0x8fd0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jl 0x2952
leaq -0x160(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x20c0
jmp 0x28e8
leaq -0x160(%rbp), %rdi
callq 0x24f0
jmp 0x28f6
leaq -0x160(%rbp), %rdi
callq 0x2110
movl $0x1, -0x4(%rbp)
movl $0x1, -0x164(%rbp)
jmp 0x2ad5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x138(%rbp)
movl %eax, -0x13c(%rbp)
jmp 0x2aed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x138(%rbp)
movl %eax, -0x13c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x2110
jmp 0x2aed
movzbl -0x102(%rbp), %esi
andl $0x1, %esi
leaq -0x188(%rbp), %rdi
callq 0x2c50
jmp 0x296a
movsbl -0x103(%rbp), %esi
leaq -0x188(%rbp), %rdi
callq 0x2cb0
jmp 0x297f
movq 0x6642(%rip), %rdi      # 0x8fc8
leaq 0x3770(%rip), %rsi      # 0x60fd
callq 0x2190
movq %rax, -0x1d0(%rbp)
jmp 0x299b
movq -0x1d0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x6623(%rip), %rcx      # 0x8fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x2190
movq %rax, -0x1d8(%rbp)
jmp 0x29c2
movq -0x1d8(%rbp), %rdi
movq 0x65e8(%rip), %rsi      # 0x8fb8
callq 0x21c0
jmp 0x29d7
movq -0x10(%rbp), %rax
movq 0x65ee(%rip), %rcx      # 0x8fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x1e8(%rbp)
leaq -0x1a9(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x22e0
movq -0x1e8(%rbp), %rsi
movq -0x1e0(%rbp), %rdx
leaq -0x1a8(%rbp), %rdi
callq 0x2230
jmp 0x2a1f
movzbl -0x101(%rbp), %edx
andl $0x1, %edx
leaq -0x188(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x31b0
jmp 0x2a3e
leaq -0x1a8(%rbp), %rdi
callq 0x2110
leaq -0x1a9(%rbp), %rdi
callq 0x21d0
movl $0x0, -0x4(%rbp)
movl $0x1, -0x164(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x2c90
jmp 0x2ad5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x138(%rbp)
movl %eax, -0x13c(%rbp)
jmp 0x2ac7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x138(%rbp)
movl %eax, -0x13c(%rbp)
jmp 0x2abb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x138(%rbp)
movl %eax, -0x13c(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x2110
leaq -0x1a9(%rbp), %rdi
callq 0x21d0
leaq -0x188(%rbp), %rdi
callq 0x2c90
jmp 0x2aed
leaq -0x128(%rbp), %rdi
callq 0x2110
movl -0x4(%rbp), %eax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
leaq -0x128(%rbp), %rdi
callq 0x2110
movq -0x138(%rbp), %rdi
callq 0x22d0
nopw %cs:(%rax,%rax)
nop