// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: ovlp_base_aln(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_aln(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);
    // 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++) {
        if(i == iend || is_pri_aln(ch_a[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 == 0) && is_alnw(ch_a[l]) && is_alnw(ch_a[i]) 
                                            && (ch_a[l].strand == 0) && (ch_a[i].strand == 1)) {
                is_done = 1;
                // if(aux_o->x_id == 29033 && aux_o->y_id == 21307){
                //     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);
                // }
                // push_replace_alnw(aux_o, q[0], q[1]-1, t[0], t[1]-1, mode);///no need this
                push_replace_alnw_adv(z, wl, aux_o, q[0], q[1]-1, t[0], t[1]-1, mode);
            } else if(mode != 3) {
                if(mode == 1 || mode == 2) adjust_ext_offset(&(q[0]), &(q[1]), &(t[0]), &(t[1]), ql, tl, 0, mode);
                // if(aux_o->x_id == 29033 && aux_o->y_id == 21307){
                //     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_CNS_L, MAX_CNS_E, FORCE_CNS_L, -1, aux_o);
            }
            
            if(!is_done) {///postprocess
                // if(aux_o->x_id == 29033 && aux_o->y_id == 21307){
                //     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 = ovlp_base_aln_all(z, ch_a, ch_n, l, i, uref, hpc_g, rref, qstr, tu, ov, ql, tl, wl, exz, aux_o, e_rate);
            }
            // if(aux_o->x_id == 29033 && aux_o->y_id == 21307){
            //     fprintf(stderr, "-is_done::%ld[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld, l::%ld, i::%ld, ch_n::%ld\n", 
            //             is_done, __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode, l, i, ch_n);
            // }
            // if(rid == (uint64_t)-1) {
            //     fprintf(stderr, "+is_done::%ld[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld, l::%ld, i::%ld, ch_n::%ld\n", 
            //             is_done, __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode, l, i, ch_n);
            // }
            l = i;
        }
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movsd %xmm0, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movl (%rcx), %eax
movl 0xc(%rcx), %r14d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
movq $-0x1, %rbx
cmovneq %rax, %rbx
cmpq %r14, %rbx
jge 0x67fb3
movq %rdx, %r12
movq %rbx, %rax
shlq $0x4, %rax
leaq (%rax,%rsi), %r13
addq $0x10, %r13
leaq 0x1(%rbx), %rbp
negq %r14
movq %rdx, 0x30(%rsp)
movq %rsi, (%rsp)
movq %r14, 0x28(%rsp)
movq %r14, %rax
addq %rbp, %rax
je 0x67d15
movl (%r13), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cmpl %ecx, %eax
je 0x67d15
cmpl %eax, 0xc(%r13)
jae 0x67d15
movq %rbx, %rcx
jmp 0x67f89
testq %rbx, %rbx
js 0x67d9e
movq %rbx, %rcx
shlq $0x4, %rcx
movl 0x4(%rsi,%rcx), %r15d
movl 0x8(%rsi,%rcx), %eax
cmpq %r12, %rbp
jge 0x67de1
movl 0x4(%r13), %r11d
movl 0x8(%r13), %r10d
movl (%rsi,%rcx), %ecx
movl %ecx, %edx
notl %edx
testl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jne 0x67e10
testl %ecx, %ecx
js 0x67e10
cmpl $-0x1, (%r13)
jne 0x67e10
decq %r10
decq %r11
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x98(%rsp), %rdx
movl %eax, %ecx
movq %r10, %r8
movq %r15, %r9
pushq $0x0
pushq %r11
callq 0x65cb8
addq $0x10, %rsp
movq %rbp, %rcx
movq (%rsp), %rsi
jmp 0x67f89
cmpq %r12, %rbp
jge 0x67ee5
movl 0x4(%r13), %r11d
movl 0x8(%r13), %r10d
cmpl %r11d, %r10d
jbe 0x67e2b
movq %r10, %rax
subq %r11, %rax
testq %rax, %rax
movl $0x0, %ecx
cmovleq %rcx, %rax
movl $0x2, %r12d
xorl %r15d, %r15d
movq 0xa8(%rsp), %rcx
movq 0xa0(%rsp), %r14
jmp 0x67e55
movq 0xa0(%rsp), %r14
movq %r14, %r11
subq %rax, %r11
movq 0xa8(%rsp), %rcx
movq %rcx, %r10
subq %r15, %r10
cmpq %r10, %r11
jle 0x67e1d
addq %rax, %r10
movl $0x1, %r12d
movq %rcx, %r11
jmp 0x67e49
xorl %r12d, %r12d
movq 0xa0(%rsp), %r14
jmp 0x67e63
addq %r15, %r11
movl $0x1, %r12d
movq %r14, %r10
jmp 0x67e49
movq %r11, %r15
subq %r10, %r15
movl $0x2, %r12d
xorl %eax, %eax
movq 0xa8(%rsp), %rcx
movq 0xa0(%rsp), %r14
testq %r15, %r15
movl $0x0, %esi
cmovleq %rsi, %r15
cmpq %r14, %r10
cmovgeq %r14, %r10
cmpq %rcx, %r11
cmovgeq %rcx, %r11
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x80(%rsp), %rcx
movq 0x88(%rsp), %r8
movq 0x90(%rsp), %r9
movsd 0x28(%rsp), %xmm0
pushq 0xa0(%rsp)
pushq $-0x1
pushq $0x100                  # imm = 0x100
pushq $0x3ff                  # imm = 0x3FF
pushq $0xc00                  # imm = 0xC00
pushq %r14
pushq 0xc8(%rsp)
pushq 0x50(%rsp)
pushq %r12
pushq %r11
pushq %r15
pushq %r10
pushq %rax
callq 0x65f06
addq $0x70, %rsp
movq %rbp, %rcx
testq %rax, %rax
movq 0x30(%rsp), %r12
movq (%rsp), %rsi
movq 0x28(%rsp), %r14
jne 0x67f89
subq $0x50, %rsp
movq 0xe8(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, (%rsp)
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq %r12, %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq 0x68(%rsp), %r9
movsd 0x70(%rsp), %xmm0
callq 0x67a5a
movq 0x50(%rsp), %rsi
addq $0x50, %rsp
movq %rbp, %rcx
addq $0x10, %r13
leaq (%r14,%rbp), %rax
incq %rax
incq %rbp
movq %rcx, %rbx
cmpq $0x1, %rax
jne 0x67cf0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1cb0c9(%rip), %rdi    # 0x233083
leaq 0x1c9792(%rip), %rsi    # 0x231753
leaq 0x1cb0c8(%rip), %rcx    # 0x233090
movl $0x4148, %edx           # imm = 0x4148
callq 0x2110