// File: /workspace/github_cpp_makefile_star2_O1/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
cmpl $0x0, 0x38(%rsp)
je 0x106097
movl (%rcx), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
notq %r8
addq %rax, %r8
notq %r9
movq %r9, %r10
addq %rax, %r10
movq %r8, %r9
movq %r10, %r8
movq %r8, -0x8(%rsp)
movq 0x40(%rsp), %r8
movl 0x10(%rdi), %eax
testq %rax, %rax
movq %rdi, -0x10(%rsp)
je 0x106158
movq 0x18(%rdi), %rdi
movq 0x20(%r8), %r15
movq $-0x1, %rbx
xorl %r12d, %r12d
movsd 0x11f3e4(%rip), %xmm0   # 0x2254b0
movq $-0x1, %r11
xorl %r13d, %r13d
movq (%rdi,%r12,8), %rbp
movq %rbp, %r10
shrq $0x21, %r10
movl (%r15,%r10,8), %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
leaq (%r10,%r13), %r14
decq %r14
cmpq %rdx, %r14
cmovgeq %rdx, %r14
cmpq %rsi, %r13
movq %rsi, %r8
cmovgq %r13, %r8
subq %r8, %r14
js 0x106126
incq %r14
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r10d, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x10613d
cmpq $-0x1, %r11
setne %r8b
cmpq $-0x1, %rbx
setne %r10b
testb %r10b, %r8b
je 0x106148
jmp 0x106166
cmpq $-0x1, %r11
cmoveq %r12, %r11
movq %r12, %rbx
movl %ebp, %r8d
addq %r8, %r13
incq %r12
cmpq %r12, %rax
jne 0x1060d6
jmp 0x106166
movq $-0x1, %r11
movq $-0x1, %rbx
movq 0x48(%rsp), %rdx
xorl %eax, %eax
cmpq $-0x1, %r11
je 0x1061c2
cmpq $-0x1, %rbx
je 0x1061c2
movl $0x0, %esi
cmpq %rbx, %r11
jg 0x1061c4
movq -0x10(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x8(%rdx), %r14
movq 0x30(%rdx), %rax
movq 0x20(%rax), %r15
xorl %esi, %esi
xorl %eax, %eax
movq (%rdi,%r11,8), %rdx
shrq $0x21, %rdx
movl (%r14,%rdx,4), %r10d
addq %r10, %rax
movl (%r15,%rdx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
addq %rdx, %rsi
incq %r11
cmpq %rbx, %r11
jle 0x10619c
jmp 0x1061c4
xorl %esi, %esi
movl 0x10(%rcx), %r11d
testq %r11, %r11
je 0x10627e
movq %rcx, %rdx
movq 0x18(%rcx), %rbx
movq 0x40(%rsp), %rcx
movq 0x20(%rcx), %r14
movq $-0x1, %r10
xorl %r15d, %r15d
movsd 0x11f2bd(%rip), %xmm0   # 0x2254b0
movq $-0x1, %rdi
xorl %r12d, %r12d
movq (%rbx,%r15,8), %r13
movq %r13, %rcx
shrq $0x21, %rcx
movl (%r14,%rcx,8), %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
leaq (%r12,%rbp), %rcx
decq %rcx
cmpq %r9, %rcx
cmovgeq %r9, %rcx
movq -0x8(%rsp), %r8
cmpq %r8, %r12
cmovgq %r12, %r8
subq %r8, %rcx
js 0x10624d
incq %rcx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %ebp, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x106263
cmpq $-0x1, %rdi
setne %cl
cmpq $-0x1, %r10
setne %r8b
testb %r8b, %cl
je 0x10626e
jmp 0x10628f
cmpq $-0x1, %rdi
cmoveq %r15, %rdi
movq %r15, %r10
movl %r13d, %ecx
addq %rcx, %r12
incq %r15
cmpq %r15, %r11
jne 0x1061fd
jmp 0x10628f
movq %rcx, %rdx
movq $-0x1, %rdi
movq $-0x1, %r10
cmpq $-0x1, %rdi
je 0x1062da
cmpq $-0x1, %r10
je 0x1062da
cmpq %r10, %rdi
jg 0x1062da
movq 0x18(%rdx), %rcx
movq 0x48(%rsp), %rdx
movq 0x8(%rdx), %r8
movq 0x30(%rdx), %rdx
movq 0x20(%rdx), %rdx
movq (%rcx,%rdi,8), %r9
shrq $0x21, %r9
movl (%r8,%r9,4), %r11d
addq %r11, %rax
movl (%rdx,%r9,8), %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
addq %r9, %rsi
incq %rdi
cmpq %r10, %rdi
jle 0x1062b5
testq %rsi, %rsi
je 0x1062e6
xorl %edx, %edx
divq %rsi
jmp 0x1062e8
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq