// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: realloc_rdb(All_reads*, ma_sub_t**, R_to_U*, unsigned long*, unsigned long, unsigned long, char*, asg_t*, ug_opt_t*)
void realloc_rdb(All_reads* rdb, ma_sub_t **cov, R_to_U *ruI, uint64_t *rmap, uint64_t rid_n, uint64_t scaf_len, char *scaf_id, 
asg_t *ng, ug_opt_t *uopt)
{
    uint64_t i, rid_n0 = rdb->total_reads, tname, cname;
    uint64_t scaf_id_len = strlen(scaf_id); char *des, *src;
    rdb->total_reads = rid_n;
    tname = rdb->name_index[rid_n0];
    fprintf(stderr, "+[M::%s] rid_n0::%lu, rid_n::%lu\n", __func__, rid_n0, rid_n);
    ///for read bases
    REALLOC(rdb->N_site, rdb->total_reads);
    REALLOC(rdb->read_length, rdb->total_reads);
    REALLOC(rdb->read_size, rdb->total_reads);
    REALLOC(rdb->read_sperate, rdb->total_reads);
    REALLOC(rdb->trio_flag, rdb->total_reads);
    REALLOC(rdb->name_index, rdb->total_reads+1);///total_reads+1
    REALLOC((*cov), rdb->total_reads);
	for (i = rid_n0; i < rdb->total_reads; i++) {
        // fprintf(stderr, "[M::%s] i::%lu\n", __func__, i);
        rdb->N_site[i] = NULL;
        rdb->read_length[i] = scaf_len;
        rdb->read_size[i] = scaf_len;
        rdb->trio_flag[i] = AMBIGU;
        (*cov)[i].c = (*cov)[i].del = 0; 
        (*cov)[i].s = 0; (*cov)[i].e = scaf_len;
        cname = scaf_id_len;
        if(rmap[i] != ((uint64_t)-1)) {///not a scaffold node
            if(rdb->N_site[rmap[i]] != NULL) {
                MALLOC(rdb->N_site[i], rdb->N_site[rmap[i]][0]+1);
                memcpy(rdb->N_site[i], rdb->N_site[rmap[i]], 
                    sizeof((*(rdb->N_site[i])))*(rdb->N_site[rmap[i]][0]+1));
            }
            rdb->read_length[i] = rdb->read_length[rmap[i]];
            rdb->read_size[i] = rdb->read_length[rmap[i]];
            rdb->trio_flag[i] = rdb->trio_flag[rmap[i]];
            (*cov)[i] = (*cov)[rmap[i]];
            cname = Get_NAME_LENGTH((*rdb), (rmap[i]));
        } 
        rdb->name_index[i] = tname; tname += cname;
        rdb->total_reads_bases += rdb->read_length[i];

        MALLOC(rdb->read_sperate[i], (rdb->read_length[i]/4+1));
        if(rmap[i] != ((uint64_t)-1)) {///not a scaffold node
            memcpy(rdb->read_sperate[i], rdb->read_sperate[rmap[i]], 
                sizeof((*(rdb->read_sperate[i])))*(rdb->read_length[i]/4+1));
        } else {
            ///set to A
            memset(rdb->read_sperate[i], 0, sizeof((*(rdb->read_sperate[i])))*(rdb->read_length[i]/4+1));
        }
	}

    rdb->index_size = rdb->total_reads;
    rdb->name_index[i] = tname; 
    rdb->total_name_length = tname; 
    rdb->name_index_size = rdb->total_reads+1;
    REALLOC(rdb->name, tname);
    for (i = rid_n0; i < rdb->total_reads; i++) {
        des = Get_NAME((*rdb), i); src = scaf_id; cname = scaf_id_len;
        if(rmap[i] != ((uint64_t)-1)) {
            src = Get_NAME((*rdb), rmap[i]); cname = Get_NAME_LENGTH((*rdb), (rmap[i]));
        }
        memcpy(des, src, sizeof((*(des)))*cname);
    }

    REALLOC(rdb->paf, rdb->total_reads); 
    memset(rdb->paf+rid_n0, 0, (rdb->total_reads-rid_n0)*sizeof((*rdb->paf)));
    REALLOC(rdb->reverse_paf, rdb->total_reads);
    memset(rdb->reverse_paf+rid_n0, 0, (rdb->total_reads-rid_n0)*sizeof((*rdb->reverse_paf)));

    ruI->len = rdb->total_reads;
    REALLOC(ruI->index, ruI->len); 
    memset(ruI->index, -1, sizeof((*(ruI->index)))*(ruI->len));

    reset_bub_label_t(uopt->b_mask_t, ng, 0, 0);
    uopt->coverage_cut = (*cov);
    uopt->reverse_sources = rdb->reverse_paf;
    uopt->sources = rdb->paf;
    fprintf(stderr, "-[M::%s] rid_n0::%lu, rid_n::%lu\n", __func__, rid_n0, rid_n);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x50(%rsp)
movq %r8, %rbx
movq %rcx, 0x8(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, %r12
movq %rdi, %r15
movq 0xa0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x90(%rsp), %rdi
movq 0x50(%r15), %rbp
movq %rdi, 0x20(%rsp)
callq 0x2090
movq %rax, 0x18(%rsp)
movq %rbx, 0x50(%r15)
movq 0x40(%r15), %rax
movq (%rax,%rbp,8), %r14
movq 0x2688a6(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x21d2b3(%rip), %rsi    # 0x2499f7
leaq 0x21dade(%rip), %rdx    # 0x24a229
movq %rbp, %rcx
movq %rbx, 0x48(%rsp)
movq %rbx, %r8
xorl %eax, %eax
callq 0x22b0
movq (%r15), %rdi
movq 0x50(%r15), %rsi
shlq $0x3, %rsi
callq 0x2370
movq %rax, (%r15)
movq 0x18(%r15), %rdi
movq 0x50(%r15), %rsi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x18(%r15)
movq 0x20(%r15), %rdi
movq 0x50(%r15), %rsi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x20(%r15)
movq 0x10(%r15), %rdi
movq 0x50(%r15), %rsi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r15)
movq 0x28(%r15), %rdi
movq 0x50(%r15), %rsi
callq 0x2370
movq %rax, 0x28(%r15)
movq 0x40(%r15), %rdi
movq 0x50(%r15), %rax
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq %rax, 0x40(%r15)
movq (%r12), %rdi
imulq $0xc, 0x50(%r15), %rsi
callq 0x2370
movq %r12, 0x10(%rsp)
movq %rax, (%r12)
movq 0x50(%r15), %rax
cmpq %rax, %rbp
movq %rbp, 0x40(%rsp)
jae 0x2c9a6
imulq $0xc, %rbp, %r12
movq 0x10(%rsp), %rdx
movq (%r15), %rax
andq $0x0, (%rax,%rbp,8)
movq 0x18(%r15), %rax
movq 0x50(%rsp), %rcx
movq %rcx, (%rax,%rbp,8)
movq 0x20(%r15), %rax
movq %rcx, (%rax,%rbp,8)
movq 0x28(%r15), %rax
xorl %esi, %esi
movb %sil, (%rax,%rbp)
movq (%rdx), %rax
andl $0x7fffffff, (%rax,%r12) # imm = 0x7FFFFFFF
movq (%rdx), %rax
movb %sil, 0x8(%rax,%r12)
andl $0x80000000, (%rax,%r12) # imm = 0x80000000
movq (%rdx), %rax
movl %ecx, 0x4(%rax,%r12)
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rbx
cmpq $-0x1, %rbx
je 0x2c8ad
movq (%r15), %r13
movq (%r13,%rbx,8), %rax
testq %rax, %rax
je 0x2c8bd
movq (%rax), %rax
leaq 0x8(,%rax,8), %rdi
callq 0x2280
movq %rax, (%r13,%rbp,8)
movq (%r15), %rax
movq (%rax,%rbp,8), %rdi
movq (%rax,%rbx,8), %rsi
movq (%rsi), %rax
leaq 0x8(,%rax,8), %rdx
callq 0x2160
movq 0x8(%rsp), %r13
movq (%r13,%rbp,8), %rbx
jmp 0x2c8c2
movq 0x40(%r15), %rax
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r13
jmp 0x2c91f
movq 0x8(%rsp), %r13
movq 0x18(%r15), %rax
movq (%rax,%rbx,8), %rcx
movq %rcx, (%rax,%rbp,8)
movq (%r13,%rbp,8), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%r15), %rcx
movq %rax, (%rcx,%rbp,8)
movq 0x28(%r15), %rax
movq (%r13,%rbp,8), %rcx
movb (%rax,%rcx), %cl
movb %cl, (%rax,%rbp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
imulq $0xc, (%r13,%rbp,8), %rcx
movl 0x8(%rax,%rcx), %edx
movl %edx, 0x8(%rax,%r12)
movq (%rax,%rcx), %rcx
movq %rcx, (%rax,%r12)
movq 0x40(%r15), %rax
movq (%r13,%rbp,8), %rcx
movq 0x8(%rax,%rcx,8), %rbx
subq (%rax,%rcx,8), %rbx
movq %r14, (%rax,%rbp,8)
movq 0x18(%r15), %rax
movq (%rax,%rbp,8), %rcx
addq %rcx, 0x58(%r15)
movq (%rax,%rbp,8), %rdi
shrq $0x2, %rdi
incq %rdi
callq 0x2280
movq 0x10(%r15), %rcx
movq %rax, (%rcx,%rbp,8)
movq (%r13,%rbp,8), %rax
movq 0x10(%r15), %rcx
movq (%rcx,%rbp,8), %rdi
cmpq $-0x1, %rax
je 0x2c974
movq (%rcx,%rax,8), %rsi
movq 0x18(%r15), %rax
movq (%rax,%rbp,8), %rdx
shrq $0x2, %rdx
incq %rdx
callq 0x2160
jmp 0x2c98a
movq 0x18(%r15), %rax
movq (%rax,%rbp,8), %rdx
shrq $0x2, %rdx
incq %rdx
xorl %esi, %esi
callq 0x20e0
addq %rbx, %r14
incq %rbp
movq 0x50(%r15), %rax
addq $0xc, %r12
cmpq %rax, %rbp
movq 0x10(%rsp), %rdx
jb 0x2c80b
movq %rax, 0x38(%r15)
movq 0x40(%r15), %rax
movq %r14, (%rax,%rbp,8)
movq %r14, 0x60(%r15)
movq 0x8(%r15), %rdi
movq 0x50(%r15), %rax
incq %rax
movq %rax, 0x48(%r15)
movq %r14, %rsi
callq 0x2370
movq %rax, 0x8(%r15)
movq 0x50(%r15), %rax
movq 0x40(%rsp), %r12
cmpq %rax, %r12
movq 0x8(%rsp), %r14
movq 0x20(%rsp), %r13
movq 0x18(%rsp), %rbp
jae 0x2ca2e
movq %r12, %rbx
movq 0x8(%r15), %rdi
movq 0x40(%r15), %rax
movq (%r14,%rbx,8), %rcx
movq %rbp, %rdx
movq %r13, %rsi
cmpq $-0x1, %rcx
je 0x2ca19
movq (%rax,%rcx,8), %r8
movq 0x8(%rax,%rcx,8), %rdx
leaq (%rdi,%r8), %rsi
subq %r8, %rdx
addq (%rax,%rbx,8), %rdi
callq 0x2160
incq %rbx
movq 0x50(%r15), %rax
cmpq %rax, %rbx
jb 0x2c9f1
movq 0x78(%r15), %rdi
imulq $0x18, %rax, %rsi
callq 0x2370
movq %rax, 0x78(%r15)
imulq $0x18, %r12, %rbx
leaq (%rax,%rbx), %rdi
movq 0x50(%r15), %r14
movq %r14, %rax
subq %r12, %rax
imulq $0x18, %rax, %rdx
xorl %esi, %esi
callq 0x20e0
movq 0x80(%r15), %rdi
imulq $0x18, %r14, %rsi
callq 0x2370
movq %rax, 0x80(%r15)
addq %rax, %rbx
movq 0x50(%r15), %r14
movq %r14, %rax
subq %r12, %rax
imulq $0x18, %rax, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
movq 0x28(%rsp), %rbx
movq %r14, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x2, %r14
movq %r14, %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movq (%rbx), %rdx
shlq $0x2, %rdx
movq %rax, %rdi
movl $0xff, %esi
callq 0x20e0
movq 0x38(%rsp), %rbx
movq 0x60(%rbx), %rdi
movq 0x30(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xa02e3
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, (%rbx)
movups 0x78(%r15), %xmm0
movups %xmm0, 0x8(%rbx)
movq 0x2684f0(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x21cfe7(%rip), %rsi    # 0x249ae1
leaq 0x21d728(%rip), %rdx    # 0x24a229
movq %r12, %rcx
movq 0x48(%rsp), %r8
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0