// File: WShabti-Team[P]WShabtiPict/wshabtilib/api/model.cpp
// Function: pictcore::Model::GenerateVirtualRoot()
void Model::GenerateVirtualRoot()
{
    DOUT( L"GenerateVirtualRoot: Begin" << endl );

    // no support for result rows in this generation mode
    assert( 0 == GetResultParameterCount() );

    GlobalZerosCount = 0;

    // this node is a virtual root node
    // muster all parameters out of the sub-models
    // use IDs to avoid adding any parameter twice
    set<wstring> paramIds;
    for( SubmodelCollection::iterator i = m_submodels.begin(); i != m_submodels.end(); ++i )
    {
        for( vector<Parameter*>::iterator ip = ( *i )->GetParameters().begin(); ip != ( *i )->GetParameters().end(); ++ip )
        {
            if( paramIds.end() == find( paramIds.begin(), paramIds.end(), ( *ip )->GetName() ) )
            {
                paramIds.insert( ( *ip )->GetName() );
                AddParameter( *ip );
            }
        }
    }
    
    // don't need this, so don't wait for it to go out of scope
    paramIds.clear();

    // create a combination for every sub-model
    // mark all satisfied except those corresponding to output rows in sub-models
    ComboCollection vecCombo;
    for( SubmodelCollection::iterator i = m_submodels.begin(); i != m_submodels.end(); ++i )
    {
        Combination *combo = new Combination( this );
        vecCombo.push_back( combo );
        int size = 1;
        for( ParamCollection::iterator ip = ( *i )->GetParameters().begin(); ip != ( *i )->GetParameters().end(); ++ip )
        {
            ( *ip )->LinkCombination( combo );
            combo->PushParameter( *ip );
            size *= ( *ip )->GetValueCount();
        }

        // init all combinations to satisfied, don't count any zeros
        combo->SetMapSize( size, COVERED );
        // for each result row
        for( int ridx = 0; ridx < ( *i )->GetResultCount(); ++ridx )
        {
            size_t index = 0;
            // calculate index to combination corresponding to this sub-model output row
            const ResultRow& results = ( *i )->GetResults()[ ridx ];
            int cidx = 0;
            for( ParamCollection::iterator ip = ( *i )->GetParameters().begin(); ip != ( *i )->GetParameters().end(); ++ip )
            {
                index *= ( *ip )->GetValueCount();
                index += results[ cidx++ ];
            }
            // make this index a target to generate
            combo->SetOpen( (int) index );
        }
    }

    gcd( vecCombo );
    DOUT( L"GenerateVirtualRoot: End << end " );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x1bf50
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x19c4b
jmp 0x19c6a
leaq 0x4ab7c(%rip), %rdi     # 0x647ce
leaq 0x4a9e8(%rip), %rsi     # 0x64641
movl $0x2bf, %edx            # imm = 0x2BF
leaq 0x4ab88(%rip), %rcx     # 0x647ed
callq 0x7450
movq -0x118(%rbp), %rax
movl $0x0, (%rax)
leaq -0x38(%rbp), %rdi
callq 0x1ca70
movq -0x118(%rbp), %rdi
addq $0x50, %rdi
callq 0x1ca90
movq %rax, -0x40(%rbp)
movq -0x118(%rbp), %rdi
addq $0x50, %rdi
callq 0x1caf0
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1cac0
testb $0x1, %al
jne 0x19cbe
jmp 0x19e5a
leaq -0x40(%rbp), %rdi
callq 0x1cb20
movq (%rax), %rdi
callq 0x1c780
movq %rax, -0x120(%rbp)
jmp 0x19cd8
movq -0x120(%rbp), %rdi
callq 0x8c90
movq %rax, -0x50(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1cb20
movq (%rax), %rdi
callq 0x1c780
movq %rax, -0x128(%rbp)
jmp 0x19d02
movq -0x128(%rbp), %rdi
callq 0x8cc0
movq %rax, -0x68(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x8cf0
testb $0x1, %al
jne 0x19d28
jmp 0x19e4a
leaq -0x38(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x1cb70
movq -0x138(%rbp), %rdi
movq %rax, -0x70(%rbp)
callq 0x1cbf0
movq -0x138(%rbp), %rdi
movq %rax, -0x80(%rbp)
callq 0x1cb70
movq %rax, -0x88(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x8d30
movq (%rax), %rdi
callq 0x1cc20
movq %rax, -0x130(%rbp)
jmp 0x19d79
movq -0x130(%rbp), %rdx
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x1cba0
movq %rax, -0x140(%rbp)
jmp 0x19d99
movq -0x140(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x1cb40
testb $0x1, %al
jne 0x19dba
jmp 0x19e3a
leaq -0x50(%rbp), %rdi
callq 0x8d30
movq (%rax), %rdi
callq 0x1cc20
movq %rax, -0x148(%rbp)
jmp 0x19dd4
movq -0x148(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x1cc40
movb %dl, -0x151(%rbp)
movq %rax, -0x150(%rbp)
jmp 0x19df3
movb -0x151(%rbp), %al
movq -0x150(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movb %al, -0x90(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x8d30
movq -0x118(%rbp), %rdi
movq (%rax), %rsi
callq 0x1c940
jmp 0x19e27
jmp 0x19e3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1a25a
jmp 0x19e3c
leaq -0x50(%rbp), %rdi
callq 0x8d70
jmp 0x19ce8
jmp 0x19e4c
leaq -0x40(%rbp), %rdi
callq 0x1cc90
jmp 0x19c94
leaq -0x38(%rbp), %rdi
callq 0x1ccb0
leaq -0xb0(%rbp), %rdi
callq 0x1ccd0
movq -0x118(%rbp), %rdi
addq $0x50, %rdi
callq 0x1ca90
movq %rax, -0xb8(%rbp)
movq -0x118(%rbp), %rdi
addq $0x50, %rdi
callq 0x1caf0
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x1cac0
testb $0x1, %al
jne 0x19eb9
jmp 0x1a21b
movl $0x40, %edi
callq 0x75e0
movq %rax, -0x160(%rbp)
jmp 0x19ecc
movq -0x118(%rbp), %rsi
movq -0x160(%rbp), %rdi
callq 0x8b60
jmp 0x19ee1
movq -0x160(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x1b6a0
jmp 0x19f04
movl $0x1, -0xcc(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x1cb20
movq (%rax), %rdi
callq 0x1c780
movq %rax, -0x168(%rbp)
jmp 0x19f2b
movq -0x168(%rbp), %rdi
callq 0x8c90
movq %rax, -0xd8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x1cb20
movq (%rax), %rdi
callq 0x1c780
movq %rax, -0x170(%rbp)
jmp 0x19f5b
movq -0x170(%rbp), %rdi
callq 0x8cc0
movq %rax, -0xe0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x8cf0
testb $0x1, %al
jne 0x19f8a
jmp 0x1a045
leaq -0xd8(%rbp), %rdi
callq 0x8d30
movq (%rax), %rdi
movq -0xc8(%rbp), %rsi
callq 0x1b740
jmp 0x19fa7
movq -0xc8(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x8d30
movq -0x178(%rbp), %rdi
movq (%rax), %rsi
callq 0x1b7d0
jmp 0x19fd2
leaq -0xd8(%rbp), %rdi
callq 0x8d30
movq (%rax), %rdi
callq 0x8eb0
movl %eax, -0x17c(%rbp)
jmp 0x19fee
movl -0x17c(%rbp), %eax
imull -0xcc(%rbp), %eax
movl %eax, -0xcc(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x8d70
jmp 0x19f3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1a24e
movq -0x160(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0x40, %esi
callq 0x7600
jmp 0x1a24e
movq -0xc8(%rbp), %rdi
movl -0xcc(%rbp), %esi
movl $0x1, %edx
callq 0x7f60
jmp 0x1a05e
movl $0x0, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
movl %eax, -0x184(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x1cb20
movq (%rax), %rdi
callq 0x1ccf0
movl %eax, -0x180(%rbp)
jmp 0x1a090
movl -0x184(%rbp), %eax
movl -0x180(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1a208
movq $0x0, -0xf0(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x1cb20
movq (%rax), %rdi
callq 0x1c890
movq %rax, -0x190(%rbp)
jmp 0x1a0cc
movq -0x190(%rbp), %rdi
movslq -0xe4(%rbp), %rsi
callq 0x1c6c0
movq %rax, -0xf8(%rbp)
movl $0x0, -0xfc(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x1cb20
movq (%rax), %rdi
callq 0x1c780
movq %rax, -0x198(%rbp)
jmp 0x1a10d
movq -0x198(%rbp), %rdi
callq 0x8c90
movq %rax, -0x108(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x1cb20
movq (%rax), %rdi
callq 0x1c780
movq %rax, -0x1a0(%rbp)
jmp 0x1a13d
movq -0x1a0(%rbp), %rdi
callq 0x8cc0
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x8cf0
testb $0x1, %al
jne 0x1a169
jmp 0x1a1de
leaq -0x108(%rbp), %rdi
callq 0x8d30
movq (%rax), %rdi
callq 0x8eb0
movl %eax, -0x1a4(%rbp)
jmp 0x1a185
movl -0x1a4(%rbp), %eax
cltq
imulq -0xf0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xf8(%rbp), %rdi
movl -0xfc(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0xfc(%rbp)
movslq %eax, %rsi
callq 0x1cd20
movq (%rax), %rax
addq -0xf0(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x8d70
jmp 0x1a120
movq -0xc8(%rbp), %rdi
movl -0xf0(%rbp), %esi
callq 0x8ae0
jmp 0x1a1f2
jmp 0x1a1f4
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x1a068
jmp 0x1a20a
leaq -0xb8(%rbp), %rdi
callq 0x1cc90
jmp 0x19e86
movq -0x118(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x15380
jmp 0x1a230
leaq -0xb0(%rbp), %rdi
callq 0x1cd40
leaq -0x38(%rbp), %rdi
callq 0x1cda0
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0xb0(%rbp), %rdi
callq 0x1cd40
leaq -0x38(%rbp), %rdi
callq 0x1cda0
movq -0x58(%rbp), %rdi
callq 0x79d0
nopl (%rax)