// File: 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
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)
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 0xd236b
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 0xd2369
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 0xd2239
jmp 0xd2358
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 0xd2356
movl -0x50(%rbp), %eax
cmpq -0x18(%rbp), %rax
je 0xd2356
movl -0x4c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0xd22d9
movl -0x50(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0xd22d9
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 0xd22d9
movl -0x50(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0xd22d7
movl -0x50(%rbp), %eax
cmpq -0x40(%rbp), %rax
jle 0xd22d7
movl -0x50(%rbp), %eax
movq %rax, -0x40(%rbp)
jmp 0xd22d9
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0xd2354
movl -0x50(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jbe 0xd2354
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 0xd2354
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0xd2352
movl -0x4c(%rbp), %eax
cmpq -0x48(%rbp), %rax
jge 0xd2352
movl -0x4c(%rbp), %eax
movq %rax, -0x48(%rbp)
jmp 0xd2354
jmp 0xd2356
jmp 0xd2358
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xd2204
jmp 0xd236b
cmpq $0x0, -0x10(%rbp)
je 0xd24ed
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 0xd24eb
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 0xd23bb
jmp 0xd24da
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 0xd24d8
movl -0x50(%rbp), %eax
cmpq -0x18(%rbp), %rax
je 0xd24d8
movl -0x4c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0xd245b
movl -0x50(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0xd245b
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 0xd245b
movl -0x50(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0xd2459
movl -0x50(%rbp), %eax
cmpq -0x40(%rbp), %rax
jle 0xd2459
movl -0x50(%rbp), %eax
movq %rax, -0x40(%rbp)
jmp 0xd245b
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0xd24d6
movl -0x50(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jbe 0xd24d6
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 0xd24d6
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0xd24d4
movl -0x4c(%rbp), %eax
cmpq -0x48(%rbp), %rax
jge 0xd24d4
movl -0x4c(%rbp), %eax
movq %rax, -0x48(%rbp)
jmp 0xd24d6
jmp 0xd24d8
jmp 0xd24da
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xd2386
jmp 0xd24ed
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
nopl (%rax,%rax)