// File: /workspace/github_cpp_makefile_star2_O1/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, 0x18(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
callq 0x45328
leaq 0x18(%r12), %rbp
movq 0x18(%r12), %rbx
movq %rbp, %rdi
movl $0x53, %esi
callq 0x45147
shlq $0x7, %rax
movq (%rbx,%rax), %rax
movq %rax, 0xa8(%r12)
movq 0x18(%r12), %rbx
movq %rbp, %rdi
movl $0x45, %esi
callq 0x45147
shlq $0x7, %rax
movq (%rbx,%rax), %rax
movq %rax, 0xb0(%r12)
movq 0x18(%r15), %rax
shlq $0x7, %r14
movq %r14, (%rsp)
cmpq $0x0, 0x70(%rax,%r14)
jle 0x4dc0f
movq (%rsp), %rcx
addq %rcx, %rax
addq $0x60, %rax
xorl %ebx, %ebx
movq %r15, 0x30(%rsp)
movq %r12, 0x8(%rsp)
movq %rbp, 0x28(%rsp)
movq (%rax), %rax
imulq $0x38, %rbx, %rcx
movq 0x20(%rax,%rcx), %r13
testq %r13, %r13
je 0x4dbf3
movq %rbx, 0x20(%rsp)
movq 0x10(%rax,%rcx), %rdx
movq %rdx, 0x10(%rsp)
movq 0xa8(%r12), %rbx
shlq $0x7, %rbx
addq 0x18(%r12), %rbx
testq %r13, %r13
jle 0x4dbb5
addq %rcx, %rax
movq 0x8(%rax), %rbp
movq 0x18(%r15), %rax
shlq $0x7, %rbp
movsbl 0x18(%rax,%rbp), %esi
movq 0x8(%rsp), %r12
movq 0x18(%r12), %r15
movq 0x28(%rsp), %rdi
callq 0x45147
movq %rax, %r14
shlq $0x7, %r14
addq %r15, %r14
movq 0x30(%rsp), %r15
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq 0x10(%rsp), %rcx
xorl %r8d, %r8d
callq 0x44de5
movq 0x18(%r15), %rax
movq 0x60(%rax,%rbp), %rax
movq %r14, %rbx
decq %r13
jne 0x4db58
jmp 0x4dbb8
movq %rbx, %r14
movq (%r14), %rax
movq 0x8(%rsp), %r12
cmpq 0xa8(%r12), %rax
movq 0x20(%rsp), %rbx
je 0x4dbf3
movq 0xb0(%r12), %rdx
shlq $0x7, %rdx
addq 0x18(%r12), %rdx
movq %r12, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rcx
xorl %r8d, %r8d
callq 0x44de5
incq %rbx
movq 0x18(%r15), %rax
movq (%rsp), %rcx
addq %rcx, %rax
addq $0x60, %rax
cmpq 0x10(%rax), %rbx
jl 0x4db1b
movq %r12, %rdi
callq 0x4d0dc
movq %r12, %rdi
callq 0x4d5ee
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq 0x18(%r15), %rax
movq (%rsp), %rcx
movq $0x0, 0x10(%rax,%rcx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq