// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x8(%rsp), %r14
andq $0x0, (%r14)
andq $0x0, 0x10(%rsp)
movq %rdi, %rbx
xorl %r13d, %r13d
movq %rsp, %r15
movq 0x18(%rbx), %r12
cmpq 0x60(%rbx), %r13
jae 0x1f47e
movq %r13, %rax
shlq $0x7, %rax
cmpb $0x44, 0x18(%r12,%rax)
jne 0x1f44b
incq %r13
jmp 0x1f42d
addq %rax, %r12
andq $0x0, 0x8(%r12)
andq $0x0, (%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x52a35
testl %eax, %eax
je 0x1f446
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
addq %rax, 0x8(%r12)
jmp 0x1f459
movq 0xa8(%rbx), %rax
shlq $0x7, %rax
leaq (%r12,%rax), %r14
andq $0x0, 0x8(%r12,%rax)
movq %rsp, %r15
andq $0x0, (%r15)
leaq 0x8(%rsp), %r12
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x52a35
testl %eax, %eax
je 0x1f4c3
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
addq %rax, 0x8(%r14)
jmp 0x1f49f
movq 0x18(%rbx), %rax
movq 0xb0(%rbx), %rcx
shlq $0x7, %rcx
leaq (%rax,%rcx), %r14
andq $0x0, 0x8(%rax,%rcx)
movq %rsp, %r15
andq $0x0, (%r15)
leaq 0x8(%rsp), %r12
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x18a44
testl %eax, %eax
je 0x1f50c
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
addq %rax, 0x8(%r14)
jmp 0x1f4e8
movq 0xa8(%rbx), %r12
shlq $0x7, %r12
addq 0x18(%rbx), %r12
movq %rsp, %r13
andq $0x0, (%r13)
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
xorl %r15d, %r15d
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x5288b
testl %eax, %eax
je 0x1f558
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rcx
cmpq %rbp, %rcx
cmovaq %rcx, %rbp
cmovaq %rax, %r15
jmp 0x1f52d
movq 0xb0(%rbx), %r12
shlq $0x7, %r12
addq 0x18(%rbx), %r12
movq %rsp, %rax
andq $0x0, (%rax)
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %rsp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
leaq 0x10(%rsp), %rcx
callq 0x529e9
testl %eax, %eax
je 0x1f5a1
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rcx
cmpq %r14, %rcx
cmovaq %rcx, %r14
cmovaq %rax, %r13
jmp 0x1f574
cmpq %r14, %rbp
jge 0x1f5b9
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x52c1e
movq %r14, %rbp
jmp 0x1f5c6
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x52c1e
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq