// File: 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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xc0, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x48(%rbp)
movsd %xmm0, -0x50(%rbp)
movsd %xmm1, -0x58(%rbp)
movsd %xmm2, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movq -0x20(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x68(%rbp)
cmpq $0x0, 0x28(%rbp)
je 0x533c0
movq 0x28(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq %rcx, (%rax)
cmpq $0x0, 0x20(%rbp)
je 0x533fb
movq -0x68(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %esi
movsd -0x50(%rbp), %xmm0
xorl %edx, %edx
leaq -0x58(%rbp), %rcx
callq 0xa7100
cmpl $0x0, %eax
jne 0x533fb
movsd 0x32eea7(%rip), %xmm0   # 0x382298
movsd %xmm0, -0x18(%rbp)
jmp 0x537bd
movq $0x0, -0x90(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x80(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x70(%rbp)
jl 0x5362d
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movq -0x20(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x70(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
subl (%rcx), %eax
cltq
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswq 0x14(%rax), %rax
addq -0x90(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x78(%rbp), %rax
jge 0x535c2
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq 0x10(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
callq 0x9e2e0
movq -0xa0(%rbp), %rax
addq $0x1, %rax
subq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %r9
movq 0x10(%rbp), %r14
movsd -0x58(%rbp), %xmm0
movq 0x18(%rbp), %rbx
movq -0x98(%rbp), %r11
movq -0xa0(%rbp), %r10
movq -0x70(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x52380
addq -0x90(%rbp), %rax
movq %rax, -0x90(%rbp)
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x535bd
cvtsi2sdq -0x90(%rbp), %xmm0
cvtsi2sdq -0x68(%rbp), %xmm1
mulsd -0x60(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x535bd
movsd 0x32ece5(%rip), %xmm0   # 0x382298
movsd %xmm0, -0x18(%rbp)
jmp 0x537bd
jmp 0x534b5
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
subl $0x1, %eax
cltq
movq %rax, -0x78(%rbp)
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5361a
cvtsi2sdq -0x90(%rbp), %xmm0
cvtsi2sdq -0x68(%rbp), %xmm1
mulsd -0x60(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5361a
movsd 0x32ec88(%rip), %xmm0   # 0x382298
movsd %xmm0, -0x18(%rbp)
jmp 0x537bd
jmp 0x5361c
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x53428
movq -0x78(%rbp), %rax
movq -0x20(%rbp), %rcx
movl 0x4(%rcx), %ecx
cmpq %rcx, %rax
jl 0x5375f
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
subq $0x1, %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x78(%rbp), %rax
jge 0x5375d
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq 0x10(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
callq 0x9e2e0
movq -0xa0(%rbp), %rax
addq $0x1, %rax
subq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %r9
movq 0x10(%rbp), %r14
movsd -0x58(%rbp), %xmm0
movq 0x18(%rbp), %rbx
movq -0x98(%rbp), %r11
movq -0xa0(%rbp), %r10
movq -0x70(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x52380
addq -0x90(%rbp), %rax
movq %rax, -0x90(%rbp)
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x53758
cvtsi2sdq -0x90(%rbp), %xmm0
cvtsi2sdq -0x68(%rbp), %xmm1
mulsd -0x60(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x53758
movsd 0x32eb47(%rip), %xmm0   # 0x382298
movsd %xmm0, -0x18(%rbp)
jmp 0x537bd
jmp 0x53653
jmp 0x5375f
movq -0x88(%rbp), %rax
cmpq -0x68(%rbp), %rax
jne 0x5376e
jmp 0x5378d
leaq 0x32f7cb(%rip), %rdi    # 0x382f40
leaq 0x32eb9f(%rip), %rsi    # 0x38231b
movl $0x34ab, %edx           # imm = 0x34AB
leaq 0x32f931(%rip), %rcx    # 0x3830b9
callq 0x2130
cmpq $0x0, 0x28(%rbp)
je 0x537a2
movq -0x90(%rbp), %rcx
movq 0x28(%rbp), %rax
movq %rcx, (%rax)
cvtsi2sdq -0x90(%rbp), %xmm0
cvtsi2sdq -0x88(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
addq $0xc0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop