// File: /workspace/github_cpp_makefile_star2_O2/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, %r13
movq %rdx, 0x28(%rsp)
movq %rsi, %r14
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, 0x10(%rsp)
movq %rbx, 0x50(%r15)
movq 0x40(%r15), %rax
movq (%rax,%rbp,8), %r12
movq 0x78460(%rip), %rax     # 0x252fe0
movq (%rax), %rdi
leaq 0x20e2c(%rip), %rsi     # 0x1fb9b6
leaq 0x21657(%rip), %rdx     # 0x1fc1e8
movq %rbp, %rcx
movq %rbx, 0x48(%rsp)
movq %rbx, %r8
movq %r14, %rbx
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 (%r14), %rdi
imulq $0xc, 0x50(%r15), %rsi
callq 0x2370
movq %r12, %rsi
movq %rax, (%r14)
imulq $0xc, %rbp, %r12
movq %rbp, 0x40(%rsp)
movq %r14, 0x8(%rsp)
movq %r13, 0x18(%rsp)
movq 0x50(%r15), %rax
cmpq %rax, %rbp
jae 0x1dadea
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 %edx, %edx
movb %dl, (%rax,%rbp)
movq (%rbx), %rax
andl $0x7fffffff, (%rax,%r12) # imm = 0x7FFFFFFF
movq (%rbx), %rax
movb %dl, 0x8(%rax,%r12)
andl $0x80000000, (%rax,%r12) # imm = 0x80000000
movq (%rbx), %rax
movl %ecx, 0x4(%rax,%r12)
movq (%r13,%rbp,8), %r14
cmpq $-0x1, %r14
je 0x1dad57
movq (%r15), %rbx
movq (%rbx,%r14,8), %rax
testq %rax, %rax
je 0x1dacf8
movq (%rax), %rax
leaq 0x8(,%rax,8), %rdi
movq %rsi, %r13
callq 0x2280
movq %rax, (%rbx,%rbp,8)
movq (%r15), %rax
movq (%rax,%rbp,8), %rdi
movq (%rax,%r14,8), %rsi
movq (%rsi), %rax
leaq 0x8(,%rax,8), %rdx
callq 0x2160
movq %r13, %rsi
movq 0x18(%rsp), %r13
movq (%r13,%rbp,8), %r14
movq 0x18(%r15), %rax
movq (%rax,%r14,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 0x8(%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), %r14
subq (%rax,%rcx,8), %r14
jmp 0x1dad60
movq 0x40(%r15), %rax
movq 0x10(%rsp), %r14
movq %rsi, %rbx
movq %rsi, (%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 0x1dadb8
movq (%rcx,%rax,8), %rsi
movq 0x18(%r15), %rax
movq (%rax,%rbp,8), %rdx
shrq $0x2, %rdx
incq %rdx
callq 0x2160
jmp 0x1dadce
movq 0x18(%r15), %rax
movq (%rax,%rbp,8), %rdx
shrq $0x2, %rdx
incq %rdx
xorl %esi, %esi
callq 0x20e0
movq %rbx, %rsi
addq %r14, %rsi
incq %rbp
addq $0xc, %r12
movq 0x18(%rsp), %r13
movq 0x8(%rsp), %rbx
jmp 0x1dac48
movq %rax, 0x38(%r15)
movq 0x40(%r15), %rax
movq %rsi, (%rax,%rbp,8)
movq %rsi, 0x60(%r15)
movq 0x8(%r15), %rdi
movq 0x50(%r15), %rax
incq %rax
movq %rax, 0x48(%r15)
callq 0x2370
movq %rax, 0x8(%r15)
movq 0x40(%rsp), %r12
movq %r12, %rbx
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %rbp
movq 0x50(%r15), %rax
cmpq %rax, %rbx
jae 0x1dae64
movq 0x8(%r15), %rdi
movq 0x40(%r15), %rax
movq (%r13,%rbx,8), %rcx
movq %rbp, %rdx
movq %r14, %rsi
cmpq $-0x1, %rcx
je 0x1dae56
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
jmp 0x1dae24
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 0x68def
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, (%rbx)
movups 0x78(%r15), %xmm0
movups %xmm0, 0x8(%rbx)
movq 0x780ba(%rip), %rax     # 0x252fe0
movq (%rax), %rdi
leaq 0x20b70(%rip), %rsi     # 0x1fbaa0
leaq 0x212b1(%rip), %rdx     # 0x1fc1e8
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