// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
movq %rdi, 0x20(%rsp)
movl (%rcx), %edx
movq %rcx, 0x10(%rsp)
movl 0xc(%rcx), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rdx
movq $-0x1, %rax
cmovneq %rdx, %rax
movq %rcx, 0x18(%rsp)
cmpq %rcx, %rax
jge 0x69df1
movq 0xb0(%rsp), %r10
movq %rax, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rsi), %r13
addq $0x18, %r13
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, 0x40(%rsp)
js 0x69c7e
movl -0x14(%r13), %r12d
movl -0x10(%r13), %r14d
cmpq 0x8(%rsp), %rcx
jge 0x69cb6
movl -0x4(%r13), %r15d
movl (%r13), %ebp
xorl %ebx, %ebx
jmp 0x69d32
cmpq 0x8(%rsp), %rcx
jge 0x69cdc
movl -0x4(%r13), %r15d
movl (%r13), %ebp
cmpl %r15d, %ebp
movq 0xb8(%rsp), %rax
jbe 0x69d0a
movq %rbp, %r14
subq %r15, %r14
testq %r14, %r14
movl $0x0, %ecx
cmovleq %rcx, %r14
movl $0x2, %ebx
xorl %r12d, %r12d
jmp 0x69d24
movq %r10, %r15
subq %r14, %r15
movq 0xb8(%rsp), %rax
movq %rax, %rbp
subq %r12, %rbp
cmpq %rbp, %r15
jle 0x69cfd
addq %r14, %rbp
movl $0x1, %ebx
movq %rax, %r15
jmp 0x69d18
movq 0x10(%rsp), %rax
movl 0x4(%rax), %r14d
movl 0x8(%rax), %ebp
movq $-0x1, %r15
movl $0x3, %ebx
movq $-0x1, %r12
jmp 0x69d32
addq %r12, %r15
movl $0x1, %ebx
movq %r10, %rbp
jmp 0x69d18
movq %r15, %r12
subq %rbp, %r12
movl $0x2, %ebx
xorl %r14d, %r14d
testq %r12, %r12
movl $0x0, %ecx
cmovleq %rcx, %r12
cmpq %r10, %rbp
cmovgeq %r10, %rbp
cmpq %rax, %r15
cmovgeq %rax, %r15
subq $0x8, %rsp
movq 0x28(%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 %rbx
pushq %r15
pushq %r12
pushq %rbp
pushq %r14
callq 0x65f06
addq $0x70, %rsp
testq %rax, %rax
jne 0x69dc3
decq %rbp
decq %r15
movq 0xa8(%rsp), %rdi
movl %r14d, %esi
movq %rbp, %rdx
movq %r12, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x65b7a
addq $0x10, %r13
movq 0x40(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, 0x18(%rsp)
movq 0xb0(%rsp), %r10
jne 0x69c52
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c928b(%rip), %rdi    # 0x233083
leaq 0x1c7954(%rip), %rsi    # 0x231753
leaq 0x1c99b5(%rip), %rcx    # 0x2337bb
movl $0x43df, %edx           # imm = 0x43DF
callq 0x2110