// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: filter_bad_khits(k_mer_hit*, k_mer_hit*, k_mer_hit*, long, double, long)
int64_t filter_bad_khits(k_mer_hit *sk, k_mer_hit *ek, k_mer_hit* a, int64_t a_n, double small_bw_rate, int64_t min_small_bw)
{
    int64_t k = 0; k_mer_hit *z; double bw_r; int64_t bw, occ = 0;
    bw_r = small_bw_rate; bw = min_small_bw; 
    if(sk) {
        for (k = 0; k < a_n; k++) {
            z = &(a[k]); 
            if((sk && (!khit_long_gap(sk, z, bw_r, bw))) || 
                                (ek && (!khit_long_gap(z, ek, bw_r, bw)))) {
                z->offset = z->self_offset = (uint32_t)-1; occ++;
            } else {
                break;
            }
        }
    }

    if(ek && k < a_n) {
        for (k = a_n-1; k >= 0; k--) {
            z = &(a[k]); 
            if(z->cnt < z->readID) continue;
            if((sk && (!khit_long_gap(sk, z, bw_r, bw))) || 
                                (ek && (!khit_long_gap(z, ek, bw_r, bw)))) {
                z->offset = z->self_offset = (uint32_t)-1; occ++;
            } else {
                break;
            }
        }
    }

    if(occ) {
        for (k = occ = 0; k < a_n; k++) {
            if(a[k].offset == (uint32_t)-1) continue;
            a[occ++] = a[k];
        }
        a_n = occ;
    } 
    return a_n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
testq %rdi, %rdi
sete %al
testq %rcx, %rcx
setle %r9b
orb %al, %r9b
jne 0x6215e
leaq 0x8(%rdx), %rax
xorl %r9d, %r9d
movl (%rax), %r10d
movl %r10d, %r15d
subl 0x8(%rdi), %r15d
movl -0x4(%rax), %r11d
movl %r11d, %ebx
subl 0x4(%rdi), %ebx
movq %r15, %r12
subq %rbx, %r12
movq %rbx, %r14
subq %r15, %r14
cmpl %ebx, %r15d
cmovaeq %r12, %r14
cmovbl %r15d, %ebx
cmpq %r8, %r14
jle 0x620ea
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %rbx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
ja 0x62136
testq %rsi, %rsi
je 0x62260
movl 0x4(%rsi), %ebx
movl 0x8(%rsi), %r14d
subl %r10d, %r14d
subl %r11d, %ebx
movq %r14, %r11
subq %rbx, %r11
movq %rbx, %r10
subq %r14, %r10
cmpl %ebx, %r14d
cmovaeq %r11, %r10
cmovbl %r14d, %ebx
cmpq %r8, %r10
jle 0x62161
xorps %xmm1, %xmm1
cvtsi2sd %r10, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %rbx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x62161
movq $-0x1, -0x4(%rax)
incq %r9
addq $0x10, %rax
cmpq %r9, %rcx
jne 0x620a0
testq %rcx, %rcx
jg 0x62279
xorl %eax, %eax
jmp 0x622a5
xorl %r9d, %r9d
testq %rcx, %rcx
setle %al
testq %rsi, %rsi
sete %r10b
cmpq %rcx, %r9
setge %r11b
orb %al, %r10b
orb %r11b, %r10b
jne 0x62260
leaq 0x1(%rcx), %rax
movq %rcx, %r10
shlq $0x4, %r10
addq %rdx, %r10
addq $-0x4, %r10
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl -0xc(%r10), %ebx
andl %r11d, %ebx
cmpl %ebx, (%r10)
jb 0x6224f
movl -0x4(%r10), %ebx
testq %rdi, %rdi
je 0x621fc
movl %ebx, %r12d
subl 0x8(%rdi), %r12d
movl -0x8(%r10), %ebp
movl %ebp, %r14d
subl 0x4(%rdi), %r14d
movq %r12, %r13
subq %r14, %r13
movq %r14, %r15
subq %r12, %r15
cmpl %r14d, %r12d
cmovaeq %r13, %r15
cmovbl %r12d, %r14d
cmpq %r8, %r15
jle 0x62200
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r14, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
ja 0x62244
jmp 0x62200
movl -0x8(%r10), %ebp
movl 0x4(%rsi), %r15d
subl %ebp, %r15d
movl 0x8(%rsi), %r14d
subl %ebx, %r14d
movq %r14, %r12
subq %r15, %r12
movq %r15, %rbx
subq %r14, %rbx
cmpl %r15d, %r14d
cmovaeq %r12, %rbx
cmovael %r15d, %r14d
cmpq %r8, %rbx
jle 0x62260
xorps %xmm1, %xmm1
cvtsi2sd %rbx, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r14, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x62260
movq $-0x1, -0x8(%r10)
incq %r9
decq %rax
addq $-0x10, %r10
cmpq $0x1, %rax
ja 0x62199
testq %rcx, %rcx
setg %sil
xorl %eax, %eax
testq %r9, %r9
setne %dil
cmoveq %rcx, %rax
testb %sil, %dil
je 0x622a5
leaq 0x4(%rdx), %rsi
xorl %eax, %eax
cmpl $-0x1, (%rsi)
je 0x6229c
leaq -0x4(%rsi), %rdi
leaq 0x1(%rax), %r8
shlq $0x4, %rax
movupd (%rdi), %xmm0
movupd %xmm0, (%rdx,%rax)
movq %r8, %rax
addq $0x10, %rsi
decq %rcx
jne 0x6227f
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq