// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movsd %xmm0, 0x18(%rsp)
movq %r9, 0x10(%rsp)
movq %rdx, (%rsp)
movq %rdi, 0x8(%rsp)
movq %r8, 0x30(%rsp)
subq %rcx, %r8
movq %r8, 0x28(%rsp)
jle 0x67c54
movq %rcx, %r12
movq 0x98(%rsp), %r10
movq %rcx, %rax
shlq $0x4, %rax
leaq (%rax,%rsi), %r14
addq $0x18, %r14
movq %r12, %rax
incq %r12
testq %rax, %rax
js 0x67ad1
movl -0x14(%r14), %r15d
movl -0x10(%r14), %ebp
cmpq (%rsp), %r12
jge 0x67b0c
movl -0x4(%r14), %ebx
movl (%r14), %r13d
xorl %r11d, %r11d
jmp 0x67b69
cmpq (%rsp), %r12
jge 0x67c65
movl -0x4(%r14), %ebx
movl (%r14), %r13d
cmpl %ebx, %r13d
movq 0xa0(%rsp), %rax
jbe 0x67b33
movq %r13, %rbp
subq %rbx, %rbp
testq %rbp, %rbp
movl $0x0, %ecx
cmovleq %rcx, %rbp
movl $0x2, %r11d
xorl %r15d, %r15d
jmp 0x67b5b
movq %r10, %rbx
subq %rbp, %rbx
movq 0xa0(%rsp), %rax
movq %rax, %r13
subq %r15, %r13
cmpq %r13, %rbx
jle 0x67b43
addq %rbp, %r13
movl $0x1, %r11d
movq %rax, %rbx
jmp 0x67b4f
movq %rbx, %r15
subq %r13, %r15
movl $0x2, %r11d
xorl %ebp, %ebp
jmp 0x67b4f
addq %r15, %rbx
movl $0x1, %r11d
movq %r10, %r13
testq %r15, %r15
movl $0x0, %ecx
cmovleq %rcx, %r15
cmpq %r10, %r13
cmovgeq %r10, %r13
cmpq %rax, %rbx
cmovgeq %rax, %rbx
cmpq $0x1, 0x28(%rsp)
jg 0x67b83
movq %r13, %rax
subq %rbp, %rax
cmpq $0x7fe, %rax            # imm = 0x7FE
jl 0x67c1c
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x80(%rsp), %rcx
movq 0x88(%rsp), %r8
movq 0x90(%rsp), %r9
movsd 0x20(%rsp), %xmm0
pushq 0xc0(%rsp)
pushq $-0x1
pushq $0x200                  # imm = 0x200
pushq $0x7ff                  # imm = 0x7FF
pushq $0x2710                 # imm = 0x2710
pushq %r10
pushq 0xe8(%rsp)
pushq 0xe8(%rsp)
pushq %r11
pushq %rbx
pushq %r15
pushq %r13
pushq %rbp
movq %r15, 0x90(%rsp)
movq %rbp, %r15
movq %r12, %rbp
movq %r11, %r12
callq 0x65f06
movq %r12, %r11
movq %rbp, %r12
movq %r15, %rbp
movq 0x90(%rsp), %r15
movq 0x108(%rsp), %r10
addq $0x70, %rsp
testq %rax, %rax
jne 0x67c45
decq %r13
decq %rbx
movq 0xb8(%rsp), %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %r11, %r9
callq 0x65b7a
movq 0x98(%rsp), %r10
addq $0x10, %r14
cmpq %r12, 0x30(%rsp)
jne 0x67aa9
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1cb330(%rip), %rdi    # 0x232f9c
leaq 0x1c9ae0(%rip), %rsi    # 0x231753
leaq 0x1cb32c(%rip), %rcx    # 0x232fa6
movl $0x412b, %edx           # imm = 0x412B
callq 0x2110