// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_scaf_path_lst(asg_t*, unsigned int, asg64_v*, unsigned long*, unsigned long*)
uint32_t gen_scaf_path_lst(asg_t *g, uint32_t s, asg64_v *b, uint64_t *blen, uint64_t *bf)
{
    
    uint32_t v = s, w = 0; uint64_t m, c1 = 0, c2 = 0;
    uint32_t kv, kw; (*blen) = 0; (*bf) = 0;

    while (1) {
        kv = get_arcs(g, v, &w, 1);  
        m = v;
        if(kv == 1) m |= ((uint64_t)(g->arc[w].ol))<<32;
        kv_push(uint64_t, *b, m);
        (*blen) += g->seq[v>>1].len + ((kv == 1)?g->arc[w].ol:0);
        if(g->seq[v>>1].c == 1) c1++;
        else if(g->seq[v>>1].c == 2) c2++;

        if(kv == 0) {(*bf) = (c1>=c2?1:2); return END_TIPS;}
        if(kv == 2) {(*bf) = (c1>=c2?1:2); return TWO_OUTPUT;}
        if(kv > 2) {(*bf) = (c1>=c2?1:2); return MUL_OUTPUT;}
        w = g->arc[w].v;
        ///up to here, kv=1
        ///kw must >= 1
        kw = get_arcs(g, w^1, NULL, 0);
        v = w;

        if(kw == 2) {(*bf) = (c1>=c2?1:2); return TWO_INPUT;}
        if(kw > 2) {(*bf) = (c1>=c2?1:2); return MUL_INPUT;}
        if(v == s) {(*bf) = (c1>=c2?1:2); return LOOP;}
    }

    (*bf) = (c1>=c2?1:2); 
    return LONG_TIPS;   
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %r12
leaq 0x8(%rsp), %rax
movl $0x0, (%rax)
xorl %eax, %eax
movq %rax, (%rcx)
movq %r8, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq %rax, (%r8)
movq $0x0, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movq %r12, %rdi
movl %ebp, %esi
leaq 0x8(%rsp), %rdx
movl $0x1, %ecx
callq 0x1efacc
movl %eax, %ebx
movl %ebp, %r13d
movq %r13, %rbp
cmpl $0x1, %eax
jne 0xde519
movq 0x8(%r12), %rax
movl 0x8(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0xc(%rax,%rcx,8), %ebp
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ebp
shlq $0x20, %rbp
orq %r13, %rbp
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0xde54d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movq %rbp, (%rax,%rcx,8)
movq 0x20(%r12), %rax
shrl %r13d
movl (%rax,%r13,8), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
xorl %edx, %edx
cmpl $0x1, %ebx
jne 0xde58a
movq 0x8(%r12), %rdx
movl 0x8(%rsp), %esi
leaq (%rsi,%rsi,2), %rsi
movl 0xc(%rdx,%rsi,8), %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edx
addl %ecx, %edx
addq %rdx, (%r14)
movzbl 0x4(%rax,%r13,8), %eax
cmpl $0x2, %eax
je 0xde5a6
cmpl $0x1, %eax
jne 0xde5ab
incq 0x18(%rsp)
jmp 0xde5ab
incq 0x10(%rsp)
testl %ebx, %ebx
je 0xde5f6
cmpl $0x2, %ebx
je 0xde610
ja 0xde5fd
movq 0x8(%r12), %rax
movl 0x8(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x8(%rax,%rcx,8), %esi
movl %esi, 0x8(%rsp)
xorl $0x1, %esi
movq %r12, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1efacc
cmpl $0x2, %eax
je 0xde604
ja 0xde60b
movl 0x8(%rsp), %ebp
cmpl 0xc(%rsp), %ebp
jne 0xde4d9
movl $0x7, %ebx
jmp 0xde610
movl $0x5, %ebx
jmp 0xde610
movl $0x4, %ebx
jmp 0xde610
movl $0x1, %ebx
jmp 0xde610
movl $0x3, %ebx
xorl %eax, %eax
movq 0x10(%rsp), %rcx
cmpq %rcx, 0x18(%rsp)
adcq $0x1, %rax
movq 0x20(%rsp), %rcx
movq %rax, (%rcx)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq