// File: 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
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x1bf50
cmpq $0x0, %rax
ja 0x17b6a
jmp 0x182d0
leaq -0x38(%rbp), %rdi
callq 0x1bfe0
leaq -0x50(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x1c000
movq -0x158(%rbp), %rdi
addq $0xd0, %rdi
callq 0x1c0b0
movq -0x160(%rbp), %rdi
movq %rax, %rsi
callq 0x1c020
jmp 0x17ba7
movq -0x158(%rbp), %rdi
addq $0x8, %rdi
callq 0x8c90
movq %rax, -0x68(%rbp)
movq -0x158(%rbp), %rdi
addq $0x8, %rdi
callq 0x8cc0
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x8cf0
testb $0x1, %al
jne 0x17be5
jmp 0x17cb0
leaq -0x68(%rbp), %rdi
callq 0x8d30
movq (%rax), %rdi
callq 0x150e0
movb %al, -0x161(%rbp)
jmp 0x17bfe
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x17c0d
jmp 0x17ca0
leaq -0x68(%rbp), %rdi
callq 0x8d30
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x1c120
jmp 0x17c2b
leaq -0x38(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x1c0e0
movb %dl, -0x171(%rbp)
movq %rax, -0x170(%rbp)
jmp 0x17c4a
movb -0x171(%rbp), %al
movq -0x170(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movb %al, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x1c160
jmp 0x17ca0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x182d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x1c160
jmp 0x182d9
jmp 0x17ca2
leaq -0x68(%rbp), %rdi
callq 0x8d70
jmp 0x17bbb
movq -0x158(%rbp), %rdi
movl $0x0, -0xa4(%rbp)
addq $0xd0, %rdi
callq 0x1c180
movq %rax, -0xb0(%rbp)
movq -0x158(%rbp), %rdi
addq $0xd0, %rdi
callq 0x1c1f0
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x1c1b0
testb $0x1, %al
jne 0x17d0a
jmp 0x18038
movq -0x158(%rbp), %rdi
addq $0x20, %rdi
callq 0xaf20
movq %rax, -0xc0(%rbp)
movq -0x158(%rbp), %rdi
addq $0x20, %rdi
callq 0xab70
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xaf50
testb $0x1, %al
jne 0x17d54
jmp 0x18016
leaq -0xc0(%rbp), %rdi
callq 0xaed0
movq %rax, %rdi
callq 0x14e30
movq %rax, -0x180(%rbp)
jmp 0x17d71
movq -0x180(%rbp), %rax
cmpq $0x1, %rax
jbe 0x17d83
jmp 0x18005
movb $0x1, -0xc9(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xaed0
movq %rax, %rdi
callq 0xb030
movq %rax, -0x188(%rbp)
jmp 0x17da7
movq -0x188(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xaed0
movq %rax, %rdi
callq 0xb060
movq %rax, -0x190(%rbp)
jmp 0x17dd2
movq -0x190(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x9130
testb $0x1, %al
jne 0x17dfc
jmp 0x17ec1
leaq -0xd8(%rbp), %rdi
callq 0x9160
movq (%rax), %rdi
callq 0x150e0
movb %al, -0x191(%rbp)
jmp 0x17e18
movb -0x191(%rbp), %al
testb $0x1, %al
jne 0x17eae
jmp 0x17e28
leaq -0xb0(%rbp), %rdi
callq 0x1c220
movq %rax, -0x1a0(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x9160
movq (%rax), %rdi
callq 0xaa30
movl %eax, -0x198(%rbp)
jmp 0x17e57
movq -0x1a0(%rbp), %rdi
movl -0x198(%rbp), %eax
movslq %eax, %rsi
callq 0x1c240
movq %rax, -0x1a8(%rbp)
jmp 0x17e75
movq -0x1a8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1b0(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x9160
movq %rax, %rcx
movq -0x1b0(%rbp), %rax
movslq 0x8(%rcx), %rcx
cmpq %rcx, %rax
je 0x17eae
movb $0x0, -0xc9(%rbp)
jmp 0x17ec1
jmp 0x17eb0
leaq -0xd8(%rbp), %rdi
callq 0x9210
jmp 0x17db5
testb $0x1, -0xc9(%rbp)
je 0x18003
leaq -0xc0(%rbp), %rdi
callq 0xaed0
movq %rax, %rdi
callq 0xb030
movq %rax, -0x1b8(%rbp)
jmp 0x17eeb
movq -0x1b8(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xaed0
movq %rax, %rdi
callq 0xb060
movq %rax, -0x1c0(%rbp)
jmp 0x17f16
movq -0x1c0(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x9130
testb $0x1, %al
jne 0x17f40
jmp 0x18001
leaq -0xe8(%rbp), %rdi
callq 0x9160
movq (%rax), %rdi
callq 0x150e0
movb %al, -0x1c1(%rbp)
jmp 0x17f5c
movb -0x1c1(%rbp), %al
testb $0x1, %al
jne 0x17f6b
jmp 0x17fee
leaq -0xe8(%rbp), %rdi
callq 0x9160
movq %rax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x1c280
movq %rax, -0x1d0(%rbp)
jmp 0x17f8c
movq -0x1d0(%rbp), %rdi
movslq -0xa4(%rbp), %rsi
callq 0x1c360
movq %rax, -0x1e8(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x9160
movq -0x1e8(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0x1c380
movb %dl, -0x1d9(%rbp)
movq %rax, -0x1d8(%rbp)
jmp 0x17fd4
movb -0x1d9(%rbp), %al
movq -0x1d8(%rbp), %rcx
movq %rcx, -0x100(%rbp)
movb %al, -0xf8(%rbp)
jmp 0x17ff0
leaq -0xe8(%rbp), %rdi
callq 0x9210
jmp 0x17ef9
jmp 0x18003
jmp 0x18005
leaq -0xc0(%rbp), %rdi
callq 0xb000
jmp 0x17d21
jmp 0x18018
leaq -0xb0(%rbp), %rdi
callq 0x1c3d0
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x17cd4
leaq -0x38(%rbp), %rdi
callq 0x1c3f0
movq %rax, -0x108(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1c450
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x1c420
testb $0x1, %al
jne 0x18074
jmp 0x18150
leaq -0x108(%rbp), %rdi
callq 0x1c480
movq %rax, %rdi
addq $0x8, %rdi
callq 0x1c4a0
movq %rax, -0x118(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x1c480
movq %rax, %rdi
addq $0x8, %rdi
callq 0x1c510
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x1c4d0
testb $0x1, %al
jne 0x180cb
jmp 0x1813d
leaq -0x118(%rbp), %rdi
callq 0x1c540
movq %rax, %rdi
callq 0x1c560
movq %rax, -0x128(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x1c540
movq %rax, %rdi
callq 0x1c5c0
movq %rax, -0x130(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x1c590
testb $0x1, %al
jne 0x1811a
jmp 0x1812a
jmp 0x1811c
leaq -0x128(%rbp), %rdi
callq 0x1c5f0
jmp 0x180e6
jmp 0x1812c
leaq -0x118(%rbp), %rdi
callq 0x1c620
jmp 0x18093
jmp 0x1813f
leaq -0x108(%rbp), %rdi
callq 0x1c640
jmp 0x18048
leaq -0x38(%rbp), %rdi
callq 0x1c3f0
movq %rax, -0x138(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1c450
movq %rax, -0x140(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x1c420
testb $0x1, %al
jne 0x1818c
jmp 0x182be
leaq -0x138(%rbp), %rdi
callq 0x1c480
movq (%rax), %rdi
callq 0xaa30
movl %eax, -0x1ec(%rbp)
jmp 0x181a8
movl -0x1ec(%rbp), %eax
movl %eax, -0x144(%rbp)
movq $0x0, -0x150(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x1f8(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x1c480
movq %rax, %rdi
addq $0x8, %rdi
callq 0x1c670
movq %rax, %rcx
movq -0x1f8(%rbp), %rax
cmpq %rcx, %rax
jae 0x182ab
leaq -0x138(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x1c480
movq %rax, %rdi
addq $0x8, %rdi
movq -0x150(%rbp), %rsi
callq 0x1c360
movq %rax, %rdi
callq 0x1c6a0
movq -0x210(%rbp), %rdi
movq %rax, -0x208(%rbp)
callq 0x1c480
movq (%rax), %rdi
callq 0x8eb0
movl %eax, -0x1fc(%rbp)
jmp 0x18249
movq -0x208(%rbp), %rax
movl -0x1fc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0x18292
movq -0x158(%rbp), %rdi
addq $0xd0, %rdi
movq -0x150(%rbp), %rsi
callq 0x1c6c0
movq %rax, %rdi
movslq -0x144(%rbp), %rsi
callq 0x1c6e0
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, (%rax)
jmp 0x18294
movq -0x150(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x150(%rbp)
jmp 0x181bf
jmp 0x182ad
leaq -0x138(%rbp), %rdi
callq 0x1c640
jmp 0x18160
leaq -0x50(%rbp), %rdi
callq 0x1c700
leaq -0x38(%rbp), %rdi
callq 0x1c760
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x1c700
leaq -0x38(%rbp), %rdi
callq 0x1c760
movq -0x58(%rbp), %rdi
callq 0x79d0
nopw %cs:(%rax,%rax)