// File: /workspace/github_cpp_makefile_star2_O3/yuanboli233[P]interdyck_graph_reduce/graphtest.cpp
// Function: main
int main(){
    string line;
    ifstream in("dotfile/exp-2020");
    while(getline(in, line)){
        SummaryGraph sGraph(line);
        queue<pair<unsigned, unsigned> > worklist;
        for(unsigned i = 0; i < sGraph.nodes.size(); i++){
            //findMatch(i, sGraph);
            SummaryNode* node = sGraph.nodes[i];
            for(vector<NodewithEID>::iterator it = node->outRedEdgeNodes.begin(); it != node->outRedEdgeNodes.end(); it++){
                unsigned tonodeID = it->nodeID;
                worklist.push(make_pair(i, tonodeID));
            }
        }

        DisjointSet m_sets(sGraph.nodes.size());

        while(!worklist.empty()){
            unsigned first = worklist.front().first;
            unsigned second = worklist.front().second;
            m_sets.join(first, second);
            worklist.pop();
        }

        unordered_map<unsigned, list<unsigned>*> nodeGroups;
        for(unsigned i = 0; i < sGraph.nodes.size(); i++){
            unsigned root = m_sets.find(i);
            if(nodeGroups.find(root) == nodeGroups.end()){
                nodeGroups[root] = new list<unsigned>();
            }
            nodeGroups[root]->push_back(i);
        }


        for(unordered_map<unsigned, list<unsigned>*>::iterator ngit = nodeGroups.begin(); ngit != nodeGroups.end(); ngit++){
            unsigned cur, prev;
            list<unsigned>* lst = ngit->second;
            for(list<unsigned>::iterator lit = lst->begin(); lit != lst->end(); lit++){
                //cout << "list item: " << *lit;
                cur = *lit;
                if(lit == lst->begin()){
                    prev = cur;
                    continue;
                }
                mergeNodes(prev, cur, sGraph);
                //cout << "merge " << prev << " with " << cur << endl;
                // last line 
                prev = cur;
            }
            cout << "\n\n";
        }
        printGraphBlue(sGraph);
        createNodeMergeMap(sGraph);
        exportMergeNodes(sGraph);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x518, %rsp            # imm = 0x518
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x3de1(%rip), %rsi      # 0x707d
leaq 0x310(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x22d0
leaq 0x10(%rsp), %r14
leaq 0xd8(%rsp), %r15
movq 0x310(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x36a7
movq %r15, %rdi
movq %r14, %rsi
callq 0x37f2
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x6816
movq 0x148(%rsp), %rax
movq 0x150(%rsp), %rcx
movq %rcx, %rsi
subq %rax, %rsi
je 0x33a5
xorl %r14d, %r14d
movq (%rax,%r14,8), %r13
movq 0x20(%r13), %rbp
cmpq 0x28(%r13), %rbp
je 0x3391
movl (%rbp), %eax
shlq $0x20, %rax
orq %r14, %rax
movq %rax, 0xa0(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x698c
addq $0x8, %rbp
cmpq 0x28(%r13), %rbp
jne 0x3353
movq 0x148(%rsp), %rax
movq 0x150(%rsp), %rcx
incl %r14d
movq %rcx, %rsi
subq %rax, %rsi
sarq $0x3, %rsi
cmpq %r14, %rsi
ja 0x3345
jmp 0x33a9
sarq $0x3, %rsi
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0x3902
movq 0x40(%rsp), %rax
cmpq %rax, 0x60(%rsp)
leaq 0xc(%rsp), %rbp
je 0x3453
movl (%rax), %esi
movl 0x4(%rax), %r13d
movq %rbx, %rdi
callq 0x3990
movl %eax, %r14d
movq %rbx, %rdi
movl %r13d, %esi
callq 0x3990
movl %eax, %eax
movq 0x88(%rsp), %rcx
movl %r14d, (%rcx,%rax,4)
movq 0x40(%rsp), %rax
movq 0x50(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x3411
addq $0x8, %rax
jmp 0x3443
movq 0x48(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x21a0
movq 0x58(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x40(%rsp)
cmpq %rax, 0x60(%rsp)
jne 0x33ce
leaq 0xd0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq $0x1, 0xa8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, 0xc0(%rsp) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movq 0x150(%rsp), %rax
cmpq 0x148(%rsp), %rax
je 0x35d1
xorl %r13d, %r13d
movq %rbx, %rdi
movl %r13d, %esi
callq 0x3990
movl %eax, %ecx
movl %eax, 0xc(%rsp)
movl %eax, %eax
movq 0xa0(%rsp), %rdi
movq 0xa8(%rsp), %r8
xorl %edx, %edx
divq %r8
movq (%rdi,%rdx,8), %rax
testq %rax, %rax
je 0x34fa
movq %rdx, %rsi
movq (%rax), %r9
cmpl 0x8(%r9), %ecx
je 0x3529
movq (%r9), %r9
testq %r9, %r9
je 0x34fa
movl 0x8(%r9), %edi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
cmpq %rsi, %rdx
jne 0x34fa
cmpl %edi, %ecx
jne 0x34db
jmp 0x3529
movl $0x18, %edi
callq 0x2190
movq %rax, %r14
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
leaq 0xa0(%rsp), %rdi
movq %rbp, %rsi
callq 0x658a
movq %r14, (%rax)
leaq 0xa0(%rsp), %rdi
movq %rbp, %rsi
callq 0x658a
movq (%rax), %r14
movl $0x18, %edi
callq 0x2190
movl %r13d, 0x10(%rax)
movq %rax, %rdi
movq %r14, %rsi
callq 0x2040
incq 0x10(%r14)
incl %r13d
movq 0x150(%rsp), %rax
subq 0x148(%rsp), %rax
sarq $0x3, %rax
cmpq %r13, %rax
ja 0x349e
movq 0xb0(%rsp), %r13
testq %r13, %r13
je 0x35d1
movq 0x10(%r13), %rbp
movq (%rbp), %rbx
cmpq %rbp, %rbx
je 0x35b3
movl 0x10(%rbx), %r14d
cmpq (%rbp), %rbx
je 0x35ab
movl %r12d, %edi
movl %r14d, %esi
movq %r15, %rdx
callq 0x28ef
movq (%rbx), %rbx
movl %r14d, %r12d
jmp 0x358e
movl $0x2, %edx
movq 0x6a19(%rip), %rdi      # 0x9fd8
leaq 0x3ac8(%rip), %rsi      # 0x708e
callq 0x21e0
movq (%r13), %r13
jmp 0x3581
movq %r15, %rdi
callq 0x2a36
movq %r15, %rdi
callq 0x2c58
movq %r15, %rdi
callq 0x303b
leaq 0xa0(%rsp), %rdi
callq 0x3eea
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
leaq 0x310(%rsp), %rbx
leaq 0x10(%rsp), %r14
je 0x3620
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
leaq 0x30(%rsp), %rdi
callq 0x5aba
leaq 0x180(%rsp), %rdi
movq 0x6977(%rip), %rsi      # 0x9fb0
callq 0x2120
leaq 0x200(%rsp), %rdi
callq 0x2080
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0x3670
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x148(%rsp), %rdi
testq %rdi, %rdi
je 0x368d
movq 0x158(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
leaq 0x110(%rsp), %rdi
callq 0x3e9e
movq %r15, %rdi
callq 0x3ec4
jmp 0x32be
leaq 0x310(%rsp), %rdi
callq 0x2060
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x36d0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21a0
xorl %eax, %eax
addq $0x518, %rsp            # imm = 0x518
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x37ce
jmp 0x3737
movq %rax, %rbx
jmp 0x3744
jmp 0x36f5
movq %rax, %rbx
jmp 0x37c1
jmp 0x3708
jmp 0x3708
movq %rax, %rbx
jmp 0x3718
jmp 0x3708
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x3eea
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x373a
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
jmp 0x373a
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x5aba
movq 0x6865(%rip), %rsi      # 0x9fb0
leaq 0x180(%rsp), %rdi
callq 0x2120
leaq 0x200(%rsp), %rdi
callq 0x2080
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0x378a
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x148(%rsp), %rdi
testq %rdi, %rdi
je 0x37a7
movq 0x158(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
leaq 0x110(%rsp), %rdi
callq 0x3e9e
leaq 0xd8(%rsp), %rdi
callq 0x3ec4
leaq 0x310(%rsp), %rdi
callq 0x2060
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x37ea
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x22b0