// File: /workspace/github_c_makefile_star2_O3/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, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, %r12
movq %rdx, 0x58(%rsp)
movl %esi, %r15d
movq %rdi, %rbp
leaq 0xf(%rsp), %rdi
callq 0x41ee0
leaq 0x18c12(%rip), %rdi     # 0x558c6
callq 0x40c20
leaq 0x74(%rsp), %r13
movl %eax, (%r13)
leaq 0x18dbc(%rip), %rdi     # 0x55a85
callq 0x40c20
movl %eax, 0x4(%r13)
leaq 0x18cd3(%rip), %rdi     # 0x559ac
callq 0x40c20
movl %eax, 0x8(%r13)
leaq 0x18ccd(%rip), %rdi     # 0x559b6
callq 0x40c20
leaq 0x68(%rsp), %r14
movl %eax, (%r14)
leaq 0x18cf1(%rip), %rdi     # 0x559ee
callq 0x40c20
movl %eax, 0x4(%r14)
leaq 0x18caf(%rip), %rdi     # 0x559bc
callq 0x40c20
movl %eax, 0x8(%r14)
leaq 0x18d23(%rip), %rdi     # 0x55a40
callq 0x40c20
leaq 0x60(%rsp), %rbx
movl %eax, (%rbx)
leaq 0x18ce8(%rip), %rdi     # 0x55a18
callq 0x40c20
movl %eax, 0x4(%rbx)
movabsq $0x300000003, %rax      # imm = 0x300000003
leaq 0x80(%rsp), %rdi
movq %rax, (%rdi)
movl $0x2, 0x8(%rdi)
movq %r13, 0x10(%rdi)
movq %r14, 0x18(%rdi)
movq %rbx, 0x20(%rdi)
movl %r15d, 0x28(%rdi)
movq %rbp, 0x30(%rdi)
xorl %eax, %eax
movq %rax, 0x38(%rdi)
movl $0x0, 0x40(%rdi)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %r15
movaps %xmm0, (%r15)
movq %rax, 0x10(%r15)
leaq 0x10(%rsp), %rcx
movaps %xmm0, (%rcx)
movq %rax, 0x10(%rcx)
leaq 0xf(%rsp), %rsi
movq %r15, %rdx
callq 0x424cc
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x3cdd7
movq 0x30(%rsp), %r15
leaq (%rax,%rax,2), %rcx
leaq (%r15,%rcx,4), %r13
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x3d058
movq %r15, %rdi
movq %r13, %rsi
callq 0x3d117
movq 0x18(%rsp), %rax
testq %rax, %rax
je 0x3ce0d
movq 0x10(%rsp), %r15
leaq (%r15,%rax,8), %r13
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x3d608
movq %r15, %rdi
movq %r13, %rsi
callq 0x3d6b7
cmpq %r12, 0x38(%rsp)
jne 0x3ce6d
movq 0x30(%rsp), %rdi
shlq $0x2, %r12
leaq (%r12,%r12,2), %rdx
movq 0x58(%rsp), %rsi
callq 0xc630
xorl %ebp, %ebp
testl %eax, %eax
jne 0x3ce7b
movq 0x50(%rsp), %rbx
cmpq %rbx, 0x18(%rsp)
jne 0x3ce7b
testq %rbx, %rbx
je 0x3ce71
movq 0x10(%rsp), %r15
xorl %r14d, %r14d
movq 0x48(%rsp), %r12
movq (%r12,%r14,8), %rdi
movq (%r15,%r14,8), %rsi
callq 0xc900
testl %eax, %eax
jne 0x3ce74
incq %r14
cmpq %r14, %rbx
jne 0x3ce4f
movq %rbx, %r14
jmp 0x3ce74
xorl %ebp, %ebp
jmp 0x3ce7b
xorl %r14d, %r14d
cmpq %rbx, %r14
sete %bpl
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x3cea0
leaq 0xf(%rsp), %rdi
callq 0x41eea
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x30(%rsp), %rsi
testq %rsi, %rsi
je 0x3cec5
leaq 0xf(%rsp), %rdi
callq 0x41eea
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
leaq 0xf(%rsp), %rdi
callq 0x41ee1
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop