// File: /workspace/github_cpp_makefile_star2_O1/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
addl %r14d, %r14d
xorl %eax, %eax
movq %rax, 0x140(%rdi)
movq %rax, 0x128(%rdi)
movq %rax, 0x110(%rdi)
movq %rax, 0xf8(%rdi)
movq %rax, 0xe0(%rdi)
cmpq %r14, 0xe8(%rdi)
jae 0x1f8ea7
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, 0xf0(%rbx)
movq %r14, 0xe0(%rbx)
movq 0xf0(%rbx), %rdi
shlq $0x5, %r14
xorl %r15d, %r15d
xorl %esi, %esi
movq %r14, %rdx
callq 0x20e0
cmpq $0x0, (%rbx)
je 0x1f8f65
movl $0x1, %ebp
movl $0x2, %r14d
leal 0x1(%r15), %eax
movq 0x40(%rbx), %rcx
cmpl $0x0, (%rcx,%rax,8)
jne 0x1f8f54
movq 0x100(%rbx), %rax
cmpq %rax, 0xf8(%rbx)
jne 0x1f8f22
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r14, %rsi
movq %rsi, 0x100(%rbx)
movq 0x108(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x108(%rbx)
movq 0xf8(%rbx), %rax
movq 0x108(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xf8(%rbx)
movl %r15d, (%rcx,%rax,4)
movq 0xf0(%rbx), %rax
movl %r15d, %ecx
shlq $0x5, %rcx
movl $0xffffffff, (%rax,%rcx) # imm = 0xFFFFFFFF
movl %ebp, %eax
addl $0x2, %r15d
incl %ebp
cmpq %rax, (%rbx)
ja 0x1f8edb
cmpq $0x0, 0xf8(%rbx)
je 0x1f9308
movq 0xf8(%rbx), %rax
testq %rax, %rax
je 0x1f91d9
xorl %edi, %edi
movq 0x108(%rbx), %rcx
leaq -0x1(%rax), %rdx
movq %rdx, 0xf8(%rbx)
movl -0x4(%rcx,%rax,4), %r8d
movq 0x40(%rbx), %rax
movq (%rax,%r8,8), %rax
testl %eax, %eax
je 0x1f91c0
movq 0xf0(%rbx), %rcx
movq %r8, %rdx
shlq $0x5, %rdx
movq 0x8(%rcx,%rdx), %rcx
movq %rcx, 0x20(%rsp)
movq 0x28(%rbx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
movq %rax, 0x18(%rsp)
shlq $0x4, %rdx
leaq (%rcx,%rdx), %r15
addq $0x8, %r15
xorl %r13d, %r13d
movq %r8, 0x8(%rsp)
movl (%r15), %r14d
movq %r14, %rbp
shlq $0x5, %rbp
addq 0xf0(%rbx), %rbp
movq 0x148(%rbx), %rax
cmpq %rax, 0x140(%rbx)
jne 0x1f9044
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x148(%rbx)
movq %rdi, %r12
movq 0x150(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x8(%rsp), %r8
movq %r12, %rdi
movq %rax, 0x150(%rbx)
movq 0x40(%rbx), %rax
movq 0x140(%rbx), %rcx
movl 0x4(%rax,%r8,8), %eax
addl %r13d, %eax
movq 0x150(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x140(%rbx)
movl %eax, (%rdx,%rcx,4)
movl -0x8(%r15), %r12d
addq 0x20(%rsp), %r12
cmpl $0x0, 0x1c(%rbp)
js 0x1f9112
movq 0x130(%rbx), %rax
cmpq %rax, 0x128(%rbx)
jne 0x1f90cc
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x130(%rbx)
movq %rdi, 0x10(%rsp)
movq 0x138(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %rax, 0x138(%rbx)
movq 0x128(%rbx), %rax
movq 0x138(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x128(%rbx)
movl %r14d, (%rcx,%rax,4)
movl %r8d, (%rbp)
orb $-0x80, 0x1f(%rbp)
movq 0x40(%rbx), %rax
movq %r14, %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,8), %eax
movl $0x80000000, %ecx       # imm = 0x80000000
orl %ecx, %eax
movl %eax, 0x1c(%rbp)
movq %r12, 0x8(%rbp)
incq %rdi
jmp 0x1f9120
cmpq 0x8(%rbp), %r12
jbe 0x1f9120
movl %r8d, (%rbp)
movq %r12, 0x8(%rbp)
movl 0x1c(%rbp), %eax
leal -0x1(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %eax       # imm = 0x80000000
orl %ecx, %eax
movl %eax, 0x1c(%rbp)
testl %ecx, %ecx
jne 0x1f91ae
movq 0x40(%rbx), %rax
cmpl $0x0, (%rax,%r14,8)
je 0x1f91ab
movq 0x100(%rbx), %rax
cmpq %rax, 0xf8(%rbx)
jne 0x1f918e
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x100(%rbx)
movq %rdi, %r12
movq 0x108(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x8(%rsp), %r8
movq %r12, %rdi
movq %rax, 0x108(%rbx)
movq 0xf8(%rbx), %rax
movq 0x108(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xf8(%rbx)
movl %r14d, (%rcx,%rax,4)
decq %rdi
incq %r13
addq $0x10, %r15
cmpq %r13, 0x18(%rsp)
jne 0x1f8fea
movq 0xf8(%rbx), %rax
testq %rax, %rax
jne 0x1f8f85
testq %rdi, %rdi
jne 0x1f9327
movq 0x128(%rbx), %rcx
testq %rcx, %rcx
je 0x1f9224
movq 0xf0(%rbx), %rdx
movq 0x138(%rbx), %rsi
movq $-0x1, %rax
xorl %edi, %edi
xorl %r8d, %r8d
movl (%rsi,%rdi,4), %r9d
shlq $0x5, %r9
movq 0x8(%rdx,%r9), %r9
cmpq %r9, %r8
cmovbeq %r9, %r8
cmovbq %rdi, %rax
incq %rdi
movl %edi, %r9d
cmpq %r9, %rcx
ja 0x1f91ff
jmp 0x1f922b
movq $-0x1, %rax
cmpq $-0x1, %rax
je 0x1f92f9
movq $0x0, 0x80(%rbx)
movq 0x138(%rbx), %rcx
movl (%rcx,%rax,4), %ebp
cmpl $-0x1, %ebp
je 0x1f92bf
movl $0x2, %r14d
movq 0x88(%rbx), %rax
cmpq %rax, 0x80(%rbx)
jne 0x1f928e
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r14, %rsi
movq %rsi, 0x88(%rbx)
movq 0x90(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x90(%rbx)
movq 0x80(%rbx), %rax
movq 0x90(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x80(%rbx)
movl %ebp, (%rcx,%rax,4)
movq 0xf0(%rbx), %rax
movl %ebp, %ecx
shlq $0x5, %rcx
movl (%rax,%rcx), %ebp
cmpl $-0x1, %ebp
jne 0x1f9255
movq 0x80(%rbx), %rax
cmpq $0x2, %rax
jb 0x1f92f9
movq %rax, %rcx
shrq %rcx
movq 0x90(%rbx), %rdx
decq %rax
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
movl (%rdx,%rax,4), %r8d
movl %r8d, (%rdx,%rsi,4)
movl %edi, (%rdx,%rax,4)
incq %rsi
movl %esi, %edi
decq %rax
cmpq %rdi, %rcx
ja 0x1f92de
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x41b00(%rip), %rdi     # 0x23ae0f
leaq 0x4000f(%rip), %rsi     # 0x239325
leaq 0x41af9(%rip), %rcx     # 0x23ae16
movl $0x17c4, %edx           # imm = 0x17C4
callq 0x2110
leaq 0x41b07(%rip), %rdi     # 0x23ae35
leaq 0x3fff0(%rip), %rsi     # 0x239325
leaq 0x41ada(%rip), %rcx     # 0x23ae16
movl $0x17de, %edx           # imm = 0x17DE
callq 0x2110