// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: realloc_rdb_adv(All_reads*, all_ul_t*, ma_sub_t**, R_to_U*, unsigned long*, unsigned long, unsigned long, char*, asg_t*, ug_opt_t*, ma_ug_t*, usc_t*)
void realloc_rdb_adv(All_reads* rdb, all_ul_t *x, 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, ma_ug_t *raw_g, usc_t *a)
{
    uint64_t i, rid_n0 = rdb->total_reads, tname, cname; usc_t *z; 
    uint64_t scaf_id_len = strlen(scaf_id); char *des, *src; int64_t nlen, ff;
    UC_Read g_read; init_UC_Read(&g_read);
    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);
    if(uopt->te) {
        assert(uopt->te->n == rid_n0);
        uopt->te->n = rdb->total_reads;
        REALLOC(uopt->te->hh, 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->trio_flag[i] = AMBIGU;
        (*cov)[i].c = (*cov)[i].del = 0; 
        // rdb->read_length[i] = scaf_len;
        // rdb->read_size[i] = scaf_len;
        // (*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]];
            (*cov)[i].s = (*cov)[rmap[i]].s; 
            (*cov)[i].e = (*cov)[rmap[i]].e;
            rdb->trio_flag[i] = rdb->trio_flag[rmap[i]];
            (*cov)[i] = (*cov)[rmap[i]];
            cname = Get_NAME_LENGTH((*rdb), (rmap[i]));
            if(uopt->te) uopt->te->hh[i] = uopt->te->hh[rmap[i]];
        } else {
            z = &(a[(i-ng->r_seq)]); assert(z->nid == i); cname = scaf_id_len;
            if(reset_scaf_node_uinfo_srt_t(z, uopt->min_ovlp, scaf_len, &nlen) == 2) {
                cname = UL_INF.nid.a[z->ulid>>1].n;///ul name length
            }
            rdb->read_length[i] = nlen;
            rdb->read_size[i] = nlen;
            (*cov)[i].s = 0; (*cov)[i].e = nlen;
            ng->seq[i].len = nlen;///update length for the scaffold node
            if(uopt->te) uopt->te->hh[i] = 0;
        } 
        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
            z = &(a[(i-ng->r_seq)]); assert(z->nid == i);
            ff = push_scaf_bases(rdb->read_sperate[i], &(rdb->N_site[i]), rdb, x, z, uopt->min_ovlp, scaf_len, rdb->read_length[i], &g_read, rmap, raw_g);
            if(ff == 1) ng->seq[i].del = 1;///could directly reuse HiFi; no need new node
            // memset(rdb->read_sperate[i], 0, sizeof((*(rdb->read_sperate[i])))*(rdb->read_length[i]/4+1));
        }
        ng->seq[i].len = rdb->read_length[i];
    }

    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++) {///only need to update names for new reads
        des = Get_NAME((*rdb), i); 
        if(rmap[i] != ((uint64_t)-1)) {
            src = Get_NAME((*rdb), rmap[i]); cname = Get_NAME_LENGTH((*rdb), (rmap[i]));
        } else {
            z = &(a[(i-ng->r_seq)]); assert(z->nid == i);
            if(reset_scaf_node_uinfo_srt_t(z, uopt->min_ovlp, scaf_len, &nlen) == 2) {
                cname = UL_INF.nid.a[z->ulid>>1].n;///ul name length
                src = UL_INF.nid.a[z->ulid>>1].a;
            } else {
                src = scaf_id; cname = scaf_id_len;
            }
            // assert(nlen == (int64_t)cname);
        }
        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;
    destory_UC_Read(&g_read);
    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 $0xa8, %rsp
movq %r9, %rbx
movq %r8, 0x40(%rsp)
movq %rcx, %r13
movq %rdx, %r14
movq %rsi, 0x80(%rsp)
movq %rdi, %r15
movq 0xf8(%rsp), %r12
movq 0xe8(%rsp), %rdi
movq 0x50(%r15), %rbp
callq 0x2090
movq %rax, 0x58(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x6bd1
movq %rbx, 0x50(%r15)
movq 0x40(%r15), %rax
movq (%rax,%rbp,8), %rax
movq %rax, 0x50(%rsp)
movq 0x807cb(%rip), %rax     # 0x252fe0
movq (%rax), %rdi
leaq 0x29197(%rip), %rsi     # 0x1fb9b6
leaq 0x291b2(%rip), %rdx     # 0x1fb9d8
movq %rbp, %rcx
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 (%r14), %rdi
imulq $0xc, 0x50(%r15), %rsi
callq 0x2370
movq %rax, (%r14)
movq 0x70(%r12), %rax
testq %rax, %rax
je 0x1d28f2
cmpq %rbp, (%rax)
jne 0x1d2f15
movq 0x50(%r15), %rsi
movq %rsi, (%rax)
movq 0x10(%rax), %rdi
callq 0x2370
movq 0xf8(%rsp), %rcx
movq 0x70(%rcx), %rcx
movq %rax, 0x10(%rcx)
movq %r13, 0x70(%rsp)
movq %rbx, 0x78(%rsp)
imulq $0xc, %rbp, %r13
leaq (,%rbp,8), %rax
movq %rax, 0x60(%rsp)
imulq $0x18, %rbp, %rdx
movq %rbp, %r12
movq %rbp, 0x48(%rsp)
movq %r14, 0x30(%rsp)
movq 0x50(%r15), %rax
cmpq %rax, %r12
movq 0x40(%rsp), %rdi
jae 0x1d2cae
movq (%r15), %rax
andq $0x0, (%rax,%r12,8)
movq 0x28(%r15), %rax
xorl %ecx, %ecx
movb %cl, (%rax,%r12)
movq (%r14), %rax
andl $0x7fffffff, (%rax,%r13) # imm = 0x7FFFFFFF
movq (%r14), %r14
movb %cl, 0x8(%r14,%r13)
movq (%rdi,%r12,8), %rbx
cmpq $-0x1, %rbx
movq %rdx, 0x38(%rsp)
je 0x1d29bb
movq (%r15), %rbp
movq (%rbp,%rbx,8), %rax
testq %rax, %rax
je 0x1d2a99
movq (%rax), %rax
leaq 0x8(,%rax,8), %rdi
callq 0x2280
movq %rax, (%rbp,%r12,8)
movq (%r15), %rax
movq (%rax,%r12,8), %rdi
movq (%rax,%rbx,8), %rsi
movq (%rsi), %rax
leaq 0x8(,%rax,8), %rdx
callq 0x2160
movq 0x40(%rsp), %rdi
movq (%rdi,%r12,8), %rbx
movq 0x30(%rsp), %rsi
movq (%rsi), %r14
jmp 0x1d2a9e
movq 0xf0(%rsp), %rax
movl 0x18(%rax), %eax
imulq $-0x18, %rax, %rdi
movq 0x108(%rsp), %rcx
leaq (%rcx,%rdi), %rbp
movl (%rbp,%r13,2), %eax
cmpq %rax, %r12
jne 0x1d2eb8
addq %rcx, %rdi
addq %rdx, %rdi
movq 0xf8(%rsp), %rax
movslq 0x44(%rax), %rsi
movq 0xe0(%rsp), %rdx
leaq 0x68(%rsp), %rcx
callq 0x1d223d
movq 0x58(%rsp), %rbx
cmpl $0x2, %eax
jne 0x1d2a2c
leaq 0x818ff(%rip), %rax     # 0x254318
movq 0x10(%rax), %rax
movl 0x4(%rbp,%r13,2), %ecx
shrl %ecx
shlq $0x4, %rcx
movl 0x8(%rax,%rcx), %ebx
movq 0x68(%rsp), %rax
movq 0x18(%r15), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x20(%r15), %rcx
movq %rax, (%rcx,%r12,8)
movl $0x80000000, %esi       # imm = 0x80000000
andl %esi, (%r14,%r13)
movq 0x30(%rsp), %r14
movq (%r14), %rcx
movl %eax, 0x4(%rcx,%r13)
movq 0xf0(%rsp), %rcx
movq 0x20(%rcx), %rcx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl (%rcx,%r12,8), %edx
andl %esi, %edx
orl %eax, %edx
movl %edx, (%rcx,%r12,8)
movq 0xf8(%rsp), %rax
movq 0x70(%rax), %rax
testq %rax, %rax
je 0x1d2ca4
movq 0x10(%rax), %rax
xorl %ecx, %ecx
movq 0x48(%rsp), %rbp
jmp 0x1d2b44
movq 0x30(%rsp), %rsi
movq 0x18(%r15), %rax
movq (%rax,%rbx,8), %rcx
movq %rcx, (%rax,%r12,8)
movq (%rdi,%r12,8), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%r15), %rcx
movq %rax, (%rcx,%r12,8)
imulq $0xc, (%rdi,%r12,8), %rax
movl (%r14,%rax), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movl (%r14,%r13), %ecx
movl $0x80000000, %edx       # imm = 0x80000000
andl %edx, %ecx
orl %eax, %ecx
movl %ecx, (%r14,%r13)
movq (%rsi), %rax
movq (%rdi,%r12,8), %rcx
imulq $0xc, %rcx, %rdx
movl 0x4(%rax,%rdx), %edx
movl %edx, 0x4(%rax,%r13)
movq 0x28(%r15), %rax
movb (%rax,%rcx), %cl
movb %cl, (%rax,%r12)
imulq $0xc, (%rdi,%r12,8), %rax
movq (%rsi), %rcx
movl 0x8(%rcx,%rax), %edx
movl %edx, 0x8(%rcx,%r13)
movq (%rcx,%rax), %rax
movq %rax, (%rcx,%r13)
movq 0x40(%r15), %rax
movq (%rdi,%r12,8), %rcx
movq 0x8(%rax,%rcx,8), %rbx
subq (%rax,%rcx,8), %rbx
movq 0xf8(%rsp), %rax
movq 0x70(%rax), %rax
testq %rax, %rax
movq 0x48(%rsp), %rbp
movq %rsi, %r14
je 0x1d2b48
movq 0x10(%rax), %rax
movb (%rax,%rcx), %cl
movb %cl, (%rax,%r12)
movq 0x40(%r15), %rax
movq 0x50(%rsp), %rcx
movq %rcx, (%rax,%r12,8)
movq 0x18(%r15), %rax
movq (%rax,%r12,8), %rcx
addq %rcx, 0x58(%r15)
movq (%rax,%r12,8), %rdi
shrq $0x2, %rdi
incq %rdi
callq 0x2280
movq 0x10(%r15), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x40(%rsp), %rax
movq (%rax,%r12,8), %rax
cmpq $-0x1, %rax
je 0x1d2bad
movq 0x10(%r15), %rcx
movq 0x18(%r15), %rdx
movq (%rcx,%r12,8), %rdi
movq (%rcx,%rax,8), %rsi
movq (%rdx,%r12,8), %rdx
shrq $0x2, %rdx
incq %rdx
callq 0x2160
jmp 0x1d2c58
movq 0xf0(%rsp), %rax
movl 0x18(%rax), %eax
imulq $-0x18, %rax, %r8
movq 0x108(%rsp), %rcx
leaq (%rcx,%r8), %rax
movl (%rax,%r13,2), %eax
cmpq %rax, %r12
jne 0x1d2ed7
movq 0x38(%rsp), %rax
addq %rcx, %rax
addq %rax, %r8
movq 0x10(%r15), %rax
movq 0x18(%r15), %rcx
movq (%rax,%r12,8), %rdi
movq (%r15), %rsi
addq 0x60(%rsp), %rsi
movq 0xf8(%rsp), %rax
movslq 0x44(%rax), %r9
movq (%rcx,%r12,8), %rax
movq 0x100(%rsp), %rcx
movq %rcx, 0x20(%rsp)
leaq 0x88(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdx
movq 0x80(%rsp), %rcx
callq 0x1d24ac
cmpl $0x1, %eax
jne 0x1d2c58
movq 0xf0(%rsp), %rax
movq 0x20(%rax), %rax
orl $0x80000000, (%rax,%r12,8) # imm = 0x80000000
addq %rbx, 0x50(%rsp)
movq 0x18(%r15), %rax
movq 0xf0(%rsp), %rcx
movq 0x20(%rcx), %rcx
movl (%rax,%r12,8), %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %eax
movl (%rcx,%r12,8), %edx
movl $0x80000000, %esi       # imm = 0x80000000
andl %esi, %edx
orl %eax, %edx
movl %edx, (%rcx,%r12,8)
incq %r12
addq $0xc, %r13
addq $0x8, 0x60(%rsp)
movq 0x38(%rsp), %rdx
addq $0x18, %rdx
jmp 0x1d291e
movq 0x48(%rsp), %rbp
jmp 0x1d2b48
movq %rax, 0x38(%r15)
movq 0x40(%r15), %rax
movq 0x50(%rsp), %rsi
movq %rsi, (%rax,%r12,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)
imulq $0x18, %rbp, %rax
movq 0x108(%rsp), %rbx
movq %rax, 0x38(%rsp)
addq %rax, %rbx
movq %rbp, %r14
movq 0x50(%r15), %rax
cmpq %rax, %r14
movq 0x40(%rsp), %rcx
jae 0x1d2db0
movq 0x8(%r15), %rsi
movq 0x40(%r15), %rax
movq (%rax,%r14,8), %r13
addq %rsi, %r13
movq (%rcx,%r14,8), %rcx
cmpq $-0x1, %rcx
je 0x1d2d2e
movq (%rax,%rcx,8), %rdi
movq 0x8(%rax,%rcx,8), %rdx
addq %rdi, %rsi
subq %rdi, %rdx
jmp 0x1d2d9c
movq 0xf0(%rsp), %rax
movl 0x18(%rax), %eax
imulq $-0x18, %rax, %r12
movl (%rbx,%r12), %eax
cmpq %rax, %r14
jne 0x1d2ef6
leaq (%rbx,%r12), %rdi
movq 0xf8(%rsp), %rax
movslq 0x44(%rax), %rsi
movq 0xe0(%rsp), %rdx
leaq 0x68(%rsp), %rcx
callq 0x1d223d
movq 0x58(%rsp), %rdx
movq 0xe8(%rsp), %rsi
cmpl $0x2, %eax
jne 0x1d2d9c
leaq 0x81593(%rip), %rax     # 0x254318
movq 0x10(%rax), %rax
movl 0x4(%rbx,%r12), %ecx
shrl %ecx
shlq $0x4, %rcx
movl 0x8(%rax,%rcx), %edx
movq (%rax,%rcx), %rsi
movq %r13, %rdi
callq 0x2160
incq %r14
addq $0x18, %rbx
jmp 0x1d2cf2
movq 0x78(%r15), %rdi
imulq $0x18, %rax, %rsi
callq 0x2370
movq %rax, 0x78(%r15)
movq 0x38(%rsp), %r14
leaq (%rax,%r14), %rdi
movq 0x50(%r15), %rbx
movq %rbx, %rax
subq %rbp, %rax
imulq $0x18, %rax, %rdx
xorl %esi, %esi
callq 0x20e0
movq 0x80(%r15), %rdi
imulq $0x18, %rbx, %rsi
callq 0x2370
movq %rax, 0x80(%r15)
addq %rax, %r14
movq 0x50(%r15), %rbx
movq %rbx, %rax
subq %rbp, %rax
imulq $0x18, %rax, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x20e0
movq 0x70(%rsp), %r14
movq %rbx, (%r14)
movq 0x8(%r14), %rdi
shlq $0x2, %rbx
movq %rbx, %rsi
callq 0x2370
movq %rax, 0x8(%r14)
movq (%r14), %rdx
shlq $0x2, %rdx
movq %rax, %rdi
movl $0xff, %esi
callq 0x20e0
movq 0xf8(%rsp), %rbx
movq 0x60(%rbx), %rdi
movq 0xf0(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x68def
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq %rax, (%rbx)
movups 0x78(%r15), %xmm0
movups %xmm0, 0x8(%rbx)
leaq 0x88(%rsp), %rdi
callq 0x6b07
movq 0x8015a(%rip), %rax     # 0x252fe0
movq (%rax), %rdi
leaq 0x28c10(%rip), %rsi     # 0x1fbaa0
leaq 0x28b41(%rip), %rdx     # 0x1fb9d8
movq %rbp, %rcx
movq 0x78(%rsp), %r8
xorl %eax, %eax
callq 0x22b0
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28bd5(%rip), %rdi     # 0x1fba94
leaq 0x24613(%rip), %rsi     # 0x1f74d9
leaq 0x28b31(%rip), %rcx     # 0x1fb9fe
movl $0x3975, %edx           # imm = 0x3975
callq 0x2110
leaq 0x28bb6(%rip), %rdi     # 0x1fba94
leaq 0x245f4(%rip), %rsi     # 0x1f74d9
leaq 0x28b12(%rip), %rcx     # 0x1fb9fe
movl $0x3988, %edx           # imm = 0x3988
callq 0x2110
leaq 0x28b97(%rip), %rdi     # 0x1fba94
leaq 0x245d5(%rip), %rsi     # 0x1f74d9
leaq 0x28af3(%rip), %rcx     # 0x1fb9fe
movl $0x399a, %edx           # imm = 0x399A
callq 0x2110
leaq 0x28acc(%rip), %rdi     # 0x1fb9e8
leaq 0x245b6(%rip), %rsi     # 0x1f74d9
leaq 0x28ad4(%rip), %rcx     # 0x1fb9fe
movl $0x3959, %edx           # imm = 0x3959
callq 0x2110