// File: /workspace/github_cpp_makefile_star2_O2/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, 0xc(%rsp)
movq %rsi, %rbx
andq $0x0, (%rsi)
movq %rdi, %r14
movq (%rdi), %rax
cmpq %rax, 0x8(%rsi)
jae 0x13fd32
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, %r15
movq %rax, 0x10(%rbx)
jmp 0x13fd36
movq 0x10(%rbx), %r15
movl 0x20(%r14), %eax
movl %eax, 0x8(%rsp)
xorl %eax, %eax
movl %eax, %eax
cmpq %rax, (%r14)
jbe 0x13fda2
andl $0x0, (%r15,%rax,4)
movq 0x10(%r14), %rdx
imulq $0x28, %rax, %rcx
movl (%rdx,%rcx), %esi
cmpl $-0x9, %esi
jbe 0x13fd60
incl %eax
jmp 0x13fd40
addq %rcx, %rdx
andl $0x7, %esi
movl %esi, (%rdx)
movq 0x10(%r14), %rdx
andl $-0x5, (%rdx,%rcx)
movq 0x10(%r14), %rdx
addq %rcx, %rdx
addq $0x8, %rdx
movl 0x10(%rdx), %esi
movl %esi, %esi
cmpq %rsi, (%rdx)
jbe 0x13fd5c
movq 0x18(%rdx), %rdi
movl (%rdi,%rsi,8), %edi
notl %edi
testl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
je 0x13fd9e
movq 0x10(%r14), %rdi
addl $0x8, (%rdi,%rcx)
incl %esi
jmp 0x13fd7e
movq %rbx, 0x10(%rsp)
movq 0x38(%r14), %rax
movabsq $-0x400000000000000, %rcx # imm = 0xFC00000000000000
andq %rcx, (%rax)
movq 0x38(%r14), %rdi
andq $0x0, 0x8(%rdi)
movl 0x18(%r14), %esi
callq 0x13fb20
movq 0x10(%r14), %rax
movl 0x18(%r14), %ecx
imulq $0x28, %rcx, %rcx
cmpl $0x7, (%rax,%rcx)
ja 0x140091
movl 0x8(%rsp), %eax
addl %eax, 0xc(%rsp)
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq 0x38(%r14), %rdi
callq 0x13fc6d
testq %rax, %rax
je 0x13ff67
movl (%rax), %esi
movq 0x10(%r14), %rdx
imulq $0x28, %rsi, %rcx
movl (%rdx,%rcx), %eax
cmpl $-0x9, %eax
ja 0x13fdee
movq %rsi, 0x20(%rsp)
cmpl $0x8, %eax
jae 0x140072
movq %rcx, 0x18(%rsp)
leaq (%rdx,%rcx), %rbx
movl 0x18(%rbx), %esi
movq 0x8(%rbx), %rdi
movl $0x0, 0x4(%rsp)
pushq $-0x1
popq %r8
xorl %r10d, %r10d
xorl %r11d, %r11d
movl %esi, %eax
cmpq %rax, %rdi
jbe 0x13fed7
movq 0x20(%rbx), %r12
movl (%r12,%rax,8), %ecx
andq %r13, %rcx
cmpq %r13, %rcx
je 0x13febc
imulq $0x28, %rcx, %rbp
testb $0x4, (%rdx,%rbp)
je 0x140015
movq %r15, %r9
cmpl 0x8(%rsp), %ecx
setae %r15b
cmpl 0xc(%rsp), %ecx
setb %bpl
andb %r15b, %bpl
cmpl $-0x1, %r8d
je 0x13fea1
movl 0x4(%r12,%rax,8), %eax
cmpl %r11d, %eax
movq %r9, %r15
ja 0x13fea9
jne 0x13febc
cmpl %r10d, (%r15,%rcx,4)
jbe 0x13fec0
movl %r11d, %eax
jmp 0x13fea9
movl 0x4(%r12,%rax,8), %eax
movq %r9, %r15
movzbl %bpl, %r8d
movl %r8d, 0x4(%rsp)
movl (%r15,%rcx,4), %r10d
movl %esi, %r8d
movl %eax, %r11d
incl %esi
jmp 0x13fe42
cmpl %r10d, (%r15,%rcx,4)
jne 0x13febc
testb %bpl, %bpl
je 0x13febc
movl %r11d, %eax
cmpl $0x0, 0x4(%rsp)
je 0x13fea9
jmp 0x13febc
addl %r10d, %r11d
movq 0x20(%rsp), %rsi
movl %r11d, (%r15,%rsi,4)
orb $0x4, (%rbx)
cmpl $-0x1, %r8d
je 0x13fef6
movq 0x20(%rbx), %rax
movl %r8d, %ecx
movl (%rax,%rcx,8), %esi
movq 0x10(%r14), %rax
movq 0x18(%rsp), %rdx
movl (%rax,%rdx), %ecx
andl $0x7, %ecx
leal (%rcx,%rsi,8), %ecx
movl %ecx, (%rax,%rdx)
xorl %ebp, %ebp
movl %ebp, %ebp
cmpq %rbp, 0x18(%rbx)
jbe 0x13fdee
movq 0x20(%rbx), %rax
movl (%rax,%rbp,8), %esi
andq %r13, %rsi
cmpq %r13, %rsi
je 0x13ff63
movq 0x10(%r14), %rcx
imulq $0x28, %rsi, %rax
movl (%rcx,%rax), %edx
testb $0x4, %dl
jne 0x140053
cmpl $0x7, %edx
jbe 0x140034
addq %rax, %rcx
andl $-0x5, %edx
addl $-0x8, %edx
movl %edx, (%rcx)
movq 0x10(%r14), %rcx
cmpl $0x7, (%rcx,%rax)
ja 0x13ff63
movq 0x38(%r14), %rdi
callq 0x13fb20
incl %ebp
jmp 0x13ff0d
movq 0x10(%r14), %rdx
movl 0x1c(%r14), %eax
imulq $0x28, %rax, %rax
movl (%rdx,%rax), %ebx
movq 0x10(%rsp), %r12
andq $0x0, (%r12)
xorl %ecx, %ecx
pushq $0x2
popq %r15
shrl $0x3, %ebx
cmpl 0x18(%r14), %ebx
je 0x13ffdd
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rcx
jne 0x13ffc4
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r15, %rsi
movq %rsi, 0x8(%r12)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
movq 0x10(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r12)
movl %ebx, (%rax,%rcx,4)
movl %ebx, %eax
imulq $0x28, %rax, %rax
movl (%rdx,%rax), %ebx
movq %rsi, %rcx
jmp 0x13ff86
movl %ecx, %eax
shrl %eax
decq %rcx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x140006
movq 0x10(%r12), %rsi
movl (%rsi,%rdx,4), %edi
movl (%rsi,%rcx,4), %r8d
movl %r8d, (%rsi,%rdx,4)
movl %edi, (%rsi,%rcx,4)
incq %rdx
decq %rcx
jmp 0x13ffe6
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb0184(%rip), %rdi     # 0x1f01a0
leaq 0xafed8(%rip), %rsi     # 0x1efefb
leaq 0xb0134(%rip), %rcx     # 0x1f015e
movl $0x5f1, %edx            # imm = 0x5F1
callq 0x2110
leaq 0xb0184(%rip), %rdi     # 0x1f01bf
leaq 0xafeb9(%rip), %rsi     # 0x1efefb
leaq 0xb0115(%rip), %rcx     # 0x1f015e
movl $0x603, %edx            # imm = 0x603
callq 0x2110
leaq 0xb0154(%rip), %rdi     # 0x1f01ae
leaq 0xafe9a(%rip), %rsi     # 0x1efefb
leaq 0xb00f6(%rip), %rcx     # 0x1f015e
movl $0x602, %edx            # imm = 0x602
callq 0x2110
leaq 0xb0115(%rip), %rdi     # 0x1f018e
leaq 0xafe7b(%rip), %rsi     # 0x1efefb
leaq 0xb00d7(%rip), %rcx     # 0x1f015e
movl $0x5eb, %edx            # imm = 0x5EB
callq 0x2110
leaq 0xb008a(%rip), %rdi     # 0x1f0122
leaq 0xafe5c(%rip), %rsi     # 0x1efefb
leaq 0xb00b8(%rip), %rcx     # 0x1f015e
movl $0x5e4, %edx            # imm = 0x5E4
callq 0x2110