// File: /workspace/github_cpp_makefile_star2_O1/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 0x7d2f8
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 0x7be29
movq %rax, %rbx
leaq -0x1(%r15), %rsi
movq %r14, %rdi
callq 0x7be29
cmpq %rax, %rbx
jg 0x7d45d
leaq 0x1(%rax), %rdx
xorpd %xmm0, %xmm0
movupd %xmm0, 0xc(%r12)
movupd %xmm0, (%r12)
shll $0x1f, %ebp
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x18(%r12), %ecx
orl %ebp, %ecx
movl %ecx, 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 0x7d44b
movq 0x8(%rsp), %r11
testq %r11, %r11
jle 0x7d2f8
movq (%rsp), %r15
testq %r15, %r15
je 0x7d2ff
movq (%r15), %rdi
jmp 0x7d301
xorl %ecx, %ecx
jmp 0x7d44b
xorl %edi, %edi
xorl %esi, %esi
testq %rdi, %rdi
cmovgq %rdi, %rsi
leaq -0x1(%r11), %rcx
cmpq %r11, %rdi
cmovgeq %rcx, %rsi
cmpq %r11, %rsi
setl %dil
jge 0x7d364
movq 0x58(%r14), %r8
movq %rsi, %r9
shlq $0x5, %r9
movslq 0x4(%r8,%r9), %r10
cmpq %r10, %rbx
jle 0x7d364
incq %rsi
addq %r9, %r8
addq $0x24, %r8
movq %rsi, %rdi
cmpq %rsi, %r11
je 0x7d35a
movslq (%r8), %r9
leaq 0x1(%rdi), %rsi
addq $0x20, %r8
cmpq %r9, %rbx
jg 0x7d33d
decq %rsi
jmp 0x7d35d
movq %r11, %rsi
cmpq %r11, %rdi
setl %dil
xorl %r8d, %r8d
testq %rsi, %rsi
cmovgq %rsi, %r8
testb %dil, %dil
cmovneq %r8, %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 0x7d3a8
leaq -0x1(%rcx), %r8
addq $-0x20, %rdi
testq %rcx, %rcx
movq %r8, %rcx
jg 0x7d38d
movq %rsi, %rcx
xorl %esi, %esi
testq %rcx, %rcx
cmovgq %rcx, %rsi
testq %r15, %r15
je 0x7d3b9
movq %rsi, (%r15)
cmpq %r11, %rcx
jge 0x7d423
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 0x7d425
cmpl $-0x1, -0x10(%rdi)
je 0x7d415
movslq -0x18(%rdi), %r9
cmpw $0x7fff, -0x8(%rdi)     # imm = 0x7FFF
jne 0x7d3f9
cmpl $0x0, (%rdi)
jne 0x7d3f9
cmpw $0x0, -0xa(%rdi)
js 0x7d415
incq %r9
cmpq %r8, %rbx
cmovgq %rbx, %r8
cmpq %r9, %rdx
cmovlq %rdx, %r9
cmpq %r8, %r9
jle 0x7d415
subq %r8, %rcx
addq %r9, %rcx
incq %rsi
addq $0x20, %rdi
cmpq %r11, %rsi
jl 0x7d3d2
jmp 0x7d425
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 0x1ab8e4(%rip), %rdi    # 0x228d48
leaq 0x1a81d8(%rip), %rsi    # 0x225643
leaq 0x1ab8de(%rip), %rcx    # 0x228d50
movl $0x5978, %edx           # imm = 0x5978
callq 0x2110