// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
movq 0x10(%rsi), %rax
movl 0x24(%rdx), %ecx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
je 0x10efcc
movl 0x28(%rdx), %esi
leaq (%rsi,%rsi,4), %rsi
cmpl $0x0, 0x10(%rax,%rsi,8)
je 0x10efcc
leaq (%rax,%rcx,8), %rcx
movl 0x14(%rdx), %r9d
movl 0x18(%rdx), %r10d
movq %r9, %r8
shlq $0x3, %r8
addq 0x18(%rcx), %r8
movl %r10d, -0x24(%rsp)
movl %r10d, %r14d
movq %r9, -0x10(%rsp)
subl %r9d, %r14d
movq %r14, -0x8(%rsp)
jne 0x10ee5e
xorl %r12d, %r12d
xorl %ecx, %ecx
jmp 0x10ee9f
movq 0x8(%rdi), %rbx
movq 0x30(%rdi), %rcx
cmpq $0x1, %r14
adcq $0x0, %r14
movq 0x20(%rcx), %r11
xorl %r15d, %r15d
xorl %ecx, %ecx
xorl %r12d, %r12d
movq (%r8,%r15,8), %r10
shrq $0x21, %r10
movl (%rbx,%r10,4), %r13d
addq %r13, %rcx
movl (%r11,%r10,8), %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
addq %r10, %r12
incq %r15
cmpq %r15, %r14
jne 0x10ee7a
movl 0x1c(%rdx), %r9d
movq %r9, %rbx
shlq $0x3, %rbx
addq 0x18(%rax,%rsi,8), %rbx
movl 0x20(%rdx), %eax
xorl %esi, %esi
movl %eax, -0x28(%rsp)
movl %eax, %r11d
movq %r9, -0x18(%rsp)
subl %r9d, %r11d
movq %rdi, -0x20(%rsp)
jne 0x10eed1
xorl %r13d, %r13d
xorl %eax, %eax
jmp 0x10ef16
movq 0x8(%rdi), %rdx
movq 0x30(%rdi), %rax
cmpq $0x1, %r11
movq %r11, %r14
adcq $0x0, %r14
movq 0x20(%rax), %rbp
xorl %r10d, %r10d
xorl %eax, %eax
xorl %r13d, %r13d
movq (%rbx,%r10,8), %r15
shrq $0x21, %r15
movl (%rdx,%r15,4), %r9d
addq %r9, %rax
movl (%rbp,%r15,8), %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
addq %r9, %r13
incq %r10
cmpq %r10, %r14
jne 0x10eef0
testq %r12, %r12
je 0x10ef23
xorl %edx, %edx
divq %r12
movq %rax, %rsi
testq %r13, %r13
movq -0x8(%rsp), %rdi
je 0x10ef37
movq %rcx, %rax
xorl %edx, %edx
divq %r13
jmp 0x10ef39
xorl %eax, %eax
movl -0x24(%rsp), %ecx
cmpl -0x10(%rsp), %ecx
je 0x10ef83
movq -0x20(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq 0x30(%rdx), %rdx
movq 0x20(%rdx), %rdx
cmpq $0x1, %rdi
adcq $0x0, %rdi
xorl %r10d, %r10d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq (%r8,%r10,8), %r9
shrq $0x21, %r9
movl (%rdx,%r9,8), %r14d
andl %ebp, %r14d
imull %esi, %r14d
addl %r14d, (%rcx,%r9,4)
incq %r10
cmpq %r10, %rdi
jne 0x10ef64
movl -0x28(%rsp), %ecx
cmpl -0x18(%rsp), %ecx
movq -0x20(%rsp), %rdx
je 0x10efcc
movq 0x8(%rdx), %rcx
movq 0x30(%rdx), %rdx
movq 0x20(%rdx), %rdx
cmpq $0x1, %r11
adcq $0x0, %r11
xorl %esi, %esi
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq (%rbx,%rsi,8), %r8
shrq $0x21, %r8
movl (%rdx,%r8,8), %r9d
andl %edi, %r9d
imull %eax, %r9d
addl %r9d, (%rcx,%r8,4)
incq %rsi
cmpq %rsi, %r11
jne 0x10efad
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq