// File: chhylp123[P]hifiasm/Correct.cpp
// Function: Merge_In_Nodes(Graph*, Node*)
void Merge_In_Nodes(Graph* DAGCon, Node* currentNode)
{
    ///if this node does not have any input, directly return
    if(Real_Length(Input_Edges((*currentNode))) == 0)
    {
        return;
    }

    RSet buf, in_buf;
    char Bases[4] = {'A', 'C', 'G', 'T'};
    char base;
    long long base_i, weight;
    int flag = 0;
    Node* get_node = NULL;
    Node* in_node_of_get_node = NULL;
    Node* consensus_node = NULL;
    Edge* e_forward = NULL;
    Edge* e_backward = NULL;

    ///merge all base for each base
    for (base_i = 0; base_i < 4; base_i++)
    {
        base = Bases[base_i];

        clear_RSet(&buf);
        flag = 0;
        weight = 0;
        ///should use getInputEdges, instead of getInputNodes
        ///check all in-nodes of currentNode
        while(getInputNodes(&buf, DAGCon, currentNode, &get_node))
        {
            ///check the corresponding node, this node must only have one out-node
            ///note this is the Real_Length, instead of the Output_Edges.length
            if((*get_node).base == base && Real_Length(Output_Edges(*get_node)) == 1)
            {
                if(flag == 0)
                {
                    flag = 1;
                    ///add a new node to merge all in-node
                    consensus_node = get_node;
                    ///link consensus_node to currentNode
                    ///set the new edge to be visited
                    if(get_bi_Edge(DAGCon, consensus_node, currentNode, &e_forward, &e_backward))
                    {
                        Visit(*e_forward) = 1;
                        Visit(*e_backward) = 1;
                    }
                    else
                    {
                        fprintf(stderr, "error\n");
                    }

                    weight = (*e_forward).weight;
                }
                else
                {
                    flag++;
                    ///add the weight of get_node->currentNode
                    if(get_bi_Edge(DAGCon, get_node, currentNode, &e_forward, &e_backward))
                    {
                        weight = weight + (*e_forward).weight;
                    }
                    else
                    {
                        fprintf(stderr, "error\n");
                    }

                    ///process the in-nodes of get_node
                    clear_RSet(&in_buf);
                    while(getInputNodes(&in_buf, DAGCon, get_node, &in_node_of_get_node))
                    {
                        ///link in-nodes of get_node to consensus_node
                        if(get_bi_Edge(DAGCon, in_node_of_get_node, consensus_node, &e_forward, &e_backward))
                        {
                            Visit(*e_forward) = 1;
                            Visit(*e_backward) = 1;
                            (*e_forward).weight += get_Edge_Weight(DAGCon, in_node_of_get_node, get_node);
                            (*e_backward).weight = (*e_forward).weight;
                        }
                        else
                        {
                            add_bi_direction_edge(DAGCon, in_node_of_get_node, consensus_node, 
                            get_Edge_Weight(DAGCon, in_node_of_get_node, get_node), 1);
                        }
                    }

                    delete_Node_DAGCon(DAGCon, get_node);
                }
            }
        }

        if(flag > 1)
        {
            get_bi_Edge(DAGCon, consensus_node, currentNode, &e_forward, &e_backward);
            (*e_forward).weight = weight;
            (*e_backward).weight = (*e_forward).weight;
        }

        if(flag > 0)
        {
            Merge_In_Nodes(DAGCon, consensus_node);   
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x78(%rcx), %rax
cmpq $0x0, %rax
jne 0x3862e
jmp 0x388fe
movl 0x34e1f1(%rip), %eax    # 0x386825
movl %eax, -0x24(%rbp)
movl $0x0, -0x3c(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x30(%rbp)
cmpq $0x4, -0x30(%rbp)
jge 0x388fe
movq -0x30(%rbp), %rax
movb -0x24(%rbp,%rax), %al
movb %al, -0x25(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x2cce0
movl $0x0, -0x3c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x18(%rbp), %rdi
leaq -0x48(%rbp), %rcx
callq 0x9fb50
cmpl $0x0, %eax
je 0x3889d
movq -0x48(%rbp), %rax
movsbl 0x18(%rax), %eax
movsbl -0x25(%rbp), %ecx
cmpl %ecx, %eax
jne 0x38898
movq -0x48(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x48(%rbp), %rcx
subq 0x58(%rcx), %rax
cmpq $0x1, %rax
jne 0x38898
cmpl $0x0, -0x3c(%rbp)
jne 0x3875f
movl $0x1, -0x3c(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x60(%rbp), %rcx
leaq -0x68(%rbp), %r8
callq 0x2c680
cmpq $0x0, %rax
je 0x38736
movq -0x60(%rbp), %rax
movq $0x1, 0x20(%rax)
movq -0x68(%rbp), %rax
movq $0x1, 0x20(%rax)
jmp 0x3874e
movq 0x38b8a3(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x349e9e(%rip), %rsi    # 0x3825e5
movb $0x0, %al
callq 0x22a0
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x38896
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x60(%rbp), %rcx
leaq -0x68(%rbp), %r8
callq 0x2c680
cmpq $0x0, %rax
je 0x38799
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
addq 0x10(%rcx), %rax
movq %rax, -0x38(%rbp)
jmp 0x387b1
movq 0x38b840(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x349e3b(%rip), %rsi    # 0x3825e5
movb $0x0, %al
callq 0x22a0
leaq -0x20(%rbp), %rdi
callq 0x2cce0
movq -0x8(%rbp), %rsi
movq -0x48(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x50(%rbp), %rcx
callq 0x9fb50
cmpl $0x0, %eax
je 0x38889
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq -0x60(%rbp), %rcx
leaq -0x68(%rbp), %r8
callq 0x2c680
cmpq $0x0, %rax
je 0x38841
movq -0x60(%rbp), %rax
movq $0x1, 0x20(%rax)
movq -0x68(%rbp), %rax
movq $0x1, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x9f9b0
movq %rax, %rcx
movq -0x60(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x38884
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x9f9b0
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %rax, %rcx
movl $0x1, %r8d
callq 0x2bbf0
jmp 0x387ba
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x9fa00
jmp 0x38898
jmp 0x3869c
cmpl $0x1, -0x3c(%rbp)
jle 0x388d8
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x60(%rbp), %rcx
leaq -0x68(%rbp), %r8
callq 0x2c680
movq -0x38(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
cmpl $0x0, -0x3c(%rbp)
jle 0x388eb
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x38600
jmp 0x388ed
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3866e
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)