// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: reset_inner_bub_het_poy(asg_t*, ma_ug_t*, bubble_type*, unsigned int, unsigned long, buf_t*, unsigned long, unsigned long, unsigned char*, ma_hit_t_alloc*, R_to_U*)
void reset_inner_bub_het_poy(asg_t* sg, ma_ug_t* ug, bubble_type* bub, uint32_t bid, uint64_t tLen, buf_t *b, 
uint64_t m_het_cov, uint64_t m_hom_cov, uint8_t *r_het_flag, ma_hit_t_alloc* sources, R_to_U* ruIndex)
{
    uint32_t beg, sink, *ba, bn, m, v, z, socc;
    get_bubbles(bub, bid, &beg, &sink, &ba, &bn, NULL);
    for (m = 0; m < bn; m++) {
        v = ba[m];
        if(IF_HOM((v>>1), *bub)) continue;
        if(ug->g->seq[v>>1].del) continue;
        if(bub->index[v>>1] == (uint32_t)-1) continue;

        if(get_unitig_het_fly(ug, v>>1, sg, m_het_cov, m_hom_cov, sources, ruIndex, r_het_flag, 20, 1, 0, (uint32_t)-1) == 1) {
            continue;
        }

        if(asg_arc_n(ug->g, v) < 2) continue;
        if(get_real_length(ug->g, v, NULL) < 2) continue;
        if(asg_bub_pop1_primary_trio(ug->g, NULL, v, tLen, b, (uint32_t)-1, (uint32_t)-1, 0, NULL, NULL, NULL, 0, 0, NULL)) {
            //beg is v, end is b.S.a[0]
            //note b.b include end, does not include beg
            for (z = socc = 0; z < b->b.n; z++) {
                if(b->b.a[z]==v || b->b.a[z]==b->S.a[0]) continue;
                socc += ug->u.a[b->b.a[z]>>1].n;
            }
            if((socc > 10) && (socc > (ug->u.a[v>>1].n*3))) {
                bub->index[v>>1] = (uint32_t)-1;
            }
        }

        
        v ^= 1;
        if(bub->index[v>>1] == (uint32_t)-1) continue;
        if(asg_arc_n(ug->g, v) < 2) continue;
        if(get_real_length(ug->g, v, NULL) < 2) continue;
        if(asg_bub_pop1_primary_trio(ug->g, NULL, v, tLen, b, (uint32_t)-1, (uint32_t)-1, 0, NULL, NULL, NULL, 0, 0, NULL)) {
            //beg is v, end is b.S.a[0]
            //note b.b include end, does not include beg
            for (z = socc = 0; z < b->b.n; z++) {
                if(b->b.a[z]==v || b->b.a[z]==b->S.a[0]) continue;
                socc += ug->u.a[b->b.a[z]>>1].n;
            }
            if((socc > 10) && (socc > (ug->u.a[v>>1].n*3))) {
                bub->index[v>>1] = (uint32_t)-1;
            }
        }
    }  
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x8(%rsp)
movq %r8, 0x18(%rsp)
movq %rdx, %r15
movq %rdi, 0x20(%rsp)
movl %ecx, %eax
movq 0x40(%rdx), %rdx
movl (%rdx,%rax,4), %ecx
movl 0x4(%rdx,%rax,4), %eax
subl %ecx, %eax
addl $-0x2, %eax
je 0x1406a4
movq %rsi, %r9
movq 0x28(%r15), %rdx
leaq (%rdx,%rcx,4), %rbx
addq $0x8, %rbx
movl %eax, %r13d
xorl %r12d, %r12d
movq %rsi, 0x10(%rsp)
movl (%rbx,%r12,4), %ebp
movl %ebp, %r14d
shrl %r14d
movq (%r15), %rax
movq 0x80(%r15), %rcx
movl (%rax,%r14,4), %eax
incq %rcx
cmpq %rax, %rcx
jae 0x1403dd
incq %r12
cmpq %r13, %r12
jne 0x1403b0
jmp 0x1406a4
cmpl $-0x1, %eax
je 0x1403d0
movq 0x18(%r9), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%r14,8)
js 0x1403d0
movq %r9, %rdi
movl %r14d, %esi
movq 0x20(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %r8
movq 0x78(%rsp), %r9
pushq $-0x1
pushq $0x0
pushq $0x1
pushq $0x14
pushq 0x90(%rsp)
pushq 0xa8(%rsp)
callq 0x13f417
movq 0x40(%rsp), %r9
addq $0x30, %rsp
cmpl $0x1, %eax
je 0x1403d0
movq 0x18(%r9), %rdi
movq 0x28(%rdi), %rax
movq (%rax,%rbp,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1403d0
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x1403d0
movq 0x8(%rdi), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rdx), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %esi
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x140478
cmpl $0x2, %esi
jl 0x1403d0
subq $0x40, %rsp
xorl %eax, %eax
movq %rax, 0x38(%rsp)
movl %eax, 0x30(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movl %eax, 0x8(%rsp)
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
xorl %esi, %esi
movl %ebp, %edx
movq 0x58(%rsp), %rcx
movq 0x48(%rsp), %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0xc02d6
movq 0x50(%rsp), %r9
addq $0x40, %rsp
testq %rax, %rax
je 0x140556
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rcx
testq %rcx, %rcx
je 0x140556
movq 0x8(%rsp), %rax
movq 0x48(%rax), %rdx
xorl %esi, %esi
xorl %eax, %eax
movl (%rdx,%rsi,4), %edi
cmpl %ebp, %edi
je 0x140529
movq 0x8(%rsp), %r8
movq 0x18(%r8), %r8
cmpl (%r8), %edi
je 0x140529
movq 0x10(%r9), %r8
shrl %edi
leaq (%rdi,%rdi,4), %rdi
addl 0x10(%r8,%rdi,8), %eax
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0x140505
cmpl $0xb, %eax
jb 0x140556
movq 0x10(%r9), %rcx
leaq (%r14,%r14,4), %rdx
movl 0x10(%rcx,%rdx,8), %ecx
leal (%rcx,%rcx,2), %ecx
cmpl %ecx, %eax
jbe 0x140556
movq (%r15), %rax
movl $0xffffffff, (%rax,%r14,4) # imm = 0xFFFFFFFF
movq (%r15), %rax
cmpl $-0x1, (%rax,%r14,4)
je 0x1403d0
xorl $0x1, %ebp
movq 0x18(%r9), %rdi
movq 0x28(%rdi), %rax
movl %ebp, %ecx
movq (%rax,%rcx,8), %rax
testl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
je 0x1403d0
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0x1403d0
movq 0x8(%rdi), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rdx), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %esi
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x1405b1
cmpl $0x2, %esi
jl 0x1403d0
subq $0x40, %rsp
xorl %eax, %eax
movq %rax, 0x38(%rsp)
movl %eax, 0x30(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movl %eax, 0x8(%rsp)
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
xorl %esi, %esi
movl %ebp, %edx
movq 0x58(%rsp), %rcx
movq 0x48(%rsp), %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0xc02d6
movq 0x50(%rsp), %r9
addq $0x40, %rsp
testq %rax, %rax
je 0x1403d0
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rcx
testq %rcx, %rcx
je 0x1403d0
movq 0x8(%rsp), %rax
movq 0x48(%rax), %rdx
xorl %esi, %esi
xorl %eax, %eax
movl (%rdx,%rsi,4), %edi
cmpl %ebp, %edi
je 0x14066a
movq 0x8(%rsp), %r8
movq 0x18(%r8), %r8
cmpl (%r8), %edi
je 0x14066a
movq 0x10(%r9), %r8
shrl %edi
leaq (%rdi,%rdi,4), %rdi
addl 0x10(%r8,%rdi,8), %eax
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0x140646
cmpl $0xb, %eax
jb 0x1403d0
movq 0x10(%r9), %rcx
leaq (%r14,%r14,4), %rdx
movl 0x10(%rcx,%rdx,8), %ecx
leal (%rcx,%rcx,2), %ecx
cmpl %ecx, %eax
jbe 0x1403d0
movq (%r15), %rax
movl $0xffffffff, (%rax,%r14,4) # imm = 0xFFFFFFFF
jmp 0x1403d0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq