// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_extend_err_non_retrieve_exz(overlap_region*, char*, char*, long, bit_extz_t*, unsigned long*, long, double, double, double, long, long, long*)
double gen_extend_err_non_retrieve_exz(overlap_region *z, char* qstr, char *tstr, int64_t tl, bit_extz_t *exz, uint64_t *v_idx, int64_t block_s, double ovlp_cut, double e_rate, double e_max, int64_t max_err, int64_t sec_check, int64_t *r_e)
{
    int64_t ovl, k, ce, an = z->w_list.n, tot_l, tot_e, ws, we, ql; 
    ovl = z->x_pos_e+1-z->x_pos_s; if(r_e) (*r_e) = INT64_MAX;
    if((sec_check) && (!simi_pass(ovl, z->align_length, 0, ovlp_cut, &e_rate))) return DBL_MAX;
    // nw = get_num_wins(z->x_pos_s, z->x_pos_e+1, block_s);
    // for (k = 0; k < an; k++) {
    //     if(z->w_list.a[k].clen) z->w_list.a[k].y_end -= z->w_list.a[k].extra_begin;
    // }

    tot_l = tot_e = 0;
    for (k = an-1, ce = z->x_pos_e; k >= 0; k--) {
        // assert(k == 0 || z->w_list.a[k].x_end > z->w_list.a[k-1].x_start);//sorted
        tot_l += z->w_list.a[k].x_end + 1 - z->w_list.a[k].x_start;
        tot_e += z->w_list.a[k].error;///matched window

        we = z->w_list.a[k].x_end;
        while (we < ce) {
            ws = we+1;
            get_win_id_by_s(z, ws, block_s, &we);
            ql = we+1-ws; tot_l += ql; 
            tot_e += gen_extend_err_0_non_retrieve_exz(z, qstr, tstr, tl, exz, v_idx, block_s, e_rate, max_err, ws, we, k);
            if((e_max > 0) && (tot_e > (ovl*e_max))) return DBL_MAX;
        }
        ce = z->w_list.a[k].x_start-1;
        if((e_max > 0) && (tot_e > (ovl*e_max))) return DBL_MAX;
    }

    if(ce >= ((int64_t)z->x_pos_s)) {
        we = ((int64_t)z->x_pos_s)-1;
        while (we < ce) {
            ws = we+1;
            get_win_id_by_s(z, ws, block_s, &we);
            ql = we+1-ws; tot_l += ql; 
            tot_e += gen_extend_err_0_non_retrieve_exz(z, qstr, tstr, tl, exz, v_idx, block_s, e_rate, max_err, ws, we, k);
            if((e_max > 0) && (tot_e > (ovl*e_max))) return DBL_MAX;
        }
    }

    assert(tot_l == ovl); if(r_e) (*r_e) = tot_e;
    return (double)(tot_e)/(double)(tot_l);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movsd %xmm2, (%rsp)
movsd %xmm1, 0x18(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq 0xa8(%rsp), %r8
movq 0xa0(%rsp), %rsi
movq 0x48(%rdi), %rax
movl 0x4(%rdi), %ecx
movl 0x8(%rdi), %ebx
leal 0x1(%rbx), %edx
movl %edx, %r9d
subl %ecx, %r9d
testq %r8, %r8
je 0x5d8d0
movabsq $0x7fffffffffffffff, %r11 # imm = 0x7FFFFFFFFFFFFFFF
movq %r11, (%r8)
testq %rsi, %rsi
je 0x5d928
movl 0x28(%rdi), %esi
testl %esi, %esi
sete %r8b
cmpl %ecx, %edx
sete %cl
orb %r8b, %cl
movsd 0x1c7c22(%rip), %xmm0   # 0x225510
movsd %xmm0, 0x8(%rsp)
jne 0x5dbcc
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
movsd 0x1c7966(%rip), %xmm1   # 0x225270
subsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
movl %esi, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
ucomisd %xmm1, %xmm0
jb 0x5dbcc
leaq -0x1(%rax), %r11
testq %rax, %rax
movq %rdi, 0x28(%rsp)
movq %r9, 0x20(%rsp)
jle 0x5daaf
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
mulsd (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %eax, %eax
movsd 0x1c7bb4(%rip), %xmm0   # 0x225510
movsd %xmm0, 0x8(%rsp)
xorl %r15d, %r15d
movq %r15, %rcx
movq %rax, %rdx
movq 0x58(%rdi), %rax
movq %r11, %r9
shlq $0x5, %r9
movslq 0x4(%rax,%r9), %r14
movl (%rax,%r9), %esi
movl %r14d, %r8d
subl %esi, %r8d
incl %r8d
movslq %r8d, %r15
addq %rcx, %r15
movq %r9, 0x50(%rsp)
movswq 0x14(%rax,%r9), %rax
addq %rdx, %rax
cmpq %r14, %rbx
jle 0x5da5e
movq %rax, %rbp
leaq 0x1(%r14), %r9
movl 0x8(%rdi), %r12d
movl 0x4(%rdi), %ecx
movq %rcx, %rax
xorl %edx, %edx
movq 0x90(%rsp), %r10
idivq %r10
subq %rdx, %rcx
movq %r9, %rax
subq %rcx, %rax
cqto
idivq %r10
incq %rax
imulq %r10, %rax
addq %rcx, %rax
decq %rax
cmpq %r12, %rax
cmovlq %rax, %r12
subq $0x8, %rsp
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
movsd 0x20(%rsp), %xmm0
movq %r11, %r13
pushq %r11
pushq %r12
pushq %r9
pushq 0xb8(%rsp)
pushq %r10
callq 0x5cbe3
addq $0x30, %rsp
addq %rbp, %rax
movsd (%rsp), %xmm0
ucomisd 0x1c7aea(%rip), %xmm0   # 0x225518
jbe 0x5da44
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
ucomisd 0x10(%rsp), %xmm0
ja 0x5dbcc
subq %r14, %r15
addq %r12, %r15
movq %r12, %r14
cmpq %rbx, %r12
movq %r13, %r11
movq 0x28(%rsp), %rdi
jl 0x5d9a5
movsd (%rsp), %xmm0
ucomisd 0x1c7aad(%rip), %xmm0   # 0x225518
jbe 0x5da81
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
ucomisd 0x10(%rsp), %xmm0
ja 0x5dbcc
movq 0x58(%rdi), %rcx
movq 0x50(%rsp), %rdx
movslq (%rcx,%rdx), %rbx
decq %rbx
leaq -0x1(%r11), %rcx
testq %r11, %r11
movq %rcx, %r11
jg 0x5d965
movq $-0x1, %r11
movq 0x20(%rsp), %r9
jmp 0x5dab4
xorl %r15d, %r15d
xorl %eax, %eax
movl 0x4(%rdi), %r12d
cmpq %r12, %rbx
jl 0x5db9b
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
decq %r12
mulsd (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x1c7a31(%rip), %xmm0   # 0x225510
movsd %xmm0, 0x8(%rsp)
movq %rax, %rbp
leaq 0x1(%r12), %r9
movl 0x8(%rdi), %r14d
movl 0x4(%rdi), %ecx
movq %rcx, %rax
xorl %edx, %edx
movq 0x90(%rsp), %r10
idivq %r10
subq %rdx, %rcx
movq %r9, %rax
subq %rcx, %rax
cqto
idivq %r10
incq %rax
imulq %r10, %rax
addq %rcx, %rax
decq %rax
cmpq %r14, %rax
cmovlq %rax, %r14
subq $0x8, %rsp
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
movsd 0x20(%rsp), %xmm0
movq %r11, %r13
pushq %r11
pushq %r14
pushq %r9
pushq 0xb8(%rsp)
pushq %r10
callq 0x5cbe3
addq $0x30, %rsp
addq %rbp, %rax
movsd (%rsp), %xmm0
ucomisd 0x1c79a9(%rip), %xmm0   # 0x225518
jbe 0x5db81
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
ucomisd 0x10(%rsp), %xmm0
ja 0x5dbcc
subq %r12, %r15
addq %r14, %r15
movq %r14, %r12
cmpq %rbx, %r14
movq %r13, %r11
movq 0x28(%rsp), %rdi
jl 0x5dae5
cmpq 0x20(%rsp), %r15
jne 0x5dbe1
movq 0xa8(%rsp), %rcx
testq %rcx, %rcx
je 0x5dbb2
movq %rax, (%rcx)
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c8680(%rip), %rdi    # 0x226268
leaq 0x1c7a54(%rip), %rsi    # 0x225643
leaq 0x1c87eb(%rip), %rcx    # 0x2263e1
movl $0x34ab, %edx           # imm = 0x34AB
callq 0x2110