// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movsd %xmm2, 0x20(%rsp)
movsd %xmm1, 0x40(%rsp)
movq %r8, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq 0xc8(%rsp), %r10
movq 0xc0(%rsp), %rdx
movq 0x48(%rdi), %r13
movl 0x4(%rdi), %eax
movq %rdi, 0x18(%rsp)
movl 0x8(%rdi), %ecx
movq %rcx, 0x28(%rsp)
incl %ecx
movl %ecx, %r8d
subl %eax, %r8d
testq %r10, %r10
je 0x2d3ca
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movq %rsi, (%r10)
testq %rdx, %rdx
je 0x2d432
movq 0x18(%rsp), %rdx
movl 0x28(%rdx), %edx
testl %edx, %edx
sete %sil
cmpl %eax, %ecx
sete %al
orb %sil, %al
movsd 0x1b6173(%rip), %xmm0   # 0x1e3560
movsd %xmm0, 0x30(%rsp)
jne 0x2d41d
cvtsi2sd %r8, %xmm2
movsd 0x1b5e9e(%rip), %xmm0   # 0x1e32a0
subsd 0x40(%rsp), %xmm0
mulsd %xmm2, %xmm0
movl %edx, %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm0, %xmm1
movapd %xmm2, %xmm0
jae 0x2d437
movsd 0x30(%rsp), %xmm0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cvtsi2sd %r8, %xmm0
movq %r8, 0x68(%rsp)
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
xorl %edi, %edi
movsd 0x1b610e(%rip), %xmm0   # 0x1e3560
movsd %xmm0, 0x30(%rsp)
xorl %r15d, %r15d
movq 0x18(%rsp), %r12
leaq -0x1(%r13), %rbp
testq %r13, %r13
jle 0x2d59f
movq 0x18(%rsp), %rax
movq 0x58(%rax), %rax
movq %rbp, %r8
shlq $0x5, %r8
movslq 0x4(%rax,%r8), %rcx
movl (%rax,%r8), %edx
movq %r8, 0x70(%rsp)
movswq 0x14(%rax,%r8), %rax
movq %rcx, 0x10(%rsp)
subl %edx, %ecx
incl %ecx
movslq %ecx, %rcx
addq %rcx, %rdi
movq %rdi, 0x8(%rsp)
addq %rax, %r15
movq %rbp, %r13
movq 0x10(%rsp), %rbp
cmpq 0x28(%rsp), %rbp
jge 0x2d556
leaq 0x1(%rbp), %rbx
movq %r12, %rdi
movq %rbx, %rsi
movq 0xb0(%rsp), %r14
movq %r14, %rdx
leaq 0x10(%rsp), %rcx
callq 0x51f8b
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
subq %rbp, %rcx
addq %rax, %rcx
movq %rcx, 0x8(%rsp)
subq $0x8, %rsp
movq %r12, %rdi
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %r8
movsd 0x48(%rsp), %xmm0
movq %r13, %rbp
pushq %r13
pushq %rax
pushq %rbx
pushq 0xd8(%rsp)
pushq %r14
callq 0x2c87f
addq $0x30, %rsp
addq %rax, %r15
movsd 0x20(%rsp), %xmm0
ucomisd 0x1b602e(%rip), %xmm0   # 0x1e3568
jbe 0x2d4a8
cvtsi2sd %r15, %xmm0
ucomisd 0x38(%rsp), %xmm0
jbe 0x2d4a8
jmp 0x2d41d
movq 0x18(%rsp), %rax
movq 0x58(%rax), %rax
movq 0x70(%rsp), %rcx
movslq (%rax,%rcx), %rax
decq %rax
movq %rax, 0x28(%rsp)
movsd 0x20(%rsp), %xmm0
ucomisd 0x1b5fea(%rip), %xmm0   # 0x1e3568
movq 0x8(%rsp), %rdi
jbe 0x2d460
cvtsi2sd %r15, %xmm0
ucomisd 0x38(%rsp), %xmm0
jbe 0x2d460
jmp 0x2d41d
movq 0x18(%rsp), %rax
movl 0x4(%rax), %eax
cmpq %rax, 0x28(%rsp)
jl 0x2d67a
movq %rdi, 0x8(%rsp)
decq %rax
leaq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq 0x18(%rsp), %r12
movq %rbp, %r13
movq 0x10(%rsp), %rbp
cmpq 0x28(%rsp), %rbp
jge 0x2d675
leaq 0x1(%rbp), %rbx
movq %r12, %rdi
movq %rbx, %rsi
movq 0xb0(%rsp), %r14
movq %r14, %rdx
leaq 0x10(%rsp), %rcx
callq 0x51f8b
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
subq %rbp, %rcx
addq %rax, %rcx
movq %rcx, 0x8(%rsp)
subq $0x8, %rsp
movq %r12, %rdi
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %r8
movsd 0x48(%rsp), %xmm0
movq %r13, %rbp
pushq %r13
pushq %rax
pushq %rbx
pushq 0xd8(%rsp)
pushq %r14
callq 0x2c87f
addq $0x30, %rsp
addq %rax, %r15
movsd 0x20(%rsp), %xmm0
ucomisd 0x1b5f0f(%rip), %xmm0   # 0x1e3568
jbe 0x2d5c7
cvtsi2sd %r15, %xmm0
ucomisd 0x38(%rsp), %xmm0
jbe 0x2d5c7
jmp 0x2d41d
movq 0x8(%rsp), %rdi
movq 0x68(%rsp), %rcx
cmpq %rcx, %rdi
jne 0x2d6ad
movq 0xc8(%rsp), %rax
testq %rax, %rax
je 0x2d694
movq %r15, (%rax)
cvtsi2sd %r15, %xmm1
cvtsi2sd %rcx, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
jmp 0x2d41d
leaq 0x1b6c14(%rip), %rdi    # 0x1e42c8
leaq 0x1b5fe8(%rip), %rsi    # 0x1e36a3
leaq 0x1b6d7f(%rip), %rcx    # 0x1e4441
movl $0x34ab, %edx           # imm = 0x34AB
callq 0x2110