// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: reassign_gaps(overlap_region*, overlap_region*, char*, long, char*, long, All_reads*, UC_Read*, asg16_v*)
void reassign_gaps(overlap_region *z, overlap_region *aux, char* qstr, int64_t ql, char* tstr, int64_t tl, All_reads *rref, UC_Read* tu, asg16_v* buf)
{
    // if(z->y_id != 24 || z->x_id != 25) return;
    if(z->non_homopolymer_errors == 0) return;
    aux->w_list.n = aux->w_list.c.n = 0; 
    aux->y_id = z->y_id; aux->y_pos_strand = z->y_pos_strand;
    aux->x_pos_s = z->x_pos_s; aux->x_pos_e = z->x_pos_e;
    aux->y_pos_s = z->y_pos_s; aux->y_pos_e = z->y_pos_e;

    int64_t k, z_n = z->w_list.n, rr = 0, re = 0;
    for (k = 0; k < z_n; k++) {
        if(move_wins(z, k, aux, rref, qstr, tstr, tu, buf, &re)) rr = 1;
    }
    ///update z by aux_o
    if(rr) update_overlap_region(z, aux, ql, ((rref)?(Get_READ_LENGTH((*rref), z->y_id)):(tl)));
    z->non_homopolymer_errors -= re;

    // if(z->y_id == 1) {
    //     fprintf(stderr, "[M::%s] rr::%ld\tx_id::%u\ty_id::%u\tx::[%u, %u)\ty::[%u, %u)\tz_n::%ld\n", 
    //             __func__, rr, z->x_id, z->y_id, z->x_pos_s, z->x_pos_e + 1, z->y_pos_s, z->y_pos_e + 1, z_n);
    //     fprintf(stderr, "qstr(%lld)::%.*s\n", qu->length, (int32_t)(qu->length), qu->seq);
    //     fprintf(stderr, "tstr(%lld)::%.*s\n", tu->length, (int32_t)(tu->length), tu->seq);
    //     ///debug
        
        // if(z->y_pos_strand) {
        //     recover_UC_Read_RC(tu, rref, z->y_id);
        // } else {
        //     recover_UC_Read(tu, rref, z->y_id);
        // }
        // if(tstr) {
        //     bit_extz_t ez; 
        //     for (k = 0; k < z_n; k++) {
        //         if(is_ualn_win((z->w_list.a[k]))) continue;
        //         set_bit_extz_t(ez, (*z), k);
        //         if(!cigar_check(tstr, qstr, &ez)) {
        //             fprintf(stderr, "\n[M::%s] x_id::%u, y_id::%u, x::[%u, %u), y::[%u, %u)\n", __func__, z->x_id, z->y_id, z->x_pos_s, z->x_pos_e + 1, z->y_pos_s, z->y_pos_e + 1);
        //             exit(1);
        //         }
        //     }
        // }
        
    // }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x20(%rsp)
cmpl $0x0, 0x30(%rdi)
je 0x509b9
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, %rbx
movq %r9, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
andq $0x0, 0x60(%rsi)
andq $0x0, 0x48(%rsi)
movl 0x10(%rdi), %eax
movl %eax, 0x10(%rsi)
movl 0x1c(%rdi), %eax
movl %eax, 0x1c(%rsi)
movq 0x4(%rdi), %rax
movq %rax, 0x4(%rsi)
movq 0x14(%rdi), %rax
movq %rax, 0x14(%rsi)
movq 0x48(%rdi), %r14
leaq 0x8(%rsp), %rax
andq $0x0, (%rax)
xorl %r15d, %r15d
testq %r14, %r14
cmovleq %r15, %r14
xorl %r13d, %r13d
cmpq %r15, %r14
je 0x50983
subq $0x8, %rsp
movq %rbx, %rdi
movl %r15d, %esi
movq %r12, %rdx
movq 0x68(%rsp), %rcx
movq %rbp, %r8
movq 0x28(%rsp), %r9
leaq 0x10(%rsp), %rax
pushq %rax
pushq 0x80(%rsp)
pushq 0x80(%rsp)
callq 0x5047c
addq $0x20, %rsp
testw %ax, %ax
pushq $0x1
popq %rax
cmovneq %rax, %r13
incq %r15
jmp 0x50938
testq %r13, %r13
je 0x509b2
movq 0x60(%rsp), %rax
testq %rax, %rax
movq 0x10(%rsp), %rcx
je 0x509a2
movq 0x18(%rax), %rax
movl 0x10(%rbx), %ecx
movq (%rax,%rcx,8), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq 0x18(%rsp), %rdx
callq 0x382a0
movl 0x8(%rsp), %eax
subl %eax, 0x30(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq