// File: /workspace/github_cpp_makefile_star2_O1/bigtit[P]ps3patcher/patcher.cc
// Function: patcher::do_patch(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
void patcher::do_patch(string name, bool swap){
  string fileout = get_dest_name(name);
  std::ifstream freader(name.c_str(), std::ios::binary);
  freader >> std::noskipws;
  std::ofstream fwriter(fileout.c_str(), std::ios::binary);
  if(swap) status("Go swap");
  status("Creating output file...");
  fwriter << freader.rdbuf(); // copy
  freader.seekg(0, std::ios::end);
  auto pos = freader.tellg();
  freader.close();
  get_ros_pdata("patch.bin", swap);
  status("input size: "+std::to_string(pos)+" bytes");
  if(pos!=0x1000000L && pos!=0x10000000L){
    remove(fileout.c_str());
    error("size error, exits");
    return;
  }
  else if(0x1000000L == pos){ // nor
    status("Go NOR");
    write_patch(0xc0010, fwriter);
    write_patch(0x7c0010, fwriter);
    if(chk_flag(0x1)){
      status("Go trvkpatches");
      get_pdata("nor_rvk.bin", swap);
      write_patch(0x40000, fwriter);
    }
    if(chk_flag(0x2)){
      status("Go forcepatch && rosheader");
      get_pdata("ros_head.bin", swap);
      write_patch(0xc0000, fwriter);
      write_patch(0x7c0000, fwriter);
    }
    status("Done NOR");
  }else{ // nand
    status("Go NAND");
    write_patch(0xc0030, fwriter);
    write_patch(0x7c0020, fwriter);
    if(chk_flag(0x1)){
      status("Go trvkpatches");
      get_pdata("nand_rvk.bin", swap);
      write_patch(0x40000, fwriter);
    }
    if(chk_flag(0x2)){
      status("Go forcepatch && rosheader");
      get_pdata("ros_head.bin", swap);
      write_patch(0xc0020, fwriter);
      write_patch(0x7c0010, fwriter);
    }
    status("Done NAND");
  }

  if(chk_flag(0x4)); // autoexit, reserved
  cout << "Done\n";
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x698, %rsp            # imm = 0x698
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %r13
leaq -0x2a8(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%rsi), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x2b8(%rbp), %rbx
movq %rbx, %rdi
callq 0x2950
leaq -0x298(%rbp), %rdi
movq %rbx, %rdx
callq 0x2c50
movq -0x2b8(%rbp), %rdi
cmpq %r12, %rdi
je 0x2ef6
callq 0x2120
movq (%r15), %rsi
leaq -0x6c0(%rbp), %rdi
movl $0x4, %edx
callq 0x2260
movq -0x6c0(%rbp), %rax
movq -0x18(%rax), %rax
andl $0xffffefff, -0x6a8(%rbp,%rax) # imm = 0xFFFFEFFF
movq -0x298(%rbp), %rsi
leaq -0x4b8(%rbp), %rdi
movl $0x4, %edx
callq 0x2160
testb %r14b, %r14b
je 0x2f82
leaq -0x268(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x1202(%rip), %rsi      # 0x4151
leaq 0x1202(%rip), %rdx      # 0x4158
leaq -0x278(%rbp), %rdi
callq 0x3a38
leaq -0x278(%rbp), %rsi
movq %r13, %rdi
callq 0x2a72
movq -0x278(%rbp), %rdi
cmpq %r15, %rdi
je 0x2f82
callq 0x2120
leaq -0x248(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x11c5(%rip), %rsi      # 0x4159
leaq 0x11d5(%rip), %rdx      # 0x4170
leaq -0x258(%rbp), %rdi
callq 0x3a38
leaq -0x258(%rbp), %rsi
movq %r13, %rdi
callq 0x2a72
movq -0x258(%rbp), %rdi
cmpq %r15, %rdi
je 0x2fc7
callq 0x2120
leaq -0x6b0(%rbp), %rsi
leaq -0x4b8(%rbp), %rdi
callq 0x2050
leaq -0x6c0(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x21c0
leaq -0x6c0(%rbp), %rdi
callq 0x2220
movq %rax, %rbx
leaq -0x6c0(%rbp), %rdi
callq 0x2040
leaq -0x228(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x1157(%rip), %rsi      # 0x4171
leaq 0x1159(%rip), %rdx      # 0x417a
leaq -0x238(%rbp), %rdi
callq 0x3a38
movzbl %r14b, %edx
leaq -0x238(%rbp), %rsi
movq %r13, %rdi
movl %edx, -0x2c(%rbp)
callq 0x2bd8
movq %r13, -0x38(%rbp)
movq -0x238(%rbp), %rdi
cmpq %r15, %rdi
je 0x3058
callq 0x2120
movq %rbx, %r12
negq %r12
cmovsq %rbx, %r12
movl $0x1, %r13d
cmpq $0xa, %r12
jb 0x30c2
movl $0x4, %r13d
movabsq $0x346dc5d63886594b, %rsi # imm = 0x346DC5D63886594B
movq %r12, %rcx
cmpq $0x63, %rcx
jbe 0x30b9
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x30bf
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x30c2
movq %rcx, %rax
mulq %rsi
shrq $0xb, %rdx
addl $0x4, %r13d
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x3081
addl $-0x3, %r13d
jmp 0x30c2
addl $-0x2, %r13d
jmp 0x30c2
decl %r13d
movq %rbx, %r15
shrq $0x3f, %r15
leal (%r15,%r13), %esi
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0x58(%rbp), %rdi
movl $0x2d, %edx
callq 0x2190
leaq -0x58(%rbp), %r14
addq (%r14), %r15
movq %r15, %rdi
movl %r13d, %esi
movq %r12, %rdx
callq 0x3980
leaq 0x107c(%rip), %rcx      # 0x417b
movl $0xc, %r8d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2170
leaq -0x68(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movq -0x38(%rbp), %r12
je 0x3139
movq %rdx, -0x78(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x68(%rbp)
jmp 0x3140
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq -0x78(%rbp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xfe8(%rip), %rsi       # 0x414a
callq 0x2270
leaq -0x88(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x3194
movq %rdx, -0x98(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x88(%rbp)
jmp 0x319b
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq -0x98(%rbp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r12, %rdi
callq 0x2a72
movq -0x98(%rbp), %rdi
cmpq %r15, %rdi
je 0x31d2
callq 0x2120
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x31e0
callq 0x2120
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x31f2
callq 0x2120
cmpq $0x1000000, %rbx        # imm = 0x1000000
je 0x3427
cmpq $0x10000000, %rbx       # imm = 0x10000000
jne 0x3664
leaq -0x148(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xfdd(%rip), %rsi       # 0x41fb
leaq 0xfdd(%rip), %rdx       # 0x4202
leaq -0x158(%rbp), %rdi
callq 0x3a38
leaq -0x158(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x158(%rbp), %rdi
cmpq %r14, %rdi
je 0x3251
callq 0x2120
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0xc0030, %esi          # imm = 0xC0030
callq 0x2ca8
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0x7c0020, %esi         # imm = 0x7C0020
callq 0x2ca8
testb $0x1, 0x18(%r12)
je 0x3326
leaq -0x128(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xf18(%rip), %rsi       # 0x41af
leaq 0xf1f(%rip), %rdx       # 0x41bd
leaq -0x138(%rbp), %rdi
callq 0x3a38
leaq -0x138(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x138(%rbp), %rdi
cmpq %r14, %rdi
je 0x32ca
callq 0x2120
leaq -0x108(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xf27(%rip), %rsi       # 0x4203
leaq 0xf2c(%rip), %rdx       # 0x420f
leaq -0x118(%rbp), %rdi
callq 0x3a38
leaq -0x118(%rbp), %rsi
movq %r12, %rdi
movl -0x2c(%rbp), %edx
callq 0x2ac6
movq -0x118(%rbp), %rdi
cmpq %r14, %rdi
je 0x3312
callq 0x2120
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0x40000, %esi          # imm = 0x40000
callq 0x2ca8
testb $0x2, 0x18(%r12)
je 0x33e7
leaq -0xe8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xe86(%rip), %rsi       # 0x41ca
leaq 0xe99(%rip), %rdx       # 0x41e4
leaq -0xf8(%rbp), %rdi
callq 0x3a38
leaq -0xf8(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0xf8(%rbp), %rdi
cmpq %r14, %rdi
je 0x3377
callq 0x2120
leaq -0xc8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xe5c(%rip), %rsi       # 0x41e5
leaq 0xe61(%rip), %rdx       # 0x41f1
leaq -0xd8(%rbp), %rdi
callq 0x3a38
leaq -0xd8(%rbp), %rsi
movq %r12, %rdi
movl -0x2c(%rbp), %edx
callq 0x2ac6
movq -0xd8(%rbp), %rdi
cmpq %r14, %rdi
je 0x33bf
callq 0x2120
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0xc0020, %esi          # imm = 0xC0020
callq 0x2ca8
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0x7c0010, %esi         # imm = 0x7C0010
callq 0x2ca8
leaq -0xa8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xe17(%rip), %rsi       # 0x4210
leaq 0xe19(%rip), %rdx       # 0x4219
leaq -0xb8(%rbp), %rdi
callq 0x3a38
leaq -0xb8(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0xb8(%rbp), %rdi
jmp 0x363d
leaq -0x208(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xd6f(%rip), %rsi       # 0x41a8
leaq 0xd6e(%rip), %rdx       # 0x41ae
leaq -0x218(%rbp), %rdi
callq 0x3a38
leaq -0x218(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x218(%rbp), %rdi
cmpq %r14, %rdi
je 0x346c
callq 0x2120
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0xc0010, %esi          # imm = 0xC0010
callq 0x2ca8
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0x7c0010, %esi         # imm = 0x7C0010
callq 0x2ca8
testb $0x1, 0x18(%r12)
je 0x3541
leaq -0x1e8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xcfd(%rip), %rsi       # 0x41af
leaq 0xd04(%rip), %rdx       # 0x41bd
leaq -0x1f8(%rbp), %rdi
callq 0x3a38
leaq -0x1f8(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x1f8(%rbp), %rdi
cmpq %r14, %rdi
je 0x34e5
callq 0x2120
leaq -0x1c8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xcc7(%rip), %rsi       # 0x41be
leaq 0xccb(%rip), %rdx       # 0x41c9
leaq -0x1d8(%rbp), %rdi
callq 0x3a38
leaq -0x1d8(%rbp), %rsi
movq %r12, %rdi
movl -0x2c(%rbp), %edx
callq 0x2ac6
movq -0x1d8(%rbp), %rdi
cmpq %r14, %rdi
je 0x352d
callq 0x2120
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0x40000, %esi          # imm = 0x40000
callq 0x2ca8
testb $0x2, 0x18(%r12)
je 0x3602
leaq -0x1a8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xc6b(%rip), %rsi       # 0x41ca
leaq 0xc7e(%rip), %rdx       # 0x41e4
leaq -0x1b8(%rbp), %rdi
callq 0x3a38
leaq -0x1b8(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x1b8(%rbp), %rdi
cmpq %r14, %rdi
je 0x3592
callq 0x2120
leaq -0x188(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xc41(%rip), %rsi       # 0x41e5
leaq 0xc46(%rip), %rdx       # 0x41f1
leaq -0x198(%rbp), %rdi
callq 0x3a38
leaq -0x198(%rbp), %rsi
movq %r12, %rdi
movl -0x2c(%rbp), %edx
callq 0x2ac6
movq -0x198(%rbp), %rdi
cmpq %r14, %rdi
je 0x35da
callq 0x2120
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0xc0000, %esi          # imm = 0xC0000
callq 0x2ca8
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0x7c0000, %esi         # imm = 0x7C0000
callq 0x2ca8
leaq -0x168(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xbde(%rip), %rsi       # 0x41f2
leaq 0xbdf(%rip), %rdx       # 0x41fa
leaq -0x178(%rbp), %rdi
callq 0x3a38
leaq -0x178(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x178(%rbp), %rdi
cmpq %r14, %rdi
je 0x3647
callq 0x2120
movq 0x297a(%rip), %rdi      # 0x5fc8
leaq 0xbc5(%rip), %rsi       # 0x421a
movl $0x5, %edx
callq 0x2180
jmp 0x3703
movq -0x298(%rbp), %rdi
callq 0x2250
movq 0x2951(%rip), %rdi      # 0x5fc8
leaq 0xb0a(%rip), %rsi       # 0x4188
movl $0xa, %edx
callq 0x2180
movq 0x2939(%rip), %rdi      # 0x5fc8
leaq 0xafd(%rip), %rsi       # 0x4193
movl $0x2, %edx
callq 0x2180
movq 0x2921(%rip), %rdi      # 0x5fc8
movl $0x44, %esi
callq 0x2210
movq %rax, %rbx
leaq 0x94e(%rip), %rsi       # 0x4009
movl $0x2, %edx
movq %rax, %rdi
callq 0x2180
leaq 0xac7(%rip), %rsi       # 0x4196
movl $0x11, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq 0x28b6(%rip), %rax      # 0x5fc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x4b0(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x4b8(%rbp,%rcx)
callq 0x2100
leaq -0x3c0(%rbp), %rdi
callq 0x2070
leaq -0x6c0(%rbp), %rdi
callq 0x2060
leaq -0x288(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x375a
callq 0x2120
addq $0x698, %rsp            # imm = 0x698
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x198(%rbp), %rdi
jmp 0x3838
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
jmp 0x3838
jmp 0x38dd
jmp 0x38dd
movq %rax, %rbx
movq -0x1b8(%rbp), %rdi
jmp 0x3838
movq %rax, %rbx
movq -0xf8(%rbp), %rdi
jmp 0x3838
movq %rax, %rbx
movq -0x1d8(%rbp), %rdi
jmp 0x3838
movq %rax, %rbx
movq -0x118(%rbp), %rdi
jmp 0x3838
jmp 0x38dd
jmp 0x38dd
jmp 0x38dd
jmp 0x38dd
movq %rax, %rbx
movq -0x1f8(%rbp), %rdi
jmp 0x3838
movq %rax, %rbx
movq -0x138(%rbp), %rdi
jmp 0x3838
jmp 0x38dd
jmp 0x38dd
movq %rax, %rbx
movq -0x178(%rbp), %rdi
jmp 0x3838
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
jmp 0x3838
jmp 0x38dd
jmp 0x38dd
movq %rax, %rbx
movq -0x218(%rbp), %rdi
jmp 0x3838
movq %rax, %rbx
movq -0x158(%rbp), %rdi
cmpq %r14, %rdi
jne 0x38b7
jmp 0x38e0
jmp 0x38dd
jmp 0x38dd
movq %rax, %rbx
movq -0x278(%rbp), %rdi
jmp 0x38b2
jmp 0x38dd
movq %rax, %rbx
movq -0x98(%rbp), %rdi
cmpq %r15, %rdi
je 0x3876
callq 0x2120
jmp 0x3876
movq %rax, %rbx
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x3889
callq 0x2120
jmp 0x3889
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
jne 0x38b7
jmp 0x38e0
jmp 0x38dd
movq %rax, %rbx
movq -0x238(%rbp), %rdi
jmp 0x38b2
jmp 0x38dd
movq %rax, %rbx
movq -0x258(%rbp), %rdi
cmpq %r15, %rdi
je 0x38e0
callq 0x2120
jmp 0x38e0
jmp 0x38dd
movq %rax, %rbx
jmp 0x38ec
movq %rax, %rbx
jmp 0x38f8
movq %rax, %rbx
movq -0x2b8(%rbp), %rdi
cmpq %r12, %rdi
jne 0x3908
jmp 0x390d
jmp 0x38dd
movq %rax, %rbx
leaq -0x4b8(%rbp), %rdi
callq 0x21d0
leaq -0x6c0(%rbp), %rdi
callq 0x2060
leaq -0x288(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x390d
callq 0x2120
movq %rbx, %rdi
callq 0x2230
nop