// File: /workspace/github_c_makefile_star2_O1/deplinenoise[P]tundra/src/Driver.cpp
// Function: t2::DriverPrepareNodes(t2::Driver*, char const**, int)
bool DriverPrepareNodes(Driver* self, const char** targets, int target_count)
{
  ProfilerScope prof_scope("Tundra PrepareNodes", 0);

  const DagData    *dag       = self->m_DagData;
  const NodeData   *src_nodes = dag->m_NodeData;
  const HashDigest *src_guids = dag->m_NodeGuids;
  MemAllocHeap     *heap      = &self->m_Heap;

  Buffer<int32_t> node_stack;
  BufferInitWithCapacity(&node_stack, heap, 1024);

  DriverSelectNodes(dag, targets, target_count, &node_stack, heap);

  const size_t node_word_count = (dag->m_NodeCount + 31) / 32;
  uint32_t* node_visited_bits = HeapAllocateArrayZeroed<uint32_t>(heap, node_word_count);

  int node_count = 0;

  Buffer<int32_t> node_indices;
  BufferInitWithCapacity(&node_indices, heap, 1024);

  while (node_stack.m_Size > 0)
  {
    int       dag_index = BufferPopOne(&node_stack);
    const int dag_word  = dag_index / 32;
    const int dag_bit   = 1 << (dag_index &31);

    if (0 == (node_visited_bits[dag_word] & dag_bit))
    {
      const NodeData* node = src_nodes + dag_index;
      CHECK(uint32_t(node->m_PassIndex) < uint32_t(dag->m_Passes.GetCount()));

      BufferAppendOne(&node_indices, &self->m_Heap, dag_index);

      node_visited_bits[dag_word] |= dag_bit;

      // Update counts
      ++node_count;
      self->m_PassNodeCount[node->m_PassIndex]++;

      // Stash node dependencies on the work queue to keep iterating
      BufferAppend(&node_stack, &self->m_Heap, node->m_Dependencies.GetArray(), node->m_Dependencies.GetCount());
    }
  }

  HeapFree(heap, node_visited_bits);
  node_visited_bits = nullptr;

  // Allocate space for nodes
  NodeState* out_nodes = BufferAllocZero(&self->m_Nodes, &self->m_Heap, node_count);

  // Initialize node state
  for (int i = 0; i < node_count; ++i)
  {
    const NodeData* src_node = src_nodes + node_indices[i];
    out_nodes[i].m_MmapData  = src_node;
    out_nodes[i].m_PassIndex = (uint16_t) src_node->m_PassIndex;
  }

  // Find frozen node state from previous build, if present.
  if (const StateData* state_data = self->m_StateData)
  {
    const NodeStateData *frozen_states    = state_data->m_NodeStates;
    const HashDigest    *state_guids      = state_data->m_NodeGuids;
    const int            state_guid_count = state_data->m_NodeCount;

    for (int i = 0; i < node_count; ++i)
    {
      const HashDigest* src_guid = src_guids + node_indices[i];

      if (const HashDigest* old_guid = BinarySearch(state_guids, state_guid_count, *src_guid))
      {
        int state_index = int(old_guid - state_guids);
        out_nodes[i].m_MmapState = frozen_states + state_index;
      }
    }
  }


  // Sort the node state array based on which pass the nodes are in.
  auto compare_node_passes = [](const NodeState& l, const NodeState& r) -> bool
  {
    return l.m_PassIndex < r.m_PassIndex;
  };

  std::sort(out_nodes, out_nodes + node_count, compare_node_passes);

  // Now that our local order is established (sorted for pass purposes),
  // initialize a remapping table from global (dag) index to local (state)
  // index. This is so we can map any DAG node reference onto any local state.
  int32_t* node_remap = BufferAllocFill(&self->m_NodeRemap, heap, dag->m_NodeCount, -1);

  CHECK(node_remap == self->m_NodeRemap.m_Storage);

  for (int local_index = 0; local_index < node_count; ++local_index)
  {
    const NodeData* global_node = out_nodes[local_index].m_MmapData;
    const int global_index = int(global_node - src_nodes);
    CHECK(node_remap[global_index] == -1);
    node_remap[global_index] = local_index;
  }

  Log(kDebug, "Node remap: %d src nodes, %d active nodes, using %d bytes of node state buffer space",
      dag->m_NodeCount, node_count, sizeof(NodeState) * node_count);

  BufferDestroy(&node_stack, &self->m_Heap);
  BufferDestroy(&node_indices, &self->m_Heap);

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
movl $0x0, 0x54(%rsp)
leaq 0x13916(%rip), %rax     # 0x1d680
cmpb $0x1, (%rax)
jne 0x9d7d
leaq 0xc863(%rip), %rdi      # 0x165d9
xorl %esi, %esi
callq 0xfb72
movq 0xa0(%rbx), %rcx
movslq 0xc(%rcx), %rax
testq %rax, %rax
leaq 0xc(%rax,%rcx), %rdx
cmoveq %rax, %rdx
movq %rdx, 0x58(%rsp)
movslq 0x8(%rcx), %rax
testq %rax, %rax
movq %rcx, 0x40(%rsp)
leaq 0x8(%rax,%rcx), %rcx
cmoveq %rax, %rcx
movq %rcx, 0xa8(%rsp)
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdi
callq 0xef62
movq %rax, (%rsp)
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movq $0x400, 0x10(%rsp)      # imm = 0x400
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdx
movaps %xmm0, (%rdx)
movq %rax, 0x10(%rdx)
leaq 0x60(%rsp), %rcx
movaps %xmm0, (%rcx)
movq %rax, 0x10(%rcx)
movq 0x40(%rsp), %r8
movl 0x18(%r8), %eax
leaq 0xb0(%rsp), %rdi
movl %eax, (%rdi)
movl 0x24(%r8), %eax
movl %eax, 0x4(%rdi)
movl 0x30(%r8), %eax
movl %eax, 0x8(%rdi)
movslq 0x20(%r8), %rax
testq %rax, %rax
leaq 0x20(%rax,%r8), %rsi
cmoveq %rax, %rsi
movq %rsi, 0x10(%rdi)
movslq 0x2c(%r8), %rax
testq %rax, %rax
leaq 0x2c(%rax,%r8), %rsi
cmoveq %rax, %rsi
movq %rsi, 0x18(%rdi)
movslq 0x38(%r8), %rax
testq %rax, %rax
leaq 0x38(%rax,%r8), %rsi
cmoveq %rax, %rsi
movq %rsi, 0x20(%rdi)
movl %ebp, 0x28(%rdi)
movq %r15, 0x30(%rdi)
movl 0x44(%r8), %eax
movl %eax, 0x38(%rdi)
movl 0x48(%r8), %eax
movl %eax, 0x3c(%rdi)
movl 0x4c(%r8), %eax
movl %eax, 0x40(%rdi)
movq %rbx, %rsi
callq 0x12144
movq %rbx, 0x28(%rsp)
movq 0x88(%rsp), %rax
testq %rax, %rax
je 0xa04f
movq 0x80(%rsp), %rbx
leaq (%rax,%rax,2), %rax
leaq (%rbx,%rax,4), %rax
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rax
addq $0x40, %rax
movq %rax, 0x30(%rsp)
movq 0x40(%rsp), %rdx
movslq 0x40(%rdx), %rcx
movq 0x30(%rsp), %rax
addq %rcx, %rax
testq %rcx, %rcx
cmoveq %rcx, %rax
movslq 0x3c(%rdx), %rdi
testq %rdi, %rdi
je 0x9f0d
movq (%rbx), %rcx
movl 0x8(%rbx), %edx
movq %rcx, %rsi
shrq $0x20, %rsi
shlq $0x2, %rdi
leaq (%rdi,%rdi,8), %rdi
cmpl %ecx, (%rax)
jne 0x9efb
cmpl %esi, 0x4(%rax)
jne 0x9efb
cmpl %edx, 0x8(%rax)
jne 0x9efb
xorl %r8d, %r8d
movq %rax, %r12
jmp 0x9efe
movb $0x1, %r8b
testb %r8b, %r8b
je 0x9f10
addq $0x24, %rax
addq $-0x24, %rdi
jne 0x9ee5
xorl %r12d, %r12d
testq %r12, %r12
je 0xa5f7
movq 0x68(%rsp), %r8
testq %r8, %r8
je 0x9f42
movq 0x60(%rsp), %rcx
movq 0x40(%rsp), %rdi
movq %rsp, %rsi
movq 0x28(%rsp), %rdx
movq %r12, %r9
callq 0xb9ed
jmp 0x9fc6
movslq 0x10(%r12), %rax
testq %rax, %rax
leaq 0x10(%rax,%r12), %r13
cmoveq %rax, %r13
movslq 0xc(%r12), %rbp
movq (%rsp), %rax
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
leaq (%rdx,%rbp), %r14
cmpq %rcx, %r14
jbe 0x9fae
movq %rdx, 0x48(%rsp)
leaq (%rcx,%rcx), %r15
testq %rcx, %rcx
movl $0x8, %ecx
cmoveq %rcx, %r15
cmpq %r14, %r15
cmovbeq %r14, %r15
leaq (,%r15,4), %rdx
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0xef72
movq %rax, (%rsp)
movq %r15, 0x10(%rsp)
movq 0x48(%rsp), %rdx
movq %r14, 0x8(%rsp)
leaq (%rax,%rdx,4), %rdi
shlq $0x2, %rbp
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3290
movslq 0x18(%r12), %rax
testq %rax, %rax
leaq 0x18(%rax,%r12), %r13
cmoveq %rax, %r13
movslq 0x14(%r12), %r12
movq (%rsp), %rax
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %rcx
leaq (%r15,%r12), %r14
cmpq %rcx, %r14
jbe 0xa028
leaq (%rcx,%rcx), %rbp
testq %rcx, %rcx
movl $0x8, %ecx
cmoveq %rcx, %rbp
cmpq %r14, %rbp
cmovbeq %r14, %rbp
leaq (,%rbp,4), %rdx
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0xef72
movq %rax, (%rsp)
movq %rbp, 0x10(%rsp)
movq %r14, 0x8(%rsp)
leaq (%rax,%r15,4), %rdi
shlq $0x2, %r12
movq %r13, %rsi
movq %r12, %rdx
callq 0x3290
addq $0xc, %rbx
cmpq 0x20(%rsp), %rbx
jne 0x9eaf
movq 0x8(%rsp), %rax
testq %rax, %rax
movq 0x28(%rsp), %rbx
je 0xa089
movq (%rsp), %r15
leaq (%r15,%rax,4), %r12
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0xd7a4
movq %r15, %rdi
movq %r12, %rsi
callq 0xd87f
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
leaq (%rdi,%rax,4), %rsi
callq 0xdae3
subq (%rsp), %rax
sarq $0x2, %rax
movq %rax, 0x8(%rsp)
leaq 0xc87a(%rip), %rsi      # 0x16929
movl $0x8, %edi
movl %eax, %edx
xorl %eax, %eax
callq 0x5ef0
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
je 0xa0e0
movq %rbx, %rdi
callq 0xef6a
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x80(%rsp), %rsi
testq %rsi, %rsi
je 0xa10c
movq %rbx, %rdi
callq 0xef6a
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
movq 0x40(%rsp), %rax
movl 0x4(%rax), %eax
leal 0x1f(%rax), %ecx
addl $0x3e, %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
sarl $0x5, %eax
movslq %eax, %r15
movq %r15, %rsi
shlq $0x4, %rsi
movq %rbx, %rdi
callq 0xef62
shlq $0x2, %r15
movq %rax, 0x38(%rsp)
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x31b0
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdi
callq 0xef62
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0xa2d0
movl $0x400, %r14d           # imm = 0x400
movq $0x0, 0x20(%rsp)
xorl %ebp, %ebp
movq 0x38(%rsp), %rsi
leaq -0x1(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rsp), %rcx
movslq -0x4(%rcx,%rax,4), %r12
leal 0x1f(%r12), %eax
testq %r12, %r12
cmovnsl %r12d, %eax
movl $0x1, %r15d
movl %r12d, %ecx
shll %cl, %r15d
sarl $0x5, %eax
movslq %eax, %r13
movl (%rsi,%r13,4), %eax
btl %r12d, %eax
jb 0xa2c0
leaq 0x1(%rbp), %rcx
cmpq %r14, %rcx
movq %rcx, 0x48(%rsp)
jbe 0xa207
testq %r14, %r14
leaq (%r14,%r14), %r14
movl $0x8, %eax
cmoveq %rax, %r14
cmpq %rcx, %r14
cmovbeq %rcx, %r14
leaq (,%r14,4), %rdx
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
callq 0xef72
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rbx
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rax
movl %r12d, (%rax,%rbp,4)
leaq (%r12,%r12,8), %rax
orl %r15d, (%rsi,%r13,4)
movq 0x58(%rsp), %rsi
movslq 0xc(%rsi,%rax,8), %rcx
incl 0x340(%rbx,%rcx,4)
leaq (%rsi,%rax,8), %rcx
movslq 0x14(%rsi,%rax,8), %rdx
testq %rdx, %rdx
leaq 0x14(%rdx,%rcx), %r12
cmoveq %rdx, %r12
movslq 0x10(%rsi,%rax,8), %rbp
movq (%rsp), %rax
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %rcx
leaq (%r15,%rbp), %r13
cmpq %rcx, %r13
jbe 0xa292
movq %rbx, %rdi
leaq (%rcx,%rcx), %rbx
testq %rcx, %rcx
movl $0x8, %ecx
cmoveq %rcx, %rbx
cmpq %r13, %rbx
cmovbeq %r13, %rbx
leaq (,%rbx,4), %rdx
movq %rax, %rsi
callq 0xef72
movq %rax, (%rsp)
movq %rbx, 0x10(%rsp)
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %rcx
incl %ecx
movq %rcx, 0x20(%rsp)
movq %r13, 0x8(%rsp)
leaq (%rax,%r15,4), %rdi
shlq $0x2, %rbp
movq %r12, %rsi
movq %rbp, %rdx
callq 0x3290
movq 0x48(%rsp), %rbp
movq 0x38(%rsp), %rsi
movq 0x8(%rsp), %rax
testq %rax, %rax
jne 0xa180
jmp 0xa2de
movq $0x0, 0x20(%rsp)
movq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0xef6a
movq 0x30(%rsp), %r14
movq 0x20(%rsp), %r15
leaq 0x100(%rbx), %rdi
movslq %r15d, %r12
movq %rbx, %rsi
movq %r12, %rdx
callq 0xdcba
movq %rax, %rbp
movq %r12, %rdx
shlq $0x6, %rdx
movq %rax, %rdi
xorl %esi, %esi
movq %rdx, 0x38(%rsp)
callq 0x31b0
movl %r15d, %ebx
movq %r12, 0xa0(%rsp)
testl %r12d, %r12d
movq 0x58(%rsp), %rsi
jle 0xa35c
leaq 0x2(%rbp), %rax
xorl %ecx, %ecx
movslq (%r14,%rcx,4), %rdx
leaq (%rdx,%rdx,8), %rdx
leaq (%rsi,%rdx,8), %rdx
movq %rdx, 0x6(%rax)
movzwl 0xc(%rdx), %edx
movw %dx, (%rax)
incq %rcx
addq $0x40, %rax
cmpq %rcx, %rbx
jne 0xa339
movq 0x28(%rsp), %rax
movq 0xa8(%rax), %rax
testq %rax, %rax
je 0xa3f2
movslq 0xc(%rax), %rcx
testq %rcx, %rcx
leaq 0xc(%rcx,%rax), %rdx
cmoveq %rcx, %rdx
movq %rdx, 0x48(%rsp)
movslq 0x8(%rax), %rcx
testq %rcx, %rcx
leaq 0x8(%rcx,%rax), %r12
cmoveq %rcx, %r12
cmpl $0x0, 0x20(%rsp)
jle 0xa3f2
movl 0x4(%rax), %r13d
leaq 0x10(%rbp), %r15
xorl %r14d, %r14d
movq 0x30(%rsp), %rax
movslq (%rax,%r14,4), %rdx
shlq $0x4, %rdx
addq 0xa8(%rsp), %rdx
movq %r12, %rdi
movl %r13d, %esi
callq 0xd763
testq %rax, %rax
je 0xa3e6
subq %r12, %rax
shrq $0x4, %rax
cltq
leaq (%rax,%rax,8), %rax
movq 0x48(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, (%r15)
incq %r14
addq $0x40, %r15
cmpq %r14, %rbx
jne 0xa3a8
cmpl $0x0, 0x20(%rsp)
movq 0x30(%rsp), %r15
je 0xa513
movq 0x38(%rsp), %rax
leaq (%rax,%rbp), %r13
bsrq 0xa0(%rsp), %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0xc303
cmpl $0x11, 0x20(%rsp)
jl 0xa508
leaq 0x400(%rbp), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0xc826
movzwl (%r12), %eax
movzwl 0x2(%r12), %ecx
movups 0x30(%r12), %xmm0
movups %xmm0, 0xdc(%rsp)
movups 0x24(%r12), %xmm0
movaps %xmm0, 0xd0(%rsp)
movups 0x14(%r12), %xmm0
movaps %xmm0, 0xc0(%rsp)
movups 0x4(%r12), %xmm0
movaps %xmm0, 0xb0(%rsp)
movq %r12, %rdx
cmpw -0x3e(%r12), %cx
jae 0xa4c2
movq %r12, %rsi
leaq -0x40(%rsi), %rdx
movups -0x40(%rsi), %xmm0
movups -0x30(%rsi), %xmm1
movups -0x20(%rsi), %xmm2
movups -0x10(%rsi), %xmm3
movups %xmm3, 0x30(%rsi)
movups %xmm2, 0x20(%rsi)
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
cmpw -0x7e(%rsi), %cx
movq %rdx, %rsi
jb 0xa496
movw %ax, (%rdx)
movw %cx, 0x2(%rdx)
movaps 0xb0(%rsp), %xmm0
movaps 0xc0(%rsp), %xmm1
movaps 0xd0(%rsp), %xmm2
movups %xmm0, 0x4(%rdx)
movups %xmm1, 0x14(%rdx)
movups %xmm2, 0x24(%rdx)
movups 0xdc(%rsp), %xmm0
movups %xmm0, 0x30(%rdx)
addq $0x40, %r12
cmpq %r13, %r12
jne 0xa445
jmp 0xa513
movq %rbp, %rdi
movq %r13, %rsi
callq 0xc826
movq 0x28(%rsp), %rsi
leaq 0xe8(%rsi), %rdi
movq 0x40(%rsp), %rax
movslq 0x4(%rax), %r13
movq %r13, %rdx
callq 0x8bc1
movq %rax, %r12
testl %r13d, %r13d
movq 0x58(%rsp), %r14
je 0xa551
shlq $0x2, %r13
movq %r12, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x31b0
movq 0x20(%rsp), %rcx
testl %ecx, %ecx
jle 0xa584
addq $0x8, %rbp
xorl %eax, %eax
movq (%rbp), %rdx
subq %r14, %rdx
shrq $0x3, %rdx
imull $0x38e38e39, %edx, %edx # imm = 0x38E38E39
movslq %edx, %rdx
movl %eax, (%r12,%rdx,4)
incq %rax
addq $0x40, %rbp
cmpq %rax, %rbx
jne 0xa560
movq 0x40(%rsp), %rax
movl 0x4(%rax), %edx
leaq 0xc05a(%rip), %rsi      # 0x165ed
movl $0x8, %edi
movq 0x38(%rsp), %r8
xorl %eax, %eax
callq 0x5ef0
movq (%rsp), %rsi
testq %rsi, %rsi
je 0xa5c7
movq 0x28(%rsp), %rdi
callq 0xef6a
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %r15, %r15
je 0xa5d9
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0xef6a
leaq 0x54(%rsp), %rdi
callq 0x5b82
movb $0x1, %al
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc30a(%rip), %rdi      # 0x16908
xorl %eax, %eax
callq 0x5bdd
jmp 0xa613
jmp 0xa613
jmp 0xa613
jmp 0xa613
jmp 0xa613
jmp 0xa613
jmp 0xa613
movq %rax, %rbx
leaq 0x54(%rsp), %rdi
callq 0x5b82
movq %rbx, %rdi
callq 0x35e0