// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
shlq %rax
movl %eax, -0xc(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x40(%rbp), %rax
movq $0x0, (%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movl -0xc(%rbp), %ecx
cmpq %rcx, %rax
jae 0x333a89
movl -0xc(%rbp), %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
shrq %rcx
movq -0x40(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq -0x40(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x4, %rcx
movq -0x40(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq -0x40(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x10, %rcx
movq -0x40(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x5, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x333a8b
movl -0xc(%rbp), %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rdx
shlq $0x5, %rdx
xorl %esi, %esi
callq 0x2100
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x333ba5
movl -0x14(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x0, %eax
je 0x333aec
jmp 0x333b97
movl -0x18(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jne 0x333b5e
movq -0x40(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x333b23
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x333b2e
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x333b2e
movq -0x68(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
movl -0x18(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rsi
movq 0x18(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x18(%rsi)
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x333ab8
movq -0x40(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x333bb2
jmp 0x333bd1
leaq 0x6422a(%rip), %rdi     # 0x397de3
leaq 0x625f9(%rip), %rsi     # 0x3961b9
movl $0x17c4, %edx           # imm = 0x17C4
leaq 0x6421e(%rip), %rcx     # 0x397dea
callq 0x2130
jmp 0x333bd3
movq -0x40(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jbe 0x333f70
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rdx
movq 0x18(%rdx), %rcx
movq %rcx, %rsi
addq $-0x1, %rsi
movq %rsi, 0x18(%rdx)
movl -0x4(%rax,%rcx,4), %eax
movl %eax, -0x18(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x40(%rcx), %rcx
movl -0x18(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x333f6b
movq -0x48(%rbp), %rax
movl -0x10(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x20(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x40(%rbp), %rcx
cmpq 0x68(%rcx), %rax
jne 0x333cfc
movq -0x40(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x333cc1
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x333ccc
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x333ccc
movq -0x70(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x40(%rbp), %rax
movq 0x70(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl -0x10(%rbp), %ecx
addq %rcx, %rax
movl %eax, %edx
movq -0x40(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x40(%rbp), %rsi
movq 0x60(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x60(%rsi)
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movq -0x48(%rbp), %rcx
movl -0x10(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x333e59
jmp 0x333d68
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x40(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jne 0x333dd1
movq -0x40(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x333d96
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x333da1
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x333da1
movq -0x78(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x50(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x58(%rax)
movl -0x20(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rsi
movq 0x48(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x48(%rsi)
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movl 0x1c(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x1c(%rax)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x20(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %edx
movq -0x50(%rbp), %rax
movl 0x1c(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0x1c(%rax)
movq -0x30(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x333e7e
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x333e7c
movl -0x18(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x333e7e
movq -0x50(%rbp), %rcx
movl 0x1c(%rcx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addl $-0x1, %eax
movl 0x1c(%rcx), %edx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %eax, %edx
movl %edx, 0x1c(%rcx)
cmpl $0x0, %eax
jne 0x333f5b
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x0, %eax
jbe 0x333f4f
jmp 0x333ec3
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jne 0x333f2c
movq -0x40(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x333ef1
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x333efc
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x333efc
movq -0x80(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
movl -0x20(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rsi
movq 0x18(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x18(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x333f4f
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x333f5d
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x333c5d
jmp 0x333bd3
cmpq $0x0, -0x38(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x333f80
jmp 0x333f82
jmp 0x333fa1
leaq 0x63e80(%rip), %rdi     # 0x397e09
leaq 0x62229(%rip), %rsi     # 0x3961b9
movl $0x17de, %edx           # imm = 0x17DE
leaq 0x63e4e(%rip), %rcx     # 0x397dea
callq 0x2130
movq $0x0, -0x58(%rbp)
movq $-0x1, -0x60(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x334014
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
movq 0x58(%rcx), %rcx
movl -0x10(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x334007
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x10(%rbp), %eax
movq %rax, -0x60(%rbp)
jmp 0x334009
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x333fb8
cmpq $-0x1, -0x60(%rbp)
je 0x3341be
movq -0x8(%rbp), %rax
movq $0x0, 0x80(%rax)
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x60(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
je 0x33411e
jmp 0x33404c
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x88(%rcx), %rax
jne 0x3340d6
movq -0x8(%rbp), %rax
cmpq $0x0, 0x88(%rax)
je 0x334089
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
shlq %rax
movq %rax, -0x88(%rbp)
jmp 0x334097
movl $0x2, %eax
movq %rax, -0x88(%rbp)
jmp 0x334097
movq -0x88(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x90(%rax)
movl -0x18(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x8(%rbp), %rsi
movq 0x80(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x80(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x334102
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
jmp 0x334040
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
shrq %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpq -0x58(%rbp), %rax
jae 0x3341bc
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x10(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x80(%rcx), %rcx
movl -0x10(%rbp), %edx
subq %rdx, %rcx
subq $0x1, %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x10(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x80(%rcx), %rcx
movl -0x10(%rbp), %esi
subq %rsi, %rcx
subq $0x1, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x334137
jmp 0x3341be
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)