// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: ovlp_rocc(u_trans_t*, ma_ug_t*, asg_t*, double, unsigned int)
uint32_t ovlp_rocc(u_trans_t *p, ma_ug_t *ug, asg_t *rg, double cov_rate, uint32_t cov_cutoff)
{
    ma_utg_t *u = NULL; uint32_t s, e, rs, re, occ, k, l;
    u = &(ug->u.a[p->qn]); s = p->qs; e = p->qe;
    if((e-s) >= (u->len*cov_rate)) return 1;
    for (k = l = occ = 0; k < u->n && occ < cov_cutoff; k++) {
        rs = l; re = l + rg->seq[u->a[k]>>33].len;
        if(rs >= e) break;
        if(s <= rs && e >= re) occ++;
        l += (uint32_t)u->a[k];
    }
    if(occ >= cov_cutoff) return 1;

    u = &(ug->u.a[p->tn]); s = p->ts; e = p->te;
    if((e-s) >= (u->len*cov_rate)) return 1;
    for (k = l = occ = 0; k < u->n && occ < cov_cutoff; k++) {
        rs = l; re = l + rg->seq[u->a[k]>>33].len;
        if(rs >= e) break;
        if(s <= rs && e >= re) occ++;
        l += (uint32_t)u->a[k];
    }
    if(occ >= cov_cutoff) return 1;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x10(%rsi), %rsi
movl 0x8(%rdi), %eax
leaq (%rax,%rax,4), %r10
movl (%rdi), %r8d
movl 0x4(%rdi), %r9d
movl %r9d, %eax
subl %r8d, %eax
cvtsi2sd %rax, %xmm1
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl (%rsi,%r10,8), %eax
cvtsi2sd %eax, %xmm2
mulsd %xmm0, %xmm2
movl $0x1, %eax
ucomisd %xmm2, %xmm1
jae 0xc2f12
movq %rdx, -0x10(%rsp)
movq %rsi, -0x8(%rsp)
leaq (%rsi,%r10,8), %rbx
movl 0x10(%rbx), %r10d
testl %r10d, %r10d
setne %r11b
testl %ecx, %ecx
setne %r15b
testl %r9d, %r9d
setne %bpl
andb %r15b, %bpl
andb %r11b, %bpl
cmpb $0x1, %bpl
jne 0xc2e3e
movq -0x10(%rsp), %rdx
movq 0x20(%rdx), %r11
movq 0x18(%rbx), %rbx
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %r13d, %r13d
movl %r13d, %r15d
movq (%rbx,%r14,8), %r12
movq %r12, %r13
shrq $0x21, %r13
movl (%r11,%r13,8), %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
addl %ebp, %r13d
cmpl %ebp, %r8d
setbe %sil
cmpl %r13d, %r9d
setae %r13b
andb %sil, %r13b
movzbl %r13b, %r13d
addl %r15d, %r13d
incq %r14
cmpl %ecx, %r13d
setb %r15b
cmpl %r10d, %r14d
jae 0xc2e3e
cmpl %ecx, %r13d
jae 0xc2e3e
addl %r12d, %ebp
cmpl %r9d, %ebp
jb 0xc2dee
testb %r15b, %r15b
je 0xc2f12
movl 0x14(%rdi), %esi
leaq (%rsi,%rsi,4), %r9
movl 0xc(%rdi), %r8d
movl 0x10(%rdi), %edi
movl %edi, %esi
subl %r8d, %esi
xorps %xmm1, %xmm1
cvtsi2sd %rsi, %xmm1
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq -0x8(%rsp), %rdx
andl (%rdx,%r9,8), %esi
xorps %xmm2, %xmm2
cvtsi2sd %esi, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jae 0xc2f12
leaq (%rdx,%r9,8), %rsi
movl 0x10(%rsi), %eax
testl %eax, %eax
setne %dl
testl %ecx, %ecx
setne %r11b
testl %edi, %edi
setne %r9b
andb %r11b, %r9b
andb %dl, %r9b
cmpb $0x1, %r9b
jne 0xc2f0a
movq -0x10(%rsp), %rdx
movq 0x20(%rdx), %rdx
movq 0x18(%rsi), %rsi
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %ebp, %ebp
movl %ebp, %r11d
movq (%rsi,%r9,8), %rbx
movq %rbx, %r14
shrq $0x21, %r14
movl (%rdx,%r14,8), %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
addl %r10d, %ebp
cmpl %r10d, %r8d
setbe %r14b
cmpl %ebp, %edi
setae %bpl
andb %r14b, %bpl
movzbl %bpl, %ebp
addl %r11d, %ebp
incq %r9
cmpl %ecx, %ebp
setb %r11b
cmpl %eax, %r9d
jae 0xc2f0a
cmpl %ecx, %ebp
jae 0xc2f0a
addl %ebx, %r10d
cmpl %edi, %r10d
jb 0xc2ebe
xorb $0x1, %r11b
movzbl %r11b, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq