// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_extend_err_exz(overlap_region*, ul_idx_t const*, hpc_t*, All_reads*, char*, char*, bit_extz_t*, unsigned long*, long, double, double, double, long, long, long*)
double gen_extend_err_exz(overlap_region *z, const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, char* qstr, 
char *tstr, 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_exz(z, uref, hpc_g, rref, qstr, tstr, 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_exz(z, uref, hpc_g, rref, qstr, tstr, 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 $0x68, %rsp
movsd %xmm2, 0x8(%rsp)
movsd %xmm1, 0x28(%rsp)
movq %r9, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, %rbp
movq 0xc8(%rsp), %r8
movq 0xc0(%rsp), %rsi
movq 0x48(%rdi), %rax
movl 0x4(%rdi), %ecx
movl 0x8(%rdi), %r14d
leal 0x1(%r14), %edx
movl %edx, %r9d
subl %ecx, %r9d
testq %r8, %r8
je 0x5d51b
movabsq $0x7fffffffffffffff, %rdi # imm = 0x7FFFFFFFFFFFFFFF
movq %rdi, (%r8)
testq %rsi, %rsi
je 0x5d573
movl 0x28(%rbp), %esi
testl %esi, %esi
sete %dil
cmpl %ecx, %edx
sete %cl
orb %dil, %cl
movsd 0x1c7fd7(%rip), %xmm0   # 0x225510
movsd %xmm0, 0x10(%rsp)
jne 0x5d83a
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
movsd 0x1c7d1b(%rip), %xmm1   # 0x225270
subsd 0x28(%rsp), %xmm1
mulsd %xmm0, %xmm1
movl %esi, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
ucomisd %xmm1, %xmm0
jb 0x5d83a
leaq -0x1(%rax), %rsi
testq %rax, %rax
movq %r9, 0x30(%rsp)
jle 0x5d70a
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %eax, %eax
movsd 0x1c7f6d(%rip), %xmm0   # 0x225510
movsd %xmm0, 0x10(%rsp)
xorl %r12d, %r12d
movq %r12, %rcx
movq %rax, %rdx
movq 0x58(%rbp), %rax
movq %rsi, 0x20(%rsp)
movq %rsi, %r8
shlq $0x5, %r8
movslq 0x4(%rax,%r8), %r15
movl (%rax,%r8), %esi
movl %r15d, %edi
subl %esi, %edi
incl %edi
movslq %edi, %r12
addq %rcx, %r12
movq %r8, 0x60(%rsp)
movswq 0x14(%rax,%r8), %rax
addq %rdx, %rax
cmpq %r15, %r14
jle 0x5d6b6
movq %rax, %rbx
leaq 0x1(%r15), %r10
movl 0x8(%rbp), %r13d
movl 0x4(%rbp), %ecx
movq %rcx, %rax
xorl %edx, %edx
movq 0xb0(%rsp), %r11
idivq %r11
subq %rdx, %rcx
movq %r10, %rax
subq %rcx, %rax
cqto
idivq %r11
incq %rax
imulq %r11, %rax
addq %rcx, %rax
decq %rax
cmpq %r13, %rax
cmovlq %rax, %r13
subq $0x8, %rsp
movq %rbp, %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r8
movq 0x60(%rsp), %r9
movsd 0x30(%rsp), %xmm0
pushq 0x28(%rsp)
pushq %r13
pushq %r10
pushq 0xd8(%rsp)
pushq %r11
pushq 0xd8(%rsp)
pushq 0xd8(%rsp)
callq 0x5c764
addq $0x40, %rsp
addq %rbx, %rax
movsd 0x8(%rsp), %xmm0
ucomisd 0x1c7e8a(%rip), %xmm0   # 0x225518
jbe 0x5d6a4
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
ucomisd 0x18(%rsp), %xmm0
ja 0x5d83a
subq %r15, %r12
addq %r13, %r12
movq %r13, %r15
cmpq %r14, %r13
jl 0x5d5ef
movsd 0x8(%rsp), %xmm0
ucomisd 0x1c7e54(%rip), %xmm0   # 0x225518
jbe 0x5d6da
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
ucomisd 0x18(%rsp), %xmm0
ja 0x5d83a
movq 0x58(%rbp), %rcx
movq 0x60(%rsp), %rdx
movslq (%rcx,%rdx), %r14
decq %r14
movq 0x20(%rsp), %rdx
leaq -0x1(%rdx), %rsi
testq %rdx, %rdx
jg 0x5d5ac
movq $-0x1, %rsi
movq 0x30(%rsp), %r9
jmp 0x5d70f
xorl %r12d, %r12d
xorl %eax, %eax
movl 0x4(%rbp), %r13d
cmpq %r13, %r14
jl 0x5d809
movq %rsi, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r9, %xmm0
decq %r13
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x1c7dd0(%rip), %xmm0   # 0x225510
movsd %xmm0, 0x10(%rsp)
movq %rax, %rbx
leaq 0x1(%r13), %r10
movl 0x8(%rbp), %r15d
movl 0x4(%rbp), %ecx
movq %rcx, %rax
xorl %edx, %edx
movq 0xb0(%rsp), %r11
idivq %r11
subq %rdx, %rcx
movq %r10, %rax
subq %rcx, %rax
cqto
idivq %r11
incq %rax
imulq %r11, %rax
addq %rcx, %rax
decq %rax
cmpq %r15, %rax
cmovlq %rax, %r15
subq $0x8, %rsp
movq %rbp, %rdi
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r8
movq 0x60(%rsp), %r9
movsd 0x30(%rsp), %xmm0
pushq 0x28(%rsp)
pushq %r15
pushq %r10
pushq 0xd8(%rsp)
pushq %r11
pushq 0xd8(%rsp)
pushq 0xd8(%rsp)
callq 0x5c764
addq $0x40, %rsp
addq %rbx, %rax
movsd 0x8(%rsp), %xmm0
ucomisd 0x1c7d33(%rip), %xmm0   # 0x225518
jbe 0x5d7f7
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
ucomisd 0x18(%rsp), %xmm0
ja 0x5d83a
subq %r13, %r12
addq %r15, %r12
movq %r15, %r13
cmpq %r14, %r15
jl 0x5d746
cmpq 0x30(%rsp), %r12
jne 0x5d84f
movq 0xc8(%rsp), %rcx
testq %rcx, %rcx
je 0x5d820
movq %rax, (%rcx)
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c8a12(%rip), %rdi    # 0x226268
leaq 0x1c7de6(%rip), %rsi    # 0x225643
leaq 0x1c8ac1(%rip), %rcx    # 0x226325
movl $0x3480, %edx           # imm = 0x3480
callq 0x2110