// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: gen_cov_rg(ma_ug_t*, asg_t*, ma_hit_t_alloc*)
uint64_t *gen_cov_rg(ma_ug_t *ug, asg_t *sg, ma_hit_t_alloc *src)
{
    uint32_t i, k, rid, j, tn; uint8_t *ff; 
    uint64_t C_bases, *cc; ma_hit_t *h; ma_utg_t *u;
    CALLOC(cc, sg->n_seq); CALLOC(ff, sg->n_seq);

    for (i = 0; i < ug->g->n_seq; i++) {
        if(ug->g->seq[i].del) continue;
        set_rset(ug, i, ff, 1);

        u = &(ug->u.a[i]);
        for (k = 0; k < u->n; k++) {
            C_bases = 0; rid = u->a[k]>>33;
            for (j = 0; j < src[rid].length; j++) {
                h = &(src[rid].buffer[j]);
                tn = Get_tn((*h));
                if((!sg->seq[tn].del) && (!ff[tn])) continue;
                if((sg->seq[tn].del) && (!check_nc_status(sg, src, ff, tn))) continue;
                C_bases += (Get_qe((*h)) - Get_qs((*h)));
            }
            if(C_bases > cc[rid]) cc[rid] = C_bases;
        }

        set_rset(ug, i, ff, 0);
    }
    free(ff);

    return cc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, 0x8(%rsp)
movq %rdi, %r14
movq %rsi, 0x18(%rsp)
movl 0x14(%rsi), %r13d
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andq %rbx, %r13
movl $0x8, %esi
movq %r13, %rdi
callq 0x2120
movq %rax, (%rsp)
movl $0x1, %esi
movq %r13, %rdi
callq 0x2120
movq %rax, %r13
movq %r14, 0x10(%rsp)
movq 0x18(%r14), %rax
movl 0x14(%rax), %ecx
andq %rbx, %rcx
movq %rcx, 0x28(%rsp)
je 0xc6b7f
movq 0x20(%rax), %rax
movq %rax, 0x20(%rsp)
xorl %esi, %esi
movq 0x20(%rsp), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0xc6b71
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rdx
movq %rsi, %r14
movl $0x1, %ecx
callq 0xc680d
movq 0x10(%rbx), %rax
movq %r14, 0x30(%rsp)
leaq (%r14,%r14,4), %rcx
movl 0x10(%rax,%rcx,8), %edx
movq %rdx, 0x40(%rsp)
testq %rdx, %rdx
je 0xc6b58
leaq (%rax,%rcx,8), %rax
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
xorl %edx, %edx
movq 0x38(%rsp), %rax
movq (%rax,%rdx,8), %rsi
shrq $0x21, %rsi
leaq (%rsi,%rsi,2), %rcx
movq 0x8(%rsp), %rax
movl 0xc(%rax,%rcx,8), %eax
testq %rax, %rax
je 0xc6b4a
movq %rsi, 0x48(%rsp)
movq %rdx, 0x50(%rsp)
movq 0x8(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
movq (%rcx), %r15
movq 0x18(%rsp), %rcx
movq 0x20(%rcx), %r14
shlq $0x3, %rax
leaq (%rax,%rax,4), %rbp
xorl %r12d, %r12d
xorl %ebx, %ebx
movl 0xc(%r15,%r12), %ecx
cmpl $0x0, (%r14,%rcx,8)
js 0xc6b16
cmpb $0x0, (%r13,%rcx)
je 0xc6b0b
movl 0x8(%r15,%r12), %eax
subl (%r15,%r12), %eax
addq %rax, %rbx
addq $0x28, %r12
cmpq %r12, %rbp
jne 0xc6aeb
jmp 0xc6b2e
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
callq 0xc6974
testl %eax, %eax
jne 0xc6aff
jmp 0xc6b0b
movq (%rsp), %rax
movq 0x48(%rsp), %rcx
cmpq (%rax,%rcx,8), %rbx
movq 0x50(%rsp), %rdx
jbe 0xc6b4a
movq (%rsp), %rax
movq %rbx, (%rax,%rcx,8)
incq %rdx
cmpq 0x40(%rsp), %rdx
jne 0xc6a9c
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %rbx
movl %ebx, %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xc680d
movq %rbx, %rsi
incq %rsi
cmpq 0x28(%rsp), %rsi
jne 0xc6a47
movq %r13, %rdi
callq 0x2220
movq (%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq