// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2c330
movq -0x8(%rbp), %rdi
movl $0x53, %esi
callq 0xa0210
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xa8(%rax)
movq -0x8(%rbp), %rdi
movl $0x45, %esi
callq 0xa0210
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xb0(%rax)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x18(%rbp), %rdx
shlq $0x7, %rdx
addq %rdx, %rcx
cmpq 0x70(%rcx), %rax
jge 0x39537
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x60(%rax), %rax
imulq $0x38, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0xa8(%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x60(%rax), %rax
imulq $0x38, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x39524
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x60(%rax), %rax
imulq $0x38, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x48(%rbp), %rax
jge 0x394de
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
movb %al, -0x49(%rbp)
movq -0x8(%rbp), %rdi
movsbl -0x49(%rbp), %esi
callq 0xa0210
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x38(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x2bbf0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x60(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x39458
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0xa8(%rcx), %rax
je 0x39522
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
shlq $0x7, %rax
addq %rax, %rdx
movq -0x38(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x2bbf0
jmp 0x39524
jmp 0x39526
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x39391
movq -0x8(%rbp), %rdi
callq 0x38d30
movq -0x8(%rbp), %rdi
callq 0x39050
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq $0x0, 0x10(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)