// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: refine_bubble_popping(ma_ug_t*, buf_t*, unsigned int, unsigned long, unsigned int, unsigned int, hap_cov_t*, utg_trans_t*, unsigned int, rd_hamming_fly_simp_t*)
uint64_t refine_bubble_popping(ma_ug_t *ug, buf_t *b, uint32_t v0, uint64_t max_dist, uint32_t positive_flag, uint32_t negative_flag, hap_cov_t *cov, utg_trans_t *o, uint32_t is_update_chain, rd_hamming_fly_simp_t *pf)
{
    // fprintf(stderr, "[M::%s]\n", __func__);
    if(!asg_bub_pop1_primary_trio(ug->g, ug, v0, max_dist, b, positive_flag, negative_flag, 0, NULL, NULL, NULL, 0, 0, NULL)) return 0;
    // if(((v0>>1) == 7536) && ((b->S.a[0]>>1) == 99223)) {
    //     fprintf(stderr, "[M::%s] uga_v::%u\n", __func__, v0); dbg_asys_gfa(ug->g);
    //     print_simple_dbg_gfa(ug->g, "uga");
    // }
    uint32_t non_positive_flag = (uint32_t)-1, v, u, k, rId, pn, npn;
    if(positive_flag == FATHER) non_positive_flag = MOTHER;
    if(positive_flag == MOTHER) non_positive_flag = FATHER;
    ma_utg_t* p = NULL;
    ///b->S.a[0] is the sink of this bubble
    ///v is the sink of this bubble
    v = b->S.a[0]; pn = npn = 0;
    ///scan node
    do {
        u = b->a[v].p; // u->v
        if(v != b->S.a[0]) {
            p = &(ug->u.a[v>>1]);
            for (k = 0; k < p->n; k++) {
                rId = p->a[k]>>33;
                if(R_INF.trio_flag[rId] == positive_flag) pn++;
                if(R_INF.trio_flag[rId] == non_positive_flag) npn++;
            }
        }
        v = u;
    } while (v != v0);
    // fprintf(stderr, "[M::%s] pn::%u, npn::%u\n", __func__, pn, npn);
    ///debug
    if((npn <= 0) || ((npn <= ((npn+pn)*0.05)) && (npn <= 64))) {///phasing is ok
        return asg_bub_pop1_primary_trio(ug->g, ug, v0, max_dist, b, positive_flag, negative_flag, 1, NULL, NULL, cov, is_update_chain, 0, o);
    }
    return renew_phase_bubble(pf, v0, b, ug, max_dist, positive_flag, negative_flag, cov, o, is_update_chain);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, %ebx
movl %edx, %ebp
movq %rsi, %r13
movq %rdi, %rsi
movq 0x18(%rdi), %rdi
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
andq $0x0, 0x38(%rsp)
andl $0x0, 0x30(%rsp)
andl $0x0, 0x28(%rsp)
andq $0x0, 0x20(%rsp)
andl $0x0, 0x8(%rsp)
movl %r9d, 0x44(%rsp)
movl %r9d, (%rsp)
movq %rsi, 0x48(%rsp)
movq %rcx, 0x50(%rsp)
movq %r13, %r8
movl %ebx, %r9d
callq 0x84a86
testq %rax, %rax
je 0xaa5f5
xorl %eax, %eax
cmpl $0x1, %ebx
sete %al
leal (%rax,%rax,2), %eax
decl %eax
cmpl $0x2, %ebx
pushq $0x1
popq %r9
cmovnel %eax, %r9d
movq (%r13), %rdi
movq 0x18(%r13), %rax
movl (%rax), %ecx
leaq 0x1a9d41(%rip), %rax    # 0x254230
movq 0x28(%rax), %rax
xorl %esi, %esi
movl %ecx, %r11d
xorl %r8d, %r8d
cmpl %ecx, %r11d
je 0xaa558
movl %ebp, %r10d
movq 0x48(%rsp), %rdx
movq 0x10(%rdx), %r14
movl %r11d, %edx
shrl %edx
imulq $0x28, %rdx, %rbp
leaq (%r14,%rbp), %rdx
movl 0x10(%r14,%rbp), %r14d
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0xaa555
movq 0x18(%rdx), %r15
movq (%r15,%rbp,8), %r15
shrq $0x21, %r15
movzbl (%rax,%r15), %r15d
xorl %r12d, %r12d
cmpl %ebx, %r15d
sete %r12b
addl %r12d, %esi
xorl %r12d, %r12d
cmpl %r15d, %r9d
sete %r12b
addl %r12d, %r8d
incq %rbp
jmp 0xaa520
movl %r10d, %ebp
movl %r11d, %edx
imulq $0x1c, %rdx, %rdx
movl (%rdi,%rdx), %r11d
cmpl %ebp, %r11d
jne 0xaa4fb
testl %r8d, %r8d
je 0xaa595
cmpl $0x40, %r8d
ja 0xaa5f9
movl %r8d, %eax
cvtsi2sd %rax, %xmm0
addl %r8d, %esi
cvtsi2sd %rsi, %xmm1
mulsd 0x138f89(%rip), %xmm1   # 0x1e3518
ucomisd %xmm0, %xmm1
jb 0xaa5f9
movq 0x48(%rsp), %rsi
movq 0x18(%rsi), %rdi
movq 0x98(%rsp), %rax
movq %rax, 0x38(%rsp)
movl 0xa0(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x20(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
andl $0x0, 0x30(%rsp)
movl 0x44(%rsp), %eax
movl %eax, (%rsp)
movl $0x1, 0x8(%rsp)
movl %ebp, %edx
movq 0x50(%rsp), %rcx
movq %r13, %r8
movl %ebx, %r9d
callq 0x84a86
jmp 0xaa644
xorl %eax, %eax
jmp 0xaa644
movl %ebp, %esi
movl 0xa0(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x44(%rsp), %eax
movl %eax, (%rsp)
movq 0xa8(%rsp), %rdi
movq %r13, %rdx
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
movl %ebx, %r9d
callq 0xa9a70
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq