// File: /workspace/github_cpp_makefile_star2_O2/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 $0x508, %rsp            # imm = 0x508
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x42bf(%rip), %rsi      # 0x707d
leaq 0x300(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x22d0
leaq 0xc8(%rsp), %r12
leaq 0x8(%rsp), %r13
leaq 0x40(%rsp), %rbx
leaq 0x300(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x2040
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2ff4
movq %r12, %rdi
leaq 0x58(%rsp), %rsi
callq 0x30f8
leaq 0x78(%rsp), %rdi
callq 0x31dc
xorl %r14d, %r14d
movl %r14d, %r14d
movq 0x138(%rsp), %rax
movq 0x140(%rsp), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
cmpq %r14, %rsi
jbe 0x2e77
movq (%rax,%r14,8), %rbx
movq 0x20(%rbx), %r15
cmpq 0x28(%rbx), %r15
je 0x2e6d
movl (%r15), %eax
shlq $0x20, %rax
orq %r14, %rax
movq %rax, 0x8(%rsp)
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x62c6
addq $0x8, %r15
jmp 0x2e45
incl %r14d
leaq 0x40(%rsp), %rbx
jmp 0x2e1e
movq %rbx, %rdi
callq 0x31f8
movq 0x88(%rsp), %rax
cmpq %rax, 0xa8(%rsp)
je 0x2eaa
movl (%rax), %esi
movl 0x4(%rax), %edx
movq %rbx, %rdi
callq 0x3258
leaq 0x78(%rsp), %rdi
callq 0x6526
jmp 0x2e7f
leaq 0x38(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x1, 0x10(%rsp)
leaq 0x18(%rsp), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
movl $0x3f800000, 0x28(%rsp) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
xorl %esi, %esi
movl %esi, 0x4(%rsp)
movl %esi, %eax
movq 0x140(%rsp), %rcx
subq 0x138(%rsp), %rcx
sarq $0x3, %rcx
cmpq %rax, %rcx
jbe 0x2f55
movq %rbx, %rdi
callq 0x3280
movl %eax, (%rsp)
movq %r13, %rdi
movq %rsp, %rsi
callq 0x5ccc
testq %rax, %rax
jne 0x2f35
pushq $0x18
popq %rdi
callq 0x21c0
movq %rax, %r14
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
movq %r13, %rdi
movq %rsp, %rsi
callq 0x5d48
movq %r14, (%rax)
movq %r13, %rdi
movq %rsp, %rsi
callq 0x5d48
movq (%rax), %rdi
leaq 0x4(%rsp), %rsi
callq 0x30ec
movl 0x4(%rsp), %esi
incl %esi
jmp 0x2ed6
leaq 0x18(%rsp), %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x2fab
movq %r12, %r13
movq 0x10(%rbx), %r12
movq %r12, %r15
movl %ebp, %r14d
movl %r14d, %ebp
movq (%r15), %r15
cmpq %r12, %r15
je 0x2f93
movl 0x10(%r15), %r14d
cmpq (%r12), %r15
je 0x2f6f
movl %ebp, %edi
movl %r14d, %esi
movq %r13, %rdx
callq 0x2701
jmp 0x2f6f
movq 0x803e(%rip), %rdi      # 0xafd8
leaq 0x40ed(%rip), %rsi      # 0x708e
callq 0x21b0
movq %r13, %r12
jmp 0x2f5a
movq %r12, %rdi
callq 0x2808
movq %r12, %rdi
callq 0x297f
movq %r12, %rdi
callq 0x2c00
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x3920
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x5102
leaq 0x78(%rsp), %rdi
callq 0x5120
movq %r12, %rdi
callq 0x32ac
jmp 0x2de0
leaq 0x300(%rsp), %rdi
callq 0x2060
leaq 0x58(%rsp), %rdi
callq 0x2308
xorl %eax, %eax
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x307f
jmp 0x3058
movq %rax, %rbx
jmp 0x3065
jmp 0x302d
movq %rax, %rbx
jmp 0x3072
jmp 0x303f
jmp 0x303f
jmp 0x303f
movq %rax, %rbx
jmp 0x304c
jmp 0x303f
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3920
leaq 0x40(%rsp), %rdi
callq 0x5102
jmp 0x305b
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x5120
leaq 0xc8(%rsp), %rdi
callq 0x32ac
leaq 0x300(%rsp), %rdi
callq 0x2060
leaq 0x58(%rsp), %rdi
callq 0x2308
movq %rbx, %rdi
callq 0x22b0
nop