// File: /workspace/github_cpp_makefile_star2_O3/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 0x6b12
movabsq $0x3000000000, %r15     # imm = 0x3000000000
testq %rax, %rax
je 0x459a
movq %r14, %rdi
callq 0x63ea
cmpq $0x1, %rax
jne 0x45a1
xorl %ebx, %ebx
jmp 0x46a7
movq %r14, %rdi
callq 0x6112
movq %rax, %r15
leaq 0x18(%rsp), %r12
leaq 0x8(%rsp), %r13
movq %r14, %rdi
callq 0x613c
cmpq %rax, %r15
je 0x4604
cmpq $0x0, 0x8(%r15)
je 0x45fe
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 0x4e54
incl (%rax)
movq (%r15), %rax
addq 0x8(%r15), %rax
leaq (%rbx,%rbp), %rcx
incq %rcx
incq %rbx
cmpq %rax, %rcx
jne 0x45cf
addq $0x20, %r15
jmp 0x45b6
movq %r14, %rdi
callq 0x63ea
movq %rax, %r15
movq %r14, %rdi
callq 0x63ea
movq %rax, %r14
movq 0x30(%rsp), %r12
leaq 0x20(%rsp), %rax
cmpq %rax, %r12
je 0x4698
shrq %r15
incq %r14
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movb $0x5f, %r13b
leaq 0x20(%r12), %rsi
movq 0x10(%rsp), %rdi
callq 0x6ac2
testb %al, %al
jne 0x4677
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 0x4677
movl 0x20(%r12), %ebx
movb 0x24(%r12), %r13b
movq %rax, %r14
movq %r12, %rdi
callq 0x2280
movq %rax, %r12
leaq 0x20(%rsp), %rax
cmpq %rax, %r12
jne 0x4637
movzbl %r13b, %r15d
shlq $0x20, %r15
movl %ebx, %ebx
jmp 0x46a7
movabsq $0x5f00000000, %r15     # imm = 0x5F00000000
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
orq %r15, %rbx
leaq 0x18(%rsp), %rdi
callq 0x518e
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x46d2
jmp 0x46d2
jmp 0x46d2
jmp 0x46d2
jmp 0x46d2
jmp 0x46d2
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x518e
movq %rbx, %rdi
callq 0x2360