// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_cns_by_poa(poa_g_t*)
void gen_cns_by_poa(poa_g_t *g)
{
    uint32_t n_vx = g->seq.n<<1, i, k, v, nv, w; uint64_t c, cc, n_pending = 0;
    ubuf_t *b = &(g->bb); poa_arc_t *av; uinfo_t *t;
    b->a.n = b->S.n = b->T.n = b->b.n = b->e.n = 0;
    kv_resize(uinfo_t, b->a, n_vx); b->a.n = n_vx; memset(b->a.a, 0, sizeof(*(b->a.a))*b->a.n);
    for (k = 0; k < g->seq.n; k++) {
        v = (k<<1) + 1;
        if(poa_arc_n(g, v)) continue;
        v ^= 1; kv_push(uint32_t, b->S, v); b->a.a[v].p = (uint32_t)-1;
    }
    assert(b->S.n);
    while (b->S.n > 0) {
        v = kv_pop(b->S); c = b->a.a[v].c;
        nv = poa_arc_n(g, v); av = poa_arc_a(g, v);
        for (i = 0; i < nv; ++i) {
            w = av[i].v; t = &b->a.a[w];
            kv_push(uint32_t, b->e, ((g->idx.a[v]>>32)+i)); ///push the edge
            cc = c + (uint32_t)av[i].ul;
            if (t->s == 0) {///a new node
                kv_push(uint32_t, b->b, w); // save it for revert
                t->p = v; t->s = 1; //t->d = d + l;
                t->r = poa_arc_n(g, w^1); t->c = cc; ///t->nc = c_nc; 
                ++n_pending; 
            } else {
                if(cc > t->c) {
                    t->p = v; t->c = cc; //t->s = 1; t->d = d + l; t->nc = c_nc; 
                }
            }

            if (--(t->r) == 0) {
                if(poa_arc_n(g, w) > 0) kv_push(uint32_t, b->S, w);
                --n_pending;
                // if(w == dest && n_pending == 0) goto pp_end;
            }
        }
    }
    assert(!n_pending);
    uint64_t m = 0, mi = (uint64_t)-1;
    for (i = 0; i < b->b.n; ++i) { // clear the states of visited vertices
        t = &b->a.a[b->b.a[i]]; ///memset(t, 0, sizeof(*(t)));
        //b->srt.a[i].c = ((uint64_t)-1) - t->c; b->srt.a[i].i = i;
        if(m < t->c) {
            m = t->c; mi = i; ///b->b.a[i];
        }
    }

    if(mi != (uint64_t)-1) {
        g->srt_b.res.n = 0;
        for(v = b->b.a[mi]; v != (uint32_t)-1; v = b->a.a[v].p) {
            kv_push(uint32_t, g->srt_b.res, v);
        }
        m = g->srt_b.res.n>>1;
        for (i = 0; i < m; i++) {
            v = g->srt_b.res.a[i]; 
            g->srt_b.res.a[i] = g->srt_b.res.a[g->srt_b.res.n-i-1];
            g->srt_b.res.a[g->srt_b.res.n-i-1] = v;
        }
    }

    // for (i = 0; i < b->b.n; ++i) { // clear the states of visited vertices
    //     t = &b->a.a[b->b.a[i]]; memset(t, 0, sizeof(*(t)));
    // }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl (%rdi), %r14d
andq $0x0, 0x140(%rdi)
andq $0x0, 0x128(%rdi)
andq $0x0, 0x110(%rdi)
andq $0x0, 0xf8(%rdi)
andq $0x0, 0xe0(%rdi)
addl %r14d, %r14d
cmpq %r14, 0xe8(%rdi)
jae 0x1b86aa
leaq -0x1(%r14), %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, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0xe8(%rbx)
movq 0xf0(%rbx), %rdi
shlq $0x5, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0xf0(%rbx)
jmp 0x1b86b1
movq 0xf0(%rbx), %rdi
movq %r14, 0xe0(%rbx)
shlq $0x5, %r14
xorl %r15d, %r15d
xorl %esi, %esi
movq %r14, %rdx
callq 0x20e0
xorl %ebp, %ebp
movl %ebp, %eax
cmpq %rax, (%rbx)
jbe 0x1b8756
leal 0x1(%r15), %eax
movq 0x40(%rbx), %rcx
cmpl $0x0, (%rcx,%rax,8)
jne 0x1b874b
movq 0xf8(%rbx), %rcx
movq 0x108(%rbx), %rax
cmpq 0x100(%rbx), %rcx
jne 0x1b872a
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x100(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x108(%rbx)
movq 0xf8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0xf8(%rbx)
movl %r15d, (%rax,%rcx,4)
movq 0xf0(%rbx), %rax
movl %r15d, %ecx
shlq $0x5, %rcx
orl $-0x1, (%rax,%rcx)
incl %ebp
addl $0x2, %r15d
jmp 0x1b86cb
movq 0xf8(%rbx), %rax
testq %rax, %rax
je 0x1b8ac1
xorl %ebp, %ebp
testq %rax, %rax
je 0x1b89ac
movq 0x108(%rbx), %rcx
leaq -0x1(%rax), %rdx
movq %rdx, 0xf8(%rbx)
movl -0x4(%rcx,%rax,4), %edx
movq 0xf0(%rbx), %rax
movq %rdx, %rcx
shlq $0x5, %rcx
movq 0x8(%rax,%rcx), %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rbx), %rax
movq 0x40(%rbx), %rcx
movq %rdx, 0x8(%rsp)
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
movq %rdx, 0x20(%rsp)
shrq $0x1c, %rcx
andq $-0x10, %rcx
leaq (%rax,%rcx), %r8
addq $0x8, %r8
xorl %r13d, %r13d
cmpq %r13, 0x20(%rsp)
je 0x1b89a0
movl (%r8), %r15d
movq %r15, %r14
shlq $0x5, %r14
addq 0xf0(%rbx), %r14
movq 0x140(%rbx), %rcx
movq 0x150(%rbx), %rax
cmpq 0x148(%rbx), %rcx
jne 0x1b8838
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x148(%rbx)
shlq $0x2, %rsi
movq %rbp, %r12
movq %rax, %rdi
movq %r8, %rbp
callq 0x2370
movq %rbp, %r8
movq %r12, %rbp
movq %rax, 0x150(%rbx)
movq 0x140(%rbx), %rcx
movq 0x40(%rbx), %rdx
movq 0x8(%rsp), %rsi
movl 0x4(%rdx,%rsi,8), %edx
addl %r13d, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x140(%rbx)
movl %edx, (%rax,%rcx,4)
movl -0x8(%r8), %r12d
addq 0x18(%rsp), %r12
movl 0x1c(%r14), %eax
testl %eax, %eax
js 0x1b8901
movq 0x128(%rbx), %rcx
movq 0x138(%rbx), %rax
cmpq 0x130(%rbx), %rcx
jne 0x1b88c7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x130(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r15, 0x10(%rsp)
movq %r13, %r15
movq %r8, %r13
callq 0x2370
movq %r13, %r8
movq %r15, %r13
movq 0x10(%rsp), %r15
movq %rax, 0x138(%rbx)
movq 0x128(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x128(%rbx)
movl %r15d, (%rax,%rcx,4)
movq 0x8(%rsp), %rax
movl %eax, (%r14)
orb $-0x80, 0x1f(%r14)
movq 0x40(%rbx), %rax
movq %r15, %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,8), %eax
movl $0x80000000, %ecx       # imm = 0x80000000
orl %ecx, %eax
movq %r12, 0x8(%r14)
incq %rbp
jmp 0x1b8913
cmpq 0x8(%r14), %r12
jbe 0x1b8913
movq 0x8(%rsp), %rcx
movl %ecx, (%r14)
movq %r12, 0x8(%r14)
addl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x1c(%r14)
testl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x1b8994
movq 0x40(%rbx), %rax
cmpl $0x0, (%rax,%r15,8)
je 0x1b8991
movq 0xf8(%rbx), %rcx
movq 0x108(%rbx), %rax
cmpq 0x100(%rbx), %rcx
jne 0x1b8982
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x100(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r8, %r12
callq 0x2370
movq %r12, %r8
movq %rax, 0x108(%rbx)
movq 0xf8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0xf8(%rbx)
movl %r15d, (%rax,%rcx,4)
decq %rbp
incq %r13
addq $0x10, %r8
jmp 0x1b87ca
movq 0xf8(%rbx), %rax
jmp 0x1b8768
testq %rbp, %rbp
jne 0x1b8ae0
movq 0x128(%rbx), %rax
pushq $-0x1
popq %r14
xorl %edx, %edx
xorl %ecx, %ecx
movl %edx, %edx
cmpq %rdx, %rax
jbe 0x1b89f4
movq 0xf0(%rbx), %rsi
movq 0x138(%rbx), %rdi
movl (%rdi,%rdx,4), %edi
shlq $0x5, %rdi
movq 0x8(%rsi,%rdi), %rsi
cmpq %rsi, %rcx
cmovbeq %rsi, %rcx
cmovbq %rdx, %r14
incl %edx
jmp 0x1b89c4
cmpq $-0x1, %r14
je 0x1b8ab2
andq $0x0, 0x80(%rbx)
shlq $0x2, %r14
addq 0x138(%rbx), %r14
xorl %ecx, %ecx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl (%r14), %r14d
cmpq %r15, %r14
je 0x1b8a7f
movq 0x90(%rbx), %rax
cmpq 0x88(%rbx), %rcx
jne 0x1b8a60
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x88(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x90(%rbx)
movq 0x80(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x80(%rbx)
movl %r14d, (%rax,%rcx,4)
shlq $0x5, %r14
addq 0xf0(%rbx), %r14
movq %rdx, %rcx
jmp 0x1b8a19
movq %rcx, %rax
shrq %rax
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, %rax
jbe 0x1b8ab2
movq 0x90(%rbx), %rsi
movl (%rsi,%rdx,4), %edi
movq %rdx, %r8
notq %r8
leaq (%rsi,%rcx,4), %r9
movl (%r9,%r8,4), %r10d
movl %r10d, (%rsi,%rdx,4)
movl %edi, (%r9,%r8,4)
incl %edx
jmp 0x1b8a87
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x405ea(%rip), %rdi     # 0x1f90b2
leaq 0x3ea0a(%rip), %rsi     # 0x1f74d9
leaq 0x405e3(%rip), %rcx     # 0x1f90b9
movl $0x17c4, %edx           # imm = 0x17C4
callq 0x2110
leaq 0x405f1(%rip), %rdi     # 0x1f90d8
leaq 0x3e9eb(%rip), %rsi     # 0x1f74d9
leaq 0x405c4(%rip), %rcx     # 0x1f90b9
movl $0x17de, %edx           # imm = 0x17DE
callq 0x2110