// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: ma_hit_contained_advance(ma_hit_t_alloc*, long long, ma_sub_t*, R_to_U*, int, int)
void ma_hit_contained_advance(ma_hit_t_alloc* sources, long long n_read, ma_sub_t *coverage_cut, 
R_to_U* ruIndex, int max_hang, int min_ovlp)
{
    ///uint32_t qn_num = 0, no_fully_qn_num = 0, tn_num = 0, no_fully_tn_num = 0;
    double startTime = Get_T();
	int32_t r;
	long long i, j, m;
	asg_arc_t t;
    ma_hit_t *h = NULL;
    ma_sub_t *sq = NULL;
    ma_sub_t *st = NULL;


    for (i = 0; i < n_read; ++i) 
    {
        if(coverage_cut[i].del) continue;

        for (j = 0; j < (long long)sources[i].length; j++)
        {
            h = &(sources[i].buffer[j]);
            //check the corresponding two reads 
		    sq = &(coverage_cut[Get_qn(*h)]);
            st = &(coverage_cut[Get_tn(*h)]);
            /****************************may have trio bugs********************************/
            if(sq->del || st->del) continue;
            if(h->del) continue;
            /****************************may have trio bugs********************************/
            r = ma_hit2arc(h, sq->e - sq->s, st->e - st->s, max_hang, asm_opt.max_hang_rate, min_ovlp, &t);
            ///r could not be MA_HT_SHORT_OVLP or MA_HT_INT
            if (r == MA_HT_QCONT) 
            {
                h->del = 1;
                delete_single_edge(sources, coverage_cut, Get_tn(*h), Get_qn(*h));
        
                delete_all_edges(sources, coverage_cut, Get_qn(*h));
                set_R_to_U(ruIndex, Get_qn(*h), Get_tn(*h), 0, NULL);
            }
		    else if (r == MA_HT_TCONT) 
            {
                h->del = 1;
                delete_single_edge(sources, coverage_cut, Get_tn(*h), Get_qn(*h));

                delete_all_edges(sources, coverage_cut, Get_tn(*h));
                set_R_to_U(ruIndex, Get_tn(*h), Get_qn(*h), 0, NULL);
            }
        }
    }

    transfor_R_to_U(ruIndex);


    for (i = 0; i < n_read; ++i) 
    {
        m = 0;
        for (j = 0; j < (long long)sources[i].length; j++)
        {
            ma_hit_t *h = &(sources[i].buffer[j]);
            if(h->del) continue;
            ///both the qn and tn have not been deleted
            if(coverage_cut[Get_qn(*h)].del != 1 && coverage_cut[Get_tn(*h)].del != 1)
            {
                h->del = 0;
                m++;
            }
            else
            {
                h->del = 1;
            }
        }

        ///if sources[i].length == 0, that means all overlapped reads with read i are the contained reads
        if(m == 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 $0x48, %rsp
movl %r9d, 0x8(%rsp)
movl %r8d, 0x14(%rsp)
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, (%rsp)
callq 0x2f3fc
movq %r14, 0x20(%rsp)
testq %r14, %r14
jle 0xa27d3
movq %r15, 0x18(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
leaq (%rax,%rax,2), %rax
cmpl $0x0, (%rbx,%rax,4)
js 0xa270a
movq (%rsp), %rcx
cmpl $0x0, 0xc(%rcx,%rax,8)
je 0xa270a
movq (%rsp), %rcx
leaq (%rcx,%rax,8), %r15
movl $0x18, %r13d
xorl %r14d, %r14d
movq (%r15), %r12
movq -0x18(%r12,%r13), %rax
movq %rax, %rbp
shrq $0x20, %rbp
leaq (,%rbp,2), %r8
addq %rbp, %r8
movl (%rbx,%r8,4), %edi
testl %edi, %edi
js 0xa26c5
movl -0xc(%r12,%r13), %ecx
movq %rcx, 0x28(%rsp)
leaq (%rcx,%rcx,2), %rcx
leaq (%rbx,%rcx,4), %rdx
movl (%rdx), %esi
testl %esi, %esi
js 0xa26c5
movq (%r12,%r13), %rcx
testq %rcx, %rcx
js 0xa26c5
movl 0x4(%rdx), %edx
subl %esi, %edx
testl %ecx, %ecx
js 0xa251a
movl -0x8(%r12,%r13), %r10d
movl -0x4(%r12,%r13), %esi
movq %rsi, 0x38(%rsp)
subl %esi, %edx
movl %edx, %r9d
movl %r10d, 0xc(%rsp)
movl %r10d, %edx
jmp 0xa2530
movl -0x8(%r12,%r13), %r9d
movl -0x4(%r12,%r13), %esi
movq %rsi, 0x38(%rsp)
subl %esi, %edx
movl %r9d, 0xc(%rsp)
leaq (%rbx,%r8,4), %rsi
movl 0x4(%rsi), %r8d
subl %edi, %r8d
cmpl %eax, %edx
movl %eax, %esi
cmovll %edx, %esi
movl -0x10(%r12,%r13), %r10d
movl %r8d, %edi
movl %r10d, 0x10(%rsp)
subl %r10d, %edi
cmpl %r9d, %edi
movl %r9d, %r10d
cmovll %edi, %r10d
cmpl 0x14(%rsp), %esi
jg 0xa26c5
cmpl 0x14(%rsp), %r10d
jg 0xa26c5
movl 0x10(%rsp), %r11d
subl %eax, %r11d
xorps %xmm1, %xmm1
cvtsi2ss %r11, %xmm1
addl %esi, %r11d
addl %r10d, %r11d
xorps %xmm2, %xmm2
cvtsi2ss %r11, %xmm2
movl %r9d, 0x34(%rsp)
movq %rbx, %r9
movq %r15, %rbx
movq %rcx, %r15
leaq 0x1f31b4(%rip), %rcx    # 0x295758
movss 0x158(%rcx), %xmm0
movq %r15, %rcx
movq %rbx, %r15
movq %r9, %rbx
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
ja 0xa26c5
movq %rcx, %r9
movq 0x38(%rsp), %rcx
subl 0xc(%rsp), %ecx
xorps %xmm1, %xmm1
cvtsi2ss %rcx, %xmm1
addl %esi, %r10d
addl %ecx, %r10d
movl 0x34(%rsp), %esi
xorps %xmm2, %xmm2
cvtsi2ss %r10, %xmm2
mulss %xmm2, %xmm0
ucomiss %xmm1, %xmm0
ja 0xa26c5
cmpl %edx, %eax
jg 0xa2653
cmpl %esi, %edi
jg 0xa2653
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
orq %rax, %r9
movq %r9, (%r12,%r13)
movq (%rsp), %rdi
movq %rbx, %rsi
movq 0x28(%rsp), %rdx
movl %ebp, %ecx
callq 0xa1aa3
testq %rax, %rax
je 0xa2639
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orq %rcx, 0x18(%rax)
movl -0x14(%r12,%r13), %ebp
movq (%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0xa1b26
movl -0x14(%r12,%r13), %esi
movl -0xc(%r12,%r13), %edx
jmp 0xa26b6
cmpl %edx, %eax
jl 0xa26db
cmpl %esi, %edi
jl 0xa26db
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
orq %rax, %r9
movq %r9, (%r12,%r13)
movq (%rsp), %rdi
movq %rbx, %rsi
movq 0x28(%rsp), %rdx
movl %ebp, %ecx
callq 0xa1aa3
movq 0x28(%rsp), %rdx
testq %rax, %rax
je 0xa26a0
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orq %rcx, 0x18(%rax)
movl -0xc(%r12,%r13), %edx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0xa1b26
movl -0x14(%r12,%r13), %edx
movl -0xc(%r12,%r13), %esi
movq 0x18(%rsp), %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xa27e9
incq %r14
movl 0xc(%r15), %eax
addq $0x28, %r13
cmpq %rax, %r14
jb 0xa24a4
jmp 0xa270a
cmpl 0x8(%rsp), %r11d
jl 0xa26c5
cmpl 0x8(%rsp), %r10d
jl 0xa26c5
addl 0x10(%rsp), %esi
subl %esi, %r8d
subl %edx, %eax
cmovlel %r8d, %eax
cmpl $-0x3, %eax
je 0xa265f
cmpl $-0x2, %eax
je 0xa25fd
jmp 0xa26c5
movq 0x40(%rsp), %rax
incq %rax
cmpq 0x20(%rsp), %rax
jne 0xa2471
movq 0x18(%rsp), %rdi
callq 0xa286b
cmpq $0x0, 0x20(%rsp)
movabsq $-0x8000000000000000, %r15 # imm = 0x8000000000000000
jle 0xa27c4
xorl %eax, %eax
leaq (%rax,%rax,2), %rcx
movq (%rsp), %rdx
movl 0xc(%rdx,%rcx,8), %edx
testl %edx, %edx
je 0xa27b1
movq (%rsp), %rsi
leaq (%rsi,%rcx,8), %rsi
movl $0x18, %edi
xorl %r8d, %r8d
xorl %r9d, %r9d
movq (%rsi), %r10
movq (%r10,%rdi), %r11
testq %r11, %r11
js 0xa279d
movl -0x14(%r10,%rdi), %r14d
leaq (%r14,%r14,2), %r14
cmpl $0x0, (%rbx,%r14,4)
js 0xa2793
movl -0xc(%r10,%rdi), %r14d
leaq (%r14,%r14,2), %r14
cmpl $0x0, (%rbx,%r14,4)
js 0xa2793
incq %r8
jmp 0xa279d
orq %r15, %r11
movq %r11, (%r10,%rdi)
movl 0xc(%rsi), %edx
incq %r9
movl %edx, %r10d
addq $0x28, %rdi
cmpq %r10, %r9
jb 0xa2762
testq %r8, %r8
jne 0xa27b6
orb $-0x80, 0x3(%rbx,%rcx,4)
incq %rax
cmpq 0x20(%rsp), %rax
jne 0xa273f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa286b