// File: /workspace/github_cpp_makefile_star2_O3/DimitriFourny[P]uaf_replacer/main.cc
// Function: dump_members(rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator> const&, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>> const&, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>> const&, unsigned long, unsigned int)
void dump_members(const rapidjson::Document& document, 
                  const rapidjson::Value& current_element, 
                  const rapidjson::Value& members, uint64_t base_offset, 
                  unsigned int deep_size) {
  // Dealing with the parents right now
  struct parent {
    size_t offset;
    const char* id;
  };
  std::vector<parent> parents;
  if (current_element.HasMember("parents")) {
    for (size_t i = 0; i < current_element["parents"].Size(); i++) {
      parents.push_back({
        current_element["parents"][i]["offset"].GetUint(),
        current_element["parents"][i]["id"].GetString()
      });
    }

    std::sort(parents.begin(), parents.end(), [](const parent& a, 
                                                 const parent& b) {
      return a.offset < b.offset;
    });
  }

  for (size_t i = 0; i < members.Size(); i++) {
    if (parents.size() > 0 && members[i].HasMember("offset")) {
      if (parents[0].offset < members[i]["offset"].GetUint()) {
        dump_parent(document, parents[0].id, base_offset + parents[0].offset, 
          deep_size);
        parents.erase(parents.begin());
      }
    }

    dump_member(document, members[i], base_offset, deep_size);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, 0x1c(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, 0x30(%rsp)
leaq 0x3a39(%rip), %rdx      # 0x70f6
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x4ae8
movq (%rbx), %rbx
movq %r14, 0x28(%rsp)
movq %r14, %rdi
callq 0x4aa8
cmpq %rax, %rbx
movq %r12, 0x10(%rsp)
je 0x38fa
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
movq $0x0, 0x20(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x39eb(%rip), %rsi      # 0x70f6
movq %r14, (%rsp)
callq 0x4d34
cmpw $0x4, 0xe(%rax)
jne 0x3a24
movl (%rax), %eax
cmpq %rax, 0x20(%rsp)
jae 0x3878
movq 0x28(%rsp), %rdi
leaq 0x39be(%rip), %rsi      # 0x70f6
callq 0x4d34
movq %rax, %rdi
movq 0x20(%rsp), %rsi
callq 0x4e06
movq %rax, %rdi
leaq 0x3977(%rip), %rsi      # 0x70cb
callq 0x4d34
testb $0x40, 0xe(%rax)
je 0x3a68
movl (%rax), %r15d
movq 0x28(%rsp), %rdi
leaq 0x3984(%rip), %rsi      # 0x70f6
callq 0x4d34
movq %rax, %rdi
movq 0x20(%rsp), %rsi
callq 0x4e06
movq %rax, %rdi
leaq 0x391a(%rip), %rsi      # 0x70a8
callq 0x4d34
movq %rax, %rdi
callq 0x474e
movq %rax, %r13
movq 0x8(%rsp), %rdx
cmpq %rdx, %rbp
je 0x37b9
movq %r15, (%rbp)
movq %r13, 0x8(%rbp)
movq (%rsp), %r14
jmp 0x3865
movq %rdx, %rbp
movq (%rsp), %rcx
subq %rcx, %rbp
movabsq $0x7ffffffffffffff0, %rax # imm = 0x7FFFFFFFFFFFFFF0
cmpq %rax, %rbp
movabsq $0x7ffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFF
je 0x3a87
movq %rbp, %r14
sarq $0x4, %r14
movl $0x1, %eax
cmpq %rcx, %rdx
je 0x37f4
movq %r14, %rax
leaq (%rax,%r14), %r12
cmpq %rsi, %r12
jb 0x3800
movq %rsi, %r12
addq %r14, %rax
cmovbq %rsi, %r12
testq %r12, %r12
je 0x381d
movq %r12, %rdi
shlq $0x4, %rdi
callq 0x2130
movq %rax, %rbx
jmp 0x381f
xorl %ebx, %ebx
shlq $0x4, %r14
movq %r15, (%rbx,%r14)
movq %r13, 0x8(%rbx,%r14)
testq %rbp, %rbp
movq (%rsp), %r14
jle 0x3843
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2230
testq %r14, %r14
je 0x3853
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2140
addq %rbx, %rbp
shlq $0x4, %r12
addq %rbx, %r12
movq %r12, 0x8(%rsp)
movq %rbx, %r14
movq 0x10(%rsp), %r12
addq $0x10, %rbp
incq 0x20(%rsp)
jmp 0x36ff
cmpq %rbp, %r14
je 0x391a
movq %rbp, %rbx
subq %r14, %rbx
movq %rbx, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x43a6
cmpq $0x101, %rbx            # imm = 0x101
jl 0x390f
leaq 0x100(%r14), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4646
cmpq %rbp, %rbx
je 0x391a
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq %rbx, %rdx
cmpq %rax, -0x10(%rbx)
jbe 0x38ed
movq %rbx, %rsi
leaq -0x10(%rsi), %rdx
movups -0x10(%rsi), %xmm0
movups %xmm0, (%rsi)
cmpq %rax, -0x20(%rsi)
movq %rdx, %rsi
ja 0x38d9
movq %rax, (%rdx)
movq %rcx, 0x8(%rdx)
addq $0x10, %rbx
jmp 0x38c1
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
movq $0x0, (%rsp)
jmp 0x391a
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4646
cmpw $0x4, 0xe(%r12)
jne 0x3a24
movq (%rsp), %rax
leaq 0x10(%rax), %r15
xorl %r13d, %r13d
leaq 0x3792(%rip), %r14      # 0x70cb
movl (%r12), %eax
cmpq %rax, %r13
jae 0x3a43
cmpq (%rsp), %rbp
je 0x39ee
movq %r12, %rdi
movl %r13d, %esi
callq 0x4e06
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x4ae8
movq 0x40(%rsp), %r12
movq %rbx, %rdi
callq 0x4aa8
cmpq %rax, %r12
je 0x39e9
movq (%rsp), %rax
movq (%rax), %rbx
movq 0x10(%rsp), %rdi
movl %r13d, %esi
callq 0x4e06
movq %rax, %rdi
movq %r14, %rsi
callq 0x4d34
testb $0x40, 0xe(%rax)
je 0x3a68
movl (%rax), %eax
cmpq %rax, %rbx
jae 0x39e9
movq (%rsp), %rax
movq 0x8(%rax), %rsi
movq (%rax), %rdx
addq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rdi
movl 0x1c(%rsp), %ecx
callq 0x3aba
cmpq %rbp, %r15
je 0x39e5
movq %rbp, %rdx
subq %r15, %rdx
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x2230
addq $-0x10, %rbp
movq 0x10(%rsp), %r12
movq %r12, %rdi
movl %r13d, %esi
callq 0x4e06
movq 0x30(%rsp), %rdi
movq %rax, %rsi
movq 0x38(%rsp), %rdx
movl 0x1c(%rsp), %ecx
callq 0x3434
incq %r13
movq 0x10(%rsp), %r12
cmpw $0x4, 0xe(%r12)
je 0x3939
leaq 0x40d3(%rip), %rdi      # 0x7afe
leaq 0x3aa0(%rip), %rsi      # 0x74d2
leaq 0x40cf(%rip), %rcx      # 0x7b08
movl $0x61b, %edx            # imm = 0x61B
callq 0x20e0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3a59
movq 0x8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x41ee(%rip), %rdi      # 0x7c5d
leaq 0x3a5c(%rip), %rsi      # 0x74d2
leaq 0x41fa(%rip), %rcx      # 0x7c77
movl $0x6ca, %edx            # imm = 0x6CA
callq 0x20e0
leaq 0x427f(%rip), %rdi      # 0x7d0d
callq 0x20c0
jmp 0x3a99
jmp 0x3a99
jmp 0x3a99
movq %rax, %rbx
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3ab2
subq %rdi, %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x2250