// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: extract_subov(long, long, overlap_region*, double, long*, ul_ov_t*)
int64_t extract_subov(int64_t ts, int64_t te, overlap_region *o, double o_rate, int64_t *in_k, ul_ov_t *res)
{
    int64_t rev = o->y_pos_strand, qs, qe, k = 0, wn = o->w_list.n, ws, we, os, oe, ovlp, salnl;
    if(ts < ((int64_t)o->y_pos_s)) ts = o->y_pos_s;
    if(te > ((int64_t)o->y_pos_e+1)) te = o->y_pos_e+1;
    if(ts >= te) return 0;
    qs = get_chain_x_by_y(o, ts); 
    qe = get_chain_x_by_y(o, te-1) + 1;
    assert(qs < qe);
    memset(res, 0, sizeof(*res)); res->rev = rev;
    res->qs = qs; res->qe = qe; res->ts = ts; res->te = te;

    if(o_rate >= 0) {
        if(wn <= 0) return 0;
        if(in_k) k = *in_k;

        if(k < 0) k = 0; if(k >= wn) k = wn-1;
        for(; k < wn && qs > o->w_list.a[k].x_end; k++);
        if(k < 0) k = 0; if(k >= wn) k = wn-1;
        for(; k >= 0 && qs < o->w_list.a[k].x_start; k--);
        ///qs <= o->w_list.a[k].x_end && qs >= o->w_list.a[k].x_start
        if(k < 0) k = 0;
        if(in_k) *in_k = k;

        for (salnl = 0; k < wn; k++) {
            ws = o->w_list.a[k].x_start;
            we = o->w_list.a[k].x_end + 1;
            if(ws >= qe) break;
            if((o->w_list.a[k].y_end == -1) || (is_ualn_win(o->w_list.a[k]))) continue;
            os = MAX(qs, ws); oe = MIN(qe, we);
            ovlp = ((oe>os)? (oe-os):0);
            if(!ovlp) continue;
            salnl += ovlp; 
        }
        // if(o->y_id == 700) {
        //     fprintf(stderr, "[M::%s] raw_t::[%ld, %ld), raw_q::[%ld, %ld), salnl::%ld\n", __func__, ts, te, qs, qe, salnl);
        // }
        if((((qe-qs)*o_rate)<=salnl) && (salnl > 0)) return 1;
        else return 0;
    }
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r13
movl 0x14(%rdx), %eax
cmpq %rdi, %rax
cmovgq %rax, %r13
movl 0x18(%rdx), %eax
leal 0x1(%rax), %r15d
incq %rax
cmpq %rsi, %rax
cmovgeq %rsi, %r15
cmpq %r15, %r13
jge 0x49c0a
movq %r8, %r12
movq %rdx, %rbx
movq %rcx, (%rsp)
movsd %xmm0, 0x10(%rsp)
movl 0x1c(%rdx), %ebp
movq 0x48(%rdx), %rax
movq %rax, 0x8(%rsp)
movq %rdx, %rdi
movq %r13, %rsi
callq 0x48903
movq %rax, %r14
leaq -0x1(%r15), %rsi
movq %rbx, %rdi
callq 0x48903
cmpq %rax, %r14
jg 0x49d31
leaq 0x1(%rax), %rcx
xorpd %xmm0, %xmm0
movupd %xmm0, (%r12)
shll $0x1f, %ebp
movl %ebp, 0x18(%r12)
movl %r14d, 0x4(%r12)
movl %ecx, 0x8(%r12)
movl %r13d, 0x10(%r12)
movl %r15d, 0x14(%r12)
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm2
ucomisd %xmm0, %xmm2
jae 0x49bf2
pushq $0x1
popq %rax
jmp 0x49d22
movq 0x8(%rsp), %r11
testq %r11, %r11
jle 0x49c0a
movq (%rsp), %r9
testq %r9, %r9
je 0x49c11
movq (%r9), %rdi
jmp 0x49c13
xorl %eax, %eax
jmp 0x49d22
xorl %edi, %edi
xorl %esi, %esi
testq %rdi, %rdi
cmovgq %rdi, %rsi
leaq -0x1(%r11), %rdx
cmpq %r11, %rdi
cmovgeq %rdx, %rsi
movq %rsi, %rdi
shlq $0x5, %rdi
orq $0x4, %rdi
cmpq %r11, %rsi
jge 0x49c56
movq 0x58(%rbx), %r8
movslq (%r8,%rdi), %r8
cmpq %r8, %r14
jle 0x49c4d
incq %rsi
addq $0x20, %rdi
jmp 0x49c32
xorl %edx, %edx
testq %rsi, %rsi
cmovgq %rsi, %rdx
movq %rdx, %rsi
shlq $0x5, %rsi
pushq $-0x1
popq %rdi
testq %rdx, %rdx
js 0x49c7e
movq 0x58(%rbx), %r8
movslq (%r8,%rsi), %r8
cmpq %r8, %r14
jge 0x49c7b
decq %rdx
addq $-0x20, %rsi
jmp 0x49c60
movq %rdx, %rdi
xorl %esi, %esi
testq %rdi, %rdi
cmovgq %rdi, %rsi
testq %r9, %r9
je 0x49c8f
movq %rsi, (%r9)
xorl %edi, %edi
testq %rdx, %rdx
cmovleq %rdi, %rdx
shlq $0x5, %rdx
orq $0x1c, %rdx
cmpq %r11, %rsi
jge 0x49cff
movq 0x58(%rbx), %r10
movslq -0x1c(%r10,%rdx), %r8
cmpq %r8, %rax
jl 0x49cff
cmpl $-0x1, -0x10(%r10,%rdx)
je 0x49cf6
movslq -0x18(%r10,%rdx), %r9
cmpw $0x7fff, -0x8(%r10,%rdx) # imm = 0x7FFF
jne 0x49cda
cmpl $0x0, (%r10,%rdx)
jne 0x49cda
cmpw $0x0, -0xa(%r10,%rdx)
js 0x49cf6
incq %r9
cmpq %r8, %r14
cmovgq %r14, %r8
cmpq %r9, %rcx
cmovlq %rcx, %r9
cmpq %r8, %r9
jle 0x49cf6
subq %r8, %rdi
addq %r9, %rdi
incq %rsi
addq $0x20, %rdx
jmp 0x49ca0
subq %r14, %rcx
cvtsi2sd %rcx, %xmm0
cvtsi2sd %rdi, %xmm1
mulsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
setae %al
testq %rdi, %rdi
setg %cl
andb %al, %cl
movzbl %cl, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19d070(%rip), %rdi    # 0x1e6da8
leaq 0x199964(%rip), %rsi    # 0x1e36a3
leaq 0x19d06a(%rip), %rcx    # 0x1e6db0
movl $0x5978, %edx           # imm = 0x5978
callq 0x2110