// File: /workspace/github_cpp_makefile_star2_O3/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, 0x10(%rsp)
movl %r8d, 0x14(%rsp)
movq %rcx, %r14
movq %rsi, 0x30(%rsp)
movl %edi, %ebx
movq %rdx, 0x8(%rsp)
movq 0x10(%rdx), %rax
movq 0x18(%rax), %r13
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, 0x18(%rsp)
movq %r12, %rdi
xorl %edx, %edx
callq 0x141a86
movq 0x58(%r14), %rax
cmpq %r15, (%rax)
je 0x149439
xorl %r12d, %r12d
movq %r13, 0x28(%rsp)
movq %r14, 0x38(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x141b50
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 0x149439
movq %r9, %rax
shrq %rax
movq 0x8(%rsp), %rdx
movq (%rdx), %rcx
movq 0x80(%rdx), %rdx
movl (%rcx,%rax,4), %ecx
incq %rdx
cmpq %rcx, %rdx
jbe 0x149371
movq 0xf0(%r14), %rdx
cmpl $0x0, 0x10(%rsp)
je 0x149358
cmpb $0x0, (%rdx,%rax)
jne 0x149358
movq 0x8(%rsp), %rsi
movq 0x40(%rsi), %rdi
movl (%rdi,%rcx,4), %esi
movl 0x4(%rdi,%rcx,4), %ecx
subl %esi, %ecx
addl $-0x2, %ecx
je 0x149358
movq 0x8(%rsp), %rdx
movq 0x28(%rdx), %rdx
leaq (%rdx,%rsi,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 0x149336
movq 0xf0(%r14), %rdx
movb $0x1, (%rdx,%rax)
movq 0x8(%rsp), %rdx
movq (%rdx), %rcx
movq 0x80(%rdx), %rdx
movl (%rcx,%rax,4), %ecx
incq %rdx
cmpl $0x0, 0x14(%rsp)
jne 0x149388
cmpq %rcx, %rdx
jne 0x149388
movq 0xf0(%r14), %rcx
movb $0x1, (%rcx,%rax)
movq 0x28(%r13), %rax
movq (%rax,%r9,8), %rax
movq %rax, %rcx
movq 0x20(%rsp), %r15
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x14941e
movq 0x8(%r13), %rdx
shrq $0x20, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r13
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rbx
addq $0xc, %rbx
xorl %ebp, %ebp
xorl %ecx, %ecx
cmpl $0x0, (%rbx,%rbp)
js 0x149415
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 0x149415
movq 0x70(%r14), %rax
movq (%rax,%r9,8), %rdx
addq %r15, %rdx
cmpq %rdx, (%rax,%rsi,8)
jbe 0x149415
movq %rdx, (%rax,%rsi,8)
movq 0x18(%rsp), %rdi
movq %r12, %r14
movq %r9, %r12
callq 0x141a86
movq %r12, %r9
movq %r14, %r12
movq 0x38(%rsp), %r14
xorl %ecx, %ecx
addq $0x18, %rbp
cmpq %rbp, %r13
jne 0x1493c2
movq %r15, 0x20(%rsp)
movq 0x58(%r14), %rax
movb $0x1, %r12b
cmpq $0x0, (%rax)
movq 0x28(%rsp), %r13
jne 0x1492a3
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq