// File: /workspace/github_cpp_makefile_star2_O3/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 $0x88, %rsp
movq %rsi, %r10
movq 0xe0(%rsp), %r15
movq 0xd8(%rsp), %r12
subq 0xd0(%rsp), %r12
leaq 0x1(%r12), %r14
cmpq 0xe8(%rsp), %r14
jge 0x8ad5f
cvtsi2sd %r14, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
cmpq $0x1f, %rax
movl $0x1f, %esi
cmovlq %rax, %rsi
testq %rax, %rax
movl $0x1, %r9d
cmovnel %esi, %r9d
cmpq $0x4, %r14
cmovll %esi, %r9d
leal (%r9,%r9), %eax
testl %r9d, %r9d
movl $0x2, %esi
cmovnel %eax, %esi
cmpl $0x4, %r14d
cmovll %eax, %esi
cmpl $0x20, %esi
movl $0x1f, %eax
movl $0x1f, %ebx
cmovgel %esi, %ebx
cmpl $0x12c, %r14d           # imm = 0x12C
cmovll %esi, %ebx
cmpl $0x1f, %ebx
cmovgel %eax, %ebx
testq %r15, %r15
sets %al
cmpq %rcx, %r15
setge %sil
xorl %r13d, %r13d
orb %al, %sil
jne 0x8b059
movslq %ebx, %r9
leaq (%r9,%r9), %r11
leaq (%r14,%r9,2), %rsi
leaq 0x1f(%rcx), %rax
movq %rax, 0x80(%rsp)
subq %r15, %rax
movq %r11, 0x78(%rsp)
addq %r11, %rax
cmpq %rsi, %rax
jl 0x8b059
subq %r9, %r15
movq %rcx, %r11
subq %r15, %r11
cmpq %rsi, %r11
cmovgeq %rsi, %r11
xorl %r13d, %r13d
testq %r15, %r15
movl $0x0, %ebp
cmovgq %r15, %rbp
movl $0x0, %eax
cmovsq %r15, %rax
addq %r11, %rax
movq %rax, 0x40(%rsp)
addq %r9, %rax
cmpq %r14, %rax
jl 0x8b059
movq %r11, 0x50(%rsp)
movq %rsi, 0x20(%rsp)
movq %r9, 0x28(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdi, 0x18(%rsp)
movq %r15, %rax
negq %rax
sarq $0x3f, %r15
andq %rax, %r15
addq 0xd0(%rsp), %r10
movq %rdx, 0x70(%rsp)
movq %rbp, 0x30(%rsp)
leaq (%rdx,%rbp), %rdi
cmpl $0x0, 0xf0(%rsp)
movq %r8, 0x58(%rsp)
movq %r10, 0x68(%rsp)
je 0x8ae90
movl $0x7fffffff, 0x2c(%r8)  # imm = 0x7FFFFFFF
movq %r8, (%rsp)
movq 0x40(%rsp), %rbp
movl %ebp, %esi
movq %r10, %rdx
movl %r14d, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x8d32c
movq 0x58(%rsp), %rdx
jmp 0x8aeb8
movq %r8, (%rsp)
movq 0x40(%rsp), %rbp
movl %ebp, %esi
movq %r10, %rdx
movl %r14d, %ecx
movl %ebx, %r8d
movl %r15d, %r9d
callq 0x8b419
movq 0x58(%rsp), %rdx
movl $0x0, 0x10(%rdx)
movl 0x2c(%rdx), %ecx
cmpl 0x28(%rdx), %ecx
movq 0x18(%rsp), %r11
jg 0x8b059
leaq 0x48(%r11), %r9
movq 0x48(%r11), %r8
cmpq 0x50(%r11), %r8
jne 0x8af21
leaq (%r8,%r8), %rax
testq %r8, %r8
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x50(%r11)
movq 0x18(%rsp), %rax
movq 0x58(%rax), %rdi
shlq $0x5, %rsi
movq %rdx, %r13
movq %r9, %rbp
callq 0x2370
movq %rbp, %r9
movq 0x40(%rsp), %rbp
movq %r13, %rdx
movq 0x18(%rsp), %r11
movq %rax, 0x58(%r11)
movq 0x48(%r11), %r8
movl 0x2c(%r13), %ecx
jmp 0x8af25
movq 0x58(%r11), %rax
leaq 0x1(%r8), %rsi
shlq $0x5, %r8
leaq (%rax,%r8), %r13
movq %rsi, (%r9)
movq 0xd0(%rsp), %rsi
movl %esi, (%rax,%r8)
movq 0xd8(%rsp), %rsi
movl %esi, 0x4(%rax,%r8)
movq 0x10(%rdx), %xmm0
movd 0x30(%rsp), %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, 0x8(%rax,%r8)
movw %cx, 0x14(%rax,%r8)
movq $0x0, 0x18(%rax,%r8)
cmpl $0x0, 0xf0(%rsp)
je 0x8b032
movq %r13, 0x10(%rsp)
movq %r13, %rdi
movq %r9, 0x60(%rsp)
movq %r9, %rsi
movq %rdx, %r13
callq 0x4b41c
movq %r13, %r8
movslq 0x14(%r13), %rax
leaq 0x1(%rax), %rcx
cmpq %rcx, %rbp
je 0x8afc5
cmpl $0x0, 0x10(%r8)
je 0x8afc5
movq 0x18(%rsp), %r11
movq 0x28(%rsp), %r9
movq 0x20(%rsp), %rsi
jmp 0x8b02b
movl 0x2c(%r8), %edx
testl %edx, %edx
movq 0x18(%rsp), %r11
movq 0x28(%rsp), %r9
movq 0x20(%rsp), %rsi
jle 0x8b02b
movl %edx, 0x4c(%rsp)
cmpl $0x0, 0x10(%r8)
movq 0x30(%rsp), %r10
movq 0x38(%rsp), %rdx
movq 0x70(%rsp), %rdi
je 0x8b006
cmpq %rbp, %rcx
jne 0x8b02b
movq 0x30(%rsp), %r10
subq %r12, %r10
addq %rax, %r10
testq %r10, %r10
sets %al
cmpq %rdx, %r10
setge %cl
orb %al, %cl
jne 0x8b02b
movq 0x80(%rsp), %rax
addq 0x78(%rsp), %rax
subq %r10, %rax
cmpq %rsi, %rax
jge 0x8b06e
movq 0x10(%rsp), %r13
jmp 0x8b03c
movq 0x28(%rsp), %r9
movq 0x20(%rsp), %rsi
subl 0x50(%rsp), %esi
movw %r15w, 0x10(%r13)
movw %si, 0x12(%r13)
movw %r9w, 0x16(%r13)
addl %r14d, 0x28(%r11)
movl $0x1, %r13d
movl %r13d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq %r9, %r10
subq %r10, %rdx
cmpq %rsi, %rdx
cmovgeq %rsi, %rdx
xorl %esi, %esi
testq %r10, %r10
movl $0x0, %r12d
cmovgq %r10, %r12
movq %r10, %rax
cmovsq %r10, %rsi
addq %rdx, %rsi
cmpq 0x30(%rsp), %r12
jne 0x8b0a4
cmpq %rbp, %rsi
je 0x8afbe
movq %rdx, 0x38(%rsp)
movq %rax, %r9
negq %rax
sarq $0x3f, %r9
andq %rax, %r9
addq %r12, %rdi
movl $0x7fffffff, 0x2c(%r8)  # imm = 0x7FFFFFFF
movq %r8, (%rsp)
movq 0x68(%rsp), %rdx
movl %r14d, %ecx
movl %ebx, %r8d
movq %r9, %rbp
callq 0x8d32c
movl 0x2c(%r13), %eax
cmpl 0x4c(%rsp), %eax
jge 0x8afb4
movq %r13, %rdx
cmpl 0x28(%r13), %eax
movq 0x18(%rsp), %r11
movq 0x28(%rsp), %r9
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %r13
jg 0x8b03c
movl 0x18(%r13), %eax
movq %rax, 0x60(%r11)
movq %r13, %rdi
movq 0x60(%rsp), %rsi
movq %rdx, %rbx
callq 0x4b41c
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %r9
movq 0x18(%rsp), %r11
movq 0x10(%rbx), %xmm0
movd %r12d, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, 0x8(%r13)
movzwl 0x2c(%rbx), %eax
movw %ax, 0x14(%r13)
movq %rbp, %r15
movq 0x38(%rsp), %rbp
movq %rbp, 0x50(%rsp)
jmp 0x8b03c