// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq %r8, 0x8(%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
movl %ecx, %esi
subq $0x8, %rsp
leaq 0x2c(%rsp), %rdx
leaq 0x28(%rsp), %rcx
leaq 0x20(%rsp), %r8
leaq 0xc(%rsp), %r9
movq %r15, %rdi
pushq $0x0
callq 0xf6ab5
popq %rax
popq %rcx
xorl %r13d, %r13d
movl 0x4(%rsp), %eax
cmpq %rax, %r13
jae 0xf8df6
movq 0x18(%rsp), %rax
movl (%rax,%r13,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 0xf8bf3
incq %r13
jmp 0xf8bbc
cmpl $-0x1, %eax
je 0xf8bee
movq 0x18(%r12), %rax
movq 0x20(%rax), %rax
cmpl $0x0, (%rax,%r14,8)
js 0xf8bee
movq %r12, %rdi
movl %r14d, %esi
movq 0x10(%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 0xf7dd6
addq $0x30, %rsp
cmpl $0x1, %eax
je 0xf8bee
movq 0x18(%r12), %rdi
movq 0x28(%rdi), %rax
testl $0xfffffffe, (%rax,%rbp,8) # imm = 0xFFFFFFFE
je 0xf8bee
movl %ebp, %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x2, %eax
jl 0xf8bee
movq 0x18(%r12), %rdi
subq $0x40, %rsp
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
andq $0x0, 0x38(%rsp)
andl $0x0, 0x30(%rsp)
andl $0x0, 0x28(%rsp)
andq $0x0, 0x20(%rsp)
andl $0x0, 0x8(%rsp)
orl $-0x1, (%rsp)
xorl %esi, %esi
movl %ebp, %edx
movq 0x48(%rsp), %rcx
movq %rbx, %r8
pushq $-0x1
popq %r9
callq 0x84a86
addq $0x40, %rsp
testq %rax, %rax
je 0xf8d08
movq 0x38(%rbx), %rcx
xorl %edx, %edx
xorl %eax, %eax
movl %edx, %edx
cmpq %rdx, %rcx
jbe 0xf8ce9
movq 0x48(%rbx), %rsi
movl (%rsi,%rdx,4), %esi
cmpl %ebp, %esi
je 0xf8ce5
movq 0x18(%rbx), %rdi
cmpl (%rdi), %esi
je 0xf8ce5
movq 0x10(%r12), %rdi
shrl %esi
imulq $0x28, %rsi, %rsi
addl 0x10(%rdi,%rsi), %eax
incl %edx
jmp 0xf8cbc
cmpl $0xb, %eax
jb 0xf8d08
movq 0x10(%r12), %rcx
imulq $0x28, %r14, %rdx
imull $0x3, 0x10(%rcx,%rdx), %ecx
cmpl %ecx, %eax
jbe 0xf8d08
movq (%r15), %rax
orl $-0x1, (%rax,%r14,4)
movq (%r15), %rax
cmpl $-0x1, (%rax,%r14,4)
je 0xf8bee
xorl $0x1, %ebp
movq 0x18(%r12), %rdi
movq 0x28(%rdi), %rax
movl %ebp, %ecx
testl $0xfffffffe, (%rax,%rcx,8) # imm = 0xFFFFFFFE
je 0xf8bee
movl %ebp, %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x2, %eax
jl 0xf8bee
movq 0x18(%r12), %rdi
subq $0x40, %rsp
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
andq $0x0, 0x38(%rsp)
andl $0x0, 0x30(%rsp)
andl $0x0, 0x28(%rsp)
andq $0x0, 0x20(%rsp)
andl $0x0, 0x8(%rsp)
orl $-0x1, (%rsp)
xorl %esi, %esi
movl %ebp, %edx
movq 0x48(%rsp), %rcx
movq %rbx, %r8
pushq $-0x1
popq %r9
callq 0x84a86
addq $0x40, %rsp
testq %rax, %rax
je 0xf8bee
movq 0x38(%rbx), %rcx
xorl %edx, %edx
xorl %eax, %eax
movl %edx, %edx
cmpq %rdx, %rcx
jbe 0xf8dca
movq 0x48(%rbx), %rsi
movl (%rsi,%rdx,4), %esi
cmpl %ebp, %esi
je 0xf8dc6
movq 0x18(%rbx), %rdi
cmpl (%rdi), %esi
je 0xf8dc6
movq 0x10(%r12), %rdi
shrl %esi
imulq $0x28, %rsi, %rsi
addl 0x10(%rdi,%rsi), %eax
incl %edx
jmp 0xf8d9d
cmpl $0xb, %eax
jb 0xf8bee
movq 0x10(%r12), %rcx
imulq $0x28, %r14, %rdx
imull $0x3, 0x10(%rcx,%rdx), %ecx
cmpl %ecx, %eax
jbe 0xf8bee
movq (%r15), %rax
orl $-0x1, (%rax,%r14,4)
jmp 0xf8bee
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq