// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x9acfe
jmp 0x9ae5c
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jge 0x9adef
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %esi
movq -0x10(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq -0x18(%rbp), %r8
movq -0x28(%rbp), %r9
movq 0x18(%rbp), %r11
movq 0x20(%rbp), %r10
leaq -0x50(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x9a460
cmpw $0x0, %ax
je 0x9addf
movq $0x1, -0x48(%rbp)
jmp 0x9ade1
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x9ad8e
cmpq $0x0, -0x48(%rbp)
je 0x9ae4b
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x9ae2e
movq 0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
jmp 0x9ae36
movq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rdx
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rcx
callq 0x673f0
movq -0x50(%rbp), %rdx
movq -0x8(%rbp), %rax
movl 0x30(%rax), %ecx
subq %rdx, %rcx
movl %ecx, 0x30(%rax)
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)