// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: ulg_pop_bubble(ul_resolve_t*, ma_ug_t*, unsigned long*, unsigned int, unsigned int, unsigned int, asg64_v*, asg64_v*)
uint64_t ulg_pop_bubble(ul_resolve_t *uidx, ma_ug_t *ug, uint64_t* i_max_dist, uint32_t max_ext, uint32_t max_ext_hifi, uint32_t skip_hom, asg64_v *in, asg64_v *ib)
{
    // fprintf(stderr, "[M::%s::] Starting...\n", __func__);
    asg_t *g = ug->g; 
    asg64_v tx = {0,0,0}, tb = {0,0,0}, *ob = NULL, *ub = NULL; 
    uint32_t v, w, n_vtx = g->n_seq<<1, n_arc, nv, i, wc[2], wm[2], mm_c, mm_m, mm_v;
    uint64_t n_pop = 0, max_dist;
    asg_arc_t *av = NULL; if (!g->is_symm) asg_symm(g);
    buf_t b; memset(&b, 0, sizeof(buf_t));
    b.a = (binfo_t*)calloc(n_vtx, sizeof(binfo_t));
    if(i_max_dist) max_dist = (*i_max_dist);
    else max_dist = get_bub_pop_max_dist_advance(g, &b);
    ob = (in?(in):(&tx)); ub = (ib?(ib):(&tb)); ob->n = ub->n = 0;

    if(max_dist > 0) {
        for (v = 0; v < n_vtx; ++v) {
            nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
            if (nv < 2 || g->seq[v>>1].del) continue;
            for (i = n_arc = 0; i < nv; ++i) {
                if (!av[i].del) ++n_arc;
            }
            if (n_arc < 2) continue;
            ///find a bubble
            ob->n = ub->n = 0;
            if(ulg_bub_pop1(uidx, ug, v, max_dist, &b, max_ext, max_ext_hifi, 1, 0, skip_hom, ob, ub, &(wc[0]), &(wm[0]))) {
                w = b.S.a[0]^1; mm_c = mm_m = mm_v = (uint32_t)-1;
                
                ob->n = ub->n = 0;
                if(ulg_bub_pop1(uidx, ug, v, max_dist, &b, max_ext, max_ext_hifi, 0, 0, skip_hom, 
                                                                                ob, ub, &(wc[0]), &(wm[0]))) {
                    mm_c = wc[0]; mm_m = wm[0]; mm_v = v;
                }

                ob->n = ub->n = 0;
                if(ulg_bub_pop1(uidx, ug, w, max_dist, &b, max_ext, max_ext_hifi, 0, 0, skip_hom, 
                                                                                ob, ub, &(wc[1]), &(wm[1]))) {
                    if((wc[1] < mm_c) && (wc[1] == mm_c && wm[1] > mm_m)) {
                        mm_c = wc[1]; mm_m = wm[1]; mm_v = w;
                    }                                                               
                }

                if(mm_v != (uint32_t)-1) {
                    ob->n = ub->n = 0;
                    w = ulg_bub_pop1(uidx, ug, mm_v, max_dist, &b, max_ext, max_ext_hifi, 0, 1, skip_hom, ob, ub, &(wc[0]), &(wm[0]));
                    assert(w);
                    n_pop += w;
                }
            }
        }
    }

    free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
    if(n_pop) asg_cleanup(g);
    if(!in) free(tx.a); if(!ib) free(tb.a);
    // fprintf(stderr, "[M::%s::] Done...\n", __func__);
    return n_pop;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r9, 0x50(%rsp)
movq %r8, 0x38(%rsp)
movl %ecx, 0x14(%rsp)
movq %rdx, %r15
movq %rdi, 0x30(%rsp)
movq %rsi, 0x8(%rsp)
movq 0x18(%rsi), %rbx
xorl %eax, %eax
movq %rax, 0x110(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x100(%rsp)
movq %rax, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movl 0x14(%rbx), %eax
leal (%rax,%rax), %ebp
testl %eax, %eax
js 0x2069b0
movq %rbx, %rdi
callq 0xa047e
xorps %xmm0, %xmm0
movq 0x150(%rsp), %r14
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movq $0x0, 0xd0(%rsp)
movl %ebp, %edi
movl $0x1c, %esi
movq %rdi, 0x28(%rsp)
callq 0x2120
movq %rax, 0x70(%rsp)
testq %r15, %r15
je 0x206a11
movq (%r15), %rcx
jmp 0x206a21
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0xbf22d
movq %rax, %rcx
testq %r14, %r14
leaq 0x100(%rsp), %rdx
cmovneq %r14, %rdx
movq 0x158(%rsp), %rax
testq %rax, %rax
leaq 0xe0(%rsp), %r10
cmovneq %rax, %r10
xorl %r13d, %r13d
movq %r13, (%r10)
movq %rdx, 0x60(%rsp)
movq %r13, (%rdx)
movq %rcx, 0x40(%rsp)
testq %rcx, %rcx
sete %al
testl %ebp, %ebp
sete %cl
orb %al, %cl
movl $0x0, %eax
movq %rax, 0x48(%rsp)
movq 0x8(%rsp), %r12
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %rdi
jne 0x206cc1
leaq 0x18(%rsp), %r11
leaq 0x20(%rsp), %r15
xorl %ebp, %ebp
movq $0x0, 0x48(%rsp)
movq %rbx, 0x58(%rsp)
movq 0x28(%rbx), %rax
movq (%rax,%rbp,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x206cb5
movq 0x20(%rbx), %rcx
movl %ebp, %edx
shrl %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0x206cb5
movq 0x8(%rbx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0xc, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0x206ae0
cmpl $0x2, %ecx
jb 0x206cb5
movq %r13, (%r10)
movq 0x60(%rsp), %rax
movq %r13, (%rax)
movq %r8, %r14
movq %r8, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq 0x40(%rsp), %rcx
movq %rax, %r12
leaq 0x70(%rsp), %r8
movl 0x14(%rsp), %r9d
pushq %r11
pushq %r15
pushq %r10
pushq %rax
pushq 0x70(%rsp)
pushq $0x0
pushq $0x1
pushq 0x70(%rsp)
movq %r10, %r15
callq 0x205f96
addq $0x40, %rsp
testq %rax, %rax
je 0x206c82
movq 0x88(%rsp), %rax
xorl %ebx, %ebx
movl (%rax), %r13d
xorl $0x1, %r13d
movq %rbx, (%r15)
movq %rbx, (%r12)
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
movq 0x40(%rsp), %rcx
leaq 0x70(%rsp), %r8
movl 0x14(%rsp), %r9d
leaq 0x18(%rsp), %rax
pushq %rax
leaq 0x28(%rsp), %rax
pushq %rax
pushq %r15
pushq %r12
movq 0x70(%rsp), %r12
pushq %r12
pushq %rbx
pushq %rbx
pushq 0x70(%rsp)
callq 0x205f96
addq $0x40, %rsp
movq %r12, %r10
movq 0x60(%rsp), %r12
movq %rax, 0x68(%rsp)
movq %rbx, (%r15)
movq %rbx, (%r12)
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movl %r13d, %edx
xorl %r13d, %r13d
movl 0x14(%rsp), %ebx
movq 0x40(%rsp), %rcx
leaq 0x70(%rsp), %r14
movq %r14, %r8
movl %ebx, %r9d
leaq 0x1c(%rsp), %rax
pushq %rax
leaq 0x2c(%rsp), %rax
pushq %rax
pushq %r15
pushq %r12
pushq %r10
pushq %r13
pushq %r13
pushq 0x70(%rsp)
callq 0x205f96
addq $0x40, %rsp
cmpq $0x0, 0x68(%rsp)
je 0x206c94
movq %r13, (%r15)
movq %r13, (%r12)
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
movq 0x40(%rsp), %rcx
movq %r14, %r8
movl %ebx, %r9d
leaq 0x18(%rsp), %rax
pushq %rax
leaq 0x28(%rsp), %rax
movq %rax, %r14
pushq %rax
movq %r15, %r13
pushq %r15
pushq %r12
pushq 0x70(%rsp)
pushq $0x1
pushq $0x0
pushq 0x70(%rsp)
callq 0x205f96
addq $0x40, %rsp
testq %rax, %rax
movq 0x58(%rsp), %rbx
je 0x206d56
addq %rax, 0x48(%rsp)
movq 0x8(%rsp), %r12
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %rdi
movq %r13, %r10
xorl %r13d, %r13d
leaq 0x18(%rsp), %r11
movq %r14, %r15
jmp 0x206cb5
movq 0x8(%rsp), %r12
movq %r14, %r8
movq 0x28(%rsp), %rdi
movq %r15, %r10
jmp 0x206cab
movq 0x8(%rsp), %r12
movq 0x30(%rsp), %r8
movq 0x28(%rsp), %rdi
movq %r15, %r10
movq 0x58(%rsp), %rbx
leaq 0x18(%rsp), %r11
leaq 0x20(%rsp), %r15
incq %rbp
cmpq %rdi, %rbp
jne 0x206aa0
movq 0x70(%rsp), %rdi
callq 0x2220
movq 0x88(%rsp), %rdi
callq 0x2220
movq 0xa0(%rsp), %rdi
callq 0x2220
movq 0xb8(%rsp), %rdi
callq 0x2220
movq 0xd0(%rsp), %rdi
callq 0x2220
movq 0x48(%rsp), %r14
testq %r14, %r14
je 0x206d11
movq %rbx, %rdi
callq 0xa02fa
cmpq $0x0, 0x150(%rsp)
jne 0x206d29
movq 0x110(%rsp), %rdi
callq 0x2220
cmpq $0x0, 0x158(%rsp)
jne 0x206d41
movq 0xf0(%rsp), %rdi
callq 0x2220
movq %r14, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x356a1(%rip), %rdi     # 0x23c3fe
leaq 0x325c1(%rip), %rsi     # 0x239325
leaq 0x352f3(%rip), %rcx     # 0x23c05e
movl $0x2790, %edx           # imm = 0x2790
callq 0x2110