// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: ovlp_base_aln_all(overlap_region*, k_mer_hit*, long, long, long, ul_idx_t const*, hpc_t*, All_reads*, char*, UC_Read*, ul_ov_t*, long, long, long, bit_extz_t*, overlap_region*, double)
int64_t ovlp_base_aln_all(overlap_region *z, k_mer_hit *ch_a, int64_t ch_n, 
int64_t soff, int64_t eoff, const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, 
char* qstr, UC_Read *tu, ul_ov_t *ov, int64_t ql, int64_t tl, int64_t wl, bit_extz_t *exz, 
overlap_region *aux_o, double e_rate)
{
    int64_t ibeg, iend, i, l, mode, q[2], t[2], is_done;
    ibeg = soff; iend = eoff;
    for (l = ibeg, i = ibeg + 1; i <= iend; i++) {
        l = i - 1;
        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] 
        }
        assert(mode != 3);
        if(mode == 1 || mode == 2) adjust_ext_offset(&(q[0]), &(q[1]), &(t[0]), &(t[1]), ql, tl, 0, mode);
        ///at cns chain, the base alignment fails; there is no anchor between soff and eoff
        if((eoff-soff<=1) && (((q[1]-q[0])>>1) < MAX_CNS_E)) {
            is_done = 0;
        } else {
            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(!is_done) {
            push_unmap_alnw(aux_o, q[0], q[1]-1, t[0], t[1]-1, mode);
            // chain_win_aln(z, dp, cl, q[0], q[1], t[0], t[1], ql, tl, wl, exz);
        }
        // if(aux_o->y_id == 109111) {
        //     fprintf(stderr, "<[M::%s::] utg%.6dl(%c), q::[%ld, %ld), t::[%ld, %ld), mode::%ld, is_done::%ld\n", 
        //             __func__, (int32_t)z->y_id+1, "+-"[z->y_pos_strand], q[0], q[1], t[0], t[1], mode, is_done);
        // }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %xmm0, 0x30(%rsp)
movq %r9, 0x28(%rsp)
movq %rcx, %r15
movq %rdx, 0x40(%rsp)
movq %rdi, 0x20(%rsp)
movq %rcx, %rax
shlq $0x4, %rax
leaq (%rax,%rsi), %r14
addq $0x18, %r14
movq %r8, 0x48(%rsp)
subq %rcx, %r8
movq %r8, 0x38(%rsp)
cmpq 0x48(%rsp), %r15
jge 0x36a24
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, (%rsp)
testq %r15, %r15
js 0x3688d
movl -0x14(%r14), %eax
movl -0x10(%r14), %ecx
movq %rax, (%rsp)
jmp 0x3689b
movq 0xb0(%rsp), %rax
movl 0x4(%rax), %ecx
pushq $-0x1
popq %rax
incq %r15
movl %ecx, %ebp
movq %rbp, 0x10(%rsp)
cmpq 0x40(%rsp), %r15
jge 0x368ba
movl -0x4(%r14), %ecx
movl (%r14), %edx
movq %rcx, 0x8(%rsp)
jmp 0x368c8
movq 0xb0(%rsp), %rcx
movl 0x8(%rcx), %edx
pushq $-0x1
popq %rcx
movl %edx, %r13d
movq %r13, 0x18(%rsp)
cmpq $-0x1, %rax
setne %dl
cmpq $-0x1, %rcx
setne %sil
testb %sil, %dl
je 0x368e8
xorl %ebx, %ebx
jmp 0x3694c
cmpq $-0x1, %rax
setne %dl
cmpq $-0x1, %rcx
sete %sil
pushq $0x1
popq %rbx
testb %sil, %dl
jne 0x36916
cmpq $-0x1, %rax
jne 0x36a35
pushq $0x2
popq %rbx
cmpq $-0x1, %rcx
je 0x36a35
leaq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %rsp, %rdx
leaq 0x8(%rsp), %rcx
movq 0xb8(%rsp), %r8
movq 0xc0(%rsp), %r9
pushq %rbx
pushq $0x0
callq 0x3023a
popq %rax
popq %rcx
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %r13
movq %r14, 0x50(%rsp)
cmpq $0x2, 0x38(%rsp)
jge 0x36975
movq %r13, %rax
subq %rbp, %rax
movq (%rsp), %r12
movq 0x8(%rsp), %r14
cmpq $0x7fe, %rax            # imm = 0x7FE
jge 0x3697e
jmp 0x369f5
movq (%rsp), %r12
movq 0x8(%rsp), %r14
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x98(%rsp), %rdx
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %r8
movq 0xb0(%rsp), %r9
movq 0x38(%rsp), %xmm0
pushq 0xe0(%rsp)
pushq $-0x1
pushq $0x200                  # imm = 0x200
pushq $0x7ff                  # imm = 0x7FF
pushq $0x2710                 # imm = 0x2710
pushq 0xe8(%rsp)
pushq 0x108(%rsp)
pushq 0x108(%rsp)
pushq %rbx
pushq %r14
pushq %r12
pushq %r13
pushq %rbp
callq 0x34db7
addq $0x70, %rsp
testq %rax, %rax
jne 0x36a16
decq %r13
decq %r14
movq 0xd8(%rsp), %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %r12, %rcx
movq %r14, %r8
movq %rbx, %r9
callq 0x34a5b
movq 0x50(%rsp), %r14
addq $0x10, %r14
jmp 0x36866
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ae4b0(%rip), %rdi    # 0x1e4eec
leaq 0x1acc60(%rip), %rsi    # 0x1e36a3
leaq 0x1ae4ac(%rip), %rcx    # 0x1e4ef6
movl $0x412b, %edx           # imm = 0x412B
callq 0x2110