// File: /workspace/github_cpp_makefile_star2_O3/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 0x2044dc
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 0x2044e3
movq 0xf0(%rbx), %rdi
movq %r14, 0xe0(%rbx)
shlq $0x5, %r14
xorl %r15d, %r15d
xorl %esi, %esi
movq %r14, %rdx
callq 0x20e0
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x20459b
movl $0x1, %ebp
movl $0x2, %r14d
leal 0x1(%r15), %eax
movq 0x40(%rbx), %rdx
cmpl $0x0, (%rdx,%rax,8)
jne 0x20458a
movq 0xf8(%rbx), %rdx
movq 0x108(%rbx), %rax
cmpq 0x100(%rbx), %rdx
jne 0x204566
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %r14, %rsi
movq %rsi, 0x100(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x108(%rbx)
movq (%rbx), %rcx
movq 0xf8(%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0xf8(%rbx)
movl %r15d, (%rax,%rdx,4)
movq 0xf0(%rbx), %rax
movl %r15d, %edx
shlq $0x5, %rdx
movl $0xffffffff, (%rax,%rdx) # imm = 0xFFFFFFFF
movl %ebp, %eax
addl $0x2, %r15d
incl %ebp
cmpq %rax, %rcx
ja 0x204512
movq 0xf8(%rbx), %rax
testq %rax, %rax
je 0x204921
xorl %edi, %edi
movq %rax, %rcx
movq 0x108(%rbx), %rdx
decq %rax
movq %rax, 0xf8(%rbx)
movl -0x4(%rdx,%rcx,4), %r8d
movq 0x40(%rbx), %rcx
movq (%rcx,%r8,8), %rcx
testl %ecx, %ecx
je 0x2047f2
movq 0xf0(%rbx), %rax
movq %r8, %rdx
shlq $0x5, %rdx
movq 0x8(%rax,%rdx), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rbx), %rax
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
movq %rcx, 0x18(%rsp)
shlq $0x4, %rdx
leaq (%rax,%rdx), %r15
addq $0x8, %r15
xorl %r13d, %r13d
movq %r8, 0x8(%rsp)
movl (%r15), %r9d
movq %r9, %rbp
shlq $0x5, %rbp
addq 0xf0(%rbx), %rbp
movq 0x140(%rbx), %rcx
movq 0x150(%rbx), %rax
cmpq 0x148(%rbx), %rcx
jne 0x20467e
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x148(%rbx)
shlq $0x2, %rsi
movq %rdi, %r12
movq %rax, %rdi
movq %r9, %r14
callq 0x2370
movq %r14, %r9
movq 0x8(%rsp), %r8
movq %r12, %rdi
movq %rax, 0x150(%rbx)
movq 0x140(%rbx), %rcx
movq 0x40(%rbx), %rdx
movl 0x4(%rdx,%r8,8), %edx
addl %r13d, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x140(%rbx)
movl %edx, (%rax,%rcx,4)
movl -0x8(%r15), %r12d
addq 0x20(%rsp), %r12
movl 0x1c(%rbp), %eax
testl %eax, %eax
js 0x20473e
movq 0x128(%rbx), %rcx
movq 0x138(%rbx), %rax
cmpq 0x130(%rbx), %rcx
jne 0x204709
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x130(%rbx)
shlq $0x2, %rsi
movq %rdi, 0x10(%rsp)
movq %rax, %rdi
movq %r9, %r14
callq 0x2370
movq %r14, %r9
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %rax, 0x138(%rbx)
movq 0x128(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x128(%rbx)
movl %r9d, (%rax,%rcx,4)
movl %r8d, (%rbp)
orb $-0x80, 0x1f(%rbp)
movq 0x40(%rbx), %rax
movq %r9, %rcx
xorq $0x1, %rcx
movl (%rax,%rcx,8), %eax
movl $0x80000000, %ecx       # imm = 0x80000000
orl %ecx, %eax
movq %r12, 0x8(%rbp)
incq %rdi
jmp 0x20474c
cmpq 0x8(%rbp), %r12
jbe 0x20474c
movl %r8d, (%rbp)
movq %r12, 0x8(%rbp)
addl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x1c(%rbp)
testl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x2047d9
movq 0x40(%rbx), %rax
cmpl $0x0, (%rax,%r9,8)
je 0x2047d6
movq 0xf8(%rbx), %rcx
movq 0x108(%rbx), %rax
cmpq 0x100(%rbx), %rcx
jne 0x2047c7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x100(%rbx)
shlq $0x2, %rsi
movq %rdi, %r14
movq %rax, %rdi
movq %r9, %r12
callq 0x2370
movq %r12, %r9
movq 0x8(%rsp), %r8
movq %r14, %rdi
movq %rax, 0x108(%rbx)
movq 0xf8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0xf8(%rbx)
movl %r9d, (%rax,%rcx,4)
decq %rdi
incq %r13
addq $0x10, %r15
cmpq %r13, 0x18(%rsp)
jne 0x204614
movq 0xf8(%rbx), %rax
testq %rax, %rax
jne 0x2045ad
testq %rdi, %rdi
jne 0x204940
movq 0x128(%rbx), %rcx
testq %rcx, %rcx
je 0x204912
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 0x20482e
cmpq $-0x1, %rax
je 0x204912
movq $0x0, 0x80(%rbx)
movq 0x138(%rbx), %rcx
movl (%rcx,%rax,4), %ebp
cmpl $-0x1, %ebp
je 0x204912
movq 0x90(%rbx), %rax
xorl %ecx, %ecx
movl $0x2, %r14d
cmpq 0x88(%rbx), %rcx
jne 0x2048bf
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r14, %rsi
movq %rsi, 0x88(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x90(%rbx)
movq 0x80(%rbx), %rdx
jmp 0x2048c2
movq %rcx, %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0x80(%rbx)
movl %ebp, (%rax,%rdx,4)
movq 0xf0(%rbx), %rsi
movl %ebp, %edi
shlq $0x5, %rdi
movl (%rsi,%rdi), %ebp
cmpl $-0x1, %ebp
jne 0x204888
cmpq $0x2, %rcx
jb 0x204912
shrq %rcx
movq 0x90(%rbx), %rax
xorl %esi, %esi
movl (%rax,%rsi,4), %edi
movl (%rax,%rdx,4), %r8d
movl %r8d, (%rax,%rsi,4)
movl %edi, (%rax,%rdx,4)
incq %rsi
movl %esi, %edi
decq %rdx
cmpq %rdi, %rcx
ja 0x2048f7
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x427cb(%rip), %rdi     # 0x2470f3
leaq 0x40cda(%rip), %rsi     # 0x245609
leaq 0x427c4(%rip), %rcx     # 0x2470fa
movl $0x17c4, %edx           # imm = 0x17C4
callq 0x2110
leaq 0x427d2(%rip), %rdi     # 0x247119
leaq 0x40cbb(%rip), %rsi     # 0x245609
leaq 0x427a5(%rip), %rcx     # 0x2470fa
movl $0x17de, %edx           # imm = 0x17DE
callq 0x2110