// File: /workspace/github_cpp_makefile_star2_O1/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 0x3d27(%rip), %rsi      # 0x7099
leaq 0x310(%rsp), %r14
movq %r14, %rdi
movl $0x8, %edx
callq 0x22d0
leaq 0x10(%rsp), %r15
leaq 0xd8(%rsp), %r12
movq 0x310(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x22e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x378e
movq %r12, %rdi
movq %r15, %rsi
callq 0x38d8
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 0x696e
movq 0x148(%rsp), %rax
movq 0x150(%rsp), %rsi
subq %rax, %rsi
je 0x3472
xorl %r15d, %r15d
movq (%rax,%r15,8), %r14
movq 0x20(%r14), %r13
cmpq 0x28(%r14), %r13
je 0x3451
movl (%r13), %eax
shlq $0x20, %rax
orq %r15, %rax
movq %rax, 0xa0(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x6ae4
addq $0x8, %r13
jmp 0x3420
incl %r15d
movq 0x148(%rsp), %rax
movq 0x150(%rsp), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
cmpq %r15, %rsi
ja 0x3418
jmp 0x3476
sarq $0x3, %rsi
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0x39e8
movq 0x40(%rsp), %rax
cmpq %rax, 0x60(%rsp)
je 0x3511
movl (%rax), %esi
movl 0x4(%rax), %r13d
movq %r14, %rdi
callq 0x3a76
movl %eax, %r15d
movq %r14, %rdi
movl %r13d, %esi
callq 0x3a76
movl %eax, %eax
movq 0x88(%rsp), %rcx
movl %r15d, (%rcx,%rax,4)
movq 0x40(%rsp), %rax
movq 0x50(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x34d5
addq $0x8, %rax
jmp 0x3507
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)
jmp 0x348b
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 0x3661
xorl %r13d, %r13d
movq %r14, %rdi
movl %r13d, %esi
callq 0x3a76
movl %eax, %ecx
movl %eax, 0xc(%rsp)
movl %eax, %eax
movq 0xa0(%rsp), %rdi
movq 0xa8(%rsp), %r8
xorl %edx, %edx
divq %r8
movq %rdx, %rsi
movq (%rdi,%rdx,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0x35cd
movq (%rdx), %r9
movq %rdx, %rax
cmpl 0x8(%r9), %ecx
je 0x35cd
movq %r9, %r10
movq (%r9), %r9
testq %r9, %r9
je 0x35cb
movl 0x8(%r9), %edi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
movl $0x0, %eax
cmpq %rsi, %rdx
jne 0x35cd
movq %r10, %rax
cmpl %edi, %ecx
jne 0x35a1
jmp 0x35cd
xorl %eax, %eax
testq %rax, %rax
je 0x35d8
cmpq $0x0, (%rax)
jne 0x360f
movl $0x18, %edi
callq 0x2190
movq %rax, %r15
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, 0x8(%rax)
movq %rax, (%rax)
leaq 0xa0(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x66f2
movq %r15, (%rax)
leaq 0xa0(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x66f2
movq (%rax), %r15
movl $0x18, %edi
callq 0x2190
movl %r13d, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2040
incq 0x10(%r15)
incl %r13d
movq 0x150(%rsp), %rax
subq 0x148(%rsp), %rax
sarq $0x3, %rax
cmpq %r13, %rax
ja 0x355c
movq 0xb0(%rsp), %r13
testq %r13, %r13
je 0x36b8
movq 0x10(%r13), %rbp
movq (%rbp), %r14
cmpq %rbp, %r14
je 0x369a
movl 0x10(%r14), %r15d
cmpq (%rbp), %r14
je 0x3692
movl %ebx, %edi
movl %r15d, %esi
movq %r12, %rdx
callq 0x294a
movq (%r14), %r14
movl %r15d, %ebx
jmp 0x3676
movl $0x2, %edx
movq 0x6932(%rip), %rdi      # 0x9fd8
leaq 0x39fd(%rip), %rsi      # 0x70aa
callq 0x21e0
movq (%r13), %r13
jmp 0x3669
movq %r12, %rdi
callq 0x2a9d
movq %r12, %rdi
callq 0x2cb3
movq %r12, %rdi
callq 0x30eb
leaq 0xa0(%rsp), %rdi
callq 0x3fd8
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
leaq 0x310(%rsp), %r14
leaq 0x10(%rsp), %r15
je 0x3707
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
leaq 0x30(%rsp), %rdi
callq 0x5baa
leaq 0x180(%rsp), %rdi
movq 0x6890(%rip), %rsi      # 0x9fb0
callq 0x2120
leaq 0x200(%rsp), %rdi
callq 0x2080
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0x3757
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x148(%rsp), %rdi
testq %rdi, %rdi
je 0x3774
movq 0x158(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
leaq 0x110(%rsp), %rdi
callq 0x3f8c
movq %r12, %rdi
callq 0x3fb2
jmp 0x3394
leaq 0x310(%rsp), %rdi
callq 0x2060
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x37b7
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 0x38b4
jmp 0x381e
jmp 0x37dc
movq %rax, %rbx
jmp 0x382b
movq %rax, %rbx
jmp 0x38a7
jmp 0x37ef
jmp 0x37ef
movq %rax, %rbx
jmp 0x37ff
jmp 0x37ef
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x3fd8
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x3821
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
jmp 0x3821
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x5baa
leaq 0x180(%rsp), %r14
movq 0x6776(%rip), %rsi      # 0x9fb0
movq %r14, %rdi
callq 0x2120
leaq 0x200(%rsp), %rdi
callq 0x2080
movq -0x20(%r14), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0x3870
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x148(%rsp), %rdi
testq %rdi, %rdi
je 0x388d
movq 0x158(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
leaq 0x110(%rsp), %rdi
callq 0x3f8c
leaq 0xd8(%rsp), %rdi
callq 0x3fb2
leaq 0x310(%rsp), %rdi
callq 0x2060
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x38d0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x22b0