// File: 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
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movl %ecx, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl -0x3c(%rbp), %ecx
subl %ecx, %eax
cvtsi2sd %rax, %xmm0
movq -0x38(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2sd %eax, %xmm1
mulsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x101ff1
movl $0x1, -0x4(%rbp)
jmp 0x1021e5
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %ecx
movq -0x38(%rbp), %rdx
xorl %eax, %eax
cmpl 0x10(%rdx), %ecx
movb %al, -0x55(%rbp)
jae 0x102023
movl -0x4c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
setb %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x10202c
jmp 0x1020a4
movl -0x54(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x54(%rbp), %eax
movq -0x20(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x38(%rbp), %rdx
movq 0x18(%rdx), %rdx
movl -0x50(%rbp), %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addl %ecx, %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x40(%rbp), %eax
jb 0x102068
jmp 0x1020a4
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
ja 0x102081
movl -0x40(%rbp), %eax
cmpl -0x48(%rbp), %eax
jb 0x102081
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x102006
movl -0x4c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jb 0x1020b8
movl $0x1, -0x4(%rbp)
jmp 0x1021e5
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl -0x3c(%rbp), %ecx
subl %ecx, %eax
cvtsi2sd %rax, %xmm0
movq -0x38(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2sd %eax, %xmm1
mulsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x10211a
movl $0x1, -0x4(%rbp)
jmp 0x1021e5
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %ecx
movq -0x38(%rbp), %rdx
xorl %eax, %eax
cmpl 0x10(%rdx), %ecx
movb %al, -0x56(%rbp)
jae 0x10214c
movl -0x4c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
setb %al
movb %al, -0x56(%rbp)
movb -0x56(%rbp), %al
testb $0x1, %al
jne 0x102155
jmp 0x1021cd
movl -0x54(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x54(%rbp), %eax
movq -0x20(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x38(%rbp), %rdx
movq 0x18(%rdx), %rdx
movl -0x50(%rbp), %esi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addl %ecx, %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x40(%rbp), %eax
jb 0x102191
jmp 0x1021cd
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
ja 0x1021aa
movl -0x40(%rbp), %eax
cmpl -0x48(%rbp), %eax
jb 0x1021aa
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x10212f
movl -0x4c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jb 0x1021de
movl $0x1, -0x4(%rbp)
jmp 0x1021e5
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)