// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
movl $0x0, 0x54(%rsp)
leaq 0x13d2e(%rip), %rax     # 0x1d680
cmpb $0x1, (%rax)
jne 0x9965
leaq 0xcc6b(%rip), %rdi      # 0x165c9
xorl %esi, %esi
callq 0xf4a3
movq 0x8(%rsp), %rdi
movq 0xa0(%rdi), %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, 0x88(%rsp)
movl $0x1000, %esi           # imm = 0x1000
callq 0xe882
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x18(%rsp)
movq $0x400, 0x20(%rsp)      # imm = 0x400
xorps %xmm0, %xmm0
leaq 0x90(%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)
movq 0x44(%r8), %rax
movq %rax, 0x38(%rdi)
movl 0x4c(%r8), %eax
movl %eax, 0x40(%rdi)
movq 0x8(%rsp), %rsi
callq 0x11a6c
movq 0x98(%rsp), %rax
testq %rax, %rax
je 0x9c54
movq 0x90(%rsp), %r14
leaq (%rax,%rax,2), %rax
leaq (%r14,%rax,4), %rax
movq %rax, 0x28(%rsp)
movq 0x40(%rsp), %rax
addq $0x40, %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rcx
movslq 0x40(%rcx), %rax
movq 0x38(%rsp), %rdx
leaq (%rax,%rdx), %r12
testq %rax, %rax
cmoveq %rax, %r12
movslq 0x3c(%rcx), %rdi
testq %rdi, %rdi
je 0xa246
movq (%r14), %rcx
movl 0x8(%r14), %edx
movq %rcx, %rsi
shrq $0x20, %rsi
movq $-0x10, %rax
subq %r12, %rax
movq $-0x18, %r15
subq %r12, %r15
shlq $0x2, %rdi
leaq (%rdi,%rdi,8), %rdi
cmpl %ecx, (%r12)
jne 0x9af5
cmpl %esi, 0x4(%r12)
jne 0x9af5
cmpl %edx, 0x8(%r12)
je 0x9b0c
addq $0x24, %r12
addq $-0x24, %rax
addq $-0x24, %r15
addq $-0x24, %rdi
jne 0x9ae1
jmp 0xa246
movq 0x68(%rsp), %r8
testq %r8, %r8
je 0x9b37
movq 0x60(%rsp), %rcx
movq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %r9
callq 0xb657
jmp 0x9bc8
movslq 0x10(%r12), %rcx
movq %rcx, %r13
subq %rax, %r13
testq %rcx, %rcx
cmoveq %rcx, %r13
movslq 0xc(%r12), %rbp
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
leaq (%rdx,%rbp), %rsi
cmpq %rcx, %rsi
jbe 0x9bb0
movq %rdx, 0x48(%rsp)
leaq (%rcx,%rcx), %rbx
testq %rcx, %rcx
movl $0x8, %ecx
cmoveq %rcx, %rbx
cmpq %rsi, %rbx
movq %rsi, 0x30(%rsp)
cmovbeq %rsi, %rbx
leaq (,%rbx,4), %rdx
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0xe892
movq %rax, 0x10(%rsp)
movq %rbx, 0x20(%rsp)
movq 0x48(%rsp), %rdx
movq 0x30(%rsp), %rsi
movq %rsi, 0x18(%rsp)
leaq (%rax,%rdx,4), %rdi
shlq $0x2, %rbp
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3290
movslq 0x18(%r12), %rax
movq %rax, %r13
subq %r15, %r13
testq %rax, %rax
cmoveq %rax, %r13
movslq 0x14(%r12), %r12
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rbx
movq 0x20(%rsp), %rcx
leaq (%rbx,%r12), %r15
cmpq %rcx, %r15
jbe 0x9c2d
leaq (%rcx,%rcx), %rbp
testq %rcx, %rcx
movl $0x8, %ecx
cmoveq %rcx, %rbp
cmpq %r15, %rbp
cmovbeq %r15, %rbp
leaq (,%rbp,4), %rdx
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0xe892
movq %rax, 0x10(%rsp)
movq %rbp, 0x20(%rsp)
movq %r15, 0x18(%rsp)
leaq (%rax,%rbx,4), %rdi
shlq $0x2, %r12
movq %r13, %rsi
movq %r12, %rdx
callq 0x3290
addq $0xc, %r14
cmpq 0x28(%rsp), %r14
jne 0x9a91
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x9ce1
leaq (%r15,%rax,4), %r12
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0xd2e2
movq %r15, %rdi
movq %r12, %rsi
callq 0xd3bd
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rax
leaq (%r15,%rax,4), %rdx
testq %rax, %rax
je 0x9cea
shlq $0x2, %rax
movl $0x4, %edi
cmpq %rdi, %rax
je 0x9cea
movl -0x4(%r15,%rdi), %esi
leaq 0x4(%rdi), %rcx
cmpl (%r15,%rdi), %esi
movq %rcx, %rdi
jne 0x9ca6
leaq (%r15,%rcx), %rdx
addq $-0x8, %rdx
cmpq %rcx, %rax
je 0x9ce6
movl %esi, %edi
movl (%r15,%rcx), %esi
cmpl %esi, %edi
je 0x9cdb
movl %esi, 0x4(%rdx)
addq $0x4, %rdx
addq $0x4, %rcx
jmp 0x9cc5
movq %r15, %rdx
jmp 0x9cea
addq $0x4, %rdx
subq %r15, %rdx
sarq $0x2, %rdx
movq %rdx, 0x18(%rsp)
leaq 0xcc1c(%rip), %rsi      # 0x16919
movl $0x8, %edi
xorl %eax, %eax
callq 0x5d74
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
je 0x9d2e
movq 0x8(%rsp), %rdi
callq 0xe88a
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x90(%rsp), %rsi
testq %rsi, %rsi
je 0x9d45
movq 0x8(%rsp), %rdi
callq 0xe88a
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 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0xe882
shlq $0x2, %r15
movq %rax, 0x30(%rsp)
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x31b0
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdi
callq 0xe882
movq %rax, 0x38(%rsp)
movq %rbx, %r15
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
je 0x9f24
movl $0x400, %r14d           # imm = 0x400
movq $0x0, 0x28(%rsp)
xorl %r8d, %r8d
movq 0x30(%rsp), %rsi
leaq -0x1(%rcx), %rbx
movq %rbx, 0x18(%rsp)
movq 0x10(%rsp), %rax
movslq -0x4(%rax,%rcx,4), %rbp
leal 0x1f(%rbp), %edx
testq %rbp, %rbp
cmovnsl %ebp, %edx
movl $0x1, %r13d
movl %ebp, %ecx
shll %cl, %r13d
sarl $0x5, %edx
movslq %edx, %r12
movl (%rsi,%r12,4), %ecx
btl %ebp, %ecx
jb 0x9f16
leaq 0x1(%r8), %rcx
cmpq %r14, %rcx
movq %rcx, 0x48(%rsp)
jbe 0x9e58
movq %r15, %rdi
movq %r8, %r15
testq %r14, %r14
leaq (%r14,%r14), %r14
movl $0x8, %eax
cmoveq %rax, %r14
cmpq %rcx, %r14
cmovbeq %rcx, %r14
leaq (,%r14,4), %rdx
movq 0x38(%rsp), %rsi
callq 0xe892
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %rcx
movq 0x30(%rsp), %rsi
movq %r15, %r8
movq %rcx, %r15
movq 0x38(%rsp), %rcx
movl %ebp, (%rcx,%r8,4)
leaq (,%rbp,8), %rcx
addq %rbp, %rcx
movq 0x58(%rsp), %rdi
leaq (%rdi,%rcx,8), %rdx
orl %r13d, (%rsi,%r12,4)
movslq 0xc(%rdi,%rcx,8), %rsi
incl 0x340(%r15,%rsi,4)
movslq 0x14(%rdi,%rcx,8), %rsi
testq %rsi, %rsi
leaq 0x14(%rsi,%rdx), %r12
cmoveq %rsi, %r12
movslq 0x10(%rdi,%rcx,8), %rbp
movq 0x20(%rsp), %rcx
leaq (%rbx,%rbp), %r13
cmpq %rcx, %r13
jbe 0x9ee3
movq %r15, %rdi
leaq (%rcx,%rcx), %r15
testq %rcx, %rcx
movl $0x8, %ecx
cmoveq %rcx, %r15
cmpq %r13, %r15
cmovbeq %r13, %r15
leaq (,%r15,4), %rdx
movq %rax, %rsi
callq 0xe892
movq %rax, 0x10(%rsp)
movq %r15, 0x20(%rsp)
movq 0x8(%rsp), %r15
movq 0x28(%rsp), %rcx
incl %ecx
movq %rcx, 0x28(%rsp)
movq %r13, 0x18(%rsp)
leaq (%rax,%rbx,4), %rdi
shlq $0x2, %rbp
movq %r12, %rsi
movq %rbp, %rdx
callq 0x3290
movq 0x18(%rsp), %rbx
movq 0x48(%rsp), %r8
movq 0x30(%rsp), %rsi
movq %rbx, %rcx
testq %rbx, %rbx
jne 0x9dc2
jmp 0x9f32
movq $0x0, 0x28(%rsp)
movq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0xe88a
movq 0x28(%rsp), %rbx
leaq 0x100(%r15), %rdi
movslq %ebx, %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0xd78c
movq %rax, %rbp
movq %r12, %rdx
shlq $0x6, %rdx
movq %rax, %rdi
xorl %esi, %esi
movq %rdx, 0x30(%rsp)
callq 0x31b0
movl %ebx, %r14d
movq %r12, 0x80(%rsp)
testl %r12d, %r12d
movq 0x58(%rsp), %rsi
movq 0x38(%rsp), %rdi
jle 0x9fb0
leaq 0x2(%rbp), %rax
xorl %ecx, %ecx
movslq (%rdi,%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, %r14
jne 0x9f8d
movq 0xa8(%r15), %rax
testq %rax, %rax
je 0xa040
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, 0x28(%rsp)
jle 0xa040
movl 0x4(%rax), %r13d
leaq 0x10(%rbp), %r15
xorl %ebx, %ebx
movq 0x38(%rsp), %rax
movslq (%rax,%rbx,4), %rdx
shlq $0x4, %rdx
addq 0x88(%rsp), %rdx
movq %r12, %rdi
movl %r13d, %esi
callq 0xd2a1
testq %rax, %rax
je 0xa034
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 %rbx
addq $0x40, %r15
cmpq %rbx, %r14
jne 0x9ff6
cmpl $0x0, 0x28(%rsp)
movq 0x8(%rsp), %rbx
movq 0x58(%rsp), %r15
je 0xa166
movq 0x30(%rsp), %rax
leaq (%rax,%rbp), %r13
bsrq 0x80(%rsp), %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0xbe83
cmpl $0x11, 0x28(%rsp)
jl 0xa15b
leaq 0x400(%rbp), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0xc396
movq (%r12), %rax
movl %eax, %ecx
shrl $0x10, %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 0xa113
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 0xa0e7
movq %rax, %xmm0
movd %xmm0, (%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 0xa098
jmp 0xa166
movq %rbp, %rdi
movq %r13, %rsi
callq 0xc396
leaq 0xe8(%rbx), %rdi
movq 0x40(%rsp), %rax
movslq 0x4(%rax), %r13
movq %rbx, %rsi
movq %r13, %rdx
callq 0x8844
movq %rax, %r12
testl %r13d, %r13d
je 0xa19d
shlq $0x2, %r13
movq %r12, %rdi
movl $0xff, %esi
movq %r13, %rdx
callq 0x31b0
movq 0x28(%rsp), %rcx
testl %ecx, %ecx
jle 0xa1d0
addq $0x8, %rbp
xorl %eax, %eax
movq (%rbp), %rdx
subq %r15, %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, %r14
jne 0xa1ac
movq 0x40(%rsp), %rax
movl 0x4(%rax), %edx
leaq 0xc3fe(%rip), %rsi      # 0x165dd
movl $0x8, %edi
movq 0x30(%rsp), %r8
xorl %eax, %eax
callq 0x5d74
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0xa213
movq %rbx, %rdi
callq 0xe88a
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpq $0x0, 0x38(%rsp)
je 0xa228
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
callq 0xe88a
leaq 0x54(%rsp), %rdi
callq 0x5a06
movb $0x1, %al
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc6ab(%rip), %rdi      # 0x168f8
xorl %eax, %eax
callq 0x5a61
jmp 0xa262
jmp 0xa262
jmp 0xa262
jmp 0xa262
jmp 0xa262
jmp 0xa262
jmp 0xa262
movq %rax, %rbx
leaq 0x54(%rsp), %rdi
callq 0x5a06
movq %rbx, %rdi
callq 0x35e0