// File: /workspace/github_cpp_makefile_star2_O1/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), %rcx
movl %r9d, %edx
shrl %edx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx,8)
js 0x1f28eb
movl 0xc0(%rsp), %edx
shrl %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0x1f28eb
movl %r9d, %ebp
movq %rbx, %rdi
movq %rsi, 0x18(%rsp)
movl $0x1, %ecx
callq 0x1f0753
movq 0x10(%rbx), %rax
movl %ebp, %ecx
shlq $0x5, %rcx
movl $0xffffffff, (%rax,%rcx) # imm = 0xFFFFFFFF
movq 0x20(%rbx), %rax
cmpq %rax, 0x18(%rbx)
jne 0x1f2491
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x20(%rbx)
movq 0x28(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rcx
movq 0x28(%rbx), %rdx
movq %rcx, %rax
incq %rax
movq %rax, 0x18(%rbx)
movl %ebp, 0x40(%rsp)
movl %ebp, (%rdx,%rcx,4)
movq 0x18(%rsp), %r8
je 0x1f2890
xorl %r13d, %r13d
movq 0x10(%rbx), %rcx
movq 0x28(%rbx), %rdx
leaq -0x1(%rax), %rsi
movq %rsi, 0x18(%rbx)
movl -0x4(%rdx,%rax,4), %r14d
movq 0x28(%r8), %rax
movq (%rax,%r14,8), %rax
testl %eax, %eax
je 0x1f2883
movq %r14, %rdx
shlq $0x5, %rdx
movl 0x4(%rcx,%rdx), %esi
movl %esi, 0x24(%rsp)
movq 0x8(%rcx,%rdx), %rsi
movq %rsi, 0x80(%rsp)
movl 0x18(%rcx,%rdx), %ecx
movq %rcx, 0x78(%rsp)
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r12
shlq $0x3, %r12
addq 0x8(%r8), %r12
movl %r14d, %ecx
xorl $0x1, %ecx
movl %ecx, 0x44(%rsp)
movl %r14d, %ecx
shrl %ecx
movq %rcx, 0x58(%rsp)
movl %eax, %esi
xorl %r15d, %r15d
movq %r14, 0x28(%rsp)
movq %r12, 0x48(%rsp)
movq %rsi, 0x10(%rsp)
leaq (%r15,%r15,2), %rax
cmpl $0x0, 0xc(%r12,%rax,8)
js 0x1f2877
leaq (%r12,%rax,8), %rax
movq 0x20(%r8), %rcx
movl 0x8(%rax), %r9d
movl %r9d, %ebp
shrl %ebp
cmpl $0x0, (%rcx,%rbp,8)
js 0x1f2877
movq %r13, 0x30(%rsp)
movq %r9, %r12
shlq $0x5, %r12
addq 0x10(%rbx), %r12
movq (%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x68(%rbx), %rax
cmpq %rax, 0x60(%rbx)
jne 0x1f25ba
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x68(%rbx)
movq 0x70(%rbx), %rdi
shlq $0x2, %rsi
movq %r9, %r13
callq 0x2370
movq %r13, %r9
movq 0x18(%rsp), %r8
movq %rax, 0x70(%rbx)
movq 0x28(%r8), %rax
movl 0x4(%rax,%r14,8), %eax
addl %r15d, %eax
movq 0x60(%rbx), %rcx
movq 0x70(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x60(%rbx)
movl %eax, (%rdx,%rcx,4)
movq %r9, 0x38(%rsp)
movq %r9, %r13
xorq $0x1, %r13
movq %r8, (%rsp)
movq 0x60(%rsp), %rdi
movl %r13d, %esi
movl 0x44(%rsp), %edx
movq %rbx, %r8
movq 0x70(%rsp), %r9
callq 0x1f20e3
movq %rax, %r14
movq 0x68(%rsp), %rax
testq %rax, %rax
je 0x1f2624
movq 0x10(%rax), %rax
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
movl 0x10(%rax,%rcx,8), %ebp
jmp 0x1f2629
movl $0x1, %ebp
addq 0x78(%rsp), %rbp
addq 0x80(%rsp), %r14
movl 0x1c(%r12), %eax
testl %eax, %eax
movq 0x18(%rsp), %r8
movq 0x38(%rsp), %r9
js 0x1f26fb
movq 0x50(%rbx), %rax
cmpq %rax, 0x48(%rbx)
jne 0x1f2686
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x50(%rbx)
movq 0x58(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x38(%rsp), %r9
movq 0x18(%rsp), %r8
movq %rax, 0x58(%rbx)
movq 0x48(%rbx), %rax
movq 0x58(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x48(%rbx)
movl %r9d, (%rcx,%rax,4)
movq 0x28(%rsp), %rax
movl %eax, (%r12)
orb $-0x80, 0x1f(%r12)
movq 0x50(%rsp), %rax
addl 0x24(%rsp), %eax
movl %eax, 0x4(%r12)
movq 0x28(%r8), %rax
movq (%rax,%r13,8), %rcx
movq %rcx, %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rdx
je 0x1f273d
shrq $0x20, %rcx
movq 0x8(%r8), %rsi
xorl %eax, %eax
movq 0x30(%rsp), %r13
movl %ecx, %edi
leaq (%rdi,%rdi,2), %rdi
movl 0xc(%rsi,%rdi,8), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %eax
incq %rcx
decq %rdx
jne 0x1f26db
orl $0x80000000, %eax       # imm = 0x80000000
jmp 0x1f2747
movq 0x88(%rbx), %rcx
movl (%r12), %edx
shrl %edx
movb (%rcx,%rdx), %dl
movq 0x58(%rsp), %rsi
cmpb (%rcx,%rsi), %dl
jne 0x1f2760
xorl %ecx, %ecx
cmpq 0x8(%r12), %r14
seta %cl
movq 0x30(%rsp), %r13
movq 0x10(%rsp), %rsi
jne 0x1f2771
movl 0x18(%r12), %edx
cmpq %rdx, %rbp
movl $0x1, %edx
cmoval %edx, %ecx
jmp 0x1f2771
movl $0x80000000, %eax       # imm = 0x80000000
movq 0x30(%rsp), %r13
movl %eax, 0x1c(%r12)
movl %ebp, 0x18(%r12)
movq %r14, 0x8(%r12)
incl %r13d
movq 0x10(%rsp), %rsi
jmp 0x1f279b
xorl %ecx, %ecx
testb %dl, %dl
setne %cl
movq 0x30(%rsp), %r13
movq 0x10(%rsp), %rsi
testl %ecx, %ecx
je 0x1f279b
movq 0x28(%rsp), %rcx
movl %ecx, (%r12)
movl %eax, 0x1c(%r12)
movq 0x50(%rsp), %rax
addl 0x24(%rsp), %eax
movl %eax, 0x4(%r12)
movl %ebp, 0x18(%r12)
movq %r14, 0x8(%r12)
movl 0x1c(%r12), %eax
leal -0x1(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %eax       # imm = 0x80000000
orl %ecx, %eax
movl %eax, 0x1c(%r12)
testl %ecx, %ecx
je 0x1f27c8
movq 0x28(%rsp), %r14
movq 0x48(%rsp), %r12
jmp 0x1f2877
movq 0x28(%r8), %rax
movq (%rax,%r9,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
movq 0x28(%rsp), %r14
movq 0x48(%rsp), %r12
je 0x1f2865
shrq $0x20, %rax
movq 0x8(%r8), %rsi
xorl %edx, %edx
movl %eax, %edi
leaq (%rdi,%rdi,2), %rdi
movl 0xc(%rsi,%rdi,8), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %edx
incq %rax
decq %rcx
jne 0x1f27f1
testl %edx, %edx
movq 0x10(%rsp), %rsi
je 0x1f2865
movq 0x20(%rbx), %rax
cmpq %rax, 0x18(%rbx)
jne 0x1f2851
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x20(%rbx)
movq 0x28(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x38(%rsp), %r9
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %r8
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
movq 0x28(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x18(%rbx)
movl %r9d, (%rcx,%rax,4)
decl %r13d
cmpl 0xc0(%rsp), %r9d
jne 0x1f2877
testl %r13d, %r13d
je 0x1f2890
incq %r15
cmpq %rsi, %r15
jne 0x1f253d
movq 0x18(%rbx), %rax
testq %rax, %rax
jne 0x1f24b8
movq %rbx, %rdi
movq 0xc8(%rsp), %rdx
movl 0x40(%rsp), %ecx
movl 0xc0(%rsp), %r8d
callq 0x1f2243
cmpq $0x0, 0x48(%rbx)
je 0x1f28e6
movl $0x1, %eax
xorl %edx, %edx
xorps %xmm0, %xmm0
movl $0x1, %ecx
movq 0x10(%rbx), %rsi
movq 0x58(%rbx), %rdi
movl (%rdi,%rdx,4), %edx
shlq $0x5, %rdx
movups %xmm0, 0x10(%rsi,%rdx)
movups %xmm0, (%rsi,%rdx)
movl %ecx, %edx
incl %ecx
cmpq %rdx, 0x48(%rbx)
ja 0x1f28c2
jmp 0x1f28eb
movl $0x1, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq