// File: /workspace/github_c_makefile_star2_O3/shuffle2[P]nx2elf/nx2elf.cpp
// Function: NsoFile::Load(std::filesystem::__cxx11::path const&)
bool Load(const fs::path& path) {
    auto file = File::Read(path);
    const size_t nro_offset = ALIGN_UP(sizeof(ModPointer), 0x10);
    if (file.size() >= sizeof(NsoHeader) &&
        !memcmp(&file[0], &nso_magic[0], nso_magic.size())) {
      memcpy(&header, &file[0], sizeof(header));

      // assume segments are after each other and mem offsets are aligned
      // note: there are also symbols "_start" and "end" which describe
      // the total size.
      auto& data_seg = header.segments[kData];
      size_t image_size =
          data_seg.mem_offset + data_seg.mem_size + data_seg.bss_align;
      image = std::vector<u8>(image_size);

      for (int i = 0; i < kNumSegment; i++) {
        auto& seg = header.segments[i];
        auto& file_size = header.segment_file_sizes[i];
        if (!Decompress(&image[seg.mem_offset], seg.mem_size,
                        &file[seg.file_offset], file_size)) {
          return false;
        }
      }
      file_type = kNso;
    } else if (file.size() >= nro_offset + sizeof(NroHeader) &&
               !memcmp(&file[nro_offset], &nro_magic[0], nro_magic.size())) {
      // Translate the nro header to nso, which is a superset
      auto nro = reinterpret_cast<NroHeader*>(&file[nro_offset]);
      if (nro->file_size != file.size()) {
        return false;
      }
      for (int i = 0; i < kNumSegment; i++) {
        auto& seg = header.segments[i];
        // TODO revisit once some nso with uncompressed segments is seen
        seg.mem_offset = seg.file_offset = nro->segments[i].offset;
        seg.mem_size = header.segment_file_sizes[i] = nro->segments[i].size;
        switch (i) {
        case kText:
          seg.bss_align = 0x100;
          break;
        case kRodata:
          seg.bss_align = 1;
          break;
        case kData:
          seg.bss_align = nro->bss_size;
          break;
        }
      }
      header.gnu_build_id = nro->gnu_build_id;
      header.dynstr = nro->dynstr;
      header.dynsym = nro->dynsym;

      image = std::move(file);
      file_type = kNro;
    }

    u8* mod_base = nullptr;
    ModPointer* mod_ptr = nullptr;
    if (file_type != kUnknown) {
      mod_ptr = reinterpret_cast<ModPointer*>(&image[0]);
      if (mod_ptr->magic_offset + sizeof(ModHeader) > image.size()) {
        return false;
      }
      mod_base = &image[mod_ptr->magic_offset];
    } else if (file.size() >= sizeof(ModPointer)) {
      // It's not an NSO or NRO, but still need to check for MOD
      mod_ptr = reinterpret_cast<ModPointer*>(&file[0]);
      if (mod_ptr->magic_offset + sizeof(ModHeader) > file.size()) {
        return false;
      }
      mod_base = &file[mod_ptr->magic_offset];
    } else {
      return false;
    }
    auto mod = reinterpret_cast<ModHeader*>(mod_base);
    if (memcmp(mod->magic, &mod_magic[0], mod_magic.size()))
      return false;

    if (file_type == kUnknown) {
      // Apparently there are images which are essentially NROs, but lack
      // the NRO header, for some reason. This is a pain.
      image = std::move(file);
      file_type = kMod;
    }
    /*
    fs::path dump(path);
    File::Write(dump.replace_extension(".bin"), image);
    //*/

    auto mod_get_offset = [&](s32 relative_offset) {
      auto ptr = reinterpret_cast<u8*>(mod_base + relative_offset);
      auto offset = reinterpret_cast<uintptr_t>(ptr) -
                    reinterpret_cast<uintptr_t>(&image[0]);
      return static_cast<u32>(offset);
    };

    dynamic = reinterpret_cast<Elf64_Dyn*>(mod_base + mod->dynamic_offset);
    for (auto dyn = dynamic; dyn->d_tag; dyn++) {
#define DT_ASSIGN_U64(dt, var) \
  case dt:                     \
    dyn_info.var = dyn->d_un;  \
    break;
      switch (dyn->d_tag) {
        DT_ASSIGN_U64(DT_SYMTAB, symtab);
        DT_ASSIGN_U64(DT_RELA, rela);
        DT_ASSIGN_U64(DT_RELASZ, relasz);
        DT_ASSIGN_U64(DT_JMPREL, jmprel);
        DT_ASSIGN_U64(DT_PLTRELSZ, pltrelsz);
        DT_ASSIGN_U64(DT_STRTAB, strtab);
        DT_ASSIGN_U64(DT_STRSZ, strsz);
        DT_ASSIGN_U64(DT_PLTGOT, pltgot);
        DT_ASSIGN_U64(DT_HASH, hash);
        DT_ASSIGN_U64(DT_GNU_HASH, gnu_hash);
        DT_ASSIGN_U64(DT_INIT, init);
        DT_ASSIGN_U64(DT_FINI, fini);
        DT_ASSIGN_U64(DT_INIT_ARRAY, init_array);
        DT_ASSIGN_U64(DT_INIT_ARRAYSZ, init_arraysz);
        DT_ASSIGN_U64(DT_FINI_ARRAY, fini_array);
        DT_ASSIGN_U64(DT_FINI_ARRAYSZ, fini_arraysz);
      }
#undef DT_ASSIGN_U64
    }
    if (file_type != kMod) {
      auto& text_seg = header.segments[kText];
      ResolvePlt(&image[text_seg.mem_offset], text_seg.mem_size);
    }

    if (file_type == kMod) {
      // need to manually build them ...
      DataExtent segments[kNumSegment]{};

      // XXX hacks...
      if (!ResolvePlt(&image[0], image.size())) {
        fputs("error: raw MOD requires .plt. please report this.\n", stderr);
        return false;
      }
      if (dyn_info.symtab >= dyn_info.strtab) {
        fputs(
            "error: raw MOD requires .dynstr directly after .dynsym. please "
            "report this.\n",
            stderr);
        return false;
      }
      // Need this up-front to be able to iter_dynsym
      header.dynsym.size = static_cast<u32>(dyn_info.strtab - dyn_info.symtab);
      // yet another dirty hack. relies on all sections having at least
      // one symbol pointing into them, and a section symbol existing for .data
      std::vector<u16> seen_shndx;
      iter_dynsym([&](const Elf64_Sym& sym, u32) {
        if (sym.st_shndx == SHN_UNDEF || sym.st_shndx >= SHN_LORESERVE) {
          return;
        }
        seen_shndx.push_back(sym.st_shndx);
      });
      std::sort(seen_shndx.begin(), seen_shndx.end());
      seen_shndx.erase(std::unique(seen_shndx.begin(), seen_shndx.end()),
                       seen_shndx.end());
      if (seen_shndx.size() != kNumSegment + 1) {
        fputs(
            "error: raw MOD failed to find .data in .dynsym. please report "
            "this.\n",
            stderr);
        return false;
      }
      iter_dynsym([&](const Elf64_Sym& sym, u32) {
        if (segments[kData].offset == 0 &&
            ELF64_ST_TYPE(sym.st_info) == STT_SECTION &&
            sym.st_shndx == seen_shndx[kData]) {
          segments[kData].offset = static_cast<u32>(sym.st_value);
        }
      });
      if (segments[kData].offset == 0) {
        fputs(
            "error: raw MOD failed to find .data in .dynsym. please report "
            "this.\n",
            stderr);
        return false;
      }

      segments[kText].offset = 0;
      segments[kText].size = static_cast<u32>(plt_info.addr + plt_info.size);
      segments[kRodata].offset =
          ALIGN_UP(segments[kText].offset + segments[kText].size, 0x1000);
      segments[kRodata].size =
          segments[kData].offset - segments[kRodata].offset;
      segments[kData].size =
          static_cast<u32>(image.size() - segments[kData].offset);

      header.dynstr.offset =
          static_cast<u32>(dyn_info.strtab - segments[kRodata].offset);
      header.dynstr.size = static_cast<u32>(dyn_info.strsz);
      header.dynsym.offset =
          static_cast<u32>(dyn_info.symtab - segments[kRodata].offset);

      for (int i = 0; i < kNumSegment; i++) {
        auto& seg = header.segments[i];
        seg.mem_offset = seg.file_offset = segments[i].offset;
        seg.mem_size = header.segment_file_sizes[i] = segments[i].size;
        switch (i) {
        case kText:
          seg.bss_align = 0x100;
          break;
        case kRodata:
          seg.bss_align = 1;
          break;
        case kData:
          // This is the actual size cleared by init code, but there
          // is a symbol named "end" which will be referenced and is
          // at the aligned boundary. So pad it out until there.
          // This is debatably a bug in nintendo's tools.
          seg.bss_align = mod_get_offset(mod->bss_end_offset) -
                          mod_get_offset(mod->bss_start_offset);
          seg.bss_align = ALIGN_UP(seg.bss_align, 0x1000) + 1;
          break;
        }
      }
    }

    // Kinda gross, but hopefully unique enough to avoid false positives...
    const GnuBuildId md5_build_id_needle = {
        {sizeof(GnuBuildId::owner), sizeof(GnuBuildId::build_id_md5), 3},
        {'G', 'N', 'U'}};
    const GnuBuildId sha1_build_id_needle = {
        {sizeof(GnuBuildId::owner), sizeof(GnuBuildId::build_id_sha1), 3},
        {'G', 'N', 'U'}};
    for (auto i : {kRodata, kText, kData}) {
      auto& seg = header.segments[i];
      note = reinterpret_cast<Elf64_Nhdr*>(
          memmemr(&image[seg.mem_offset], seg.mem_size, &md5_build_id_needle,
                  offsetof(GnuBuildId, build_id_md5)));
      if (note) {
        break;
      }
      note = reinterpret_cast<Elf64_Nhdr*>(
          memmemr(&image[seg.mem_offset], seg.mem_size, &sha1_build_id_needle,
                  offsetof(GnuBuildId, build_id_sha1)));
      if (note) {
        break;
      }
    }

    // In case of MOD-only file, we can only fill in build id if the section was
    // found manually
    if (file_type == kMod && note) {
      auto build_id = reinterpret_cast<const GnuBuildId*>(note);
      memcpy(header.gnu_build_id.data(), build_id->build_id_raw.data(),
             build_id->header.n_descsz);
    }

    eh_info.hdr_addr = mod_get_offset(mod->eh_start_offset);
    eh_info.hdr_size = mod_get_offset(mod->eh_end_offset) - eh_info.hdr_addr;

    return true;
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %rbx
movq %rdi, %r15
leaq -0xb0(%rbp), %r14
movl $0x0, (%r14)
callq 0x2100
movq %rax, 0x8(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21f0
cmpq $-0x1, %rax
je 0xc204
leaq -0x70(%rbp), %rdi
leaq -0x80(%rbp), %rdx
movq %rax, %rsi
callq 0xf556
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
leaq 0x9043(%rip), %rcx      # 0x151f9
leaq -0x80(%rbp), %rdi
callq 0xbf84
movq -0x80(%rbp), %r13
testq %r13, %r13
je 0xc20e
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
subq %rdi, %rsi
movl $0x1, %edx
movq %r13, %rcx
callq 0x2250
testq %rax, %rax
je 0xc218
movq -0x70(%rbp), %r12
movq -0x68(%rbp), %r14
movq -0x60(%rbp), %rbx
pxor %xmm0, %xmm0
movdqa %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
jmp 0xc220
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0xc23d
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0xc228
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r12d, %r12d
movq %r13, %rdi
callq 0x2190
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0xc23d
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %r14, %rax
subq %r12, %rax
cmpq $0x100, %rax            # imm = 0x100
jb 0xc339
cmpl $0x304f534e, (%r12)     # imm = 0x304F534E
jne 0xc341
leaq 0x4(%r15), %rdi
movl $0x100, %edx            # imm = 0x100
movq %r12, %rsi
callq 0x2160
movl 0x3c(%r15), %esi
addl 0x38(%r15), %esi
addl 0x40(%r15), %esi
leaq -0x70(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
movq %rbx, -0x38(%rbp)
callq 0xf556
movq 0x108(%r15), %rdi
movq 0x118(%r15), %rsi
movq -0x70(%rbp), %rax
movq %rax, 0x108(%r15)
movq -0x68(%rbp), %rax
movq %rax, 0x110(%r15)
movq -0x60(%rbp), %rax
movq %rax, 0x118(%r15)
pxor %xmm0, %xmm0
movdqa %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
testq %rdi, %rdi
je 0xc2f0
subq %rdi, %rsi
callq 0x21b0
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0xc2f0
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x21b0
xorl %ebx, %ebx
movl 0x18(%r15,%rbx,4), %esi
addq 0x108(%r15), %rsi
movl 0x14(%r15,%rbx,4), %ecx
movl 0x1c(%r15,%rbx,4), %edx
addq %r12, %rcx
movl 0x64(%r15,%rbx), %r8d
movq %r15, %rdi
callq 0xf5c0
testb %al, %al
je 0xc798
addq $0x4, %rbx
cmpq $0xc, %rbx
jne 0xc2f2
movl $0x1, %r13d
movq -0x38(%rbp), %rbx
jmp 0xc45a
cmpq $0x80, %rax
jb 0xc34c
cmpl $0x304f524e, 0x10(%r12) # imm = 0x304F524E
je 0xc38c
movl (%r15), %r13d
testl %r13d, %r13d
jne 0xc45d
cmpq $0x8, %rax
jb 0xc483
movq %rbx, %rdx
movl 0x4(%r12), %ebx
leaq 0x1c(%rbx), %rcx
cmpq %rax, %rcx
ja 0xc381
cmpl $0x30444f4d, (%r12,%rbx) # imm = 0x30444F4D
je 0xc7ad
xorl %r13d, %r13d
movq %rdx, %rbx
jmp 0xc48b
movl 0x18(%r12), %ecx
xorl %r13d, %r13d
cmpq %rcx, %rax
jne 0xc48b
xorl %eax, %eax
movl 0x20(%r12,%rax,2), %ecx
movl %ecx, 0x14(%r15,%rax,4)
movl %ecx, 0x18(%r15,%rax,4)
movl 0x24(%r12,%rax,2), %ecx
movl %ecx, 0x64(%r15,%rax)
movl %ecx, 0x1c(%r15,%rax,4)
testl %r13d, %r13d
je 0xc3cf
cmpl $0x2, %r13d
jne 0xc3d6
movl 0x38(%r12), %ecx
jmp 0xc3db
movl $0x100, %ecx            # imm = 0x100
jmp 0xc3db
movl $0x1, %ecx
movl %ecx, 0x20(%r15,%rax,4)
incl %r13d
addq $0x4, %rax
cmpq $0xc, %rax
jne 0xc39f
movdqu 0x40(%r12), %xmm0
movdqu 0x50(%r12), %xmm1
movdqu %xmm1, 0x54(%r15)
movdqu %xmm0, 0x44(%r15)
movq 0x70(%r12), %rax
movq %rax, 0x94(%r15)
movq 0x78(%r12), %rax
movq %rax, 0x9c(%r15)
movq 0x108(%r15), %rdi
movq 0x118(%r15), %rsi
movq %r12, 0x108(%r15)
movq %r14, 0x110(%r15)
movq %rbx, 0x118(%r15)
movl $0x2, %r13d
testq %rdi, %rdi
je 0xc455
subq %rdi, %rsi
callq 0x21b0
xorl %r12d, %r12d
xorl %ebx, %ebx
movl %r13d, (%r15)
movq 0x108(%r15), %rsi
movq 0x110(%r15), %rcx
movl 0x4(%rsi), %eax
leaq 0x1c(%rax), %rdx
subq %rsi, %rcx
cmpq %rcx, %rdx
ja 0xc483
cmpl $0x30444f4d, (%rsi,%rax) # imm = 0x30444F4D
je 0xc4ae
xorl %r13d, %r13d
testq %r12, %r12
je 0xc499
subq %r12, %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x21b0
movl %r13d, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, -0x74(%rbp)
movq %rbx, -0x38(%rbp)
movq %r12, -0x30(%rbp)
addq %rax, %rsi
movslq 0x4(%rsi), %rax
leaq (%rsi,%rax), %rcx
movq %rcx, 0x120(%r15)
leaq 0x1a8(%r15), %rcx
movq %rcx, -0xf0(%rbp)
leaq 0x1a0(%r15), %rcx
movq %rcx, -0xe8(%rbp)
leaq 0x198(%r15), %rcx
movq %rcx, -0xe0(%rbp)
leaq 0x190(%r15), %rcx
movq %rcx, -0xd8(%rbp)
leaq 0x188(%r15), %rcx
movq %rcx, -0xd0(%rbp)
leaq 0x180(%r15), %rcx
movq %rcx, -0xc8(%rbp)
leaq 0x178(%r15), %r9
leaq 0x170(%r15), %r10
leaq 0x168(%r15), %r11
leaq 0x160(%r15), %rdi
leaq 0x158(%r15), %rcx
movq %rcx, -0xc0(%rbp)
leaq 0x150(%r15), %rbx
movq %rsi, -0xb8(%rbp)
leaq 0x8(%rsi,%rax), %r13
leaq 0x148(%r15), %rax
leaq 0x140(%r15), %rcx
leaq 0x138(%r15), %rdx
leaq 0x130(%r15), %r14
leaq 0x8ad0(%rip), %rsi      # 0x15050
jmp 0xc5fc
movq %rbx, %r12
jmp 0xc5f0
movq %r9, %r12
cmpq $0x6ffffef5, %r8        # imm = 0x6FFFFEF5
je 0xc5f0
jmp 0xc5f8
movq -0xd0(%rbp), %r12
jmp 0xc5f0
movq -0xc8(%rbp), %r12
jmp 0xc5f0
movq %r10, %r12
jmp 0xc5f0
movq -0xc0(%rbp), %r12
jmp 0xc5f0
movq %r11, %r12
jmp 0xc5f0
movq %rdx, %r12
jmp 0xc5f0
movq %rdi, %r12
jmp 0xc5f0
movq -0xd8(%rbp), %r12
jmp 0xc5f0
movq %rcx, %r12
jmp 0xc5f0
movq -0xe8(%rbp), %r12
jmp 0xc5f0
movq %rax, %r12
jmp 0xc5f0
movq -0xf0(%rbp), %r12
jmp 0xc5f0
movq -0xe0(%rbp), %r12
movq (%r13), %r8
movq %r8, (%r12)
addq $0x10, %r13
movq -0x8(%r13), %r8
cmpq $0x1c, %r8
ja 0xc587
movslq (%rsi,%r8,4), %r8
addq %rsi, %r8
movq %r14, %r12
jmpq *%r8
cmpl $0x3, -0x74(%rbp)
movq -0x30(%rbp), %r12
movq -0x38(%rbp), %rbx
je 0xc642
movl 0x18(%r15), %esi
movl 0x1c(%r15), %edx
addq 0x108(%r15), %rsi
movq %r15, %rdi
callq 0xf5fc
cmpl $0x3, (%r15)
jne 0xc981
pxor %xmm0, %xmm0
movdqa %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq 0x108(%r15), %rsi
movq 0x110(%r15), %rdx
subq %rsi, %rdx
movq %r15, %rdi
callq 0xf5fc
testb %al, %al
je 0xcb12
movq (%r14), %rax
movq -0xc0(%rbp), %rcx
movq (%rcx), %rcx
cmpq %rax, %rcx
jbe 0xcb1b
subl %eax, %ecx
movl %ecx, 0xa0(%r15)
xorl %eax, %eax
movq %rax, -0xa0(%rbp)
pxor %xmm0, %xmm0
movdqa %xmm0, -0xb0(%rbp)
leaq -0x130(%rbp), %rsi
movq %rax, 0x8(%rsi)
leaq -0xb0(%rbp), %r14
movq %r14, (%rsi)
leaq 0x307e(%rip), %rax      # 0xf742
movq %rax, 0x18(%rsi)
leaq 0x307d(%rip), %rax      # 0xf74c
movq %rax, 0x10(%rsi)
movq %r15, %rdi
callq 0xf68e
movq -0x120(%rbp), %rax
testq %rax, %rax
je 0xc6f8
leaq -0x130(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0xb0(%rbp), %r13
movq -0xa8(%rbp), %r12
cmpq %r12, %r13
je 0xc7a4
movq %r12, %rax
subq %r13, %rax
sarq %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0xf8f5
movq %r13, %rdi
movq %r12, %rsi
callq 0xf9ec
movq -0xb0(%rbp), %r13
movq -0xa8(%rbp), %rax
cmpq %rax, %r13
movq -0x30(%rbp), %r12
je 0xc819
leaq 0x2(%r13), %rcx
cmpq %rax, %rcx
je 0xc819
movzwl -0x2(%rcx), %edx
leaq 0x2(%rcx), %rsi
cmpw (%rcx), %dx
movq %rsi, %rcx
jne 0xc75a
leaq -0x4(%rsi), %rcx
cmpq %rax, %rsi
je 0xc806
movl %edx, %edi
movzwl (%rsi), %edx
cmpw %dx, %di
je 0xc792
movw %dx, 0x2(%rcx)
addq $0x2, %rcx
addq $0x2, %rsi
jmp 0xc777
xorl %r13d, %r13d
movq -0x38(%rbp), %rbx
jmp 0xc486
movq %r13, %rax
movq -0x30(%rbp), %r12
jmp 0xc819
movq 0x108(%r15), %rdi
movq 0x118(%r15), %rsi
movq %r12, 0x108(%r15)
movq %r14, 0x110(%r15)
movq %rdx, 0x118(%r15)
testq %rdi, %rdi
je 0xc7dd
subq %rdi, %rsi
callq 0x21b0
addq %rbx, %r12
movl $0x3, (%r15)
movl $0x3, -0x74(%rbp)
movq $0x0, -0x38(%rbp)
movq %r12, %rsi
movq $0x0, -0x30(%rbp)
jmp 0xc4bd
addq $0x2, %rcx
cmpq %rax, %rcx
je 0xc819
movq %rcx, -0xa8(%rbp)
movq %rcx, %rax
subq %r13, %rax
cmpq $0x8, %rax
jne 0xcafd
leaq -0x70(%rbp), %rax
leaq -0x110(%rbp), %rsi
movq %rax, (%rsi)
movq %r14, 0x8(%rsi)
leaq 0x3459(%rip), %rax      # 0xfc98
movq %rax, 0x18(%rsi)
leaq 0x3480(%rip), %rax      # 0xfcca
movq %rax, 0x10(%rsi)
movq %r15, %rdi
callq 0xf68e
movq -0x100(%rbp), %rax
testq %rax, %rax
je 0xc873
leaq -0x110(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movl -0x60(%rbp), %eax
testl %eax, %eax
je 0xcafd
movl $0x0, -0x70(%rbp)
movl 0x1b0(%r15), %ecx
movl 0x1b8(%r15), %edx
leal (%rdx,%rcx), %esi
movl %esi, -0x6c(%rbp)
addl %edx, %ecx
addl $0xfff, %ecx            # imm = 0xFFF
andl $0xfffff000, %ecx       # imm = 0xFFFFF000
movl %ecx, -0x68(%rbp)
movl %eax, %edx
subl %ecx, %edx
movl %edx, -0x64(%rbp)
movl 0x110(%r15), %edx
movq 0x108(%r15), %rsi
subl %esi, %edx
subl %eax, %edx
movl %edx, -0x5c(%rbp)
movl 0x130(%r15), %eax
movl 0x158(%r15), %edx
subl %ecx, %edx
movl %edx, 0x94(%r15)
movl 0x160(%r15), %edx
movl %edx, 0x98(%r15)
subl %ecx, %eax
movl %eax, 0x9c(%r15)
xorl %eax, %eax
xorl %ecx, %ecx
movq -0xb8(%rbp), %rdi
movl -0x70(%rbp,%rax,2), %edx
movl %edx, 0x14(%r15,%rax,4)
movl %edx, 0x18(%r15,%rax,4)
movl -0x6c(%rbp,%rax,2), %edx
movl %edx, 0x64(%r15,%rax)
movl %edx, 0x1c(%r15,%rax,4)
cmpl $0x2, %ecx
je 0xc930
cmpl $0x1, %ecx
jne 0xc951
movl $0x1, 0x20(%r15,%rax,4)
jmp 0xc95a
movl 0xc(%rdi), %edx
addl %edi, %edx
movl 0x8(%rdi), %esi
addl %edi, %esi
subl %esi, %edx
addl $0xfff, %edx            # imm = 0xFFF
andl $0xfffff000, %edx       # imm = 0xFFFFF000
incl %edx
movl %edx, 0x20(%r15,%rax,4)
jmp 0xc95a
movl $0x100, 0x20(%r15,%rax,4) # imm = 0x100
incl %ecx
addq $0x4, %rax
cmpq $0xc, %rax
jne 0xc8ff
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0xc981
movq -0xa0(%rbp), %rsi
subq %rdi, %rsi
callq 0x21b0
pxor %xmm0, %xmm0
movdqu %xmm0, -0x64(%rbp)
xorl %ecx, %ecx
movl %ecx, -0x44(%rbp)
movdqu %xmm0, -0x54(%rbp)
movabsq $0x1000000004, %rax     # imm = 0x1000000004
movq %rax, -0x70(%rbp)
movl $0x3, %eax
movl %eax, -0x68(%rbp)
movw $0x4e47, %dx            # imm = 0x4E47
movw %dx, -0x64(%rbp)
movb $0x55, %sil
movb %sil, -0x62(%rbp)
movdqu %xmm0, -0xa4(%rbp)
movl %ecx, -0x84(%rbp)
movdqu %xmm0, -0x94(%rbp)
movabsq $0x1400000004, %rdi     # imm = 0x1400000004
movq %rdi, -0xb0(%rbp)
movl %eax, -0xa8(%rbp)
movw %dx, -0xa4(%rbp)
movb %sil, -0xa2(%rbp)
movq $0x1, -0x80(%rbp)
movl $0x2, -0x78(%rbp)
leaq 0x14(%r15), %rdx
movq 0x108(%r15), %rax
movq -0xb8(%rbp), %r14
movl -0x80(%rbp,%rcx), %esi
shlq $0x4, %rsi
movl 0x4(%rdx,%rsi), %edi
movl 0x8(%rdx,%rsi), %esi
addq %rax, %rdi
leaq (%rsi,%rdi), %r8
addq $-0x10, %r8
movq %r8, %rsi
cmpq %rdi, %r8
jae 0xca5a
movq $0x0, 0x128(%r15)
movq $0x0, 0x128(%r15)
addq $0x4, %rcx
cmpq $0xc, %rcx
jne 0xca15
jmp 0xcad2
movdqu (%rsi), %xmm0
pcmpeqb -0x70(%rbp), %xmm0
pmovmskb %xmm0, %r9d
cmpl $0xffff, %r9d           # imm = 0xFFFF
je 0xcaae
decq %rsi
cmpq %rdi, %rsi
jae 0xca5a
movq $0x0, 0x128(%r15)
movdqu -0xb0(%rbp), %xmm0
movdqu (%r8), %xmm1
pcmpeqb %xmm0, %xmm1
pmovmskb %xmm1, %esi
cmpl $0xffff, %esi           # imm = 0xFFFF
je 0xcaab
decq %r8
cmpq %rdi, %r8
jae 0xca8c
jmp 0xca43
movq %r8, %rsi
movq %rsi, 0x128(%r15)
cmpl $0x3, (%r15)
jne 0xcad2
leaq 0x44(%r15), %rdi
movl 0x4(%rsi), %edx
addq $0x10, %rsi
callq 0x2160
movq 0x108(%r15), %rax
movl 0x10(%r14), %ecx
addl %r14d, %ecx
subl %eax, %ecx
movq %rcx, 0x1c0(%r15)
movl 0x14(%r14), %edx
addl %r14d, %edx
subl %eax, %edx
subq %rcx, %rdx
movq %rdx, 0x1c8(%r15)
movb $0x1, %r13b
jmp 0xc486
leaq -0xb0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x22fc
jmp 0xc483
leaq 0x861b(%rip), %rdi      # 0x15134
jmp 0xcb22
leaq 0x8645(%rip), %rdi      # 0x15167
movq 0xc4af(%rip), %rax      # 0x18fd8
movq (%rax), %rsi
callq 0x21c0
jmp 0xc483
jmp 0xcb85
jmp 0xcb85
jmp 0xcbce
movq %rax, %r15
movq -0x100(%rbp), %rax
testq %rax, %rax
je 0xcb92
leaq -0x110(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xcb92
jmp 0xcb85
movq %rax, %r15
movq -0x120(%rbp), %rax
testq %rax, %rax
je 0xcb92
leaq -0x130(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xcb92
movq %rax, %rdi
callq 0xc0db
jmp 0xcbce
movq %rax, %r15
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0xcbd1
movq -0xa0(%rbp), %rsi
subq %rdi, %rsi
callq 0x21b0
jmp 0xcbd1
movq %r12, -0x30(%rbp)
movq %rax, %r15
jmp 0xcbd8
movq %rax, %r15
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0xcbe8
movq -0x60(%rbp), %rsi
jmp 0xcbe0
movq %r12, -0x30(%rbp)
movq %rax, %r15
cmpq $0x0, -0x30(%rbp)
je 0xcbe8
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %r15, %rdi
callq 0x2280