// File: /workspace/github_cpp_makefile_star2_O2/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 0x4971c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r14
movq %rdx, %rbx
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 %r13d, %r13d
movq %rdx, %rdi
movq %rcx, %rsi
movq %rcx, 0x10(%rsp)
xorl %edx, %edx
xorl %ecx, %ecx
movq %r12, %r8
movq %rsi, %r9
pushq %rax
pushq %r10
pushq %rbp
pushq %r11
pushq %r15
callq 0x49357
addq $0x30, %rsp
movq %rax, %rbp
leaq 0x38(%rsp), %r10
leaq 0x28(%rsp), %rax
subq $0x8, %rsp
movq %rbx, %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 0x49357
addq $0x30, %rsp
movl %r15d, 0x10(%r14)
movq 0x10(%rsp), %rcx
movl %ecx, 0x14(%r14)
leal 0x1(%rax), %edx
movq %rbp, %rcx
shrq %rcx
testq %rbp, %rbp
pushq $-0x1
popq %rsi
cmovnsl %ebp, %esi
movl %esi, 0x4(%r14)
movl %edx, 0x8(%r14)
cmovsq %r13, %rcx
movq %rax, %rsi
shrq %rsi
incq %rsi
testq %rax, %rax
pushq $0x1
popq %rdx
cmovnsq %rsi, %rdx
movq -0x8(%r12), %rsi
movq (%r12), %rax
movq %rcx, %rdi
shlq $0x5, %rdi
orq $0x1c, %rdi
cmpq %rdx, %rcx
jae 0x496e5
movq 0x58(%rbx), %r8
cmpw $0x7fff, -0x8(%r8,%rdi) # imm = 0x7FFF
jne 0x496b0
cmpl $0x0, (%r8,%rdi)
jne 0x496b0
cmpw $0x0, -0xa(%r8,%rdi)
js 0x496dc
movslq -0x1c(%r8,%rdi), %r9
cmpq %r9, %rsi
cmovgq %rsi, %r9
movslq -0x18(%r8,%rdi), %r8
cmpq %r8, %rax
cmovlq %rax, %r8
subq %r9, %r8
leaq 0x1(%r8), %r8
movl $0x0, %r9d
cmovgeq %r8, %r9
addq %r9, %r13
incq %rcx
addq $0x20, %rdi
jmp 0x4968d
subq %rsi, %rax
cvtsi2sd %r13, %xmm0
incq %rax
cvtsi2sd %rax, %xmm1
mulsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setbe %al
testq %r13, %r13
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