// File: /workspace/github_cpp_makefile_star2_O1/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:
testq %rsi, %rsi
setne %al
je 0x8296c
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
cmpl $-0x1, 0xc(%rdi)
je 0x8296f
xorl %ecx, %ecx
jmp 0x82997
xorl %eax, %eax
retq
leaq 0x2c(%rdi), %r9
leaq -0x1(%rsi), %r8
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %r8
je 0x82ba9
incq %rcx
cmpl $-0x1, (%r9)
leaq 0x20(%r9), %r9
je 0x8297b
cmpq %rsi, %rcx
setb %al
testb %al, %al
je 0x82ba7
movq %rcx, %r11
shlq $0x5, %r11
movslq (%rdi,%r11), %rax
cmpq %rsi, %rcx
jae 0x829ec
addq %rdi, %r11
leaq (%rax,%rdx), %rbx
xorl %r8d, %r8d
movq %rcx, %r9
movslq 0x4(%r11), %r10
incq %r10
cmpl $-0x1, 0xc(%r11)
je 0x829d6
movslq (%r11), %r14
movslq %r10d, %r15
subq %r14, %r15
addq %r15, %r8
cmpq %r10, %rbx
jbe 0x829f9
incq %r9
addq $0x20, %r11
cmpq %rsi, %r9
jb 0x829bc
movq %rsi, %r9
jmp 0x829f9
movq $-0x1, %r10
xorl %r8d, %r8d
movq %rcx, %r9
movq 0x1a283f(%rip), %xmm1   # 0x225240
movapd 0x1a2847(%rip), %xmm2   # 0x225250
subq %rax, %r10
cmpq %rdx, %r10
jb 0x82a57
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
jb 0x82a57
movl $0x1, %eax
jmp 0x82ba9
incq %r9
cmpq %rsi, %r9
jae 0x82ba7
xorl %eax, %eax
movq %r9, %r11
shlq $0x5, %r11
movslq 0x4(%rdi,%r11), %r10
incq %r10
cmpl $-0x1, 0xc(%rdi,%r11)
je 0x82a8b
addq %rdi, %r11
movslq (%r11), %r11
movslq %r10d, %rbx
subq %r11, %rbx
addq %rbx, %r8
cmpq %rsi, %rcx
jae 0x82aca
movq %rcx, %r11
shlq $0x5, %r11
addq %rdi, %r11
movslq (%r11), %rbx
leaq (%rbx,%rdx), %r14
cmpq %r10, %r14
jae 0x82aca
cmpl $-0x1, 0xc(%r11)
je 0x82abb
movl 0x4(%r11), %ebp
subl %ebx, %ebp
incl %ebp
movslq %ebp, %rbx
subq %rbx, %r8
incq %rcx
addq $0x20, %r11
cmpq %rcx, %rsi
jne 0x82a9a
movq %rsi, %rcx
movq %rcx, %r11
shlq $0x5, %r11
movslq (%rdi,%r11), %rbx
movq %r10, %r11
subq %rbx, %r11
cmpq %rdx, %r11
jb 0x82b20
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 %r11, %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 0x82a4d
testq %rcx, %rcx
je 0x82b99
cmpq %rdx, %r11
jae 0x82b99
decq %rcx
movq %rcx, %rbx
shlq $0x5, %rbx
leaq (%rdi,%rbx), %r11
cmpl $-0x1, 0xc(%rdi,%rbx)
je 0x82b4e
movl 0x4(%r11), %ebx
subl (%r11), %ebx
incl %ebx
movslq %ebx, %rbx
addq %rbx, %r8
movslq (%r11), %r11
subq %r11, %r10
cmpq %rdx, %r10
jb 0x82b99
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 0x82a4d
incq %r9
cmpq %rsi, %r9
jne 0x82a65
jmp 0x82ba9
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
popq %rbp
retq