// File: /workspace/github_c_makefile_star2_O0/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
subq $0x390, %rsp            # imm = 0x390
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x280(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x2e10
movq $0x10, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x8f50
cmpq $0x100, %rax            # imm = 0x100
jb 0x433b
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8f70
movq %rax, -0x290(%rbp)
leaq 0x63fc9(%rip), %rdi     # 0x6810c
xorl %eax, %eax
movl %eax, %esi
callq 0x8f90
movq %rax, -0x288(%rbp)
leaq 0x63fb2(%rip), %rdi     # 0x6810c
callq 0x8fc0
movq -0x290(%rbp), %rdi
movq -0x288(%rbp), %rsi
movq %rax, %rdx
callq 0x2140
cmpl $0x0, %eax
jne 0x433b
movq -0x280(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x2a8(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x8f70
movq -0x2a8(%rbp), %rdi
movq %rax, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x21f0
movq -0x280(%rbp), %rax
addq $0x34, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movl 0x4(%rcx), %eax
movl 0x8(%rcx), %edx
addl %edx, %eax
movl 0xc(%rcx), %ecx
addl %ecx, %eax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x2a0(%rbp)
leaq -0x61(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x8fd0
movq -0x2a0(%rbp), %rsi
movq -0x298(%rbp), %rdx
leaq -0x60(%rbp), %rdi
callq 0x8ff0
jmp 0x4209
movq -0x280(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
leaq -0x60(%rbp), %rsi
callq 0x9060
leaq -0x60(%rbp), %rdi
callq 0x9090
leaq -0x61(%rbp), %rdi
callq 0x90f0
movl $0x0, -0x78(%rbp)
cmpl $0x3, -0x78(%rbp)
jge 0x4329
movq -0x280(%rbp), %rdi
movslq -0x78(%rbp), %rax
shlq $0x4, %rax
leaq 0x14(%rdi,%rax), %rax
movq %rax, -0x80(%rbp)
movslq -0x78(%rbp), %rax
leaq 0x64(%rdi,%rax,4), %rax
movq %rax, -0x88(%rbp)
addq $0x108, %rdi            # imm = 0x108
movq -0x80(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
callq 0x8f70
movq %rax, -0x2b8(%rbp)
movq -0x80(%rbp), %rcx
movl (%rcx), %eax
movl 0x8(%rcx), %ecx
movl %ecx, -0x2b0(%rbp)
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x8f70
movq -0x280(%rbp), %rdi
movq -0x2b8(%rbp), %rsi
movl -0x2b0(%rbp), %edx
movq %rax, %rcx
movq -0x88(%rbp), %rax
movl (%rax), %r8d
callq 0x9110
movb %al, -0x2a9(%rbp)
jmp 0x42cf
movb -0x2a9(%rbp), %al
testb $0x1, %al
jne 0x4319
jmp 0x42db
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x53e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x90f0
jmp 0x53fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x53fa
jmp 0x431b
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x4239
movq -0x280(%rbp), %rax
movl $0x1, (%rax)
jmp 0x4559
leaq -0x30(%rbp), %rdi
callq 0x8f50
cmpq $0x80, %rax
jb 0x4557
leaq -0x30(%rbp), %rdi
movl $0x10, %esi
callq 0x8f70
movq %rax, -0x2c8(%rbp)
leaq 0x63da4(%rip), %rdi     # 0x68110
xorl %eax, %eax
movl %eax, %esi
callq 0x8f90
movq %rax, -0x2c0(%rbp)
leaq 0x63d8d(%rip), %rdi     # 0x68110
callq 0x8fc0
movq -0x2c8(%rbp), %rdi
movq -0x2c0(%rbp), %rsi
movq %rax, %rdx
callq 0x2140
cmpl $0x0, %eax
jne 0x4557
leaq -0x30(%rbp), %rdi
movl $0x10, %esi
callq 0x8f70
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x2d0(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x8f50
movq %rax, %rcx
movq -0x2d0(%rbp), %rax
cmpq %rcx, %rax
je 0x43f8
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x53e3
movl $0x0, -0x9c(%rbp)
cmpl $0x3, -0x9c(%rbp)
jge 0x44e8
movq -0x280(%rbp), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x4, %rcx
leaq 0x14(%rax,%rcx), %rcx
movq %rcx, -0xa8(%rbp)
movq -0x98(%rbp), %rcx
movslq -0x9c(%rbp), %rdx
movl 0x10(%rcx,%rdx,8), %edx
movq -0xa8(%rbp), %rcx
movl %edx, (%rcx)
movq -0xa8(%rbp), %rcx
movl %edx, 0x4(%rcx)
movq -0x98(%rbp), %rcx
movslq -0x9c(%rbp), %rdx
movl 0x14(%rcx,%rdx,8), %ecx
movl %ecx, 0x64(%rax,%rdx,4)
movq -0xa8(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x9c(%rbp), %eax
movl %eax, -0x2d4(%rbp)
testl %eax, %eax
je 0x449e
jmp 0x4484
movl -0x2d4(%rbp), %eax
subl $0x1, %eax
je 0x44ae
jmp 0x4491
movl -0x2d4(%rbp), %eax
subl $0x2, %eax
je 0x44be
jmp 0x44d2
movq -0xa8(%rbp), %rax
movl $0x100, 0xc(%rax)       # imm = 0x100
jmp 0x44d2
movq -0xa8(%rbp), %rax
movl $0x1, 0xc(%rax)
jmp 0x44d2
movq -0x98(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0xa8(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x44d4
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x4402
movq -0x280(%rbp), %rdi
movq -0x98(%rbp), %rax
movq 0x30(%rax), %rcx
movq %rcx, 0x44(%rdi)
movq 0x38(%rax), %rcx
movq %rcx, 0x4c(%rdi)
movq 0x40(%rax), %rcx
movq %rcx, 0x54(%rdi)
movq 0x48(%rax), %rax
movq %rax, 0x5c(%rdi)
movq -0x98(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, 0x94(%rdi)
movq -0x98(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, 0x9c(%rdi)
addq $0x108, %rdi            # imm = 0x108
leaq -0x30(%rbp), %rsi
callq 0x9060
movq -0x280(%rbp), %rax
movl $0x2, (%rax)
jmp 0x4559
movq -0x280(%rbp), %rax
movq $0x0, -0xb0(%rbp)
movq $0x0, -0xb8(%rbp)
cmpl $0x0, (%rax)
je 0x4612
movq -0x280(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
xorl %eax, %eax
movl %eax, %esi
callq 0x8f70
movq -0x280(%rbp), %rdi
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movl 0x4(%rax), %eax
addq $0x1c, %rax
movq %rax, -0x2e0(%rbp)
addq $0x108, %rdi            # imm = 0x108
callq 0x8f50
movq %rax, %rcx
movq -0x2e0(%rbp), %rax
cmpq %rcx, %rax
jbe 0x45e7
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x53e3
movq -0x280(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
movq -0xb8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
callq 0x8f70
movq %rax, -0xb0(%rbp)
jmp 0x46a8
leaq -0x30(%rbp), %rdi
callq 0x8f50
cmpq $0x8, %rax
jb 0x4693
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8f70
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movl 0x4(%rax), %eax
addq $0x1c, %rax
movq %rax, -0x2e8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x8f50
movq %rax, %rcx
movq -0x2e8(%rbp), %rax
cmpq %rcx, %rax
jbe 0x4675
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x53e3
movq -0xb8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x8f70
movq %rax, -0xb0(%rbp)
jmp 0x46a6
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x53e3
jmp 0x46a8
movq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x2f8(%rbp)
leaq 0x63a49(%rip), %rdi     # 0x68114
xorl %eax, %eax
movl %eax, %esi
callq 0x8f90
movq %rax, -0x2f0(%rbp)
leaq 0x63a32(%rip), %rdi     # 0x68114
callq 0x8fc0
movq -0x2f8(%rbp), %rdi
movq -0x2f0(%rbp), %rsi
movq %rax, %rdx
callq 0x2140
cmpl $0x0, %eax
je 0x4715
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x53e3
movq -0x280(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x4745
movq -0x280(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
leaq -0x30(%rbp), %rsi
callq 0x9060
movq -0x280(%rbp), %rax
movl $0x3, (%rax)
movq -0x280(%rbp), %rax
leaq -0xb0(%rbp), %rcx
movq %rcx, -0xd0(%rbp)
movq %rax, -0xc8(%rbp)
movq -0xb0(%rbp), %rcx
movq -0xc0(%rbp), %rdx
movslq 0x4(%rdx), %rdx
addq %rdx, %rcx
movq %rcx, 0x120(%rax)
movq 0x120(%rax), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x4ac3
movq -0xd8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x300(%rbp)
subq $0x2, %rax
je 0x4953
jmp 0x47b9
movq -0x300(%rbp), %rax
subq $0x3, %rax
je 0x49ad
jmp 0x47cc
movq -0x300(%rbp), %rax
subq $0x4, %rax
je 0x49cb
jmp 0x47df
movq -0x300(%rbp), %rax
subq $0x5, %rax
je 0x4971
jmp 0x47f2
movq -0x300(%rbp), %rax
subq $0x6, %rax
je 0x48db
jmp 0x4805
movq -0x300(%rbp), %rax
subq $0x7, %rax
je 0x48f9
jmp 0x4818
movq -0x300(%rbp), %rax
subq $0x8, %rax
je 0x4917
jmp 0x482b
movq -0x300(%rbp), %rax
subq $0xa, %rax
je 0x498f
jmp 0x483e
movq -0x300(%rbp), %rax
subq $0xc, %rax
je 0x4a07
jmp 0x4851
movq -0x300(%rbp), %rax
subq $0xd, %rax
je 0x4a25
jmp 0x4864
movq -0x300(%rbp), %rax
subq $0x17, %rax
je 0x4935
jmp 0x4877
movq -0x300(%rbp), %rax
subq $0x19, %rax
je 0x4a40
jmp 0x488a
movq -0x300(%rbp), %rax
subq $0x1a, %rax
je 0x4a76
jmp 0x489d
movq -0x300(%rbp), %rax
subq $0x1b, %rax
je 0x4a5b
jmp 0x48b0
movq -0x300(%rbp), %rax
subq $0x1c, %rax
je 0x4a91
jmp 0x48c3
movq -0x300(%rbp), %rax
subq $0x6ffffef5, %rax       # imm = 0x6FFFFEF5
je 0x49e9
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x130(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x138(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x140(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x148(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x150(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x158(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x160(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x168(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x170(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x178(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x180(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x188(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x190(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x198(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x1a0(%rax)
jmp 0x4aaa
movq -0x280(%rbp), %rax
movq -0xd8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x1a8(%rax)
jmp 0x4aac
movq -0xd8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xd8(%rbp)
jmp 0x478b
movq -0x280(%rbp), %rax
cmpl $0x3, (%rax)
je 0x4b1b
movq -0x280(%rbp), %rdi
movq %rdi, %rax
addq $0x14, %rax
movq %rax, -0xe0(%rbp)
addq $0x108, %rdi            # imm = 0x108
movq -0xe0(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
callq 0x8f70
movq -0x280(%rbp), %rdi
movq %rax, %rsi
movq -0xe0(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %edx
callq 0x9170
jmp 0x4b19
jmp 0x4b1b
movq -0x280(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x50d7
movq -0x280(%rbp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, -0x100(%rbp)
movq $0x0, -0xf0(%rbp)
addq $0x108, %rdi            # imm = 0x108
movq %rdi, -0x318(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x8f70
movq -0x318(%rbp), %rdi
movq %rax, -0x310(%rbp)
callq 0x8f50
movq -0x280(%rbp), %rdi
movq -0x310(%rbp), %rsi
movq %rax, %rdx
callq 0x9170
movb %al, -0x301(%rbp)
jmp 0x4b8f
movb -0x301(%rbp), %al
testb $0x1, %al
jne 0x4bc6
jmp 0x4b9b
movq 0x6e43e(%rip), %rax     # 0x72fe0
movq (%rax), %rsi
leaq 0x63594(%rip), %rdi     # 0x68140
callq 0x2270
jmp 0x4bb3
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x53e3
movq -0x280(%rbp), %rcx
movq 0x130(%rcx), %rax
cmpq 0x158(%rcx), %rax
jb 0x4c08
movq 0x6e3fc(%rip), %rax     # 0x72fe0
movq (%rax), %rsi
leaq 0x63585(%rip), %rdi     # 0x68173
callq 0x2270
jmp 0x4bf5
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x53e3
movq -0x280(%rbp), %rax
movl 0x130(%rax), %edx
movl 0x158(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xa0(%rax)
leaq -0x118(%rbp), %rdi
movq %rdi, -0x328(%rbp)
callq 0x92b0
movq -0x328(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x138(%rbp), %rdi
movq %rdi, -0x320(%rbp)
leaq -0x140(%rbp), %rsi
callq 0x9370
movq -0x280(%rbp), %rdi
movq -0x320(%rbp), %rsi
callq 0x92d0
jmp 0x4c73
leaq -0x138(%rbp), %rdi
callq 0x9400
leaq -0x118(%rbp), %rdi
movq %rdi, -0x330(%rbp)
callq 0x9460
movq -0x330(%rbp), %rdi
movq %rax, -0x148(%rbp)
callq 0x9490
movq %rax, -0x150(%rbp)
movq -0x148(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x9420
jmp 0x4cc1
leaq -0x118(%rbp), %rdi
movq %rdi, -0x340(%rbp)
callq 0x9460
movq -0x340(%rbp), %rdi
movq %rax, -0x168(%rbp)
callq 0x9490
movq %rax, -0x170(%rbp)
movq -0x168(%rbp), %rdi
movq -0x170(%rbp), %rsi
callq 0x9550
movq %rax, -0x338(%rbp)
jmp 0x4d0a
movq -0x338(%rbp), %rax
movq %rax, -0x160(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x9590
leaq -0x118(%rbp), %rdi
movq %rdi, -0x350(%rbp)
callq 0x9490
movq %rax, -0x180(%rbp)
leaq -0x178(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x9590
movq -0x350(%rbp), %rdi
movq -0x158(%rbp), %rsi
movq -0x178(%rbp), %rdx
callq 0x94c0
movq %rax, -0x348(%rbp)
jmp 0x4d7b
movq -0x348(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x95d0
cmpq $0x4, %rax
je 0x4df4
movq 0x6e23e(%rip), %rax     # 0x72fe0
movq (%rax), %rsi
leaq 0x63414(%rip), %rdi     # 0x681c0
callq 0x2270
jmp 0x4db3
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x50a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x9400
jmp 0x50c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x50c6
leaq -0x100(%rbp), %rax
movq %rax, -0x1b8(%rbp)
leaq -0x118(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x1a8(%rbp), %rdi
movq %rdi, -0x358(%rbp)
leaq -0x1b8(%rbp), %rsi
callq 0x95f0
movq -0x280(%rbp), %rdi
movq -0x358(%rbp), %rsi
callq 0x92d0
jmp 0x4e3f
leaq -0x1a8(%rbp), %rdi
callq 0x9400
cmpl $0x0, -0xf0(%rbp)
jne 0x4e9c
movq 0x6e185(%rip), %rax     # 0x72fe0
movq (%rax), %rsi
leaq 0x6335b(%rip), %rdi     # 0x681c0
callq 0x2270
jmp 0x4e6c
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x50a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x9400
jmp 0x50c6
movq -0x280(%rbp), %rdi
movl $0x0, -0x100(%rbp)
movq 0x1b0(%rdi), %rax
addq 0x1b8(%rdi), %rax
movl %eax, -0xfc(%rbp)
movl -0x100(%rbp), %eax
addl -0xfc(%rbp), %eax
addl $0xfff, %eax            # imm = 0xFFF
andl $0xfffff000, %eax       # imm = 0xFFFFF000
movl %eax, -0xf8(%rbp)
movl -0xf0(%rbp), %eax
subl -0xf8(%rbp), %eax
movl %eax, -0xf4(%rbp)
addq $0x108, %rdi            # imm = 0x108
callq 0x8f50
movq %rax, %rcx
movq -0x280(%rbp), %rax
movl -0xf0(%rbp), %edx
subq %rdx, %rcx
movl %ecx, -0xec(%rbp)
movq 0x158(%rax), %rcx
movl -0xf8(%rbp), %edx
subq %rdx, %rcx
movl %ecx, 0x94(%rax)
movq 0x160(%rax), %rcx
movl %ecx, 0x98(%rax)
movq 0x130(%rax), %rcx
movl -0xf8(%rbp), %edx
subq %rdx, %rcx
movl %ecx, 0x9c(%rax)
movl $0x0, -0x1bc(%rbp)
cmpl $0x3, -0x1bc(%rbp)
jge 0x509e
movq -0x280(%rbp), %rax
movslq -0x1bc(%rbp), %rcx
shlq $0x4, %rcx
leaq 0x14(%rax,%rcx), %rcx
movq %rcx, -0x1c8(%rbp)
movslq -0x1bc(%rbp), %rcx
movl -0x100(%rbp,%rcx,8), %edx
movq -0x1c8(%rbp), %rcx
movl %edx, (%rcx)
movq -0x1c8(%rbp), %rcx
movl %edx, 0x4(%rcx)
movslq -0x1bc(%rbp), %rdx
movl -0xfc(%rbp,%rdx,8), %ecx
movl %ecx, 0x64(%rax,%rdx,4)
movq -0x1c8(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x1bc(%rbp), %eax
movl %eax, -0x35c(%rbp)
testl %eax, %eax
je 0x4fee
jmp 0x4fd1
movl -0x35c(%rbp), %eax
subl $0x1, %eax
je 0x5001
jmp 0x4fde
movl -0x35c(%rbp), %eax
subl $0x2, %eax
je 0x5011
jmp 0x5088
movq -0x1c8(%rbp), %rax
movl $0x100, 0xc(%rax)       # imm = 0x100
jmp 0x5088
movq -0x1c8(%rbp), %rax
movl $0x1, 0xc(%rax)
jmp 0x5088
movq -0xc0(%rbp), %rax
movl 0xc(%rax), %esi
leaq -0xd0(%rbp), %rdi
callq 0x9680
movl %eax, -0x360(%rbp)
jmp 0x502f
movq -0xc0(%rbp), %rax
movl 0x8(%rax), %esi
leaq -0xd0(%rbp), %rdi
callq 0x9680
movl %eax, -0x364(%rbp)
jmp 0x504d
movl -0x364(%rbp), %eax
movl -0x360(%rbp), %ecx
subl %eax, %ecx
movq -0x1c8(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x1c8(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0xfff, %ecx            # imm = 0xFFF
andl $0xfffff000, %ecx       # imm = 0xFFFFF000
addl $0x1, %ecx
movq -0x1c8(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x508a
movl -0x1bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1bc(%rbp)
jmp 0x4f57
movl $0x0, -0x8c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x96e0
movl -0x8c(%rbp), %eax
testl %eax, %eax
jne 0x53e3
jmp 0x50c4
jmp 0x50d7
leaq -0x118(%rbp), %rdi
callq 0x96e0
jmp 0x53fa
leaq -0x1f8(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2170
movl $0x4, -0x1f8(%rbp)
movl $0x10, -0x1f4(%rbp)
movl $0x3, -0x1f0(%rbp)
movb $0x47, -0x1ec(%rbp)
movb $0x4e, -0x1eb(%rbp)
movb $0x55, -0x1ea(%rbp)
leaq -0x228(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2170
movl $0x4, -0x228(%rbp)
movl $0x14, -0x224(%rbp)
movl $0x3, -0x220(%rbp)
movb $0x47, -0x21c(%rbp)
movb $0x4e, -0x21b(%rbp)
movb $0x55, -0x21a(%rbp)
movl $0x1, -0x24c(%rbp)
movl $0x0, -0x248(%rbp)
movl $0x2, -0x244(%rbp)
leaq -0x24c(%rbp), %rax
movq %rax, -0x240(%rbp)
movq $0x3, -0x238(%rbp)
leaq -0x240(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0x230(%rbp), %rdi
callq 0x9740
movq %rax, -0x258(%rbp)
movq -0x230(%rbp), %rdi
callq 0x9760
movq %rax, -0x260(%rbp)
movq -0x258(%rbp), %rax
cmpq -0x260(%rbp), %rax
je 0x52f5
movq -0x280(%rbp), %rdi
movq -0x258(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x264(%rbp)
movl -0x264(%rbp), %eax
shlq $0x4, %rax
leaq 0x14(%rdi,%rax), %rax
movq %rax, -0x270(%rbp)
addq $0x108, %rdi            # imm = 0x108
movq -0x270(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
callq 0x8f70
movq %rax, %rdi
movq -0x270(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
leaq -0x1f8(%rbp), %rdx
movl $0x10, %ecx
callq 0x97a0
movq %rax, -0x370(%rbp)
jmp 0x524f
movq -0x280(%rbp), %rax
movq -0x370(%rbp), %rcx
movq %rcx, 0x128(%rax)
cmpq $0x0, 0x128(%rax)
je 0x5273
jmp 0x52f5
movq -0x280(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
movq -0x270(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
callq 0x8f70
movq %rax, %rdi
movq -0x270(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
leaq -0x228(%rbp), %rdx
movl $0x10, %ecx
callq 0x97a0
movq %rax, -0x378(%rbp)
jmp 0x52bb
movq -0x280(%rbp), %rax
movq -0x378(%rbp), %rcx
movq %rcx, 0x128(%rax)
cmpq $0x0, 0x128(%rax)
je 0x52dc
jmp 0x52f5
jmp 0x52de
movq -0x258(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x258(%rbp)
jmp 0x51ce
movq -0x280(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x5366
movq -0x280(%rbp), %rax
cmpq $0x0, 0x128(%rax)
je 0x5366
movq -0x280(%rbp), %rdi
movq 0x128(%rdi), %rax
movq %rax, -0x278(%rbp)
addq $0x4, %rdi
addq $0x40, %rdi
callq 0x9820
movq %rax, -0x380(%rbp)
movq -0x278(%rbp), %rdi
addq $0x10, %rdi
callq 0x9840
movq -0x380(%rbp), %rdi
movq %rax, %rsi
movq -0x278(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
callq 0x21f0
movq -0xc0(%rbp), %rax
movl 0x10(%rax), %esi
leaq -0xd0(%rbp), %rdi
callq 0x9680
movl %eax, -0x384(%rbp)
jmp 0x5384
movq -0x280(%rbp), %rax
movl -0x384(%rbp), %ecx
movl %ecx, %ecx
movq %rcx, 0x1c0(%rax)
movq -0xc0(%rbp), %rax
movl 0x14(%rax), %esi
leaq -0xd0(%rbp), %rdi
callq 0x9680
movl %eax, -0x388(%rbp)
jmp 0x53b8
movq -0x280(%rbp), %rax
movl -0x388(%rbp), %ecx
movl %ecx, %ecx
subq 0x1c0(%rax), %rcx
movq %rcx, 0x1c8(%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x9090
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x390, %rsp            # imm = 0x390
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x9090
movq -0x70(%rbp), %rdi
callq 0x2370
nopl (%rax)