// File: /workspace/github_cpp_makefile_star2_O3/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 0x3a3c
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 0x3a3c
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 0x3a3c
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 0x3984
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 0x3429
cmpq $0x10000000, %rbx       # imm = 0x10000000
jne 0x3668
leaq -0x148(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xfdd(%rip), %rsi       # 0x41fb
leaq 0xfdd(%rip), %rdx       # 0x4202
leaq -0x158(%rbp), %rdi
callq 0x3a3c
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
movb 0x18(%r12), %al
testb $0x1, %al
je 0x332c
leaq -0x128(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xf17(%rip), %rsi       # 0x41af
leaq 0xf1e(%rip), %rdx       # 0x41bd
leaq -0x138(%rbp), %rdi
callq 0x3a3c
leaq -0x138(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x138(%rbp), %rdi
cmpq %r14, %rdi
je 0x32cb
callq 0x2120
leaq -0x108(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xf26(%rip), %rsi       # 0x4203
leaq 0xf2b(%rip), %rdx       # 0x420f
leaq -0x118(%rbp), %rdi
callq 0x3a3c
leaq -0x118(%rbp), %rsi
movq %r12, %rdi
movl -0x2c(%rbp), %edx
callq 0x2ac6
movq -0x118(%rbp), %rdi
cmpq %r14, %rdi
je 0x3313
callq 0x2120
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0x40000, %esi          # imm = 0x40000
callq 0x2ca8
movb 0x18(%r12), %al
testb $0x2, %al
je 0x33e9
leaq -0xe8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xe84(%rip), %rsi       # 0x41ca
leaq 0xe97(%rip), %rdx       # 0x41e4
leaq -0xf8(%rbp), %rdi
callq 0x3a3c
leaq -0xf8(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0xf8(%rbp), %rdi
cmpq %r14, %rdi
je 0x3379
callq 0x2120
leaq -0xc8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xe5a(%rip), %rsi       # 0x41e5
leaq 0xe5f(%rip), %rdx       # 0x41f1
leaq -0xd8(%rbp), %rdi
callq 0x3a3c
leaq -0xd8(%rbp), %rsi
movq %r12, %rdi
movl -0x2c(%rbp), %edx
callq 0x2ac6
movq -0xd8(%rbp), %rdi
cmpq %r14, %rdi
je 0x33c1
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 0xe15(%rip), %rsi       # 0x4210
leaq 0xe17(%rip), %rdx       # 0x4219
leaq -0xb8(%rbp), %rdi
callq 0x3a3c
leaq -0xb8(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0xb8(%rbp), %rdi
jmp 0x3641
leaq -0x208(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xd6d(%rip), %rsi       # 0x41a8
leaq 0xd6c(%rip), %rdx       # 0x41ae
leaq -0x218(%rbp), %rdi
callq 0x3a3c
leaq -0x218(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x218(%rbp), %rdi
cmpq %r14, %rdi
je 0x346e
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
movb 0x18(%r12), %al
testb $0x1, %al
je 0x3549
leaq -0x1e8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xcfa(%rip), %rsi       # 0x41af
leaq 0xd01(%rip), %rdx       # 0x41bd
leaq -0x1f8(%rbp), %rdi
callq 0x3a3c
leaq -0x1f8(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x1f8(%rbp), %rdi
cmpq %r14, %rdi
je 0x34e8
callq 0x2120
leaq -0x1c8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xcc4(%rip), %rsi       # 0x41be
leaq 0xcc8(%rip), %rdx       # 0x41c9
leaq -0x1d8(%rbp), %rdi
callq 0x3a3c
leaq -0x1d8(%rbp), %rsi
movq %r12, %rdi
movl -0x2c(%rbp), %edx
callq 0x2ac6
movq -0x1d8(%rbp), %rdi
cmpq %r14, %rdi
je 0x3530
callq 0x2120
leaq -0x4b8(%rbp), %rdx
movq %r12, %rdi
movl $0x40000, %esi          # imm = 0x40000
callq 0x2ca8
movb 0x18(%r12), %al
testb $0x2, %al
je 0x3606
leaq -0x1a8(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xc67(%rip), %rsi       # 0x41ca
leaq 0xc7a(%rip), %rdx       # 0x41e4
leaq -0x1b8(%rbp), %rdi
callq 0x3a3c
leaq -0x1b8(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x1b8(%rbp), %rdi
cmpq %r14, %rdi
je 0x3596
callq 0x2120
leaq -0x188(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xc3d(%rip), %rsi       # 0x41e5
leaq 0xc42(%rip), %rdx       # 0x41f1
leaq -0x198(%rbp), %rdi
callq 0x3a3c
leaq -0x198(%rbp), %rsi
movq %r12, %rdi
movl -0x2c(%rbp), %edx
callq 0x2ac6
movq -0x198(%rbp), %rdi
cmpq %r14, %rdi
je 0x35de
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 0xbda(%rip), %rsi       # 0x41f2
leaq 0xbdb(%rip), %rdx       # 0x41fa
leaq -0x178(%rbp), %rdi
callq 0x3a3c
leaq -0x178(%rbp), %rsi
movq %r12, %rdi
callq 0x2a72
movq -0x178(%rbp), %rdi
cmpq %r14, %rdi
je 0x364b
callq 0x2120
movq 0x2976(%rip), %rdi      # 0x5fc8
leaq 0xbc1(%rip), %rsi       # 0x421a
movl $0x5, %edx
callq 0x2180
jmp 0x3707
movq -0x298(%rbp), %rdi
callq 0x2250
movq 0x294d(%rip), %rdi      # 0x5fc8
leaq 0xb06(%rip), %rsi       # 0x4188
movl $0xa, %edx
callq 0x2180
movq 0x2935(%rip), %rdi      # 0x5fc8
leaq 0xaf9(%rip), %rsi       # 0x4193
movl $0x2, %edx
callq 0x2180
movq 0x291d(%rip), %rdi      # 0x5fc8
movl $0x44, %esi
callq 0x2210
movq %rax, %rbx
leaq 0x94a(%rip), %rsi       # 0x4009
movl $0x2, %edx
movq %rax, %rdi
callq 0x2180
leaq 0xac3(%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 0x28b2(%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 0x375e
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 0x383c
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
jmp 0x383c
jmp 0x38e1
jmp 0x38e1
movq %rax, %rbx
movq -0x1b8(%rbp), %rdi
jmp 0x383c
movq %rax, %rbx
movq -0xf8(%rbp), %rdi
jmp 0x383c
movq %rax, %rbx
movq -0x1d8(%rbp), %rdi
jmp 0x383c
movq %rax, %rbx
movq -0x118(%rbp), %rdi
jmp 0x383c
jmp 0x38e1
jmp 0x38e1
jmp 0x38e1
jmp 0x38e1
movq %rax, %rbx
movq -0x1f8(%rbp), %rdi
jmp 0x383c
movq %rax, %rbx
movq -0x138(%rbp), %rdi
jmp 0x383c
jmp 0x38e1
jmp 0x38e1
movq %rax, %rbx
movq -0x178(%rbp), %rdi
jmp 0x383c
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
jmp 0x383c
jmp 0x38e1
jmp 0x38e1
movq %rax, %rbx
movq -0x218(%rbp), %rdi
jmp 0x383c
movq %rax, %rbx
movq -0x158(%rbp), %rdi
cmpq %r14, %rdi
jne 0x38bb
jmp 0x38e4
jmp 0x38e1
jmp 0x38e1
movq %rax, %rbx
movq -0x278(%rbp), %rdi
jmp 0x38b6
jmp 0x38e1
movq %rax, %rbx
movq -0x98(%rbp), %rdi
cmpq %r15, %rdi
je 0x387a
callq 0x2120
jmp 0x387a
movq %rax, %rbx
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x388d
callq 0x2120
jmp 0x388d
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
jne 0x38bb
jmp 0x38e4
jmp 0x38e1
movq %rax, %rbx
movq -0x238(%rbp), %rdi
jmp 0x38b6
jmp 0x38e1
movq %rax, %rbx
movq -0x258(%rbp), %rdi
cmpq %r15, %rdi
je 0x38e4
callq 0x2120
jmp 0x38e4
jmp 0x38e1
movq %rax, %rbx
jmp 0x38f0
movq %rax, %rbx
jmp 0x38fc
movq %rax, %rbx
movq -0x2b8(%rbp), %rdi
cmpq %r12, %rdi
jne 0x390c
jmp 0x3911
jmp 0x38e1
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 0x3911
callq 0x2120
movq %rbx, %rdi
callq 0x2230
nop