// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq $0x1, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
callq 0x1cbba0
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movl -0x4(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movl -0x4(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
movl -0x4(%rbp), %eax
movl %eax, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x1cbc50
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
cmpq $0x0, (%rax)
jbe 0x1d96c5
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
leaq -0x50(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x1cbe10
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x50(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x10(%rbp), %rax
jbe 0x1d9453
jmp 0x1d96c5
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x50(%rbp), %rcx
shrq %rcx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x1d952f
cmpl $0x0, -0x28(%rbp)
je 0x1d9519
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x50(%rbp), %rcx
shrq %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1d9519
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x50(%rbp), %rcx
shrq %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %esi
leaq -0x2c(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x34(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl -0x34(%rbp), %ecx
cmpq %rcx, %rax
jae 0x1d9517
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x40(%rbp), %rcx
movq -0x68(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x1d94df
jmp 0x1d9519
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x50(%rbp), %rcx
shrq %rcx
movb $0x1, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x50(%rbp), %rcx
shrq %rcx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x1d9570
cmpl $0x0, -0x24(%rbp)
jne 0x1d9570
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x50(%rbp), %rcx
shrq %rcx
movb $0x1, (%rax,%rcx)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x70(%rbp), %rax
jae 0x1d96b8
movq -0x88(%rbp), %rax
imulq $0x18, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1d95e5
jmp 0x1d96a7
movq -0x88(%rbp), %rax
imulq $0x18, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq %rax, -0x58(%rbp)
movq -0x88(%rbp), %rax
imulq $0x18, -0x60(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, %eax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0x1d9622
movq $0x0, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x58(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1d96a5
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x20(%rbp), %rcx
movq 0x70(%rcx), %rcx
movq -0x50(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
addq -0x78(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x1d96a5
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq -0x78(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x58(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
movq -0x58(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
callq 0x1cbc50
jmp 0x1d96a7
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x1d95b8
movq $0x0, -0x80(%rbp)
jmp 0x1d9401
addq $0x90, %rsp
popq %rbp
retq
nop