// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: hc_simple_traversal(bubble_type*, asg_t*, ma_utg_v*, ubuf_t*, all_ul_t*, unsigned int, unsigned int, ul_path_t*)
uint32_t hc_simple_traversal(bubble_type* bub, asg_t *g, ma_utg_v *gu, ubuf_t *b, all_ul_t *ul, uint32_t src, uint32_t dest, ul_path_t *res)
{
    uint32_t v, nv, i, w, n_pending = 0, is_update = 0; uint64_t l, d, c, cc, nc, c_nc; asg_arc_t *av; uinfo_t *t;
    if (g->seq[src>>1].del || g->seq[dest>>1].del) return 0;
    clear_ubuf_t(b, g, ul, 1);  b->a.a[src].p = (uint32_t)-1;
    kv_push(uint32_t, b->S, src);
    while (b->S.n > 0) {
        v = kv_pop(b->S); d = b->a.a[v].d; c = b->a.a[v].c; nc = b->a.a[v].nc;
        nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
        for (i = 0; i < nv; ++i) {
            if (av[i].del || g->seq[av[i].v>>1].del) continue;
            w = av[i].v; l = (uint32_t)av[i].ul; t = &b->a.a[w];
            kv_push(uint32_t, b->e, ((g->idx[v]>>32)+i)); ///push the edge
            // fprintf(stderr, "+[M::%s::] utg%.6d%c(%c:%u) -> utg%.6d%c(%c:%u)\n", __func__, 
            // (v>>1)+1, "lc"[gu->a[v>>1].circ], "+-"[v&1], v, 
            // (w>>1)+1, "lc"[gu->a[w>>1].circ], "+-"[w&1], w);
            cc = c + get_eul_weight(bub, w^1, v^1, b->a.a, b, ul, g);
            c_nc = nc + (gu?gu->a[w>>1].n:1);
            // fprintf(stderr, "-[M::%s::] utg%.6d%c(%c:%u) -> utg%.6d%c(%c:%u)\n", __func__, 
            // (v>>1)+1, "lc"[gu->a[v>>1].circ], "+-"[v&1], v, 
            // (w>>1)+1, "lc"[gu->a[w>>1].circ], "+-"[w&1], w);

            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 = get_arcs(g, w^1, NULL, 0);
                t->nc = c_nc; t->c = cc;
                ++n_pending; 
            } else {
                is_update = 0;
                if(b->us.a[t->p>>1] == b->us.a[v>>1]) {
                    if(cc > t->c) is_update = 1;
                    if(cc == t->c && c_nc > t->nc) is_update = 1;
                } else {
                    if(b->us.a[t->p>>1]) is_update = 1;
                    else is_update = 0;
                }

                if(is_update) {
                    t->p = v; t->s = 1; t->d = d + l; t->nc = c_nc; t->c = cc;
                }
            }

            if (--(t->r) == 0) {
                if(get_arcs(g, w, NULL, 0) > 0) kv_push(uint32_t, b->S, w);
                --n_pending;
                if(w == dest && n_pending == 0) goto pp_end;
            }
        }
    }
    pp_end:
    extract_paths(b, gu, res, src, dest);
    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)));
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r8, 0x70(%rsp)
movq %rcx, %rbx
movq %rdx, 0x68(%rsp)
movq %rdi, 0x60(%rsp)
movq 0x20(%rsi), %rdx
movl %r9d, %ecx
shrl %ecx
xorl %eax, %eax
cmpl $0x0, (%rdx,%rcx,8)
js 0x1b1f09
movl 0xc0(%rsp), %ecx
shrl %ecx
cmpl $0x0, (%rdx,%rcx,8)
js 0x1b1f09
movl %r9d, %ebp
movq %rsi, %r13
pushq $0x1
popq %rcx
movq %rbx, %rdi
callq 0x1b0093
movq 0x10(%rbx), %rax
movl %ebp, %ecx
shlq $0x5, %rcx
orl $-0x1, (%rax,%rcx)
movq 0x18(%rbx), %rcx
pushq $0x2
popq %rax
cmpq 0x20(%rbx), %rcx
jne 0x1b1b88
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %rax, %rsi
movq %rsi, 0x20(%rbx)
movq 0x28(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rcx
jmp 0x1b1b8c
movq 0x28(%rbx), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x18(%rbx)
movl %ebp, 0x40(%rsp)
movl %ebp, (%rax,%rcx,4)
xorl %r12d, %r12d
movq %r13, 0x20(%rsp)
testq %rdx, %rdx
je 0x1b1ec1
movq 0x10(%rbx), %rax
movq 0x28(%rbx), %rcx
leaq -0x1(%rdx), %rsi
movq %rsi, 0x18(%rbx)
movl -0x4(%rcx,%rdx,4), %edx
movq %rdx, %rcx
shlq $0x5, %rcx
movl 0x4(%rax,%rcx), %esi
movl %esi, 0x1c(%rsp)
movq 0x8(%rax,%rcx), %rsi
movq %rsi, 0x80(%rsp)
movl 0x18(%rax,%rcx), %eax
movq %rax, 0x78(%rsp)
movq 0x8(%r13), %rax
movq 0x28(%r13), %rcx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %r15d
shrq $0x20, %rcx
movl %edx, %esi
xorl $0x1, %esi
movl %esi, 0x44(%rsp)
movq %rdx, 0x28(%rsp)
shrl %edx
movq %rdx, 0x58(%rsp)
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %r14
addq $0xc, %r14
xorl %edi, %edi
movq %r15, 0x48(%rsp)
cmpq %rdi, %r15
je 0x1b1eb8
cmpl $0x0, (%r14)
js 0x1b1eac
movq 0x20(%r13), %rax
movl -0x4(%r14), %r8d
movl %r8d, %ebp
shrl %ebp
cmpl $0x0, (%rax,%rbp,8)
js 0x1b1eac
movq -0xc(%r14), %rax
movq %rax, 0x50(%rsp)
movq %r8, %r15
shlq $0x5, %r15
addq 0x10(%rbx), %r15
movq 0x60(%rbx), %rcx
movq 0x70(%rbx), %rax
cmpq 0x68(%rbx), %rcx
movq %r8, 0x10(%rsp)
movq %r12, 0x30(%rsp)
jne 0x1b1ca7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x68(%rbx)
shlq $0x2, %rsi
movq %rdi, %r12
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %r8
movq %r12, %rdi
movq %rax, 0x70(%rbx)
movq 0x60(%rbx), %rcx
movq 0x28(%r13), %rdx
movq 0x28(%rsp), %rsi
movl 0x4(%rdx,%rsi,8), %edx
movq %rdi, 0x38(%rsp)
addl %edi, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x60(%rbx)
movl %edx, (%rax,%rcx,4)
movl %r8d, %r12d
xorl $0x1, %r12d
movq %r13, (%rsp)
movq 0x60(%rsp), %rdi
movl %r12d, %esi
movl 0x44(%rsp), %edx
movq %rbx, %r8
movq 0x70(%rsp), %r9
callq 0x1b1822
movq %rax, %r8
pushq $0x1
popq %r13
movq 0x68(%rsp), %rax
testq %rax, %rax
je 0x1b1d08
movq 0x10(%rax), %rax
imulq $0x28, %rbp, %rcx
movl 0x10(%rax,%rcx), %r13d
addq 0x78(%rsp), %r13
addq 0x80(%rsp), %r8
movl 0x1c(%r15), %eax
testl %eax, %eax
js 0x1b1daf
movq %r8, %rbp
movq 0x48(%rbx), %rcx
movq 0x58(%rbx), %rax
cmpq 0x50(%rbx), %rcx
jne 0x1b1d58
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x50(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x58(%rbx)
movq 0x48(%rbx), %rcx
movq 0x10(%rsp), %rsi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x48(%rbx)
movl %esi, (%rax,%rcx,4)
movq 0x28(%rsp), %rax
movl %eax, (%r15)
orb $-0x80, 0x1f(%r15)
movq 0x50(%rsp), %rax
addl 0x1c(%rsp), %eax
movl %eax, 0x4(%r15)
movq 0x20(%rsp), %rdi
movl %r12d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
orl $0x80000000, %eax       # imm = 0x80000000
movl %r13d, 0x18(%r15)
movq %rbp, 0x8(%r15)
movq 0x30(%rsp), %r12
incl %r12d
movq 0x38(%rsp), %rdi
jmp 0x1b1e09
movq 0x88(%rbx), %rdx
movl (%r15), %ecx
shrl %ecx
movb (%rdx,%rcx), %cl
movq 0x58(%rsp), %rsi
cmpb (%rdx,%rsi), %cl
movq 0x38(%rsp), %rdi
jne 0x1b1de3
cmpq 0x8(%r15), %r8
movq 0x30(%rsp), %r12
jne 0x1b1ddf
movl 0x18(%r15), %ecx
cmpq %rcx, %r13
ja 0x1b1dec
jmp 0x1b1e09
testb %cl, %cl
movq 0x30(%rsp), %r12
je 0x1b1e09
movq 0x28(%rsp), %rcx
movl %ecx, (%r15)
movq 0x50(%rsp), %rcx
addl 0x1c(%rsp), %ecx
movl %ecx, 0x4(%r15)
movl %r13d, 0x18(%r15)
movq %r8, 0x8(%r15)
addl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x1c(%r15)
testl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x1b1e2d
movq 0x20(%rsp), %r13
movq 0x48(%rsp), %r15
jmp 0x1b1eac
movq 0x20(%rsp), %r13
movq %r13, %rdi
movq 0x10(%rsp), %r15
movl %r15d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
movq %r15, %rsi
testl %eax, %eax
movq 0x48(%rsp), %r15
je 0x1b1e96
movq 0x18(%rbx), %rcx
movq 0x28(%rbx), %rax
cmpq 0x20(%rbx), %rcx
jne 0x1b1e8b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x20(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %rsi
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x18(%rbx)
movl %esi, (%rax,%rcx,4)
decl %r12d
cmpl 0xc0(%rsp), %esi
movq 0x38(%rsp), %rdi
jne 0x1b1eac
testl %r12d, %r12d
je 0x1b1ec1
incq %rdi
addq $0x18, %r14
jmp 0x1b1c20
movq 0x18(%rbx), %rdx
jmp 0x1b1ba3
movq %rbx, %rdi
movq 0xc8(%rsp), %rdx
movl 0x40(%rsp), %ecx
movl 0xc0(%rsp), %r8d
callq 0x1b1965
xorl %eax, %eax
xorps %xmm0, %xmm0
movl %eax, %eax
cmpq %rax, 0x48(%rbx)
jbe 0x1b1f06
movq 0x10(%rbx), %rcx
movq 0x58(%rbx), %rdx
movl (%rdx,%rax,4), %edx
shlq $0x5, %rdx
movups %xmm0, 0x10(%rcx,%rdx)
movups %xmm0, (%rcx,%rdx)
incl %eax
jmp 0x1b1ee2
pushq $0x1
popq %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq