// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: ovlp_base_direct(overlap_region*, k_mer_hit*, long, ul_ov_t*, long, ul_idx_t const*, hpc_t*, All_reads*, char*, UC_Read*, bit_extz_t*, overlap_region*, double, long, long, unsigned long)
void ovlp_base_direct(overlap_region *z, k_mer_hit *ch_a, int64_t ch_n, 
ul_ov_t *ov, int64_t wl, const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, char* qstr, UC_Read *tu, 
bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t ql, int64_t tl, uint64_t rid)
{
    int64_t ibeg, iend, i, l, mode, q[2], t[2], is_done;
    if(ov->qn == ((uint32_t)-1)) ibeg = -1;
    else ibeg = ov->qn;
    iend = ov->tn;
    assert(iend>=ibeg+1);
    // if(z->x_id == 57 && z->y_id == 2175) {
    //     fprintf(stderr, "\n***[M::%s::rid->%lu] utg%.6dl(%c), s::%u, e::%u, z::[%u, %u), ibeg::%ld, iend::%ld, ch_n::%ld\n", 
    //     __func__, rid, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], ov->qs, ov->qe, z->x_pos_s, z->x_pos_e+1, ibeg, iend, ch_n);
    // }
    for (l = ibeg, i = ibeg + 1; i <= iend; i++) {
        q[0] = q[1] = t[0] = t[1] = mode = -1; is_done = 0;
        if(l >= 0) {
            q[0] = ch_a[l].self_offset; t[0] = ch_a[l].offset;
        } else {
            q[0] = ov->qs;
        }

        if(i < ch_n) {
            q[1] = ch_a[i].self_offset; t[1] = ch_a[i].offset;
        } else {
            q[1] = ov->qe;
        }

        if((t[0] != -1) && (t[1] != -1)) {
            mode = 0;//global
        } else if((t[0] != -1) && (t[1] == -1)) {
            mode = 1;///forward extension
        } else if((t[0] == -1) && (t[1] != -1)) {
            mode = 2;///backward extension
        } else {
            mode = 3;///no primary hit within [ibeg, iend] 
        }

        if(mode == 1 || mode == 2) adjust_ext_offset(&(q[0]), &(q[1]), &(t[0]), &(t[1]), ql, tl, 0, mode);
        // if(z->x_id == 57 && z->y_id == 2175) {
        //     fprintf(stderr, "#[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld\n", 
        //             __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode);
        // }
        is_done = hc_aln_exz_adv(z, uref, hpc_g, rref, qstr, tu, q[0], q[1], t[0], t[1], mode, wl, exz, ql, e_rate, 
        MAX_SIN_L, MAX_SIN_E, FORCE_SIN_L, -1, aux_o);

        // if(z->x_id == 57 && z->y_id == 2175) {
        //     fprintf(stderr, "-is_done::%ld[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld\n", 
        //             is_done, __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode);
        // }
                
        if(!is_done) {///postprocess
            push_unmap_alnw(aux_o, q[0], q[1]-1, t[0], t[1]-1, mode);
        }
        l = i;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm0, 0x38(%rsp)
movq %r9, 0x30(%rsp)
movq %r8, 0x28(%rsp)
movq %rdx, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movl (%rcx), %eax
movl 0xc(%rcx), %edi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rdx, %rax
movq $-0x1, %rdx
cmovneq %rax, %rdx
movq %rdi, 0x8(%rsp)
cmpq %rdi, %rdx
jge 0x6a16f
movq 0xb0(%rsp), %r10
leaq 0x4(%rcx), %rax
movq %rax, (%rsp)
movq %rdx, %rax
shlq $0x4, %rax
leaq (%rax,%rsi), %r15
addq $0x10, %r15
movq %rcx, 0x20(%rsp)
movq $-0x1, %rbp
movq (%rsp), %rax
movq $-0x1, %rbx
testq %rdx, %rdx
js 0x69fcf
leaq -0x8(%r15), %rax
movl -0xc(%r15), %ebx
incq %rdx
movq %rdx, 0x40(%rsp)
cmpq 0x18(%rsp), %rdx
jge 0x69fe5
movl 0x4(%r15), %ebp
movq %r15, %rcx
cmpq $-0x1, %rbx
setne %dl
cmpq $-0x1, %rbp
setne %sil
testb %sil, %dl
je 0x6a000
xorl %r13d, %r13d
xorl %edx, %edx
jmp 0x6a038
cmpq $-0x1, %rbx
setne %dl
cmpq $-0x1, %rbp
sete %sil
testb %sil, %dl
je 0x6a01e
movb $0x1, %dl
movl $0x1, %r13d
jmp 0x6a038
cmpq $-0x1, %rbp
setne %sil
cmpq $-0x1, %rbx
sete %dl
andb %sil, %dl
movzbl %dl, %r13d
xorq $0x3, %r13
movl (%rax), %r14d
movl 0x8(%rcx), %r12d
testb %dl, %dl
je 0x6a0ae
cmpl $0x2, %r13d
movq 0xb8(%rsp), %rax
je 0x6a070
cmpl $0x1, %r13d
jne 0x6a08d
movq %r10, %rbp
subq %r14, %rbp
movq %rax, %r12
subq %rbx, %r12
cmpq %r12, %rbp
jle 0x6a082
addq %r14, %r12
movq %rax, %rbp
jmp 0x6a08d
movq %rbp, %rbx
subq %r12, %rbx
jge 0x6a08a
movq %r12, %r14
subq %rbp, %r14
xorl %ebx, %ebx
jmp 0x6a08d
addq %rbx, %rbp
movq %r10, %r12
jmp 0x6a08d
xorl %r14d, %r14d
testq %r14, %r14
movl $0x0, %ecx
cmovleq %rcx, %r14
testq %rbx, %rbx
cmovleq %rcx, %rbx
cmpq %r10, %r12
cmovgeq %r10, %r12
cmpq %rax, %rbp
cmovgeq %rax, %rbp
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %r8
movq 0xa0(%rsp), %r9
movsd 0x40(%rsp), %xmm0
pushq 0xb0(%rsp)
pushq $-0x1
pushq $0x200                  # imm = 0x200
pushq $0x7ff                  # imm = 0x7FF
pushq $0x2710                 # imm = 0x2710
pushq %r10
pushq 0xd8(%rsp)
pushq 0x68(%rsp)
pushq %r13
pushq %rbp
pushq %rbx
pushq %r12
pushq %r14
callq 0x661e6
addq $0x70, %rsp
testq %rax, %rax
jne 0x6a13f
decq %r12
decq %rbp
movq 0xa8(%rsp), %rdi
movl %r14d, %esi
movq %r12, %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq %r13, %r9
callq 0x65e4a
addq $0x10, %r15
movq 0x40(%rsp), %rdx
cmpq %rdx, 0x8(%rsp)
movq 0x20(%rsp), %rcx
movq 0xb0(%rsp), %r10
jne 0x69fb0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bcdfd(%rip), %rdi    # 0x226f73
leaq 0x1bb4c6(%rip), %rsi    # 0x225643
leaq 0x1bd527(%rip), %rcx    # 0x2276ab
movl $0x43df, %edx           # imm = 0x43DF
callq 0x2110