// File: /workspace/github_cpp_makefile_star2_O3/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 0x888db
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 0x1a8d3c(%rip), %xmm1   # 0x2315a0
pushq 0xa8(%rsp)
pushq 0x18(%rsp)
callq 0x59be2
addq $0x20, %rsp
testq %rbp, %rbp
je 0x888c6
testl %eax, %eax
je 0x888c6
incl %r15d
subl %r13d, %r15d
je 0x888c6
movl 0x28(%r12,%r14), %eax
testl %eax, %eax
je 0x888c6
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
mulsd 0x1a8d4e(%rip), %xmm0   # 0x2315f0
cmpl $0x1c2, %eax            # imm = 0x1C2
jb 0x888c6
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
ucomisd %xmm0, %xmm1
jb 0x888c6
movb $0x3, 0x2c(%r12,%r14)
movq 0x30(%rsp), %rcx
addq %rax, 0x18(%rcx)
addq $0xa8, %r14
decq %rbx
movq 0x30(%rsp), %r12
jne 0x88829
movq 0x90(%rsp), %rbx
cmpq $0x0, 0x10(%rsp)
movq 0x98(%rsp), %r8
je 0x88913
cmpq $0x0, 0x18(%r12)
jle 0x88913
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rcx
movq %r12, %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
callq 0x4ad19
movq $0x0, 0x18(%r12)
movq 0x10(%r12), %rax
movq %rax, 0x28(%rsp)
testq %rax, %rax
movq 0x38(%rsp), %r15
jle 0x88aec
movsd 0x1a8c34(%rip), %xmm0   # 0x231570
mulsd 0x40(%rsp), %xmm0
movq (%rsp), %rax
leaq 0x50(%rax), %rbp
addq $0xdfc, %rax            # imm = 0xDFC
movq %rax, 0x20(%rsp)
movsd 0x1a8ca3(%rip), %xmm1   # 0x231600
movsd %xmm0, 0x48(%rsp)
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
xorl %r14d, %r14d
testq %rbx, %rbx
je 0x8897b
movq 0x10(%rbx), %rax
jmp 0x8897d
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 0x5c901
addq $0x30, %rsp
movb $0x0, 0x2c(%r13)
movsd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x88a0a
movsd 0x48(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq 0x90(%rsp), %rbx
jb 0x88ade
movb $0x3, 0x2c(%r13)
jmp 0x88ade
movq 0x48(%r13), %rax
testq %rax, %rax
je 0x88a70
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x58(%r13), %rdi
cmpl $0x0, 0x1c(%rdi,%r15)
jne 0x88a64
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 0x89ef9
addq $0x30, %rsp
movq 0x48(%r13), %rax
incq %r12
addq $0x20, %r15
cmpq %rax, %r12
jb 0x88a19
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 0x49760
movq 0x38(%rsp), %r15
movq %r13, %rdi
testq %r15, %r15
je 0x88aba
movq %r15, %rsi
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movsd 0x18(%rsp), %xmm0
callq 0x49e91
jmp 0x88ad6
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movsd 0x18(%rsp), %xmm0
movq %rbx, %r8
callq 0x4a52c
movq 0x90(%rsp), %rbx
incq %r14
cmpq 0x28(%rsp), %r14
jne 0x88970
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq