// File: /workspace/github_cpp_makefile_star2_O3/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 0x4c1ac
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r15
movq $0x0, 0x18(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
xorl %r11d, %r11d
movq %rdi, 0x30(%rsp)
movq 0x70(%rbx), %rax
testq %rax, %rax
jle 0x4c0d3
leaq 0x1ea0b0(%rip), %rcx    # 0x235c5d
movb (%rbp,%rcx), %r8b
xorl %r13d, %r13d
xorl %r9d, %r9d
xorl %r14d, %r14d
movq 0x60(%rbx), %rdx
imulq $0x38, %r14, %rcx
incq %r14
leaq (%rdx,%rcx), %rdi
addq $0x8, %rdi
movq %rax, %rsi
negq %rsi
cmpq $-0x1, (%rdi)
jne 0x4bbf3
addq $0x38, %rdi
leaq (%rsi,%r14), %rcx
incq %rcx
incq %r14
cmpq $0x1, %rcx
jne 0x4bbd4
jmp 0x4c097
movq 0x18(%r15), %rcx
movq -0x8(%rdi), %r12
shlq $0x7, %r12
cmpb %r8b, 0x18(%rcx,%r12)
jne 0x4c08a
addq %rcx, %r12
movq 0x50(%r12), %rdi
subq 0x58(%r12), %rdi
cmpq $0x1, %rdi
jne 0x4c08a
movb %r8b, 0xf(%rsp)
testl %r13d, %r13d
je 0x4bcda
movq %r9, 0x38(%rsp)
cmpb $0x44, 0x18(%rbx)
je 0x4bcc6
addq $0x30, %rdx
xorl %r9d, %r9d
cmpq %rax, %r9
jge 0x4bcc6
imulq $0x38, %r9, %rdi
incq %r9
addq %rdx, %rdi
movq -0x28(%rdi), %r8
cmpq $-0x1, %r8
jne 0x4bc74
addq $0x38, %rdi
leaq (%rsi,%r9), %r8
incq %r8
incq %r9
cmpq $0x1, %r8
jne 0x4bc54
jmp 0x4bcc6
movq -0x30(%rdi), %r10
cmpq (%r12), %r10
jne 0x4bc45
movq -0x8(%rdi), %rax
movq %r10, %rsi
shlq $0x7, %rsi
movq 0x40(%rcx,%rsi), %rdx
cmpq 0x50(%rcx,%rsi), %rax
jae 0x4bd7c
imulq $0x38, %rax, %rsi
cmpq %r10, (%rdx,%rsi)
jne 0x4bd7c
addq %rdx, %rsi
cmpq %r8, 0x8(%rsi)
jne 0x4bd7c
shlq $0x7, %r8
imulq $0x38, (%rdi), %r9
addq 0x60(%rcx,%r8), %r9
jmp 0x4bd93
movq %r11, 0x20(%rsp)
callq 0x57d0
movq 0x10(%rsp), %r9
jmp 0x4bda6
cmpb $0x44, 0x18(%rbx)
je 0x4bd6c
addq $0x30, %rdx
xorl %r9d, %r9d
cmpq %rax, %r9
jge 0x4bd6c
imulq $0x38, %r9, %rdi
incq %r9
addq %rdx, %rdi
movq -0x28(%rdi), %r8
cmpq $-0x1, %r8
jne 0x4bd1a
addq $0x38, %rdi
leaq (%rsi,%r9), %r8
incq %r8
incq %r9
cmpq $0x1, %r8
jne 0x4bcfa
jmp 0x4bd6c
movq -0x30(%rdi), %r10
cmpq (%r12), %r10
jne 0x4bceb
movq -0x8(%rdi), %rax
movq %r10, %rsi
shlq $0x7, %rsi
movq 0x40(%rcx,%rsi), %rdx
cmpq 0x50(%rcx,%rsi), %rax
jae 0x4c04d
imulq $0x38, %rax, %r11
cmpq %r10, (%rdx,%r11)
jne 0x4c04d
addq %rdx, %r11
cmpq %r8, 0x8(%r11)
jne 0x4c04d
shlq $0x7, %r8
imulq $0x38, (%rdi), %rsi
addq 0x60(%rcx,%r8), %rsi
jmp 0x4c064
movq %r11, %r13
callq 0x57ec
movq %r13, %r11
jmp 0x4c076
imulq $0x38, (%rdi), %rsi
addq %rsi, %rdx
shlq $0x7, %r8
imulq $0x38, %rax, %r9
addq 0x60(%rcx,%r8), %r9
movq %rdx, %rsi
movq %rsi, 0x20(%rsp)
movq 0x38(%rsp), %rax
addq 0x10(%rsi), %rax
movq %rax, 0x38(%rsp)
movq 0x70(%r12), %rcx
testq %rcx, %rcx
jle 0x4c024
xorl %r15d, %r15d
movq 0x60(%r12), %rax
imulq $0x38, %r15, %rdx
incq %r15
leaq (%rax,%rdx), %rsi
addq $0x8, %rsi
movq %rcx, %rdx
negq %rdx
cmpq $-0x1, (%rsi)
jne 0x4bdf0
addq $0x38, %rsi
leaq (%rdx,%r15), %rdi
incq %rdi
incq %r15
cmpq $0x1, %rdi
jne 0x4bdd1
jmp 0x4c024
movq %r9, 0x10(%rsp)
movq 0x30(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq -0x8(%rsi), %rdi
shlq $0x7, %rdi
leaq (%rdx,%rdi), %rsi
cmpb $0x44, 0x18(%rdx,%rdi)
je 0x4be20
movq 0x18(%rsp), %rdi
cmpb $0x44, 0x18(%rdi)
jne 0x4bec0
movq (%rsi), %rcx
leaq 0x40(%rax), %r8
xorl %r9d, %r9d
imulq $0x38, %r9, %r10
movq 0x8(%rax,%r10), %rdi
cmpq $-0x1, %rdi
jne 0x4be4c
addq %r8, %r10
incq %r9
movq (%r10), %rdi
addq $0x38, %r10
cmpq $-0x1, %rdi
je 0x4be3c
imulq $0x38, %r9, %r10
incq %r9
cmpq %rcx, (%rax,%r10)
jne 0x4be2a
addq %r10, %rax
movq 0x28(%rax), %r8
movq %rcx, %r10
shlq $0x7, %r10
movq 0x40(%rdx,%r10), %r9
cmpq 0x50(%rdx,%r10), %r8
jae 0x4be86
imulq $0x38, %r8, %rdx
cmpq %rcx, (%r9,%rdx)
jne 0x4be86
addq %r9, %rdx
cmpq %rdi, 0x8(%rdx)
je 0x4be8a
movq 0x30(%rax), %r8
imulq $0x38, %r8, %rax
movq 0x10(%r9,%rax), %rcx
movl $0x1, %r8d
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rdx
callq 0x4446e
movq 0x70(%r12), %rcx
movq 0x10(%rsp), %r9
cmpq %rcx, %r15
jl 0x4bdb7
jmp 0x4c024
movq %rsi, 0x28(%rsp)
movq 0x18(%rsp), %rdi
movq 0x70(%rdi), %r8
movq %r8, %r11
negq %r11
xorl %edi, %edi
cmpq %r8, %rdi
movq 0x28(%rsp), %rsi
jge 0x4be20
movq 0x18(%rsp), %r9
movq 0x60(%r9), %r9
imulq $0x38, %rdi, %r10
incq %rdi
addq %r10, %r9
addq $0x30, %r9
movq -0x28(%r9), %r10
cmpq $-0x1, %r10
jne 0x4bf1e
addq $0x38, %r9
leaq (%r11,%rdi), %r10
incq %r10
incq %rdi
cmpq $0x1, %r10
jne 0x4befb
jmp 0x4be20
movq -0x30(%r9), %rsi
movq %rcx, 0x40(%rsp)
movq 0x28(%rsp), %rcx
cmpq (%rcx), %rsi
movq 0x40(%rsp), %rcx
jne 0x4bed6
movq -0x8(%r9), %rdi
movq %rsi, %r11
movq %rsi, %r8
shlq $0x7, %r8
movq 0x40(%rdx,%r8), %rsi
movq 0x50(%rdx,%r8), %r8
movq %r8, 0x28(%rsp)
cmpq %r8, %rdi
movq %rsi, 0x20(%rsp)
jae 0x4bf7a
imulq $0x38, %rdi, %r8
cmpq %r11, (%rsi,%r8)
jne 0x4bf7a
addq %rsi, %r8
cmpq %r10, 0x8(%r8)
jne 0x4bf7a
shlq $0x7, %r10
imulq $0x38, (%r9), %rdi
jmp 0x4bf89
imulq $0x38, (%r9), %r8
addq %rsi, %r8
shlq $0x7, %r10
imulq $0x38, %rdi, %rdi
addq 0x60(%rdx,%r10), %rdi
movl $0x1, %edx
movq %rdx, 0x20(%r8)
movq %rdi, 0x10(%rsp)
movq %rdx, 0x20(%rdi)
leaq 0x40(%rax), %rdx
xorl %r10d, %r10d
imulq $0x38, %r10, %rdi
movq 0x8(%rax,%rdi), %r9
cmpq $-0x1, %r9
jne 0x4bfc9
addq %rdx, %rdi
incq %r10
movq (%rdi), %r9
addq $0x38, %rdi
cmpq $-0x1, %r9
je 0x4bfb9
imulq $0x38, %r10, %rdi
incq %r10
cmpq %r11, (%rax,%rdi)
jne 0x4bfa7
addq %rdi, %rax
movq 0x28(%rax), %rdx
cmpq 0x28(%rsp), %rdx
movq 0x20(%rsp), %r10
jae 0x4bffc
imulq $0x38, %rdx, %rdi
cmpq %r11, (%r10,%rdi)
jne 0x4bffc
addq %r10, %rdi
cmpq %r9, 0x8(%rdi)
je 0x4c000
movq 0x30(%rax), %rdx
imulq $0x38, %rdx, %rax
movq 0x10(%r8), %rdx
addq 0x10(%r10,%rax), %rdx
movq %r8, 0x20(%rsp)
movq %rdx, 0x10(%r8)
movq 0x10(%rsp), %r9
movq %rdx, 0x10(%r9)
jmp 0x4beb2
movq %r9, 0x10(%rsp)
incl %r13d
movq 0x30(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x85f79
movq 0x20(%rsp), %r11
movq 0x38(%rsp), %r9
movb 0xf(%rsp), %r8b
jmp 0x4c08a
imulq $0x38, (%rdi), %rsi
addq %rsi, %rdx
shlq $0x7, %r8
imulq $0x38, %rax, %rsi
addq 0x60(%rcx,%r8), %rsi
movq %rdx, %r11
movl $0x1, %eax
movq %rax, 0x20(%r11)
movq %rsi, 0x10(%rsp)
movq %rax, 0x20(%rsi)
movb 0xf(%rsp), %r8b
movq 0x10(%r11), %r9
movl $0x1, %r13d
movq %r12, 0x18(%rsp)
movq 0x70(%rbx), %rax
cmpq %rax, %r14
jl 0x4bbbb
cmpl $0x2, %r13d
jl 0x4c0bb
movq 0x18(%rsp), %rcx
cmpb $0x44, 0x18(%rcx)
je 0x4c0ae
cmpb $0x44, 0x18(%rbx)
jne 0x4c0e5
movq %r9, 0x10(%r11)
movq 0x10(%rsp), %rax
movq %r9, 0x10(%rax)
testl %r13d, %r13d
jle 0x4c0d3
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq %r11, %r14
callq 0x4bb5b
movq %r14, %r11
incq %rbp
cmpq $0x4, %rbp
jne 0x4bb99
jmp 0x4c19e
movq %rax, %rsi
negq %rsi
xorl %edi, %edi
cmpq %rax, %rdi
jge 0x4c0ae
movq 0x60(%rbx), %rcx
imulq $0x38, %rdi, %rdx
incq %rdi
addq %rdx, %rcx
addq $0x30, %rcx
movq -0x28(%rcx), %rdx
cmpq $-0x1, %rdx
jne 0x4c124
addq $0x38, %rcx
leaq (%rsi,%rdi), %rdx
incq %rdx
incq %rdi
cmpq $0x1, %rdx
jne 0x4c104
jmp 0x4c0ae
movq -0x30(%rcx), %r8
movq %r9, %r10
movq 0x18(%rsp), %r9
cmpq (%r9), %r8
movq %r10, %r9
jne 0x4c0ed
movq -0x8(%rcx), %rsi
movq 0x18(%r15), %rax
movq %r8, %r9
shlq $0x7, %r9
movq 0x40(%rax,%r9), %rdi
cmpq 0x50(%rax,%r9), %rsi
jae 0x4c17a
imulq $0x38, %rsi, %r11
cmpq %r8, (%rdi,%r11)
jne 0x4c17a
addq %rdi, %r11
cmpq %rdx, 0x8(%r11)
jne 0x4c17a
shlq $0x7, %rdx
imulq $0x38, (%rcx), %rcx
addq 0x60(%rax,%rdx), %rcx
movq %rcx, 0x10(%rsp)
jmp 0x4c196
imulq $0x38, (%rcx), %rcx
addq %rcx, %rdi
shlq $0x7, %rdx
imulq $0x38, %rsi, %rcx
addq 0x60(%rax,%rdx), %rcx
movq %rcx, 0x10(%rsp)
movq %rdi, %r11
movq %r10, %r9
jmp 0x4c0ae
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq