// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: collect_trans_purge_joint_cov(hap_cov_t*, ma_ug_t*, hap_overlaps*)
void collect_trans_purge_joint_cov(hap_cov_t *cov, ma_ug_t *ug, hap_overlaps* x)
{
    if(ug->u.a[x->xUid].n == 0 || ug->u.a[x->yUid].n == 0) return;
    uint64_t *a[2], a_n[2], uCov[2], uLen[2], uDepth[2], i, rId;
    
    a[0] = ug->u.a[x->xUid].a + x->x_beg_id;
    a_n[0] = x->x_end_id - x->x_beg_id;
    uCov[0] = uLen[0] = 0;
    for (i = 0; i < a_n[0]; i++)
    {
        rId = a[0][i]>>33;
        uCov[0] += cov->cov[rId];
        uLen[0] += cov->read_g->seq[rId].len;
    }
    
    a[1] = ug->u.a[x->yUid].a + x->y_beg_id;
    a_n[1] = x->y_end_id - x->y_beg_id;
    uCov[1] = uLen[1] = 0;
    for (i = 0; i < a_n[1]; i++)
    {
        rId = a[1][i]>>33;
        uCov[1] += cov->cov[rId];
        uLen[1] += cov->read_g->seq[rId].len;
    }
    
    uDepth[0] = (uLen[0] == 0? 0 : uCov[1] / uLen[0]);
    uDepth[1] = (uLen[1] == 0? 0 : uCov[0] / uLen[1]);

    for (i = 0; i < a_n[0]; i++)
    {
        rId = a[0][i]>>33;
        cov->cov[rId] += (uDepth[0] * cov->read_g->seq[rId].len);
    }

    for (i = 0; i < a_n[1]; i++)
    {
        rId = a[1][i]>>33;
        cov->cov[rId] += (uDepth[1] * cov->read_g->seq[rId].len);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x10(%rsi), %rax
movl 0x24(%rdx), %ecx
imulq $0x28, %rcx, %rcx
cmpl $0x0, 0x10(%rax,%rcx)
je 0xcff7b
movl 0x28(%rdx), %esi
imulq $0x28, %rsi, %rsi
cmpl $0x0, 0x10(%rax,%rsi)
je 0xcff7b
addq %rax, %rcx
movl 0x14(%rdx), %r8d
movl 0x18(%rdx), %r9d
movq %r8, %r10
shlq $0x3, %r10
addq 0x18(%rcx), %r10
subl %r8d, %r9d
xorl %r14d, %r14d
xorl %ecx, %ecx
xorl %r8d, %r8d
cmpq %r8, %r9
je 0xcfe9e
movq (%r10,%r8,8), %r11
shrq $0x21, %r11
movq 0x8(%rdi), %rbx
movq 0x30(%rdi), %r15
movl (%rbx,%r11,4), %ebx
addq %rbx, %rcx
movq 0x20(%r15), %rbx
movl (%rbx,%r11,8), %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
addq %r11, %r14
incq %r8
jmp 0xcfe6b
movl 0x1c(%rdx), %r8d
movl 0x20(%rdx), %r11d
movq %r8, %rbx
shlq $0x3, %rbx
addq 0x18(%rax,%rsi), %rbx
subl %r8d, %r11d
xorl %r15d, %r15d
xorl %eax, %eax
xorl %edx, %edx
cmpq %rdx, %r11
je 0xcfeef
movq (%rbx,%rdx,8), %rsi
shrq $0x21, %rsi
movq 0x8(%rdi), %r8
movq 0x30(%rdi), %r12
movl (%r8,%rsi,4), %r8d
addq %r8, %rax
movq 0x20(%r12), %r8
movl (%r8,%rsi,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq %rsi, %r15
incq %rdx
jmp 0xcfebc
xorl %esi, %esi
movl $0x0, %r8d
testq %r14, %r14
je 0xcff04
xorl %edx, %edx
divq %r14
movq %rax, %r8
testq %r15, %r15
je 0xcff14
movq %rcx, %rax
xorl %edx, %edx
divq %r15
movq %rax, %rsi
xorl %eax, %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rax, %r9
je 0xcff47
movq (%r10,%rax,8), %rdx
shrq $0x21, %rdx
movq 0x8(%rdi), %r14
movq 0x30(%rdi), %r15
movq 0x20(%r15), %r15
movl (%r15,%rdx,8), %ebp
andl %ecx, %ebp
imull %r8d, %ebp
addl %ebp, (%r14,%rdx,4)
incq %rax
jmp 0xcff1b
xorl %eax, %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rax, %r11
je 0xcff7b
movq (%rbx,%rax,8), %rdx
shrq $0x21, %rdx
movq 0x8(%rdi), %r8
movq 0x30(%rdi), %r9
movq 0x20(%r9), %r9
movl (%r9,%rdx,8), %r9d
andl %ecx, %r9d
imull %esi, %r9d
addl %r9d, (%r8,%rdx,4)
incq %rax
jmp 0xcff4e
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq