// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: aln_wlst_adv(overlap_region*, All_reads*, hpc_t*, ul_idx_t const*, char*, char*, char*, Correct_dumy*, unsigned int, unsigned int, long, long, long, long, double, unsigned int)
inline uint32_t aln_wlst_adv(overlap_region *z, All_reads *rref, hpc_t *hpc_g, 
const ul_idx_t *uref, char *qstr, char *tstr, char *tstr1, Correct_dumy* dumy,
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, aln_l, t_tot_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; unsigned int error;
    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
    if(rref) {
        thres = double_error_threshold(get_init_err_thres(ql, e_rate, block_s, THRESHOLD), ql);
    } else {
        thres = double_ul_error_threshold(get_init_err_thres(ql, e_rate, block_s, THRESHOLD_MAX_SIZE), ql);
    }
    aln_l = ql + (thres << 1);
    if(hpc_g) t_tot_l = hpc_len(*hpc_g, id);
    else if(uref) t_tot_l = uref->ug->u.a[id].len;
    else t_tot_l = Get_READ_LENGTH((*rref), id);

    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; 
    if(rref) {
        fill_subregion(tstr, t_s, t_pri_l, rev, rref, id, aux_beg, aux_end); t_string = tstr;
    } else {
        t_string = return_str_seq(tstr, t_s, t_pri_l, rev, hpc_g, uref, id, aux_beg, aux_end);
    }

    if(is_cigar) {
        ///note!!! need notification
        t_end = Reserve_Banded_BPM_PATH(t_string, aln_l, q_string, ql, thres, &error, &r_ts,
        &(dumy->path_length), dumy->matrix_bit, dumy->path, -1, -1);
    } else {
        ///note!!! need notification
        t_end = Reserve_Banded_BPM(t_string, aln_l, q_string, ql, thres, &error);    
    }
    if(error!=(unsigned int)-1) {
        if(is_cigar) {
            ///this condition is always wrong
            ///in best case, r_ts = threshold, t_end = aln_l - thres - 1
            if (((t_end+1) == aln_l) || (r_ts == 0)) {
                if(recal_boundary(q_string, tstr1, ql, thres, t_s, r_ts, t_end,
                aux_beg, aux_end, error, id, aln_l, rev, dumy, rref, hpc_g, uref, 
                &t_s, &r_ts, &t_end, &aux_beg, &aux_end, &error)) {
                    t_string = update_des_str(tstr, t_s, aln_l-aux_beg-aux_end, rev, rref, hpc_g, uref,
                                                    id, aux_beg, aux_end, hpc_g?NULL:tstr1);
                }
            }
        }

        kv_pushp(window_list, z->w_list, &p);
        p->x_start = qs; p->x_end = qe; ///must set x_start/x_end here
        if(is_cigar) {
            generate_cigar(dumy->path, dumy->path_length, p, &(z->w_list), &r_ts, &t_end, &error, q_string, ql, t_string);  
        } else {
            p->cidx = p->clen = 0;
        }
        p->y_start = t_s + r_ts;///difference
        p->y_end = t_s + t_end;
        p->error = error;
        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 %r8, %r10
movq %rdx, %rbx
movq %rsi, %r11
movq 0xf8(%rsp), %rdx
movq 0xe8(%rsp), %r14
movq 0xe0(%rsp), %rsi
movl 0xd8(%rsp), %eax
movl $0x0, 0x8(%rsp)
subq %rsi, %r14
incq %r14
testq %r11, %r11
je 0x89767
movl $0xf, %r8d
cmpq %rdx, %r14
jge 0x89734
cvtsi2sd %r14, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r8
cmpq $0x1f, %r8
movl $0x1f, %edx
cmovlq %r8, %rdx
testq %r8, %r8
movl $0x1, %r8d
cmovnel %edx, %r8d
cmpq $0x4, %r14
cmovll %edx, %r8d
leal (%r8,%r8), %edx
testl %r8d, %r8d
movl $0x2, %r8d
cmovnel %edx, %r8d
cmpl $0x4, %r14d
cmovll %edx, %r8d
cmpl $0x20, %r8d
movl $0x1f, %edx
cmovgel %r8d, %edx
cmpl $0x12c, %r14d           # imm = 0x12C
cmovll %r8d, %edx
jmp 0x897d2
movl $0x1f, %r8d
cmpq %rdx, %r14
jge 0x897a2
cvtsi2sd %r14, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r8
cmpq $0x1f, %r8
movl $0x1f, %edx
cmovlq %r8, %rdx
testq %r8, %r8
movl $0x1, %r8d
cmovnel %edx, %r8d
cmpq $0x4, %r14
cmovll %edx, %r8d
testl %r8d, %r8d
movl $0x1, %edx
cmovnel %r8d, %edx
cmpl $0x4, %r14d
cmovll %r8d, %edx
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x1a7dba(%rip), %xmm0   # 0x231580
cvttsd2si %xmm0, %r8d
cmpl %r8d, %edx
cmovlel %r8d, %edx
movq 0xf0(%rsp), %r13
cmpl $0x1f, %edx
movl $0x1f, %r8d
cmovll %edx, %r8d
movl %eax, %ebp
testq %rbx, %rbx
je 0x89810
movq (%rbx), %rax
movq 0x10(%rax), %rax
leaq (,%rbp,4), %rdx
addq %rbp, %rdx
movl (%rax,%rdx,8), %r15d
shrl %r15d
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
jmp 0x8983c
testq %rcx, %rcx
je 0x89834
movq (%rcx), %rax
movq 0x10(%rax), %rax
leaq (,%rbp,4), %rdx
addq %rbp, %rdx
movl (%rax,%rdx,8), %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
jmp 0x8983c
movq 0x18(%r11), %rax
movq (%rax,%rbp,8), %r15
xorl %r12d, %r12d
testq %r13, %r13
js 0x89dcc
cmpq %r13, %r15
jle 0x89dcc
movq %rbp, 0x20(%rsp)
movslq %r8d, %rdx
leaq (%rdx,%rdx), %rax
leaq (%r14,%rdx,2), %r8
subq %r13, %rax
addq %r15, %rax
addq $0x1f, %rax
cmpq %r8, %rax
jl 0x89dcc
movq $0x0, 0x50(%rsp)
subq %rdx, %r13
movq %r13, 0x58(%rsp)
subq %r13, %r15
cmpq %r8, %r15
cmovgeq %r8, %r15
movq %r8, %rbp
subq %r15, %rbp
movq %rbp, 0x70(%rsp)
xorl %r12d, %r12d
testq %r13, %r13
js 0x898ac
movq $0x0, (%rsp)
jmp 0x898c7
addq %r13, %r15
negq %r13
movq %r13, 0x50(%rsp)
movq $0x0, 0x58(%rsp)
movq %r13, (%rsp)
xorl %r13d, %r13d
leaq (%r15,%rdx), %rax
cmpq %r14, %rax
jl 0x89dcc
movl 0xd0(%rsp), %eax
testq %r11, %r11
movq %rdi, 0x68(%rsp)
movq %r9, 0x18(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x60(%rsp)
movq %r10, 0x30(%rsp)
movq %r11, 0x80(%rsp)
movq %r8, 0x38(%rsp)
movq %rbp, 0x40(%rsp)
movq %rbx, 0x78(%rsp)
je 0x89958
movq (%rsp), %rbx
leaq (%r9,%rbx), %rbp
movzbl %al, %ecx
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r11, %r8
movq 0x20(%rsp), %r9
callq 0x32ef8
movq 0x18(%rsp), %rdi
movl $0x4e, %esi
movq %rbx, %rdx
callq 0x20e0
addq %r15, %rbp
movslq 0x40(%rsp), %rdx
movq %rbp, %rdi
movl $0x4e, %esi
jmp 0x89a3e
testq %rbx, %rbx
je 0x8998c
movq (%rbx), %rax
movq 0x10(%rax), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
movq 0x20(%rax,%rcx,8), %rdi
movl 0xd0(%rsp), %edx
testb %dl, %dl
je 0x899e8
leaq (%rax,%rcx,8), %rax
movl (%rax), %eax
shrl %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jmp 0x899ea
movq %r9, %rdi
movl $0x4e, %esi
movq (%rsp), %rbx
movq %rbx, %rdx
callq 0x20e0
movq 0x18(%rsp), %rax
leaq (%rax,%rbx), %rbp
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
subq $0x8, %rsp
movl 0xd8(%rsp), %eax
movzbl %al, %ecx
xorl %edi, %edi
movq %rbp, %rsi
movq %r13, %r8
movq %r15, %r9
pushq $0x0
callq 0x36049
addq $0x10, %rsp
jmp 0x89a2e
xorl %eax, %eax
addq %rax, %rdi
movq %rbp, %rax
movq (%rsp), %rbx
orq %rbx, %rax
je 0x89de1
movq %rdi, 0x10(%rsp)
movq %r9, %rdi
movl $0x4e, %esi
movq %rbx, %rdx
callq 0x20e0
movq 0x18(%rsp), %rax
leaq (%rax,%rbx), %rbp
movq 0x10(%rsp), %rsi
addq %r13, %rsi
movq %rbp, %rdi
movq %r15, %rdx
callq 0x2160
addq %r15, %rbp
movq %rbp, %rdi
movl $0x4e, %esi
movq 0x40(%rsp), %rdx
callq 0x20e0
movq 0xe0(%rsp), %rsi
movq 0x30(%rsp), %r10
movq 0x18(%rsp), %rdi
movq 0xc8(%rsp), %rcx
addq %rsi, %r10
cmpl $0x0, 0x100(%rsp)
movq %r10, 0x30(%rsp)
movq %rdi, 0x10(%rsp)
je 0x89c8e
leaq 0x7d70(%rcx), %rax
leaq 0xff0(%rcx), %r15
leaq 0xa14(%rcx), %r11
movzwl 0x48(%rsp), %r8d
leaq 0x2c(%rsp), %rbp
movq 0x38(%rsp), %rbx
movl %ebx, %esi
movq %r10, %rdx
movl %r14d, %ecx
movq %rbp, %r9
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
pushq %r10
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
pushq %r10
pushq %r11
pushq %r15
pushq %rax
leaq 0x30(%rsp), %rax
pushq %rax
callq 0x85726
addq $0x30, %rsp
movl %eax, 0xc(%rsp)
movq %rbp, %r11
movl (%rbp), %r10d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl %ecx, %r10d
movq 0x68(%rsp), %rbp
movq 0xe8(%rsp), %rdi
movq 0xe0(%rsp), %r8
movq 0x80(%rsp), %r15
movq 0x78(%rsp), %rcx
je 0x89dcc
movq %rcx, %r12
leal 0x1(%rax), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbx
sete %dl
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
sete %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x89cce
movq 0xc0(%rsp), %rsi
movslq %ecx, %r9
cltq
subq $0x8, %rsp
leaq 0x78(%rsp), %rbp
movq 0x38(%rsp), %rdi
movq %r14, %rdx
movq 0x50(%rsp), %rcx
movq %r13, %r8
pushq %r11
pushq %rbp
leaq 0x68(%rsp), %r11
pushq %r11
movq 0x88(%rsp), %rbp
leaq 0x2c(%rsp), %r11
pushq %r11
leaq 0x30(%rsp), %r11
pushq %r11
leaq 0x88(%rsp), %r11
pushq %r11
pushq 0x98(%rsp)
pushq %r12
pushq %r15
pushq 0x118(%rsp)
movl 0x128(%rsp), %r11d
pushq %r11
pushq %rbx
pushq 0x88(%rsp)
pushq %r10
pushq 0xb8(%rsp)
pushq 0x80(%rsp)
pushq %rax
callq 0x9c14d
movq 0xf0(%rsp), %r9
movq 0xa8(%rsp), %r10
movq 0x170(%rsp), %r8
movq 0x178(%rsp), %rdi
addq $0x90, %rsp
testl %eax, %eax
je 0x89cce
testq %r12, %r12
sete %al
movq 0xc0(%rsp), %rsi
testq %rsi, %rsi
setne %cl
movq %rsi, 0x10(%rsp)
testb %cl, %al
jne 0x89cce
movq %r15, %r11
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %r13
movq 0x70(%rsp), %r15
subq %r13, %rbx
subq %r15, %rbx
testq %r11, %r11
je 0x89de9
movslq %r13d, %r12
movq %r15, (%rsp)
leaq (%r10,%r12), %r15
movl 0xd0(%rsp), %eax
movzbl %al, %ecx
movq %r15, %rdi
movq %rbx, %rdx
movq %r11, %r8
movq 0x20(%rsp), %r9
movq %r10, %r13
callq 0x32ef8
movq %r13, %rdi
movl $0x4e, %esi
movq %r12, %rdx
callq 0x20e0
addq %rbx, %r15
movslq (%rsp), %rdx
movq %r15, %rdi
movl $0x4e, %esi
callq 0x20e0
movq 0xe0(%rsp), %r8
movq 0xe8(%rsp), %rdi
movq %r13, 0x10(%rsp)
jmp 0x89cce
movzwl 0x48(%rsp), %r8d
leaq 0x2c(%rsp), %rbx
movq 0x38(%rsp), %rsi
movq %r10, %rdx
movl %r14d, %ecx
movq %rbx, %r9
callq 0x84e99
movl %eax, 0xc(%rsp)
cmpl $-0x1, (%rbx)
movq 0x68(%rsp), %rbp
movq 0xe8(%rsp), %rdi
movq 0xe0(%rsp), %r8
je 0x89dcc
leaq 0x48(%rbp), %rbx
movq 0x48(%rbp), %rcx
cmpq 0x50(%rbp), %rcx
jne 0x89d17
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x50(%rbp)
movq 0x58(%rbp), %rdi
shlq $0x5, %rsi
callq 0x2370
movq 0xe0(%rsp), %r8
movq 0xe8(%rsp), %rdi
movq %rax, 0x58(%rbp)
movq 0x48(%rbp), %rcx
jmp 0x89d1b
movq 0x58(%rbp), %rax
leaq 0x1(%rcx), %rdx
shlq $0x5, %rcx
leaq (%rax,%rcx), %r15
movq %rdx, (%rbx)
movl %r8d, (%rax,%rcx)
movl %edi, 0x4(%rax,%rcx)
cmpl $0x0, 0x100(%rsp)
je 0x89d7c
movq 0xc8(%rsp), %rdi
movl 0x7d70(%rdi), %esi
addq $0xa14, %rdi            # imm = 0xA14
leaq 0x2c(%rsp), %rax
leaq 0x8(%rsp), %r8
leaq 0xc(%rsp), %r9
movq %r15, %rdx
movq %rbx, %rcx
pushq 0x10(%rsp)
pushq %r14
pushq 0x40(%rsp)
pushq %rax
callq 0x85cd2
addq $0x20, %rsp
jmp 0x89d84
movq $0x0, 0x18(%r15)
movl 0x58(%rsp), %eax
movl 0x8(%rsp), %ecx
addl %eax, %ecx
movl %ecx, 0x8(%r15)
addl 0xc(%rsp), %eax
movl %eax, 0xc(%r15)
movzwl 0x2c(%rsp), %eax
movw %ax, 0x14(%r15)
movzwl 0x50(%rsp), %eax
movw %ax, 0x10(%r15)
movzwl 0x70(%rsp), %eax
movw %ax, 0x12(%r15)
movq 0x48(%rsp), %rax
movw %ax, 0x16(%r15)
addl %r14d, 0x28(%rbp)
movl $0x1, %r12d
movl %r12d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %r13, %rdi
jmp 0x89a55
movq %rbx, 0x38(%rsp)
testq %r12, %r12
je 0x89e23
movq (%r12), %rax
movq 0x10(%rax), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
movq 0x20(%rax,%rcx,8), %rbx
movl 0xd0(%rsp), %edx
testb %dl, %dl
je 0x89e81
leaq (%rax,%rcx,8), %rax
movl (%rax), %eax
shrl %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
jmp 0x89e83
movq %r10, %rdi
movq %rsi, (%rsp)
movl $0x4e, %esi
movq %r13, %rdx
movq %r10, %r12
movq %r9, %rbx
callq 0x20e0
addq %r12, %r13
movq (%rbx), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rcx,4), %rdx
shlq $0x3, %rdx
addq 0x10(%rax), %rdx
subq $0x8, %rsp
movl 0xd8(%rsp), %eax
movzbl %al, %ecx
xorl %edi, %edi
movq %r13, %rsi
movq 0x8(%rsp), %r8
movq 0x40(%rsp), %rbx
movq %rbx, %r9
pushq $0x0
callq 0x36049
addq $0x10, %rsp
jmp 0x89ebf
xorl %eax, %eax
addq %rax, %rbx
movq %r15, %rax
orq %r13, %rax
je 0x89eec
movq %r10, %rdi
movq %rsi, (%rsp)
movl $0x4e, %esi
movq %r13, %rdx
movq %r10, %r12
callq 0x20e0
addq %r12, %r13
addq (%rsp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
movq 0x38(%rsp), %rbx
movq %rbx, %rdx
callq 0x2160
addq %rbx, %r13
movq %r13, %rdi
movl $0x4e, %esi
movq %r15, %rdx
callq 0x20e0
movq 0xe0(%rsp), %r8
movq 0xe8(%rsp), %rdi
movq %r12, 0x10(%rsp)
jmp 0x89cce
addq %rsi, %rbx
movq %rbx, 0x10(%rsp)
jmp 0x89cce