// File: 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
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movss %xmm0, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0xd1d3a
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jge 0xd1d38
movq -0x58(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0xd1bdd
jmp 0xd1d27
leaq 0x2f36ec(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
movzbl (%rax,%rcx), %eax
cmpl -0x30(%rbp), %eax
jne 0xd1c08
jmp 0xd1d27
movq -0x58(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x4c(%rbp)
movq -0x58(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0xd1d25
movl -0x50(%rbp), %eax
cmpq -0x18(%rbp), %rax
je 0xd1d25
movl -0x4c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0xd1ca8
movl -0x50(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0xd1ca8
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl -0x4c(%rbp), %ecx
subl %ecx, %eax
cvtsi2ss %rax, %xmm0
movss -0x2c(%rbp), %xmm1
movl -0x50(%rbp), %eax
subl %ecx, %eax
cvtsi2ss %rax, %xmm2
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xd1ca8
movl -0x50(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0xd1ca6
movl -0x50(%rbp), %eax
cmpq -0x40(%rbp), %rax
jle 0xd1ca6
movl -0x50(%rbp), %eax
movq %rax, -0x40(%rbp)
jmp 0xd1ca8
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0xd1d23
movl -0x50(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jbe 0xd1d23
movl -0x50(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %eax, %ecx
subl %edx, %ecx
cvtsi2ss %rcx, %xmm0
movss -0x2c(%rbp), %xmm1
movl -0x4c(%rbp), %ecx
subl %ecx, %eax
cvtsi2ss %rax, %xmm2
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xd1d23
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0xd1d21
movl -0x4c(%rbp), %eax
cmpq -0x48(%rbp), %rax
jge 0xd1d21
movl -0x4c(%rbp), %eax
movq %rax, -0x48(%rbp)
jmp 0xd1d23
jmp 0xd1d25
jmp 0xd1d27
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xd1ba8
jmp 0xd1d3a
cmpq $0x0, -0x10(%rbp)
je 0xd1ee7
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jge 0xd1ee5
movq -0x58(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0xd1d8a
jmp 0xd1ed4
leaq 0x2f353f(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
movzbl (%rax,%rcx), %eax
cmpl -0x30(%rbp), %eax
jne 0xd1db5
jmp 0xd1ed4
movq -0x58(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x4c(%rbp)
movq -0x58(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0xd1ed2
movl -0x50(%rbp), %eax
cmpq -0x18(%rbp), %rax
je 0xd1ed2
movl -0x4c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0xd1e55
movl -0x50(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0xd1e55
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl -0x4c(%rbp), %ecx
subl %ecx, %eax
cvtsi2ss %rax, %xmm0
movss -0x2c(%rbp), %xmm1
movl -0x50(%rbp), %eax
subl %ecx, %eax
cvtsi2ss %rax, %xmm2
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xd1e55
movl -0x50(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0xd1e53
movl -0x50(%rbp), %eax
cmpq -0x40(%rbp), %rax
jle 0xd1e53
movl -0x50(%rbp), %eax
movq %rax, -0x40(%rbp)
jmp 0xd1e55
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0xd1ed0
movl -0x50(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jbe 0xd1ed0
movl -0x50(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %eax, %ecx
subl %edx, %ecx
cvtsi2ss %rcx, %xmm0
movss -0x2c(%rbp), %xmm1
movl -0x4c(%rbp), %ecx
subl %ecx, %eax
cvtsi2ss %rax, %xmm2
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xd1ed0
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0xd1ece
movl -0x4c(%rbp), %eax
cmpq -0x48(%rbp), %rax
jge 0xd1ece
movl -0x4c(%rbp), %eax
movq %rax, -0x48(%rbp)
jmp 0xd1ed0
jmp 0xd1ed2
jmp 0xd1ed4
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xd1d55
jmp 0xd1ee7
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x48(%rbp), %rax
movl %eax, %edx
movq -0x28(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, (%rax)
popq %rbp
retq
nopw %cs:(%rax,%rax)