// File: /workspace/github_cpp_makefile_star2_O2/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, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
movq 0x18(%rsi), %rbx
xorps %xmm0, %xmm0
andq $0x0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
andq $0x0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movl 0x14(%rbx), %eax
leal (%rax,%rax), %ebp
testl %eax, %eax
js 0x1c46ec
movq %rbx, %rdi
callq 0x69638
xorps %xmm0, %xmm0
movq 0x150(%rsp), %r14
movups %xmm0, 0xd0(%rsp)
movups %xmm0, 0xc0(%rsp)
movups %xmm0, 0xb0(%rsp)
movups %xmm0, 0xa0(%rsp)
movups %xmm0, 0x90(%rsp)
movups %xmm0, 0x80(%rsp)
movl %ebp, %edi
pushq $0x1c
popq %rsi
movq %rdi, 0x28(%rsp)
callq 0x2120
movq %rax, 0x78(%rsp)
testq %r15, %r15
je 0x1c4742
movq (%r15), %rcx
jmp 0x1c4752
leaq 0x78(%rsp), %rsi
movq %rbx, %rdi
callq 0x84975
movq %rax, %rcx
testq %r14, %r14
leaq 0x100(%rsp), %rdx
cmovneq %r14, %rdx
movq 0x158(%rsp), %rax
testq %rax, %rax
leaq 0xe0(%rsp), %rsi
cmovneq %rax, %rsi
andq $0x0, (%rsi)
andq $0x0, (%rdx)
testq %rcx, %rcx
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %r8
je 0x1c49e9
movq %rsi, 0x60(%rsp)
movq %rdx, 0x68(%rsp)
movq %rcx, 0x30(%rsp)
xorl %ebp, %ebp
leaq 0x20(%rsp), %r10
leaq 0x78(%rsp), %r13
movq $0x0, 0x40(%rsp)
movq %rbx, 0x48(%rsp)
movq 0x60(%rsp), %r12
movq 0x68(%rsp), %r15
cmpq %r8, %rbp
je 0x1c49e2
movq 0x28(%rbx), %rax
movq (%rax,%rbp,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1c49da
movq 0x20(%rbx), %rcx
movl %ebp, %edx
shrl %edx
cmpl $0x0, (%rcx,%rdx,8)
js 0x1c49da
movq 0x8(%rbx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
imulq $0x18, %rax, %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
addq $0xc, %rcx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %rax
je 0x1c4832
movl (%rcx,%rdx), %r9d
notl %r9d
shrl $0x1f, %r9d
addl %r9d, %esi
addq $0x18, %rdx
jmp 0x1c4819
cmpl $0x2, %esi
jb 0x1c49da
andq $0x0, (%r12)
andq $0x0, (%r15)
movq %r14, %rsi
movl %ebp, %edx
movq 0x30(%rsp), %rcx
movq %r13, %r8
movl 0x14(%rsp), %r9d
leaq 0x58(%rsp), %r14
pushq %r14
pushq %r10
pushq %r12
pushq %r15
pushq 0x70(%rsp)
pushq $0x0
pushq $0x1
pushq 0x70(%rsp)
callq 0x1c3ee5
addq $0x40, %rsp
testq %rax, %rax
je 0x1c49ab
movq 0x90(%rsp), %rax
movl (%rax), %r13d
andq $0x0, (%r12)
xorl $0x1, %r13d
andq $0x0, (%r15)
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
movq 0x30(%rsp), %rcx
leaq 0x78(%rsp), %r8
movl 0x14(%rsp), %r9d
pushq %r14
leaq 0x28(%rsp), %rax
pushq %rax
pushq %r12
pushq %r15
movq 0x70(%rsp), %r14
pushq %r14
pushq $0x0
pushq $0x0
pushq 0x70(%rsp)
callq 0x1c3ee5
addq $0x40, %rsp
andq $0x0, (%r12)
movq %rax, 0x70(%rsp)
andq $0x0, (%r15)
movq %rbx, %rdi
movq %r14, %rbx
movq 0x8(%rsp), %rsi
movl %r13d, %edx
leaq 0x78(%rsp), %r13
movl 0x14(%rsp), %r14d
movq 0x30(%rsp), %rcx
movq %r13, %r8
movl %r14d, %r9d
leaq 0x5c(%rsp), %rax
pushq %rax
leaq 0x2c(%rsp), %rax
pushq %rax
pushq %r12
pushq %r15
pushq %rbx
pushq $0x0
pushq $0x0
pushq 0x70(%rsp)
callq 0x1c3ee5
addq $0x40, %rsp
cmpq $0x0, 0x70(%rsp)
je 0x1c49c1
andq $0x0, (%r12)
andq $0x0, (%r15)
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
movq 0x30(%rsp), %rcx
movq %r13, %r8
movl %r14d, %r9d
leaq 0x58(%rsp), %rax
pushq %rax
leaq 0x28(%rsp), %rax
movq %rax, %r13
pushq %rax
pushq %r12
pushq %r15
pushq %rbx
pushq $0x1
pushq $0x0
pushq 0x70(%rsp)
callq 0x1c3ee5
addq $0x40, %rsp
testq %rax, %rax
movq 0x48(%rsp), %rbx
je 0x1c4a7e
addq %rax, 0x40(%rsp)
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %r8
movq %r13, %r10
leaq 0x78(%rsp), %r13
jmp 0x1c49da
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %r8
leaq 0x20(%rsp), %r10
jmp 0x1c49da
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %rdi
movq 0x28(%rsp), %r8
leaq 0x20(%rsp), %r10
movq 0x48(%rsp), %rbx
incq %rbp
jmp 0x1c47cb
movq 0x40(%rsp), %r15
jmp 0x1c49ec
xorl %r15d, %r15d
movq 0x78(%rsp), %rdi
callq 0x2220
movq 0x90(%rsp), %rdi
callq 0x2220
movq 0xa8(%rsp), %rdi
callq 0x2220
movq 0xc0(%rsp), %rdi
callq 0x2220
movq 0xd8(%rsp), %rdi
callq 0x2220
testq %r15, %r15
movq 0x150(%rsp), %r14
je 0x1c4a3f
movq %rbx, %rdi
callq 0x694eb
testq %r14, %r14
jne 0x1c4a51
movq 0x110(%rsp), %rdi
callq 0x2220
cmpq $0x0, 0x158(%rsp)
jne 0x1c4a69
movq 0xf0(%rsp), %rdi
callq 0x2220
movq %r15, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x35c1c(%rip), %rdi     # 0x1fa6a1
leaq 0x32a4d(%rip), %rsi     # 0x1f74d9
leaq 0x3586e(%rip), %rcx     # 0x1fa301
movl $0x2790, %edx           # imm = 0x2790
callq 0x2110