// File: chhylp123[P]hifiasm/Correct.cpp
// Function: generate_best_seq_from_nodes(Graph*)
long long generate_best_seq_from_nodes(Graph* DAGCon)
{
    long long max_start = 0, max_end = 0;
    RSet iter;
    Edge* e = NULL;
    Node* newNode = NULL;
    Node* getNode = NULL;
    Node* max_start_node = NULL;
    Node* max_end_node = NULL;
    long long max_count = 0;
    uint64_t i;

   for (i = 0; i < DAGCon->g_nodes.length; i++)
   {
       newNode = &(G_Node(*DAGCon, i));
       if(If_Node_Exist(*newNode))
        {
            newNode->weight = 0;
            clear_RSet(&iter);
            while(getOutputEdges(&iter, DAGCon, newNode, &e))
            {
                newNode->weight += e->weight;
            }
        }
   }
    
    newNode = &(G_Node(*DAGCon, DAGCon->s_start_nodeID));
    newNode->weight = 0;
    clear_RSet(&iter);
    while(getOutputEdges(&iter, DAGCon, newNode, &e))
    {
        newNode->weight += e->weight;
    }


    newNode = &(G_Node(*DAGCon, DAGCon->s_end_nodeID));
    newNode->weight = 0;
    clear_RSet(&iter);
    while(getInputEdges(&iter, DAGCon, newNode, &e))
    {
        newNode->weight += e->weight;
    }


    

    ///check the out-edges of start node
    ///must to be 0
    max_start = 0;
    newNode = &(G_Node(*DAGCon, DAGCon->s_start_nodeID));
    clear_RSet(&iter);
    while(getOutputNodes(&iter, DAGCon, newNode, &getNode))
    {
        if(getNode->weight > (uint64_t)max_start)
        {
            max_start = getNode->weight;
            max_start_node = getNode;
        }
    }

    ///check the in-edges of end node
    ///must to be 0
    max_end = 0;
    newNode = &(G_Node(*DAGCon, DAGCon->s_end_nodeID));
    clear_RSet(&iter);
    while(getInputNodes(&iter, DAGCon, newNode, &getNode))
    {
        if(getNode->weight > (uint64_t)max_end)
        {
            max_end = getNode->weight;
            max_end_node = getNode;
        }
    }

    if(max_start >= max_end)
    {
        max_count = max_start;
        generate_seq_from_node(DAGCon, max_start_node, 0);
    }
    else
    {
        max_count = max_end;
        generate_seq_from_node(DAGCon, max_end_node, 1);
    }

    return max_count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x60(%rcx), %rax
jae 0x39130
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x44, %eax
je 0x3911d
movq -0x30(%rbp), %rax
movq $0x0, 0x8(%rax)
leaq -0x20(%rbp), %rdi
callq 0x2cce0
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rcx
callq 0x9fc50
cmpl $0x0, %eax
je 0x3911b
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x390eb
jmp 0x3911d
jmp 0x3911f
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x390a4
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0xa8(%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq $0x0, 0x8(%rax)
leaq -0x20(%rbp), %rdi
callq 0x2cce0
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rcx
callq 0x9fc50
cmpl $0x0, %eax
je 0x39193
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x39163
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0xb0(%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq $0x0, 0x8(%rax)
leaq -0x20(%rbp), %rdi
callq 0x2cce0
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rcx
callq 0x2cd00
cmpl $0x0, %eax
je 0x391f6
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x391c6
movq $0x0, -0x10(%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, -0x30(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x2cce0
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x38(%rbp), %rcx
callq 0x9f8b0
cmpl $0x0, %eax
je 0x39263
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x10(%rbp), %rax
jbe 0x39261
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x39225
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0xb0(%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x2cce0
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x20(%rbp), %rdi
leaq -0x38(%rbp), %rcx
callq 0x9fb50
cmpl $0x0, %eax
je 0x392d0
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x18(%rbp), %rax
jbe 0x392ce
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x39292
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
jl 0x392f3
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
xorl %edx, %edx
callq 0xa0000
jmp 0x3930d
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0x1, %edx
callq 0xa0000
movq -0x50(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)