// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl 0x40(%rbp), %eax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
movq %r8, -0x58(%rbp)
movl %r9d, -0x5c(%rbp)
movsd %xmm0, -0x68(%rbp)
movq $0x0, -0x88(%rbp)
movq 0x28(%rbp), %rax
addq $0x1, %rax
subq 0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movsd -0x68(%rbp), %xmm0
movq 0x38(%rbp), %rsi
movl -0x5c(%rbp), %eax
movl %eax, %edx
callq 0x9e1c0
movl %eax, %edi
movq -0x70(%rbp), %rax
movl %eax, %esi
callq 0x9e370
cltq
movq %rax, -0xa8(%rbp)
movq -0x70(%rbp), %rax
movq -0xa8(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0xa8(%rbp), %rdi
movq 0x30(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x80(%rbp), %rcx
leaq -0x90(%rbp), %r8
leaq -0x98(%rbp), %r9
leaq 0x30(%rbp), %r10
leaq -0xa0(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x33f90
cmpl $0x0, %eax
jne 0xa8012
movl $0x0, -0x2c(%rbp)
jmp 0xa8410
movq -0xa0(%rbp), %rax
addq -0xa8(%rbp), %rax
cmpq -0x70(%rbp), %rax
jge 0xa8032
movl $0x0, -0x2c(%rbp)
jmp 0xa8410
movq -0x40(%rbp), %rax
addq 0x20(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x48(%rbp), %rax
addq 0x30(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpl $0x0, 0x40(%rbp)
je 0xa80a9
movq -0x58(%rbp), %rax
movl $0x7fffffff, 0x2c(%rax) # imm = 0x7FFFFFFF
movq -0xb8(%rbp), %rdi
movq -0x78(%rbp), %rax
movl %eax, %esi
movq -0xb0(%rbp), %rdx
movq -0x70(%rbp), %rax
movl %eax, %ecx
movq -0xa8(%rbp), %rax
movl %eax, %r8d
movq -0x90(%rbp), %rax
movl %eax, %r9d
movq -0x58(%rbp), %rax
movq %rax, (%rsp)
callq 0xab870
jmp 0xa80ef
movq -0xb8(%rbp), %rdi
movq -0x78(%rbp), %rax
movl %eax, %esi
movq -0xb0(%rbp), %rdx
movq -0x70(%rbp), %rax
movl %eax, %ecx
movq -0xa8(%rbp), %rax
movl %eax, %r8d
movq -0x90(%rbp), %rax
movl %eax, %r9d
movq -0x58(%rbp), %rax
movq %rax, (%rsp)
callq 0xa8960
movq -0x58(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x58(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x58(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jg 0xa8409
jmp 0xa8105
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jne 0xa8177
movq -0x38(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0xa8136
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
shlq %rax
movq %rax, -0xc0(%rbp)
jmp 0xa8144
movl $0x2, %eax
movq %rax, -0xc0(%rbp)
jmp 0xa8144
movq -0xc0(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rsi
shlq $0x5, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rdx
movq 0x48(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x48(%rdx)
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq 0x20(%rbp), %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, (%rax)
movq 0x28(%rbp), %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x4(%rax)
movq 0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x8(%rax)
movq 0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq 0x14(%rcx), %rcx
addq %rcx, %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0x2c(%rax), %eax
movw %ax, %cx
movq -0x88(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x88(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x88(%rbp), %rax
movl $0x0, 0x18(%rax)
cmpl $0x0, 0x40(%rbp)
je 0xa83b0
movq -0x88(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x48, %rsi
movq -0x58(%rbp), %rdx
callq 0x38180
movq -0x58(%rbp), %rax
movl 0x14(%rax), %eax
addl $0x1, %eax
cltq
cmpq -0x78(%rbp), %rax
je 0xa8268
movq -0x58(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0xa83ae
movq -0x58(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jle 0xa83ae
movq -0xb0(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq -0x78(%rbp), %r8
movq -0xa8(%rbp), %r9
movq 0x30(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x58(%rbp), %rax
movslq 0x10(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x58(%rbp), %rax
movslq 0x14(%rax), %r13
movq -0x58(%rbp), %rax
movslq 0x2c(%rax), %r12
movl 0x18(%rbp), %eax
movl %eax, %r15d
movl 0x10(%rbp), %r14d
movq -0x58(%rbp), %rbx
leaq 0x30(%rbp), %r11
leaq -0x90(%rbp), %r10
leaq -0x98(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, (%rsp)
movq -0xd0(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0xc8(%rbp), %rax
movq %r13, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movl %r14d, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0xc7100
cmpl $0x0, %eax
je 0xa83ac
movq -0x88(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x88(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x48, %rsi
movq -0x58(%rbp), %rdx
callq 0x38180
movq 0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x8(%rax)
movq 0x30(%rbp), %rax
movq -0x58(%rbp), %rcx
movslq 0x14(%rcx), %rcx
addq %rcx, %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rax
movl 0x2c(%rax), %eax
movw %ax, %cx
movq -0x88(%rbp), %rax
movw %cx, 0x14(%rax)
jmp 0xa83ae
jmp 0xa83b0
movq -0x90(%rbp), %rax
movw %ax, %cx
movq -0x88(%rbp), %rax
movw %cx, 0x10(%rax)
movq -0x98(%rbp), %rax
movw %ax, %cx
movq -0x88(%rbp), %rax
movw %cx, 0x12(%rax)
movq -0xa8(%rbp), %rax
movw %ax, %cx
movq -0x88(%rbp), %rax
movw %cx, 0x16(%rax)
movq -0x70(%rbp), %rdx
movq -0x38(%rbp), %rax
movl 0x28(%rax), %ecx
addq %rdx, %rcx
movl %ecx, 0x28(%rax)
movl $0x1, -0x2c(%rbp)
jmp 0xa8410
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop