// File: 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
movq %rsp, %rbp
subq $0x620, %rsp            # imm = 0x620
movl $0x0, -0x4(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3310
leaq 0xe8df(%rip), %rsi      # 0x13081
leaq -0x230(%rbp), %rdi
movl $0x8, %edx
callq 0x33c0
jmp 0x47b5
jmp 0x47b7
leaq -0x230(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x3070
movq %rax, -0x5c0(%rbp)
jmp 0x47d0
movq -0x5c0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32d0
movb %al, -0x5c1(%rbp)
jmp 0x47ee
movb -0x5c1(%rbp), %al
testb $0x1, %al
jne 0x47fd
jmp 0x4dde
leaq -0x478(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x5610
jmp 0x480f
leaq -0x4c8(%rbp), %rdi
callq 0x5700
jmp 0x481d
movl $0x0, -0x4cc(%rbp)
movl -0x4cc(%rbp), %eax
movq %rax, -0x5d0(%rbp)
leaq -0x478(%rbp), %rdi
addq $0x70, %rdi
callq 0x5250
movq %rax, %rcx
movq -0x5d0(%rbp), %rax
cmpq %rcx, %rax
jae 0x49a4
leaq -0x478(%rbp), %rdi
addq $0x70, %rdi
movl -0x4cc(%rbp), %eax
movl %eax, %esi
callq 0x4e30
movq (%rax), %rax
movq %rax, -0x4d8(%rbp)
movq -0x4d8(%rbp), %rdi
addq $0x20, %rdi
callq 0x4fd0
movq %rax, -0x4e0(%rbp)
movq -0x4d8(%rbp), %rdi
addq $0x20, %rdi
callq 0x5040
movq %rax, -0x4e8(%rbp)
leaq -0x4e0(%rbp), %rdi
leaq -0x4e8(%rbp), %rsi
callq 0x5000
testb $0x1, %al
jne 0x48c3
jmp 0x498e
leaq -0x4e0(%rbp), %rdi
callq 0x5070
movl (%rax), %eax
movl %eax, -0x4ec(%rbp)
leaq -0x4cc(%rbp), %rdi
leaq -0x4ec(%rbp), %rsi
callq 0x5760
movq %rax, -0x5d8(%rbp)
jmp 0x48f3
movq -0x5d8(%rbp), %rax
movq %rax, -0x4f4(%rbp)
leaq -0x4c8(%rbp), %rdi
leaq -0x4f4(%rbp), %rsi
callq 0x5730
jmp 0x4916
jmp 0x4918
leaq -0x4e0(%rbp), %rdi
xorl %esi, %esi
callq 0x5090
movq %rax, -0x500(%rbp)
jmp 0x4890
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x4e12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x4e06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x4dd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x4dc4
jmp 0x4990
movl -0x4cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4cc(%rbp)
jmp 0x4827
leaq -0x408(%rbp), %rdi
callq 0x5250
movl %eax, %esi
leaq -0x518(%rbp), %rdi
callq 0x5790
jmp 0x49c0
jmp 0x49c2
leaq -0x4c8(%rbp), %rdi
callq 0x5820
movb %al, -0x5d9(%rbp)
jmp 0x49d6
movb -0x5d9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x49e7
jmp 0x4a74
leaq -0x4c8(%rbp), %rdi
callq 0x5840
movq %rax, -0x5e8(%rbp)
jmp 0x49fc
movq -0x5e8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x51c(%rbp)
leaq -0x4c8(%rbp), %rdi
callq 0x5840
movq %rax, -0x5f0(%rbp)
jmp 0x4a20
movq -0x5f0(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x520(%rbp)
movl -0x51c(%rbp), %esi
movl -0x520(%rbp), %edx
leaq -0x518(%rbp), %rdi
callq 0x5860
jmp 0x4a4a
leaq -0x4c8(%rbp), %rdi
callq 0x58c0
jmp 0x4a58
jmp 0x49c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x4db8
leaq -0x558(%rbp), %rdi
callq 0x5310
movl $0x0, -0x55c(%rbp)
movl -0x55c(%rbp), %eax
movq %rax, -0x5f8(%rbp)
leaq -0x478(%rbp), %rdi
addq $0x70, %rdi
callq 0x5250
movq %rax, %rcx
movq -0x5f8(%rbp), %rax
cmpq %rcx, %rax
jae 0x4bff
movl -0x55c(%rbp), %esi
leaq -0x518(%rbp), %rdi
callq 0x58e0
movl %eax, -0x5fc(%rbp)
jmp 0x4ad4
movl -0x5fc(%rbp), %eax
movl %eax, -0x560(%rbp)
leaq -0x558(%rbp), %rdi
leaq -0x560(%rbp), %rsi
callq 0x5360
movq %rax, -0x608(%rbp)
jmp 0x4afc
movq -0x608(%rbp), %rax
movq %rax, -0x568(%rbp)
leaq -0x558(%rbp), %rdi
callq 0x5390
movq %rax, -0x570(%rbp)
leaq -0x568(%rbp), %rdi
leaq -0x570(%rbp), %rsi
callq 0x5330
testb $0x1, %al
jne 0x4b36
jmp 0x4bb5
movl $0x18, %edi
callq 0x3210
movq %rax, -0x610(%rbp)
jmp 0x4b49
movq -0x610(%rbp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x53c0
leaq -0x558(%rbp), %rdi
leaq -0x560(%rbp), %rsi
callq 0x53e0
movq %rax, -0x618(%rbp)
jmp 0x4b7f
movq -0x618(%rbp), %rax
movq -0x610(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x4bb5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x558(%rbp), %rdi
callq 0x55f0
jmp 0x4db8
leaq -0x558(%rbp), %rdi
leaq -0x560(%rbp), %rsi
callq 0x53e0
movq %rax, -0x620(%rbp)
jmp 0x4bd1
movq -0x620(%rbp), %rax
movq (%rax), %rdi
leaq -0x55c(%rbp), %rsi
callq 0x5410
jmp 0x4be9
jmp 0x4beb
movl -0x55c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x55c(%rbp)
jmp 0x4a8a
leaq -0x558(%rbp), %rdi
callq 0x5450
movq %rax, -0x578(%rbp)
leaq -0x558(%rbp), %rdi
callq 0x5390
movq %rax, -0x580(%rbp)
leaq -0x578(%rbp), %rdi
leaq -0x580(%rbp), %rsi
callq 0x5480
testb $0x1, %al
jne 0x4c41
jmp 0x4d59
leaq -0x578(%rbp), %rdi
callq 0x54b0
movq 0x8(%rax), %rax
movq %rax, -0x590(%rbp)
movq -0x590(%rbp), %rdi
callq 0x54e0
movq %rax, -0x598(%rbp)
movq -0x590(%rbp), %rdi
callq 0x5540
movq %rax, -0x5a0(%rbp)
leaq -0x598(%rbp), %rdi
leaq -0x5a0(%rbp), %rsi
callq 0x5510
testb $0x1, %al
jne 0x4c9a
jmp 0x4d28
leaq -0x598(%rbp), %rdi
callq 0x5570
movl (%rax), %eax
movl %eax, -0x584(%rbp)
movq -0x590(%rbp), %rdi
callq 0x54e0
movq %rax, -0x5a8(%rbp)
leaq -0x598(%rbp), %rdi
leaq -0x5a8(%rbp), %rsi
callq 0x5950
testb $0x1, %al
jne 0x4cda
jmp 0x4ce8
movl -0x584(%rbp), %eax
movl %eax, -0x588(%rbp)
jmp 0x4d0e
movl -0x588(%rbp), %edi
movl -0x584(%rbp), %esi
leaq -0x478(%rbp), %rdx
callq 0x3a70
jmp 0x4d02
movl -0x584(%rbp), %eax
movl %eax, -0x588(%rbp)
leaq -0x598(%rbp), %rdi
xorl %esi, %esi
callq 0x5590
movq %rax, -0x5b0(%rbp)
jmp 0x4c6b
movq 0x192a9(%rip), %rdi     # 0x1dfd8
leaq 0xe35c(%rip), %rsi      # 0x13092
callq 0x3200
jmp 0x4d3d
jmp 0x4d3f
leaq -0x578(%rbp), %rdi
xorl %esi, %esi
callq 0x55c0
movq %rax, -0x5b8(%rbp)
jmp 0x4c12
leaq -0x478(%rbp), %rdi
callq 0x3c60
jmp 0x4d67
leaq -0x478(%rbp), %rdi
callq 0x3f30
jmp 0x4d75
leaq -0x478(%rbp), %rdi
callq 0x4460
jmp 0x4d83
leaq -0x558(%rbp), %rdi
callq 0x55f0
leaq -0x518(%rbp), %rdi
callq 0x5980
leaq -0x4c8(%rbp), %rdi
callq 0x59a0
leaq -0x478(%rbp), %rdi
callq 0x59c0
jmp 0x47b7
leaq -0x518(%rbp), %rdi
callq 0x5980
leaq -0x4c8(%rbp), %rdi
callq 0x59a0
leaq -0x478(%rbp), %rdi
callq 0x59c0
jmp 0x4e06
movl $0x0, -0x4(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x3090
leaq -0x28(%rbp), %rdi
callq 0x3408
movl -0x4(%rbp), %eax
addq $0x620, %rsp            # imm = 0x620
popq %rbp
retq
leaq -0x230(%rbp), %rdi
callq 0x3090
leaq -0x28(%rbp), %rdi
callq 0x3408
movq -0x238(%rbp), %rdi
callq 0x3390
nopw (%rax,%rax)