// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: refine_ed_aln_test(overlap_region_alloc*, All_reads*, ul_idx_t const*, UC_Read*, Correct_dumy*, UC_Read*, kvec_t_u64_warp*, long, double, double)
inline void refine_ed_aln_test(overlap_region_alloc* overlap_list, All_reads *rref, const ul_idx_t *uref, 
                        UC_Read* g_read, Correct_dumy* dumy, UC_Read* overlap_read, kvec_t_u64_warp* v_idx, int64_t block_s, double e_rate, double e_rate_final)
{
    int64_t j, on, ovl; uint64_t k; double rr; overlap_region *z; 

    overlap_list->mapped_overlaps_length = 0; on = overlap_list->length;
    for (j = 0; j < on; ++j) {
        z = &(overlap_list->list[j]); ovl = z->x_pos_e+1-z->x_pos_s;
        if(!align_ul_ed_post(z, uref, NULL, g_read->seq, dumy->overlap_region, dumy->overlap_region_fix, 
                        dumy, e_rate, block_s, OVERLAP_THRESHOLD_NOSI_FILTER, NULL)) {
            continue;
        }
        if(uref && simi_pass(ovl, z->align_length, uref?1:0, OVERLAP_THRESHOLD_NOSI_FILTER, NULL)) {
            z->is_match = 3; overlap_list->mapped_overlaps_length += z->align_length;
        }
    }

    if(uref && overlap_list->mapped_overlaps_length > 0) {
        set_herror_win(overlap_list, dumy, v_idx, e_rate, g_read->length, block_s);
    }

    double e_max = e_rate_final * 1.5;
    overlap_list->mapped_overlaps_length = 0; on = overlap_list->length;
    for (j = 0; j < on; j++) {
        z = &(overlap_list->list[j]); ovl = z->x_pos_e + 1 - z->x_pos_s;
        rr = gen_extend_err(z, uref, NULL, rref, g_read->seq, dumy->overlap_region, dumy->overlap_region_fix,
                    dumy, v_idx?v_idx->a.a:NULL, block_s, -1, e_rate, (e_max+0.000001), NULL);
        z->is_match = 0;///must be here;
        if (rr <= e_rate_final) {
            for (k = 0; k < z->w_list.n; k++) {
                if(z->w_list.a[k].clen) continue;
                gen_backtrace_adv(&(z->w_list.a[k]), z, rref, NULL, uref, g_read->seq, dumy->overlap_region, dumy->overlap_region_fix, 
                dumy, z->y_pos_strand, z->y_id);
            }
            
            overlap_list->mapped_overlaps_length += ovl;
            z->is_match = 1; append_unmatched_wins(z, block_s);
            if(rref) {
                calculate_boundary_cigars(z, rref, dumy, g_read, e_rate);
            } else {
                calculate_ul_boundary_cigars(z, uref, dumy, g_read, e_rate, block_s);
            }
        } else if (rr <= e_max) {
            z->is_match = 3;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movsd %xmm1, 0x38(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %r8, %rbx
movq %rcx, (%rsp)
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r13
andq $0x0, 0x18(%rdi)
movq 0x10(%rdi), %r12
leaq 0x50(%r8), %rax
movq %rax, 0x30(%rsp)
leaq 0xdfc(%r8), %rax
movq %rax, 0x28(%rsp)
xorl %ebp, %ebp
testq %r12, %r12
cmovleq %rbp, %r12
movq %rsi, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
subq $0x1, %r12
jb 0x5561e
movq (%r13), %r13
movq %r13, %rdi
addq %rbp, %rdi
movl 0x4(%r13,%rbp), %eax
movl %eax, 0x18(%rsp)
movl 0x8(%r13,%rbp), %r14d
movq (%rsp), %rax
movq (%rax), %rcx
subq $0x10, %rsp
movq %r15, %rsi
xorl %edx, %edx
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %r9
movsd 0x18(%rsp), %xmm0
movsd 0x18df43(%rip), %xmm1   # 0x1e34f0
pushq 0xa8(%rsp)
pushq %rbx
callq 0x2a687
addq $0x20, %rsp
testq %r15, %r15
je 0x55608
testl %eax, %eax
je 0x55608
incl %r14d
subl 0x18(%rsp), %r14d
je 0x55608
movl 0x28(%r13,%rbp), %eax
testl %eax, %eax
je 0x55608
cvtsi2sd %r14, %xmm0
mulsd 0x18df61(%rip), %xmm0   # 0x1e3548
cmpl $0x1c2, %eax            # imm = 0x1C2
jb 0x55608
cvtsi2sd %rax, %xmm1
ucomisd %xmm0, %xmm1
jb 0x55608
movb $0x3, 0x2c(%r13,%rbp)
movq 0x10(%rsp), %rcx
addq %rax, 0x18(%rcx)
addq $0xa8, %rbp
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %r13
jmp 0x55563
testq %r15, %r15
movq 0x98(%rsp), %r8
movq 0x90(%rsp), %r12
je 0x55656
cmpq $0x0, 0x18(%r13)
jle 0x55656
movq (%rsp), %rax
movq 0x8(%rax), %rcx
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movsd 0x8(%rsp), %xmm0
callq 0x1e2db
movsd 0x18de62(%rip), %xmm0   # 0x1e34c0
andq $0x0, 0x18(%r13)
mulsd 0x38(%rsp), %xmm0
movq 0x10(%r13), %rax
movsd 0x18dedb(%rip), %xmm1   # 0x1e3550
movsd %xmm0, 0x40(%rsp)
addsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
xorl %edx, %edx
testq %rax, %rax
cmovleq %rdx, %rax
movq %rax, 0x50(%rsp)
cmpq 0x50(%rsp), %rdx
je 0x55806
testq %r12, %r12
je 0x556aa
movq 0x10(%r12), %rax
jmp 0x556ac
xorl %eax, %eax
movq (%r13), %rcx
movq %rdx, 0x18(%rsp)
imulq $0xa8, %rdx, %rdx
leaq (%rcx,%rdx), %r12
movl 0x8(%rcx,%rdx), %ebp
subl 0x4(%rcx,%rdx), %ebp
movq (%rsp), %rcx
movq (%rcx), %r8
subq $0x8, %rsp
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r14, %rcx
movq 0x38(%rsp), %r9
movsd 0x10(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
pushq $0x0
pushq 0xa8(%rsp)
pushq %rax
pushq %rbx
pushq 0x50(%rsp)
callq 0x2cc26
addq $0x30, %rsp
movb $0x0, 0x2c(%r12)
movsd 0x38(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x55734
movsd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x557f1
movb $0x3, 0x2c(%r12)
jmp 0x557f1
incl %ebp
xorl %r13d, %r13d
xorl %r14d, %r14d
cmpq 0x48(%r12), %r14
jae 0x55793
movq 0x58(%r12), %rdi
cmpl $0x0, 0x1c(%rdi,%r13)
jne 0x5578a
addq %r13, %rdi
movq (%rsp), %rax
movq (%rax), %r9
movl 0x10(%r12), %eax
movl 0x1c(%r12), %r10d
subq $0x8, %rsp
movq %r12, %rsi
movq 0x28(%rsp), %rdx
xorl %ecx, %ecx
movq %r15, %r8
pushq %rax
pushq %r10
pushq %rbx
pushq 0x48(%rsp)
pushq 0x58(%rsp)
callq 0x567ea
addq $0x30, %rsp
incq %r14
addq $0x20, %r13
jmp 0x5573c
movq 0x10(%rsp), %r13
addq %rbp, 0x18(%r13)
movb $0x1, 0x2c(%r12)
movq %r12, %rdi
movq 0x98(%rsp), %rbp
movq %rbp, %rsi
callq 0x1cf34
movq 0x20(%rsp), %r14
movq %r12, %rdi
testq %r14, %r14
je 0x557d9
movq %r14, %rsi
movq %rbx, %rdx
movq (%rsp), %rcx
movsd 0x8(%rsp), %xmm0
callq 0x1d5df
jmp 0x557f1
movq %r15, %rsi
movq %rbx, %rdx
movq (%rsp), %rcx
movsd 0x8(%rsp), %xmm0
movq %rbp, %r8
callq 0x1dbea
movq 0x18(%rsp), %rdx
incq %rdx
movq 0x90(%rsp), %r12
jmp 0x55693
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq