// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, %rbx
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
callq 0x18519
pushq $0x53
popq %rsi
movq %r12, %rdi
callq 0x52d66
movq (%rax), %rax
movq %rax, 0xa8(%r12)
pushq $0x45
popq %rsi
movq %r12, %rdi
callq 0x52d66
movq (%rax), %rax
movq %rax, 0xb0(%r12)
shlq $0x7, %rbx
xorl %esi, %esi
movq %rbx, 0x18(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
cmpq 0x70(%rax,%rbx), %rsi
jge 0x1f715
leaq (%rax,%rbx), %rcx
addq $0x60, %rcx
movq (%rcx), %rdx
movq %rsi, 0x20(%rsp)
imulq $0x38, %rsi, %rsi
movq 0x20(%rdx,%rsi), %rbx
testq %rbx, %rbx
je 0x1f703
leaq (%rdx,%rsi), %rcx
movq 0xa8(%r12), %r14
shlq $0x7, %r14
addq 0x18(%r12), %r14
movq 0x10(%rdx,%rsi), %r13
testq %rbx, %rbx
movl $0x0, %edx
cmovleq %rdx, %rbx
subq $0x1, %rbx
jb 0x1f6d4
movq 0x8(%rcx), %r15
shlq $0x7, %r15
movsbl 0x18(%rax,%r15), %esi
movq %r12, %rdi
callq 0x52d66
movq %rax, %rbp
movq %r12, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x181b2
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x60(%rax,%r15), %rcx
movq %rbp, %r14
jmp 0x1f68e
movq (%r14), %rax
cmpq 0xa8(%r12), %rax
je 0x1f703
movq 0xb0(%r12), %rdx
shlq $0x7, %rdx
addq 0x18(%r12), %rdx
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x181b2
movq 0x20(%rsp), %rsi
incq %rsi
movq 0x18(%rsp), %rbx
jmp 0x1f632
movq %r12, %rdi
callq 0x1f1c6
movq %r12, %rdi
callq 0x1f407
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
andq $0x0, 0x10(%rax,%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq