// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: push_wlst(ul_idx_t const*, hpc_t*, All_reads*, overlap_region*, char*, char*, char*, Correct_dumy*, long, long, long, long, long, long, long, long, long, double, long, unsigned int, double, void*)
uint32_t push_wlst(const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, overlap_region* ol, 
                        char* qstr, char *tstr, char *tstr_1, Correct_dumy* dumy,
                        int64_t qs, int64_t qe, int64_t ts, int64_t te, int64_t tl, 
                        int64_t error, int64_t aux_beg, int64_t aux_end, int64_t thres, double e_rate, 
                        int64_t block_s, uint32_t sec_check, double ovlp_cut, void *km)
{

    window_list p, t, *a; int64_t w_e, w_s, ce = qs - 1, cs = ol->x_pos_s, toff, ovl, ualn, aln; 
    uint64_t a_n, k;
    
    p.x_start = qs; p.x_end = qe; p.y_start = ts; p.y_end = te; p.error = error;
    p.extra_begin = aux_beg; p.extra_end = aux_end;
    p.error_threshold = thres; p.cidx = p.clen = 0;
    if(ol->w_list.n > 0) { //utilize the the end pos of pre-window in forward
        w_e = ol->w_list.a[ol->w_list.n-1].x_end; 
        toff = ol->w_list.a[ol->w_list.n-1].y_end + 1 - ol->w_list.a[ol->w_list.n-1].extra_begin;
        while ((w_e < ce) && (toff < tl)) {
            w_s = w_e + 1;
            get_win_id_by_s(ol, w_s, block_s, &w_e);
            // x_start = w_s; x_end = w_e;
            if(aln_wlst_adv(ol, rref, hpc_g, uref, qstr, tstr, tstr_1, dumy,
            ol->y_pos_strand, ol->y_id, w_s, w_e, toff, block_s, e_rate, 0)) {
                toff = ol->w_list.a[ol->w_list.n-1].y_end + 1 - ol->w_list.a[ol->w_list.n-1].extra_begin;
            } else {
                break;
            }
        }
        cs = ol->w_list.a[ol->w_list.n-1].x_end + 1;
    }
    ///utilize the the start pos of next window in backward
    a_n = ol->w_list.n; w_s = qs;
    if(w_s > cs) {
        gen_backtrace_adv(&p, ol, rref, hpc_g, uref, qstr, tstr, tstr_1, dumy, ol->y_pos_strand, ol->y_id);
        p.y_end += p.extra_begin;
        toff = p.y_start - 1;
        while ((w_s > cs) && (toff > 0)) {
            w_e = w_s - 1;
            get_win_id_by_e(ol, w_e, block_s, &w_s);
            // x_start = w_s; x_end = w_e; x_len = x_end + 1 - x_start;
            if(aln_wlst_adv(ol, rref, hpc_g, uref, qstr, tstr, tstr_1, dumy,
                ol->y_pos_strand, ol->y_id, w_s, w_e, toff+1-(w_e+1-w_s), block_s, e_rate, 1)) {
                ///y_start has no shift, but y_end has shift  
                ol->w_list.a[ol->w_list.n-1].y_start -= ol->w_list.a[ol->w_list.n-1].extra_begin; 
                toff = ol->w_list.a[ol->w_list.n-1].y_start - 1;
            } else {
                break;
            }
        }
    }

    ol->align_length += qe + 1 - qs;
    ovl = ol->x_pos_e+1-ol->x_pos_s; ualn = (qe + 1 - ol->x_pos_s) - ol->align_length; aln = ovl-ualn;
    if((!simi_pass(ovl, aln, 0, ovlp_cut, &e_rate)) && (!simi_pass(ovl, aln, sec_check, ovlp_cut, NULL))) {
        kv_push(window_list, ol->w_list, p); 
        return 0;
    }

    if(ol->w_list.n > a_n) {
        a = ol->w_list.a + a_n; a_n = ol->w_list.n - a_n; toff = a_n; a_n >>=1;
        for (k = 0; k < a_n; k++) {
            t = a[k]; a[k] = a[toff-1-k]; a[toff-1-k] = t;
        }
    }
    kv_push(window_list, ol->w_list, p); 
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movsd %xmm1, 0x58(%rsp)
movsd %xmm0, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, %rbx
movq %rdx, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x118(%rsp), %r12
movq 0xd8(%rsp), %rcx
movq 0xd0(%rsp), %rdi
movl 0xe0(%rsp), %eax
movl 0x4(%rbx), %r13d
movl %edi, 0x38(%rsp)
movl %ecx, 0x3c(%rsp)
movl %eax, 0x40(%rsp)
movl 0xe8(%rsp), %eax
movl %eax, 0x44(%rsp)
movzwl 0xf8(%rsp), %eax
movw %ax, 0x4c(%rsp)
movzwl 0x100(%rsp), %eax
movw %ax, 0x48(%rsp)
movzwl 0x108(%rsp), %eax
movw %ax, 0x4a(%rsp)
movzwl 0x110(%rsp), %eax
movw %ax, 0x4e(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x48(%rbx), %r15
testq %r15, %r15
movq %r9, 0x30(%rsp)
je 0x598f0
leaq -0x1(%rdi), %r14
movq 0x58(%rbx), %rcx
movq %r15, %rdx
shlq $0x5, %rdx
movl -0x1c(%rcx,%rdx), %eax
movslq %eax, %r13
cmpq %r13, %r14
jle 0x598e9
movl -0x14(%rcx,%rdx), %esi
movswl -0x10(%rcx,%rdx), %ecx
subl %ecx, %esi
incl %esi
movslq %esi, %r10
cmpq 0xf0(%rsp), %r10
jge 0x598e9
movq %r9, %rbp
movq %r13, %r11
incq %r11
movl 0x8(%rbx), %r13d
movl 0x4(%rbx), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r12
subq %rdx, %rcx
movq %r11, %rax
subq %rcx, %rax
cqto
idivq %r12
incq %rax
imulq %r12, %rax
addq %rcx, %rax
decq %rax
cmpq %r13, %rax
cmovlq %rax, %r13
movl 0x1c(%rbx), %eax
movl 0x10(%rbx), %r15d
subq $0x8, %rsp
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %r8
movq %rbp, %r9
movsd 0x30(%rsp), %xmm0
pushq $0x0
pushq %r12
pushq %r10
pushq %r13
pushq %r11
pushq %r15
pushq %rax
pushq 0x108(%rsp)
pushq 0x108(%rsp)
callq 0x896ad
addq $0x50, %rsp
movq 0x48(%rbx), %r15
movq 0x58(%rbx), %rcx
testl %eax, %eax
je 0x598d6
cmpq %r14, %r13
jge 0x598d6
movq %r15, %rax
shlq $0x5, %rax
movl -0x14(%rcx,%rax), %edx
movswl -0x10(%rcx,%rax), %eax
subl %eax, %edx
incl %edx
movslq %edx, %r10
cmpq 0xf0(%rsp), %r10
jl 0x5981a
movq %r15, %rax
shlq $0x5, %rax
movl -0x1c(%rcx,%rax), %eax
movq 0xd0(%rsp), %rdi
incl %eax
movslq %eax, %r13
jmp 0x598f3
xorl %r15d, %r15d
cmpq %rdi, %r13
jge 0x59a1a
movl 0x10(%rbx), %eax
movl 0x1c(%rbx), %r10d
subq $0x8, %rsp
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x28(%rsp), %r9
pushq %rax
pushq %r10
pushq 0xe0(%rsp)
pushq 0xe0(%rsp)
pushq 0x58(%rsp)
callq 0x89ef9
addq $0x30, %rsp
movswl 0x10(%r14), %eax
addl %eax, 0xc(%r14)
movl 0x8(%r14), %ecx
cmpl $0x2, %ecx
jl 0x59a1a
movq 0xd0(%rsp), %r14
movq %r14, %rsi
leaq -0x1(%r14), %r11
movl 0x10(%rbx), %r10d
movl 0x4(%rbx), %r14d
movq %r14, %rax
xorl %edx, %edx
idivq %r12
subq %r14, %rdx
leaq (%rsi,%rdx), %rax
decq %rax
cqto
idivq %r12
negq %rdx
leaq (%rsi,%rdx), %rax
decq %rax
cmpq %r14, %rax
cmovgq %rax, %r14
movl 0x1c(%rbx), %eax
movl %ecx, %ebp
subq %rsi, %rbp
addq %r14, %rbp
subq $0x8, %rsp
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x38(%rsp), %r9
movsd 0x30(%rsp), %xmm0
pushq $0x1
pushq %r12
pushq %rbp
pushq %r11
pushq %r14
pushq %r10
pushq %rax
pushq 0x108(%rsp)
pushq 0x108(%rsp)
callq 0x896ad
addq $0x50, %rsp
testl %eax, %eax
je 0x59a1a
movq 0x48(%rbx), %rax
movq 0x58(%rbx), %rdx
shlq $0x5, %rax
movswl -0x10(%rdx,%rax), %esi
movl -0x18(%rdx,%rax), %ecx
subl %esi, %ecx
movl %ecx, -0x18(%rdx,%rax)
cmpq %r13, %r14
jle 0x59a1a
cmpl $0x1, %ecx
jg 0x59962
movq 0xd8(%rsp), %rdi
movl %edi, %eax
movq 0xd0(%rsp), %rcx
subl %ecx, %eax
movl 0x28(%rbx), %ecx
addl %eax, %ecx
incl %ecx
movl 0x4(%rbx), %edx
movl 0x8(%rbx), %eax
incl %eax
movl %eax, %esi
subl %edx, %esi
movl %ecx, 0x28(%rbx)
subl %edx, %eax
je 0x59b5b
notq %rdi
addq %rdx, %rdi
addq %rcx, %rdi
addq %rsi, %rdi
je 0x59b5b
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd 0x1d78a0(%rip), %xmm2   # 0x231310
subsd 0x28(%rsp), %xmm2
mulsd %xmm0, %xmm2
cvtsi2sd %rdi, %xmm1
ucomisd %xmm2, %xmm1
jae 0x59ab6
cmpl $0x0, 0x120(%rsp)
je 0x59aa6
cmpq $0x1c2, %rdi            # imm = 0x1C2
jl 0x59b5b
mulsd 0x1d7b4c(%rip), %xmm0   # 0x2315f0
jmp 0x59aac
mulsd 0x58(%rsp), %xmm0
ucomisd %xmm0, %xmm1
jb 0x59b5b
movq 0x48(%rbx), %rcx
movq %rcx, %rax
subq %r15, %rax
jbe 0x59b2a
cmpq $0x2, %rax
jb 0x59b2a
movq 0x58(%rbx), %rdx
shlq $0x5, %r15
addq %rdx, %r15
shrq %rax
shlq $0x5, %rcx
addq %rdx, %rcx
addq $-0x20, %rcx
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movaps %xmm1, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%r15)
movups %xmm0, (%r15)
movapd 0x60(%rsp), %xmm0
movapd 0x70(%rsp), %xmm1
movupd %xmm1, 0x10(%rcx)
movupd %xmm0, (%rcx)
addq $0x20, %r15
addq $-0x20, %rcx
decq %rax
jne 0x59ae1
movq 0x48(%rbx), %rcx
cmpq 0x50(%rbx), %rcx
jne 0x59ba7
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x50(%rbx)
movq 0x58(%rbx), %rdi
shlq $0x5, %rsi
callq 0x2370
movq %rax, 0x58(%rbx)
movq 0x48(%rbx), %rcx
jmp 0x59bab
movq 0x48(%rbx), %rcx
cmpq 0x50(%rbx), %rcx
jne 0x59b90
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x50(%rbx)
movq 0x58(%rbx), %rdi
shlq $0x5, %rsi
callq 0x2370
movq %rax, 0x58(%rbx)
movq 0x48(%rbx), %rcx
jmp 0x59b94
movq 0x58(%rbx), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x48(%rbx)
shlq $0x5, %rcx
addq %rax, %rcx
xorl %eax, %eax
jmp 0x59bbf
movq 0x58(%rbx), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x48(%rbx)
shlq $0x5, %rcx
addq %rax, %rcx
movl $0x1, %eax
movups 0x38(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq