// File: /workspace/github_cpp_makefile_star2_O2/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:
movq 0x70(%rsi), %rax
cmpq 0x78(%rsi), %rax
je 0x1ee3c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x20(%rsp), %rax
andq $0x0, (%rax)
leaq 0x18(%rsp), %rax
andq $0x0, (%rax)
movq %rsp, %rax
andq $0x0, (%rax)
leaq 0x10(%rsp), %rax
andq $0x0, (%rax)
xorl %eax, %eax
leaq 0x40(%rsp), %r12
xorl %r13d, %r13d
cmpq $0x4, %rax
je 0x1ee2e
andq $0x0, 0x40(%rsp)
movq %rax, 0x30(%rsp)
leaq 0x1c8fae(%rip), %rcx    # 0x1e7bad
movb (%rax,%rcx), %r15b
movq $0x0, 0x28(%rsp)
movl $0x0, 0xc(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
leaq 0x20(%rsp), %rcx
callq 0x529e9
testl %eax, %eax
je 0x1edda
movq 0x20(%rsp), %rbp
cmpb %r15b, 0x18(%rbp)
jne 0x1ec14
movq 0x50(%rbp), %rax
subq 0x58(%rbp), %rax
cmpq $0x1, %rax
jne 0x1ec14
cmpl $0x0, 0xc(%rsp)
je 0x1ed71
movq %r14, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %rsp, %rcx
leaq 0x10(%rsp), %r8
callq 0x1871a
testq %rax, %rax
je 0x1ed50
movq (%rsp), %rax
movq 0x28(%rsp), %rcx
addq 0x10(%rax), %rcx
movq %rcx, 0x28(%rsp)
leaq 0x18(%rsp), %rbp
incl 0xc(%rsp)
andq $0x0, 0x38(%rsp)
movq 0x20(%rsp), %rdx
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rcx
callq 0x529e9
testl %eax, %eax
je 0x1ed3e
movq 0x18(%rsp), %rsi
movq %r14, %rdi
movq %r13, %rdx
movq %rsp, %rcx
leaq 0x10(%rsp), %r8
callq 0x1871a
testq %rax, %rax
je 0x1ed0a
movq (%rsp), %rax
pushq $0x1
popq %rcx
movq %rcx, 0x20(%rax)
movq 0x10(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x528d5
movq (%rsp), %rcx
addq 0x10(%rcx), %rax
movq %rax, 0x10(%rcx)
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
jmp 0x1ec93
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %rdx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x528d5
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x18(%rsp), %rbp
movq %r13, %rdx
movq %rax, %rcx
pushq $0x1
popq %r8
callq 0x181b2
jmp 0x1ec93
movq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x528ff
jmp 0x1ec14
movq 0x234289(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x1c4c0c(%rip), %rdi    # 0x1e396d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0x1ec84
movq %r14, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %rsp, %rcx
leaq 0x10(%rsp), %r8
callq 0x1871a
testq %rax, %rax
je 0x1edb8
movq (%rsp), %rax
pushq $0x1
popq %rdx
movq %rdx, 0x20(%rax)
movq 0x10(%rsp), %rcx
movq %rdx, 0x20(%rcx)
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
pushq $0x1
popq %rax
movl %eax, 0xc(%rsp)
movq %rbp, %r13
jmp 0x1ec14
movq 0x234221(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x1c4ba4(%rip), %rdi    # 0x1e396d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq (%rsp), %rax
jmp 0x1eda0
movl 0xc(%rsp), %eax
cmpl $0x2, %eax
jb 0x1ee11
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %rsp, %rcx
leaq 0x10(%rsp), %r8
callq 0x1871a
movq (%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0x1ee16
cmpl $0x1, %eax
jne 0x1ee21
movq %r14, %rdi
movq %r13, %rsi
callq 0x1eb95
movq 0x30(%rsp), %rax
incq %rax
jmp 0x1ebe3
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq