// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: get_pair_purge_coverage(ma_utg_t*, long long, long long, ma_utg_t*, long long, long long, unsigned int, asg_t*, hap_cov_t*)
uint64_t get_pair_purge_coverage(ma_utg_t *xReads, long long xPosBeg, long long xPosEnd, 
ma_utg_t *yReads, long long yPosBeg, long long yPosEnd, uint32_t rev, asg_t *read_g, hap_cov_t *cov)
{
    long long offset, r_beg, r_end, i_beg, i_end, ovlp, IdxBeg, IdxEnd;
    uint64_t i, rId, uCov, uLen;
    ma_utg_t *x = NULL;
    uCov = uLen = 0;
    if(rev) 
    {
        yPosBeg = yReads->len - yPosBeg - 1;
        yPosEnd = yReads->len - yPosEnd - 1;
        offset = yPosBeg; yPosBeg = yPosEnd; yPosEnd = offset;
    }
    

    IdxBeg = IdxEnd = -1; 
    x = xReads; i_beg = xPosBeg; i_end = xPosEnd;
    for (i = 0, offset = 0; i < x->n; i++)
    {
        rId = x->a[i]>>33;
        r_beg = offset; r_end = offset + (long long)(read_g->seq[rId].len) - 1;
        offset += (uint32_t)x->a[i];
        ovlp = (long long)(MIN(r_end, i_end)) - (long long)(MAX(r_beg, i_beg)) + 1;
        if(ovlp <= 0 || ovlp < read_g->seq[rId].len * 0.8)
        {
            if(IdxBeg != -1 && IdxEnd != -1) break;
            continue;
        }

        if(IdxBeg == -1) IdxBeg = i;
        IdxEnd = i;
    }
    if(IdxBeg != -1 && IdxEnd != -1)
    {
        for (i = IdxBeg; (long long)i <= IdxEnd; i++)
        {
            rId = x->a[i]>>33;
            uCov += cov->cov[rId];
            uLen += cov->read_g->seq[rId].len;
        }
    }    



    IdxBeg = IdxEnd = -1; 
    x = yReads; i_beg = yPosBeg; i_end = yPosEnd;
    for (i = 0, offset = 0; i < x->n; i++)
    {
        rId = x->a[i]>>33;
        r_beg = offset; r_end = offset + (long long)(read_g->seq[rId].len) - 1;
        offset += (uint32_t)x->a[i];
        ovlp = (long long)(MIN(r_end, i_end)) - (long long)(MAX(r_beg, i_beg)) + 1;
        if(ovlp <= 0 || ovlp < read_g->seq[rId].len * 0.8)
        {
            if(IdxBeg != -1 && IdxEnd != -1) break;
            continue;
        }

        if(IdxBeg == -1) IdxBeg = i;
        IdxEnd = i;
    }
    if(IdxBeg != -1 && IdxEnd != -1)
    {
        for (i = IdxBeg; (long long)i <= IdxEnd; i++)
        {
            rId = x->a[i]>>33;
            uCov += cov->cov[rId];
            uLen += cov->read_g->seq[rId].len;
        }
    }

    return (uLen == 0? 0 : uCov / uLen);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %r12
cmpl $0x0, 0x38(%rsp)
je 0x10a844
movl (%rcx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
notq %r8
addq %rax, %r8
notq %r9
movq %r9, %rsi
addq %rax, %rsi
movq %r8, %r9
movq %rsi, %r8
movq 0x40(%rsp), %r13
movl 0x10(%rdi), %eax
testq %rax, %rax
movq %rcx, -0x10(%rsp)
je 0x10a969
movq %rdi, -0x8(%rsp)
movq 0x18(%rdi), %rcx
movq 0x20(%r13), %rdi
movq $-0x1, %rbx
xorl %r13d, %r13d
movsd 0x126d37(%rip), %xmm0   # 0x2315b0
movq $-0x1, %r14
xorl %ebp, %ebp
movq (%rcx,%r13,8), %r10
movq %r10, %r11
shrq $0x21, %r11
movl (%rdi,%r11,8), %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
leaq (%r11,%rbp), %r15
decq %r15
cmpq %rdx, %r15
cmovgeq %rdx, %r15
cmpq %r12, %rbp
movq %r12, %rsi
cmovgq %rbp, %rsi
subq %rsi, %r15
js 0x10a8d2
incq %r15
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r11d, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x10a8e9
cmpq $-0x1, %r14
setne %sil
cmpq $-0x1, %rbx
setne %r11b
testb %r11b, %sil
je 0x10a8f4
jmp 0x10a902
cmpq $-0x1, %r14
cmoveq %r13, %r14
movq %r13, %rbx
movl %r10d, %esi
addq %rsi, %rbp
incq %r13
cmpq %r13, %rax
jne 0x10a882
xorl %eax, %eax
cmpq $-0x1, %r14
je 0x10a96f
cmpq $-0x1, %rbx
movq -0x10(%rsp), %rcx
movq 0x40(%rsp), %r13
je 0x10a96b
movl $0x0, %esi
cmpq %rbx, %r14
jg 0x10a97b
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rdx
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x30(%rax), %rax
movq 0x20(%rax), %r10
xorl %esi, %esi
xorl %eax, %eax
movq (%rdx,%r14,8), %r15
shrq $0x21, %r15
movl (%rdi,%r15,4), %r11d
addq %r11, %rax
movl (%r10,%r15,8), %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
addq %r11, %rsi
incq %r14
cmpq %rbx, %r14
jle 0x10a942
jmp 0x10a97b
xorl %eax, %eax
xorl %esi, %esi
jmp 0x10a97b
xorl %esi, %esi
movq -0x10(%rsp), %rcx
movq 0x40(%rsp), %r13
movl 0x10(%rcx), %ebx
testq %rbx, %rbx
je 0x10aa7a
movq 0x18(%rcx), %r14
movq 0x20(%r13), %r11
movq $-0x1, %rdx
xorl %r15d, %r15d
movsd 0x126c0f(%rip), %xmm0   # 0x2315b0
movq $-0x1, %rdi
xorl %r12d, %r12d
movq (%r14,%r15,8), %r10
movq %r10, %rcx
shrq $0x21, %rcx
movl (%r11,%rcx,8), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
leaq (%r12,%r13), %rcx
decq %rcx
cmpq %r9, %rcx
cmovgeq %r9, %rcx
cmpq %r8, %r12
movq %r8, %rbp
cmovgq %r12, %rbp
subq %rbp, %rcx
js 0x10a9fb
incq %rcx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r13d, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x10aa11
cmpq $-0x1, %rdi
setne %cl
cmpq $-0x1, %rdx
setne %bpl
testb %bpl, %cl
je 0x10aa1c
jmp 0x10aa2a
cmpq $-0x1, %rdi
cmoveq %r15, %rdi
movq %r15, %rdx
movl %r10d, %ecx
addq %rcx, %r12
incq %r15
cmpq %r15, %rbx
jne 0x10a9ab
cmpq $-0x1, %rdi
je 0x10aa7a
cmpq $-0x1, %rdx
je 0x10aa7a
cmpq %rdx, %rdi
jg 0x10aa7a
movq -0x10(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0x48(%rsp), %r9
movq 0x8(%r9), %r8
movq 0x30(%r9), %r9
movq 0x20(%r9), %r9
movq (%rcx,%rdi,8), %r10
shrq $0x21, %r10
movl (%r8,%r10,4), %r11d
addq %r11, %rax
movl (%r9,%r10,8), %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
addq %r10, %rsi
incq %rdi
cmpq %rdx, %rdi
jle 0x10aa55
testq %rsi, %rsi
je 0x10aa86
xorl %edx, %edx
divq %rsi
jmp 0x10aa88
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq