// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movl %r9d, 0x1c(%rsp)
movl %r8d, 0x20(%rsp)
movq %rcx, %r14
movq %rsi, 0x40(%rsp)
movl %edi, %ebx
movq %rdx, 0x10(%rsp)
movq 0x10(%rdx), %rax
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x30(%rcx), %r15
movq %r15, %rdi
callq 0xfa62b
movq 0xf0(%r14), %rax
movl %ebx, %esi
shrl %ebx
movb $0x1, (%rax,%rbx)
movq 0x70(%r14), %rax
andq $0x0, (%rax,%rsi,8)
movq %r15, 0x28(%rsp)
movq %r15, %rdi
xorl %edx, %edx
callq 0xfa671
xorl %r12d, %r12d
movq %r14, 0x48(%rsp)
movq 0x58(%r14), %rax
cmpq $0x0, (%rax)
je 0x101638
movq 0x28(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0xfa734
movq 0x40(%r14), %rax
movq 0x50(%rsp), %rdi
movb $0x1, (%rax,%rdi)
movq 0x70(%r14), %rax
movq 0x40(%rsp), %rcx
cmpq %rcx, (%rax,%rdi,8)
ja 0x101638
movq %rdi, %r15
shrq %r15
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movq 0x80(%rax), %rax
movl (%rcx,%r15,4), %esi
incq %rax
cmpq %rsi, %rax
jbe 0x101585
movq 0xf0(%r14), %rax
cmpl $0x0, 0x1c(%rsp)
je 0x10156a
cmpb $0x0, (%rax,%r15)
jne 0x10156a
movq %rdi, %rbx
andq $0x0, (%rsp)
movq 0x10(%rsp), %rdi
leaq 0x64(%rsp), %rdx
leaq 0x60(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x24(%rsp), %r9
callq 0xf6ab5
xorl %ecx, %ecx
movl 0x24(%rsp), %edx
movq 0xf0(%r14), %rax
cmpq %rdx, %rcx
jae 0x101567
movq 0x58(%rsp), %rdx
movl (%rdx,%rcx,4), %edx
shrl %edx
movb $0x1, (%rax,%rdx)
incq %rcx
jmp 0x101544
movq %rbx, %rdi
movb $0x1, (%rax,%r15)
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movq 0x80(%rax), %rax
movl (%rcx,%r15,4), %esi
incq %rax
cmpl $0x0, 0x20(%rsp)
jne 0x10159d
cmpq %rsi, %rax
jne 0x10159d
movq 0xf0(%r14), %rax
movb $0x1, (%rax,%r15)
movq 0x38(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%rdi,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
movq 0x30(%rsp), %r15
imulq $0x18, %rdx, %r13
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %rbx
addq $0xc, %rbx
xorl %ebp, %ebp
xorl %ecx, %ecx
cmpq %rbp, %r13
je 0x10162b
cmpl $0x0, (%rbx,%rbp)
js 0x101625
movl -0xc(%rbx,%rbp), %r15d
testb $0x1, %r12b
cmoveq %rcx, %r15
movl -0x4(%rbx,%rbp), %esi
movq 0x40(%r14), %rax
cmpb $0x0, (%rax,%rsi)
jne 0x101625
movq 0x70(%r14), %rax
movq (%rax,%rdi,8), %rdx
addq %r15, %rdx
cmpq %rdx, (%rax,%rsi,8)
jbe 0x101625
movq %rdx, (%rax,%rsi,8)
movq %r12, %r14
movq %rdi, %r12
movq 0x28(%rsp), %rdi
callq 0xfa671
movq %r12, %rdi
movq %r14, %r12
movq 0x48(%rsp), %r14
xorl %ecx, %ecx
addq $0x18, %rbp
jmp 0x1015cd
movq %r15, 0x30(%rsp)
movb $0x1, %r12b
jmp 0x1014a4
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq