// File: /workspace/github_cpp_makefile_star2_O3/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 0x7cdab
movq %r8, %r12
movq %rdx, %r14
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 0x7b997
movq %rax, %rbx
leaq -0x1(%r15), %rsi
movq %r14, %rdi
callq 0x7b997
cmpq %rax, %rbx
jg 0x7cee6
leaq 0x1(%rax), %rdx
xorpd %xmm0, %xmm0
movupd %xmm0, (%r12)
shll $0x1f, %ebp
movl %ebp, 0x18(%r12)
movl %ebx, 0x4(%r12)
movl %edx, 0x8(%r12)
movl %r13d, 0x10(%r12)
movl %r15d, 0x14(%r12)
movl $0x1, %ecx
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm2
ucomisd %xmm0, %xmm2
jb 0x7ced4
movq 0x8(%rsp), %r10
testq %r10, %r10
jle 0x7cdab
movq (%rsp), %r9
testq %r9, %r9
je 0x7cdb2
movq (%r9), %rdi
jmp 0x7cdb4
xorl %ecx, %ecx
jmp 0x7ced4
xorl %edi, %edi
xorl %esi, %esi
testq %rdi, %rdi
cmovgq %rdi, %rsi
leaq -0x1(%r10), %rcx
cmpq %r10, %rdi
cmovgeq %rcx, %rsi
cmpq %r10, %rsi
jae 0x7cdfe
movq 0x58(%r14), %rdi
movq %rsi, %r8
shlq $0x5, %r8
addq %r8, %rdi
addq $0x4, %rdi
movslq (%rdi), %r8
cmpq %r8, %rbx
jle 0x7cdf5
incq %rsi
addq $0x20, %rdi
cmpq %rsi, %r10
jne 0x7cddf
jmp 0x7cdfe
xorl %ecx, %ecx
testq %rsi, %rsi
cmovgq %rsi, %rcx
movq %rcx, %rsi
sarq $0x3f, %rsi
andq %rcx, %rsi
decq %rsi
movq %rcx, %rdi
shlq $0x5, %rdi
addq 0x58(%r14), %rdi
movslq (%rdi), %r8
cmpq %r8, %rbx
jge 0x7ce31
leaq -0x1(%rcx), %r8
addq $-0x20, %rdi
testq %rcx, %rcx
movq %r8, %rcx
jg 0x7ce16
movq %rsi, %rcx
xorl %esi, %esi
testq %rcx, %rcx
cmovgq %rcx, %rsi
testq %r9, %r9
je 0x7ce42
movq %rsi, (%r9)
cmpq %r10, %rcx
jge 0x7ceac
movq 0x58(%r14), %rcx
movq %rsi, %rdi
shlq $0x5, %rdi
addq %rcx, %rdi
addq $0x1c, %rdi
xorl %ecx, %ecx
movslq -0x1c(%rdi), %r8
cmpq %r8, %rax
jl 0x7ceae
cmpl $-0x1, -0x10(%rdi)
je 0x7ce9e
movslq -0x18(%rdi), %r9
cmpw $0x7fff, -0x8(%rdi)     # imm = 0x7FFF
jne 0x7ce82
cmpl $0x0, (%rdi)
jne 0x7ce82
cmpw $0x0, -0xa(%rdi)
js 0x7ce9e
incq %r9
cmpq %r8, %rbx
cmovgq %rbx, %r8
cmpq %r9, %rdx
cmovlq %rdx, %r9
cmpq %r8, %r9
jle 0x7ce9e
subq %r8, %rcx
addq %r9, %rcx
incq %rsi
addq $0x20, %rdi
cmpq %r10, %rsi
jl 0x7ce5b
jmp 0x7ceae
xorl %ecx, %ecx
subq %rbx, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
cvtsi2sd %rcx, %xmm1
mulsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
setae %al
testq %rcx, %rcx
setg %cl
andb %al, %cl
movzbl %cl, %ecx
movq %rcx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b7f6b(%rip), %rdi    # 0x234e58
leaq 0x1b485f(%rip), %rsi    # 0x231753
leaq 0x1b7f65(%rip), %rcx    # 0x234e60
movl $0x5978, %edx           # imm = 0x5978
callq 0x2110