// File: /workspace/github_cpp_makefile_star2_O1/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:
cmpl $0x0, 0x30(%rdi)
je 0x849b1
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r12
movq %rsi, %r11
movq %rdi, %r14
xorl %eax, %eax
movq %rax, 0x60(%rsi)
movq %rax, 0x48(%rsi)
movl 0x10(%rdi), %edx
movl %edx, 0x10(%rsi)
movl 0x1c(%rdi), %edx
movl %edx, 0x1c(%rsi)
movl 0x4(%rdi), %edx
movl %edx, 0x4(%rsi)
movl 0x8(%rdi), %edx
movl %edx, 0x8(%rsi)
movl 0x14(%rdi), %edx
movl %edx, 0x14(%rsi)
movl 0x18(%rdi), %edx
movl %edx, 0x18(%rsi)
movq 0x48(%rdi), %rdx
movq %rax, 0x8(%rsp)
testq %rdx, %rdx
jle 0x8499b
movq %r8, %rbp
movq %r9, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movq 0x60(%rsp), %rax
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %rdx, 0x20(%rsp)
subq $0x8, %rsp
movq %r14, %rdi
movl %r15d, %esi
movq %r11, %rdx
movq %rax, %rcx
movq %r12, %r8
movq %rbp, %r9
leaq 0x10(%rsp), %rax
pushq %rax
pushq 0x80(%rsp)
pushq 0x80(%rsp)
movq %r11, %rbx
callq 0x84432
movq 0x40(%rsp), %rdx
movq %rbx, %r11
addq $0x20, %rsp
testw %ax, %ax
movq 0x60(%rsp), %rax
movl $0x1, %ecx
cmovneq %rcx, %r13
incq %r15
cmpq %r15, %rdx
jne 0x84919
testq %r13, %r13
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
je 0x8499b
testq %rax, %rax
je 0x84990
movq 0x18(%rax), %rax
movl 0x10(%r14), %ecx
movq (%rax,%rcx,8), %rcx
movq %r14, %rdi
movq %r11, %rsi
callq 0x69a6f
movl 0x8(%rsp), %eax
subl %eax, 0x30(%r14)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq