// File: /workspace/github_cpp_makefile_star2_O1/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, 0x14(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, 0x38(%rsp)
leaq 0x4049(%rip), %rdx      # 0x70f6
leaq 0x30(%rsp), %rdi
callq 0x44fa
movq 0x30(%rsp), %rbx
movq %r12, %rdi
callq 0x44ba
cmpq %rax, %rbx
je 0x32f9
movq %r14, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
movq $0x0, 0x20(%rsp)
movq %r12, 0x28(%rsp)
movq %r12, %rdi
leaq 0x3ffd(%rip), %rsi      # 0x70f6
movq %r15, (%rsp)
callq 0x473c
cmpw $0x4, 0xe(%rax)
jne 0x3420
movl (%rax), %eax
cmpq %rax, 0x20(%rsp)
jae 0x326d
movq %r12, %rdi
leaq 0x3fd2(%rip), %rsi      # 0x70f6
callq 0x473c
movq %rax, %rdi
movq 0x20(%rsp), %rsi
callq 0x480e
movq %rax, %rdi
leaq 0x3f8b(%rip), %rsi      # 0x70cb
callq 0x473c
testb $0x40, 0xe(%rax)
je 0x3464
movl (%rax), %r12d
movq 0x28(%rsp), %rdi
leaq 0x3f98(%rip), %rsi      # 0x70f6
callq 0x473c
movq %rax, %rdi
movq 0x20(%rsp), %rsi
callq 0x480e
movq %rax, %rdi
leaq 0x3f2e(%rip), %rsi      # 0x70a8
callq 0x473c
movq %rax, %rdi
callq 0x4160
movq %rax, %r14
cmpq 0x8(%rsp), %r13
je 0x31a7
movq %r12, (%r13)
movq %r14, 0x8(%r13)
movq (%rsp), %r15
movq 0x28(%rsp), %r12
jmp 0x325f
movq %r13, %rbp
movq (%rsp), %rcx
subq %rcx, %rbp
movabsq $0x7ffffffffffffff0, %rax # imm = 0x7FFFFFFFFFFFFFF0
cmpq %rax, %rbp
je 0x3483
movq %rbp, %rbx
sarq $0x4, %rbx
movl $0x1, %eax
cmpq %rcx, %r13
je 0x31d8
movq %rbx, %rax
leaq (%rax,%rbx), %rcx
movabsq $0x7ffffffffffffff, %r13 # imm = 0x7FFFFFFFFFFFFFF
cmpq %r13, %rcx
jb 0x31ee
movq %r13, %rcx
addq %rbx, %rax
jb 0x31f6
movq %rcx, %r13
testq %r13, %r13
je 0x320c
movq %r13, %rdi
shlq $0x4, %rdi
callq 0x2130
movq %rax, %r15
jmp 0x320f
xorl %r15d, %r15d
shlq $0x4, %rbx
movq %r12, (%r15,%rbx)
movq %r14, 0x8(%r15,%rbx)
testq %rbp, %rbp
movq (%rsp), %rbx
jle 0x3233
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2230
testq %rbx, %rbx
movq 0x28(%rsp), %r12
je 0x324d
movq 0x8(%rsp), %rsi
subq %rbx, %rsi
movq %rbx, %rdi
callq 0x2140
addq %r15, %rbp
shlq $0x4, %r13
addq %r15, %r13
movq %r13, 0x8(%rsp)
movq %rbp, %r13
addq $0x10, %r13
incq 0x20(%rsp)
jmp 0x30ef
cmpq %r13, %r15
je 0x331a
movq %r13, %rbx
subq %r15, %rbx
movq %rbx, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x3da6
cmpq $0x101, %rbx            # imm = 0x101
jl 0x330f
leaq 0x100(%r15), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4059
cmpq %r13, %rbx
je 0x331a
movq 0x18(%rsp), %r14
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq %rbx, %rdx
cmpq -0x10(%rbx), %rax
jae 0x32e7
movq %rbx, %rsi
leaq -0x10(%rsi), %rdx
movups -0x10(%rsi), %xmm0
movups %xmm0, (%rsi)
cmpq -0x20(%rsi), %rax
movq %rdx, %rsi
jb 0x32d3
movq %rax, (%rdx)
movq %rcx, 0x8(%rdx)
addq $0x10, %rbx
cmpq %r13, %rbx
jne 0x32c0
jmp 0x331f
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
movq $0x0, (%rsp)
jmp 0x331f
movq %r15, %rdi
movq %r13, %rsi
callq 0x4059
movq 0x18(%rsp), %r14
cmpw $0x4, 0xe(%r14)
jne 0x3420
movq (%rsp), %rax
leaq 0x10(%rax), %rbp
xorl %r15d, %r15d
movl (%r14), %eax
cmpq %rax, %r15
jae 0x343f
movq %r14, %rbx
cmpq (%rsp), %r13
je 0x33ee
movq %rbx, %rdi
movl %r15d, %esi
callq 0x480e
movq %rax, %r14
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
leaq 0x3d5f(%rip), %rdx      # 0x70cb
callq 0x44fa
movq 0x30(%rsp), %r12
movq %r14, %rdi
callq 0x44ba
cmpq %rax, %r12
je 0x33ee
movq (%rsp), %rax
movq (%rax), %r14
movq %rbx, %rdi
movl %r15d, %esi
callq 0x480e
movq %rax, %rdi
leaq 0x3d2c(%rip), %rsi      # 0x70cb
callq 0x473c
testb $0x40, 0xe(%rax)
je 0x3464
movl (%rax), %eax
cmpq %rax, %r14
jae 0x33ee
movq (%rsp), %rax
movq 0x8(%rax), %rsi
movq (%rax), %rdx
addq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rdi
movl 0x14(%rsp), %ecx
callq 0x34cc
cmpq %r13, %rbp
je 0x33ea
movq %rbp, %rsi
movq %r13, %rdx
subq %rbp, %rdx
movq (%rsp), %rdi
callq 0x2230
addq $-0x10, %r13
movq %rbx, %rdi
movl %r15d, %esi
callq 0x480e
movq 0x38(%rsp), %rdi
movq %rax, %rsi
movq 0x40(%rsp), %rdx
movl 0x14(%rsp), %ecx
callq 0x2e24
incq %r15
movq %rbx, %r14
cmpw $0x4, 0xe(%rbx)
je 0x3336
leaq 0x46d7(%rip), %rdi      # 0x7afe
leaq 0x40a4(%rip), %rsi      # 0x74d2
leaq 0x46d3(%rip), %rcx      # 0x7b08
movl $0x61b, %edx            # imm = 0x61B
callq 0x20e0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3455
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 0x47f2(%rip), %rdi      # 0x7c5d
leaq 0x4060(%rip), %rsi      # 0x74d2
leaq 0x47fe(%rip), %rcx      # 0x7c77
movl $0x6ca, %edx            # imm = 0x6CA
callq 0x20e0
leaq 0x4883(%rip), %rdi      # 0x7d0d
callq 0x20c0
movq %rax, %rbx
movq $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
jmp 0x34ae
jmp 0x34ab
jmp 0x34ab
jmp 0x34ab
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x34c4
movq 0x8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x2250