// File: 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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xe0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0xa4f56
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x58(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movq -0x80(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x68(%rbp)
movq -0x80(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x38(%rbp), %r8
addq $0x50, %r8
movq -0x38(%rbp), %r9
addq $0xdfc, %r9             # imm = 0xDFC
movq -0x38(%rbp), %r10
movsd -0x48(%rbp), %xmm0
movq 0x18(%rbp), %rax
xorl %edx, %edx
movsd 0x2dd35c(%rip), %xmm1   # 0x382228
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x4ea30
cmpl $0x0, %eax
jne 0xa4eea
jmp 0xa4f45
cmpq $0x0, -0x28(%rbp)
je 0xa4f43
movq -0x68(%rbp), %rdi
movq -0x80(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %esi
movq -0x28(%rbp), %rcx
xorl %edx, %edx
movl $0x1, %eax
cmpq $0x0, %rcx
cmovnel %eax, %edx
movsd 0x2dd310(%rip), %xmm0   # 0x382228
xorl %eax, %eax
movl %eax, %ecx
callq 0xa7100
cmpl $0x0, %eax
je 0xa4f43
movq -0x80(%rbp), %rax
movb $0x3, 0x2c(%rax)
movq -0x80(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
jmp 0xa4f45
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0xa4e58
cmpq $0x0, -0x28(%rbp)
je 0xa4f8a
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jle 0xa4f8a
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq 0x10(%rbp), %rdx
movsd -0x48(%rbp), %xmm0
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movq 0x18(%rbp), %r8
callq 0x37650
movsd 0x2dd26e(%rip), %xmm0   # 0x382200
mulsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0xa525c
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x58(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movq -0x80(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0x68(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x38(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xa0(%rbp)
movq -0x38(%rbp), %rax
addq $0xdfc, %rax            # imm = 0xDFC
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0xa506c
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xc8(%rbp)
jmp 0xa5077
xorl %eax, %eax
movq %rax, -0xc8(%rbp)
jmp 0xa5077
movq -0x90(%rbp), %r11
movq -0x98(%rbp), %rbx
movq -0xa0(%rbp), %r9
movq -0xa8(%rbp), %r8
movq -0xb0(%rbp), %rcx
movq -0xb8(%rbp), %rsi
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %r10
movq 0x18(%rbp), %rax
movsd -0x48(%rbp), %xmm1
movsd 0x2dd1c0(%rip), %xmm2   # 0x382280
addsd -0x88(%rbp), %xmm2
xorl %edx, %edx
movsd 0x2dd1a6(%rip), %xmm0   # 0x382278
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
callq 0x52920
movsd %xmm0, -0x78(%rbp)
movq -0x80(%rbp), %rax
movb $0x0, 0x2c(%rax)
movsd -0x78(%rbp), %xmm1
movsd -0x50(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xa522c
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x80(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0xa51c4
movq -0x80(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x70(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
je 0xa5149
jmp 0xa51b3
movq -0x80(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x70(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
movq -0x80(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %rax
movq (%rax), %r9
movq -0x38(%rbp), %r14
addq $0x50, %r14
movq -0x38(%rbp), %rbx
addq $0xdfc, %rbx            # imm = 0xDFC
movq -0x38(%rbp), %r11
movq -0x80(%rbp), %rax
movl 0x1c(%rax), %r10d
movq -0x80(%rbp), %rax
movl 0x10(%rax), %eax
xorl %ecx, %ecx
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0xa6b10
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0xa511c
movq -0x68(%rbp), %rcx
movq -0x18(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x80(%rbp), %rax
movb $0x1, 0x2c(%rax)
movq -0x80(%rbp), %rdi
movq 0x18(%rbp), %rsi
callq 0x34ab0
cmpq $0x0, -0x20(%rbp)
je 0xa520c
movq -0x80(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movsd -0x48(%rbp), %xmm0
callq 0x35990
jmp 0xa522a
movq -0x80(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movsd -0x48(%rbp), %xmm0
movq 0x18(%rbp), %r8
callq 0x36730
jmp 0xa5249
movsd -0x78(%rbp), %xmm1
movsd -0x88(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xa5247
movq -0x80(%rbp), %rax
movb $0x3, 0x2c(%rax)
jmp 0xa5249
jmp 0xa524b
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0xa4fbf
addq $0xe0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax,%rax)