// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rcx, 0x10(%rsp)
movq %rsi, %r10
movq %rdi, %r15
movq 0x8(%rdi), %rax
movq $-0x1, %r11
cmpq %rsi, %rax
jle 0x61753
decq %rax
movq (%r15), %rcx
movq %rax, %rsi
shlq $0x4, %rsi
movl (%rcx,%rsi), %ecx
notl %ecx
movq %rax, %r11
testl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jne 0x619f8
movq 0x68(%rsp), %r13
movq 0x60(%rsp), %rdi
cmpq %r10, %r13
jge 0x6187a
movq %rbx, 0x8(%rsp)
movq %r13, %r12
shlq $0x4, %r12
movq %r11, %rbx
shlq $0x4, %rbx
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl $0x80000000, %r14d      # imm = 0x80000000
movq %r10, 0x20(%rsp)
movq %rbx, 0x18(%rsp)
movq (%r15), %rax
movl (%rax,%r12), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rdi, %rcx
jne 0x6189a
movl 0x8(%rax,%r12), %ecx
cmpq %rdx, %rcx
jae 0x618bd
movl 0x4(%rax,%r12), %esi
cmpq %r8, %rsi
jae 0x61862
testq %r11, %r11
js 0x617dc
cmpl %esi, 0x4(%rax,%rbx)
jae 0x61862
leaq (%rax,%rbx), %rsi
cmpl %ecx, 0x8(%rsi)
jae 0x61862
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x61839
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r15)
shlq $0x4, %rsi
movq %rax, %rdi
movq %r8, %rbx
movq %rdx, %rbp
movq %r11, %r14
callq 0x2370
movq %r14, %r11
movl $0x80000000, %r14d      # imm = 0x80000000
movq 0x20(%rsp), %r10
movq %rbp, %rdx
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq %rbx, %r8
movq 0x18(%rsp), %rbx
movq 0x60(%rsp), %rdi
movq %rax, (%r15)
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), %r9d
andl %ebp, %r9d
movl (%rax,%rcx), %esi
andl %r14d, %esi
orl %r9d, %esi
movl %esi, (%rax,%rcx)
incq %r13
addq $0x10, %r12
cmpq %r13, %r10
jne 0x6178e
movq %r10, %r13
movq 0x8(%rsp), %rbx
cmpq $-0x1, %rdx
sete %al
movq 0x10(%rsp), %r14
cmpq $-0x1, %r14
sete %cl
orb %al, %cl
jne 0x619e6
movq (%r15), %rax
jmp 0x618df
cmpq $-0x1, %rdx
sete %cl
movq 0x10(%rsp), %r14
cmpq $-0x1, %r14
sete %sil
orb %cl, %sil
movq 0x8(%rsp), %rbx
je 0x618df
jmp 0x619e6
movq 0x10(%rsp), %r14
cmpq $-0x1, %r14
je 0x619e6
movl 0x8(%rax,%r12), %ecx
cmpq %r14, %rcx
movq 0x8(%rsp), %rbx
jb 0x61a17
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x61931
leaq (%rcx,%rcx), %r9
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %r9, %rsi
movq %rsi, 0x10(%r15)
shlq $0x4, %rsi
movq %rax, %rdi
movq %rbx, 0x8(%rsp)
movq %r8, %rbx
movq %rdx, %rbp
movq %r10, %r12
callq 0x2370
movq %r12, %r10
movq %rbp, %rdx
movq %rbx, %r8
movq 0x8(%rsp), %rbx
movq 0x60(%rsp), %rdi
movq %rax, (%r15)
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)
movq (%r15), %rax
cmpq %r10, %r13
jge 0x6198f
movq %r13, %rcx
shlq $0x4, %rcx
addq %rax, %rcx
addq $0x8, %rcx
movl -0x8(%rcx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdi, %rdx
jne 0x6198f
movl (%rcx), %edx
cmpq %r14, %rdx
jae 0x6198f
incq %r13
addq $0x10, %rcx
cmpq %r13, %r10
jne 0x6196b
movq %r10, %r13
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x619c0
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rdx, %rsi
movq %rsi, 0x10(%r15)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r15)
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 %r14d
movl %r14d, 0x8(%rax,%rcx)
decl %ebx
movl %ebx, 0x4(%rax,%rcx)
movq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d0f77(%rip), %rdi    # 0x232976
leaq 0x1cfd4d(%rip), %rsi    # 0x231753
leaq 0x1d0f7e(%rip), %rcx    # 0x23298b
movl $0x39aa, %edx           # imm = 0x39AA
callq 0x2110
leaq 0x1d0fe5(%rip), %rdi    # 0x232a03
leaq 0x1cfd2e(%rip), %rsi    # 0x231753
leaq 0x1d0f5f(%rip), %rcx    # 0x23298b
movl $0x39be, %edx           # imm = 0x39BE
callq 0x2110