// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x58(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x5b188
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x5b186
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x5b12a
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movsd -0x48(%rbp), %xmm0
movq -0x50(%rbp), %rdx
callq 0xb7300
cmpq $0x0, %rax
je 0x5b14d
cmpq $0x0, -0x10(%rbp)
je 0x5b171
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
movsd -0x48(%rbp), %xmm0
movq -0x50(%rbp), %rdx
callq 0xb7300
cmpq $0x0, %rax
jne 0x5b171
movq -0x40(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movq -0x40(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x5b173
jmp 0x5b186
jmp 0x5b175
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5b0e6
jmp 0x5b188
cmpq $0x0, -0x10(%rbp)
je 0x5b265
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x5b265
movq -0x20(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jl 0x5b263
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x40(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0x5b1e4
jmp 0x5b252
cmpq $0x0, -0x8(%rbp)
je 0x5b207
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movsd -0x48(%rbp), %xmm0
movq -0x50(%rbp), %rdx
callq 0xb7300
cmpq $0x0, %rax
je 0x5b22a
cmpq $0x0, -0x10(%rbp)
je 0x5b24e
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
movsd -0x48(%rbp), %xmm0
movq -0x50(%rbp), %rdx
callq 0xb7300
cmpq $0x0, %rax
jne 0x5b24e
movq -0x40(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movq -0x40(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x5b250
jmp 0x5b263
jmp 0x5b252
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5b1ad
jmp 0x5b265
cmpq $0x0, -0x58(%rbp)
je 0x5b2ea
movq $0x0, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x5b2e2
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x4(%rax)
jne 0x5b29d
jmp 0x5b2d4
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq -0x58(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x58(%rbp)
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5b27c
movq -0x58(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)