// File: /workspace/github_cpp_makefile_star2_O1/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
movq 0x60(%rdi), %rax
testq %rax, %rax
movq %rdi, (%rsp)
je 0x4d6b8
movq 0x18(%rdi), %rcx
xorl %edx, %edx
xorl %esi, %esi
movq %rdx, %r15
shlq $0x7, %r15
cmpb $0x44, 0x18(%rcx,%r15)
je 0x4d6aa
addq %rcx, %r15
movq 0x50(%r15), %r8
leaq -0x1(%r8), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
movb $0x1, %bpl
cmpq %r8, %r11
jge 0x4d697
movq 0x40(%r15), %r14
imulq $0x38, %r11, %rbx
movb $0x1, %bpl
cmpq $-0x1, 0x8(%r14,%rbx)
je 0x4d658
movb $0x1, %bl
jmp 0x4d677
addq %r14, %rbx
addq $0x40, %rbx
cmpq %r11, %r9
je 0x4d694
incq %r11
cmpq $-0x1, (%rbx)
leaq 0x38(%rbx), %rbx
je 0x4d65f
cmpq %r8, %r11
setl %bl
testb %bl, %bl
je 0x4d697
imulq $0x38, %r11, %rbx
cmpq $-0x1, 0x8(%r14,%rbx)
je 0x4d697
addq %rbx, %r14
incq %r11
xorl %ebp, %ebp
movq %r14, %rsi
jmp 0x4d697
movq %r8, %r11
testb %bpl, %bpl
jne 0x4d6a2
addq 0x10(%rsi), %r10
jmp 0x4d639
movq %r10, 0x8(%r15)
movq (%rsp), %rdi
incq %rdx
cmpq %rax, %rdx
jne 0x4d615
jmp 0x4d6ba
xorl %esi, %esi
movq 0x18(%rdi), %rax
movq 0xa8(%rdi), %rcx
shlq $0x7, %rcx
leaq (%rax,%rcx), %r9
movq %rax, 0x8(%rsp)
movq 0x50(%rax,%rcx), %r10
leaq -0x1(%r10), %r11
xorl %ecx, %ecx
xorl %edx, %edx
movb $0x1, %dil
cmpq %r10, %rdx
jge 0x4d73d
movq 0x40(%r9), %r8
imulq $0x38, %rdx, %rbx
movb $0x1, %dil
cmpq $-0x1, 0x8(%r8,%rbx)
je 0x4d6fe
movb $0x1, %bl
jmp 0x4d71d
addq %r8, %rbx
addq $0x40, %rbx
cmpq %rdx, %r11
je 0x4d73a
incq %rdx
cmpq $-0x1, (%rbx)
leaq 0x38(%rbx), %rbx
je 0x4d705
cmpq %r10, %rdx
setl %bl
testb %bl, %bl
je 0x4d73d
imulq $0x38, %rdx, %rbx
cmpq $-0x1, 0x8(%r8,%rbx)
je 0x4d73d
addq %rbx, %r8
incq %rdx
xorl %edi, %edi
movq %r8, %rsi
jmp 0x4d73d
movq %r10, %rdx
testb %dil, %dil
jne 0x4d748
addq 0x10(%rsi), %rcx
jmp 0x4d6df
movq %rcx, 0x8(%r9)
movq (%rsp), %rax
movq 0xb0(%rax), %rcx
movq %rcx, 0x10(%rsp)
shlq $0x7, %rcx
movq 0x8(%rsp), %rax
leaq (%rax,%rcx), %rdx
movq 0x70(%rax,%rcx), %rax
leaq -0x1(%rax), %r8
xorl %r14d, %r14d
xorl %r15d, %r15d
movb $0x1, %bpl
cmpq %rax, %r15
jge 0x4d7d7
movq 0x60(%rdx), %r12
imulq $0x38, %r15, %rcx
movb $0x1, %bpl
cmpq $-0x1, 0x8(%r12,%rcx)
je 0x4d797
movb $0x1, %bl
jmp 0x4d7b7
leaq (%r12,%rcx), %rbx
addq $0x40, %rbx
cmpq %r15, %r8
je 0x4d7d4
incq %r15
cmpq $-0x1, (%rbx)
leaq 0x38(%rbx), %rbx
je 0x4d79f
cmpq %rax, %r15
setl %bl
testb %bl, %bl
je 0x4d7d7
imulq $0x38, %r15, %rcx
cmpq $-0x1, 0x8(%r12,%rcx)
je 0x4d7d7
addq %rcx, %r12
incq %r15
xorl %ebp, %ebp
movq %r12, %rsi
jmp 0x4d7d7
movq %rax, %r15
testb %bpl, %bpl
jne 0x4d7e2
addq 0x10(%rsi), %r14
jmp 0x4d778
movq %r14, 0x8(%rdx)
xorl %esi, %esi
xorl %r13d, %r13d
xorl %r15d, %r15d
xorl %r12d, %r12d
movb $0x1, %bpl
cmpq %r10, %rsi
jge 0x4d84f
movq 0x40(%r9), %rbx
imulq $0x38, %rsi, %rcx
movq 0x8(%rbx,%rcx), %r14
movb $0x1, %bpl
cmpq $-0x1, %r14
je 0x4d813
movb $0x1, %bl
jmp 0x4d835
addq %rcx, %rbx
addq $0x40, %rbx
cmpq %rsi, %r11
je 0x4d84c
movq (%rbx), %r14
addq $0x38, %rbx
incq %rsi
cmpq $-0x1, %r14
je 0x4d81a
cmpq %r10, %rsi
setl %bl
testb %bl, %bl
je 0x4d84f
shlq $0x7, %r14
addq 0x8(%rsp), %r14
incq %rsi
xorl %ebp, %ebp
movq %r14, %r13
jmp 0x4d84f
movq %r10, %rsi
testb %bpl, %bpl
jne 0x4d865
movq 0x8(%r13), %rcx
cmpq %r15, %rcx
cmovaq %rcx, %r15
cmovaq %r13, %r12
jmp 0x4d7f1
xorl %r9d, %r9d
xorl %r14d, %r14d
xorl %esi, %esi
movq (%rsp), %rdi
movb $0x1, %r10b
cmpq %rax, %r9
jge 0x4d8de
movq 0x60(%rdx), %r11
imulq $0x38, %r9, %rcx
movb $0x1, %r10b
cmpq $-0x1, 0x8(%r11,%rcx)
je 0x4d890
movb $0x1, %bl
jmp 0x4d8b0
leaq (%r11,%rcx), %rbx
addq $0x40, %rbx
cmpq %r9, %r8
je 0x4d8d7
incq %r9
cmpq $-0x1, (%rbx)
leaq 0x38(%rbx), %rbx
je 0x4d898
cmpq %rax, %r9
setl %bl
testb %bl, %bl
je 0x4d8da
imulq $0x38, %r9, %rcx
cmpq $-0x1, 0x8(%r11,%rcx)
je 0x4d8da
addq %rcx, %r11
movq (%r11), %r13
shlq $0x7, %r13
addq 0x8(%rsp), %r13
incq %r9
xorl %r10d, %r10d
jmp 0x4d8da
movq %rax, %r9
movq (%rsp), %rdi
testb %r10b, %r10b
jne 0x4d8f7
movq 0x8(%r13), %rcx
cmpq %r14, %rcx
cmovaq %rcx, %r14
cmovaq %r13, %rsi
jmp 0x4d871
cmpq %r14, %r15
jge 0x4d90b
movl $0x1, %edx
callq 0x86d67
jmp 0x4da6b
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rdi)
movq $0x0, 0x80(%rdi)
movq 0x10(%rsp), %rax
cmpq %rax, (%r12)
je 0x4da68
leaq 0x70(%rdi), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
movsbq 0x18(%r12), %r14
movq 0x78(%rdi), %rbx
movq 0x88(%rdi), %rsi
cmpq %rsi, %rbx
jl 0x4d9bc
movq 0x8(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x4d97f
subq %rax, %rbx
leaq (,%rbx,8), %rdx
movq 0x90(%rdi), %rdi
leaq (%rdi,%rax,8), %rsi
cmpq %rax, %rbx
jle 0x4d9a7
callq 0x2360
jmp 0x4d9ac
leaq (%rsi,%rsi), %rax
movq %rax, 0x88(%rdi)
movq 0x90(%rdi), %rdi
shlq $0x4, %rsi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0x90(%rdi)
jmp 0x4d9bc
callq 0x2160
movq (%rsp), %rdi
movq $0x0, 0x70(%rdi)
movq %rbx, 0x78(%rdi)
movq 0x78(%rdi), %rax
movq 0x90(%rdi), %rcx
movq %r14, (%rcx,%rax,8)
incq 0x78(%rdi)
movq 0x50(%r12), %rax
leaq -0x1(%rax), %rcx
xorl %edx, %edx
xorl %esi, %esi
movb $0x1, %r11b
cmpq %rax, %rdx
jge 0x4da3e
movq 0x40(%r12), %r9
imulq $0x38, %rdx, %r10
movq 0x8(%r9,%r10), %r8
movb $0x1, %r11b
cmpq $-0x1, %r8
je 0x4da00
movb $0x1, %r9b
jmp 0x4da23
addq %r10, %r9
addq $0x40, %r9
cmpq %rdx, %rcx
je 0x4da3b
movq (%r9), %r8
addq $0x38, %r9
incq %rdx
cmpq $-0x1, %r8
je 0x4da07
cmpq %rax, %rdx
setl %r9b
testb %r9b, %r9b
je 0x4da3e
shlq $0x7, %r8
addq 0x18(%rdi), %r8
incq %rdx
xorl %r11d, %r11d
movq %r8, %rbp
jmp 0x4da3e
movq %rax, %rdx
testb %r11b, %r11b
jne 0x4da54
movq 0x8(%rbp), %r8
cmpq %rsi, %r8
cmovaq %rbp, %r13
cmovaq %r8, %rsi
jmp 0x4d9dc
movq (%r13), %rax
movq %r13, %r12
cmpq 0xb0(%rdi), %rax
jne 0x4d93a
movq %r15, %r14
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq