// File: /workspace/github_c_makefile_star2_O2/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 $0x118, %rsp            # imm = 0x118
movq %rsi, %r12
movq %rdi, %rbx
leaq -0xc0(%rbp), %r14
andl $0x0, (%r14)
callq 0x2110
movq %rax, 0x8(%r14)
movq %r12, %rdi
movq %r14, %rsi
callq 0x2210
cmpq $-0x1, %rax
je 0x2c11
leaq -0x80(%rbp), %r14
leaq -0x38(%rbp), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x52a2
leaq 0xf664(%rip), %rdx      # 0x12209
leaq -0x38(%rbp), %rdi
movq %r12, %rsi
callq 0x28f9
movq -0x38(%rbp), %rcx
leaq -0x50(%rbp), %r15
testq %rcx, %rcx
je 0x2be9
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
subq %rdi, %rsi
pushq $0x1
popq %rdx
callq 0x2280
testq %rax, %rax
je 0x2be9
movq -0x80(%rbp), %rax
movq %rax, -0x50(%rbp)
movups -0x78(%rbp), %xmm0
movups %xmm0, -0x48(%rbp)
movq %r14, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
andq $0x0, 0x10(%r15)
leaq -0x38(%rbp), %rdi
callq 0x54a2
leaq -0x80(%rbp), %rdi
callq 0x5518
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %rax
jmp 0x2c22
andq $0x0, -0x40(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
xorl %r15d, %r15d
xorl %eax, %eax
subq %r15, %rax
cmpq $0x100, %rax            # imm = 0x100
jb 0x2cc8
cmpl $0x304f534e, (%r15)     # imm = 0x304F534E
jne 0x2cd0
leaq 0x4(%rbx), %rdi
movl $0x100, %edx            # imm = 0x100
movq %r15, %rsi
callq 0x2170
movl 0x3c(%rbx), %esi
addl 0x38(%rbx), %esi
addl 0x40(%rbx), %esi
leaq -0x80(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x52a2
leaq 0x108(%rbx), %rdi
leaq -0x80(%rbp), %r14
movq %r14, %rsi
callq 0x55aa
movq %r14, %rdi
callq 0x5518
xorl %r14d, %r14d
pushq $0x1
popq %r12
cmpq $0xc, %r14
je 0x2dad
movl 0x14(%rbx,%r14,4), %ecx
movl 0x18(%rbx,%r14,4), %esi
addq 0x108(%rbx), %rsi
movl 0x1c(%rbx,%r14,4), %edx
addq -0x50(%rbp), %rcx
movl 0x64(%rbx,%r14), %r8d
movq %rbx, %rdi
callq 0x52f4
addq $0x4, %r14
testb %al, %al
jne 0x2c8a
jmp 0x2ddc
cmpq $0x80, %rax
jb 0x2cda
cmpl $0x304f524e, 0x10(%r15) # imm = 0x304F524E
je 0x2d15
movl (%rbx), %r12d
testl %r12d, %r12d
jne 0x2db0
movq -0x48(%rbp), %rax
subq %r15, %rax
cmpq $0x8, %rax
jb 0x2ddc
movl 0x4(%r15), %ecx
leaq 0x1c(%rcx), %rdx
xorl %r12d, %r12d
cmpq %rax, %rdx
ja 0x2ddf
addq %rcx, %r15
movb $0x1, %al
jmp 0x2dd3
movl 0x18(%r15), %ecx
xorl %r12d, %r12d
cmpq %rcx, %rax
jne 0x2ddf
pushq $0x1
popq %rax
xorl %ecx, %ecx
cmpq $0xc, %rcx
je 0x2d71
movl 0x20(%r15,%rcx,2), %edx
movl %edx, 0x14(%rbx,%rcx,4)
movl %edx, 0x18(%rbx,%rcx,4)
movl 0x24(%r15,%rcx,2), %edx
movl %edx, 0x64(%rbx,%rcx)
movl %edx, 0x1c(%rbx,%rcx,4)
testl %r12d, %r12d
je 0x2d5b
cmpl $0x2, %r12d
jne 0x2d62
movl 0x38(%r15), %edx
jmp 0x2d64
movl $0x100, %edx            # imm = 0x100
jmp 0x2d64
movl %eax, %edx
movl %edx, 0x20(%rbx,%rcx,4)
addq $0x4, %rcx
incl %r12d
jmp 0x2d2a
movups 0x40(%r15), %xmm0
movups 0x50(%r15), %xmm1
movups %xmm1, 0x54(%rbx)
movups %xmm0, 0x44(%rbx)
movq 0x70(%r15), %rax
movq %rax, 0x94(%rbx)
movq 0x78(%r15), %rax
movq %rax, 0x9c(%rbx)
leaq 0x108(%rbx), %rdi
leaq -0x50(%rbp), %rsi
callq 0x55aa
pushq $0x2
popq %r12
movl %r12d, (%rbx)
movq 0x108(%rbx), %r15
movq 0x110(%rbx), %rcx
movl 0x4(%r15), %eax
leaq 0x1c(%rax), %rdx
subq %r15, %rcx
cmpq %rcx, %rdx
ja 0x2ddc
addq %rax, %r15
xorl %eax, %eax
cmpl $0x30444f4d, (%r15)     # imm = 0x30444F4D
je 0x2dfd
xorl %r12d, %r12d
leaq -0x50(%rbp), %rdi
callq 0x5518
movl %r12d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x3
popq %r14
testb %al, %al
je 0x2e1e
leaq 0x108(%rbx), %rdi
leaq -0x50(%rbp), %rsi
callq 0x55aa
movl $0x3, (%rbx)
movl %r14d, %r12d
movslq 0x4(%r15), %rax
leaq (%r15,%rax), %rcx
movq %rcx, 0x120(%rbx)
leaq 0x1a8(%rbx), %rcx
movq %rcx, -0xf8(%rbp)
leaq 0x1a0(%rbx), %rcx
movq %rcx, -0xf0(%rbp)
leaq 0x198(%rbx), %rcx
movq %rcx, -0xe8(%rbp)
leaq 0x190(%rbx), %rcx
movq %rcx, -0xe0(%rbp)
leaq 0x188(%rbx), %rcx
movq %rcx, -0xd8(%rbp)
leaq 0x180(%rbx), %rcx
movq %rcx, -0xd0(%rbp)
leaq 0x178(%rbx), %r9
leaq 0x170(%rbx), %rcx
movq %rcx, -0xc8(%rbp)
leaq 0x168(%rbx), %r11
leaq 0x160(%rbx), %r8
leaq 0x158(%rbx), %rcx
movq %rcx, -0x90(%rbp)
leaq 0x150(%rbx), %r14
movq %r15, -0x88(%rbp)
leaq 0x8(%r15,%rax), %rax
leaq 0x148(%rbx), %rcx
leaq 0x140(%rbx), %rdx
leaq 0x138(%rbx), %rsi
leaq 0x130(%rbx), %r13
leaq 0xf178(%rip), %rdi      # 0x12060
jmp 0x2f66
movq %r14, %r15
jmp 0x2f5c
movq %r9, %r15
cmpq $0x6ffffef5, %r10       # imm = 0x6FFFFEF5
je 0x2f5c
jmp 0x2f62
movq -0xd8(%rbp), %r15
jmp 0x2f5c
movq -0xd0(%rbp), %r15
jmp 0x2f5c
movq -0xc8(%rbp), %r15
jmp 0x2f5c
movq -0x90(%rbp), %r15
jmp 0x2f5c
movq %r11, %r15
jmp 0x2f5c
movq %rsi, %r15
jmp 0x2f5c
movq %r8, %r15
jmp 0x2f5c
movq -0xe0(%rbp), %r15
jmp 0x2f5c
movq %rdx, %r15
jmp 0x2f5c
movq -0xf0(%rbp), %r15
jmp 0x2f5c
movq %rcx, %r15
jmp 0x2f5c
movq -0xf8(%rbp), %r15
jmp 0x2f5c
movq -0xe8(%rbp), %r15
movq (%rax), %r10
movq %r10, (%r15)
addq $0x10, %rax
movq -0x8(%rax), %r10
cmpq $0x1c, %r10
ja 0x2eef
movslq (%rdi,%r10,4), %r10
addq %rdi, %r10
movq %r13, %r15
jmpq *%r10
cmpl $0x3, %r12d
je 0x2fa5
movl 0x18(%rbx), %esi
movl 0x1c(%rbx), %edx
addq 0x108(%rbx), %rsi
movq %rbx, %rdi
callq 0x5330
cmpl $0x3, (%rbx)
jne 0x31c1
xorps %xmm0, %xmm0
andq $0x0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movq 0x108(%rbx), %rsi
movq 0x110(%rbx), %rdx
subq %rsi, %rdx
movq %rbx, %rdi
callq 0x5330
testb %al, %al
je 0x331f
movq (%r13), %rax
movq -0x90(%rbp), %rcx
movq (%rcx), %rcx
cmpq %rax, %rcx
jbe 0x3328
subl %eax, %ecx
movl %ecx, 0xa0(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, -0xc0(%rbp)
andq $0x0, -0xb0(%rbp)
leaq -0x138(%rbp), %rsi
andq $0x0, 0x8(%rsi)
leaq -0xc0(%rbp), %rax
movq %rax, (%rsi)
leaq 0x269a(%rip), %rax      # 0x56ba
movq %rax, 0x18(%rsi)
leaq 0x2699(%rip), %rax      # 0x56c4
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0x53d0
leaq -0x138(%rbp), %rdi
callq 0x5430
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x58e0
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x5dbe
leaq -0xc0(%rbp), %r15
movq 0x8(%r15), %rdx
movq %r15, %rdi
movq %rax, %rsi
callq 0x5450
movq -0xb8(%rbp), %rax
subq -0xc0(%rbp), %rax
cmpq $0x8, %rax
jne 0x32f8
leaq -0x80(%rbp), %rax
leaq -0x118(%rbp), %rsi
movq %rax, (%rsi)
movq %r15, 0x8(%rsi)
leaq 0x2d8a(%rip), %rax      # 0x5e3a
movq %rax, 0x18(%rsi)
leaq 0x2d89(%rip), %rax      # 0x5e44
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0x53d0
leaq -0x118(%rbp), %rdi
callq 0x5430
movl -0x70(%rbp), %eax
testl %eax, %eax
je 0x32f8
andl $0x0, -0x80(%rbp)
movl 0x1b0(%rbx), %ecx
movl 0x1b8(%rbx), %edx
leal (%rdx,%rcx), %esi
movl %esi, -0x7c(%rbp)
addl %edx, %ecx
addl $0xfff, %ecx            # imm = 0xFFF
andl $0xfffff000, %ecx       # imm = 0xFFFFF000
movl %ecx, -0x78(%rbp)
movl %eax, %edx
subl %ecx, %edx
movl %edx, -0x74(%rbp)
movl 0x110(%rbx), %edx
movq 0x108(%rbx), %rsi
subl %esi, %edx
subl %eax, %edx
movl %edx, -0x6c(%rbp)
movl 0x130(%rbx), %eax
movl 0x158(%rbx), %edx
subl %ecx, %edx
movl %edx, 0x94(%rbx)
movl 0x160(%rbx), %edx
movl %edx, 0x98(%rbx)
subl %ecx, %eax
movl %eax, 0x9c(%rbx)
xorl %eax, %eax
xorl %ecx, %ecx
movq -0x88(%rbp), %rdi
cmpq $0xc, %rcx
je 0x31b5
movl -0x80(%rbp,%rcx,2), %edx
movl %edx, 0x14(%rbx,%rcx,4)
movl %edx, 0x18(%rbx,%rcx,4)
movl -0x7c(%rbp,%rcx,2), %edx
movl %edx, 0x64(%rbx,%rcx)
movl %edx, 0x1c(%rbx,%rcx,4)
cmpl $0x2, %eax
je 0x3185
cmpl $0x1, %eax
jne 0x31a5
movl $0x1, 0x20(%rbx,%rcx,4)
jmp 0x31ad
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(%rbx,%rcx,4)
jmp 0x31ad
movl $0x100, 0x20(%rbx,%rcx,4) # imm = 0x100
addq $0x4, %rcx
incl %eax
jmp 0x3153
leaq -0xc0(%rbp), %rdi
callq 0x5ed8
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rdx
movups %xmm0, 0xc(%rdx)
andl $0x0, 0x2c(%rdx)
movups %xmm0, 0x1c(%rdx)
movabsq $0x1000000004, %rax     # imm = 0x1000000004
movq %rax, (%rdx)
pushq $0x3
popq %rsi
movl %esi, 0x8(%rdx)
movw $0x4e47, %ax            # imm = 0x4E47
movw %ax, 0xc(%rdx)
movb $0x55, %cl
movb %cl, 0xe(%rdx)
leaq -0xc0(%rbp), %rdi
andl $0x0, 0x2c(%rdi)
movups %xmm0, 0xc(%rdi)
movups %xmm0, 0x1c(%rdi)
movabsq $0x1400000004, %rdx     # imm = 0x1400000004
movq %rdx, (%rdi)
movl %esi, 0x8(%rdi)
movw %ax, 0xc(%rdi)
movb %cl, 0xe(%rdi)
movq $0x1, -0x38(%rbp)
movl $0x2, -0x30(%rbp)
leaq 0x14(%rbx), %r14
xorl %r15d, %r15d
pushq $0x10
popq %r13
cmpq $0xc, %r15
je 0x32a3
movl -0x38(%rbp,%r15), %r12d
shlq $0x4, %r12
movl 0x4(%r14,%r12), %edi
movl 0x8(%r14,%r12), %esi
addq 0x108(%rbx), %rdi
leaq -0x80(%rbp), %rdx
movq %r13, %rcx
callq 0x545a
movq %rax, 0x128(%rbx)
testq %rax, %rax
jne 0x32a3
addq %r14, %r12
movl 0x4(%r12), %edi
movl 0x8(%r12), %esi
addq 0x108(%rbx), %rdi
leaq -0xc0(%rbp), %rdx
movq %r13, %rcx
callq 0x545a
movq %rax, 0x128(%rbx)
addq $0x4, %r15
testq %rax, %rax
je 0x3238
cmpl $0x3, (%rbx)
jne 0x32c4
movq 0x128(%rbx), %rsi
testq %rsi, %rsi
je 0x32c4
leaq 0x44(%rbx), %rdi
movl 0x4(%rsi), %edx
addq $0x10, %rsi
callq 0x2170
movq -0x88(%rbp), %rsi
movl 0x10(%rsi), %eax
addl %esi, %eax
movl 0x108(%rbx), %ecx
subl %ecx, %eax
movq %rax, 0x1c0(%rbx)
movl 0x14(%rsi), %edx
addl %esi, %edx
subl %ecx, %edx
subq %rax, %rdx
movq %rdx, 0x1c8(%rbx)
movb $0x1, %r12b
jmp 0x2ddf
movq 0x13cd9(%rip), %rax     # 0x16fd8
movq (%rax), %rsi
leaq 0xeebb(%rip), %rdi      # 0x121c4
callq 0x21e0
leaq -0xc0(%rbp), %rdi
callq 0x5ed8
jmp 0x2ddc
leaq 0xee1e(%rip), %rdi      # 0x12144
jmp 0x332f
leaq 0xee48(%rip), %rdi      # 0x12177
movq 0x13ca2(%rip), %rax     # 0x16fd8
movq (%rax), %rsi
callq 0x21e0
jmp 0x2ddc
jmp 0x3384
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
jmp 0x3364
jmp 0x3355
jmp 0x3355
movq %rax, %rbx
jmp 0x3369
movq %rax, %rbx
leaq -0x138(%rbp), %rdi
callq 0x5430
leaq -0xc0(%rbp), %rdi
callq 0x5ed8
jmp 0x3387
jmp 0x3384
jmp 0x3384
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
jmp 0x338b
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x5518
movq %rbx, %rdi
callq 0x22b0