// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: generate_best_seq_from_edges(Graph*)
long long generate_best_seq_from_edges(Graph* DAGCon)
{
    long long max_start = 0, max_end = 0, max_start_edge = 0, max_end_edge = 0;
    RSet iter;
    Edge* e = NULL;
    Node* newNode = NULL;
    long long max_count = 0;
    

    ///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(getOutputEdges(&iter, DAGCon, newNode, &e))
    {
        if(e->weight > (uint64_t)max_start)
        {
            max_start = e->weight;
            max_start_edge = iter.index - 1;
        }
    }

    ///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(getInputEdges(&iter, DAGCon, newNode, &e))
    {
        if(e->weight > (uint64_t)max_end)
        {
            max_end = e->weight;
            max_end_edge = iter.index - 1;
        }
    }

    if(max_start >= max_end)
    {
        max_count = max_start;
        generate_seq_from_path(DAGCon, 
        &G_Node(*DAGCon, Output_Edges(G_Node(*DAGCon, DAGCon->s_start_nodeID)).list[max_start_edge].out_node), 0);
    }
    else
    {
        max_count = max_end;
        generate_seq_from_path(DAGCon, 
        &G_Node(*DAGCon, Input_Edges(G_Node(*DAGCon, DAGCon->s_end_nodeID)).list[max_end_edge].in_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), %r12
movq 0xa8(%rdi), %rax
shlq $0x7, %rax
movq 0x50(%r12,%rax), %rdx
testq %rdx, %rdx
jle 0x4c749
leaq (%r12,%rax), %rcx
movq 0x40(%rcx), %rsi
addq $0x10, %rsi
xorl %ecx, %ecx
xorl %r15d, %r15d
xorl %edi, %edi
imulq $0x38, %rdi, %r8
addq %rsi, %r8
cmpq $-0x1, -0x8(%r8)
jne 0x4c731
incq %rdi
addq $0x38, %r8
cmpq %rdi, %rdx
jne 0x4c71c
jmp 0x4c74e
movq (%r8), %r8
cmpq %r15, %r8
cmovaq %r8, %r15
cmovaq %rdi, %rcx
incq %rdi
cmpq %rdx, %rdi
jl 0x4c715
jmp 0x4c74e
xorl %r15d, %r15d
xorl %ecx, %ecx
movq 0xb0(%rbx), %rdx
movq %rdx, %rsi
shlq $0x7, %rsi
movq 0x70(%r12,%rsi), %r8
testq %r8, %r8
jle 0x4c7ae
leaq (%r12,%rsi), %rdi
movq 0x60(%rdi), %r9
addq $0x10, %r9
xorl %edi, %edi
xorl %r14d, %r14d
xorl %r10d, %r10d
imulq $0x38, %r10, %r11
addq %r9, %r11
cmpq $-0x1, -0x8(%r11)
jne 0x4c796
incq %r10
addq $0x38, %r11
cmpq %r10, %r8
jne 0x4c781
jmp 0x4c7b3
movq (%r11), %r11
cmpq %r14, %r11
cmovaq %r11, %r14
cmovaq %r10, %rdi
incq %r10
cmpq %r8, %r10
jl 0x4c77a
jmp 0x4c7b3
xorl %r14d, %r14d
xorl %edi, %edi
cmpq %r14, %r15
jge 0x4c7de
movq 0x60(%r12,%rsi), %rax
imulq $0x38, %rdi, %rcx
movq (%rax,%rcx), %rsi
shlq $0x7, %rsi
addq %r12, %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x86085
jmp 0x4c925
movq 0x40(%r12,%rax), %rax
imulq $0x38, %rcx, %rcx
movq 0x8(%rax,%rcx), %rax
shlq $0x7, %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rbx)
movq $0x0, 0x80(%rbx)
cmpq %rdx, (%r12,%rax)
jne 0x4c810
movq %r15, %r14
jmp 0x4c925
movq %r15, (%rsp)
addq %rax, %r12
leaq 0x70(%rbx), %r14
xorl %ebp, %ebp
xorl %r13d, %r13d
movsbq 0x18(%r12), %r15
movq 0x88(%rbx), %rsi
cmpq %rsi, %rbp
jl 0x4c895
movq (%r14), %rax
testq %rax, %rax
je 0x4c85c
subq %rax, %rbp
leaq (,%rbp,8), %rdx
movq 0x90(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
cmpq %rax, %rbp
jle 0x4c884
callq 0x2360
jmp 0x4c889
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 0x4c895
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 0x4c90d
movq 0x40(%r12), %rcx
addq $0x10, %rcx
movq %rax, %rdx
negq %rdx
xorl %edi, %edi
xorl %esi, %esi
imulq $0x38, %rsi, %r8
addq %rcx, %r8
incq %rsi
movq -0x8(%r8), %r9
cmpq $-0x1, %r9
jne 0x4c8f2
addq $0x38, %r8
leaq (%rdx,%rsi), %r9
incq %r9
incq %rsi
cmpq $0x1, %r9
jne 0x4c8d2
jmp 0x4c90d
movq (%r8), %r8
cmpq %rdi, %r8
jbe 0x4c908
shlq $0x7, %r9
addq 0x18(%rbx), %r9
movq %r9, %r13
movq %r8, %rdi
cmpq %rax, %rsi
jl 0x4c8c8
movq (%r13), %rax
movq %r13, %r12
cmpq 0xb0(%rbx), %rax
jne 0x4c820
movq (%rsp), %r14
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq