// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
sete %al
testq %rcx, %rcx
setle %r9b
orb %al, %r9b
jne 0x62659
leaq 0x8(%rdx), %r9
xorl %eax, %eax
movl (%r9), %r10d
movl %r10d, %r15d
subl 0x8(%rdi), %r15d
movl -0x4(%r9), %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 0x625f4
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %rbx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
ja 0x6263c
testq %rsi, %rsi
je 0x6265b
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 0x6265b
xorps %xmm1, %xmm1
cvtsi2sd %r10, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %rbx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x6265b
movq $-0x1, -0x4(%r9)
incq %rax
addq $0x10, %r9
cmpq %rax, %rcx
jne 0x625aa
movq %rcx, %rax
jmp 0x6265b
xorl %eax, %eax
testq %rsi, %rsi
sete %r9b
cmpq %rcx, %rax
setge %r10b
testq %rcx, %rcx
setle %r11b
orb %r9b, %r11b
orb %r10b, %r11b
jne 0x6274f
leaq 0x1(%rcx), %r9
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 0x6273e
testq %rdi, %rdi
je 0x626ee
movl -0x8(%r10), %ebx
movl -0x4(%r10), %r15d
subl 0x8(%rdi), %r15d
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 0x626ee
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %rbx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
ja 0x62733
movl 0x4(%rsi), %ebx
movl 0x8(%rsi), %r15d
subl -0x4(%r10), %r15d
subl -0x8(%r10), %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 0x6274f
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %rbx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x6274f
movq $-0x1, -0x8(%r10)
incq %rax
decq %r9
addq $-0x10, %r10
cmpq $0x1, %r9
jg 0x62694
testq %rax, %rax
je 0x62787
testq %rcx, %rcx
jle 0x6278c
leaq 0x4(%rdx), %rsi
xorl %eax, %eax
cmpl $-0x1, (%rsi)
je 0x6277c
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 0x6275f
jmp 0x6278e
movq %rcx, %rax
jmp 0x6278e
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
retq