// File: /workspace/github_cpp_makefile_star2_O1/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 0xf1c2
movq %rdi, %rbx
movb $0x1, 0x3d(%rdi)
cmpl $0x0, 0x38(%rdi)
jle 0xf19a
xorl %r15d, %r15d
movl $0x0, 0x14(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
xorl %ebp, %ebp
movl %ebp, 0x10(%rsp)
movq %r15, 0x30(%rbx)
movq 0x40(%rbx), %r13
movl $0x0, %ebp
movl $0x0, %r12d
cmpq 0x48(%rbx), %r13
je 0xf07e
addq $0x8, %r13
xorl %r12d, %r12d
xorl %ebp, %ebp
movq -0x8(%r13), %rdi
callq 0x5e8a
movl %eax, %r14d
addl %eax, %ebp
movq -0x8(%r13), %rdi
movq 0x10(%rdi), %rax
subq 0x8(%rdi), %rax
shrq $0x3, %rax
decl %eax
cmpl %eax, 0x30(%rdi)
jl 0xf06b
callq 0x6230
testb %al, %al
je 0xf063
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movb $0x1, %al
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0xf06d
cmpl $0x1, %r14d
sbbl $-0x1, %r12d
xorl %eax, %eax
testb %al, %al
jne 0xf07e
leaq 0x8(%r13), %rax
cmpq 0x48(%rbx), %r13
movq %rax, %r13
jne 0xf026
cmpl 0x14(%rsp), %r12d
jle 0xf099
movl %r15d, 0xc(%rsp)
movl $0x1, 0x8(%rsp)
movl %r12d, 0x14(%rsp)
jmp 0xf0b8
jne 0xf0b4
movl 0x10(%rsp), %r14d
cmpl %r14d, %ebp
jle 0xf0cd
movl %r15d, 0xc(%rsp)
movl $0x1, 0x8(%rsp)
jmp 0xf0b8
movl 0x10(%rsp), %ebp
incq %r15
movslq 0x38(%rbx), %rax
cmpq %rax, %r15
jl 0xf000
jmp 0xf18c
movq 0xa8(%rbx), %rax
cmpq 0xb0(%rbx), %rax
je 0xf156
testl %ebp, %ebp
jne 0xf156
testl %r14d, %r14d
jne 0xf156
movq 0xb0(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rdx
movl $0x1, %ebp
movl $0x1, %ecx
cmpq %rdx, %r15
jge 0xf10a
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 0xf141
movl (%rax,%r15,4), %ebp
cmpl %ebp, %edx
movl 0xc(%rsp), %eax
cmovll %r15d, %eax
movl %eax, 0xc(%rsp)
xorl %ebp, %ebp
jmp 0xf0b8
cmpl %r14d, %ebp
jne 0xf184
callq 0x5100
movl 0x8(%rsp), %ecx
incl %ecx
cltd
movl %ecx, 0x8(%rsp)
idivl %ecx
testl %edx, %edx
cmovnel %r14d, %ebp
movl 0xc(%rsp), %eax
cmovel %r15d, %eax
movl %eax, 0xc(%rsp)
jmp 0xf0b8
movl %r14d, %ebp
jmp 0xf0b8
cmpl $0x0, 0x8(%rsp)
setg %dl
movl 0xc(%rsp), %eax
jmp 0xf19e
xorl %eax, %eax
xorl %edx, %edx
movb $0x0, 0x3d(%rbx)
movq 0xc0(%rbx), %rcx
cmpl $0x1, 0x58(%rcx)
je 0xf1b3
testb %dl, %dl
je 0xf1e1
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17736(%rip), %rdi     # 0x268ff
leaq 0x17738(%rip), %rsi     # 0x26908
leaq 0x17793(%rip), %rcx     # 0x2696a
movl $0x3d, %edx
callq 0x52c0
leaq 0x177a7(%rip), %rdi     # 0x2698f
leaq 0x17719(%rip), %rsi     # 0x26908
leaq 0x17774(%rip), %rcx     # 0x2696a
movl $0x85, %edx
callq 0x52c0