// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movq 0x60(%rdi), %rcx
testq %rcx, %rcx
je 0x4c9c2
xorl %edx, %edx
movq %rdx, %rsi
shlq $0x7, %rsi
cmpb $0x44, 0x18(%rax,%rsi)
je 0x4c9ba
addq %rax, %rsi
movq 0x50(%rsi), %rdi
testq %rdi, %rdi
jle 0x4c9b3
movq 0x40(%rsi), %r8
addq $0x10, %r8
movq %rdi, %r10
negq %r10
xorl %r11d, %r11d
xorl %r9d, %r9d
imulq $0x38, %r11, %r14
addq %r8, %r14
incq %r11
cmpq $-0x1, -0x8(%r14)
jne 0x4c9a9
addq $0x38, %r14
leaq (%r10,%r11), %r15
incq %r15
incq %r11
cmpq $0x1, %r15
jne 0x4c98c
jmp 0x4c9b6
addq (%r14), %r9
cmpq %rdi, %r11
jl 0x4c982
jmp 0x4c9b6
xorl %r9d, %r9d
movq %r9, 0x8(%rsi)
incq %rdx
cmpq %rcx, %rdx
jne 0x4c954
movq 0xa8(%rbx), %rcx
shlq $0x7, %rcx
leaq (%rax,%rcx), %r8
movq 0x50(%rax,%rcx), %rsi
testq %rsi, %rsi
jle 0x4ca1f
movq 0x40(%r8), %rdx
addq $0x10, %rdx
movq %rsi, %rdi
negq %rdi
xorl %r9d, %r9d
xorl %ecx, %ecx
imulq $0x38, %r9, %r10
addq %rdx, %r10
incq %r9
cmpq $-0x1, -0x8(%r10)
jne 0x4ca15
addq $0x38, %r10
leaq (%rdi,%r9), %r11
incq %r11
incq %r9
cmpq $0x1, %r11
jne 0x4c9f8
jmp 0x4ca21
addq (%r10), %rcx
cmpq %rsi, %r9
jl 0x4c9ee
jmp 0x4ca21
xorl %ecx, %ecx
movq %rcx, 0x8(%r8)
movq 0xb0(%rbx), %rcx
movq %rcx, %rdx
shlq $0x7, %rdx
leaq (%rax,%rdx), %rdi
movq 0x70(%rax,%rdx), %rdx
testq %rdx, %rdx
jle 0x4ca86
movq 0x60(%rdi), %r10
addq $0x10, %r10
movq %rdx, %r11
negq %r11
xorl %r14d, %r14d
xorl %r9d, %r9d
imulq $0x38, %r14, %r15
addq %r10, %r15
incq %r14
cmpq $-0x1, -0x8(%r15)
jne 0x4ca7c
addq $0x38, %r15
leaq (%r11,%r14), %r12
incq %r12
incq %r14
cmpq $0x1, %r12
jne 0x4ca5f
jmp 0x4ca89
addq (%r15), %r9
cmpq %rdx, %r14
jl 0x4ca55
jmp 0x4ca89
xorl %r9d, %r9d
movq %r9, 0x8(%rdi)
testq %rsi, %rsi
jle 0x4caf1
movq 0x40(%r8), %r8
movq %rsi, %r9
negq %r9
addq $0x8, %r8
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r10d, %r10d
imulq $0x38, %r10, %r11
incq %r10
addq %r8, %r11
movq (%r11), %r14
cmpq $-0x1, %r14
jne 0x4cad2
leaq (%r9,%r10), %r14
incq %r14
incq %r10
addq $0x38, %r11
cmpq $0x1, %r14
jne 0x4cab3
jmp 0x4caf7
shlq $0x7, %r14
leaq (%rax,%r14), %r11
movq 0x8(%rax,%r14), %r14
cmpq %r15, %r14
cmovaq %r14, %r15
cmovaq %r11, %r12
cmpq %rsi, %r10
jl 0x4caa9
jmp 0x4caf7
xorl %r15d, %r15d
xorl %r12d, %r12d
testq %rdx, %rdx
jle 0x4cb5b
movq 0x60(%rdi), %rdi
addq $0x8, %rdi
movq %rdx, %r8
negq %r8
xorl %esi, %esi
xorl %r14d, %r14d
xorl %r9d, %r9d
imulq $0x38, %r9, %r10
incq %r9
addq %rdi, %r10
cmpq $-0x1, (%r10)
jne 0x4cb38
addq $0x38, %r10
leaq (%r8,%r9), %r11
incq %r11
incq %r9
cmpq $0x1, %r11
jne 0x4cb1c
jmp 0x4cb60
movq -0x8(%r10), %r10
shlq $0x7, %r10
leaq (%rax,%r10), %r11
movq 0x8(%rax,%r10), %r10
cmpq %r14, %r10
cmovaq %r10, %r14
cmovaq %r11, %rsi
cmpq %rdx, %r9
jl 0x4cb12
jmp 0x4cb60
xorl %r14d, %r14d
xorl %esi, %esi
cmpq %r14, %r15
jge 0x4cb77
movq %rbx, %rdi
movl $0x1, %edx
callq 0x8633d
jmp 0x4ccae
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rbx)
movq $0x0, 0x80(%rbx)
cmpq %rcx, (%r12)
jne 0x4cb97
movq %r15, %r14
jmp 0x4ccae
movq %r15, (%rsp)
leaq 0x70(%rbx), %r14
xorl %ebp, %ebp
xorl %r13d, %r13d
movsbq 0x18(%r12), %r15
movq 0x88(%rbx), %rsi
cmpq %rsi, %rbp
jl 0x4cc19
movq (%r14), %rax
testq %rax, %rax
je 0x4cbe0
subq %rax, %rbp
leaq (,%rbp,8), %rdx
movq 0x90(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
cmpq %rax, %rbp
jle 0x4cc08
callq 0x2360
jmp 0x4cc0d
leaq (%rsi,%rsi), %rax
movq %rax, 0x88(%rbx)
movq 0x90(%rbx), %rdi
shlq $0x4, %rsi
callq 0x2370
movq %rax, 0x90(%rbx)
movq 0x78(%rbx), %rbp
jmp 0x4cc19
callq 0x2160
movq $0x0, 0x70(%rbx)
movq %rbp, 0x78(%rbx)
movq 0x90(%rbx), %rax
movq %r15, (%rax,%rbp,8)
movq 0x78(%rbx), %rbp
incq %rbp
movq %rbp, 0x78(%rbx)
movq 0x50(%r12), %rax
testq %rax, %rax
jle 0x4cc96
movq 0x40(%r12), %rcx
movq %rax, %rdx
negq %rdx
addq $0x8, %rcx
xorl %esi, %esi
xorl %edi, %edi
imulq $0x38, %rdi, %r8
incq %rdi
addq %rcx, %r8
movq (%r8), %r9
cmpq $-0x1, %r9
jne 0x4cc75
leaq (%rdx,%rdi), %r9
incq %r9
incq %rdi
addq $0x38, %r8
cmpq $0x1, %r9
jne 0x4cc56
jmp 0x4cc96
movq 0x18(%rbx), %r8
shlq $0x7, %r9
leaq (%r8,%r9), %r10
movq 0x8(%r8,%r9), %r8
cmpq %rsi, %r8
cmovaq %r10, %r13
cmovaq %r8, %rsi
cmpq %rax, %rdi
jl 0x4cc4c
movq (%r13), %rax
movq %r13, %r12
cmpq 0xb0(%rbx), %rax
jne 0x4cba4
movq (%rsp), %r14
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq