// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
callq 0x2510
movsd %xmm0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0xd11d3
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jge 0xd119d
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0xd106b
jmp 0xd118c
movq -0x18(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
movl %ecx, %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq -0x60(%rbp), %rcx
movl 0xc(%rcx), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xd10b9
movq -0x70(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xd10be
jmp 0xd118c
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movl 0x4(%rax), %esi
movq -0x68(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %esi
movq -0x70(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x70(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %edx
movl -0x1c(%rbp), %ecx
leaq 0x2f3704(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movl -0x20(%rbp), %r8d
leaq -0x58(%rbp), %r9
callq 0xd0300
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
jge 0xd111e
cmpl $-0x2, -0x74(%rbp)
je 0xd111e
cmpl $-0x3, -0x74(%rbp)
jne 0xd1146
movq -0x60(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x18(%rax), %rcx
orq $0x0, %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xd118a
movq -0x60(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x18(%rax), %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x60(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x60(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %ecx
callq 0xd0020
jmp 0xd118c
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xd101e
cmpq $0x0, -0x40(%rbp)
jne 0xd11c0
movq -0x18(%rbp), %rax
imulq $0xc, -0x30(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%rax)
jmp 0xd11c2
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xd1000
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)