// File: /workspace/github_cpp_makefile_star2_O3/WShabti-Team[P]WShabtiPict/wshabtilib/api/parameter.cpp
// Function: pictcore::Parameter::PickValue()
int Parameter::PickValue()
{
    assert(!m_bound);

    int maxComplete    = 0;
    int maxTotal       = 0;
    int bestValue      = 0;
    int bestValueCount = 0;

    m_bound = true; // a white lie to facilitate Combination::Feasible()

    for (int value = 0; value < m_valueCount; ++value)
    {
        int totalZeros = 0;
        int complete   = 0;
        // try binding that value and see how feasible it is
        m_currentValue = value;

        for (ComboCollection::iterator iter = m_combinations.begin(); iter != m_combinations.end(); ++iter)
        {
            int zeros = (*iter)->Feasible();
            totalZeros += zeros;
            if ((*iter)->GetBoundCount() >= (*iter)->GetParameterCount() - 1)
            {
                if (zeros)
                    ++complete;

                if ((*iter)->ViolatesExclusion())
                {
                    // make sure we don't pick this value, and move on
                    totalZeros = -1;
                    complete   = -1;
                    break;
                }
            }
        }
        if (complete > maxComplete)
        {
            maxComplete    = complete;
            bestValue      = value;
            maxTotal       = totalZeros;
            bestValueCount = 1;
        }
        else if (complete == maxComplete)
        {
            if (totalZeros > maxTotal)
            {
                bestValue      = value;
                maxTotal       = totalZeros;
                bestValueCount = 1;
            }
            else if (!m_valueWeights.empty() && 0 == totalZeros && 0 == maxTotal)
            {
                // Arbitrary choice - we already have this parameter covered
                // Use weights if they exist
                bestValueCount += GetWeight(value);
                if (rand() % bestValueCount < GetWeight(value))
                {
                    bestValue = value;
                }
            }
            else if (totalZeros == maxTotal && !(rand() % ++bestValueCount))
            {
                bestValue = value;
                maxTotal  = totalZeros;
            }
        }
    }
    m_bound = false;

    // What if bestValueCount is 0 here due to exclusions?
    // That would be a bug, but better put in a check.
    if( m_task->GetGenerationMode() != Preview )
    {
        assert( bestValueCount > 0 );
        if( bestValueCount <= 0 )
        {
            throw GenerationError( __FILE__, __LINE__, GenerationFailure );
        }
    }

    return bestValue;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpb $0x1, 0x3d(%rdi)
je 0xefdd
movq %rdi, %rbx
movb $0x1, 0x3d(%rdi)
cmpl $0x0, 0x38(%rdi)
jle 0xefb5
xorl %r15d, %r15d
movl $0x0, 0x14(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
movq %r15, 0x30(%rbx)
movq 0x40(%rbx), %r13
movl $0x0, %ebp
movl $0x0, %r12d
cmpq 0x48(%rbx), %r13
je 0xee9c
xorl %r12d, %r12d
xorl %ebp, %ebp
movq (%r13), %rdi
callq 0x5ea0
movl %eax, %r14d
movq (%r13), %rdi
movq 0x10(%rdi), %rax
subq 0x8(%rdi), %rax
shrq $0x3, %rax
decl %eax
cmpl %eax, 0x30(%rdi)
jl 0xee82
cmpl $0x1, %r14d
sbbl $-0x1, %r12d
callq 0x6276
testb %al, %al
jne 0xee91
addl %r14d, %ebp
addq $0x8, %r13
cmpq 0x48(%rbx), %r13
jne 0xee4e
jmp 0xee9c
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl 0x14(%rsp), %r12d
jle 0xeebe
movl %ebp, 0x10(%rsp)
movl %r15d, 0xc(%rsp)
movl $0x1, 0x8(%rsp)
movl %r12d, 0x14(%rsp)
jmp 0xef97
jne 0xef97
movl 0x10(%rsp), %edi
cmpl %edi, %ebp
jle 0xeee2
movl %ebp, 0x10(%rsp)
movl %r15d, 0xc(%rsp)
movl $0x1, 0x8(%rsp)
jmp 0xef97
movq 0xa8(%rbx), %rax
movq 0xb0(%rbx), %rcx
cmpq %rcx, %rax
setne %dl
movl %ebp, %esi
orl %edi, %esi
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xef73
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rdx
movl $0x1, %ebp
movl $0x1, %ecx
cmpq %rdx, %r15
jge 0xef24
movl (%rax,%r15,4), %ecx
movl 0x8(%rsp), %r14d
addl %ecx, %r14d
callq 0x5100
cltd
movl %r14d, 0x8(%rsp)
idivl %r14d
movq 0xa8(%rbx), %rax
movq 0xb0(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r15
jge 0xef5b
movl (%rax,%r15,4), %ebp
cmpl %ebp, %edx
movl 0xc(%rsp), %eax
cmovll %r15d, %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
jmp 0xef97
cmpl %edi, %ebp
jne 0xef97
callq 0x5100
movl 0x8(%rsp), %ecx
incl %ecx
cltd
movl %ecx, 0x8(%rsp)
idivl %ecx
testl %edx, %edx
movl 0xc(%rsp), %eax
cmovel %r15d, %eax
movl %eax, 0xc(%rsp)
incq %r15
movslq 0x38(%rbx), %rax
cmpq %rax, %r15
jl 0xee30
cmpl $0x0, 0x8(%rsp)
setg %dl
movl 0xc(%rsp), %eax
jmp 0xefb9
xorl %eax, %eax
xorl %edx, %edx
movb $0x0, 0x3d(%rbx)
movq 0xc0(%rbx), %rcx
cmpl $0x1, 0x58(%rcx)
je 0xefce
testb %dl, %dl
je 0xeffc
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1791b(%rip), %rdi     # 0x268ff
leaq 0x1791d(%rip), %rsi     # 0x26908
leaq 0x17978(%rip), %rcx     # 0x2696a
movl $0x3d, %edx
callq 0x52c0
leaq 0x1798c(%rip), %rdi     # 0x2698f
leaq 0x178fe(%rip), %rsi     # 0x26908
leaq 0x17959(%rip), %rcx     # 0x2696a
movl $0x85, %edx
callq 0x52c0
nop