// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: select_bmer_distance(unsigned int, unsigned long, bubble_type const*, min_cut_t*, unsigned int, unsigned int)
void select_bmer_distance(uint32_t src, uint64_t k, const bubble_type* bub, min_cut_t* x, 
uint32_t bub_only, uint32_t bub_extend)
{
    uint32_t beg, sink, n, *a;
    asg_t *sg = bub->ug->g;
    uint64_t v, u, i, j, nv, w, first = 1;
    asg_arc_t *av = NULL;
    reset_pdq(&(x->pq));

    x->bmerVis.a[src>>1] = 1;
    x->pq.dis.a[src] = 0;
    push_pdq(&(x->pq), src, 0);

    while (pdq_cnt(x->pq) > 0)
    {
        pop_pdq(&(x->pq), &v, &w);
        x->pq.vis.a[v] = 1;
        if(x->pq.dis.a[v] > k) break;

        ///fprintf(stderr, "******utg%.6dl, dis: %lu\n", (int)((v>>1)+1), x->pq.dis.a[v]); 

        if(IF_BUB(v>>1, *bub))
        {
            if(bub_extend && x->bmerVis.a[v>>1] == 0)
            {
                get_bubbles((bubble_type*)bub, bub->index[v>>1], &beg, &sink, &a, &n, NULL);
                for (j = 0; j < n; j++) x->bmerVis.a[(a[j]>>1)] = 1;
            }
            x->bmerVis.a[v>>1] = 1;
        }
         
        if(IF_HET(v>>1, *bub) && bub_only == 0) x->bmerVis.a[v>>1] = 1;

        av = asg_arc_a(sg, v);
        nv = asg_arc_n(sg, v);
        for (i = 0; i < nv; i++)
        {
            if(av[i].del) continue;
            u = av[i].v;
            w = (uint32_t)av[i].ul;
            if(first) w = 0;

            if(x->pq.vis.a[u] == 0 && x->pq.dis.a[u] > x->pq.dis.a[v] + w)
            {
                x->pq.dis.a[u] = x->pq.dis.a[v] + w;
                push_pdq(&(x->pq), u, x->pq.dis.a[u]);
            }
        }

        first = 0;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, 0x8(%rsp)
movl %r8d, 0xc(%rsp)
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, 0x30(%rsp)
movl %edi, %ebx
movq 0x10(%rdx), %rax
movq 0x18(%rax), %rbp
leaq 0x30(%rcx), %r12
movq $0x1, 0x48(%rcx)
movq 0x58(%rcx), %rax
xorl %r15d, %r15d
movq %r15, (%rax)
movq 0x60(%rcx), %rdx
movq 0x70(%rcx), %rdi
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x20e0
movq 0x30(%r14), %rdx
movq 0x40(%r14), %rdi
xorl %esi, %esi
callq 0x20e0
movq 0xf0(%r14), %rax
movl %ebx, %esi
shrl %ebx
movb $0x1, (%rax,%rbx)
movq 0x70(%r14), %rax
movq %r15, (%rax,%rsi,8)
movq %r12, 0x10(%rsp)
movq %r12, %rdi
xorl %edx, %edx
callq 0x13bc89
movq 0x58(%r14), %rax
cmpq %r15, (%rax)
je 0x142e52
xorl %r12d, %r12d
movq %rbp, 0x20(%rsp)
movq %r13, 0x28(%rsp)
movq %r14, 0x38(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x13bd51
movq 0x40(%r14), %rax
movq 0x40(%rsp), %r9
movb $0x1, (%rax,%r9)
movq 0x70(%r14), %rax
movq 0x30(%rsp), %rcx
cmpq %rcx, (%rax,%r9,8)
ja 0x142e52
movq %r9, %rax
shrq %rax
movq (%r13), %rcx
movq 0x80(%r13), %rdx
movl (%rcx,%rax,4), %ecx
incq %rdx
cmpq %rcx, %rdx
jbe 0x142d74
cmpl $0x0, 0x8(%rsp)
je 0x142d69
movq 0xf0(%r14), %rdx
cmpb $0x0, (%rdx,%rax)
jne 0x142d69
movq 0x40(%r13), %rsi
movl (%rsi,%rcx,4), %edx
movl 0x4(%rsi,%rcx,4), %ecx
subl %edx, %ecx
addl $-0x2, %ecx
je 0x142d69
movq 0x28(%r13), %rsi
leaq (%rsi,%rdx,4), %rdx
addq $0x8, %rdx
xorl %esi, %esi
movq 0xf0(%r14), %rdi
movl (%rdx,%rsi,4), %r8d
shrl %r8d
movb $0x1, (%rdi,%r8)
incq %rsi
cmpq %rsi, %rcx
jne 0x142d4e
movq 0xf0(%r14), %rcx
movb $0x1, (%rcx,%rax)
cmpl $0x0, 0xc(%rsp)
jne 0x142d9c
movq (%r13), %rcx
movq 0x80(%r13), %rdx
incq %rdx
movl (%rcx,%rax,4), %ecx
cmpq %rcx, %rdx
jne 0x142d9c
movq 0xf0(%r14), %rcx
movb $0x1, (%rcx,%rax)
movq 0x28(%rbp), %rax
movq (%rax,%r9,8), %rax
movq %rax, %rcx
movq 0x18(%rsp), %r13
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x142e32
movq 0x8(%rbp), %rdx
shrq $0x20, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r15
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rbx
addq $0xc, %rbx
xorl %ebp, %ebp
xorl %ecx, %ecx
cmpl $0x0, (%rbx,%rbp)
js 0x142e29
movl -0xc(%rbx,%rbp), %r13d
testb $0x1, %r12b
cmoveq %rcx, %r13
movl -0x4(%rbx,%rbp), %esi
movq 0x40(%r14), %rax
cmpb $0x0, (%rax,%rsi)
jne 0x142e29
movq 0x70(%r14), %rax
movq (%rax,%r9,8), %rdx
addq %r13, %rdx
cmpq %rdx, (%rax,%rsi,8)
jbe 0x142e29
movq %rdx, (%rax,%rsi,8)
movq 0x10(%rsp), %rdi
movq %r12, %r14
movq %r9, %r12
callq 0x13bc89
movq %r12, %r9
movq %r14, %r12
movq 0x38(%rsp), %r14
xorl %ecx, %ecx
addq $0x18, %rbp
cmpq %rbp, %r15
jne 0x142dd6
movq %r13, 0x18(%rsp)
movq 0x58(%r14), %rax
movb $0x1, %r12b
cmpq $0x0, (%rax)
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %rbp
jne 0x142cc9
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq