// File: /workspace/github_cpp_makefile_star2_O3/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, 0x68(%rsp)
movq %rcx, %rbx
movq %rdx, 0x60(%rsp)
movq %rdi, 0x58(%rsp)
movq 0x20(%rsi), %rcx
movl %r9d, %edx
shrl %edx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx,8)
js 0x1fde2b
movl 0xc0(%rsp), %edx
shrl %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0x1fde2b
movl %r9d, %ebp
movq %rbx, %rdi
movq %rsi, 0x18(%rsp)
movl $0x1, %ecx
callq 0x1fbce4
movq 0x10(%rbx), %rax
movl %ebp, %ecx
shlq $0x5, %rcx
movl $0xffffffff, (%rax,%rcx) # imm = 0xFFFFFFFF
movq 0x18(%rbx), %rdx
cmpq 0x20(%rbx), %rdx
jne 0x1fda18
leaq (%rdx,%rdx), %rax
testq %rdx, %rdx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x20(%rbx)
movq 0x28(%rbx), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rdx
jmp 0x1fda1c
movq 0x28(%rbx), %rax
movq %rdx, %rcx
incq %rcx
movq %rcx, 0x18(%rbx)
movl %ebp, 0x38(%rsp)
movl %ebp, (%rax,%rdx,4)
movq 0x18(%rsp), %r8
je 0x1fddd0
xorl %r14d, %r14d
movq %rcx, %rax
movq 0x10(%rbx), %rdx
movq 0x28(%rbx), %rsi
decq %rcx
movq %rcx, 0x18(%rbx)
movl -0x4(%rsi,%rax,4), %r13d
movq 0x28(%r8), %rax
movq (%rax,%r13,8), %rax
testl %eax, %eax
je 0x1fddc7
movq %r13, %rcx
shlq $0x5, %rcx
movl 0x4(%rdx,%rcx), %esi
movl %esi, 0x2c(%rsp)
movq 0x8(%rdx,%rcx), %rsi
movq %rsi, 0x78(%rsp)
movl 0x18(%rdx,%rcx), %ecx
movq %rcx, 0x70(%rsp)
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r12
shlq $0x3, %r12
addq 0x8(%r8), %r12
movl %r13d, %ecx
xorl $0x1, %ecx
movl %ecx, 0x3c(%rsp)
movl %r13d, %ecx
shrl %ecx
movq %rcx, 0x50(%rsp)
movl %eax, %eax
movq %rax, 0x80(%rsp)
xorl %r15d, %r15d
movq %r13, 0x10(%rsp)
movq %r12, 0x40(%rsp)
leaq (%r15,%r15,2), %rax
cmpl $0x0, 0xc(%r12,%rax,8)
js 0x1fddb2
leaq (%r12,%rax,8), %rax
movq 0x20(%r8), %rcx
movl 0x8(%rax), %r9d
movl %r9d, %ebp
shrl %ebp
cmpl $0x0, (%rcx,%rbp,8)
js 0x1fddb2
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq %r9, %r12
shlq $0x5, %r12
addq 0x10(%rbx), %r12
movq 0x60(%rbx), %rcx
movq 0x70(%rbx), %rax
cmpq 0x68(%rbx), %rcx
movq %r14, 0x20(%rsp)
jne 0x1fdb46
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x68(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r9, %r14
callq 0x2370
movq %r14, %r9
movq 0x18(%rsp), %r8
movq %rax, 0x70(%rbx)
movq 0x60(%rbx), %rcx
movq 0x28(%r8), %rdx
movl 0x4(%rdx,%r13,8), %edx
addl %r15d, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x60(%rbx)
movl %edx, (%rax,%rcx,4)
movq %r9, 0x30(%rsp)
movq %r9, %r13
xorq $0x1, %r13
movq %r8, (%rsp)
movq 0x58(%rsp), %rdi
movl %r13d, %esi
movl 0x3c(%rsp), %edx
movq %rbx, %r8
movq 0x68(%rsp), %r9
callq 0x1fd66d
movq %rax, %r14
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x1fdba8
movq 0x10(%rax), %rax
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
movl 0x10(%rax,%rcx,8), %ebp
jmp 0x1fdbad
movl $0x1, %ebp
addq 0x70(%rsp), %rbp
addq 0x78(%rsp), %r14
movl 0x1c(%r12), %eax
testl %eax, %eax
movq 0x18(%rsp), %r8
movq 0x30(%rsp), %r9
js 0x1fdc76
movq 0x48(%rbx), %rcx
movq 0x58(%rbx), %rax
cmpq 0x50(%rbx), %rcx
jne 0x1fdc0e
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x50(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %r8
movq %rax, 0x58(%rbx)
movq 0x48(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x48(%rbx)
movl %r9d, (%rax,%rcx,4)
movq 0x10(%rsp), %rax
movl %eax, (%r12)
orb $-0x80, 0x1f(%r12)
movq 0x48(%rsp), %rax
addl 0x2c(%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 0x1fdca8
shrq $0x20, %rcx
movq 0x8(%r8), %rsi
xorl %eax, %eax
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 0x1fdc56
orl $0x80000000, %eax       # imm = 0x80000000
jmp 0x1fdcad
movq 0x88(%rbx), %rdx
movl (%r12), %ecx
shrl %ecx
movb (%rdx,%rcx), %cl
movq 0x50(%rsp), %rsi
cmpb (%rdx,%rsi), %cl
jne 0x1fdcc6
cmpq 0x8(%r12), %r14
movq 0x10(%rsp), %r13
jne 0x1fdca4
movl 0x18(%r12), %ecx
cmpq %rcx, %rbp
ja 0x1fdccf
jmp 0x1fdceb
movl $0x80000000, %eax       # imm = 0x80000000
movq 0x10(%rsp), %r13
movl %ebp, 0x18(%r12)
movq %r14, 0x8(%r12)
movq 0x20(%rsp), %r14
incl %r14d
jmp 0x1fdcf0
testb %cl, %cl
movq 0x10(%rsp), %r13
je 0x1fdceb
movl %r13d, (%r12)
movq 0x48(%rsp), %rcx
addl 0x2c(%rsp), %ecx
movl %ecx, 0x4(%r12)
movl %ebp, 0x18(%r12)
movq %r14, 0x8(%r12)
movq 0x20(%rsp), %r14
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 0x1fdd13
movq 0x40(%rsp), %r12
jmp 0x1fddb2
movq 0x28(%r8), %rax
movq (%rax,%r9,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
movq 0x40(%rsp), %r12
je 0x1fdda0
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 0x1fdd37
testl %edx, %edx
je 0x1fdda0
movq 0x18(%rbx), %rcx
movq 0x28(%rbx), %rax
cmpq 0x20(%rbx), %rcx
jne 0x1fdd94
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x20(%rbx)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %r8
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x18(%rbx)
movl %r9d, (%rax,%rcx,4)
decl %r14d
cmpl 0xc0(%rsp), %r9d
jne 0x1fddb2
testl %r14d, %r14d
je 0x1fddd0
incq %r15
cmpq 0x80(%rsp), %r15
jne 0x1fdac2
movq 0x18(%rbx), %rcx
testq %rcx, %rcx
jne 0x1fda3b
movq %rbx, %rdi
movq 0xc8(%rsp), %rdx
movl 0x38(%rsp), %ecx
movl 0xc0(%rsp), %r8d
callq 0x1fd7cd
cmpq $0x0, 0x48(%rbx)
je 0x1fde26
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 0x1fde02
jmp 0x1fde2b
movl $0x1, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq