// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x18, %rsp
movq 0x18(%rdi), %rsi
movq 0xa8(%rdi), %rax
shlq $0x7, %rax
leaq (%rsi,%rax), %r8
movq %rax, 0x10(%rsp)
movq 0x50(%rsi,%rax), %r9
leaq -0x1(%r9), %r10
xorl %r11d, %r11d
xorl %edx, %edx
xorl %ebx, %ebx
xorl %ecx, %ecx
movb $0x1, %bpl
cmpq %r9, %r11
jge 0x4d4e0
movq 0x40(%r8), %r14
imulq $0x38, %r11, %rax
movb $0x1, %bpl
cmpq $-0x1, 0x8(%r14,%rax)
je 0x4d4a0
movb $0x1, %al
jmp 0x4d4c0
leaq (%r14,%rax), %r15
addq $0x40, %r15
cmpq %r11, %r10
je 0x4d4dd
incq %r11
cmpq $-0x1, (%r15)
leaq 0x38(%r15), %r15
je 0x4d4a8
cmpq %r9, %r11
setl %al
testb %al, %al
je 0x4d4e0
imulq $0x38, %r11, %rax
cmpq $-0x1, 0x8(%r14,%rax)
je 0x4d4e0
addq %rax, %r14
incq %r11
xorl %ebp, %ebp
movq %r14, %rdx
jmp 0x4d4e0
movq %r9, %r11
testb %bpl, %bpl
jne 0x4d4fa
movq 0x10(%rdx), %rax
cmpq %rbx, %rax
cmovaq %rax, %rbx
leaq -0x1(%r11), %rax
cmovaq %rax, %rcx
jmp 0x4d481
movq %rdi, 0x8(%rsp)
movq 0xb0(%rdi), %r8
shlq $0x7, %r8
leaq (%rsi,%r8), %r10
movq 0x70(%rsi,%r8), %r11
leaq -0x1(%r11), %r14
xorl %r12d, %r12d
xorl %r9d, %r9d
xorl %r15d, %r15d
movb $0x1, %bpl
cmpq %r11, %r12
jge 0x4d57e
movq 0x60(%r10), %r13
imulq $0x38, %r12, %rax
movb $0x1, %bpl
cmpq $-0x1, 0x8(%r13,%rax)
je 0x4d53f
movb $0x1, %al
jmp 0x4d55e
addq %r13, %rax
addq $0x40, %rax
cmpq %r12, %r14
je 0x4d57b
incq %r12
cmpq $-0x1, (%rax)
leaq 0x38(%rax), %rax
je 0x4d546
cmpq %r11, %r12
setl %al
testb %al, %al
je 0x4d57e
imulq $0x38, %r12, %rax
cmpq $-0x1, 0x8(%r13,%rax)
je 0x4d57e
addq %rax, %r13
incq %r12
xorl %ebp, %ebp
movq %r13, %rdx
jmp 0x4d57e
movq %r11, %r12
testb %bpl, %bpl
jne 0x4d599
movq 0x10(%rdx), %rax
cmpq %r9, %rax
cmovaq %rax, %r9
leaq -0x1(%r12), %rax
cmovaq %rax, %r15
jmp 0x4d520
cmpq %r9, %rbx
jge 0x4d5b1
imulq $0x38, %r15, %rax
addq 0x60(%rsi,%r8), %rax
movl $0x1, %edx
movq %r9, %rbx
jmp 0x4d5c8
movq 0x10(%rsp), %rax
movq 0x40(%rsi,%rax), %rax
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
addq $0x8, %rax
xorl %edx, %edx
movq 0x8(%rsp), %rdi
movq (%rax), %rax
shlq $0x7, %rax
addq %rax, %rsi
callq 0x86a37
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq