// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movl %r8d, %ebp
movq %rcx, %r13
movq %rdx, 0x18(%rsp)
movq %rsi, %rax
movq %rdi, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
leaq 0x363a(%rip), %rsi      # 0x60f6
movq %rax, 0x40(%rsp)
movq %rax, %rdi
callq 0x37c6
testb %al, %al
je 0x2c75
xorl %ebx, %ebx
xorl %r14d, %r14d
movq $0x0, (%rsp)
movl %ebp, 0x14(%rsp)
movq %r13, 0x48(%rsp)
movq 0x40(%rsp), %rdi
leaq 0x3603(%rip), %rsi      # 0x60f6
callq 0x3ef6
movq %rax, %rdi
callq 0x38ea
movl %eax, %eax
cmpq %rax, (%rsp)
movq %r14, 0x8(%rsp)
jae 0x2c7d
movq 0x40(%rsp), %rdi
leaq 0x35d9(%rip), %rsi      # 0x60f6
callq 0x3ef6
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x3fa0
movq %rax, %rdi
leaq 0x3593(%rip), %rsi      # 0x60cb
callq 0x3ef6
movq %rax, %rdi
callq 0x3914
movl %eax, %ebp
movq 0x40(%rsp), %rdi
leaq 0x35a3(%rip), %rsi      # 0x60f6
callq 0x3ef6
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x3fa0
movq %rax, %rdi
leaq 0x353a(%rip), %rsi      # 0x60a8
callq 0x3ef6
movq %rax, %rdi
callq 0x37ec
movq %rax, %r14
movl %ebp, %r12d
cmpq 0x30(%rsp), %rbx
je 0x2bab
movq %r12, (%rbx)
movq %r14, 0x8(%rbx)
addq $0x10, %rbx
movq %rbx, 0x28(%rsp)
movl 0x14(%rsp), %ebp
movq 0x48(%rsp), %r13
movq 0x8(%rsp), %r14
jmp 0x2c6c
movq %rbx, %rbp
movq 0x8(%rsp), %rax
subq %rax, %rbp
movabsq $0x7ffffffffffffff0, %rcx # imm = 0x7FFFFFFFFFFFFFF0
cmpq %rcx, %rbp
je 0x2de2
movq %rbp, %r15
sarq $0x4, %r15
cmpq %rax, %rbx
movq %r15, %rax
pushq $0x1
popq %rcx
cmoveq %rcx, %rax
leaq (%rax,%r15), %r13
movabsq $0x7ffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFF
cmpq %rcx, %r13
cmovaeq %rcx, %r13
addq %r15, %rax
cmovbq %rcx, %r13
testq %r13, %r13
je 0x2c0f
movq %r13, %rdi
shlq $0x4, %rdi
callq 0x2130
movq %rax, %rbx
jmp 0x2c11
xorl %ebx, %ebx
movq %r15, %rax
shlq $0x4, %rax
movq %r12, (%rbx,%rax)
movq %r14, 0x8(%rbx,%rax)
testq %rbp, %rbp
movq 0x8(%rsp), %r14
jle 0x2c39
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2230
leaq (%rbx,%rbp), %r12
addq $0x10, %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x3460
movq %r12, 0x28(%rsp)
shlq $0x4, %r13
addq %rbx, %r13
movq %r13, 0x30(%rsp)
movq %rbx, %r14
movq %r12, %rbx
movl 0x14(%rsp), %ebp
movq 0x48(%rsp), %r13
incq (%rsp)
jmp 0x2ae7
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0x2cf7
movq %r14, 0x20(%rsp)
cmpq %rbx, %r14
je 0x2cdd
movq %rbx, %r15
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 %r15, %rsi
callq 0x346f
cmpq $0x101, %rbx            # imm = 0x101
jl 0x2ce2
movq %r15, %r12
leaq 0x100(%r14), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x36d7
cmpq %r12, %rbx
je 0x2cf2
movq %rbx, %rdi
callq 0x3747
addq $0x10, %rbx
jmp 0x2cca
movq %rbx, %r12
jmp 0x2cf7
movq %r14, %rdi
movq %r15, %r12
movq %r15, %rsi
callq 0x36d7
jmp 0x2cf7
movq 0x8(%rsp), %r14
movq %r14, %rbx
leaq 0x10(%r14), %rax
movq %rax, (%rsp)
xorl %r14d, %r14d
movq 0x18(%rsp), %rdi
callq 0x38ea
movl %eax, %eax
cmpq %rax, %r14
jae 0x2dc5
cmpq %rbx, %r12
je 0x2d9e
movq 0x18(%rsp), %rdi
movl %r14d, %esi
callq 0x3fa0
movq %rax, %rdi
leaq 0x3395(%rip), %rsi      # 0x60cb
callq 0x37c6
testb %al, %al
je 0x2d9e
movq (%rbx), %r15
movq 0x18(%rsp), %rdi
movl %r14d, %esi
callq 0x3fa0
movq %rax, %rdi
leaq 0x3372(%rip), %rsi      # 0x60cb
callq 0x3ef6
movq %rax, %rdi
callq 0x3914
movl %eax, %eax
cmpq %rax, %r15
jae 0x2d9e
movq 0x8(%rbx), %rsi
movq (%rbx), %rdx
addq %r13, %rdx
movq 0x50(%rsp), %rdi
movl %ebp, %ecx
callq 0x2e2d
movq (%rsp), %rsi
cmpq %r12, %rsi
je 0x2d9a
movq %r12, %rdx
subq %rsi, %rdx
movq %rbx, %rdi
callq 0x2230
addq $-0x10, %r12
movq 0x18(%rsp), %rdi
movl %r14d, %esi
callq 0x3fa0
movq 0x50(%rsp), %rdi
movq %rax, %rsi
movq %r13, %rdx
movl %ebp, %ecx
callq 0x28d2
incq %r14
jmp 0x2d05
leaq 0x20(%rsp), %rdi
movq %r12, 0x8(%rdi)
callq 0x2fb2
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x20(%rsp)
leaq 0x3f1f(%rip), %rdi      # 0x6d0d
callq 0x20c0
jmp 0x2df5
movq %rax, %rbx
jmp 0x2e1b
movq %rax, %rbx
movq %r14, 0x20(%rsp)
jmp 0x2e1b
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x2e1b
movq %rax, %rbx
movq %r12, 0x28(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x2fb2
movq %rbx, %rdi
callq 0x2250