// File: chhylp123[P]hifiasm/Correct.cpp
// Function: gen_hc_r_alin_re(overlap_region*, Candidates_list*, char*, unsigned long, char*, unsigned long, bit_extz_t*, overlap_region*, double, long, long, long, long, asg16_v*)
uint64_t gen_hc_r_alin_re(overlap_region* z, Candidates_list *cl, char* qstr, uint64_t ql, char* tstr, uint64_t tl, bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf)
{
    double err, e_max, rr; int64_t re;

    err = e_rate; e_max = err * 1.5;

    z->shared_seed = z->non_homopolymer_errors;///for index

    if(!align_hc_ed_post_non_retrieve_extz(z, qstr, ql, tstr, tl, exz, err, wl, OVERLAP_THRESHOLD_HIFI_FILTER, 0, NULL)) return 0;

    rr = gen_extend_err_non_retrieve_exz(z, qstr, tstr, tl, exz, NULL, wl, -1, err, (e_max+0.000001), THRESHOLD_MAX_SIZE, 0, &re);
    z->is_match = 0; 

    if (rr > err) return 0;
    z->non_homopolymer_errors = re;

    // if(z->x_id == 3196 && z->y_id == 3199) fprintf(stderr, "-0-[M::%s] tid::%u\t%.*s\trr::%f\tre::%ld\n", __func__, z->y_id, (int)Get_NAME_LENGTH(R_INF, z->y_id), Get_NAME(R_INF, z->y_id), rr, re);

    if(!gen_hc_fast_non_retrieve_cigar(z, cl, wl, qstr, ql, tstr, tl, exz, aux_o, e_rate, rid, khit)) return 0;

    // if(z->x_id == 3196 && z->y_id == 3199) fprintf(stderr, "-1-[M::%s] tid::%u\t%.*s\trr::%f\tre::%ld\n", __func__, z->y_id, (int)Get_NAME_LENGTH(R_INF, z->y_id), Get_NAME(R_INF, z->y_id), rr, re);

    reassign_gaps(z, aux_o, qstr, ql, tstr, tl, NULL, NULL, buf);

    // if(z->x_id == 3196 && z->y_id == 3199) fprintf(stderr, "-2-[M::%s] tid::%u\t%.*s\trr::%f\tre::%u\n", __func__, z->y_id, (int)Get_NAME_LENGTH(R_INF, z->y_id), Get_NAME(R_INF, z->y_id), rr, z->non_homopolymer_errors);
    
    z->is_match = 1; ///z->non_homopolymer_errors = re;
    z->strong = z->without_large_indel = 0;

    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x90, %rsp
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
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 -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x2e68d7(%rip), %xmm0   # 0x382200
mulsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x20(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movq 0x10(%rbp), %r9
movsd -0x58(%rbp), %xmm0
movq 0x20(%rbp), %rax
movsd 0x2e68fe(%rip), %xmm1   # 0x382268
xorl %r10d, %r10d
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x51210
cmpl $0x0, %eax
jne 0x9b99a
movq $0x0, -0x18(%rbp)
jmp 0x9bae0
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq 0x10(%rbp), %r8
movq 0x20(%rbp), %r10
movsd -0x58(%rbp), %xmm1
movsd 0x2e68c1(%rip), %xmm2   # 0x382280
addsd -0x60(%rbp), %xmm2
xorl %eax, %eax
movl %eax, %r9d
movsd 0x2e68a7(%rip), %xmm0   # 0x382278
leaq -0x70(%rbp), %rax
movq %r10, (%rsp)
movq $0x1f, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x53340
movsd %xmm0, -0x68(%rbp)
movq -0x20(%rbp), %rax
movb $0x0, 0x2c(%rax)
movsd -0x68(%rbp), %xmm0
ucomisd -0x58(%rbp), %xmm0
jbe 0x9ba1b
movq $0x0, -0x18(%rbp)
jmp 0x9bae0
movq -0x70(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq 0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movq -0x48(%rbp), %r14
movq 0x10(%rbp), %rbx
movq 0x18(%rbp), %r11
movsd -0x50(%rbp), %xmm0
movq 0x28(%rbp), %r10
movq 0x30(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x996e0
cmpq $0x0, %rax
jne 0x9ba86
movq $0x0, -0x18(%rbp)
jmp 0x9bae0
movq -0x20(%rbp), %rdi
movq 0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %r9
movq 0x40(%rbp), %rax
xorl %r10d, %r10d
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x9acc0
movq -0x20(%rbp), %rax
movb $0x1, 0x2c(%rax)
movq -0x20(%rbp), %rax
movb $0x0, 0x2d(%rax)
movq -0x20(%rbp), %rax
movb $0x0, 0x2e(%rax)
movq $0x1, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq