// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/Driver.cpp
// Function: t2::DriverSelectNodes(t2::DagData const*, char const**, int, t2::Buffer<int>*, t2::MemAllocHeap*)
static void DriverSelectNodes(const DagData* dag, const char** targets, int target_count, Buffer<int32_t>* out_nodes, MemAllocHeap* heap)
{
  Buffer<TargetSpec> target_specs;
  Buffer<const char*> named_targets;

  BufferInit(&target_specs);
  BufferInit(&named_targets);

  TargetSelectInput tsel;
  tsel.m_ConfigCount            = dag->m_ConfigCount;
  tsel.m_VariantCount           = dag->m_VariantCount;
  tsel.m_SubVariantCount        = dag->m_SubVariantCount;
  tsel.m_ConfigNameHashes       = dag->m_ConfigNameHashes;
  tsel.m_VariantNameHashes      = dag->m_VariantNameHashes;
  tsel.m_SubVariantNameHashes   = dag->m_SubVariantNameHashes;
  tsel.m_InputNameCount         = target_count;
  tsel.m_InputNames             = targets;
  tsel.m_DefaultConfigIndex     = dag->m_DefaultConfigIndex;
  tsel.m_DefaultVariantIndex    = dag->m_DefaultVariantIndex;
  tsel.m_DefaultSubVariantIndex = dag->m_DefaultSubVariantIndex;

  SelectTargets(tsel, heap, &target_specs, &named_targets);

  for (const TargetSpec& spec : target_specs)
  {
    const BuildTupleData* tuple = FindBuildTuple(dag, spec);
    if (!tuple)
      Croak("couldn't find build tuple in DAG");

    if (named_targets.m_Size > 0)
    {
      FindNodesByName(
          dag,
          out_nodes, heap,
          named_targets.m_Storage, named_targets.m_Size,
          tuple);
    }
    else
    {
      BufferAppend(out_nodes, heap, tuple->m_DefaultNodes.GetArray(), tuple->m_DefaultNodes.GetCount());
    }

    BufferAppend(out_nodes, heap, tuple->m_AlwaysNodes.GetArray(), tuple->m_AlwaysNodes.GetCount());
  }

  std::sort(out_nodes->begin(), out_nodes->end());
  int32_t* new_end = std::unique(out_nodes->begin(), out_nodes->end());
  out_nodes->m_Size = new_end - out_nodes->begin();
  Log(kDebug, "Node selection finished with %d nodes to build", (int) out_nodes->m_Size);

  BufferDestroy(&named_targets, heap);
  BufferDestroy(&target_specs, heap);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x14c30
leaq -0x58(%rbp), %rdi
callq 0x14c60
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0xa0(%rbp)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x9c(%rbp)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x98(%rbp)
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
callq 0x14c90
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
addq $0x2c, %rdi
callq 0x14c90
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rdi
addq $0x38, %rdi
callq 0x14c90
movq %rax, -0x80(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rax
movl 0x4c(%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x28(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
leaq -0x40(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x1e2a0
leaq -0x40(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x14cb0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x14cd0
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rax
cmpq -0xb8(%rbp), %rax
je 0xe544
movq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0xd4(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0xcc(%rbp)
movq -0xd4(%rbp), %rax
movq %rax, -0xe4(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0xdc(%rbp)
movq -0xe4(%rbp), %rsi
movl -0xdc(%rbp), %edx
callq 0x10500
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
jne 0xe450
leaq 0x16533(%rip), %rdi     # 0x2497c
movb $0x0, %al
callq 0x75a0
cmpq $0x0, -0x50(%rbp)
jbe 0xe479
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0xc8(%rbp), %r9
callq 0x105b0
jmp 0xe4d3
movq -0x20(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0xc8(%rbp), %rdi
addq $0xc, %rdi
callq 0x145f0
movq %rax, -0xf8(%rbp)
movq -0xc8(%rbp), %rdi
addq $0xc, %rdi
callq 0x14610
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
movslq %eax, %rcx
callq 0x145a0
movq -0x20(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0xc8(%rbp), %rdi
addq $0x14, %rdi
callq 0x145f0
movq %rax, -0x110(%rbp)
movq -0xc8(%rbp), %rdi
addq $0x14, %rdi
callq 0x14610
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rsi
movq -0x110(%rbp), %rdx
movslq %eax, %rcx
callq 0x145a0
movq -0xb0(%rbp), %rax
addq $0xc, %rax
movq %rax, -0xb0(%rbp)
jmp 0xe3c5
movq -0x20(%rbp), %rdi
callq 0x14d30
movq %rax, -0x138(%rbp)
movq -0x20(%rbp), %rdi
callq 0x14d50
movq -0x138(%rbp), %rdi
movq %rax, %rsi
callq 0x14cf0
movq -0x20(%rbp), %rdi
callq 0x14d30
movq %rax, -0x130(%rbp)
movq -0x20(%rbp), %rdi
callq 0x14d50
movq -0x130(%rbp), %rdi
movq %rax, %rsi
callq 0x14d70
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x20(%rbp), %rdi
callq 0x14d30
movq -0x128(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
movl $0x8, %edi
leaq 0x163bf(%rip), %rsi     # 0x2499d
movb $0x0, %al
callq 0x7a60
movq -0x28(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x14db0
movq -0x28(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x14e10
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopl (%rax,%rax)