// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: build_DAGCon(Graph*, Graph*, long long, long long*)
void build_DAGCon(Graph* DAGCon, Graph* backbone, long long currentNodeID, long long* max_count)
{
    long long i, j, path_weight, nodeID, step;
    char base;
    clear_Graph(DAGCon);
    Node* newNode;
    Node* lastNode;

    ///add the start node and the end node
    newNode = add_Node_DAGCon(DAGCon, 'S');
    DAGCon->s_start_nodeID = newNode->ID;

    newNode = add_Node_DAGCon(DAGCon, 'E');
    DAGCon->s_end_nodeID = newNode->ID;


    for (i = 0; i < (long long)G_Node(*backbone, currentNodeID).insertion_edges.length; i++)
    {
        path_weight = G_Node(*backbone, currentNodeID).insertion_edges.list[i].weight;
        
        lastNode = &(G_Node(*DAGCon, DAGCon->s_start_nodeID));

        step = G_Node(*backbone, currentNodeID).insertion_edges.list[i].length;
        if(step != 0)
        {
            nodeID = G_Node(*backbone, currentNodeID).insertion_edges.list[i].out_node;
        
            for (j = 0; j < step; j++)
            {
                base = G_Node(*backbone, nodeID).base;
                newNode = add_Node_DAGCon(DAGCon, base);
                add_bi_direction_edge(DAGCon, lastNode, newNode, path_weight, 0);

                nodeID = G_Node(*backbone, nodeID).insertion_edges.list[0].out_node;

                lastNode = newNode;
            }

            if(lastNode->ID != DAGCon->s_start_nodeID)
            {
                add_bi_direction_edge(DAGCon, lastNode, &(G_Node(*DAGCon, DAGCon->s_end_nodeID)), path_weight, 0);

            }
        }


        
    }


    Merge_DAGCon(DAGCon);

    ///(*max_count) = generate_best_seq_from_edges(DAGCon);
    (*max_count) = generate_best_seq_from_nodes(DAGCon);
    
    ///very important
    backbone->g_nodes.list[currentNodeID].num_insertions = 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r14
callq 0x4495d
leaq 0x18(%r14), %r12
movq 0x18(%r14), %rbx
movq %r12, %rdi
movl $0x53, %esi
callq 0x44796
shlq $0x7, %rax
movq (%rbx,%rax), %rax
movq %rax, 0xa8(%r14)
movq 0x18(%r14), %rbx
movq %r12, %rdi
movl $0x45, %esi
callq 0x44796
shlq $0x7, %rax
movq (%rbx,%rax), %rax
movq %r14, %rbx
movq %rax, 0xb0(%r14)
movq 0x18(%rbp), %rax
shlq $0x7, %r13
cmpq $0x0, 0x70(%rax,%r13)
jle 0x4ce4d
leaq (%rax,%r13), %rcx
addq $0x60, %rcx
xorl %edi, %edi
movq %r13, 0x18(%rsp)
movq %r12, 0x28(%rsp)
movq %rbx, (%rsp)
movq (%rcx), %r8
imulq $0x38, %rdi, %rsi
movq 0x20(%r8,%rsi), %r15
testq %r15, %r15
je 0x4ce38
movq 0x10(%r8,%rsi), %rcx
movq 0xa8(%rbx), %rdx
movq %rdx, %r14
shlq $0x7, %r14
addq 0x18(%rbx), %r14
testq %r15, %r15
jle 0x4ce0c
movq %rdi, 0x20(%rsp)
addq %rsi, %r8
movq %rcx, 0x8(%rsp)
movq %r14, 0x30(%rsp)
movq 0x8(%r8), %r13
shlq $0x7, %r13
movsbl 0x18(%rax,%r13), %esi
movq %rbp, %r12
movq (%rsp), %rbx
movq 0x18(%rbx), %rbp
movq 0x28(%rsp), %rdi
callq 0x44796
movq %rax, %r14
shlq $0x7, %r14
addq %rbp, %r14
movq %r12, %rbp
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
movq %r14, %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x4446e
movq 0x18(%r12), %rax
movq 0x60(%rax,%r13), %r8
decq %r15
jne 0x4cd96
movq (%rsp), %rbx
movq 0xa8(%rbx), %rdx
movq 0x18(%rsp), %r13
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rcx
cmpq %rdx, (%r14)
je 0x4ce38
movq 0xb0(%rbx), %rdx
shlq $0x7, %rdx
addq 0x18(%rbx), %rdx
movq %rdi, %r15
movq %rbx, %rdi
movq %r14, %rsi
xorl %r8d, %r8d
callq 0x4446e
movq %r15, %rdi
movq 0x18(%rbp), %rax
incq %rdi
leaq (%rax,%r13), %rcx
addq $0x60, %rcx
cmpq 0x10(%rcx), %rdi
jl 0x4cd54
movq %rbx, %rdi
callq 0x4c401
movq %rbx, %rdi
callq 0x4c937
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq 0x18(%rbp), %rax
movq $0x0, 0x10(%rax,%r13)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq