// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %xmm0, 0x48(%rsp)
movq %r9, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rdi, 0x28(%rsp)
movl (%rcx), %edx
movq %rcx, 0x20(%rsp)
movl 0xc(%rcx), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rdx
pushq $-0x1
popq %rax
cmoveq %rax, %rdx
movq %rcx, 0x50(%rsp)
cmpq %rcx, %rdx
jge 0x38956
movq %rdx, %rax
shlq $0x4, %rax
leaq (%rax,%rsi), %rcx
addq $0x18, %rcx
cmpq %rdx, 0x50(%rsp)
je 0x38947
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, (%rsp)
testq %rdx, %rdx
js 0x387cb
movl -0x14(%rcx), %ebp
movl -0x10(%rcx), %eax
movq %rbp, (%rsp)
jmp 0x387d6
movq 0x20(%rsp), %rax
movl 0x4(%rax), %eax
pushq $-0x1
popq %rbp
incq %rdx
movl %eax, %r15d
movq %r15, 0x10(%rsp)
cmpq 0x30(%rsp), %rdx
movq %rcx, 0x58(%rsp)
jge 0x387f9
movl -0x4(%rcx), %ebx
movl (%rcx), %eax
movq %rbx, 0x8(%rsp)
jmp 0x38804
movq 0x20(%rsp), %rax
movl 0x8(%rax), %eax
pushq $-0x1
popq %rbx
movl %eax, %r14d
movq %r14, 0x18(%rsp)
cmpq $-0x1, %rbp
setne %al
cmpq $-0x1, %rbx
setne %cl
testb %cl, %al
movq %rdx, 0x60(%rsp)
je 0x38828
xorl %r12d, %r12d
jmp 0x3889e
cmpq $-0x1, %rbp
setne %al
cmpq $-0x1, %rbx
sete %cl
pushq $0x1
popq %r13
testb %cl, %al
jne 0x3885b
cmpq $-0x1, %rbx
setne %al
cmpq $-0x1, %rbp
sete %cl
andb %al, %cl
pushq $0x2
popq %r13
pushq $0x3
popq %r12
cmpb $0x1, %cl
jne 0x3889e
leaq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %rsp, %rdx
leaq 0x8(%rsp), %rcx
movq 0xd0(%rsp), %r8
movq 0xd8(%rsp), %r9
pushq %r13
pushq $0x0
callq 0x3023a
popq %rax
popq %rcx
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r14
movq (%rsp), %rbp
movq 0x8(%rsp), %rbx
movq %r13, %r12
subq $0x8, %rsp
movq 0x30(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0xa8(%rsp), %rdx
movq 0xb0(%rsp), %rcx
movq 0xb8(%rsp), %r8
movq 0xc0(%rsp), %r9
movq 0x50(%rsp), %xmm0
pushq 0xd0(%rsp)
pushq $-0x1
pushq $0x200                  # imm = 0x200
pushq $0x7ff                  # imm = 0x7FF
pushq $0x2710                 # imm = 0x2710
pushq 0x100(%rsp)
pushq 0xf8(%rsp)
pushq 0x78(%rsp)
pushq %r12
pushq %rbx
pushq %rbp
pushq %r14
pushq %r15
callq 0x34db7
addq $0x70, %rsp
testq %rax, %rax
jne 0x38934
decq %r14
decq %rbx
movq 0xc8(%rsp), %rdi
movl %r15d, %esi
movq %r14, %rdx
movq %rbp, %rcx
movq %rbx, %r8
movq %r12, %r9
callq 0x34a5b
movq 0x58(%rsp), %rcx
addq $0x10, %rcx
movq 0x60(%rsp), %rdx
jmp 0x387a6
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ac676(%rip), %rdi    # 0x1e4fd3
leaq 0x1aad3f(%rip), %rsi    # 0x1e36a3
leaq 0x1acda0(%rip), %rcx    # 0x1e570b
movl $0x43df, %edx           # imm = 0x43DF
callq 0x2110