// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: align_ul_ed_post(overlap_region*, ul_idx_t const*, hpc_t*, char*, char*, char*, Correct_dumy*, double, long, double, void*)
uint32_t align_ul_ed_post(overlap_region *z, const ul_idx_t *uref, hpc_t *hpc_g, char* qstr, char *tstr, char *tstr_1, 
Correct_dumy* dumy, double e_rate, int64_t w_l, double ovlp_cut, void *km)
{
    int64_t q_s, q_e, nw, k, q_l, t_tot_l, sec_check = (uref&&(!hpc_g))?1:0;
    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; z->is_match = 0; z->align_length = 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);
    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); t_tot_l = hpc_g?hpc_len(*hpc_g, z->y_id):uref->ug->u.a[z->y_id].len;
        if(init_waln(thre, t_s, t_tot_l, aln_l, &aux_beg, &aux_end, &t_s, &t_pri_l)) {
            q_string = qstr+q_s; 
            t_string = return_str_seq(tstr, t_s, t_pri_l, z->y_pos_strand, hpc_g, uref, z->y_id, aux_beg, aux_end);

            t_end = Reserve_Banded_BPM(t_string, aln_l, q_string, q_l, thre, &error);
            // int32_t debug_t_end, debug_error;
            // debug_t_end = ed_band_cal_semi(t_string, aln_l, q_string, q_l, thre, &debug_error);
            // if((t_end != debug_t_end) || (t_end >= 0 && debug_t_end >= 0 && debug_error != (int32_t)error)) {
            //     fprintf(stderr, "[M::%s] debug_error->%d, error->%d\n", __func__, debug_error, error);
            // }
            

            if (error!=((unsigned int)-1)) {
                ///t_s do not have aux_beg, while t_s + t_end (aka, te) has 
                if(!push_wlst(uref, hpc_g, NULL, z, qstr, tstr, tstr_1, dumy, q_s, q_e, t_s, t_s + t_end, 
                                        t_tot_l, error, aux_beg, aux_end, thre, e_rate, w_l, sec_check, ovlp_cut, km)) {
                    return 0;
                }
                // 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((!simi_pass(z->x_pos_e+1-z->x_pos_s, z->align_length, 0, ovlp_cut, &e_rate)) &&
        (!simi_pass(z->x_pos_e+1-z->x_pos_s, z->align_length, sec_check, ovlp_cut, NULL))) return 0;
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movsd %xmm1, 0x58(%rsp)
movsd %xmm0, 0x38(%rsp)
movq %r9, 0x78(%rsp)
movq %r8, 0x8(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdx, %r11
movq %rdi, %rbx
movq 0xe8(%rsp), %r10
movq %rsi, 0x30(%rsp)
testq %rsi, %rsi
setne %dil
testq %rdx, %rdx
sete %r8b
movq $0x0, 0x48(%rbx)
movb $0x0, 0x2c(%rbx)
movl $0x0, 0x28(%rbx)
movl 0x8(%rbx), %r12d
movl 0x4(%rbx), %ecx
leal 0x1(%r12), %r9d
movq %rcx, %rax
xorl %edx, %edx
idivq %r10
movq %rdx, %rsi
movq %rdx, %rax
subq %rcx, %rax
addq %r9, %rax
cqto
idivq %r10
xorl %r9d, %r9d
testq %rdx, %rdx
setg %r9b
addq %rax, %r9
movq %r9, 0x90(%rsp)
jle 0x5a04b
andb %r8b, %dil
movq %rcx, %rbp
subq %rsi, %rbp
movq 0xe8(%rsp), %rax
addq %rbp, %rax
decq %rax
cmpq %r12, %rax
cmovlq %rax, %r12
cmpq %rcx, %rbp
cmovleq %rcx, %rbp
movzbl %dil, %eax
movq %rax, 0x50(%rsp)
leaq 0x38(%rbx), %rax
movq %rax, 0x40(%rsp)
xorl %eax, %eax
movq %r11, 0x68(%rsp)
movq %rax, 0x98(%rsp)
leaq 0x1(%r12), %rax
movq %rax, 0xa0(%rsp)
movq %rax, %rdx
subq %rbp, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
mulsd 0x38(%rsp), %xmm0
cvttsd2si %xmm0, %rax
cmpq $0x1f, %rax
movl $0x1f, %ecx
cmovlq %rax, %rcx
movq %rdx, 0x70(%rsp)
cmpq $0x4, %rdx
movq %rcx, %rsi
movl $0x1, %edx
cmovgeq %rdx, %rsi
testq %rax, %rax
cmovneq %rcx, %rsi
movq %rsi, 0x10(%rsp)
movl 0x4(%rbx), %r13d
movl 0x14(%rbx), %r14d
movl 0x40(%rbx), %esi
decl %esi
movq 0x40(%rsp), %rdi
callq 0x3d110
cltq
movl 0x40(%rbx), %r15d
cmpq %rax, %rbp
je 0x59d80
testl %r15d, %r15d
je 0x5a0b9
xorl %r15d, %r15d
movq 0x40(%rsp), %rdi
movl %r15d, %esi
callq 0x3d110
cltq
cmpq %rax, %rbp
jl 0x59d6b
incq %r15
movl 0x40(%rbx), %eax
cmpq %rax, %r15
jb 0x59d4a
jmp 0x59d77
testq %r15, %r15
je 0x5a0b9
movl 0x40(%rbx), %eax
cmpq %rax, %r15
je 0x5a0b9
decl %r15d
movq 0x40(%rsp), %rdi
movl %r15d, %esi
callq 0x3d11b
movl 0x10(%rbx), %ecx
leaq (%rcx,%rcx,4), %r8
movq 0x68(%rsp), %r11
testq %r11, %r11
je 0x59db6
movq (%r11), %rcx
movq 0x10(%rcx), %rcx
movl (%rcx,%r8,8), %ecx
shrl %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
jmp 0x59dcd
movq 0x30(%rsp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movl (%rcx,%r8,8), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
movq %rbp, %rdx
subq %r13, %rdx
addq %rdx, %r14
movslq %eax, %r13
addq %r14, %r13
movl %ecx, %esi
cmpq %rsi, %r13
jae 0x5a002
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx), %rax
movq 0x70(%rsp), %rdx
leaq (%rdx,%rcx,2), %r10
subq %r13, %rax
addq %rsi, %rax
addq $0x1f, %rax
cmpq %r10, %rax
jl 0x5a002
subq 0x10(%rsp), %r13
movq %rsi, 0x88(%rsp)
movq %rsi, %rax
subq %r13, %rax
cmpq %r10, %rax
cmovgeq %r10, %rax
movq %r10, %r9
subq %rax, %r9
movq %r13, %rcx
negq %rcx
movq %r13, %rdx
sarq $0x3f, %rdx
andq %rcx, %rdx
testq %r13, %r13
movl $0x0, %r14d
cmovgq %r13, %r14
movl $0x0, %ecx
cmovnsq %rcx, %r13
addq %rax, %r13
movb 0x1c(%rbx), %cl
testq %r11, %r11
movq %r14, 0x28(%rsp)
movq %r9, 0x20(%rsp)
movq %rdx, 0x80(%rsp)
je 0x59e8d
movq (%r11), %rax
movq 0x10(%rax), %rax
testb %cl, %cl
je 0x59ee9
leaq (%rax,%r8,8), %rcx
movl (%rcx), %r15d
shrl %r15d
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
jmp 0x59eec
movq 0x8(%rsp), %rdi
movq %r8, %r15
movl $0x4e, %esi
movq %rdx, %r14
movq %r10, 0x18(%rsp)
movb %cl, 0x7(%rsp)
callq 0x20e0
movq 0x8(%rsp), %rax
addq %rax, %r14
movq 0x30(%rsp), %rax
movq (%rax), %rax
shlq $0x3, %r15
addq 0x10(%rax), %r15
subq $0x8, %rsp
movzbl 0xf(%rsp), %ecx
xorl %edi, %edi
movq %r14, %rsi
movq %r15, %rdx
movq 0x30(%rsp), %r8
movq %r13, %r9
pushq $0x0
callq 0x36049
addq $0x10, %rsp
jmp 0x59f2b
xorl %r15d, %r15d
movq %r9, %rcx
addq 0x20(%rax,%r8,8), %r15
orq %rdx, %rcx
je 0x59f4c
movq 0x8(%rsp), %rdi
movl $0x4e, %esi
movq %rdx, %r14
movq %r10, 0x18(%rsp)
callq 0x20e0
movq 0x8(%rsp), %rax
addq %rax, %r14
addq 0x28(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2160
addq %r13, %r14
movq %r14, %rdi
movl $0x4e, %esi
movq 0x20(%rsp), %rdx
callq 0x20e0
movq 0x18(%rsp), %r10
movq 0x8(%rsp), %r15
jmp 0x59f4f
addq %r14, %r15
movq 0x60(%rsp), %rax
leaq (%rax,%rbp), %rdx
movzwl 0x10(%rsp), %r8d
movq %r15, %rdi
movl %r10d, %esi
movq 0x70(%rsp), %rcx
leaq 0x4c(%rsp), %r9
callq 0x84e99
movl 0x4c(%rsp), %r10d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %r10
movq 0x68(%rsp), %r11
movq 0x88(%rsp), %r14
je 0x5a002
cltq
movq 0x28(%rsp), %r13
addq %r13, %rax
subq $0x8, %rsp
xorl %r15d, %r15d
movq 0x38(%rsp), %rdi
movq %r11, %rsi
xorl %edx, %edx
movq %rbx, %rcx
movq 0x68(%rsp), %r8
movq 0x10(%rsp), %r9
movsd 0x40(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
pushq 0x58(%rsp)
pushq 0xf8(%rsp)
pushq 0x28(%rsp)
pushq 0x40(%rsp)
pushq 0xa8(%rsp)
pushq %r10
pushq %r14
pushq %rax
pushq %r13
pushq %r12
pushq %rbp
pushq 0x140(%rsp)
pushq 0xe0(%rsp)
callq 0x5971d
addq $0x70, %rsp
testl %eax, %eax
je 0x5a04e
addq 0xe8(%rsp), %r12
movl 0x8(%rbx), %ecx
cmpq %rcx, %r12
cmovgeq %rcx, %r12
movq 0x98(%rsp), %rax
incq %rax
cmpq 0x90(%rsp), %rax
movq 0xa0(%rsp), %rbp
jne 0x59cc0
movl 0x28(%rbx), %eax
incl %ecx
testl %eax, %eax
sete %dl
subl 0x4(%rbx), %ecx
sete %sil
orb %dl, %sil
je 0x5a063
xorl %r15d, %r15d
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd 0x1d729d(%rip), %xmm2   # 0x231310
subsd 0x38(%rsp), %xmm2
movl %eax, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd %xmm0, %xmm2
movl $0x1, %r15d
ucomisd %xmm2, %xmm1
jae 0x5a04e
cmpl $0x0, 0x50(%rsp)
je 0x5a0ab
cmpl $0x1c2, %eax            # imm = 0x1C2
jb 0x5a04b
mulsd 0x1d7547(%rip), %xmm0   # 0x2315f0
jmp 0x5a0b1
mulsd 0x58(%rsp), %xmm0
ucomisd %xmm0, %xmm1
jae 0x5a04e
jmp 0x5a04b
callq 0x5d4e