// File: /workspace/github_cpp_makefile_star2_O3/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, 0x18(%rsp)
movl %ecx, 0x1c(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
callq 0x2f3fc
movq %r14, 0x38(%rsp)
testq %r14, %r14
jle 0xa2b3c
xorl %ecx, %ecx
movq %rbx, 0x30(%rsp)
leaq (%rcx,%rcx,2), %rdx
movq 0x10(%rsp), %rax
cmpl $0x0, 0xc(%rax,%rdx,8)
je 0xa2b29
movq %rcx, 0x48(%rsp)
movq 0x10(%rsp), %rax
movq %rdx, 0x40(%rsp)
leaq (%rax,%rdx,8), %r13
movl $0x18, %r15d
xorl %r12d, %r12d
movq $0x0, 0x28(%rsp)
movq %r13, 0x20(%rsp)
movq (%r13), %rax
movq (%rax,%r15), %rsi
testq %rsi, %rsi
js 0xa2aa7
movq -0x18(%rax,%r15), %rdi
movq %rdi, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r10
movl (%rbx,%r10,4), %edx
testl %edx, %edx
js 0xa2aa7
movl -0xc(%rax,%r15), %r11d
leaq (%r11,%r11,2), %r8
leaq (%rbx,%r8,4), %r8
movl (%r8), %r9d
testl %r9d, %r9d
js 0xa2aa7
movl 0x4(%r8), %r8d
subl %r9d, %r8d
testl %esi, %esi
movq %r11, 0x50(%rsp)
js 0xa29a6
movl -0x8(%rax,%r15), %r9d
movl -0x4(%rax,%r15), %r14d
subl %r14d, %r8d
movl %r8d, %ebp
movl %r9d, 0x8(%rsp)
movl %r9d, %r8d
jmp 0xa29b7
movl -0x8(%rax,%r15), %ebp
movl -0x4(%rax,%r15), %r14d
subl %r14d, %r8d
movl %ebp, 0x8(%rsp)
leaq (%rbx,%r10,4), %r9
movl 0x4(%r9), %r11d
subl %edx, %r11d
cmpl %edi, %r8d
movl %edi, %r9d
cmovll %r8d, %r9d
movl -0x10(%rax,%r15), %edx
movl %r11d, %r10d
movl %edx, 0xc(%rsp)
subl %edx, %r10d
cmpl %ebp, %r10d
movl %ebp, 0x4(%rsp)
cmovll %r10d, %ebp
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl 0x1c(%rsp), %edx
cmpl %edx, %r9d
jg 0xa2a56
cmpl %edx, %ebp
jg 0xa2a56
movl 0xc(%rsp), %edx
subl %edi, %edx
cvtsi2ss %rdx, %xmm1
addl %r9d, %edx
addl %ebp, %edx
cvtsi2ss %rdx, %xmm2
leaq 0x1f2d44(%rip), %r13    # 0x295758
movss 0x158(%r13), %xmm0
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
jbe 0xa2a2d
movq 0x20(%rsp), %r13
jmp 0xa2a56
subl 0x8(%rsp), %r14d
xorps %xmm1, %xmm1
cvtsi2ss %r14, %xmm1
addl %r9d, %ebp
addl %r14d, %ebp
xorps %xmm2, %xmm2
cvtsi2ss %rbp, %xmm2
mulss %xmm2, %xmm0
ucomiss %xmm1, %xmm0
movq 0x20(%rsp), %r13
jbe 0xa2abd
testl %ebx, %ebx
sets %dl
addl $0x3, %ebx
cmpl $0x2, %ebx
setae %dil
testb %dil, %dl
jne 0xa2a76
incq 0x28(%rsp)
movq 0x30(%rsp), %rbx
jmp 0xa2aa7
movabsq $-0x8000000000000000, %r14 # imm = 0x8000000000000000
orq %r14, %rsi
movq %rsi, (%rax,%r15)
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %rbx
movq %rbx, %rsi
movq 0x50(%rsp), %rdx
callq 0xa1aa3
testq %rax, %rax
je 0xa2aa7
orq %r14, 0x18(%rax)
incq %r12
movl 0xc(%r13), %eax
addq $0x28, %r15
cmpq %rax, %r12
jb 0xa2936
jmp 0xa2b17
cmpl 0x4(%rsp), %r10d
setl %r9b
setg %bl
cmpl %r8d, %edi
setg %r14b
setl %r10b
orb %bl, %r14b
cmpb $0x1, %r14b
jne 0xa2a6a
orb %r9b, %r10b
je 0xa2a6a
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
movl 0x18(%rsp), %r9d
cmpl %r9d, %edx
jl 0xa2a56
cmpl %r9d, %ebp
jl 0xa2a56
movl 0x4(%rsp), %edx
addl 0xc(%rsp), %edx
subl %edx, %r11d
subl %r8d, %edi
cmovlel %r11d, %edi
movl %edi, %ebx
jmp 0xa2a56
cmpq $0x0, 0x28(%rsp)
movq 0x48(%rsp), %rcx
movq 0x40(%rsp), %rdx
jne 0xa2b2e
orb $-0x80, 0x3(%rbx,%rdx,4)
incq %rcx
cmpq 0x38(%rsp), %rcx
jne 0xa28f8
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq