// File: /workspace/github_cpp_makefile_star2_O2/WShabti-Team[P]WShabtiPict/wshabtilib/api/model.cpp
// Function: pictcore::Model::markUndefinedValuesInResultParams()
void Model::markUndefinedValuesInResultParams()
{
    // don't bother if no result parameters were defined
    if( GetResultParameterCount() <= 0 ) return;

    
    // set up an auxiliary structure that for each result parameter holds
    // an array of as many elements as there are rows in the output; each
    // element is a set of integers

    // for each result param
    // initilize a vector of N lists, where N = number of rows

    map< Parameter*, vector< set< int > > > excludedResultValues;

    vector< set< int > > emptyVector;
    emptyVector.resize( m_results.size() );
    for( ParamCollection::iterator ip = m_parameters.begin(); ip != m_parameters.end(); ++ip )
    {
        if( ( *ip )->IsExpectedResultParam() )
        {
            excludedResultValues.insert( make_pair( *ip, emptyVector ) );
        }
    }

    // remove excluded elements
    // for each result row (i_row)
    //   for each exclusion (i_excl)
    //     if non-result items of i_excl consistent with i_row
    //     for each result param of i_excl (i_param)
    //       remove value of i_param from corresponding set in structure

    int row_idx = 0;
    for( ResultCollection::iterator i_row = m_results.begin();
                                    i_row != m_results.end(); ++i_row, ++row_idx )
    {
        for( ExclusionCollection::iterator i_excl = m_exclusions.begin();
                                           i_excl != m_exclusions.end(); ++i_excl )
        {
            // only look at exclusions that have only one result param in them
            // if there are two or more, they will skew the true picture
            if( i_excl->ResultParamCount() > 1 ) continue;

            bool matches = true;
            for( Exclusion::iterator i_term = i_excl->begin();
                                     i_term != i_excl->end(); ++i_term )
            {
                // TODO: when result params are suported check modl/modl021.txt doesn't break here
                if( !i_term->first->IsExpectedResultParam()
                &&  i_row->at( i_term->first->GetSequence() ) != i_term->second )
                {
                    matches = false;
                    break;
                }
            }

            if( matches )
            {
                for( Exclusion::iterator i_term = i_excl->begin();
                                         i_term != i_excl->end(); ++i_term )
                {
                    if( i_term->first->IsExpectedResultParam() )
                    {
                        excludedResultValues[ i_term->first ][ row_idx ].insert( i_term->second );
                    }
                }
            }
        }
    }

    DOUT( L"-- result param map --\n" );
    for( auto ip = excludedResultValues.begin(); ip != excludedResultValues.end(); ++ip )
    {
        DOUT( ip->first->GetName() << ":\n" );
        for( auto iv = ip->second.begin(); iv != ip->second.end(); ++iv )
        {
            for( auto il = iv->begin(); il != iv->end(); ++il )
            {
                DOUT( *il << L" " );
            }
            DOUT( "\n" );
        }
    }

    //mark output rows as unknown

    //for each i_row in S
    //for each result param (i_param) in i_row
    //if i_param's set is empty
    //mark corresponding result value in the output as unknown

    for( map< Parameter*, vector< set< int > > >::iterator ip = excludedResultValues.begin();
                                                           ip != excludedResultValues.end();
                                                           ++ip )
    {
        int col = ( ip->first )->GetSequence();

        for( size_t row = 0; row < ip->second.size(); ++row )
        {
            // all values have to be excluded except for 1
            if( ip->second[ row ].size() != ip->first->GetValueCount() - 1 )
            {
                m_results[ row ][ col ] = Parameter::UndefinedValue;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
callq 0xc4cc
testq %rax, %rax
je 0xada7
leaq 0x40(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq 0xd8(%rbx), %rax
subq 0xd0(%rbx), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
movq %rax, %rsi
callq 0xc4ec
movq 0x8(%rbx), %r15
leaq 0x70(%rsp), %r14
leaq 0x68(%rsp), %r12
leaq 0x20(%rsp), %r13
leaq 0x38(%rsp), %rbp
cmpq 0x10(%rbx), %r15
je 0xac3e
movq (%r15), %rax
cmpb $0x1, 0x3c(%rax)
jne 0xac38
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xccbe
movq %rbp, %rdi
movq %r12, %rsi
callq 0xe88e
movq %r14, %rdi
callq 0xc594
addq $0x8, %r15
jmp 0xac08
movq 0xd0(%rbx), %r14
leaq 0x28(%rbx), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x38(%rsp), %r15
movq %rbx, 0x10(%rsp)
cmpq 0xd8(%rbx), %r14
je 0xad2a
movq 0x38(%rbx), %r12
imulq $0x30, 0x8(%rsp), %rbx
cmpq 0x18(%rsp), %r12
je 0xad17
leaq 0x20(%r12), %rdi
callq 0x9a8a
cmpq $0x1, %rax
jbe 0xaca0
movq %r12, %rdi
callq 0x6500
movq %rax, %r12
jmp 0xac78
movq 0x38(%r12), %r13
leaq 0x28(%r12), %rbp
cmpq %rbp, %r13
je 0xacdb
movq 0x20(%r13), %rax
cmpb $0x0, 0x3c(%rax)
jne 0xacce
movslq 0x2c(%rax), %rsi
movq %r14, %rdi
callq 0xc522
movslq 0x28(%r13), %rcx
cmpq %rcx, (%rax)
jne 0xac93
movq %r13, %rdi
callq 0x6500
movq %rax, %r13
jmp 0xacaa
movq 0x38(%r12), %r13
cmpq %rbp, %r13
je 0xac93
movq 0x20(%r13), %rax
cmpb $0x1, 0x3c(%rax)
jne 0xad0a
leaq 0x20(%r13), %rsi
movq %r15, %rdi
callq 0xc544
movq (%rax), %rdi
addq %rbx, %rdi
leaq 0x28(%r13), %rsi
callq 0xebf0
movq %r13, %rdi
callq 0x6500
movq %rax, %r13
jmp 0xace0
addq $0x18, %r14
incq 0x8(%rsp)
movq 0x10(%rsp), %rbx
jmp 0xac61
movq %rbx, %r15
movq 0x50(%rsp), %rdi
pushq $0x30
popq %rbx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x40(%rsp), %r12
cmpq %r12, %rdi
je 0xad93
movq 0x20(%rdi), %rcx
movq 0x28(%rdi), %rsi
movslq 0x2c(%rcx), %r8
movq 0x30(%rdi), %rax
subq %rsi, %rax
cqto
idivq %rbx
movq 0xd0(%r15), %rdx
xorl %r9d, %r9d
subq $0x1, %rax
jb 0xad89
movslq 0x38(%rcx), %r10
decq %r10
cmpq %r10, 0x28(%rsi,%r9,2)
je 0xad83
movq (%rdx,%r9), %r10
movq %r14, (%r10,%r8,8)
addq $0x18, %r9
jmp 0xad67
callq 0x6320
movq %rax, %rdi
jmp 0xad40
leaq 0x20(%rsp), %rdi
callq 0xc594
leaq 0x38(%rsp), %rdi
callq 0xd09c
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xadce
jmp 0xadce
movq %rax, %rbx
movq %r14, %rdi
callq 0xc594
jmp 0xadd1
jmp 0xadce
jmp 0xadce
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xc594
leaq 0x38(%rsp), %rdi
callq 0xd09c
movq %rbx, %rdi
callq 0x66e0
nop