// File: chhylp123[P]hifiasm/Correct.cpp
// Function: k_hits_bcheck(All_reads*, ul_idx_t const*, overlap_region_alloc*, Candidates_list*, unsigned long, unsigned long*, unsigned long, char*, char*, char*)
uint64_t k_hits_bcheck(All_reads *rref, const ul_idx_t *uref, overlap_region_alloc* ol, Candidates_list *cl, 
uint64_t khit, uint64_t *a, uint64_t a_n, char* qstr, char *str0, char *str1)
{
    if(a_n < 2) return 1;
    uint64_t k, e; char *ref0, *ref1; overlap_region *z;

    e = cl->list[(uint32_t)a[0]].offset; 
    if(e >= khit) e-=khit;
    else return 0;
    z = &(ol->list[cl->list[(uint32_t)a[0]].readID]);
    ref0 = retrive_str_piece_exz(rref, uref, str0, e, khit, z->y_pos_strand, z->y_id);
    // fprintf(stderr, "\n[M::%s::] qstr::%.*s\n", __func__, 
    // (int32_t)khit, qstr+cl->list[(uint32_t)a[0]].self_offset-khit);
    // fprintf(stderr, "[M::%s::qoff->%u::toff->%u::%c] tstr0::%.*s\n", __func__, 
    // cl->list[(uint32_t)a[0]].self_offset, cl->list[(uint32_t)a[0]].offset, "+-"[z->y_pos_strand], (int32_t)khit, ref0);

    for (k = 1; k < a_n; k++) {
        e = cl->list[(uint32_t)a[k]].offset; 
        if(e >= khit) e-=khit;
        else return 0;
        z = &(ol->list[cl->list[(uint32_t)a[k]].readID]);
        ref1 = retrive_str_piece_exz(rref, uref, str1, e, khit, z->y_pos_strand, z->y_id);
        // fprintf(stderr, "[M::%s::qoff->%u::toff->%u::%c] tstr1::%.*s\n", __func__, 
        // cl->list[(uint32_t)a[k]].self_offset, cl->list[(uint32_t)a[k]].offset, "+-"[z->y_pos_strand], (int32_t)khit, ref1);
        if(memcmp(ref0, ref1, khit)) return 0;
    }
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x28(%rbp), %rax
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)
cmpq $0x2, 0x10(%rbp)
jae 0x5aec4
movq $0x1, -0x8(%rbp)
jmp 0x5b07b
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x30(%rbp), %rax
jb 0x5aefd
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x5af0a
movq $0x0, -0x8(%rbp)
jmp 0x5b07b
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq -0x38(%rbp), %rdx
movq (%rdx), %rdx
movl %edx, %edx
shlq $0x4, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x20(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %r9d
movq -0x60(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, (%rsp)
callq 0x5add0
movq %rax, -0x50(%rbp)
movq $0x1, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq 0x10(%rbp), %rax
jae 0x5b073
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x30(%rbp), %rax
jb 0x5afc6
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x5afd3
movq $0x0, -0x8(%rbp)
jmp 0x5b07b
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
movl %edx, %edx
shlq $0x4, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x28(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %r9d
movq -0x60(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, (%rsp)
callq 0x5add0
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x20b0
cmpl $0x0, %eax
je 0x5b060
movq $0x0, -0x8(%rbp)
jmp 0x5b07b
jmp 0x5b062
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x5af7a
movq $0x1, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)