// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x38(%rbp), %rdx
movl $0x1, %ecx
callq 0x311ba0
movl %eax, -0x54(%rbp)
movl -0x34(%rbp), %eax
movq %rax, -0x40(%rbp)
cmpl $0x1, -0x54(%rbp)
jne 0x12cf8b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
shlq $0x20, %rax
orq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x12cf8d
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x12cff5
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x12cfba
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x12cfc5
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x12cfc5
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x64(%rbp)
cmpl $0x1, -0x54(%rbp)
jne 0x12d055
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x68(%rbp)
jmp 0x12d05c
xorl %eax, %eax
movl %eax, -0x68(%rbp)
jmp 0x12d05c
movl -0x64(%rbp), %eax
movl -0x68(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0x12d098
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x12d0bf
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x2, %eax
jne 0x12d0bd
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x12d0bf
cmpl $0x0, -0x54(%rbp)
jne 0x12d0f3
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rsi
movl $0x2, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovael %ecx, %eax
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x12d22b
cmpl $0x2, -0x54(%rbp)
jne 0x12d127
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rsi
movl $0x2, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovael %ecx, %eax
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x2, -0x4(%rbp)
jmp 0x12d22b
cmpl $0x2, -0x54(%rbp)
jbe 0x12d15b
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rsi
movl $0x2, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovael %ecx, %eax
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x4, -0x4(%rbp)
jmp 0x12d22b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311ba0
movl %eax, -0x58(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x2, -0x58(%rbp)
jne 0x12d1c2
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rsi
movl $0x2, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovael %ecx, %eax
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x12d22b
cmpl $0x2, -0x58(%rbp)
jbe 0x12d1f3
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rsi
movl $0x2, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovael %ecx, %eax
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x3, -0x4(%rbp)
jmp 0x12d22b
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x12d226
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rsi
movl $0x2, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovael %ecx, %eax
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x7, -0x4(%rbp)
jmp 0x12d22b
jmp 0x12cf3e
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)