// File: /workspace/github_cpp_makefile_star2_O2/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 0xfb79
movq %rdi, %rbx
movb $0x1, 0x3d(%rdi)
xorl %r14d, %r14d
xorl %r15d, %r15d
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
movslq 0x38(%rbx), %rax
cmpq %rax, %r14
jge 0xfb4e
movl %r15d, 0x14(%rsp)
movq %r14, 0x30(%rbx)
movq 0x40(%rbx), %r12
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpq 0x48(%rbx), %r12
je 0xfa7e
movq (%r12), %rdi
callq 0x6b98
movl %eax, %r15d
movq (%r12), %rdi
movq 0x10(%rdi), %rax
subq 0x8(%rdi), %rax
shrq $0x3, %rax
decl %eax
cmpl %eax, 0x30(%rdi)
jl 0xfa6e
cmpl $0x1, %r15d
sbbl $-0x1, %r13d
callq 0x6f0e
testb %al, %al
jne 0xfa77
addl %r15d, %ebp
addq $0x8, %r12
jmp 0xfa34
pushq $-0x1
popq %r13
movl %r13d, %ebp
cmpl 0x10(%rsp), %r13d
movl 0x14(%rsp), %r15d
jle 0xfaa3
movl %ebp, %r15d
movl %r14d, 0xc(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
movl %r13d, 0x10(%rsp)
jmp 0xfb46
jne 0xfb46
cmpl %r15d, %ebp
jle 0xfac2
movl %ebp, %r15d
movl %r14d, 0xc(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
jmp 0xfb46
movq 0xa8(%rbx), %rax
cmpq 0xb0(%rbx), %rax
setne %al
movl %ebp, %ecx
orl %r15d, %ecx
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xfb21
movq %rbx, %rdi
movl %r14d, %esi
callq 0x6fec
movl 0x8(%rsp), %ebp
addl %eax, %ebp
callq 0x6120
cltd
movl %ebp, 0x8(%rsp)
idivl %ebp
movl %edx, %r15d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x6fec
cmpl %eax, %r15d
movl 0xc(%rsp), %eax
cmovll %r14d, %eax
movl %eax, 0xc(%rsp)
xorl %r15d, %r15d
jmp 0xfb46
cmpl %r15d, %ebp
jne 0xfb46
callq 0x6120
movl 0x8(%rsp), %ecx
incl %ecx
cltd
movl %ecx, 0x8(%rsp)
idivl %ecx
testl %edx, %edx
movl 0xc(%rsp), %eax
cmovel %r14d, %eax
movl %eax, 0xc(%rsp)
incq %r14
jmp 0xfa15
movb $0x0, 0x3d(%rbx)
movq 0xc0(%rbx), %rax
cmpl $0x1, 0x58(%rax)
je 0xfb66
cmpl $0x0, 0x8(%rsp)
jle 0xfb96
movl 0xc(%rsp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12d77(%rip), %rdi     # 0x228f7
leaq 0x12d79(%rip), %rsi     # 0x22900
leaq 0x12dd4(%rip), %rcx     # 0x22962
pushq $0x3d
popq %rdx
callq 0x6310
leaq 0x12dea(%rip), %rdi     # 0x22987
leaq 0x12d5c(%rip), %rsi     # 0x22900
leaq 0x12db7(%rip), %rcx     # 0x22962
movl $0x85, %edx
callq 0x6310
nop