// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: win_cluster_fliter(window_list*, unsigned long, unsigned long, double)
uint64_t win_cluster_fliter(window_list *wa, uint64_t wn, uint64_t min_ovlp, double o_rate)
{
    uint64_t k, ws = (uint64_t)-1, we = (uint64_t)-1, aln_ol, sk;
    for (k = 0; k < wn && wa[k].y_end == -1; k++);
    if(k >= wn) return 0; ws = wa[k].x_start;

    for (aln_ol = 0, sk = k; k < wn; k++) {
        we = wa[k].x_end+1; 
        if(wa[k].y_end != -1) {
            aln_ol += wa[k].x_end+1-wa[k].x_start;
        }
        if(we >= ws + min_ovlp) break;
    }
    // fprintf(stderr, "[M::%s::] aln_ol::%lu, w::[%lu, %lu), min_ovlp::%lu, o_rate::%f\n", 
    // __func__, aln_ol, ws, we, min_ovlp, o_rate);
    if((aln_ol >= (we-ws)*o_rate) && (we-ws >= min_ovlp)) return 1;

    for (k++; k < wn; k++) {
        we = wa[k].x_end+1; 
        if(wa[k].y_end != -1) {
            aln_ol += wa[k].x_end+1-wa[k].x_start;
        }
        for (; sk < wn && wa[sk].x_start + min_ovlp < we; sk++) {
            if(wa[sk].y_end != -1) aln_ol -= wa[sk].x_end+1-wa[sk].x_start;
        }
        ws = wa[sk].x_start; 
        // fprintf(stderr, "+[M::%s::] aln_ol::%lu, w::[%lu, %lu), min_ovlp::%lu, o_rate::%f, k::[%lu, %lu)\n", 
        //     __func__, aln_ol, ws, we, min_ovlp, o_rate, sk, k);
        if((aln_ol >= (we-ws)*o_rate) && (we-ws >= min_ovlp)) return 1;
        if((sk > 0) && (we-ws < min_ovlp)) {
            sk--; if(wa[sk].y_end != -1) aln_ol += wa[sk].x_end+1-wa[sk].x_start;
            ws = wa[sk].x_start;  
            // fprintf(stderr, "-[M::%s::] aln_ol::%lu, w::[%lu, %lu), min_ovlp::%lu, o_rate::%f, k::[%lu, %lu)\n", 
            // __func__, aln_ol, ws, we, min_ovlp, o_rate, sk, k);
            if((aln_ol >= (we-ws)*o_rate) && (we-ws >= min_ovlp)) return 1;
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
xorl %eax, %eax
movq %rdi, %r11
xorl %ecx, %ecx
cmpq %rcx, %rsi
je 0x4eece
cmpl $-0x1, 0xc(%r11)
jne 0x4ecc8
incq %rcx
addq $0x20, %r11
jmp 0x4ecaf
movslq (%r11), %rax
leaq (%rax,%rdx), %rbx
movabsq $-0x1, %r10
xorl %r8d, %r8d
movq %rcx, %r9
cmpq %r9, %rsi
je 0x4ed0c
movslq 0x4(%r11), %r10
incq %r10
cmpl $-0x1, 0xc(%r11)
je 0x4ecfe
movslq (%r11), %r14
movslq %r10d, %r15
subq %r14, %r15
addq %r15, %r8
cmpq %r10, %rbx
jbe 0x4ed0f
incq %r9
addq $0x20, %r11
jmp 0x4ecdf
movq %rsi, %r9
movq 0x194559(%rip), %xmm1   # 0x1e3270
movapd 0x194561(%rip), %xmm2   # 0x1e3280
subq %rax, %r10
movabsq $0x1, %rax
cmpq %rdx, %r10
jb 0x4ed71
movq %r8, %xmm3
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subpd %xmm2, %xmm3
movapd %xmm3, %xmm4
unpckhpd %xmm3, %xmm4            # xmm4 = xmm4[1],xmm3[1]
addsd %xmm3, %xmm4
movq %r10, %xmm3
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subpd %xmm2, %xmm3
movapd %xmm3, %xmm5
unpckhpd %xmm3, %xmm5            # xmm5 = xmm5[1],xmm3[1]
addsd %xmm3, %xmm5
mulsd %xmm0, %xmm5
ucomisd %xmm5, %xmm4
jae 0x4eece
movapd 0x194507(%rip), %xmm3   # 0x1e3280
incq %r9
cmpq %rsi, %r9
jae 0x4eecc
movq %r9, %r11
shlq $0x5, %r11
movslq 0x4(%rdi,%r11), %r10
incq %r10
cmpl $-0x1, 0xc(%rdi,%r11)
je 0x4edab
addq %rdi, %r11
movslq (%r11), %r11
movslq %r10d, %rbx
subq %r11, %rbx
addq %rbx, %r8
cmpq %rsi, %rcx
movq %rsi, %r11
cmovaq %rcx, %r11
movq %rcx, %rbx
shlq $0x5, %rbx
addq %rdi, %rbx
cmpq %rcx, %r11
je 0x4eded
movslq (%rbx), %r14
leaq (%r14,%rdx), %r15
cmpq %r10, %r15
jae 0x4edfb
cmpl $-0x1, 0xc(%rbx)
je 0x4ede4
movl 0x4(%rbx), %ebp
subl %r14d, %ebp
incl %ebp
movslq %ebp, %r14
subq %r14, %r8
incq %rcx
addq $0x20, %rbx
jmp 0x4edbf
movq %r11, %rcx
shlq $0x5, %rcx
movslq (%rdi,%rcx), %r14
movq %r11, %rcx
movq %r8, %xmm5
punpckldq %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1]
subpd %xmm2, %xmm5
movapd %xmm5, %xmm4
unpckhpd %xmm5, %xmm4            # xmm4 = xmm4[1],xmm5[1]
addsd %xmm5, %xmm4
movq %r10, %r11
subq %r14, %r11
cmpq %rdx, %r11
jb 0x4ee46
movq %r11, %xmm5
punpckldq %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1]
subpd %xmm2, %xmm5
movapd %xmm5, %xmm6
unpckhpd %xmm5, %xmm6            # xmm6 = xmm6[1],xmm5[1]
addsd %xmm5, %xmm6
mulsd %xmm0, %xmm6
ucomisd %xmm6, %xmm4
jae 0x4eece
testq %rcx, %rcx
je 0x4ed79
cmpq %rdx, %r11
jae 0x4ed79
decq %rcx
movq %rcx, %rbx
shlq $0x5, %rbx
cmpl $-0x1, 0xc(%rdi,%rbx)
movslq (%rdi,%rbx), %r11
je 0x4ee97
addq %rdi, %rbx
movl 0x4(%rbx), %ebx
subl %r11d, %ebx
incl %ebx
movslq %ebx, %rbx
addq %rbx, %r8
movq %r8, %xmm5
punpckldq %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1]
subpd %xmm3, %xmm5
movapd %xmm5, %xmm4
unpckhpd %xmm5, %xmm4            # xmm4 = xmm4[1],xmm5[1]
addsd %xmm5, %xmm4
subq %r11, %r10
movq %r10, %xmm5
punpckldq %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1]
subpd %xmm3, %xmm5
cmpq %rdx, %r10
jb 0x4ed79
movapd %xmm5, %xmm6
unpckhpd %xmm5, %xmm6            # xmm6 = xmm6[1],xmm5[1]
addsd %xmm5, %xmm6
mulsd %xmm0, %xmm6
ucomisd %xmm6, %xmm4
jb 0x4ed79
jmp 0x4eece
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
popq %rbp
retq