// File: /workspace/github_cpp_makefile_star2_O1/chrischute[P]are-you-the-one/src/ayto.cpp
// Function: getNextTruthBoothGuess(PerfectMatchingSet const*, TruthBoothSet const*)
Tb getNextTruthBoothGuess(const PmSet* possibleAnswers, const TbSet* guessesAlreadyMade)
{
    Tb nextGuess(-1, '_');
    map<Tb, int> numOccurrencesOfMatch;

    if (guessesAlreadyMade->size() == 0 ||
            possibleAnswers->size() == 1) {
        // Nothing to gain from running minimax here.
        return Tb(0, '0');
    }

    // Count the number of occurrences in possible answers of each match.
    for (PmSet::const_iterator iterPerm = possibleAnswers->begin();
         iterPerm != possibleAnswers->end();
         ++iterPerm) {
	int i = 0;
        for (Pm::const_iterator iterChar = iterPerm->begin();
            iterChar != iterPerm->end();
            ++iterChar) {
            ++numOccurrencesOfMatch[Tb(i++, *iterChar)];
        }
    }

    // Ideally a pairing occurs in 1/2 of all possible answers.
    // The worst-case response is always the complement of the
    // best-case response. We want to optimize the worst case, which
    // occurs when both yes/no cut the remaining solutions in half.
    long optimalNumOccurrences = possibleAnswers->size() / 2;
    long closestNumOccurrences = possibleAnswers->size() + 1;

    for (map<Tb, int>::const_iterator it = numOccurrencesOfMatch.begin();
        it != numOccurrencesOfMatch.end();
        ++it) {

        if (!guessesAlreadyMade->contains(it->first) &&
                (optimalNumOccurrences - it->second) <
                abs(optimalNumOccurrences - closestNumOccurrences)) {
            nextGuess = it->first;
            closestNumOccurrences = it->second;
        }
    }

    return nextGuess;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
leaq 0x20(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq %rsi, 0x10(%rsp)
movq %rsi, %rdi
callq 0x6c60
movabsq $0x3000000000, %r15     # imm = 0x3000000000
testq %rax, %rax
je 0x4649
movq %r14, %rdi
callq 0x64f0
cmpq $0x1, %rax
jne 0x4650
xorl %ebx, %ebx
jmp 0x4756
movq %r14, %rdi
callq 0x6210
movq %rax, %r15
leaq 0x18(%rsp), %r12
leaq 0x8(%rsp), %r13
movq %r14, %rdi
callq 0x623a
cmpq %rax, %r15
je 0x46b3
cmpq $0x0, 0x8(%r15)
je 0x46ad
movq (%r15), %rbp
xorl %ebx, %ebx
movb (%rbp,%rbx), %al
movl %ebx, 0x8(%rsp)
movb %al, 0xc(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x4ef4
incl (%rax)
movq (%r15), %rax
addq 0x8(%r15), %rax
leaq (%rbx,%rbp), %rcx
incq %rcx
incq %rbx
cmpq %rax, %rcx
jne 0x467e
addq $0x20, %r15
jmp 0x4665
movq %r14, %rdi
callq 0x64f0
movq %rax, %r15
movq %r14, %rdi
callq 0x64f0
movq %rax, %r14
movq 0x30(%rsp), %r12
leaq 0x20(%rsp), %rax
cmpq %rax, %r12
je 0x4747
shrq %r15
incq %r14
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movb $0x5f, %r13b
leaq 0x20(%r12), %rsi
movq 0x10(%rsp), %rdi
callq 0x6c10
testb %al, %al
jne 0x4726
movslq 0x28(%r12), %rax
movq %r15, %rcx
subq %rax, %rcx
movq %r15, %rdx
subq %r14, %rdx
movq %rdx, %rsi
negq %rsi
cmovsq %rdx, %rsi
cmpq %rsi, %rcx
jge 0x4726
movl 0x20(%r12), %ebx
movb 0x24(%r12), %r13b
movq %rax, %r14
movq %r12, %rdi
callq 0x2290
movq %rax, %r12
leaq 0x20(%rsp), %rax
cmpq %rax, %r12
jne 0x46e6
movzbl %r13b, %r15d
shlq $0x20, %r15
movl %ebx, %ebx
jmp 0x4756
movabsq $0x5f00000000, %r15     # imm = 0x5F00000000
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
orq %r15, %rbx
leaq 0x18(%rsp), %rdi
callq 0x5258
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4781
jmp 0x4781
jmp 0x4781
jmp 0x4781
jmp 0x4781
jmp 0x4781
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x5258
movq %rbx, %rdi
callq 0x2370