// File: /workspace/github_cpp_makefile_star2_O1/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, 0x40(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %r8, (%rsp)
movq %rcx, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, %r12
movq $0x0, 0x18(%rdi)
movq 0x10(%rdi), %rbx
testq %rbx, %rbx
movq %rdi, 0x30(%rsp)
jle 0x895a9
movq (%rsp), %rax
leaq 0x50(%rax), %rcx
movq %rcx, 0x20(%rsp)
addq $0xdfc, %rax            # imm = 0xDFC
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
movq 0x10(%rsp), %rbp
movq (%r12), %r12
leaq (%r12,%r14), %rdi
movl 0x4(%r12,%r14), %r13d
movl 0x8(%r12,%r14), %r15d
movq 0x8(%rsp), %rax
movq (%rax), %rcx
subq $0x10, %rsp
movq %rbp, %rsi
xorl %edx, %edx
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r9
movsd 0x28(%rsp), %xmm0
movsd 0x19bf6e(%rip), %xmm1   # 0x2254a0
pushq 0xa8(%rsp)
pushq 0x18(%rsp)
callq 0x5a68a
addq $0x20, %rsp
testq %rbp, %rbp
je 0x89594
testl %eax, %eax
je 0x89594
incl %r15d
subl %r13d, %r15d
je 0x89594
movl 0x28(%r12,%r14), %eax
testl %eax, %eax
je 0x89594
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
mulsd 0x19bf80(%rip), %xmm0   # 0x2254f0
cmpl $0x1c2, %eax            # imm = 0x1C2
jb 0x89594
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
ucomisd %xmm0, %xmm1
jb 0x89594
movb $0x3, 0x2c(%r12,%r14)
movq 0x30(%rsp), %rcx
addq %rax, 0x18(%rcx)
addq $0xa8, %r14
decq %rbx
movq 0x30(%rsp), %r12
jne 0x894f7
movq 0x90(%rsp), %rbx
cmpq $0x0, 0x10(%rsp)
movq 0x98(%rsp), %r8
je 0x895e1
cmpq $0x0, 0x18(%r12)
jle 0x895e1
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rcx
movq %r12, %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
callq 0x4b691
movq $0x0, 0x18(%r12)
movq 0x10(%r12), %rax
movq %rax, 0x28(%rsp)
testq %rax, %rax
movq 0x38(%rsp), %r15
jle 0x897b5
movsd 0x19be66(%rip), %xmm0   # 0x225470
mulsd 0x40(%rsp), %xmm0
movq (%rsp), %rax
leaq 0x50(%rax), %rbp
addq $0xdfc, %rax            # imm = 0xDFC
movq %rax, 0x20(%rsp)
movsd 0x19bed5(%rip), %xmm1   # 0x225500
movsd %xmm0, 0x48(%rsp)
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
xorl %r14d, %r14d
testq %rbx, %rbx
je 0x89649
movq 0x10(%rbx), %rax
jmp 0x8964b
xorl %eax, %eax
movq (%r12), %rcx
imulq $0xa8, %r14, %rdx
leaq (%rcx,%rdx), %r13
movl 0x8(%rcx,%rdx), %ebx
subl 0x4(%rcx,%rdx), %ebx
movq 0x8(%rsp), %rcx
movq (%rcx), %r8
subq $0x8, %rsp
movq %r13, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rbp, %r9
movsd 0x20(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
pushq $0x0
pushq 0xa8(%rsp)
pushq %rax
pushq 0x20(%rsp)
pushq 0x48(%rsp)
callq 0x5d0fb
addq $0x30, %rsp
movb $0x0, 0x2c(%r13)
movsd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x896d8
movsd 0x48(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq 0x90(%rsp), %rbx
jb 0x897a7
movb $0x3, 0x2c(%r13)
jmp 0x897a7
cmpq $0x0, 0x48(%r13)
je 0x89739
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x58(%r13), %rdi
cmpl $0x0, 0x1c(%rdi,%r15)
jne 0x8972c
addq %r15, %rdi
movq 0x8(%rsp), %rax
movq (%rax), %r9
movl 0x10(%r13), %eax
movl 0x1c(%r13), %r10d
subq $0x8, %rsp
movq %r13, %rsi
movq 0x40(%rsp), %rdx
xorl %ecx, %ecx
movq 0x18(%rsp), %r8
pushq %rax
pushq %r10
pushq 0x18(%rsp)
pushq 0x40(%rsp)
pushq %rbp
callq 0x8ab12
addq $0x30, %rsp
incq %r12
addq $0x20, %r15
cmpq 0x48(%r13), %r12
jb 0x896e5
incl %ebx
movq 0x30(%rsp), %r12
addq %rbx, 0x18(%r12)
movb $0x1, 0x2c(%r13)
movq %r13, %rdi
movq 0x98(%rsp), %rbx
movq %rbx, %rsi
callq 0x4a082
movq 0x38(%rsp), %r15
movq %r13, %rdi
testq %r15, %r15
je 0x89783
movq %r15, %rsi
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movsd 0x18(%rsp), %xmm0
callq 0x4a7c5
jmp 0x8979f
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movsd 0x18(%rsp), %xmm0
movq %rbx, %r8
callq 0x4aed4
movq 0x90(%rsp), %rbx
incq %r14
cmpq 0x28(%rsp), %r14
jne 0x8963e
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq