// File: 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
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq $-0x1, -0x38(%rbp)
movq $-0x1, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x51(%rbp)
jae 0x97595
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
sete %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x9759e
jmp 0x975ae
jmp 0x975a0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x9756d
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jb 0x975c5
movq $0x0, -0x8(%rbp)
jmp 0x9798f
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x9767f
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
je 0x97659
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
subl (%rcx), %eax
cltq
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
addq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jb 0x9766c
jmp 0x9767f
jmp 0x9766e
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x975eb
movq -0x48(%rbp), %xmm0
movaps 0x2ea985(%rip), %xmm3   # 0x382010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x2ea989(%rip), %xmm2   # 0x382020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x976ef
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x976ef
movq $0x1, -0x8(%rbp)
jmp 0x9798f
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x97987
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
je 0x97769
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
subl (%rcx), %eax
cltq
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x9776b
movq -0x50(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x52(%rbp)
jae 0x9779a
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq (%rax), %rax
addq -0x20(%rbp), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0x52(%rbp)
movb -0x52(%rbp), %al
testb $0x1, %al
jne 0x977a3
jmp 0x977ff
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
je 0x977ec
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq -0x50(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
subl (%rcx), %eax
movslq %eax, %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x977ee
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x9776b
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x5, %rcx
movslq (%rax,%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %xmm0
movaps 0x2ea7f1(%rip), %xmm3   # 0x382010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x2ea7f5(%rip), %xmm2   # 0x382020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x97883
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x97883
movq $0x1, -0x8(%rbp)
jmp 0x9798f
cmpq $0x0, -0x50(%rbp)
jbe 0x97974
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x97974
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
je 0x978f1
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq -0x50(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
subl (%rcx), %eax
cltq
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
shlq $0x5, %rcx
movslq (%rax,%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %xmm0
movaps 0x2ea6ff(%rip), %xmm3   # 0x382010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x2ea703(%rip), %xmm2   # 0x382020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x97972
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x97972
movq $0x1, -0x8(%rbp)
jmp 0x9798f
jmp 0x97974
jmp 0x97976
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x976fb
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)