// File: /workspace/github_cpp_makefile_star2_O2/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 0x6b2d3
movl 0xc(%rdi), %ecx
leaq 0x1e9013(%rip), %r11    # 0x254230
movq 0x28(%r11), %r14
imulq $0x28, %rcx, %r15
xorl %r12d, %r12d
movq %rax, %r11
movq %r10, %rcx
movq %rax, %r8
cmpq %r12, %r15
je 0x6b2dc
movq (%rdi), %rbx
cmpq $0x0, 0x18(%rbx,%r12)
js 0x6b267
movl 0xc(%rbx,%r12), %r13d
movzbl (%r14,%r13), %ebp
cmpl %r9d, %ebp
je 0x6b267
movq (%rbx,%r12), %r13
testl %r13d, %r13d
je 0x6b267
movl 0x8(%rbx,%r12), %ebp
cmpq %rdx, %rbp
jne 0x6b26d
addq $0x28, %r12
jmp 0x6b231
cmpl %r13d, %r8d
jbe 0x6b2a2
cmpl %r8d, %ebp
jbe 0x6b2a2
movq %r11, %rbx
cmpq %rbp, %r11
jg 0x6b282
movq %rbp, %rbx
movl %r8d, %eax
subl %r13d, %eax
cvtsi2ss %rax, %xmm1
movl %ebp, %eax
subl %r13d, %eax
cvtsi2ss %rax, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
cmovaq %rbx, %r11
cmpl %r13d, %r10d
jbe 0x6b267
cmpl %r10d, %ebp
jbe 0x6b267
movl %ebp, %eax
subl %r10d, %eax
cvtsi2ss %rax, %xmm1
subl %r13d, %ebp
cvtsi2ss %rbp, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jbe 0x6b267
movl %r13d, %eax
cmpq %rcx, %rax
cmovlq %rax, %rcx
jmp 0x6b267
movq %rax, %r11
movq %r10, %rcx
movq %rax, %r8
testq %rsi, %rsi
je 0x6b39d
movl 0xc(%rsi), %eax
leaq 0x1e8f41(%rip), %rdi    # 0x254230
movq 0x28(%rdi), %rdi
imulq $0x28, %rax, %r14
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x6b39d
movq (%rsi), %rbx
cmpq $0x0, 0x18(%rbx,%r15)
js 0x6b32f
movl 0xc(%rbx,%r15), %eax
movzbl (%rdi,%rax), %eax
cmpl %r9d, %eax
je 0x6b32f
movq (%rbx,%r15), %r12
testl %r12d, %r12d
je 0x6b32f
movl 0x8(%rbx,%r15), %r13d
cmpq %rdx, %r13
jne 0x6b335
addq $0x28, %r15
jmp 0x6b2fa
cmpl %r12d, %r8d
jbe 0x6b36b
cmpl %r8d, %r13d
jbe 0x6b36b
movq %r11, %rbx
cmpq %r13, %r11
jg 0x6b34a
movq %r13, %rbx
movl %r8d, %eax
subl %r12d, %eax
cvtsi2ss %rax, %xmm1
movl %r13d, %eax
subl %r12d, %eax
cvtsi2ss %rax, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
cmovaq %rbx, %r11
cmpl %r12d, %r10d
jbe 0x6b32f
cmpl %r10d, %r13d
jbe 0x6b32f
movl %r13d, %eax
subl %r10d, %eax
cvtsi2ss %rax, %xmm1
subl %r12d, %r13d
cvtsi2ss %r13, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jbe 0x6b32f
movl %r12d, %eax
cmpq %rcx, %rax
cmovlq %rax, %rcx
jmp 0x6b32f
movq -0x10(%rsp), %rax
movl %r11d, 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