// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: force_trio_clean(ma_ug_t*, asg_t*, ma_sub_t*, ma_hit_t_alloc*, ma_hit_t_alloc*, R_to_U*, unsigned char, float, float, unsigned int)
void force_trio_clean(ma_ug_t* ug, asg_t* read_g, ma_sub_t* coverage_cut, 
ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex, 
uint8_t flag, float self_drop_rate, float contig_drop_rate, uint32_t min_occ)
{
    asg_t* nsg = ug->g;
    uint32_t beg, end, n_vtx = nsg->n_seq<<1, k, i, rId, tf_occ, tnf_occ, flag_occ, non_flag_occ, n_reduce = 1;
    long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen;
    buf_t b; memset(&b, 0, sizeof(buf_t));
    ma_utg_t *u = NULL;
    uint8_t* primary_flag = (uint8_t*)calloc(read_g->n_seq, sizeof(uint8_t));

    while (n_reduce)
    {
        n_reduce = 0;
        n_vtx = nsg->n_seq;
        for (beg = 0; beg < n_vtx; ++beg) 
        {
            if(nsg->seq[beg>>1].del || asg_arc_n(nsg, beg) <= 0 || get_real_length(nsg, beg, NULL)<=0)
            {
                continue;
            }
            if(get_real_length(nsg, beg^1, NULL) == 1)///check if beg is the tig end
            {
                get_real_length(nsg, beg^1, &end);
                if(get_real_length(nsg, end^1, NULL) == 1) continue;
            }
            b.b.n = 0; tf_occ = tnf_occ = 0;
            get_unitig(nsg, ug, beg, &end, &nodeLen, &baseLen, &max_stop_nodeLen, &max_stop_baseLen, 1, &b);

            for (i = 0; i < b.b.n; i++)
            {
                u = &((ug)->u.a[b.b.a[i]>>1]);
                for (k = 0; k < u->n; k++)
                {
                    rId = u->a[k]>>33;
                    if(R_INF.trio_flag[rId] == AMBIGU) continue;
                    if(R_INF.trio_flag[rId] == DROP) continue;
                    if(R_INF.trio_flag[rId] == flag) tf_occ++;
                    if(R_INF.trio_flag[rId] != flag) tnf_occ++;
                }
            }
            if(tnf_occ <= ((tnf_occ+tf_occ)*contig_drop_rate)) continue;

            for (i = 0; i < b.b.n; i++)
            {
                flag_occ = non_flag_occ = 0;
                u = &((ug)->u.a[b.b.a[i]>>1]);
                for (k = 0; k < u->n; k++)
                {
                    rId = u->a[k]>>33;
                    if(R_INF.trio_flag[rId] == AMBIGU) continue;
                    if(R_INF.trio_flag[rId] == DROP) continue;
                    if(R_INF.trio_flag[rId] == flag) flag_occ++;
                    if(R_INF.trio_flag[rId] != flag) non_flag_occ++;
                }

                if(non_flag_occ <= min_occ) continue;
                if(non_flag_occ <= ((non_flag_occ+flag_occ)*self_drop_rate)) continue;
                if(non_flag_occ <= ((tf_occ+tnf_occ)*contig_drop_rate)) continue;
                if(if_primary_unitig(u, read_g, coverage_cut, sources, ruIndex, primary_flag))
                {
                    continue;
                }

                if(u->m != 0)
                {
                    u->circ = u->end = u->len = u->m = u->n = u->start = 0;
                    free(u->a);
                    u->a = NULL;
                }
                asg_seq_del(nsg, b.b.a[i]>>1);
                n_reduce++;
            }
            
        }
    }

    free(b.b.a);
    asg_cleanup(nsg);
    free(primary_flag);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movl 0x18(%rbp), %eax
movb 0x10(%rbp), %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movss %xmm0, -0x34(%rbp)
movss %xmm1, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x4c(%rbp)
movl $0x1, -0x6c(%rbp)
leaq -0xf8(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movq $0x0, -0x100(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x108(%rbp)
cmpl $0x0, -0x6c(%rbp)
je 0x11f3d2
movl $0x0, -0x6c(%rbp)
movq -0x40(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x4c(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x11f3cd
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x44(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x11ef9c
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x44(%rbp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x0, %eax
jbe 0x11ef9c
movq -0x40(%rbp), %rdi
movl -0x44(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
jg 0x11efa1
jmp 0x11f3bf
movq -0x40(%rbp), %rdi
movl -0x44(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x1, %eax
jne 0x11efeb
movq -0x40(%rbp), %rdi
movl -0x44(%rbp), %esi
xorl $0x1, %esi
leaq -0x48(%rbp), %rdx
callq 0x166b50
movq -0x40(%rbp), %rdi
movl -0x48(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x1, %eax
jne 0x11efe9
jmp 0x11f3bf
jmp 0x11efeb
movq $0x0, -0xc0(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x44(%rbp), %edx
leaq -0x48(%rbp), %rcx
leaq -0x78(%rbp), %r8
leaq -0x80(%rbp), %r9
leaq -0x88(%rbp), %r11
leaq -0x90(%rbp), %r10
leaq -0xf8(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpq -0xc0(%rbp), %rax
jae 0x11f154
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xb0(%rbp), %rcx
movl -0x54(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x100(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq -0x100(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x11f144
movq -0x100(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x58(%rbp)
leaq 0x2a620d(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x58(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x11f0d5
jmp 0x11f136
leaq 0x2a61f4(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x58(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x5, %eax
jne 0x11f0ee
jmp 0x11f136
leaq 0x2a61db(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x58(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzbl 0x10(%rbp), %ecx
cmpl %ecx, %eax
jne 0x11f111
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
leaq 0x2a61b8(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x58(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzbl 0x10(%rbp), %ecx
cmpl %ecx, %eax
je 0x11f134
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x11f136
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x11f090
jmp 0x11f146
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x11f052
movl -0x60(%rbp), %eax
movl %eax, %ecx
movl %ecx, %eax
cvtsi2ss %rcx, %xmm1
movl -0x5c(%rbp), %ecx
addl %ecx, %eax
cvtsi2ss %rax, %xmm0
mulss -0x38(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x11f179
jmp 0x11f3bf
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpq -0xc0(%rbp), %rax
jae 0x11f3bd
movl $0x0, -0x68(%rbp)
movl $0x0, -0x64(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xb0(%rbp), %rcx
movl -0x54(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x100(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq -0x100(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x11f280
movq -0x100(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x58(%rbp)
leaq 0x2a60d1(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x58(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x11f211
jmp 0x11f272
leaq 0x2a60b8(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x58(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x5, %eax
jne 0x11f22a
jmp 0x11f272
leaq 0x2a609f(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x58(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzbl 0x10(%rbp), %ecx
cmpl %ecx, %eax
jne 0x11f24d
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
leaq 0x2a607c(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x58(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzbl 0x10(%rbp), %ecx
cmpl %ecx, %eax
je 0x11f270
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x11f272
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x11f1cc
movl -0x68(%rbp), %eax
cmpl 0x18(%rbp), %eax
ja 0x11f28d
jmp 0x11f3af
movl -0x68(%rbp), %eax
movl %eax, %ecx
movl %ecx, %eax
cvtsi2ss %rcx, %xmm1
movl -0x64(%rbp), %ecx
addl %ecx, %eax
cvtsi2ss %rax, %xmm0
mulss -0x34(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x11f2b2
jmp 0x11f3af
movl -0x68(%rbp), %eax
cvtsi2ss %rax, %xmm1
movl -0x5c(%rbp), %eax
movl -0x60(%rbp), %ecx
addl %ecx, %eax
cvtsi2ss %rax, %xmm0
mulss -0x38(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x11f2d6
jmp 0x11f3af
movq -0x100(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x108(%rbp), %r9
callq 0x1185a0
cmpb $0x0, %al
je 0x11f302
jmp 0x11f3af
movq -0x100(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x11f38e
movq -0x100(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x100(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x100(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x100(%rbp), %rax
movl (%rax), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x100(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x100(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x100(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2210
movq -0x100(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x40(%rbp), %rdi
movq -0xb0(%rbp), %rax
movl -0x54(%rbp), %ecx
movl (%rax,%rcx,4), %esi
shrl %esi
callq 0xd9510
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x11f180
jmp 0x11f3bf
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x11ef4d
jmp 0x11ef26
movq -0xb0(%rbp), %rdi
callq 0x2210
movq -0x40(%rbp), %rdi
callq 0xcdd10
movq -0x108(%rbp), %rdi
callq 0x2210
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax)