// File: yuanboli233[P]interdyck_graph_reduce/graphtest.cpp
// Function: mergeNodes(unsigned int, unsigned int, SummaryGraph&)
void mergeNodes(unsigned anodeID, unsigned bnodeID, SummaryGraph& sGraph){
    if(root(anodeID, sGraph) != anodeID || root(bnodeID, sGraph) != bnodeID)
        return mergeNodes(root(anodeID, sGraph), root(bnodeID, sGraph), sGraph);

    if(anodeID == bnodeID)
        return;

    SummaryNode* anode = sGraph.nodes[anodeID];
    SummaryNode* bnode = sGraph.nodes[bnodeID];

    bnode->belongto = anode->id;

    for(vector<NodewithEID>::iterator it = bnode->outRedEdgeNodes.begin(); it != bnode->outRedEdgeNodes.end(); it++){
        unsigned eid = it->edgeID;
        unsigned tonodeID = root(it->nodeID, sGraph);
        NodewithEID newEidNode(tonodeID, eid);
        // do not care duplicate
        anode->outRedEdgeNodes.push_back(newEidNode);
        //cout << "add new red edge " << anode->id << "->" << tonodeID << " with eid " << eid << endl;
    }
    bnode->outRedEdgeNodes.clear();

    for(vector<NodewithEID>::iterator it = bnode->outBlueEdgeNodes.begin(); it != bnode->outBlueEdgeNodes.end(); it++){
        unsigned eid = it->edgeID;
        unsigned tonodeID = root(it->nodeID, sGraph);
        NodewithEID newEidNode(tonodeID, eid);
        // do not care duplicate
        anode->outBlueEdgeNodes.push_back(newEidNode);
        //cout << "add new blue edge " << anode->id << "->" << tonodeID << " with eid " << eid << endl;
    }
    bnode->outBlueEdgeNodes.clear();

    //cout << "Merge " << anodeID << " with " << bnodeID << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x35c0
cmpl -0x4(%rbp), %eax
jne 0x3aa7
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x35c0
cmpl -0x8(%rbp), %eax
je 0x3ad5
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x35c0
movl %eax, -0x74(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x35c0
movl -0x74(%rbp), %edi
movl %eax, %esi
movq -0x10(%rbp), %rdx
callq 0x3a70
jmp 0x3c53
movl -0x4(%rbp), %eax
cmpl -0x8(%rbp), %eax
jne 0x3ae2
jmp 0x3c53
movq -0x10(%rbp), %rdi
addq $0x70, %rdi
movl -0x4(%rbp), %eax
movl %eax, %esi
callq 0x4e30
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
addq $0x70, %rdi
movl -0x8(%rbp), %eax
movl %eax, %esi
callq 0x4e30
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x68(%rax)
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x4fd0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x5040
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x5000
testb $0x1, %al
jne 0x3b56
jmp 0x3bad
leaq -0x28(%rbp), %rdi
callq 0x5070
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5070
movl (%rax), %edi
movq -0x10(%rbp), %rsi
callq 0x35c0
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %esi
movl -0x34(%rbp), %edx
leaq -0x40(%rbp), %rdi
callq 0x5140
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
leaq -0x40(%rbp), %rsi
callq 0x5160
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x5090
movq %rax, -0x48(%rbp)
jmp 0x3b32
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x51d0
movq -0x20(%rbp), %rdi
addq $0x50, %rdi
callq 0x4fd0
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
addq $0x50, %rdi
callq 0x5040
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x5000
testb $0x1, %al
jne 0x3bef
jmp 0x3c46
leaq -0x50(%rbp), %rdi
callq 0x5070
movl 0x4(%rax), %eax
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x5070
movl (%rax), %edi
movq -0x10(%rbp), %rsi
callq 0x35c0
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %esi
movl -0x5c(%rbp), %edx
leaq -0x68(%rbp), %rdi
callq 0x5140
movq -0x18(%rbp), %rdi
addq $0x50, %rdi
leaq -0x68(%rbp), %rsi
callq 0x5160
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x5090
movq %rax, -0x70(%rbp)
jmp 0x3bcb
movq -0x20(%rbp), %rdi
addq $0x50, %rdi
callq 0x51d0
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)