// File: /workspace/github_cpp_makefile_star2_O1/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 0x4ce48
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r13
xorl %esi, %esi
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
xorl %r8d, %r8d
xorl %r11d, %r11d
xorl %r12d, %r12d
leaq 0x1dd4f6(%rip), %rax    # 0x229b4d
movb (%rbp,%rax), %r15b
xorl %r14d, %r14d
movq $0x0, 0x28(%rsp)
xorl %r10d, %r10d
movq 0x70(%rbx), %rax
leaq -0x1(%rax), %rcx
movq %rsi, 0x8(%rsp)
movb $0x1, %dl
cmpq %rax, %r14
jge 0x4c6df
movq 0x60(%rbx), %r9
imulq $0x38, %r14, %rdi
movb $0x1, %dl
cmpq $-0x1, 0x8(%r9,%rdi)
je 0x4c696
movb $0x1, %dil
jmp 0x4c6b6
addq %r9, %rdi
addq $0x40, %rdi
cmpq %r14, %rcx
je 0x4c6dc
incq %r14
cmpq $-0x1, (%rdi)
leaq 0x38(%rdi), %rdi
je 0x4c69d
cmpq %rax, %r14
setl %dil
testb %dil, %dil
je 0x4c6df
imulq $0x38, %r14, %rdi
cmpq $-0x1, 0x8(%r9,%rdi)
je 0x4c6df
addq %rdi, %r9
movq (%r9), %r12
shlq $0x7, %r12
addq 0x18(%r13), %r12
incq %r14
xorl %edx, %edx
jmp 0x4c6df
movq %rax, %r14
testb %dl, %dl
jne 0x4cce7
movb 0x18(%r12), %dil
cmpb %r15b, %dil
jne 0x4c678
movq 0x50(%r12), %rdx
subq 0x58(%r12), %rdx
cmpq $0x1, %rdx
jne 0x4c678
testl %r10d, %r10d
jne 0x4c84e
movb $0x1, %dl
cmpb $0x44, %dil
je 0x4c806
cmpb $0x44, 0x18(%rbx)
je 0x4c806
movq %r8, 0x20(%rsp)
xorl %edi, %edi
movb $0x1, %dl
cmpq %rax, %rdi
jge 0x4c74a
movq 0x60(%rbx), %r9
imulq $0x38, %rdi, %r10
movb $0x1, %r8b
cmpq $-0x1, 0x8(%r9,%r10)
je 0x4c74f
movb $0x1, %r10b
jmp 0x4c76f
movb $0x1, %r8b
jmp 0x4c791
addq %r9, %r10
addq $0x40, %r10
cmpq %rdi, %rcx
je 0x4c78e
incq %rdi
cmpq $-0x1, (%r10)
leaq 0x38(%r10), %r10
je 0x4c756
cmpq %rax, %rdi
setl %r10b
testb %r10b, %r10b
je 0x4c791
imulq $0x38, %rdi, %r10
cmpq $-0x1, 0x8(%r9,%r10)
je 0x4c791
addq %r10, %r9
incq %rdi
xorl %r8d, %r8d
movq %r9, %rsi
jmp 0x4c791
movq %rax, %rdi
testb %r8b, %r8b
jne 0x4c7e3
movq (%rsi), %r8
cmpq (%r12), %r8
jne 0x4c72b
movq 0x8(%rsi), %rax
movq 0x28(%rsi), %rdx
movq 0x18(%r13), %rcx
movq %r8, %rdi
shlq $0x7, %rdi
addq %rcx, %rdi
addq $0x40, %rdi
cmpq 0x10(%rdi), %rdx
jae 0x4c7ea
movq (%rdi), %r10
imulq $0x38, %rdx, %r9
cmpq %r8, (%r10,%r9)
jne 0x4c7ea
movq %r10, %r8
addq %r9, %r8
cmpq %rax, 0x8(%r8)
jne 0x4c7ea
imulq $0x38, 0x30(%rsi), %rdx
shlq $0x7, %rax
jmp 0x4c7fa
movq 0x20(%rsp), %r8
jmp 0x4c806
imulq $0x38, 0x30(%rsi), %r8
addq (%rdi), %r8
shlq $0x7, %rax
imulq $0x38, %rdx, %rdx
addq 0x60(%rcx,%rax), %rdx
movq %rdx, 0x10(%rsp)
xorl %edx, %edx
testb %dl, %dl
jne 0x4c833
movl $0x1, %eax
movq %rax, 0x20(%r8)
movq 0x10(%rsp), %rcx
movq %rax, 0x20(%rcx)
movq 0x10(%r8), %rax
movq %rax, 0x28(%rsp)
movl $0x1, %r10d
movq %r12, %rsi
jmp 0x4c66b
movq %r11, 0x38(%rsp)
movq %r8, 0x20(%rsp)
callq 0x570c
movq 0x20(%rsp), %r8
movq 0x38(%rsp), %r11
jmp 0x4c81c
movb $0x1, %sil
cmpb $0x44, %dil
je 0x4c95e
cmpb $0x44, 0x18(%rbx)
je 0x4c95e
movq %r8, 0x20(%rsp)
xorl %edi, %edi
movb $0x1, %sil
cmpq %rax, %rdi
jge 0x4c88f
movl %r10d, %esi
movq 0x60(%rbx), %r9
imulq $0x38, %rdi, %r10
movb $0x1, %r8b
cmpq $-0x1, 0x8(%r9,%r10)
je 0x4c894
movb $0x1, %r10b
jmp 0x4c8b4
movb $0x1, %r8b
jmp 0x4c8dc
addq %r9, %r10
addq $0x40, %r10
cmpq %rdi, %rcx
je 0x4c8d3
incq %rdi
cmpq $-0x1, (%r10)
leaq 0x38(%r10), %r10
je 0x4c89b
cmpq %rax, %rdi
setl %r10b
testb %r10b, %r10b
je 0x4c8d6
imulq $0x38, %rdi, %r10
cmpq $-0x1, 0x8(%r9,%r10)
je 0x4c8d6
addq %r10, %r9
incq %rdi
xorl %r8d, %r8d
movq %r9, %rdx
jmp 0x4c8d6
movq %rax, %rdi
movl %esi, %r10d
movb $0x1, %sil
testb %r8b, %r8b
jne 0x4c93b
movq (%rdx), %r8
cmpq (%r12), %r8
jne 0x4c86c
movq 0x8(%rdx), %rax
movq %rdx, %rsi
movq 0x28(%rdx), %rdx
movq 0x18(%r13), %rcx
movq %r8, %rdi
shlq $0x7, %rdi
addq %rcx, %rdi
addq $0x40, %rdi
cmpq 0x10(%rdi), %rdx
jae 0x4c942
movl %r10d, 0x1c(%rsp)
movq (%rdi), %r10
imulq $0x38, %rdx, %r9
cmpq %r8, (%r10,%r9)
movq %r10, %r8
movl 0x1c(%rsp), %r10d
jne 0x4c942
addq %r9, %r8
cmpq %rax, 0x8(%r8)
jne 0x4c942
imulq $0x38, 0x30(%rsi), %rdx
shlq $0x7, %rax
jmp 0x4c952
movq 0x20(%rsp), %r8
jmp 0x4c95e
imulq $0x38, 0x30(%rsi), %r8
addq (%rdi), %r8
shlq $0x7, %rax
imulq $0x38, %rdx, %rdx
addq 0x60(%rcx,%rax), %rdx
movq %rdx, 0x10(%rsp)
xorl %esi, %esi
testb %sil, %sil
movq %r13, 0x30(%rsp)
jne 0x4ccc3
movq 0x28(%rsp), %rax
addq 0x10(%r8), %rax
movq %rax, 0x28(%rsp)
incl %r10d
movl %r10d, 0x1c(%rsp)
xorl %r13d, %r13d
movq %rbp, 0x40(%rsp)
movq 0x70(%r12), %rdx
movb $0x1, %al
cmpq %rdx, %r13
jge 0x4c9b2
movq 0x60(%r12), %rcx
imulq $0x38, %r13, %rsi
movb $0x1, %al
cmpq $-0x1, 0x8(%rcx,%rsi)
movq 0x8(%rsp), %r10
je 0x4c9b9
movb $0x1, %dl
jmp 0x4c9dd
movq 0x8(%rsp), %r10
jmp 0x4ca0a
leaq (%rcx,%rsi), %rdi
addq $0x40, %rdi
leaq -0x1(%rdx), %rsi
cmpq %r13, %rsi
je 0x4ca07
incq %r13
cmpq $-0x1, (%rdi)
leaq 0x38(%rdi), %rdi
je 0x4c9c5
cmpq %rdx, %r13
setl %dl
testb %dl, %dl
je 0x4ca0a
imulq $0x38, %r13, %rdx
cmpq $-0x1, 0x8(%rcx,%rdx)
je 0x4ca0a
addq %rdx, %rcx
movq (%rcx), %r11
shlq $0x7, %r11
movq 0x30(%rsp), %rax
addq 0x18(%rax), %r11
incq %r13
xorl %eax, %eax
jmp 0x4ca0a
movq %rdx, %r13
testb %al, %al
jne 0x4cc8f
movb $0x1, %al
cmpb $0x44, 0x18(%r11)
je 0x4cb22
cmpb $0x44, 0x18(%r10)
je 0x4cb22
movq %r8, 0x20(%rsp)
movq 0x70(%r10), %rdx
leaq -0x1(%rdx), %rsi
xorl %edi, %edi
movb $0x1, %al
cmpq %rdx, %rdi
jge 0x4ca58
movq 0x60(%r10), %r9
imulq $0x38, %rdi, %r10
movb $0x1, %r8b
cmpq $-0x1, 0x8(%r9,%r10)
je 0x4ca5d
movb $0x1, %r10b
jmp 0x4ca7d
movb $0x1, %r8b
jmp 0x4caa4
addq %r9, %r10
addq $0x40, %r10
cmpq %rdi, %rsi
je 0x4ca9c
incq %rdi
cmpq $-0x1, (%r10)
leaq 0x38(%r10), %r10
je 0x4ca64
cmpq %rdx, %rdi
setl %r10b
testb %r10b, %r10b
je 0x4ca9f
imulq $0x38, %rdi, %r10
cmpq $-0x1, 0x8(%r9,%r10)
je 0x4ca9f
addq %r10, %r9
incq %rdi
xorl %r8d, %r8d
movq %r9, %rcx
jmp 0x4ca9f
movq %rdx, %rdi
movq 0x8(%rsp), %r10
testb %r8b, %r8b
jne 0x4caff
movq (%rcx), %r8
cmpq (%r11), %r8
jne 0x4ca39
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rsi
movq 0x30(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq %r8, %rdi
shlq $0x7, %rdi
addq %rdx, %rdi
addq $0x40, %rdi
cmpq 0x10(%rdi), %rsi
jae 0x4cb06
movq (%rdi), %r10
imulq $0x38, %rsi, %r9
cmpq %r8, (%r10,%r9)
movq %r10, %r8
movq 0x8(%rsp), %r10
jne 0x4cb06
addq %r9, %r8
cmpq %rax, 0x8(%r8)
jne 0x4cb06
imulq $0x38, 0x30(%rcx), %rcx
shlq $0x7, %rax
jmp 0x4cb16
movq 0x20(%rsp), %r8
jmp 0x4cb22
imulq $0x38, 0x30(%rcx), %r8
addq (%rdi), %r8
shlq $0x7, %rax
imulq $0x38, %rsi, %rcx
addq 0x60(%rdx,%rax), %rcx
movq %rcx, 0x10(%rsp)
xorl %eax, %eax
testb %al, %al
je 0x4cbdb
movq %r8, 0x20(%rsp)
movq 0x60(%r12), %rax
movq (%r11), %rcx
leaq 0x40(%rax), %rdx
xorl %esi, %esi
imulq $0x38, %rsi, %rdi
cmpq $-0x1, 0x8(%rax,%rdi)
jne 0x4cb59
addq %rdx, %rdi
incq %rsi
cmpq $-0x1, (%rdi)
leaq 0x38(%rdi), %rdi
je 0x4cb4c
imulq $0x38, %rsi, %rdi
movq (%rax,%rdi), %r8
incq %rsi
cmpq %rcx, %r8
jne 0x4cb3d
leaq (%rax,%rdi), %rcx
movq 0x28(%rcx), %r9
movq 0x30(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq %r8, %rsi
shlq $0x7, %rsi
addq %rsi, %rdx
addq $0x40, %rdx
cmpq 0x10(%rdx), %r9
jae 0x4cba9
movq (%rdx), %rsi
imulq $0x38, %r9, %r9
cmpq %r8, (%rsi,%r9)
jne 0x4cba9
movq 0x8(%rax,%rdi), %rax
addq %r9, %rsi
cmpq %rax, 0x8(%rsi)
je 0x4cbb1
imulq $0x38, 0x30(%rcx), %rsi
addq (%rdx), %rsi
movq 0x10(%rsi), %rcx
movl $0x1, %r8d
movq 0x30(%rsp), %rdi
movq %r11, %rsi
movq %r10, %rdx
movq %r11, %rbp
callq 0x44de5
movq %rbp, %r11
movq 0x20(%rsp), %r8
jmp 0x4c98a
movl $0x1, %eax
movq %r8, %r10
movq %rax, 0x20(%r8)
movq 0x10(%rsp), %rcx
movq %rax, 0x20(%rcx)
movq 0x60(%r12), %rax
movq (%r11), %rcx
leaq 0x40(%rax), %rdx
xorl %esi, %esi
imulq $0x38, %rsi, %rdi
cmpq $-0x1, 0x8(%rax,%rdi)
jne 0x4cc1a
addq %rdx, %rdi
incq %rsi
cmpq $-0x1, (%rdi)
leaq 0x38(%rdi), %rdi
je 0x4cc0d
imulq $0x38, %rsi, %rdi
movq (%rax,%rdi), %r8
incq %rsi
cmpq %rcx, %r8
jne 0x4cbfe
leaq (%rax,%rdi), %rcx
movq 0x28(%rcx), %r9
movq 0x30(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq %r8, %rsi
shlq $0x7, %rsi
addq %rsi, %rdx
addq $0x40, %rdx
cmpq 0x10(%rdx), %r9
jae 0x4cc6a
movq (%rdx), %rsi
imulq $0x38, %r9, %r9
cmpq %r8, (%rsi,%r9)
jne 0x4cc6a
movq 0x8(%rax,%rdi), %rax
addq %r9, %rsi
cmpq %rax, 0x8(%rsi)
je 0x4cc72
imulq $0x38, 0x30(%rcx), %rsi
addq (%rdx), %rsi
movq %r10, %r8
movq 0x10(%r10), %rax
addq 0x10(%rsi), %rax
movq %rax, 0x10(%r10)
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
jmp 0x4c98a
movq 0x30(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r11, 0x38(%rsp)
movq %r8, %rbp
callq 0x868c0
movq 0x8(%rsp), %rsi
movq %rbp, %r8
movq 0x38(%rsp), %r11
movq 0x40(%rsp), %rbp
movl 0x1c(%rsp), %r10d
jmp 0x4c66b
movq %r11, 0x38(%rsp)
movq %r8, %r13
movl %r10d, 0x1c(%rsp)
callq 0x56f0
movl 0x1c(%rsp), %r10d
movq %r13, %r8
movq 0x38(%rsp), %r11
jmp 0x4c97a
cmpl $0x2, %r10d
jl 0x4ce0f
cmpb $0x44, 0x18(%rsi)
je 0x4cdfd
cmpb $0x44, 0x18(%rbx)
je 0x4cdfd
xorl %r14d, %r14d
movb $0x1, %dil
cmpq %rax, %r14
jge 0x4cd7a
movl %r10d, %r15d
movq %r8, %r10
movq 0x60(%rbx), %r8
imulq $0x38, %r14, %r9
movb $0x1, %dil
cmpq $-0x1, 0x8(%r8,%r9)
je 0x4cd2e
movb $0x1, %r9b
jmp 0x4cd4e
addq %r8, %r9
addq $0x40, %r9
cmpq %r14, %rcx
je 0x4cd6c
incq %r14
cmpq $-0x1, (%r9)
leaq 0x38(%r9), %r9
je 0x4cd35
cmpq %rax, %r14
setl %r9b
testb %r9b, %r9b
je 0x4cd6f
imulq $0x38, %r14, %r9
cmpq $-0x1, 0x8(%r8,%r9)
je 0x4cd6f
addq %r9, %r8
incq %r14
xorl %edi, %edi
movq %r8, %rdx
jmp 0x4cd6f
movq %rax, %r14
movq %r10, %r8
movq 0x8(%rsp), %rsi
movl %r15d, %r10d
testb %dil, %dil
jne 0x4cdfd
movq (%rdx), %rdi
cmpq (%rsi), %rdi
jne 0x4cd08
movl %r10d, %r14d
movq 0x8(%rdx), %rax
movq 0x28(%rdx), %rsi
movq 0x18(%r13), %rcx
movq %rdi, %r8
shlq $0x7, %r8
addq %rcx, %r8
addq $0x40, %r8
cmpq 0x10(%r8), %rsi
jae 0x4cdd8
movq (%r8), %r10
imulq $0x38, %rsi, %r9
cmpq %rdi, (%r10,%r9)
jne 0x4cdd8
addq %r9, %r10
cmpq %rax, 0x8(%r10)
jne 0x4cdd8
shlq $0x7, %rax
imulq $0x38, 0x30(%rdx), %rdx
addq 0x60(%rcx,%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %r10, %r8
jmp 0x4cdf5
imulq $0x38, 0x30(%rdx), %rdx
addq (%r8), %rdx
movq %rdx, %r8
shlq $0x7, %rax
imulq $0x38, %rsi, %rdx
addq 0x60(%rcx,%rax), %rdx
movq %rdx, 0x10(%rsp)
movq 0x8(%rsp), %rsi
movl %r14d, %r10d
movq 0x28(%rsp), %rcx
movq %rcx, 0x10(%r8)
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
testl %r10d, %r10d
jle 0x4ce2d
movq %r13, %rdi
movq %r11, %r14
movq %r8, %r15
callq 0x4c618
movq 0x8(%rsp), %rsi
movq %r15, %r8
movq %r14, %r11
incq %rbp
cmpq $0x4, %rbp
jne 0x4c650
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq