// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: get_win_off(long, utg_ct_t*, overlap_region*, double, ul_ov_t*)
int64_t get_win_off(int64_t ql, utg_ct_t *p, overlap_region* o, double o_rate, ul_ov_t *res)
{
    if(!o->w_list.n) return 0;
    int64_t q[2], t[2], wk[2], wq[2], wt[2], k, tot_l, qs, qe, ts, te, os, oe, ovlp, aln_l;
    qs = 0; qe = ql-1; ts = p->s; te = p->e-1; //[qs, qe] && [ps, pe]

    k = 0; memset(res, 0, sizeof((*res)));
    k = get_win_yoff(o, ts, k, qs, qe, ts, te, q, t, &(wq[0]), &(wt[0])); wk[0] = k; 
    k = get_win_yoff(o, te, k, qs, qe, ts, te, q, t, &(wq[1]), &(wt[1])); wk[1] = k;
    res->ts = ts; res->te = te + 1;///offset of t
    res->qs = wk[0]<0?(uint32_t)-1:wk[0]; res->qe = wk[1] + 1;///id of window

    wk[0] = ((wk[0]>=0)?(wk[0]>>1):0);
    wk[1] = ((wk[1]>=0)?(wk[1]>>1):0)+1;
    tot_l = wq[1]+1-wq[0]; aln_l = 0;
    for (k = wk[0]; k < wk[1]; k++) {
        if(is_ualn_win(o->w_list.a[k])) continue;
        os = MAX(wq[0], o->w_list.a[k].x_start); 
        oe = MIN(wq[1], o->w_list.a[k].x_end) + 1;
        ovlp = ((oe>os)? (oe-os):0); aln_l += ovlp;
    }
    if((aln_l < (tot_l*o_rate)) || (aln_l == 0)) return 0;
	return 1;
}

// Assembly:
cmpq $0x0, 0x48(%rdx)
je 0x7c86f
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r14
movq %rdi, %r12
movsd %xmm0, 0x18(%rsp)
decq %r12
movl 0x4(%rsi), %ecx
movl 0x8(%rsi), %eax
movq %rax, 0x10(%rsp)
leal -0x1(%rax), %r15d
xorps %xmm0, %xmm0
movups %xmm0, 0xc(%r14)
movups %xmm0, (%r14)
subq $0x8, %rsp
leaq 0x28(%rsp), %rax
leaq 0x38(%rsp), %r10
leaq 0x48(%rsp), %rbp
leaq 0x58(%rsp), %r11
xorl %ebx, %ebx
movq %rdx, %rdi
movq %rcx, %rsi
movq %rcx, 0x10(%rsp)
movq %rdx, %r13
xorl %edx, %edx
xorl %ecx, %ecx
movq %r12, %r8
movq %rsi, %r9
pushq %rax
pushq %r10
pushq %rbp
pushq %r11
pushq %r15
callq 0x7c4d3
addq $0x30, %rsp
movq %rax, %rbp
leaq 0x38(%rsp), %r10
leaq 0x28(%rsp), %rax
subq $0x8, %rsp
movq %r13, 0x8(%rsp)
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
movq %r12, %r8
movq 0x10(%rsp), %r15
movq %r15, %r9
pushq %rax
pushq %r10
movq %r10, %r12
leaq 0x58(%rsp), %rax
pushq %rax
leaq 0x70(%rsp), %rax
pushq %rax
pushq %rsi
callq 0x7c4d3
addq $0x30, %rsp
movl %r15d, 0x10(%r14)
movq 0x10(%rsp), %rcx
movl %ecx, 0x14(%r14)
leal 0x1(%rax), %ecx
movq %rbp, %rdi
shrq %rdi
testq %rbp, %rbp
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovnsl %ebp, %edx
movl %edx, 0x4(%r14)
movl %ecx, 0x8(%r14)
cmovsq %rbx, %rdi
movq %rax, %rcx
shrq %rcx
incq %rcx
testq %rax, %rax
movl $0x1, %eax
cmovnsq %rcx, %rax
movq -0x8(%r12), %rdx
movq (%r12), %rsi
movq %rsi, %rcx
subq %rdx, %rcx
incq %rcx
subq %rdi, %rax
jbe 0x7c83e
movq (%rsp), %r8
movq 0x58(%r8), %r8
shlq $0x5, %rdi
addq %r8, %rdi
addq $0x1c, %rdi
xorl %ebx, %ebx
cmpw $0x7fff, -0x8(%rdi)     # imm = 0x7FFF
jne 0x7c80b
cmpl $0x0, (%rdi)
jne 0x7c80b
cmpw $0x0, -0xa(%rdi)
js 0x7c835
movslq -0x1c(%rdi), %r8
cmpq %r8, %rdx
cmovgq %rdx, %r8
movslq -0x18(%rdi), %r9
cmpq %r9, %rsi
cmovlq %rsi, %r9
subq %r8, %r9
leaq 0x1(%r9), %r8
movl $0x0, %r9d
cmovgeq %r8, %r9
addq %r9, %rbx
addq $0x20, %rdi
decq %rax
jne 0x7c7f7
cvtsi2sd %rbx, %xmm0
cvtsi2sd %rcx, %xmm1
mulsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setbe %al
testq %rbx, %rbx
setne %cl
andb %al, %cl
movzbl %cl, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
retq