// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/TargetSelect.cpp
// Function: t2::SelectTargets(t2::TargetSelectInput const&, t2::MemAllocHeap*, t2::Buffer<t2::TargetSpec>*, t2::Buffer<char const*>*)
void SelectTargets(const TargetSelectInput& input, MemAllocHeap* heap, Buffer<TargetSpec>* output, Buffer<const char*>* target_names)
{
  if (input.m_ConfigCount > 32 || input.m_VariantCount > 32 || input.m_SubVariantCount > 32)
    Croak("too many configs/variants/subvariants -- keep it below 32");

  int spec_count = 0;
  InputSpec* specs = (InputSpec*) alloca(sizeof(InputSpec) * (input.m_InputNameCount + 1));

  uint32_t subvariant_bits = 0;
  uint32_t variant_bits    = 0;

  for (int i = 0, count = input.m_InputNameCount; i < count; ++i)
  {
    const char* input_name = input.m_InputNames[i];
    const uint32_t input_hash = Djb2Hash(input_name);
    int item_index;

    if (FindHash(&item_index, input.m_SubVariantNameHashes, input.m_SubVariantCount, input_hash))
    {
      subvariant_bits |= 1 << item_index;
    }
    else if (FindHash(&item_index, input.m_VariantNameHashes, input.m_VariantCount, input_hash))
    {
      variant_bits |= 1 << item_index;
    }
    else if (DestructureInputSpec(input, &specs[spec_count], input_name))
    {
      spec_count++;
    }
    else
    {
      BufferAppendOne(target_names, heap, input_name);
    }
  }

  if (0 == spec_count && input.m_DefaultConfigIndex >= 0)
  {
    specs[0].m_ConfigIndex     = input.m_DefaultConfigIndex;
    specs[0].m_VariantIndex    = -1;
    specs[0].m_SubVariantIndex = -1;
    spec_count = 1;
  }

  if (0 == subvariant_bits && input.m_DefaultSubVariantIndex >= 0)
    subvariant_bits |= 1 << input.m_DefaultSubVariantIndex;

  if (0 == variant_bits && input.m_DefaultVariantIndex >= 0)
    variant_bits |= 1 << input.m_DefaultVariantIndex;

  for (int i = 0; i < spec_count; ++i)
  {
    const InputSpec& spec = specs[i];

    int config_index = spec.m_ConfigIndex;

    int vbits = spec.m_VariantIndex >= 0 ? 1 << spec.m_VariantIndex : variant_bits;

    while (vbits)
    {
      int variant_index = CountTrailingZeroes(vbits);
      vbits &= ~(1 << variant_index);

      int svbits = spec.m_SubVariantIndex >= 0 ? 1 << spec.m_SubVariantIndex : subvariant_bits;

      while (svbits)
      {
        int subvariant_index = CountTrailingZeroes(svbits);
        svbits &= ~(1 << subvariant_index);

        TargetSpec spec = { config_index, variant_index, subvariant_index };

        bool found = false;

        for (size_t o = 0, count = output->m_Size; o < count; ++o)
        {
          if (output->m_Storage[o] == spec)
          {
            found = true;
            break;
          }
        }

        if (!found)
        {
          BufferAppendOne(output, heap, spec);
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x20, (%rax)
jg 0x1e2d8
movq -0x8(%rbp), %rax
cmpl $0x20, 0x4(%rax)
jg 0x1e2d8
movq -0x8(%rbp), %rax
cmpl $0x20, 0x8(%rax)
jle 0x1e2e6
leaq 0x728c(%rip), %rdi      # 0x2556b
movb $0x0, %al
callq 0x75a0
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
incl %eax
cltq
leaq (%rax,%rax,2), %rax
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1e418
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x7860
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
movl -0x4c(%rbp), %ecx
leaq -0x50(%rbp), %rdi
callq 0x1e680
testb $0x1, %al
jne 0x1e381
jmp 0x1e393
movl -0x50(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
orl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x1e408
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edx
movl -0x4c(%rbp), %ecx
leaq -0x50(%rbp), %rdi
callq 0x1e680
testb $0x1, %al
jne 0x1e3b4
jmp 0x1e3c6
movl -0x50(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
orl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x1e406
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x24(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rsi
movq -0x48(%rbp), %rdx
callq 0x1e6e0
testb $0x1, %al
jne 0x1e3e8
jmp 0x1e3f3
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1e404
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x1d730
jmp 0x1e406
jmp 0x1e408
jmp 0x1e40a
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1e334
xorl %eax, %eax
cmpl -0x24(%rbp), %eax
jne 0x1e453
movq -0x8(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jl 0x1e453
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movl $0x1, -0x24(%rbp)
xorl %eax, %eax
cmpl -0x34(%rbp), %eax
jne 0x1e478
movq -0x8(%rbp), %rax
cmpl $0x0, 0x40(%rax)
jl 0x1e478
movq -0x8(%rbp), %rax
movl 0x40(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
orl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
xorl %eax, %eax
cmpl -0x38(%rbp), %eax
jne 0x1e49d
movq -0x8(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
jl 0x1e49d
movq -0x8(%rbp), %rax
movl 0x3c(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
orl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x1e66e
movq -0x30(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jl 0x1e4ec
movq -0x60(%rbp), %rax
movl 0x4(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0xb8(%rbp)
jmp 0x1e4f5
movl -0x38(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movl %eax, -0x68(%rbp)
cmpl $0x0, -0x68(%rbp)
je 0x1e65e
movl -0x68(%rbp), %edi
callq 0x7e50
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
xorl $-0x1, %eax
andl -0x68(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jl 0x1e546
movq -0x60(%rbp), %rax
movl 0x8(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0xbc(%rbp)
jmp 0x1e54f
movl -0x34(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
movl %eax, -0x70(%rbp)
cmpl $0x0, -0x70(%rbp)
je 0x1e659
movl -0x70(%rbp), %edi
callq 0x7e50
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
xorl $-0x1, %eax
andl -0x70(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0x78(%rbp)
movb $0x0, -0x81(%rbp)
movq $0x0, -0x90(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x98(%rbp), %rax
jae 0x1e603
movq -0x18(%rbp), %rax
movq (%rax), %rdi
imulq $0xc, -0x90(%rbp), %rax
addq %rax, %rdi
leaq -0x80(%rbp), %rsi
callq 0x1e990
testb $0x1, %al
jne 0x1e5e4
jmp 0x1e5ed
movb $0x1, -0x81(%rbp)
jmp 0x1e603
jmp 0x1e5ef
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x1e5b3
testb $0x1, -0x81(%rbp)
jne 0x1e654
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x80(%rbp), %rax
movq %rax, -0xa4(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0xa4(%rbp), %rax
movq %rax, -0xb4(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0xb4(%rbp), %rdx
movl -0xac(%rbp), %ecx
callq 0x1e9e0
jmp 0x1e558
jmp 0x1e4fe
jmp 0x1e660
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1e4a4
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)