// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movsd %xmm0, 0x70(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, %r13
movq $0x0, 0x48(%rdi)
movl 0x8(%rdi), %r14d
movl 0x4(%rdi), %edi
leal 0x1(%r14), %esi
movq %rdi, %rax
xorl %edx, %edx
idivq %r8
movq %rdx, %rcx
movq %rdx, %rax
subq %rdi, %rax
addq %rsi, %rax
cqto
idivq %r8
xorl %esi, %esi
testq %rdx, %rdx
setg %sil
movq %rdi, %rdx
subq %rcx, %rdx
movq %r8, 0x18(%rsp)
leaq (%r8,%rdx), %rcx
decq %rcx
cmpq %r14, %rcx
cmovlq %rcx, %r14
addq %rax, %rsi
jle 0x49bf7
cmpq %rdi, %rdx
cmovgq %rdx, %rdi
leaq 0x38(%r13), %rax
movq %rax, 0x68(%rsp)
movq %r13, 0x40(%rsp)
movq %rsi, 0x78(%rsp)
leaq 0x1(%r14), %r15
movq %r15, 0x80(%rsp)
subq %rdi, %r15
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
mulsd 0x70(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
cmpq $0x1f, %rax
jl 0x499e5
movl $0x1f, %ecx
cmpq $0x4, %r15
movq %rcx, %rbp
movl $0x1, %edx
cmovgeq %rdx, %rbp
testq %rax, %rax
cmovneq %rcx, %rbp
movl 0x4(%r13), %eax
movl 0x14(%r13), %ebx
movq %rdi, %r12
subq %rax, %r12
movq %rdi, 0x38(%rsp)
movq 0x68(%rsp), %rsi
callq 0x48df6
addq %rbx, %rax
addq %r12, %rax
leaq (%r15,%rbp,2), %r9
movq 0x30(%rsp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movl 0x10(%r13), %edx
leaq (%rdx,%rdx,4), %rbx
movl (%rcx,%rbx,8), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movb $0x1, %cl
movq $-0x1, %rdx
cmpq %rdi, %rax
jae 0x49aa0
leaq (,%rbp,2), %rsi
subq %rax, %rsi
addq %rdi, %rsi
addq $0x1f, %rsi
movq $-0x1, %r8
movq $-0x1, 0x8(%rsp)
movq $-0x1, %r10
cmpq %r9, %rsi
jl 0x49acd
subq %rbp, %rax
subq %rax, %rdi
cmpq %r9, %rdi
movq %rdi, %r10
cmovgeq %r9, %r10
movq %r9, %r8
subq %r10, %r8
testq %rax, %rax
js 0x49ab9
xorl %edx, %edx
movq %rax, 0x8(%rsp)
jmp 0x49acb
movq $-0x1, %r8
movq $-0x1, 0x8(%rsp)
movq $-0x1, %r10
jmp 0x49acd
addq %rax, %r10
negq %rax
movq $0x0, 0x8(%rsp)
movq %rax, %rdx
xorl %ecx, %ecx
testb %cl, %cl
jne 0x49bd1
movzbl 0x1c(%r13), %eax
movl %eax, 0x10(%rsp)
movq 0x50(%rsp), %r12
movq %r12, %rdi
movl $0x4e, %esi
movq %rdx, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movq %r9, 0x60(%rsp)
movq %r10, 0x58(%rsp)
callq 0x20e0
movq 0x28(%rsp), %rax
leaq (%r12,%rax), %r13
movq 0x30(%rsp), %rax
movq (%rax), %rax
shlq $0x3, %rbx
addq 0x10(%rax), %rbx
subq $0x8, %rsp
xorl %edi, %edi
movq %r13, %rsi
movq %rbx, %rdx
movl 0x18(%rsp), %ecx
movq 0x10(%rsp), %r8
movq 0x60(%rsp), %rbx
movq %rbx, %r9
pushq $0x0
callq 0x36b0d
addq $0x10, %rsp
addq %rbx, %r13
movq %r13, %rdi
movq 0x40(%rsp), %r13
movl $0x4e, %esi
movq 0x20(%rsp), %rdx
callq 0x20e0
movq 0x48(%rsp), %rax
movq 0x38(%rsp), %rcx
leaq (%rax,%rcx), %rdx
movzwl %bp, %r8d
movq %r12, %rdi
movq 0x60(%rsp), %rsi
movl %r15d, %ecx
leaq 0x14(%rsp), %r9
callq 0x8578f
movq 0x20(%rsp), %r11
movq 0x28(%rsp), %r10
movl 0x14(%rsp), %r9d
cmpl $-0x1, %r9d
je 0x49bd1
addl %r15d, 0x28(%r13)
movq 0x8(%rsp), %rcx
addl %ecx, %eax
subq $0x8, %rsp
movq %r13, %rdi
movq 0x40(%rsp), %rsi
movq %r14, %rdx
movl %eax, %r8d
pushq 0xc8(%rsp)
pushq 0x28(%rsp)
pushq %rbp
pushq %r11
pushq %r10
callq 0x3fb41
addq $0x30, %rsp
addq 0x18(%rsp), %r14
movl 0x8(%r13), %eax
cmpq %rax, %r14
cmovgeq %rax, %r14
movq 0x78(%rsp), %rsi
decq %rsi
movq 0x80(%rsp), %rdi
jne 0x499b0
movl 0x8(%r13), %eax
cmpq %rax, %r14
jne 0x49c12
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1dba0f(%rip), %rdi    # 0x225628
leaq 0x1dba23(%rip), %rsi    # 0x225643
leaq 0x1dba28(%rip), %rcx    # 0x22564f
movl $0x349, %edx            # imm = 0x349
callq 0x2110