// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]tundra/unittest/Test_TargetSelect.cpp
// Function: TargetSelectTest::RunTest(char const**, int, t2::TargetSpec const*, unsigned long, char const**, unsigned long)
static bool RunTest(
      const char** names, int name_count,
      const TargetSpec* expected_specs, size_t expected_spec_count,
      const char** expected_names, size_t expected_name_count)
  {
    MemAllocHeap heap;
    HeapInit(&heap);

    uint32_t config_hashes[ARRAY_SIZE(s_Configs)]         = { Djb2Hash(s_Configs[0]), Djb2Hash(s_Configs[1]), Djb2Hash(s_Configs[2]) };
    uint32_t variant_hashes[ARRAY_SIZE(s_Variants)]       = { Djb2Hash(s_Variants[0]), Djb2Hash(s_Variants[1]), Djb2Hash(s_Variants[2]) };
    uint32_t subvariant_hashes[ARRAY_SIZE(s_SubVariants)] = { Djb2Hash(s_SubVariants[0]), Djb2Hash(s_SubVariants[1]) };

    TargetSelectInput input;
    input.m_ConfigCount = ARRAY_SIZE(config_hashes);
    input.m_VariantCount = ARRAY_SIZE(variant_hashes);
    input.m_SubVariantCount = ARRAY_SIZE(subvariant_hashes);
    input.m_ConfigNameHashes = config_hashes;
    input.m_VariantNameHashes = variant_hashes;
    input.m_SubVariantNameHashes = subvariant_hashes;

    input.m_InputNameCount = name_count;
    input.m_InputNames = names;

    input.m_DefaultConfigIndex = 0;
    input.m_DefaultVariantIndex = 0;
    input.m_DefaultSubVariantIndex = 0;

    Buffer<TargetSpec> specs;
    Buffer<const char*> target_names;

    BufferInit(&specs);
    BufferInit(&target_names);

    SelectTargets(input, &heap, &specs, &target_names);

    std::sort(specs.m_Storage, specs.m_Storage + specs.m_Size);
    std::sort(target_names.m_Storage, target_names.m_Storage + target_names.m_Size, [](const char* l, const char* r) { return strcmp(l, r) < 0; });

    bool success = false;

    if (specs.m_Size == expected_spec_count)
    {
      if (0 == memcmp(specs.m_Storage, expected_specs, sizeof(TargetSpec) * expected_spec_count))
      {
        if (target_names.m_Size == expected_name_count)
        {
          size_t i = 0;
          for ( ; i < expected_name_count; ++i)
          {
            if (0 != strcmp(expected_names[i], target_names[i]))
            {
              break;
            }
          }

          if (i == expected_name_count)
          {
            success = true;
          }
        }
      }
    }

    BufferDestroy(&target_names, &heap);
    BufferDestroy(&specs, &heap);

    HeapDestroy(&heap);

    return success;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, %rbx
movq %r8, %r14
movq %rcx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movq %rdi, %rbp
leaq 0xb(%rsp), %rdi
callq 0x350bc
leaq 0x17597(%rip), %rdi     # 0x478a6
callq 0x33f4e
leaq 0x74(%rsp), %r13
movl %eax, (%r13)
leaq 0x17741(%rip), %rdi     # 0x47a65
callq 0x33f4e
movl %eax, 0x4(%r13)
leaq 0x17658(%rip), %rdi     # 0x4798c
callq 0x33f4e
movl %eax, 0x8(%r13)
leaq 0x17652(%rip), %rdi     # 0x47996
callq 0x33f4e
leaq 0x68(%rsp), %r12
movl %eax, (%r12)
leaq 0x17675(%rip), %rdi     # 0x479ce
callq 0x33f4e
movl %eax, 0x4(%r12)
leaq 0x17632(%rip), %rdi     # 0x4799c
callq 0x33f4e
movl %eax, 0x8(%r12)
leaq 0x176a5(%rip), %rdi     # 0x47a20
callq 0x33f4e
leaq 0x60(%rsp), %r15
movl %eax, (%r15)
leaq 0x17669(%rip), %rdi     # 0x479f8
callq 0x33f4e
movabsq $0x300000003, %rcx      # imm = 0x300000003
leaq 0x80(%rsp), %rdi
movq %rcx, (%rdi)
movl $0x2, 0x8(%rdi)
movq %r13, 0x10(%rdi)
movq %r12, 0x18(%rdi)
movq %r15, 0x20(%rdi)
movl 0xc(%rsp), %ecx
movl %ecx, 0x28(%rdi)
movq %rbp, 0x30(%rdi)
andq $0x0, 0x38(%rdi)
andl $0x0, 0x40(%rdi)
movl %eax, 0x4(%r15)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
leaq 0x20(%rsp), %rbp
movaps %xmm0, (%rbp)
andq $0x0, 0x10(%rbp)
leaq 0xb(%rsp), %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x3568c
movq (%r15), %rdi
imulq $0xc, 0x8(%r15), %rsi
addq %rdi, %rsi
callq 0x3067e
movq (%rbp), %rdi
movq 0x8(%rbp), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x30d4a
movq 0x18(%rsp), %rax
cmpq %rax, 0x8(%r15)
jne 0x30472
movq 0x40(%rsp), %rdi
imulq $0xc, %rax, %rdx
movq 0x10(%rsp), %rsi
callq 0xd660
xorl %ebp, %ebp
testl %eax, %eax
jne 0x30480
cmpq %rbx, 0x28(%rsp)
jne 0x30480
movq 0x20(%rsp), %r12
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x30476
movq (%r14,%r15,8), %rdi
movq (%r12,%r15,8), %rsi
callq 0xd950
testl %eax, %eax
jne 0x30479
incq %r15
jmp 0x30457
xorl %ebp, %ebp
jmp 0x30480
movq %rbx, %r15
cmpq %rbx, %r15
sete %bpl
leaq 0x20(%rsp), %rdi
leaq 0xb(%rsp), %rbx
movq %rbx, %rsi
callq 0x30636
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x3065a
movq %rbx, %rdi
callq 0x350bd
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop