// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r12
movq $0x0, (%rsi)
movq (%rdi), %rdx
cmpq %rdx, 0x8(%rsi)
jae 0x18374a
decq %rdx
movq %rdx, %rcx
shrq %rcx
orq %rdx, %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(%r15)
movq 0x10(%r15), %rdi
leaq 0x4(,%rcx,4), %rsi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r12), %rdx
jmp 0x18374e
movq 0x10(%r15), %rax
movl 0x20(%r12), %ecx
movl %ecx, 0xc(%rsp)
testq %rdx, %rdx
je 0x1837f0
xorl %edx, %edx
xorl %r10d, %r10d
movl $0x0, (%rax,%rdx,4)
movq 0x10(%r12), %rdi
leaq (%rdx,%rdx,4), %rcx
movl (%rdi,%rcx,8), %esi
cmpl $-0x9, %esi
ja 0x1837e0
leaq (%rdi,%rcx,8), %rdi
andl $0x7, %esi
movl %esi, (%rdi)
movq 0x10(%r12), %rdi
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %rsi
andl $-0x5, (%rdi,%rsi)
movq 0x10(%r12), %rdi
movl 0x18(%rdi,%rsi), %r8d
movq 0x8(%rdi,%rsi), %rdx
cmpq %r8, %rdx
jbe 0x1837e0
addq %rdi, %rsi
addq $0x8, %rsi
leal 0x1(%r8), %edi
movq 0x18(%rsi), %r9
movl (%r9,%r8,8), %r8d
notl %r8d
testl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
je 0x1837d6
movq 0x10(%r12), %rdx
addl $0x8, (%rdx,%rcx,8)
movq (%rsi), %rdx
movl %edi, %r8d
incl %edi
cmpq %r8, %rdx
ja 0x1837b6
incl %r10d
movq %r10, %rdx
cmpq %r10, (%r12)
ja 0x183765
movq %rax, 0x10(%rsp)
movabsq $-0x400000000000000, %rcx # imm = 0xFC00000000000000
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq 0x38(%r12), %rax
andq %rcx, (%rax)
movq 0x38(%r12), %rax
movl 0x18(%r12), %ecx
movq (%rax), %rdx
movq 0x18(%rax), %rsi
movq $0x1, 0x8(%rax)
andq 0x10(%rax), %rdx
andq %r10, %rdx
movl %ecx, (%rsi,%rdx,4)
movq 0x10(%r12), %rdx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x7, (%rdx,%rcx,8)
ja 0x183ce8
addl 0xc(%rsp), %ebx
movl $0x1, %ecx
movq %r15, 0x30(%rsp)
movq %r12, 0x20(%rsp)
movl %ebx, 0x1c(%rsp)
movq (%rax), %rdx
movq 0x18(%rax), %rsi
leaq 0x1(%rdx), %rdi
andq %r10, %rdi
movq %rdx, %r8
movabsq $-0x400000000000000, %r9 # imm = 0xFC00000000000000
andq %r9, %r8
andq 0x10(%rax), %rdi
orq %r8, %rdi
movq %rdi, (%rax)
decq %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%r12), %rcx
testq %rsi, %rsi
je 0x183bb2
andq %r10, %rdx
movl (%rsi,%rdx,4), %edx
leaq (%rdx,%rdx,4), %rax
movl (%rcx,%rax,8), %esi
cmpl $-0x8, %esi
jae 0x183b96
cmpl $0x8, %esi
jae 0x183cc9
leaq (%rcx,%rax,8), %r8
movl 0x18(%r8), %esi
movq 0x8(%r8), %rdi
cmpq %rsi, %rdi
movq %r8, 0x28(%rsp)
jbe 0x183976
movq 0x20(%r8), %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
xorl %r10d, %r10d
xorl %r11d, %r11d
xorl %ebx, %ebx
movl 0x1c(%rsp), %r13d
movl (%r8,%rsi,8), %r14d
movl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
andq %r15, %r14
cmpq %r15, %r14
je 0x183959
leaq (%r14,%r14,4), %r15
testb $0x4, (%rcx,%r15,8)
je 0x183caa
cmpl 0xc(%rsp), %r14d
setae %r15b
cmpl %r13d, %r14d
setb %bpl
andb %r15b, %bpl
cmpl $-0x1, %r9d
je 0x183941
movl 0x4(%r8,%rsi,8), %r15d
cmpl %r10d, %r15d
ja 0x183946
jne 0x183959
movq 0x10(%rsp), %r15
cmpl %r11d, (%r15,%r14,4)
jbe 0x183962
movl %r10d, %r15d
jmp 0x183946
movl 0x4(%r8,%rsi,8), %r15d
movzbl %bpl, %ebx
movq 0x10(%rsp), %r9
movl (%r9,%r14,4), %r11d
movl %esi, %r9d
movl %r15d, %r10d
incl %esi
cmpq %rsi, %rdi
ja 0x1838eb
jmp 0x183988
cmpl %r11d, (%r15,%r14,4)
jne 0x183959
testb %bpl, %bpl
je 0x183959
movl %r10d, %r15d
testl %ebx, %ebx
je 0x183946
jmp 0x183959
movq 0x10(%rsp), %rcx
movl $0x0, (%rcx,%rdx,4)
orb $0x4, (%r8)
jmp 0x1839b7
addl %r11d, %r10d
movq 0x10(%rsp), %rcx
movl %r10d, (%rcx,%rdx,4)
movq 0x28(%rsp), %r8
orb $0x4, (%r8)
cmpl $-0x1, %r9d
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
je 0x1839b7
movq 0x20(%r8), %rcx
movl %r9d, %edx
movl (%rcx,%rdx,8), %edx
movq 0x10(%r12), %rcx
movl (%rcx,%rax,8), %esi
andl $0x7, %esi
leal (%rsi,%rdx,8), %edx
movl %edx, (%rcx,%rax,8)
cmpq $0x0, 0x18(%r8)
je 0x183b96
xorl %r13d, %r13d
movq 0x20(%r8), %rax
movl (%rax,%r13,8), %r15d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %r15
cmpq %rax, %r15
je 0x183b7f
movq 0x10(%r12), %rdx
leaq (%r15,%r15,4), %rax
movl (%rdx,%rax,8), %ecx
testb $0x4, %cl
jne 0x183c8b
cmpl $0x7, %ecx
jbe 0x183c6c
leaq (%rdx,%rax,8), %rdx
andl $-0x5, %ecx
addl $-0x8, %ecx
movl %ecx, (%rdx)
movq 0x10(%r12), %rcx
cmpl $0x7, (%rcx,%rax,8)
ja 0x183b7f
movq 0x38(%r12), %r14
movq (%r14), %rsi
movq 0x8(%r14), %rbx
movq %rsi, %rax
shrq $0x3a, %rax
movl $0x1, %edx
movl %eax, %ecx
shlq %cl, %rdx
cmpq %rdx, %rbx
jne 0x183b65
leal 0x1(%rax), %r12d
movl $0x1, %ebp
movl %r12d, %ecx
shlq %cl, %rbp
cmpq %rbx, %rbp
jae 0x183aa3
movq $-0x1, %r12
incq %r12
movq %rbx, %rdx
movl %r12d, %ecx
shrq %cl, %rdx
cmpq $0x3f, %r12
ja 0x183a80
testq %rdx, %rdx
jne 0x183a69
cmpq %r12, %rax
jne 0x183a8f
movq 0x20(%rsp), %r12
jmp 0x183b65
movl $0x1, %ebp
movl %r12d, %ecx
shlq %cl, %rbp
cmpq %rax, %r12
jbe 0x183b8e
movq 0x18(%r14), %rdi
movl $0x4, %esi
movl %r12d, %ecx
shlq %cl, %rsi
callq 0x2370
movq %rax, 0x18(%r14)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq %rsi, %rax
andq %r10, %rax
addq %rax, %rdx
cmpq %rbx, %rdx
jbe 0x183b10
movq 0x18(%r14), %rcx
movq %rbx, %rdx
subq %rax, %rdx
movq %rbp, %rsi
subq %rdx, %rsi
leaq (%rcx,%rsi,4), %rdi
leaq (%rcx,%rax,4), %rsi
shlq $0x2, %rdx
callq 0x2360
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
subq %rbx, %rbp
addq (%r14), %rbp
movq %rbp, %rsi
jmp 0x183b33
subq %rbp, %rdx
jbe 0x183b33
movq 0x18(%r14), %rdi
leaq (%rdi,%rbp,4), %rsi
shlq $0x2, %rdx
callq 0x2360
movabsq $0x3ffffffffffffff, %r10 # imm = 0x3FFFFFFFFFFFFFF
movq (%r14), %rsi
movq %r12, %rax
shlq $0x3a, %rax
andq %r10, %rsi
orq %rax, %rsi
movq $-0x1, %rax
movl %r12d, %ecx
shlq %cl, %rax
movq %rsi, (%r14)
notq %rax
movq %rax, 0x10(%r14)
movq 0x8(%r14), %rbx
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r8
movq 0x18(%r14), %rax
leaq 0x1(%rbx), %rcx
movq %rcx, 0x8(%r14)
andq %r10, %rsi
addq %rbx, %rsi
andq 0x10(%r14), %rsi
movl %r15d, (%rax,%rsi,4)
incl %r13d
cmpq %r13, 0x18(%r8)
ja 0x1839d6
jmp 0x183b96
movq %rbx, %rdx
jmp 0x183acc
movq 0x38(%r12), %rax
movq 0x8(%rax), %rcx
testq %rcx, %rcx
movq 0x30(%rsp), %r15
jne 0x18385e
movq 0x10(%r12), %rcx
movl 0x1c(%r12), %eax
leaq (%rax,%rax,4), %rax
movl (%rcx,%rax,8), %ebx
shrl $0x3, %ebx
cmpl 0x18(%r12), %ebx
movq $0x0, (%r15)
je 0x183c5d
movq 0x10(%r15), %rax
xorl %edx, %edx
movl $0x2, %r14d
cmpq 0x8(%r15), %rdx
jne 0x183c0e
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %r14, %rsi
movq %rsi, 0x8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rsi
movq 0x10(%r12), %rcx
jmp 0x183c11
movq %rdx, %rsi
leaq 0x1(%rsi), %rdx
movq %rdx, (%r15)
movl %ebx, (%rax,%rsi,4)
movl %ebx, %edi
leaq (%rdi,%rdi,4), %rdi
movl (%rcx,%rdi,8), %ebx
shrl $0x3, %ebx
cmpl 0x18(%r12), %ebx
jne 0x183bdf
testl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
je 0x183c5d
shrl %edx
movq 0x10(%r15), %rax
leaq (%rax,%rsi,4), %rcx
negq %rdx
xorl %esi, %esi
movl (%rax), %edi
movl (%rcx,%rsi,4), %r8d
movl %r8d, (%rax)
movl %edi, (%rcx,%rsi,4)
addq $0x4, %rax
decq %rsi
cmpq %rsi, %rdx
jne 0x183c45
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xba68c(%rip), %rdi     # 0x23e2ff
leaq 0xba3c1(%rip), %rsi     # 0x23e03b
leaq 0xba61d(%rip), %rcx     # 0x23e29e
movl $0x603, %edx            # imm = 0x603
callq 0x2110
leaq 0xba65c(%rip), %rdi     # 0x23e2ee
leaq 0xba3a2(%rip), %rsi     # 0x23e03b
leaq 0xba5fe(%rip), %rcx     # 0x23e29e
movl $0x602, %edx            # imm = 0x602
callq 0x2110
leaq 0xba62f(%rip), %rdi     # 0x23e2e0
leaq 0xba383(%rip), %rsi     # 0x23e03b
leaq 0xba5df(%rip), %rcx     # 0x23e29e
movl $0x5f1, %edx            # imm = 0x5F1
callq 0x2110
leaq 0xba5fe(%rip), %rdi     # 0x23e2ce
leaq 0xba364(%rip), %rsi     # 0x23e03b
leaq 0xba5c0(%rip), %rcx     # 0x23e29e
movl $0x5eb, %edx            # imm = 0x5EB
callq 0x2110
leaq 0xba573(%rip), %rdi     # 0x23e262
leaq 0xba345(%rip), %rsi     # 0x23e03b
leaq 0xba5a1(%rip), %rcx     # 0x23e29e
movl $0x5e4, %edx            # imm = 0x5E4
callq 0x2110