// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_extend_err(overlap_region*, ul_idx_t const*, hpc_t*, All_reads*, char*, char*, char*, Correct_dumy*, unsigned long*, long, double, double, double, long*)
double gen_extend_err(overlap_region *z, const ul_idx_t *uref, hpc_t *hpc_g, All_reads *rref, char* qstr, 
char *tstr, char *tstr_1, Correct_dumy* dumy, uint64_t *v_idx, int64_t block_s, double ovlp_cut, double e_rate, double e_max, 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(!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(z, uref, hpc_g, rref, qstr, tstr, tstr_1, dumy, v_idx, block_s, e_rate, 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(z, uref, hpc_g, rref, qstr, tstr, tstr_1, dumy, v_idx, block_s, e_rate, 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 $0x88, %rsp
movsd %xmm2, 0x18(%rsp)
movsd %xmm1, 0x38(%rsp)
movq %r9, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq 0xe0(%rsp), %rdx
movq 0x48(%rdi), %r13
movl 0x4(%rdi), %eax
movl 0x8(%rdi), %ecx
movq %rcx, 0x20(%rsp)
leal 0x1(%rcx), %r9d
testq %rdx, %rdx
je 0x2cc89
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, (%rdx)
movl 0x28(%rdi), %ecx
testl %ecx, %ecx
sete %dl
cmpl %eax, %r9d
sete %sil
orb %dl, %sil
movsd 0x1b68bd(%rip), %xmm0   # 0x1e3560
movsd %xmm0, 0x48(%rsp)
jne 0x2ccd8
subl %eax, %r9d
cvtsi2sd %r9, %xmm1
movsd 0x1b65e5(%rip), %xmm0   # 0x1e32a0
subsd 0x38(%rsp), %xmm0
movsd %xmm1, 0x40(%rsp)
mulsd %xmm1, %xmm0
movl %ecx, %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm0, %xmm1
jae 0x2ccf0
movsd 0x48(%rsp), %xmm0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
testq %r13, %r13
cmovgq %r13, %rax
pushq $0xc
popq %rcx
subq $0x1, %rax
jb 0x2cd1b
movq 0x58(%rdi), %rdx
cmpl $0x0, 0x10(%rdx,%rcx)
je 0x2cd15
movswl 0x4(%rdx,%rcx), %esi
subl %esi, (%rdx,%rcx)
addq $0x20, %rcx
jmp 0x2ccfc
movq %r9, 0x78(%rsp)
movsd 0x40(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %r9d, %r9d
xorl %ebp, %ebp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rbx
leaq -0x1(%r13), %r12
testq %r13, %r13
jle 0x2ce95
movq 0x58(%rdi), %rax
movq %r12, %rdi
shlq $0x5, %rdi
movslq 0x4(%rax,%rdi), %rcx
movl (%rax,%rdi), %edx
movq %rdi, 0x80(%rsp)
movswq 0x14(%rax,%rdi), %rax
movq %rcx, 0x10(%rsp)
subl %edx, %ecx
incl %ecx
movslq %ecx, %rcx
addq %rcx, %r9
movq %r9, 0x8(%rsp)
addq %rax, %rbp
movq %r12, %r13
movq 0x10(%rsp), %r12
cmpq 0x20(%rsp), %r12
jge 0x2ce49
leaq 0x1(%r12), %r14
movq %rbx, %rdi
movq %r14, %rsi
movq 0xd8(%rsp), %r15
movq %r15, %rdx
leaq 0x10(%rsp), %rcx
callq 0x51f8b
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
subq %r12, %rcx
addq %rax, %rcx
movq %rcx, 0x8(%rsp)
subq $0x8, %rsp
movq %rbx, %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %r8
movq 0x78(%rsp), %r9
movsd 0x40(%rsp), %xmm0
movq %r13, %r12
pushq %r13
pushq %rax
pushq %r14
pushq %r15
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
callq 0x2bf95
addq $0x40, %rsp
addq %rax, %rbp
movsd 0x18(%rsp), %xmm0
ucomisd 0x1b673b(%rip), %xmm0   # 0x1e3568
jbe 0x2cd86
cvtsi2sd %rbp, %xmm0
ucomisd 0x28(%rsp), %xmm0
jbe 0x2cd86
jmp 0x2ccd8
movq 0x30(%rsp), %rdi
movq 0x58(%rdi), %rax
movq 0x80(%rsp), %rcx
movslq (%rax,%rcx), %rax
decq %rax
movq %rax, 0x20(%rsp)
movsd 0x18(%rsp), %xmm0
ucomisd 0x1b66f4(%rip), %xmm0   # 0x1e3568
movq 0x8(%rsp), %r9
jbe 0x2cd41
cvtsi2sd %rbp, %xmm0
ucomisd 0x28(%rsp), %xmm0
jbe 0x2cd41
jmp 0x2ccd8
movl 0x4(%rdi), %eax
cmpq %rax, 0x20(%rsp)
jl 0x2cf80
movq %r9, 0x8(%rsp)
decq %rax
leaq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq 0x30(%rsp), %rbx
movq %r12, %r13
movq 0x10(%rsp), %r12
cmpq 0x20(%rsp), %r12
jge 0x2cf7b
leaq 0x1(%r12), %r14
movq %rbx, %rdi
movq %r14, %rsi
movq 0xd8(%rsp), %r15
movq %r15, %rdx
leaq 0x10(%rsp), %rcx
callq 0x51f8b
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
subq %r12, %rcx
addq %rax, %rcx
movq %rcx, 0x8(%rsp)
subq $0x8, %rsp
movq %rbx, %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %r8
movq 0x78(%rsp), %r9
movsd 0x40(%rsp), %xmm0
movq %r13, %r12
pushq %r13
pushq %rax
pushq %r14
pushq %r15
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
pushq 0xf8(%rsp)
callq 0x2bf95
addq $0x40, %rsp
addq %rax, %rbp
movsd 0x18(%rsp), %xmm0
ucomisd 0x1b6609(%rip), %xmm0   # 0x1e3568
jbe 0x2ceb8
cvtsi2sd %rbp, %xmm0
ucomisd 0x28(%rsp), %xmm0
jbe 0x2ceb8
jmp 0x2ccd8
movq 0x8(%rsp), %r9
cmpq 0x78(%rsp), %r9
jne 0x2cfad
movq 0xe0(%rsp), %rax
testq %rax, %rax
je 0x2cf97
movq %rbp, (%rax)
cvtsi2sd %rbp, %xmm0
divsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x2ccd8
leaq 0x1b7314(%rip), %rdi    # 0x1e42c8
leaq 0x1b66e8(%rip), %rsi    # 0x1e36a3
leaq 0x1b7313(%rip), %rcx    # 0x1e42d5
movl $0x3454, %edx           # imm = 0x3454
callq 0x2110