// File: /workspace/github_cpp_makefile_star2_O2/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, %r12d
leaq 0x8(%rsp), %rax
andl $0x0, (%rax)
movq %rdi, %rbx
andq $0x0, (%rcx)
movq %r8, 0x20(%rsp)
andq $0x0, (%r8)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
leaq 0x8(%rsp), %rdx
pushq $0x1
popq %rcx
callq 0x1a5422
movl %eax, %ebp
movl %r12d, %r13d
movq %r13, %r12
cmpl $0x1, %eax
jne 0xa0da4
movq 0x8(%rbx), %rax
movl 0x8(%rsp), %ecx
imulq $0x18, %rcx, %rcx
movl 0xc(%rax,%rcx), %r12d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r12d
shlq $0x20, %r12
orq %r13, %r12
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0xa0dd6
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
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 %r12, (%rax,%rcx,8)
movq 0x20(%rbx), %rax
shrl %r13d
movl (%rax,%r13,8), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
xorl %edx, %edx
cmpl $0x1, %ebp
jne 0xa0e11
movq 0x8(%rbx), %rdx
movl 0x8(%rsp), %esi
imulq $0x18, %rsi, %rsi
movl 0xc(%rdx,%rsi), %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 0xa0e2d
cmpl $0x1, %eax
jne 0xa0e32
incq 0x18(%rsp)
jmp 0xa0e32
incq 0x10(%rsp)
testl %ebp, %ebp
je 0xa0e7b
cmpl $0x2, %ebp
je 0xa0e8a
ja 0xa0e7f
movq 0x8(%rbx), %rax
movl 0x8(%rsp), %ecx
imulq $0x18, %rcx, %rcx
movl 0x8(%rax,%rcx), %esi
movl %esi, 0x8(%rsp)
xorl $0x1, %esi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
cmpl $0x2, %eax
je 0xa0e83
ja 0xa0e87
movl 0x8(%rsp), %r12d
cmpl 0xc(%rsp), %r12d
jne 0xa0d64
pushq $0x7
jmp 0xa0e89
pushq $0x5
jmp 0xa0e89
pushq $0x4
jmp 0xa0e89
pushq $0x1
jmp 0xa0e89
pushq $0x3
popq %rbp
xorl %eax, %eax
movq 0x10(%rsp), %rcx
cmpq %rcx, 0x18(%rsp)
adcq $0x1, %rax
movq 0x20(%rsp), %rcx
movq %rax, (%rcx)
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq