// File: /workspace/github_cpp_makefile_star2_O2/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), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rsi, 0x10(%rsp)
movq %rsi, %rdi
callq 0x6198
movabsq $0x3000000000, %r15     # imm = 0x3000000000
testq %rax, %rax
je 0x3a87
movq %r14, %rdi
callq 0x5b24
cmpq $0x1, %rax
jne 0x3a8e
xorl %ebx, %ebx
jmp 0x3b72
movq %r14, %rdi
callq 0x58ca
movq %rax, %r15
leaq 0x18(%rsp), %r12
leaq 0x8(%rsp), %r13
movq %r14, %rdi
callq 0x58f4
cmpq %rax, %r15
je 0x3aea
movq (%r15), %rbp
xorl %ebx, %ebx
movq %rbp, %rax
leaq (%rbx,%rbp), %rcx
addq 0x8(%r15), %rax
cmpq %rax, %rcx
je 0x3ae4
movb (%rcx), %al
movl %ebx, 0x8(%rsp)
movb %al, 0xc(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x42a4
incl (%rax)
movq (%r15), %rax
incq %rbx
jmp 0x3ab8
addq $0x20, %r15
jmp 0x3aa3
movq %r14, %rdi
callq 0x5b24
movq %rax, %r15
movq %r14, %rdi
callq 0x5b24
movq %rax, %r14
shrq %r15
incq %r14
movb $0x5f, %r13b
pushq $-0x1
popq %rbx
movq 0x30(%rsp), %r12
leaq 0x20(%rsp), %rax
cmpq %rax, %r12
je 0x3b68
leaq 0x20(%r12), %rsi
movq 0x10(%rsp), %rdi
callq 0x616a
testb %al, %al
jne 0x3b5b
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 0x3b5b
movl 0x20(%r12), %ebx
movb 0x24(%r12), %r13b
movq %rax, %r14
movq %r12, %rdi
callq 0x2280
movq %rax, %r12
jmp 0x3b11
movzbl %r13b, %r15d
shlq $0x20, %r15
movl %ebx, %ebx
orq %r15, %rbx
leaq 0x18(%rsp), %rdi
callq 0x45f0
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3b9d
jmp 0x3b9d
jmp 0x3b9d
jmp 0x3b9d
jmp 0x3b9d
jmp 0x3b9d
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x45f0
movq %rbx, %rdi
callq 0x2380