// File: chhylp123[P]hifiasm/Correct.cpp
// Function: verify_ul_window_s(overlap_region*, ul_idx_t const*, char*, char*, double, long, long, void*)
void verify_ul_window_s(overlap_region *z, const ul_idx_t *uref, char* qstr, char *tstr,
double e_rate, int64_t w_l, int64_t e_max, void *km)
{
    int64_t q_s, q_e, nw, k, q_l;
    int64_t aux_beg, aux_end, t_s, thre, aln_l, t_pri_l, t_end;
    char *q_string, *t_string; unsigned int error;
    z->w_list.n = 0; nw = get_num_wins(z->x_pos_s, z->x_pos_e+1, w_l);
    get_win_se_by_normalize_xs(z, (z->x_pos_s/w_l)*w_l, w_l, &q_s, &q_e);
    // q_s = z->x_pos_s; get_win_id_by_s(z, q_s, w_l, &q_e); 
    for (k = 0; k < nw; k++) {
        aux_beg = aux_end = 0; q_l = 1 + q_e - q_s;
        thre = q_l*e_rate; thre = Adjust_Threshold(thre, q_l);
        if(thre > THRESHOLD_MAX_SIZE) thre = THRESHOLD_MAX_SIZE;
        ///offset of y
        t_s = (q_s - z->x_pos_s) + z->y_pos_s;
        t_s += y_start_offset(q_s, &(z->f_cigar));

        aln_l = q_l + (thre<<1);
        // if(z->y_id == 115) {
        //     fprintf(stderr, "+[M::] q_s::%ld, t_s::%ld, t_pri_l::%ld, aux_beg::%ld, aux_end::%ld, aln_l::%ld, t_end::%ld, error::%u\n", 
        //     q_s, t_s, t_pri_l, aux_beg, aux_end, aln_l, t_end, error);
        // }
        if(init_waln(thre, t_s, uref->ug->u.a[z->y_id].len, aln_l, &aux_beg, &aux_end, &t_s, &t_pri_l)) {
            gen_str_seq(tstr, t_s, t_pri_l, z->y_pos_strand, uref, z->y_id, aux_beg, aux_end);
            q_string = qstr+q_s; t_string = tstr;
            t_end = Reserve_Banded_BPM(t_string, aln_l, q_string, q_l, thre, &error);
            // if(z->y_id == 115) {
            //     fprintf(stderr, "-[M::] q_s::%ld, t_s::%ld, t_pri_l::%ld, aux_beg::%ld, aux_end::%ld, aln_l::%ld, t_end::%ld, error::%u, thre::%ld\n", 
            //     q_s, t_s, t_pri_l, aux_beg, aux_end, aln_l, t_end, error, thre);
            // }
            if (error!=((unsigned int)-1)) {
                z->align_length += q_l;
                ///t_s do not have aux_beg, while t_s + t_end (aka, te) has 
                append_window_list(z, q_s, q_e, t_s, t_s + t_end, error, aux_beg, aux_end, thre, w_l, km);
            }
        }
        q_s = q_e + 1; q_e = q_s + w_l - 1; 
        if(q_e >= (int64_t)z->x_pos_e) q_e = z->x_pos_e;
    }

    // if(q_e != (int64_t)z->x_pos_e) {
    //     fprintf(stderr, "[M::%s] q_e::%ld, z->x_pos_s::%u, z->x_pos_e::%u, w_l::%ld, nw::%ld\n", __func__, 
    //     q_e, z->x_pos_s, z->x_pos_e, w_l, nw);
    // }
    assert(q_e == (int64_t)z->x_pos_e);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xe0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %edi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
movq -0x40(%rbp), %rdx
callq 0x340c0
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
cqto
idivq -0x40(%rbp)
movq %rax, %rsi
imulq -0x40(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x50(%rbp), %rcx
leaq -0x58(%rbp), %r8
callq 0x9e0f0
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0x3451c
movq $0x0, -0x80(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
subq -0x50(%rbp), %rax
movq %rax, -0x70(%rbp)
cvtsi2sdq -0x70(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x342c5
cmpq $0x4, -0x70(%rbp)
jl 0x342c5
movl $0x1, %eax
movq %rax, -0xc8(%rbp)
jmp 0x342d3
movq -0x90(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x1f, -0x90(%rbp)
jle 0x342f6
movq $0x1f, -0x90(%rbp)
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %ecx
subq %rcx, %rax
movq -0x18(%rbp), %rcx
movl 0x14(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x38, %rsi
callq 0x331a0
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x70(%rbp), %rax
movq -0x90(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
movq -0x98(%rbp), %rcx
leaq -0x78(%rbp), %r8
leaq -0x80(%rbp), %r9
leaq -0x88(%rbp), %r10
leaq -0xa0(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x33f90
cmpl $0x0, %eax
je 0x344d2
movq -0x30(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movb %al, %cl
movq -0x20(%rbp), %r8
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %r9d
movq -0x78(%rbp), %r10
movq -0x80(%rbp), %rax
movzbl %cl, %ecx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x34130
movq -0x28(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
movq -0x98(%rbp), %rax
movl %eax, %esi
movq -0xb0(%rbp), %rdx
movq -0x70(%rbp), %rax
movl %eax, %ecx
movq -0x90(%rbp), %rax
leaq -0xbc(%rbp), %r9
movzwl %ax, %r8d
callq 0x9c2b0
cltq
movq %rax, -0xa8(%rbp)
cmpl $-0x1, -0xbc(%rbp)
je 0x344d0
movq -0x70(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x28(%rax), %ecx
addq %rdx, %rcx
movl %ecx, 0x28(%rax)
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x88(%rbp), %rax
movl %eax, %ecx
movq -0x88(%rbp), %rax
addq -0xa8(%rbp), %rax
movl %eax, %r8d
movl -0xbc(%rbp), %r9d
movq -0x78(%rbp), %rax
movl %eax, %r14d
movq -0x80(%rbp), %rax
movl %eax, %ebx
movq -0x90(%rbp), %rax
movl %eax, %r11d
movq -0x40(%rbp), %rax
movl %eax, %r10d
movq 0x10(%rbp), %rax
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x22d00
jmp 0x344d2
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jl 0x34509
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x58(%rbp)
jmp 0x3450b
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x34261
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jne 0x3452e
jmp 0x3454d
leaq 0x34ddcb(%rip), %rdi    # 0x382300
leaq 0x34dddf(%rip), %rsi    # 0x38231b
movl $0x349, %edx            # imm = 0x349
leaq 0x34dddf(%rip), %rcx    # 0x382327
callq 0x2130
addq $0xe0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)