// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_ug_coverage(ma_utg_t*, asg_t*, ma_sub_t const*, ma_hit_t_alloc*, R_to_U*, unsigned char*, unsigned long*, unsigned long*)
uint32_t get_ug_coverage(ma_utg_t* u, asg_t* read_g, const ma_sub_t* coverage_cut, ma_hit_t_alloc* sources, R_to_U* ruIndex, uint8_t* r_flag, uint64_t *rR, uint64_t *rC)
{
    uint32_t k, j, rId, tn, is_Unitig;
    long long R_bases = 0, C_bases = 0;
    ma_hit_t *h;
    if(rR) (*rR) = 0; if(rC) (*rC) = 0;
    if(u->m == 0) return 0;

    for (k = 0; k < u->n; k++)
    {
        if(u->a[k] == (uint64_t)-1) continue;
        rId = u->a[k]>>33;
        r_flag[rId] = 1;
    }

    for (k = 0; k < u->n; k++)
    {
        if(u->a[k] == (uint64_t)-1) continue;
        rId = u->a[k]>>33;
        R_bases += (coverage_cut[rId].e - coverage_cut[rId].s);
        for (j = 0; j < (uint64_t)(sources[rId].length); j++)
        {
            h = &(sources[rId].buffer[j]);
            if(h->el != 1) continue;
            tn = Get_tn((*h));
            if(read_g->seq[tn].del == 1)
            {
                ///get the id of read that contains it 
                get_R_to_U(ruIndex, tn, &tn, &is_Unitig);
                if(tn == (uint32_t)-1 || is_Unitig == 1 || read_g->seq[tn].del == 1) continue;
            }
            if(read_g->seq[tn].del == 1) continue;
            if(r_flag[tn] != 1) continue;
            C_bases += (Get_qe((*h)) - Get_qs((*h)));
        }
    }


    for (k = 0; k < u->n; k++)
    {
        if(u->a[k] == (uint64_t)-1) continue;
        rId = u->a[k]>>33;
        r_flag[rId] = 0;
    }

    if(rR) (*rR) = R_bases; if(rC) (*rC) = C_bases;
    return R_bases == 0? 0:C_bases/R_bases;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0xee42a
movq 0x10(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, 0x18(%rbp)
je 0xee43c
movq 0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0xee452
movl $0x0, -0x4(%rbp)
jmp 0xee6c8
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0xee4a5
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
cmpq $-0x1, (%rax,%rcx,8)
jne 0xee479
jmp 0xee49a
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
movl -0x44(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xee459
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0xee62d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
cmpq $-0x1, (%rax,%rcx,8)
jne 0xee4d3
jmp 0xee61f
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
subl %ecx, %eax
movl %eax, %eax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x28(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0xee61d
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl -0x40(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x1, %eax
je 0xee571
jmp 0xee60f
movq -0x68(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0xee5cb
movq -0x30(%rbp), %rdi
movl -0x48(%rbp), %esi
leaq -0x48(%rbp), %rdx
leaq -0x4c(%rbp), %rcx
callq 0xd3d50
cmpl $-0x1, -0x48(%rbp)
je 0xee5c7
cmpl $0x1, -0x4c(%rbp)
je 0xee5c7
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0xee5c9
jmp 0xee60f
jmp 0xee5cb
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x48(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0xee5e3
jmp 0xee60f
movq -0x38(%rbp), %rax
movl -0x48(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
je 0xee5f5
jmp 0xee60f
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x68(%rbp), %rcx
movq (%rcx), %rcx
subl %ecx, %eax
movl %eax, %eax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xee523
jmp 0xee61f
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xee4ac
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0xee680
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
cmpq $-0x1, (%rax,%rcx,8)
jne 0xee654
jmp 0xee675
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
movl -0x44(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xee634
cmpq $0x0, 0x10(%rbp)
je 0xee692
movq -0x58(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, 0x18(%rbp)
je 0xee6a4
movq -0x60(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x58(%rbp)
jne 0xee6b3
xorl %eax, %eax
movq %rax, -0x70(%rbp)
jmp 0xee6c1
movq -0x60(%rbp), %rax
cqto
idivq -0x58(%rbp)
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)