// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: delete_useless_trio_nodes(ma_ug_t**, asg_t*, ma_sub_t*, ma_hit_t_alloc*, R_to_U*, unsigned int, float, float, unsigned int)
void delete_useless_trio_nodes(ma_ug_t **ug, asg_t* read_g, ma_sub_t* coverage_cut, 
ma_hit_t_alloc* sources, R_to_U* ruIndex, uint32_t flag, float flag_rate, float used_rate, uint32_t min_occ)
{
    asg_t* nsg = (*ug)->g;
    uint32_t v, n_vtx = nsg->n_seq;
    uint8_t* primary_flag = (uint8_t*)calloc(read_g->n_seq, sizeof(uint8_t));

    if(flag_rate > 0 && used_rate > 0 && min_occ > 0) {
        rescue_useless_trio_nodes(*ug, flag, flag_rate, used_rate, min_occ);
    }

    for (v = 0; v < n_vtx; ++v) 
    {
        if(nsg->seq[v].del) continue;
        if(nsg->seq[v].c == ALTER_LABLE &&
          (if_primary_unitig(&((*ug)->u.a[v]), read_g, coverage_cut, sources, 
          ruIndex, primary_flag) == 0))
        {
            asg_seq_del(nsg, v);
            if((*ug)->u.a[v].m!=0)
            {
                (*ug)->u.a[v].m = (*ug)->u.a[v].n = 0;
                free((*ug)->u.a[v].a);
                (*ug)->u.a[v].a = NULL;
            }

            continue;
        }

        //note: after cleaning, some cirle might be gone, or we have some new circles
        //so need to renew .circ
        /**
        if(get_unitig(nsg, NULL, (v<<1), &convex, &nodeLen, &baseLen, 
                                        &max_stop_nodeLen, &max_stop_baseLen, 1, NULL)==LOOP)
        {
            (*ug)->u.a[v].circ = 1;
            (*ug)->u.a[v].start = (*ug)->u.a[v].end = UINT32_MAX;
        }
        else
        {
            (*ug)->u.a[v].circ = 0;

            (*ug)->u.a[v].start = (*ug)->u.a[v].a[0]>>32;
            (*ug)->u.a[v].end = ((*ug)->u.a[v].a[(*ug)->u.a[v].n-1]>>32)^1;
        }
        **/        
    }

    asg_cleanup(nsg);
    free(primary_flag);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movl %r9d, 0xc(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rdi, %r13
movl 0x90(%rsp), %ebx
movq (%rdi), %r14
movq 0x18(%r14), %rbp
movl 0x14(%rbp), %r15d
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq %rsi, 0x10(%rsp)
movl 0x14(%rsi), %edi
andq %r12, %rdi
pushq $0x1
popq %rsi
callq 0x2120
movl %ebx, %edx
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movq %rax, %rbx
xorps %xmm3, %xmm3
xorps %xmm2, %xmm2
cmpnltps %xmm1, %xmm2
cmpnltps %xmm0, %xmm3
orps %xmm2, %xmm3
movd %xmm3, %eax
testl %edx, %edx
sete %cl
orb %al, %cl
testb $0x1, %cl
jne 0x9972e
movq %r14, %rdi
movl 0xc(%rsp), %esi
callq 0x994e4
andq %r12, %r15
xorl %r12d, %r12d
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x997c3
movq 0x20(%rbp), %rax
cmpl $0x0, (%rax,%r14,8)
js 0x997b7
cmpb $0x1, 0x4(%rax,%r14,8)
jne 0x997b7
movq (%r13), %rax
movq 0x10(%rax), %rdi
addq %r12, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r8
movq %rbx, %r9
callq 0x945a4
testb %al, %al
jne 0x997b7
movq %rbp, %rdi
movl %r14d, %esi
callq 0x6f8da
movq (%r13), %rax
movq 0x10(%rax), %rax
cmpl $0x0, 0xc(%rax,%r12)
je 0x997b7
andq $0x0, 0xc(%rax,%r12)
movq 0x18(%rax,%r12), %rdi
callq 0x2220
movq (%r13), %rax
movq 0x10(%rax), %rax
andq $0x0, 0x18(%rax,%r12)
incq %r14
addq $0x28, %r12
jmp 0x99737
movq %rbp, %rdi
callq 0x694eb
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220