// File: /workspace/github_cpp_makefile_star2_O2/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, 0x10(%rsp)
callq 0x251c
movq %rbx, %rsi
xorl %ecx, %ecx
testq %r14, %r14
cmovleq %rcx, %r14
movq %r14, 0x28(%rsp)
movq %rbx, 0x20(%rsp)
cmpq 0x28(%rsp), %rcx
je 0x6ad82
movq %rcx, 0x30(%rsp)
imulq $0x18, %rcx, %r12
addq 0x10(%rsp), %r12
xorl %ebp, %ebp
movq $0x0, 0x18(%rsp)
xorl %ebx, %ebx
movl 0xc(%r12), %eax
cmpq %rax, %rbx
jae 0x6ad64
movq (%r12), %r14
movq 0x18(%r14,%rbp), %r13
testq %r13, %r13
js 0x6ad58
movq (%r14,%rbp), %r15
shrq $0x20, %r15
imulq $0xc, %r15, %rcx
movl (%rsi,%rcx), %eax
testl %eax, %eax
js 0x6ad58
movl 0xc(%r14,%rbp), %edi
imulq $0xc, %rdi, %rdx
addq %rsi, %rdx
movl (%rdx), %r8d
testl %r8d, %r8d
js 0x6ad58
movq %rdi, 0x38(%rsp)
leaq (%r14,%rbp), %rdi
addq %rsi, %rcx
movl 0x4(%rcx), %esi
subl %eax, %esi
movl 0x4(%rdx), %edx
subl %r8d, %edx
leaq 0x1e8a65(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movl 0x8(%rsp), %ecx
movl 0xc(%rsp), %r8d
leaq 0x40(%rsp), %r9
callq 0x6a4a7
testl %eax, %eax
sets %cl
addl $0x3, %eax
cmpl $0x2, %eax
setae %al
testb %al, %cl
jne 0x6ad31
movq %r13, 0x18(%r14,%rbp)
incq 0x18(%rsp)
movq 0x20(%rsp), %rsi
jmp 0x6ad58
btsq $0x3f, %r13
movq %r13, 0x18(%r14,%rbp)
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %r14
movq %r14, %rsi
movq 0x38(%rsp), %rdx
movl %r15d, %ecx
callq 0x6a334
movq %r14, %rsi
incq %rbx
addq $0x28, %rbp
jmp 0x6ac86
cmpq $0x0, 0x18(%rsp)
movq 0x30(%rsp), %rcx
jne 0x6ad7a
imulq $0xc, %rcx, %rax
orb $-0x80, 0x3(%rsi,%rax)
incq %rcx
jmp 0x6ac60
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq