// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
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, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2cce0
movq -0x8(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rcx
callq 0x9fc50
cmpl $0x0, %eax
je 0x38f25
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x10(%rbp), %rax
jbe 0x38f23
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x30(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x38ee3
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, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2cce0
movq -0x8(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rcx
callq 0x2cd00
cmpl $0x0, %eax
je 0x38f96
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x18(%rbp), %rax
jbe 0x38f94
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x38f54
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
jl 0x38fee
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0xa8(%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x40(%rax), %rax
imulq $0x38, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shlq $0x7, %rax
addq %rax, %rsi
xorl %edx, %edx
callq 0x9fdd0
jmp 0x3903c
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0xb0(%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x60(%rax), %rax
imulq $0x38, -0x28(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
shlq $0x7, %rax
addq %rax, %rsi
movl $0x1, %edx
callq 0x9fdd0
movq -0x48(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)