// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: push_adp_k_hits(Candidates_list*, long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, long, long)
int64_t push_adp_k_hits(Candidates_list *cl, int64_t cln, uint64_t qs, uint64_t qe, uint64_t ts, uint64_t te, uint64_t readID, int64_t ci, int64_t dbgid)
{
    int64_t k = ci, m = -1; k_mer_hit *p = NULL;
    if(cl->length > cln) {
        m = cl->length-1; assert(is_alnw(cl->list[m]));
    }
    for (; k < cln && cl->list[k].readID == readID && cl->list[k].self_offset < qs; k++) {
        p = &(cl->list[k]);
        // fprintf(stderr, "[M::%s::] p->q::%ld, p->t::%ld\n", __func__, p->self_offset, p->offset);
        if(p->offset >= ts) continue;
        if((m>=0) && ((cl->list[m].offset >= p->offset) || (cl->list[m].self_offset >= p->self_offset))) {
            continue;
        }
        kv_pushp_cl(k_mer_hit, (*cl), &p); *p = cl->list[k]; p->readID = p->cnt;
        // if(dbgid == 109111 || dbgid == 75436) {
        //     fprintf(stderr, "[M::%s::k->%ld] self_offset::%u, offset::%u, cl->length::%lld, cln::%ld, p->readID::%u\n", 
        //     __func__, k, cl->list[k].self_offset, cl->list[k].offset, cl->length, cln, p->readID);
        // }
    }
    if(qs == (uint64_t)-1 || qe == (uint64_t)-1) return k;
    // if(!(k >= cln || cl->list[k].self_offset >= qe)) {
    //      fprintf(stderr, "[M::%s::] k::%ld, self_offset::%u, offset::%u\n", 
    //                 __func__, k, cl->list[k].self_offset, cl->list[k].offset);
    // }
    assert(k >= cln || cl->list[k].readID != readID || cl->list[k].self_offset >= qe);
    ///push qs, ts
    kv_pushp_cl(k_mer_hit, (*cl), &p); 
    p->readID = ((uint32_t)(0x7fffffff));
    p->cnt = (uint32_t)-1; p->strand = 0; 
    p->self_offset = qs; p->offset = ts;
    
    for (; k < cln && cl->list[k].readID == readID && cl->list[k].self_offset < qe; k++);

    ///push qe, te
    kv_pushp_cl(k_mer_hit, (*cl), &p); 
    p->readID = ((uint32_t)(0x7fffffff));
    p->cnt = (uint32_t)-1; p->strand = 1; 
    p->self_offset = qe-1; p->offset = te-1;
    return k;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r13
movq %rcx, %r12
movq %rsi, %rbp
movq %rdi, %r15
movq 0x8(%rdi), %rax
movq $-0x1, %r9
cmpq %rsi, %rax
jle 0x61d11
decq %rax
movq (%r15), %rcx
movq %rax, %rsi
shlq $0x4, %rsi
movl (%rcx,%rsi), %ecx
notl %ecx
movq %rax, %r9
testl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jne 0x61fba
movq 0x68(%rsp), %r14
movq 0x60(%rsp), %rbx
cmpq %rbp, %r14
setl %al
jge 0x61e5f
movq %r12, 0x8(%rsp)
movq (%r15), %rdi
movq %r14, %r12
shlq $0x4, %r12
movl (%rdi,%r12), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rbx, %rcx
jne 0x61e5a
movq %r13, (%rsp)
leaq (%rdi,%r12), %rcx
leaq 0x1(%r14), %r13
movq %r9, %r10
shlq $0x4, %r10
movq %rdx, 0x10(%rsp)
movq %r9, 0x20(%rsp)
movq %r10, 0x18(%rsp)
movl 0x8(%rcx), %esi
cmpq %rdx, %rsi
jae 0x61e4b
movl 0x4(%rcx), %eax
cmpq %r8, %rax
jae 0x61e18
testq %r9, %r9
js 0x61d9c
cmpl %eax, 0x4(%rdi,%r10)
jae 0x61e18
leaq (%rdi,%r10), %rax
cmpl %esi, 0x8(%rax)
jae 0x61e18
movq 0x10(%r15), %rax
cmpq %rax, 0x8(%r15)
jne 0x61de0
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%r15)
shlq $0x4, %rsi
movq %r8, %rbx
callq 0x2370
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %r9
movq 0x10(%rsp), %rdx
movq %rbx, %r8
movq 0x60(%rsp), %rbx
movq %rax, (%r15)
movq (%r15), %rax
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r15)
shlq $0x4, %rcx
movups (%rax,%r12), %xmm0
movups %xmm0, (%rax,%rcx)
movl 0xc(%rax,%rcx), %edi
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edi
movl (%rax,%rcx), %esi
movl $0x80000000, %r11d      # imm = 0x80000000
andl %r11d, %esi
orl %edi, %esi
movl %esi, (%rax,%rcx)
cmpq %rbp, %r13
setl %al
je 0x61e53
incq %r14
movq (%r15), %rdi
movq %r14, %rcx
shlq $0x4, %rcx
addq %rdi, %rcx
movl 0x10(%rdi,%r12), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
incq %r13
addq $0x10, %r12
cmpq %rbx, %rsi
je 0x61d6b
decq %r13
movq %r13, %r14
jmp 0x61e56
movq %rbp, %r14
movq (%rsp), %r13
movq 0x8(%rsp), %r12
cmpq $-0x1, %rdx
sete %cl
cmpq $-0x1, %r12
sete %sil
orb %cl, %sil
jne 0x61fa8
testb $0x1, %al
je 0x61ea2
movq (%r15), %rax
movq %r14, %rcx
shlq $0x4, %rcx
movl (%rax,%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
cmpq %rbx, %rsi
jne 0x61ea2
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpq %r12, %rax
jb 0x61fd9
movq 0x10(%r15), %rax
cmpq %rax, 0x8(%r15)
jne 0x61ee7
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x10(%r15)
movq (%r15), %rdi
shlq $0x4, %rsi
movq %r13, (%rsp)
movq %r8, %r13
movq %rdx, 0x10(%rsp)
callq 0x2370
movq 0x10(%rsp), %rdx
movq %r13, %r8
movq (%rsp), %r13
movq %rax, (%r15)
movq (%r15), %rax
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r15)
shlq $0x4, %rcx
movl $0xffffffff, 0xc(%rax,%rcx) # imm = 0xFFFFFFFF
movl $0x7fffffff, (%rax,%rcx) # imm = 0x7FFFFFFF
movl %edx, 0x8(%rax,%rcx)
movl %r8d, 0x4(%rax,%rcx)
cmpq %rbp, %r14
jge 0x61f4c
movq (%r15), %rax
movq %r14, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
addq $0x8, %rax
movl -0x8(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rbx, %rcx
jne 0x61f4c
movl (%rax), %ecx
cmpq %r12, %rcx
jae 0x61f4c
incq %r14
addq $0x10, %rax
cmpq %r14, %rbp
jne 0x61f28
movq %rbp, %r14
movq 0x10(%r15), %rax
cmpq %rax, 0x8(%r15)
jne 0x61f79
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x10(%r15)
movq (%r15), %rdi
shlq $0x4, %rsi
callq 0x2370
movq %rax, (%r15)
movq (%r15), %rax
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
shlq $0x4, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %edx, 0xc(%rax,%rcx)
movl %edx, (%rax,%rcx)
decl %r12d
movl %r12d, 0x8(%rax,%rcx)
decl %r13d
movl %r13d, 0x4(%rax,%rcx)
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c48a5(%rip), %rdi    # 0x226866
leaq 0x1c367b(%rip), %rsi    # 0x225643
leaq 0x1c48ac(%rip), %rcx    # 0x22687b
movl $0x39aa, %edx           # imm = 0x39AA
callq 0x2110
leaq 0x1c4913(%rip), %rdi    # 0x2268f3
leaq 0x1c365c(%rip), %rsi    # 0x225643
leaq 0x1c488d(%rip), %rcx    # 0x22687b
movl $0x39be, %edx           # imm = 0x39BE
callq 0x2110