// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq %r8, %r15
movsd %xmm0, 0x8(%rsp)
movq %rcx, %r13
movq %rsi, %r12
movq %rdi, 0x10(%rsp)
xorl %r14d, %r14d
testq %rdi, %rdi
je 0x31bf9
testq %r13, %r13
movl $0x0, %ebx
cmovgq %r13, %rbx
movq %rdx, (%rsp)
movq %rdx, %rbp
cmpq %r14, %rbx
je 0x31c8e
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movsd 0x8(%rsp), %xmm0
movq %r15, %rdx
callq 0x5e518
testq %rax, %rax
je 0x31be7
testq %r12, %r12
je 0x31c8b
movq %rbp, %rdi
movq %r12, %rsi
movsd 0x8(%rsp), %xmm0
movq %r15, %rdx
callq 0x5e518
testq %rax, %rax
jne 0x31bf5
orq $-0x1, 0x4(%rbp)
incq %r14
addq $0x10, %rbp
jmp 0x31ba1
movq (%rsp), %rdx
testq %r12, %r12
sete %al
cmpq %r13, %r14
setge %cl
orb %al, %cl
jne 0x31c94
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq %r13, %rbx
movq %rdx, (%rsp)
movq %rbx, %rax
shlq $0x4, %rax
addq %rdx, %rax
testq %rbx, %rbx
jle 0x31c8b
decq %rbx
leaq -0x10(%rax), %rbp
movl -0x10(%rax), %ecx
andl %esi, %ecx
cmpl %ecx, -0x4(%rax)
movq %rbp, %rax
jb 0x31c23
cmpq $0x0, 0x10(%rsp)
je 0x31c5f
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movsd 0x8(%rsp), %xmm0
movq %r15, %rdx
callq 0x5e518
testq %rax, %rax
je 0x31c78
movq %rbp, %rdi
movq %r12, %rsi
movsd 0x8(%rsp), %xmm0
movq %r15, %rdx
callq 0x5e518
testq %rax, %rax
jne 0x31c8b
orq $-0x1, 0x4(%rbp)
incq %r14
movq (%rsp), %rdx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
jmp 0x31c19
movq %r14, %rbx
movq (%rsp), %rdx
jmp 0x31c97
movq %r14, %rbx
testq %rbx, %rbx
je 0x31cd7
xorl %eax, %eax
testq %r13, %r13
cmovleq %rax, %r13
leaq 0x4(%rdx), %rax
movq %r13, %rcx
xorl %r13d, %r13d
subq $0x1, %rcx
jb 0x31cd7
cmpl $-0x1, (%rax)
je 0x31cd1
leaq -0x4(%rax), %rdi
leaq 0x1(%r13), %rsi
shlq $0x4, %r13
movups (%rdi), %xmm0
movups %xmm0, (%rdx,%r13)
movq %rsi, %r13
addq $0x10, %rax
jmp 0x31caf
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq