// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movl %r9d, %ebp
movl %r8d, %ebx
movq %rcx, %r15
movl %edx, %r13d
movq %rsi, %r12
movq %rdi, %rsi
movq 0x18(%rdi), %rdi
xorl %r14d, %r14d
movq %r14, 0x38(%rsp)
movl %r14d, 0x30(%rsp)
movl %r14d, 0x28(%rsp)
movq %r14, 0x20(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
movl %r14d, 0x8(%rsp)
movl %r9d, (%rsp)
movq %rsi, 0x50(%rsp)
movq %r12, %r8
movl %ebx, %r9d
callq 0xbf39f
testq %rax, %rax
je 0xe6f55
movl %ebp, 0x4c(%rsp)
movq %r15, 0x60(%rsp)
movq 0xb8(%rsp), %rdi
xorl %eax, %eax
cmpl $0x1, %ebx
sete %al
leal (%rax,%rax,2), %eax
decl %eax
cmpl $0x2, %ebx
movl $0x1, %r8d
cmovnel %eax, %r8d
movq (%r12), %r9
movq %r12, 0x58(%rsp)
movq 0x18(%r12), %rax
movl (%rax), %eax
leaq 0x1a43e7(%rip), %rcx    # 0x28b230
movq 0x28(%rcx), %r11
movl %eax, %r10d
xorl %esi, %esi
cmpl %eax, %r10d
je 0xe6eab
movq 0x50(%rsp), %rcx
movq 0x10(%rcx), %rdx
movl %r10d, %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rbp
movl 0x10(%rdx,%rbp,8), %ecx
testq %rcx, %rcx
je 0xe6eab
leaq (%rdx,%rbp,8), %rdx
movq 0x18(%rdx), %rdx
xorl %ebp, %ebp
movq (%rdx,%rbp,8), %r15
shrq $0x21, %r15
movzbl (%r11,%r15), %r15d
xorl %r12d, %r12d
cmpl %ebx, %r15d
sete %r12b
addl %r12d, %r14d
xorl %r12d, %r12d
cmpl %r15d, %r8d
sete %r12b
addl %r12d, %esi
incq %rbp
cmpq %rbp, %rcx
jne 0xe6e7c
movl %r10d, %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl (%r9,%rdx), %r10d
cmpl %r13d, %r10d
jne 0xe6e52
testl %esi, %esi
je 0xe6eef
cmpl $0x40, %esi
ja 0xe6f59
movl %esi, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
addl %esi, %r14d
cvtsi2sd %r14, %xmm1
mulsd 0x13e5df(%rip), %xmm1   # 0x2254c8
ucomisd %xmm0, %xmm1
jb 0xe6f59
movq 0x50(%rsp), %rsi
movq 0x18(%rsi), %rdi
movq 0xa8(%rsp), %rax
movq %rax, 0x38(%rsp)
movl 0xb0(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x20(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, (%rsp)
movl $0x0, 0x30(%rsp)
movl $0x1, 0x8(%rsp)
movl %r13d, %edx
movq 0x60(%rsp), %rcx
movq 0x58(%rsp), %r8
movl %ebx, %r9d
callq 0xbf39f
jmp 0xe6f9f
xorl %eax, %eax
jmp 0xe6f9f
movl %r13d, %esi
movl 0xb0(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, (%rsp)
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x60(%rsp), %r8
movl %ebx, %r9d
callq 0xe6105
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq