// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: collect_contain(ma_hit_t_alloc*, ma_hit_t_alloc*, unsigned long, ma_sub_t*, ma_sub_t*, float)
void collect_contain(ma_hit_t_alloc* paf1, ma_hit_t_alloc* paf2, uint64_t rLen, 
ma_sub_t* max_left, ma_sub_t* max_right, float overlap_rate)
{
    long long j, new_left_e, new_right_s;
    new_left_e = max_left->e;
    new_right_s = max_right->s;
    uint32_t qs, qe;
    ma_hit_t_alloc* paf;

    if(paf1 != NULL)
    {
        paf = paf1;
        for (j = 0; j < paf->length; j++)
        {
            if(paf->buffer[j].del) continue;

            qs = Get_qs(paf->buffer[j]);
            qe = Get_qe(paf->buffer[j]);
            ///check contained overlaps
            if(qs != 0 && qe != rLen)
            {
                ///[qs, qe), [max_left.s, max_left.e)
                if(qs < max_left->e && qe > max_left->e && max_left->e - qs > (overlap_rate * (qe -qs)))
                {
                    ///if(qe > max_left->e) max_left->e = qe;
                    if(qe > max_left->e && qe > new_left_e) new_left_e = qe;
                }

                ///[qs, qe), [max_right.s, max_right.e)
                if(qs < max_right->s && qe > max_right->s && qe - max_right->s > (overlap_rate * (qe -qs)))
                {
                    ///if(qs < max_right->s) max_right->s = qs;
                    if(qs < max_right->s && qs < new_right_s) new_right_s = qs;
                }
            }
        }
    }

    if(paf2 != NULL)
    {
        paf = paf2;
        for (j = 0; j < paf->length; j++)
        {
            if(paf->buffer[j].del) continue;

            qs = Get_qs(paf->buffer[j]);
            qe = Get_qe(paf->buffer[j]);
            ///check contained overlaps
            if(qs != 0 && qe != rLen)
            {
                ///[qs, qe), [max_left.s, max_left.e)
                if(qs < max_left->e && qe > max_left->e && max_left->e - qs > (overlap_rate * (qe -qs)))
                {
                    ///if(qe > max_left->e) max_left->e = qe;
                    if(qe > max_left->e && qe > new_left_e) new_left_e = qe;
                }

                ///[qs, qe), [max_right.s, max_right.e)
                if(qs < max_right->s && qe > max_right->s && qe - max_right->s > (overlap_rate * (qe -qs)))
                {
                    ///if(qs < max_right->s) max_right->s = qs;
                    if(qs < max_right->s && qs < new_right_s) new_right_s = qs;
                }
            }
        }
    }

    max_left->e = new_left_e;
    max_right->s = new_right_s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl 0x4(%rcx), %eax
movl (%r8), %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
testq %rdi, %rdi
je 0xa2854
movl 0xc(%rdi), %r10d
testq %r10, %r10
je 0xa2854
movq (%rdi), %r11
shlq $0x3, %r10
leaq (%r10,%r10,4), %rbx
xorl %r14d, %r14d
movq %r9, %rdi
movq %rax, %r10
cmpq $0x0, 0x18(%r11,%r14)
js 0xa27d6
movq (%r11,%r14), %r15
testl %r15d, %r15d
je 0xa27d6
movl 0x8(%r11,%r14), %r12d
cmpq %rdx, %r12
jne 0xa27e1
addq $0x28, %r14
cmpq %r14, %rbx
jne 0xa27bb
jmp 0xa285a
cmpl %r15d, %eax
jbe 0xa281c
cmpl %eax, %r12d
jbe 0xa281c
movq %r10, %r13
cmpq %r12, %r10
jg 0xa27f6
movq %r12, %r13
movl %eax, %ebp
subl %r15d, %ebp
xorps %xmm1, %xmm1
cvtsi2ss %rbp, %xmm1
movl %r12d, %ebp
subl %r15d, %ebp
xorps %xmm2, %xmm2
cvtsi2ss %rbp, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
cmovaq %r13, %r10
cmpl %r15d, %r9d
jbe 0xa27d6
cmpl %r9d, %r12d
jbe 0xa27d6
movl %r12d, %r13d
subl %r9d, %r13d
xorps %xmm1, %xmm1
cvtsi2ss %r13, %xmm1
subl %r15d, %r12d
xorps %xmm2, %xmm2
cvtsi2ss %r12, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jbe 0xa27d6
movl %r15d, %r15d
cmpq %rdi, %r15
cmovlq %r15, %rdi
jmp 0xa27d6
movq %rax, %r10
movq %r9, %rdi
testq %rsi, %rsi
je 0xa2917
movl 0xc(%rsi), %r11d
testq %r11, %r11
je 0xa2917
movq (%rsi), %rsi
shlq $0x3, %r11
leaq (%r11,%r11,4), %r11
xorl %ebx, %ebx
cmpq $0x0, 0x18(%rsi,%rbx)
js 0xa2898
movq (%rsi,%rbx), %r14
testl %r14d, %r14d
je 0xa2898
movl 0x8(%rsi,%rbx), %r15d
cmpq %rdx, %r15
jne 0xa28a3
addq $0x28, %rbx
cmpq %rbx, %r11
jne 0xa287d
jmp 0xa2917
cmpl %r14d, %eax
jbe 0xa28df
cmpl %eax, %r15d
jbe 0xa28df
movq %r10, %r12
cmpq %r15, %r10
jg 0xa28b8
movq %r15, %r12
movl %eax, %r13d
subl %r14d, %r13d
xorps %xmm1, %xmm1
cvtsi2ss %r13, %xmm1
movl %r15d, %r13d
subl %r14d, %r13d
xorps %xmm2, %xmm2
cvtsi2ss %r13, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
cmovaq %r12, %r10
cmpl %r14d, %r9d
jbe 0xa2898
cmpl %r9d, %r15d
jbe 0xa2898
movl %r15d, %r12d
subl %r9d, %r12d
xorps %xmm1, %xmm1
cvtsi2ss %r12, %xmm1
subl %r14d, %r15d
xorps %xmm2, %xmm2
cvtsi2ss %r15, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jbe 0xa2898
movl %r14d, %r14d
cmpq %rdi, %r14
cmovlq %r14, %rdi
jmp 0xa2898
movl %r10d, 0x4(%rcx)
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl $0x80000000, %eax       # imm = 0x80000000
andl (%r8), %eax
orl %edi, %eax
movl %eax, (%r8)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq