// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: collect_contain_trio(ma_hit_t_alloc*, ma_hit_t_alloc*, unsigned long, ma_sub_t*, ma_sub_t*, float, unsigned int)
void collect_contain_trio(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, uint32_t trio_flag)
{
    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;

            if(R_INF.trio_flag[Get_tn(paf->buffer[j])] == trio_flag) 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;

            if(R_INF.trio_flag[Get_tn(paf->buffer[j])] == trio_flag) 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
movq %rcx, -0x10(%rsp)
movl 0x4(%rcx), %eax
movq %r8, -0x8(%rsp)
movl (%r8), %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
testq %rdi, %rdi
je 0xa310a
movq %rax, %r8
movl 0xc(%rdi), %ecx
testq %rcx, %rcx
je 0xa3115
movq (%rdi), %rbx
leaq 0x1f31e5(%rip), %rdi    # 0x296230
movq 0x28(%rdi), %r14
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %r15
xorl %r12d, %r12d
movq %r10, %rcx
movq %r8, %rdi
cmpq $0x0, 0x18(%rbx,%r12)
js 0xa308a
movl 0xc(%rbx,%r12), %r11d
movzbl (%r14,%r11), %r11d
cmpl %r9d, %r11d
je 0xa308a
movq (%rbx,%r12), %r13
testl %r13d, %r13d
je 0xa308a
movl 0x8(%rbx,%r12), %ebp
cmpq %rdx, %rbp
jne 0xa3098
addq $0x28, %r12
cmpq %r12, %r15
jne 0xa3060
jmp 0xa311b
cmpl %r13d, %r8d
jbe 0xa30d3
cmpl %r8d, %ebp
jbe 0xa30d3
movq %rdi, %r11
cmpq %rbp, %rdi
jg 0xa30ad
movq %rbp, %r11
movl %r8d, %eax
subl %r13d, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
movl %ebp, %eax
subl %r13d, %eax
xorps %xmm2, %xmm2
cvtsi2ss %rax, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
cmovaq %r11, %rdi
cmpl %r13d, %r10d
jbe 0xa308a
cmpl %r10d, %ebp
jbe 0xa308a
movl %ebp, %eax
subl %r10d, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
subl %r13d, %ebp
xorps %xmm2, %xmm2
cvtsi2ss %rbp, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jbe 0xa308a
movl %r13d, %eax
cmpq %rcx, %rax
cmovlq %rax, %rcx
jmp 0xa308a
movq %rax, %rdi
movq %r10, %rcx
movq %rax, %r8
jmp 0xa311b
movq %r8, %rdi
movq %r10, %rcx
testq %rsi, %rsi
je 0xa31f2
movl 0xc(%rsi), %r11d
testq %r11, %r11
je 0xa31f2
movq (%rsi), %rsi
leaq 0x1f30f5(%rip), %rax    # 0x296230
movq 0x28(%rax), %rbx
shlq $0x3, %r11
leaq (%r11,%r11,4), %r14
xorl %r15d, %r15d
cmpq $0x0, 0x18(%rsi,%r15)
js 0xa3173
movl 0xc(%rsi,%r15), %eax
movzbl (%rbx,%rax), %eax
cmpl %r9d, %eax
je 0xa3173
movq (%rsi,%r15), %r12
testl %r12d, %r12d
je 0xa3173
movl 0x8(%rsi,%r15), %r13d
cmpq %rdx, %r13
jne 0xa317e
addq $0x28, %r15
cmpq %r15, %r14
jne 0xa314a
jmp 0xa31f2
cmpl %r12d, %r8d
jbe 0xa31ba
cmpl %r8d, %r13d
jbe 0xa31ba
movq %rdi, %r11
cmpq %r13, %rdi
jg 0xa3193
movq %r13, %r11
movl %r8d, %eax
subl %r12d, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
movl %r13d, %eax
subl %r12d, %eax
xorps %xmm2, %xmm2
cvtsi2ss %rax, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
cmovaq %r11, %rdi
cmpl %r12d, %r10d
jbe 0xa3173
cmpl %r10d, %r13d
jbe 0xa3173
movl %r13d, %eax
subl %r10d, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
subl %r12d, %r13d
xorps %xmm2, %xmm2
cvtsi2ss %r13, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jbe 0xa3173
movl %r12d, %eax
cmpq %rcx, %rax
cmovlq %rax, %rcx
jmp 0xa3173
movq -0x10(%rsp), %rax
movl %edi, 0x4(%rax)
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl $0x80000000, %eax       # imm = 0x80000000
movq -0x8(%rsp), %rdx
andl (%rdx), %eax
orl %ecx, %eax
movl %eax, (%rdx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq