// File: /workspace/github_cpp_makefile_star2_O2/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, 0x8(%rsp)
movq %rsi, %r12
movq %rdi, %r15
movq 0x8(%rdi), %r11
cmpq %rsi, %r11
movq %rcx, (%rsp)
jle 0x312bb
decq %r11
movq (%r15), %rax
movq %r11, %rcx
shlq $0x4, %rcx
movl (%rax,%rcx), %eax
notl %eax
testl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x312bf
leaq 0x1b3623(%rip), %rdi    # 0x1e48c6
leaq 0x1b23f9(%rip), %rsi    # 0x1e36a3
leaq 0x1b362a(%rip), %rcx    # 0x1e48db
movl $0x39aa, %edx           # imm = 0x39AA
callq 0x2110
pushq $-0x1
popq %r11
movq 0x68(%rsp), %rbx
movq 0x60(%rsp), %rdi
movq %rbx, %r13
shlq $0x4, %r13
orq $0x8, %r13
movq %r11, %r10
shlq $0x4, %r10
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl $0x80000000, %r14d      # imm = 0x80000000
movq %r8, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %r12, 0x20(%rsp)
cmpq %r12, %rbx
jge 0x313de
movq (%r15), %rax
movl -0x8(%rax,%r13), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rdi, %rcx
jne 0x313fd
movl (%rax,%r13), %ecx
cmpq %rdx, %rcx
jae 0x3141a
movl -0x4(%rax,%r13), %esi
cmpq %r8, %rsi
jae 0x313d2
testq %r11, %r11
js 0x3134d
cmpl %esi, 0x4(%rax,%r10)
jae 0x313d2
leaq (%rax,%r10), %rsi
cmpl %ecx, 0x8(%rsi)
jae 0x313d2
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x313a8
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r15)
shlq $0x4, %rsi
movq %rdi, %rbp
movq %rax, %rdi
movq %r10, %r14
movq %r11, %r12
callq 0x2370
movq %r12, %r11
movq 0x20(%rsp), %r12
movq %r14, %r10
movl $0x80000000, %r14d      # imm = 0x80000000
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %r8
movq %rbp, %rdi
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq %rax, (%r15)
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r15)
shlq $0x4, %rcx
movups -0x8(%rax,%r13), %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 %rbx
addq $0x10, %r13
jmp 0x312f5
cmpq $-0x1, %rdx
sete %al
movq (%rsp), %rbp
cmpq $-0x1, %rbp
sete %cl
orb %al, %cl
jne 0x314cb
movq (%r15), %rax
jmp 0x31435
cmpq $-0x1, %rdx
sete %cl
movq (%rsp), %rbp
cmpq $-0x1, %rbp
sete %sil
orb %cl, %sil
je 0x31435
jmp 0x314cb
movq (%rsp), %rbp
cmpq $-0x1, %rbp
je 0x314cb
movl (%rax,%r13), %ecx
cmpq %rbp, %rcx
jb 0x3153a
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x31474
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r15)
shlq $0x4, %rsi
movq %rdi, %r14
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %r8
movq %r14, %rdi
movq %rax, (%r15)
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r15)
shlq $0x4, %rcx
orl $-0x1, 0xc(%rax,%rcx)
movl $0x7fffffff, (%rax,%rcx) # imm = 0x7FFFFFFF
movl %edx, 0x8(%rax,%rcx)
movl %r8d, 0x4(%rax,%rcx)
cmpq %r12, %rbx
movq %r12, %r14
cmovgq %rbx, %r14
movq (%r15), %rax
addq %rax, %r13
cmpq %r12, %rbx
jge 0x314d3
movl -0x8(%r13), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rdi, %rcx
jne 0x314d0
movl (%r13), %ecx
cmpq %rbp, %rcx
jae 0x314d0
incq %rbx
addq $0x10, %r13
jmp 0x314a5
movq %rbx, %r14
jmp 0x31528
movq %rbx, %r14
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x31502
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r15)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r15)
movq 0x8(%r15), %rcx
movq 0x8(%rsp), %rsi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
shlq $0x4, %rcx
orl $-0x1, 0xc(%rax,%rcx)
orl $-0x1, (%rax,%rcx)
decl %ebp
movl %ebp, 0x8(%rax,%rcx)
decl %esi
movl %esi, 0x4(%rax,%rcx)
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b3412(%rip), %rdi    # 0x1e4953
leaq 0x1b215b(%rip), %rsi    # 0x1e36a3
leaq 0x1b338c(%rip), %rcx    # 0x1e48db
movl $0x39be, %edx           # imm = 0x39BE
callq 0x2110