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

    RSet buf, out_buf;
    char Bases[4] = {'A', 'C', 'G', 'T'};
    char base;
    long long base_i, weight;
    int flag = 0;
    Node* get_node_1 = NULL;
    Node* out_node_of_get_node_1 = NULL;
    Node* consensus_node_1 = NULL;
    Edge* e_forward_1 = NULL;
    Edge* e_backward_1 = 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 getOutputEdges, instead of getOutputNodes
        ///check all out-nodes of currentNode
        while(getOutputNodes(&buf, DAGCon, currentNode, &get_node_1))
        {
            ///check the corresponding node, this node must only have one in-node
            ///note this is the Real_Length, instead of the Input_Edges.length
            if((*get_node_1).base == base && Real_Length(Input_Edges(*get_node_1)) == 1)
            {
                if(flag == 0)
                {
                    flag = 1;
                    ///add a new node to merge all out-node
                    consensus_node_1 = get_node_1;
                    ///link consensus_node to currentNode
                    ///set the new edge to be visited
                    if(get_bi_Edge(DAGCon, currentNode, consensus_node_1, &e_forward_1, &e_backward_1))
                    {
                        Visit(*e_forward_1) = 1;
                        Visit(*e_backward_1) = 1;
                    }
                    else
                    {
                        fprintf(stderr, "error\n");
                    }

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

                    ///process the out-nodes of get_node
                    clear_RSet(&out_buf);
                    while(getOutputNodes(&out_buf, DAGCon, get_node_1, &out_node_of_get_node_1))
                    {
                        ///link consensus_node to the out-nodes of get_node
                        if(get_bi_Edge(DAGCon, consensus_node_1, out_node_of_get_node_1, &e_forward_1, &e_backward_1))
                        {
                            Visit(*e_forward_1) = 1;
                            Visit(*e_backward_1) = 1;
                            (*e_forward_1).weight += get_Edge_Weight(DAGCon, get_node_1, out_node_of_get_node_1);
                            (*e_backward_1).weight = (*e_forward_1).weight;
                        }
                        else
                        {
                            add_bi_direction_edge(DAGCon, consensus_node_1, out_node_of_get_node_1, 
                            get_Edge_Weight(DAGCon, get_node_1, out_node_of_get_node_1), 1);
                        }
                    }

                    delete_Node_DAGCon(DAGCon, get_node_1);
                }
            }
        }

        if(flag > 1)
        {
            get_bi_Edge(DAGCon, currentNode, consensus_node_1, &e_forward_1, &e_backward_1);
            (*e_forward_1).weight = weight;
            (*e_backward_1).weight = (*e_forward_1).weight;
        }

        if(flag > 0)
        {
            Merge_Out_Nodes(DAGCon, consensus_node_1);   
        }
    }
}

// Assembly:
movq 0x50(%rsi), %rax
cmpq 0x58(%rsi), %rax
je 0x1eb94
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 0x1eb86
andq $0x0, 0x40(%rsp)
movq %rax, 0x30(%rsp)
leaq 0x1c9256(%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 0x5288b
testl %eax, %eax
je 0x1eb32
movq 0x20(%rsp), %rbp
cmpb %r15b, 0x18(%rbp)
jne 0x1e96c
movq 0x70(%rbp), %rax
subq 0x78(%rbp), %rax
cmpq $0x1, %rax
jne 0x1e96c
cmpl $0x0, 0xc(%rsp)
je 0x1eac9
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %rsp, %rcx
leaq 0x10(%rsp), %r8
callq 0x1871a
testq %rax, %rax
je 0x1eaa8
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 0x5288b
testl %eax, %eax
je 0x1ea96
movq 0x18(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
movq %rsp, %rcx
leaq 0x10(%rsp), %r8
callq 0x1871a
testq %rax, %rax
je 0x1ea62
movq (%rsp), %rax
pushq $0x1
popq %rcx
movq %rcx, 0x20(%rax)
movq 0x10(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x20(%rsp), %rsi
movq 0x18(%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 0x1e9eb
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %rsi
movq %r14, %rdi
movq %rbp, %rdx
callq 0x528d5
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
leaq 0x18(%rsp), %rbp
movq %rax, %rcx
pushq $0x1
popq %r8
callq 0x181b2
jmp 0x1e9eb
movq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x528ff
jmp 0x1e96c
movq 0x234531(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x1c4eb4(%rip), %rdi    # 0x1e396d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0x1e9dc
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %rsp, %rcx
leaq 0x10(%rsp), %r8
callq 0x1871a
testq %rax, %rax
je 0x1eb10
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 0x1e96c
movq 0x2344c9(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x1c4e4c(%rip), %rdi    # 0x1e396d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq (%rsp), %rax
jmp 0x1eaf8
movl 0xc(%rsp), %eax
cmpl $0x2, %eax
jb 0x1eb69
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %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 0x1eb6e
cmpl $0x1, %eax
jne 0x1eb79
movq %r14, %rdi
movq %r13, %rsi
callq 0x1e8ed
movq 0x30(%rsp), %rax
incq %rax
jmp 0x1e93b
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq