// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $-0x1, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x18(%rbp), %rax
jle 0x5a028
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
subq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x5a007
jmp 0x5a026
leaq 0x329530(%rip), %rdi    # 0x38353e
leaq 0x328306(%rip), %rsi    # 0x38231b
movl $0x39aa, %edx           # imm = 0x39AA
leaq 0x329532(%rip), %rcx    # 0x383553
callq 0x2130
jmp 0x5a028
jmp 0x5a02a
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x51(%rbp)
jge 0x5a080
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq 0x10(%rbp), %rcx
movb %al, -0x51(%rbp)
jne 0x5a080
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpq -0x20(%rbp), %rax
setb %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x5a08c
jmp 0x5a1dc
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
cmpq -0x30(%rbp), %rax
jb 0x5a0b4
jmp 0x5a1cb
cmpq $0x0, -0x48(%rbp)
jl 0x5a0fc
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x50(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x5a0f7
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x50(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jb 0x5a0fc
jmp 0x5a1cb
jmp 0x5a0fe
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x5a165
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x5a12c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x5a137
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x5a137
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x4, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x40(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x50(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x50(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x5a02a
cmpq $-0x1, -0x20(%rbp)
je 0x5a1ea
cmpq $-0x1, -0x28(%rbp)
jne 0x5a1f7
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5a4a9
movq -0x40(%rbp), %rcx
movb $0x1, %al
cmpq -0x18(%rbp), %rcx
movb %al, -0x61(%rbp)
jge 0x5a24d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movb $0x1, %al
cmpq 0x10(%rbp), %rcx
movb %al, -0x61(%rbp)
jne 0x5a24d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpq -0x28(%rbp), %rax
setae %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x5a256
jmp 0x5a258
jmp 0x5a277
leaq 0x32936c(%rip), %rdi    # 0x3835cb
leaq 0x3280b5(%rip), %rsi    # 0x38231b
movl $0x39be, %edx           # imm = 0x39BE
leaq 0x3292e1(%rip), %rcx    # 0x383553
callq 0x2130
jmp 0x5a279
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x5a2e0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x5a2a7
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x5a2b2
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x5a2b2
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x4, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
orl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movq -0x50(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x71(%rbp)
jge 0x5a3a5
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq 0x10(%rbp), %rcx
movb %al, -0x71(%rbp)
jne 0x5a3a5
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpq -0x28(%rbp), %rax
setb %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x5a3ae
jmp 0x5a3be
jmp 0x5a3b0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x5a34f
jmp 0x5a3c0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x5a427
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x5a3ee
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x5a3f9
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x5a3f9
movq -0x80(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x4, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
orl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movq -0x50(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)