// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %rbx
movq %r8, %r15
movq %rcx, 0x18(%rsp)
movq %rdx, %r13
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
movq 0x70(%rsp), %rbp
movq 0x60(%rsp), %r12
movl 0x30(%rdi), %eax
movl %eax, 0x24(%rdi)
subq $0x10, %rsp
movsd 0x19240f(%rip), %xmm1   # 0x1e3540
movq %rdx, %rsi
movq %r8, %rcx
movq %r9, %r8
movq %r12, %r9
movsd %xmm0, 0x18(%rsp)
pushq $0x0
pushq %rbp
callq 0x2bd31
addq $0x20, %rsp
testl %eax, %eax
je 0x511a1
movsd 0x192365(%rip), %xmm2   # 0x1e34c0
movsd 0x8(%rsp), %xmm0
mulsd %xmm0, %xmm2
movapd %xmm0, %xmm1
addsd 0x1923df(%rip), %xmm2   # 0x1e3550
leaq 0x20(%rsp), %rax
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
pushq %rax
pushq $0x0
pushq $0x1f
pushq %rbp
callq 0x2d35e
addq $0x20, %rsp
movb $0x0, 0x2c(%r14)
ucomisd 0x8(%rsp), %xmm0
jbe 0x511a8
xorl %eax, %eax
jmp 0x5123f
movq 0x80(%rsp), %rax
movq 0x68(%rsp), %rdx
movl 0x20(%rsp), %ecx
movl %ecx, 0x30(%r14)
subq $0x30, %rsp
movq %rax, 0x20(%rsp)
movq %rdx, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq %rbx, (%rsp)
movq %r14, %rdi
movq 0x40(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq 0x48(%rsp), %r12
movq %r12, %r8
movq %r15, %r9
movsd 0x38(%rsp), %xmm0
callq 0x4fd4e
popq %rcx
popq %rdx
movq 0xb0(%rsp), %rax
movq %rax, 0x10(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rsp)
movq %r14, %rdi
movq 0x88(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x508c8
addq $0x20, %rsp
movw $0x1, 0x2c(%r14)
movb $0x0, 0x2e(%r14)
pushq $0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq