// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq %r9, %rbx
movq %r8, %r15
movq %rcx, 0x8(%rsp)
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r14
movq 0x50(%rsp), %r12
movl 0x30(%rdi), %eax
movl %eax, 0x24(%rdi)
subq $0x10, %rsp
movsd 0x1acd8d(%rip), %xmm1   # 0x2315f8
movq %rdx, %rsi
movq %r8, %rcx
movq %r9, %r8
movq %r12, %r9
movsd %xmm0, 0x10(%rsp)
pushq $0x0
pushq 0x78(%rsp)
callq 0x5b663
addq $0x20, %rsp
testl %eax, %eax
je 0x848df
movsd 0x1accd8(%rip), %xmm2   # 0x231570
movsd (%rsp), %xmm0
mulsd %xmm0, %xmm2
movapd %xmm0, %xmm1
addsd 0x1acd53(%rip), %xmm2   # 0x231600
leaq 0x10(%rsp), %rax
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
pushq %rax
pushq $0x0
pushq $0x1f
pushq 0x78(%rsp)
callq 0x5d06c
addq $0x20, %rsp
movb $0x0, 0x2c(%r14)
ucomisd (%rsp), %xmm0
jbe 0x848e6
xorl %eax, %eax
jmp 0x8498f
movl 0x10(%rsp), %eax
movl %eax, 0x30(%r14)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x7d1f5
subq $0x30, %rsp
movq 0xa0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq %rbx, (%rsp)
movq %r14, %rdi
movq %rbp, %rsi
movq 0x90(%rsp), %rdx
movq %r13, %rcx
movq 0x38(%rsp), %r12
movq %r12, %r8
movq %r15, %r9
movsd 0x30(%rsp), %xmm0
callq 0x6b184
addq $0x10, %rsp
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rsp)
movq %r14, %rdi
movq 0x78(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
movq %rbx, %r9
callq 0x83f97
addq $0x20, %rsp
movw $0x1, 0x2c(%r14)
movb $0x0, 0x2e(%r14)
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq