// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: aln_wlst_adv_non_retrieve_exz(overlap_region*, char*, char*, long, bit_extz_t*, unsigned int, unsigned int, unsigned int, long, long, long, long, double, unsigned int)
inline uint32_t aln_wlst_adv_non_retrieve_exz(overlap_region *z, char *qstr, char *tstr, int64_t t_tot_l, bit_extz_t *exz, uint32_t max_err,
uint32_t rev, uint32_t id, int64_t qs, int64_t qe, int64_t t_s, int64_t block_s, double e_rate, uint32_t is_cigar)
{
    int64_t ql, tl, aln_l; window_list *p = NULL; ///int r_ts = 0, t_end;
    int64_t aux_beg, aux_end, t_pri_l; int64_t thres; char *q_string, *t_string; 
    ql = qe + 1 - qs;
    ///there are two potiential reasons for unmatched window:
    ///1. this window has a large number of differences
    ///2. DP does not start from the right offset
    thres = double_error_threshold(get_init_err_thres(ql, e_rate, block_s, max_err), ql);

    aln_l = ql + (thres << 1);

    if(!init_waln(thres, t_s, t_tot_l, aln_l, &aux_beg, &aux_end, &t_s, &t_pri_l)) return 0;
    if(t_pri_l + thres < ql) return 0;

    q_string = qstr + qs; t_string = tstr + t_s;

    tl = t_pri_l;
    if(is_cigar) {
        clear_align(*exz);
        ed_band_cal_semi_64_w_absent_diag_trace(t_string, tl, q_string, ql, thres, aux_beg, exz);
    } else {
        ed_band_cal_semi_64_w_absent_diag(t_string, tl, q_string, ql, thres, aux_beg, exz); exz->ps = 0;
    }

    // if(id == 40 && qs == 79670 && qe == 79824) {
    //     fprintf(stderr, "\n[M::%s::semi] exz->ps::%d, exz->pe::%d, exz->ts::%d, exz->te::%d, exz->err::%d, exz->cigar.n::%d\n", 
    //     __func__, exz->ps, exz->pe, exz->ts, exz->te, exz->err, (int32_t)exz->cigar.n);
    // }

    if(is_align(*exz)) {
        kv_pushp(window_list, z->w_list, &p);
        p->x_start = qs; p->x_end = qe; ///must set x_start/x_end here
        p->y_start = t_s + exz->ps;///difference
        p->y_end = t_s + exz->pe;
        p->error = exz->err;
        p->cidx = p->clen = 0;
        if(is_cigar) {
            push_wcigar(p, &(z->w_list), exz);
            ///this condition is always wrong
            ///in best case, r_ts = threshold, t_end = aln_l - thres - 1
            if ((((exz->pe+1) == tl) || (exz->ps == 0)) && (exz->err > 0)) {
                if(recal_boundary_non_retrieve_exz(q_string, tstr, t_tot_l, ql, tl, thres, t_s, exz->ps, exz->pe,
                exz->err, id, rev, exz, &t_s, &aux_beg, &aux_end)) {
                    //update cigar
                    z->w_list.c.n = p->cidx; push_wcigar(p, &(z->w_list), exz);

                    p->y_start = t_s + exz->ps;///difference
                    p->y_end = t_s + exz->pe;
                    p->error = exz->err;
                }
            }
        } 

        p->extra_begin = aux_beg;
        p->extra_end = aux_end;
        p->error_threshold = thres;
        z->align_length += ql; 
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, 0x48(%rsp)
movq %rsi, %r10
movq 0xd0(%rsp), %rax
movq 0xc8(%rsp), %rbx
subq 0xc0(%rsp), %rbx
leaq 0x1(%rbx), %r14
cmpq 0xd8(%rsp), %r14
jge 0x8b94e
cvtsi2sd %r14, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r8
cmpq $0x1f, %r8
movl $0x1f, %esi
cmovlq %r8, %rsi
testq %r8, %r8
movl $0x1, %r9d
cmovnel %esi, %r9d
cmpq $0x4, %r14
cmovll %esi, %r9d
leal (%r9,%r9), %r8d
testl %r9d, %r9d
movl $0x2, %esi
cmovnel %r8d, %esi
cmpl $0x4, %r14d
cmovll %r8d, %esi
cmpl $0x20, %esi
movl $0x1f, %r8d
movl $0x1f, %r13d
cmovgel %esi, %r13d
cmpl $0x12c, %r14d           # imm = 0x12C
cmovll %esi, %r13d
cmpl $0x1f, %r13d
cmovgel %r8d, %r13d
movslq %r13d, %r8
leaq (%r8,%r8), %rbp
leaq (%r14,%r8,2), %r12
testq %rax, %rax
sets %r9b
cmpq %rcx, %rax
setge %sil
movb $0x1, %r15b
movq $-0x1, %r11
orb %r9b, %sil
movq %rbp, 0x20(%rsp)
jne 0x8ba0b
movq %rcx, %rsi
subq %rax, %rsi
leaq (%rsi,%rbp), %r11
addq $0x1f, %r11
movq $-0x1, %r9
movq $-0x1, %rsi
movq $-0x1, %rbp
cmpq %r12, %r11
movq $-0x1, %r11
jl 0x8ba31
subq %r8, %rax
movq %rcx, %rbp
subq %rax, %rbp
cmpq %r12, %rbp
cmovgeq %r12, %rbp
movq %r12, %rsi
subq %rbp, %rsi
testq %rax, %rax
js 0x8ba22
xorl %r9d, %r9d
movq %rax, %r11
jmp 0x8ba2e
movq $-0x1, %r9
movq $-0x1, %rsi
movq $-0x1, %rbp
jmp 0x8ba31
addq %rax, %rbp
negq %rax
xorl %r11d, %r11d
movq %rax, %r9
xorl %r15d, %r15d
movq %r12, 0x68(%rsp)
movq %rcx, 0x70(%rsp)
movq %rdi, 0x8(%rsp)
xorl %r12d, %r12d
testb %r15b, %r15b
jne 0x8bd7f
leaq (%r8,%rbp), %rax
cmpq %r14, %rax
jl 0x8bd7f
movq %rsi, 0x28(%rsp)
movq %r8, 0x10(%rsp)
addq 0xc0(%rsp), %r10
movq %rdx, 0x60(%rsp)
movq %r11, 0x18(%rsp)
leaq (%rdx,%r11), %rdi
cmpl $0x0, 0xe0(%rsp)
movq %r10, 0x58(%rsp)
movq %r9, 0x30(%rsp)
je 0x8bab0
movq 0x48(%rsp), %r15
movl $0x7fffffff, 0x2c(%r15) # imm = 0x7FFFFFFF
movq %r15, (%rsp)
movl %ebp, %esi
movq %r10, %rdx
movl %r14d, %ecx
movl %r13d, %r8d
callq 0x8dd8a
jmp 0x8bad1
movq 0x48(%rsp), %r15
movq %r15, (%rsp)
movl %ebp, %esi
movq %r10, %rdx
movl %r14d, %ecx
movl %r13d, %r8d
callq 0x8c179
movl $0x0, 0x10(%r15)
movl 0x2c(%r15), %eax
cmpl 0x28(%r15), %eax
jg 0x8bd7f
movq 0x8(%rsp), %r12
movq 0x50(%r12), %rax
cmpq %rax, 0x48(%r12)
jne 0x8bb18
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x50(%r12)
movq 0x58(%r12), %rdi
shlq $0x5, %rsi
callq 0x2370
movq %rax, 0x58(%r12)
movq 0x48(%r12), %rax
movq 0x58(%r12), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x48(%r12)
shlq $0x5, %rax
leaq (%rcx,%rax), %rdi
movq 0xc0(%rsp), %rdx
movl %edx, (%rcx,%rax)
movq 0xc8(%rsp), %rdx
movl %edx, 0x4(%rcx,%rax)
movl 0x10(%r15), %edx
movq 0x18(%rsp), %rsi
addl %esi, %edx
movl %edx, 0x8(%rcx,%rax)
movl 0x14(%r15), %edx
addl %esi, %edx
movl %edx, 0xc(%rcx,%rax)
movzwl 0x2c(%r15), %edx
movw %dx, 0x14(%rcx,%rax)
movq $0x0, 0x18(%rcx,%rax)
cmpl $0x0, 0xe0(%rsp)
je 0x8bc85
leaq 0x48(%r12), %rsi
movq %rdi, 0x40(%rsp)
movq %rsi, 0x50(%rsp)
movq %r15, %rdx
callq 0x4bdb5
movslq 0x14(%r15), %rcx
leaq 0x1(%rcx), %rsi
cmpq %rsi, %rbp
je 0x8bbc3
cmpl $0x0, 0x10(%r15)
je 0x8bbc3
movq 0x10(%rsp), %r9
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r10
jmp 0x8bd07
movl 0x2c(%r15), %r12d
testl %r12d, %r12d
movq 0x10(%rsp), %r9
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r10
jle 0x8bc99
cmpl $0x0, 0x10(%r15)
movq 0x18(%rsp), %rax
movq 0x60(%rsp), %rdi
je 0x8bc07
movb $0x1, %r11b
cmpq %rbp, %rsi
jne 0x8bcfd
movq 0x18(%rsp), %rax
subq %rbx, %rax
addq %rcx, %rax
testq %rax, %rax
sets %cl
movq 0x70(%rsp), %r15
cmpq %r15, %rax
setge %sil
movb $0x1, %r11b
movq $-0x1, %rdx
orb %cl, %sil
jne 0x8bca0
movq 0x20(%rsp), %r11
addq %r15, %r11
subq %rax, %r11
addq $0x1f, %r11
movq $-0x1, 0x20(%rsp)
movq $-0x1, 0x38(%rsp)
movq $-0x1, %rsi
movb $0x1, %cl
movq 0x68(%rsp), %rbx
cmpq %rbx, %r11
movb $0x1, %r11b
jl 0x8bcd1
subq %r9, %rax
subq %rax, %r15
cmpq %rbx, %r15
movq %r15, %rsi
cmovgeq %rbx, %rsi
subq %rsi, %rbx
testq %rax, %rax
js 0x8bcbd
movq $0x0, 0x20(%rsp)
movq %rax, %rdx
jmp 0x8bcca
movq 0x10(%rsp), %r9
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r10
jmp 0x8bd65
movq 0x8(%rsp), %r12
jmp 0x8bd07
movq $-0x1, 0x20(%rsp)
movq $-0x1, 0x38(%rsp)
movq $-0x1, %rsi
movb $0x1, %cl
jmp 0x8bcd1
addq %rax, %rsi
negq %rax
xorl %edx, %edx
movq %rax, 0x20(%rsp)
movq %rbx, 0x38(%rsp)
xorl %ecx, %ecx
testb %cl, %cl
je 0x8bce1
movq 0x8(%rsp), %r12
movq 0x48(%rsp), %r15
jmp 0x8bd02
movq %rdx, %rbx
cmpq 0x18(%rsp), %rdx
movq 0x48(%rsp), %r15
jne 0x8bd91
cmpq %rbp, %rsi
jne 0x8bd91
movq 0x8(%rsp), %r12
testb %r11b, %r11b
je 0x8bd0e
movq 0x40(%rsp), %rdi
jmp 0x8bd65
movq 0x40(%rsp), %r13
movl 0x18(%r13), %eax
movq %rax, 0x60(%r12)
movq %r13, %rdi
movq 0x50(%rsp), %rsi
movq %r15, %rdx
movq %r8, %rbx
movq %r10, 0x30(%rsp)
movq 0x18(%rsp), %rbp
callq 0x4bdb5
movq %r13, %rdi
movq 0x30(%rsp), %r10
movq %rbx, %r8
movq 0x10(%rsp), %r9
movl 0x10(%r15), %eax
addl %ebp, %eax
movl %eax, 0x8(%r13)
addl 0x14(%r15), %ebp
movl %ebp, 0xc(%r13)
movzwl 0x2c(%r15), %eax
movw %ax, 0x14(%r13)
movw %r10w, 0x10(%rdi)
movw %r8w, 0x12(%rdi)
movw %r9w, 0x16(%rdi)
addl %r14d, 0x28(%r12)
movl $0x1, %r12d
movl %r12d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r10, %rbp
addq %rbx, %rdi
movl $0x7fffffff, 0x2c(%r15) # imm = 0x7FFFFFFF
movq %r15, (%rsp)
movq 0x58(%rsp), %rdx
movl %r14d, %ecx
movl %r13d, %r8d
movq 0x20(%rsp), %r13
movl %r13d, %r9d
callq 0x8dd8a
movl 0x2c(%r15), %eax
cmpl %r12d, %eax
jge 0x8bdf8
cmpl 0x28(%r15), %eax
movq 0x8(%rsp), %r12
movq 0x10(%rsp), %r9
movq 0x28(%rsp), %r8
movq %rbp, %r10
movb $0x1, %r11b
jg 0x8bd02
xorl %r11d, %r11d
movq %rbx, 0x18(%rsp)
movq %r13, %r10
movq 0x38(%rsp), %r8
jmp 0x8bd02
movq 0x8(%rsp), %r12
movq 0x10(%rsp), %r9
movq 0x28(%rsp), %r8
movq %rbp, %r10
movb $0x1, %r11b
jmp 0x8bd02