// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/ecovlp.cpp
// Function: gseq_cns_g(cns_gfa*, asg32_v*, unsigned int)
void gseq_cns_g(cns_gfa *cns, asg32_v *b32, uint32_t bl)
{
    b32->n = 0; kv_resize(uint32_t, *b32, cns->n);
    uint32_t v, vk, w, mme, mmn, mmk, mmw, *ii = b32->a, *p; cns_t *av;
    uint32_t bs = cns->off, be = bl + cns->off, sw;
    for (v = 0; v < cns->n; v++) {
        ii[v] = 0;///score
        if(del_cns_nn((*cns), v)) continue;
        cns->a[v].sc = 0; ///in-degree or prefix
        cns->a[v].f = 0;

        av = &((*cns).a[v]);
        for (vk = av->arc.nou; vk < av->arc.n; vk++) {///in-edge of v
            if(del_cns_arc((*av), vk)) continue;
            cns->a[v].sc++;///in-degree
        }
    }

    kdq_clear(cns->q); 
    kdq_push(uint32_t, cns->q, cns->si); ///in-degree == 0
    assert((cns->a[cns->si].sc == 0) && (!del_cns_nn((*cns), cns->si)));

    while (1) {
        p = kdq_shift(uint32_t, cns->q);
        if(!p) break; v = *p;

        if(del_cns_nn((*cns), v)) continue;
        assert(cns->a[v].sc == 0); ///in-degree == 0

        av = &((*cns).a[v]);
        for (vk = av->arc.nou, mme = mmn = mmw = 0, mmk = (uint32_t)-1; vk < av->arc.n; vk++) {///in-edge of v
            if(del_cns_arc((*av), vk)) continue;
            w = av->arc.a[vk].v;
            assert((*cns).a[w].f);
            sw = ((w >= bs && w < be)?1:0); ///backbone

            if((mmk == ((uint32_t)-1)) || (av->arc.a[vk].sc > mme) || 
                (((av->arc.a[vk].sc == mme) && (ii[w] > mmn))) ||
                (((av->arc.a[vk].sc == mme) && (ii[w] == mmn) && (sw == 1) && (mmw == 0)))) {
                mmk = vk; mme = av->arc.a[vk].sc; mmn = ii[w]; mmw = sw;
            }
        }

        ii[v] = mme + mmn; cns->a[v].f = 1;
        if(mmk != ((uint32_t)-1)) cns->a[v].sc = av->arc.a[mmk].v; 
        else cns->a[v].sc = v;

        for (vk = 0; vk < av->arc.nou; vk++) {///out-edge of v
            if(del_cns_arc((*av), vk)) continue;
            w = av->arc.a[vk].v;
            assert(cns->a[w].f == 0);
            assert(cns->a[w].sc);
            cns->a[w].sc--;
            if(cns->a[w].sc == 0) {
                kdq_push(uint32_t, cns->q, w); ///in-degree == 0
            }
        }

        // fprintf(stderr, "[M::%s] sc[%u]::%u\n", __func__, v, ii[v]);
    }

    for (v = cns->a[cns->ei].sc, b32->n = 0; v != cns->si; v = cns->a[v].sc) {
        // fprintf(stderr, "[M::%s] v::%u\n", __func__, v);
        kv_push(uint32_t, *b32, v);
    }
    assert(v == cns->si);
    
    mmn = b32->n; mmn >>= 1;
    for (vk = 0; vk < mmn; vk++) {
        v = b32->a[vk]; b32->a[vk] = b32->a[b32->n-vk-1]; b32->a[b32->n-vk-1] = v;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, 0x14(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq $0x0, (%rsi)
movq (%rdi), %rax
cmpq %rax, 0x8(%rsi)
jae 0x17c9f1
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq 0x10(%rbx), %rax
movq %rax, 0x8(%rsp)
movl 0x20(%r14), %eax
movl %eax, 0x10(%rsp)
cmpq $0x0, (%r14)
je 0x17ca87
xorl %edx, %edx
xorl %eax, %eax
movq 0x8(%rsp), %rcx
movl $0x0, (%rcx,%rdx,4)
movq 0x10(%r14), %rdi
leaq (%rdx,%rdx,4), %rcx
movl (%rdi,%rcx,8), %esi
cmpl $-0x9, %esi
ja 0x17ca7d
leaq (%rdi,%rcx,8), %rdi
andl $0x7, %esi
movl %esi, (%rdi)
movq 0x10(%r14), %rsi
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %rdx
andl $-0x5, (%rsi,%rdx)
movq 0x10(%r14), %rsi
movl 0x18(%rsi,%rdx), %edi
cmpq %rdi, 0x8(%rsi,%rdx)
jbe 0x17ca7d
addq %rsi, %rdx
addq $0x8, %rdx
leal 0x1(%rdi), %esi
movq 0x18(%rdx), %r8
movl (%r8,%rdi,8), %edi
notl %edi
testl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
je 0x17ca74
movq 0x10(%r14), %rdi
addl $0x8, (%rdi,%rcx,8)
movl %esi, %edi
incl %esi
cmpq %rdi, (%rdx)
ja 0x17ca5a
incl %eax
movq %rax, %rdx
cmpq %rax, (%r14)
ja 0x17ca0c
movq %rbx, 0x18(%rsp)
movabsq $-0x400000000000000, %r15 # imm = 0xFC00000000000000
movq 0x38(%r14), %rax
andq %r15, (%rax)
movq 0x38(%r14), %rdi
movq $0x0, 0x8(%rdi)
movl 0x18(%r14), %esi
callq 0x17c80f
movq 0x10(%r14), %rax
movl 0x18(%r14), %ecx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x7, (%rax,%rcx,8)
ja 0x17cdf8
movl 0x10(%rsp), %eax
addl %eax, 0x14(%rsp)
movabsq $0x3ffffffffffffff, %r12 # imm = 0x3FFFFFFFFFFFFFF
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq 0x38(%r14), %rcx
movq 0x8(%rcx), %rdx
testq %rdx, %rdx
je 0x17cb1b
movq (%rcx), %rsi
movq %rsi, %rax
andq %r12, %rax
leaq 0x1(%rsi), %rdi
andq %r12, %rdi
andq %r15, %rsi
shlq $0x2, %rax
addq 0x18(%rcx), %rax
andq 0x10(%rcx), %rdi
orq %rsi, %rdi
movq %rdi, (%rcx)
decq %rdx
movq %rdx, 0x8(%rcx)
jmp 0x17cb1d
xorl %eax, %eax
testq %rax, %rax
je 0x17ccad
movl (%rax), %r10d
movq 0x10(%r14), %rdx
leaq (%r10,%r10,4), %rax
movl (%rdx,%rax,8), %esi
cmpl $-0x9, %esi
ja 0x17cae0
cmpl $0x8, %esi
jae 0x17cdd9
leaq (%rdx,%rax,8), %rbx
movl 0x18(%rbx), %r8d
movq 0x8(%rbx), %r9
cmpq %r8, %r9
jbe 0x17cbf0
movq %r10, 0x20(%rsp)
movq 0x20(%rbx), %r10
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edi, %edi
xorl %r11d, %r11d
xorl %ebp, %ebp
movl (%r10,%r8,8), %r12d
andq %r13, %r12
cmpq %r13, %r12
je 0x17cbbc
leaq (%r12,%r12,4), %r15
testb $0x4, (%rdx,%r15,8)
je 0x17cdba
cmpl 0x10(%rsp), %r12d
setae %cl
cmpl 0x14(%rsp), %r12d
setb %r15b
andb %cl, %r15b
cmpl $-0x1, %esi
je 0x17cba7
cmpl %edi, 0x4(%r10,%r8,8)
jbe 0x17cbc6
movzbl %r15b, %ebp
movl 0x4(%r10,%r8,8), %edi
movq 0x8(%rsp), %rcx
movl (%rcx,%r12,4), %r11d
movl %r8d, %esi
incl %r8d
cmpq %r8, %r9
ja 0x17cb6c
jmp 0x17cbf9
jne 0x17cbd3
movq 0x8(%rsp), %rcx
cmpl %r11d, (%rcx,%r12,4)
ja 0x17cba7
cmpl %edi, 0x4(%r10,%r8,8)
jne 0x17cbbc
movq 0x8(%rsp), %rcx
cmpl %r11d, (%rcx,%r12,4)
jne 0x17cbbc
testb %r15b, %r15b
je 0x17cbbc
testl %ebp, %ebp
je 0x17cba7
jmp 0x17cbbc
xorl %edi, %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
jmp 0x17cc15
addl %r11d, %edi
movabsq $-0x400000000000000, %r15 # imm = 0xFC00000000000000
movabsq $0x3ffffffffffffff, %r12 # imm = 0x3FFFFFFFFFFFFFF
movq 0x20(%rsp), %r10
movq 0x8(%rsp), %rcx
movl %edi, (%rcx,%r10,4)
orb $0x4, (%rbx)
cmpl $-0x1, %esi
je 0x17cc30
movq 0x20(%rbx), %rcx
movl %esi, %edx
movl (%rcx,%rdx,8), %r10d
movq 0x10(%r14), %rcx
movl (%rcx,%rax,8), %edx
andl $0x7, %edx
leal (%rdx,%r10,8), %edx
movl %edx, (%rcx,%rax,8)
cmpq $0x0, 0x18(%rbx)
je 0x17cae0
movl $0x1, %ebp
xorl %eax, %eax
movq 0x20(%rbx), %rcx
movl (%rcx,%rax,8), %esi
andq %r13, %rsi
cmpq %r13, %rsi
je 0x17cc9e
movq 0x10(%r14), %rdx
leaq (%rsi,%rsi,4), %rax
movl (%rdx,%rax,8), %ecx
testb $0x4, %cl
jne 0x17cd9b
cmpl $0x7, %ecx
jbe 0x17cd7c
leaq (%rdx,%rax,8), %rdx
andl $-0x5, %ecx
addl $-0x8, %ecx
movl %ecx, (%rdx)
movq 0x10(%r14), %rcx
cmpl $0x7, (%rcx,%rax,8)
ja 0x17cc9e
movq 0x38(%r14), %rdi
callq 0x17c80f
movl %ebp, %eax
incl %ebp
cmpq %rax, 0x18(%rbx)
ja 0x17cc53
jmp 0x17cae0
movq 0x10(%r14), %rax
movl 0x1c(%r14), %ecx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %ebx
movq 0x18(%rsp), %r12
movq $0x0, (%r12)
shrl $0x3, %ebx
cmpl 0x18(%r14), %ebx
je 0x17cd30
movl $0x2, %r15d
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0x17cd06
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r15, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rax
movq 0x10(%r12), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r12)
movl %ebx, (%rcx,%rax,4)
movq 0x10(%r14), %rax
movl %ebx, %ecx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %ebx
shrl $0x3, %ebx
cmpl 0x18(%r14), %ebx
jne 0x17ccd8
movq (%r12), %rdx
cmpl $0x2, %edx
jb 0x17cd6d
movl %edx, %eax
shrl %eax
cmpl $0x1, %eax
adcl $0x0, %eax
movq 0x10(%r12), %rcx
leaq (%rcx,%rdx,4), %rdx
addq $-0x4, %rdx
negq %rax
xorl %esi, %esi
movl (%rcx), %edi
movl (%rdx,%rsi,4), %r8d
movl %r8d, (%rcx)
movl %edi, (%rdx,%rsi,4)
addq $0x4, %rcx
decq %rsi
cmpq %rsi, %rax
jne 0x17cd55
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb532c(%rip), %rdi     # 0x2320af
leaq 0xb5061(%rip), %rsi     # 0x231deb
leaq 0xb52bd(%rip), %rcx     # 0x23204e
movl $0x603, %edx            # imm = 0x603
callq 0x2110
leaq 0xb52fc(%rip), %rdi     # 0x23209e
leaq 0xb5042(%rip), %rsi     # 0x231deb
leaq 0xb529e(%rip), %rcx     # 0x23204e
movl $0x602, %edx            # imm = 0x602
callq 0x2110
leaq 0xb52cf(%rip), %rdi     # 0x232090
leaq 0xb5023(%rip), %rsi     # 0x231deb
leaq 0xb527f(%rip), %rcx     # 0x23204e
movl $0x5f1, %edx            # imm = 0x5F1
callq 0x2110
leaq 0xb529e(%rip), %rdi     # 0x23207e
leaq 0xb5004(%rip), %rsi     # 0x231deb
leaq 0xb5260(%rip), %rcx     # 0x23204e
movl $0x5eb, %edx            # imm = 0x5EB
callq 0x2110
leaq 0xb5213(%rip), %rdi     # 0x232012
leaq 0xb4fe5(%rip), %rsi     # 0x231deb
leaq 0xb5241(%rip), %rcx     # 0x23204e
movl $0x5e4, %edx            # imm = 0x5E4
callq 0x2110