// File: /workspace/github_cpp_makefile_star2_O3/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 0x4bb5a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r15
xorl %esi, %esi
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
xorl %r10d, %r10d
movq %rdi, 0x38(%rsp)
movq 0x50(%rbx), %rax
testq %rax, %rax
jle 0x4ba85
leaq 0x1ea74b(%rip), %rcx    # 0x235c5d
movb (%rbp,%rcx), %dil
xorl %r13d, %r13d
xorl %r11d, %r11d
xorl %r14d, %r14d
movq 0x40(%rbx), %rcx
negq %rax
imulq $0x38, %r14, %rdx
incq %r14
addq %rdx, %rcx
addq $0x8, %rcx
movq (%rcx), %r12
cmpq $-0x1, %r12
jne 0x4b557
leaq (%rax,%r14), %rdx
incq %rdx
incq %r14
addq $0x38, %rcx
cmpq $0x1, %rdx
jne 0x4b535
jmp 0x4ba4d
movq 0x18(%r15), %rax
shlq $0x7, %r12
cmpb %dil, 0x18(%rax,%r12)
jne 0x4ba40
addq %rax, %r12
movq 0x70(%r12), %rcx
movq %rcx, %rdx
subq 0x78(%r12), %rdx
cmpq $0x1, %rdx
jne 0x4ba40
movb %dil, 0xf(%rsp)
testl %r13d, %r13d
je 0x4b65a
movq %r11, 0x30(%rsp)
cmpb $0x44, 0x18(%rbx)
movq %rsi, 0x20(%rsp)
je 0x4b641
movq %rcx, %rdi
negq %rdi
xorl %r8d, %r8d
cmpq %rcx, %r8
jge 0x4b641
movq 0x60(%r12), %rdx
imulq $0x38, %r8, %r9
incq %r8
addq %r9, %rdx
addq $0x30, %rdx
movq -0x28(%rdx), %r11
cmpq $-0x1, %r11
jne 0x4b5eb
addq $0x38, %rdx
leaq (%rdi,%r8), %r9
incq %r9
incq %r8
cmpq $0x1, %r9
jne 0x4b5cb
jmp 0x4b641
movq -0x30(%rdx), %r9
cmpq (%rbx), %r9
jne 0x4b5af
movq -0x8(%rdx), %rcx
movq %r9, %r8
shlq $0x7, %r8
movq 0x40(%rax,%r8), %rdi
cmpq 0x50(%rax,%r8), %rcx
jae 0x4b70f
imulq $0x38, %rcx, %r8
cmpq %r9, (%rdi,%r8)
jne 0x4b70f
addq %rdi, %r8
cmpq %r11, 0x8(%r8)
jne 0x4b70f
shlq $0x7, %r11
imulq $0x38, (%rdx), %rcx
addq 0x60(%rax,%r11), %rcx
movq %rcx, 0x10(%rsp)
jmp 0x4b72b
movq %r10, 0x28(%rsp)
callq 0x5798
movq 0x20(%rsp), %rsi
movq 0x30(%rsp), %rcx
jmp 0x4b739
cmpb $0x44, 0x18(%rbx)
je 0x4b6fa
movq %rcx, %rdi
negq %rdi
xorl %r8d, %r8d
cmpq %rcx, %r8
jge 0x4b6fa
movq 0x60(%r12), %rdx
imulq $0x38, %r8, %rsi
incq %r8
addq %rsi, %rdx
addq $0x30, %rdx
movq -0x28(%rdx), %rsi
cmpq $-0x1, %rsi
jne 0x4b6a9
addq $0x38, %rdx
leaq (%rdi,%r8), %rsi
incq %rsi
incq %r8
cmpq $0x1, %rsi
jne 0x4b689
jmp 0x4b6fa
movq -0x30(%rdx), %r9
cmpq (%rbx), %r9
jne 0x4b66d
movq -0x8(%rdx), %rcx
movq %r9, %r8
shlq $0x7, %r8
movq 0x40(%rax,%r8), %rdi
cmpq 0x50(%rax,%r8), %rcx
jae 0x4ba05
imulq $0x38, %rcx, %r10
cmpq %r9, (%rdi,%r10)
jne 0x4ba05
addq %rdi, %r10
cmpq %rsi, 0x8(%r10)
jne 0x4ba05
shlq $0x7, %rsi
imulq $0x38, (%rdx), %rcx
addq 0x60(%rax,%rsi), %rcx
jmp 0x4ba1c
movq %r10, %r13
callq 0x57b4
movq %r13, %r10
movb 0xf(%rsp), %dil
jmp 0x4ba33
imulq $0x38, (%rdx), %rdx
addq %rdx, %rdi
shlq $0x7, %r11
imulq $0x38, %rcx, %rcx
addq 0x60(%rax,%r11), %rcx
movq %rcx, 0x10(%rsp)
movq %rdi, %r8
movq %r8, 0x28(%rsp)
movq 0x30(%rsp), %rcx
addq 0x10(%r8), %rcx
movq 0x50(%r12), %rax
testq %rax, %rax
movq %rcx, 0x30(%rsp)
jle 0x4b9dc
xorl %r15d, %r15d
movq 0x40(%r12), %rdx
movq %rax, %rcx
negq %rcx
imulq $0x38, %r15, %rdi
incq %r15
addq %rdi, %rdx
addq $0x8, %rdx
movq (%rdx), %rdi
cmpq $-0x1, %rdi
jne 0x4b78a
leaq (%rcx,%r15), %rdi
incq %rdi
incq %r15
addq $0x38, %rdx
cmpq $0x1, %rdi
jne 0x4b768
jmp 0x4b9dc
movq 0x38(%rsp), %rcx
movq 0x18(%rcx), %rcx
shlq $0x7, %rdi
movq %rcx, 0x18(%rsp)
leaq (%rcx,%rdi), %rdx
cmpb $0x44, 0x18(%rsi)
je 0x4b7b6
movq 0x18(%rsp), %rcx
cmpb $0x44, 0x18(%rcx,%rdi)
jne 0x4b860
movq 0x60(%rdx), %rax
movq (%r12), %r11
leaq 0x40(%rax), %r8
xorl %r9d, %r9d
imulq $0x38, %r9, %r10
movq 0x8(%rax,%r10), %rdi
cmpq $-0x1, %rdi
jne 0x4b7e7
addq %r8, %r10
incq %r9
movq (%r10), %rdi
addq $0x38, %r10
cmpq $-0x1, %rdi
je 0x4b7d7
imulq $0x38, %r9, %r10
incq %r9
cmpq %r11, (%rax,%r10)
jne 0x4b7c5
addq %r10, %rax
movq 0x28(%rax), %r8
movq %r11, %r10
shlq $0x7, %r10
movq 0x18(%rsp), %rcx
movq 0x40(%rcx,%r10), %r9
cmpq 0x50(%rcx,%r10), %r8
movq 0x20(%rsp), %rsi
jae 0x4b82b
imulq $0x38, %r8, %rcx
cmpq %r11, (%r9,%rcx)
jne 0x4b82b
addq %r9, %rcx
cmpq %rdi, 0x8(%rcx)
je 0x4b82f
movq 0x30(%rax), %r8
imulq $0x38, %r8, %rax
movq 0x10(%r9,%rax), %rcx
movl $0x1, %r8d
movq 0x38(%rsp), %rdi
callq 0x4446e
movq 0x50(%r12), %rax
cmpq %rax, %r15
movq 0x20(%rsp), %rsi
jl 0x4b74f
jmp 0x4b9dc
movq 0x70(%rdx), %r9
movq %r9, %r10
negq %r10
xorl %r11d, %r11d
cmpq %r9, %r11
jge 0x4b7b6
movq %r9, %rcx
movq 0x60(%rdx), %r9
imulq $0x38, %r11, %rsi
incq %r11
leaq (%r9,%rsi), %rdi
addq $0x30, %rdi
movq -0x28(%rdi), %r8
cmpq $-0x1, %r8
jne 0x4b8af
addq $0x38, %rdi
leaq (%r10,%r11), %rsi
incq %rsi
incq %r11
cmpq $0x1, %rsi
jne 0x4b88c
jmp 0x4b7b6
movq %r9, 0x40(%rsp)
movq -0x30(%rdi), %rsi
movq 0x20(%rsp), %r9
cmpq (%r9), %rsi
movq %rcx, %r9
jne 0x4b86d
movq -0x8(%rdi), %rdx
movq %rsi, %r10
shlq $0x7, %r10
movq 0x18(%rsp), %rcx
movq 0x40(%rcx,%r10), %r9
cmpq 0x50(%rcx,%r10), %rdx
jae 0x4b908
imulq $0x38, %rdx, %r10
cmpq %rsi, (%r9,%r10)
jne 0x4b908
addq %r9, %r10
cmpq %r8, 0x8(%r10)
jne 0x4b908
shlq $0x7, %r8
imulq $0x38, (%rdi), %rsi
movq 0x18(%rsp), %rcx
addq 0x60(%rcx,%r8), %rsi
jmp 0x4b924
imulq $0x38, (%rdi), %rsi
addq %rsi, %r9
shlq $0x7, %r8
imulq $0x38, %rdx, %rsi
movq 0x18(%rsp), %rcx
addq 0x60(%rcx,%r8), %rsi
movq %r9, %r10
movl $0x1, %edx
movq %r10, 0x28(%rsp)
movq %rdx, 0x20(%r10)
movq %rsi, 0x10(%rsp)
movq %rdx, 0x20(%rsi)
movq (%r12), %rdx
movq 0x40(%rsp), %r11
leaq 0x40(%r11), %r8
xorl %r9d, %r9d
imulq $0x38, %r9, %r10
movq 0x8(%r11,%r10), %rdi
cmpq $-0x1, %rdi
jne 0x4b96d
addq %r8, %r10
incq %r9
movq (%r10), %rdi
addq $0x38, %r10
cmpq $-0x1, %rdi
je 0x4b95d
imulq $0x38, %r9, %rsi
incq %r9
movq 0x40(%rsp), %r11
cmpq %rdx, (%r11,%rsi)
jne 0x4b94b
addq %rsi, %r11
movq %r11, %r10
movq 0x28(%r11), %r9
movq %rdx, %rsi
shlq $0x7, %rsi
movq 0x18(%rsp), %rcx
movq 0x40(%rcx,%rsi), %r8
cmpq 0x50(%rcx,%rsi), %r9
jae 0x4b9b4
imulq $0x38, %r9, %rcx
cmpq %rdx, (%r8,%rcx)
jne 0x4b9b4
addq %r8, %rcx
cmpq %rdi, 0x8(%rcx)
je 0x4b9b8
movq 0x30(%r10), %r9
imulq $0x38, %r9, %rcx
movq 0x28(%rsp), %rsi
movq 0x10(%rsi), %rdx
addq 0x10(%r8,%rcx), %rdx
movq %rdx, 0x10(%rsi)
movq 0x10(%rsp), %rcx
movq %rdx, 0x10(%rcx)
jmp 0x4b84d
incl %r13d
movq 0x38(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x85f79
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %r10
movq 0x30(%rsp), %r11
movb 0xf(%rsp), %dil
jmp 0x4ba40
imulq $0x38, (%rdx), %rdx
addq %rdx, %rdi
shlq $0x7, %rsi
imulq $0x38, %rcx, %rcx
addq 0x60(%rax,%rsi), %rcx
movq %rdi, %r10
movb 0xf(%rsp), %dil
movl $0x1, %eax
movq %rax, 0x20(%r10)
movq %rcx, 0x10(%rsp)
movq %rax, 0x20(%rcx)
movq 0x10(%r10), %r11
movl $0x1, %r13d
movq %r12, %rsi
movq 0x50(%rbx), %rax
cmpq %rax, %r14
jl 0x4b520
cmpl $0x2, %r13d
jl 0x4ba6c
cmpb $0x44, 0x18(%rbx)
je 0x4ba5f
cmpb $0x44, 0x18(%rsi)
jne 0x4ba97
movq %r11, 0x10(%r10)
movq 0x10(%rsp), %rax
movq %r11, 0x10(%rax)
testl %r13d, %r13d
jle 0x4ba85
movq %r15, %rdi
movq %r10, %r14
movq %rsi, %r12
callq 0x4b4c7
movq %r12, %rsi
movq %r14, %r10
incq %rbp
cmpq $0x4, %rbp
jne 0x4b4fe
jmp 0x4bb4c
movq 0x70(%rsi), %rdx
movq %rdx, %r9
negq %r9
xorl %edi, %edi
cmpq %rdx, %rdi
jge 0x4ba5f
movq 0x60(%rsi), %rax
imulq $0x38, %rdi, %rcx
incq %rdi
addq %rcx, %rax
addq $0x30, %rax
movq -0x28(%rax), %rcx
cmpq $-0x1, %rcx
jne 0x4bada
addq $0x38, %rax
leaq (%r9,%rdi), %rcx
incq %rcx
incq %rdi
cmpq $0x1, %rcx
jne 0x4baba
jmp 0x4ba5f
movq -0x30(%rax), %r8
cmpq (%rbx), %r8
jne 0x4baa3
movq %r11, %r14
movq -0x8(%rax), %r11
movq 0x18(%r15), %rdx
movq %r8, %r9
shlq $0x7, %r9
movq 0x40(%rdx,%r9), %rdi
cmpq 0x50(%rdx,%r9), %r11
jae 0x4bb28
imulq $0x38, %r11, %r10
cmpq %r8, (%rdi,%r10)
jne 0x4bb28
addq %rdi, %r10
cmpq %rcx, 0x8(%r10)
jne 0x4bb28
shlq $0x7, %rcx
imulq $0x38, (%rax), %rax
addq 0x60(%rdx,%rcx), %rax
movq %rax, 0x10(%rsp)
jmp 0x4bb44
imulq $0x38, (%rax), %rax
addq %rax, %rdi
shlq $0x7, %rcx
imulq $0x38, %r11, %rax
addq 0x60(%rdx,%rcx), %rax
movq %rax, 0x10(%rsp)
movq %rdi, %r10
movq %r14, %r11
jmp 0x4ba5f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq