// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x325f9c
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl 0x10(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x325fa8
movl $0x0, -0x4(%rbp)
jmp 0x3266f2
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movl $0x1, %ecx
callq 0x322ba0
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jne 0x326048
movq -0x28(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x326007
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
shlq %rax
movq %rax, -0x98(%rbp)
jmp 0x326015
movl $0x2, %eax
movq %rax, -0x98(%rbp)
jmp 0x326015
movq -0x98(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movl -0x34(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x28(%rbp), %rsi
movq 0x18(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x18(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x32606b
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jbe 0x32667b
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x28(%rbp), %rdx
movq 0x18(%rdx), %rcx
movq %rcx, %rsi
addq $-0x1, %rsi
movq %rsi, 0x18(%rdx)
movl -0x4(%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x38(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x326676
movq -0x88(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x32617d
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x88(%rbp), %rcx
movl -0x40(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x326182
jmp 0x326668
movq -0x88(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x88(%rbp), %rax
movl -0x40(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x44(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x28(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x68(%rcx), %rax
jne 0x32623e
movq -0x28(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x3261fd
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
shlq %rax
movq %rax, -0xa0(%rbp)
jmp 0x32620b
movl $0x2, %eax
movq %rax, -0xa0(%rbp)
jmp 0x32620b
movq -0xa0(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x28(%rbp), %rax
movq 0x70(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl -0x40(%rbp), %ecx
addq %rcx, %rax
movl %eax, %edx
movq -0x28(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x28(%rbp), %rsi
movq 0x60(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x60(%rsi)
movl %edx, (%rax,%rcx,4)
movq -0x68(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
xorl $0x1, %esi
movl -0x38(%rbp), %edx
xorl $0x1, %edx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
movq -0x18(%rbp), %rax
movq %rax, (%rsp)
callq 0x325a70
movq %rax, %rcx
movq -0xb0(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0xa8(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3262f3
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x44(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0xb4(%rbp)
jmp 0x326300
movl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x326300
movq -0xa8(%rbp), %rax
movl -0xb4(%rbp), %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x90(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x326459
jmp 0x32632e
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jne 0x3263a0
movq -0x28(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x32635f
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
shlq %rax
movq %rax, -0xc0(%rbp)
jmp 0x32636d
movl $0x2, %eax
movq %rax, -0xc0(%rbp)
jmp 0x32636d
movq -0xc0(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x58(%rax)
movl -0x44(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x28(%rbp), %rsi
movq 0x48(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x48(%rsi)
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %ecx
movq -0x90(%rbp), %rax
movl %ecx, (%rax)
movq -0x90(%rbp), %rax
movl 0x1c(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x1c(%rax)
movq -0x60(%rbp), %rax
addq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x90(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rdi
movl -0x44(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311ba0
movl %eax, %edx
movq -0x90(%rbp), %rax
movl 0x1c(%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, 0x1c(%rax)
movq -0x80(%rbp), %rax
movl %eax, %ecx
movq -0x90(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x70(%rbp), %rcx
movq -0x90(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x32656b
movl $0x0, -0x4c(%rbp)
movq -0x28(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x90(%rbp), %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movq -0x28(%rbp), %rcx
movq 0x88(%rcx), %rcx
movl -0x38(%rbp), %edx
shrl %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x3264db
movq -0x70(%rbp), %rax
movq -0x90(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x3264ae
movl $0x1, -0x4c(%rbp)
movq -0x70(%rbp), %rax
movq -0x90(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x3264d9
movq -0x80(%rbp), %rax
movq -0x90(%rbp), %rcx
movl 0x18(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x3264d9
movl $0x1, -0x4c(%rbp)
jmp 0x32650b
movq -0x28(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x90(%rbp), %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
cmpb $0x0, (%rax,%rcx)
je 0x326502
movl $0x1, -0x4c(%rbp)
jmp 0x326509
movl $0x0, -0x4c(%rbp)
jmp 0x32650b
cmpl $0x0, -0x4c(%rbp)
je 0x326569
movl -0x38(%rbp), %ecx
movq -0x90(%rbp), %rax
movl %ecx, (%rax)
movq -0x90(%rbp), %rax
movl 0x1c(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x1c(%rax)
movq -0x60(%rbp), %rax
addq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x90(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x80(%rbp), %rax
movl %eax, %ecx
movq -0x90(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x70(%rbp), %rcx
movq -0x90(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x32656b
movq -0x90(%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 0x326666
movq -0x18(%rbp), %rdi
movl -0x44(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311ba0
cmpl $0x0, %eax
jbe 0x32664b
jmp 0x3265b6
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jne 0x326628
movq -0x28(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x3265e7
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
shlq %rax
movq %rax, -0xc8(%rbp)
jmp 0x3265f5
movl $0x2, %eax
movq %rax, -0xc8(%rbp)
jmp 0x3265f5
movq -0xc8(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movl -0x44(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x28(%rbp), %rsi
movq 0x18(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x18(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x32664b
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpl 0x10(%rbp), %eax
jne 0x326664
cmpl $0x0, -0x48(%rbp)
jne 0x326664
jmp 0x32667d
jmp 0x326666
jmp 0x326668
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x32612a
jmp 0x32606b
jmp 0x32667d
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq 0x18(%rbp), %rdx
movl -0x34(%rbp), %ecx
movl 0x10(%rbp), %r8d
callq 0x325c30
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x3266eb
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x58(%rcx), %rcx
movl -0x40(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x32669c
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nop