// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: ma_hit_flt(ma_hit_t_alloc*, long long, ma_sub_t*, int, int)
void ma_hit_flt(ma_hit_t_alloc* sources, long long n_read, ma_sub_t *coverage_cut, int max_hang, int min_ovlp)
{
    double startTime = Get_T();
	long long i, j, rLen;
	asg_arc_t t;

    for (i = 0; i < n_read; ++i) 
    {
        rLen = 0;
        for (j = 0; j < (long long)sources[i].length; j++)
        {
            ma_hit_t *h = &(sources[i].buffer[j]);
            if(h->del) continue;
            //check the corresponding two reads 
		    const ma_sub_t *sq = &(coverage_cut[Get_qn(*h)]);
            const ma_sub_t *st = &(coverage_cut[Get_tn(*h)]);
            int r;
		    if (sq->del || st->del) continue;
            ///[sq->s, sq->e) and [st->s, st->e) are the high coverage region in query and target
            ///here just exculde the overhang?
            ///in miniasm the 5-th option is 0.5, instead of 0.8
            /**note!!! h->qn and h->qs have been normalized by sq->s
             * h->ts and h->tn have been normalized by sq->e
             **/  
            ///here the max_hang = 1000, asm_opt.max_hang_rate = 0.8, min_ovlp = 50
            ///for me, there should not have any overhang..so r cannot be equal to MA_HT_INT
            ///sq->e - sq->s = the length of query; st->e - st->s = the length od target
            r = ma_hit2arc(h, sq->e - sq->s, st->e - st->s, max_hang, asm_opt.max_hang_rate, min_ovlp, &t);


            ///for me, there should not have any overhang..so r cannot be equal to MA_HT_INT
            ///and I think if we use same min_ovlp in all functions, r also cannot be MA_HT_SHORT_OVLP
            ///so it does not matter we have ma_hit2arc or not
		    if (r >= 0 || r == MA_HT_QCONT || r == MA_HT_TCONT)
            {
                h->del = 0;
                rLen++;
            }
            else
            {
                h->del = 1;
                delete_single_edge(sources, coverage_cut, Get_tn(*h), Get_qn(*h));
            }
        
            
        }

        if(rLen == 0)
        {
            (coverage_cut)[i].del = 1;
        }
    }

    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] takes %0.2f s\n\n", __func__, Get_T()-startTime);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, 0xc(%rsp)
movl %ecx, 0x8(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, (%rsp)
callq 0x300fc
movq %r14, 0x20(%rsp)
testq %r14, %r14
jle 0xa1f47
movq %rbx, %rsi
xorl %ecx, %ecx
movq %rbx, 0x18(%rsp)
leaq (%rcx,%rcx,2), %rdx
movq (%rsp), %rax
cmpl $0x0, 0xc(%rax,%rdx,8)
je 0xa1f34
movq %rcx, 0x30(%rsp)
movq (%rsp), %rax
movq %rdx, 0x28(%rsp)
leaq (%rax,%rdx,8), %rbx
xorl %ebp, %ebp
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
movq (%rbx), %r14
movq 0x18(%r14,%rbp), %r13
testq %r13, %r13
js 0xa1f0f
movq (%r14,%rbp), %r15
shrq $0x20, %r15
leaq (%r15,%r15,2), %rcx
movl (%rsi,%rcx,4), %eax
testl %eax, %eax
js 0xa1f0f
movl 0xc(%r14,%rbp), %edi
leaq (%rdi,%rdi,2), %rdx
leaq (%rsi,%rdx,4), %rdx
movl (%rdx), %r8d
testl %r8d, %r8d
js 0xa1f0f
movq %rdi, 0x38(%rsp)
leaq (%r14,%rbp), %rdi
leaq (%rsi,%rcx,4), %rcx
movl 0x4(%rcx), %esi
subl %eax, %esi
movl 0x4(%rdx), %edx
subl %r8d, %edx
leaq 0x1e88c8(%rip), %rax    # 0x28a758
movss 0x158(%rax), %xmm0
movl 0x8(%rsp), %ecx
movl 0xc(%rsp), %r8d
leaq 0x40(%rsp), %r9
callq 0xa159b
testl %eax, %eax
sets %cl
addl $0x3, %eax
cmpl $0x2, %eax
setae %al
testb %al, %cl
jne 0xa1ece
movq %r13, 0x18(%r14,%rbp)
incq 0x10(%rsp)
movq 0x18(%rsp), %rsi
jmp 0xa1f0f
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
orq %rax, %r13
movq %r13, 0x18(%r14,%rbp)
movq (%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rsi, %r14
movq 0x38(%rsp), %rdx
movl %r15d, %ecx
callq 0xa13a9
testq %rax, %rax
je 0xa1f0c
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orq %rcx, 0x18(%rax)
movq %r14, %rsi
incq %r12
movl 0xc(%rbx), %eax
addq $0x28, %rbp
cmpq %rax, %r12
jb 0xa1e30
cmpq $0x0, 0x10(%rsp)
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %rdx
jne 0xa1f39
orb $-0x80, 0x3(%rsi,%rdx,4)
incq %rcx
cmpq 0x20(%rsp), %rcx
jne 0xa1dfd
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq