// File: chhylp123[P]hifiasm/hic.cpp
// Function: select_bmer(unsigned int, unsigned long, bubble_type const*, min_cut_t*, unsigned int)
uint64_t select_bmer(uint32_t src, uint64_t k, const bubble_type* bub, min_cut_t* x, uint32_t bub_only)
{
    uint32_t beg, sink, n, *a;
    uint32_t v, d, u, i, nv, b_mer_d, j;
    asg_t *sg = bub->ug->g;
    uint64_t *p = NULL;
    asg_arc_t *av = NULL;

    memset(x->rGraphVis.a, 0, x->rGraphVis.n);
    kdq_push(uint64_t, x->q, set_dv(src , 0));
    b_mer_d = 0; 

    x->rGraphVis.a[src] = 1;
    x->bmerVis.a[src] = 1;

    while (1)
    {
        p = kdq_shift(uint64_t, x->q);
        if(!p) break;
        v = (uint32_t)(*p); d = ((uint64_t)(*p))>>32;

        v = v<<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>>1;
            if(x->rGraphVis.a[u]) continue;
            x->rGraphVis.a[u] = 1;
            if(IF_HOM(u, *bub))
            {
                if(d < k) kdq_push(uint64_t, x->q, set_dv(u, d+1));
            }
            else
            {
                kdq_push(uint64_t, x->q, set_dv(u , d));
                b_mer_d = d;
                if(IF_BUB(u, *bub) && x->bmerVis.a[u] == 0)
                {
                    get_bubbles((bubble_type*)bub, bub->index[u], &beg, &sink, &a, &n, NULL);
                    for (j = 0; j < n; j++) x->bmerVis.a[(a[j]>>1)] = 1;
                }
                //must be here
                if(bub_only == 0) x->bmerVis.a[u] = 1;
            }            
        }


        v = v + 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>>1;
            if(x->rGraphVis.a[u]) continue;
            x->rGraphVis.a[u] = 1;
            if(IF_HOM(u, *bub))
            {
                if(d < k) kdq_push(uint64_t, x->q, set_dv(u, d+1));
            }
            else
            {
                kdq_push(uint64_t, x->q, set_dv(u , d));
                b_mer_d = d;
                if(IF_BUB(u, *bub) && x->bmerVis.a[u] == 0)
                {
                    get_bubbles((bubble_type*)bub, bub->index[u], &beg, &sink, &a, &n, NULL);
                    for (j = 0; j < n; j++) x->bmerVis.a[(a[j]>>1)] = 1;
                }
                //must be here
                if(bub_only == 0) x->bmerVis.a[u] = 1;
            }            
        }
    }

    return b_mer_d;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq 0xc0(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0xb0(%rax), %rdx
xorl %esi, %esi
callq 0x2100
movq -0x20(%rbp), %rax
movq 0xf8(%rax), %rax
movq %rax, -0x78(%rbp)
movl -0x4(%rbp), %eax
movl %eax, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x214660
movq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x1d7cb0
movl $0x0, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq 0xc0(%rax), %rax
movl -0x4(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movl -0x4(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq 0xf8(%rax), %rdi
callq 0x1d7d50
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x1d8f0f
jmp 0x1d9361
movq -0x68(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x3c(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
shll %eax
movl %eax, -0x3c(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x1d913e
movq -0x70(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1d8f98
jmp 0x1d9130
movq -0x70(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq 0xc0(%rax), %rax
movl -0x44(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x1d8fc7
jmp 0x1d9130
movq -0x20(%rbp), %rax
movq 0xc0(%rax), %rax
movl -0x44(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1d9037
movl -0x40(%rbp), %eax
cmpq -0x10(%rbp), %rax
jae 0x1d9032
movq -0x20(%rbp), %rax
movq 0xf8(%rax), %rax
movq %rax, -0x80(%rbp)
movl -0x44(%rbp), %eax
movl %eax, %edi
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x214660
movq -0x80(%rbp), %rdi
movq %rax, %rsi
callq 0x1d7cb0
jmp 0x1d912e
movq -0x20(%rbp), %rax
movq 0xf8(%rax), %rax
movq %rax, -0x88(%rbp)
movl -0x44(%rbp), %eax
movl %eax, %edi
movl -0x40(%rbp), %eax
movl %eax, %esi
callq 0x214660
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x1d7cb0
movl -0x40(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x1d9114
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movl -0x44(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1d9114
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x38(%rbp), %r8
leaq -0x30(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x1d9112
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x38(%rbp), %rcx
movl -0x54(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1d90e2
jmp 0x1d9114
cmpl $0x0, -0x24(%rbp)
jne 0x1d912c
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movl -0x44(%rbp), %ecx
movb $0x1, (%rax,%rcx)
jmp 0x1d912e
jmp 0x1d9130
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1d8f6e
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x60(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x1d935c
movq -0x70(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1d91b0
jmp 0x1d934e
movq -0x70(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq 0xc0(%rax), %rax
movl -0x44(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x1d91df
jmp 0x1d934e
movq -0x20(%rbp), %rax
movq 0xc0(%rax), %rax
movl -0x44(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1d9255
movl -0x40(%rbp), %eax
cmpq -0x10(%rbp), %rax
jae 0x1d9250
movq -0x20(%rbp), %rax
movq 0xf8(%rax), %rax
movq %rax, -0x90(%rbp)
movl -0x44(%rbp), %eax
movl %eax, %edi
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x214660
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x1d7cb0
jmp 0x1d934c
movq -0x20(%rbp), %rax
movq 0xf8(%rax), %rax
movq %rax, -0x98(%rbp)
movl -0x44(%rbp), %eax
movl %eax, %edi
movl -0x40(%rbp), %eax
movl %eax, %esi
callq 0x214660
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x1d7cb0
movl -0x40(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x1d9332
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movl -0x44(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1d9332
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x38(%rbp), %r8
leaq -0x30(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x1c4b20
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x1d9330
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movq -0x38(%rbp), %rcx
movl -0x54(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1d9300
jmp 0x1d9332
cmpl $0x0, -0x24(%rbp)
jne 0x1d934a
movq -0x20(%rbp), %rax
movq 0xf0(%rax), %rax
movl -0x44(%rbp), %ecx
movb $0x1, (%rax,%rcx)
jmp 0x1d934c
jmp 0x1d934e
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1d9186
jmp 0x1d8eef
movl -0x50(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)