// File: /workspace/github_cpp_makefile_star2_O1/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 $0x98, %rsp
movq %r9, %rbx
movq %r8, 0x30(%rsp)
movq %rcx, %rbp
movq %rdx, %r13
movq %rsi, 0x70(%rsp)
movq %rdi, %r15
movq 0xe8(%rsp), %r12
movq 0xd8(%rsp), %rdi
movq 0x50(%r15), %r14
callq 0x2090
movq %rax, 0x38(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x3372c
movq %rbx, 0x50(%r15)
movq 0x40(%r15), %rax
movq (%rax,%r14,8), %rax
movq %rax, 0x40(%rsp)
movq 0x25de07(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x211530(%rip), %rsi    # 0x23d713
leaq 0x21154b(%rip), %rdx    # 0x23d735
movq %r14, %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 (%r13), %rdi
imulq $0xc, 0x50(%r15), %rsi
callq 0x2370
movq %r13, 0x28(%rsp)
movq %rax, (%r13)
movq 0x70(%r12), %rax
testq %rax, %rax
je 0x2c2bd
cmpq %r14, (%rax)
jne 0x2c8ef
movq 0x50(%r15), %rsi
movq %rsi, (%rax)
movq 0x10(%rax), %rdi
callq 0x2370
movq 0xe8(%rsp), %rcx
movq 0x70(%rcx), %rcx
movq %rax, 0x10(%rcx)
movq %rbp, 0x58(%rsp)
movq %rbx, 0x60(%rsp)
movq 0x50(%r15), %rax
cmpq %rax, %r14
movq %r14, 0x68(%rsp)
jae 0x2c672
imulq $0xc, %r14, %r13
imulq $0x18, %r14, %rax
movq %rax, 0x50(%rsp)
leaq (,%r14,8), %rax
movq %rax, 0x48(%rsp)
movq %r14, %rbp
movq 0xe8(%rsp), %r12
movq 0x40(%rsp), %rsi
movq (%r15), %rax
andq $0x0, (%rax,%rbp,8)
movq 0x28(%r15), %rax
xorl %edx, %edx
movb %dl, (%rax,%rbp)
movq 0x28(%rsp), %rcx
movq (%rcx), %rax
andl $0x7fffffff, (%rax,%r13) # imm = 0x7FFFFFFF
movq (%rcx), %rax
movb %dl, 0x8(%rax,%r13)
movq 0x30(%rsp), %rcx
movq (%rcx,%rbp,8), %rbx
cmpq $-0x1, %rbx
je 0x2c43b
movq (%r15), %r14
movq (%r14,%rbx,8), %rax
testq %rax, %rax
je 0x2c380
movq (%rax), %rax
leaq 0x8(,%rax,8), %rdi
movq %rsi, %r12
callq 0x2280
movq %rax, (%r14,%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 %r12, %rsi
movq 0x18(%r15), %rax
movq 0x30(%rsp), %rdi
movq (%rdi,%rbp,8), %rcx
movq (%rax,%rcx,8), %rcx
movq %rcx, (%rax,%rbp,8)
movq (%rdi,%rbp,8), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%r15), %rcx
movq %rax, (%rcx,%rbp,8)
movq 0x28(%rsp), %r8
movq (%r8), %rax
imulq $0xc, (%rdi,%rbp,8), %rcx
movl (%rax,%rcx), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
movl (%rax,%r13), %edx
movl $0x80000000, %r9d       # imm = 0x80000000
andl %r9d, %edx
orl %ecx, %edx
movl %edx, (%rax,%r13)
movq (%r8), %rax
movq (%rdi,%rbp,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,%rbp)
imulq $0xc, (%rdi,%rbp,8), %rax
movq (%r8), %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,%rbp,8), %rcx
movq 0x8(%rax,%rcx,8), %rbx
subq (%rax,%rcx,8), %rbx
movq 0xe8(%rsp), %r14
movq %r14, %r12
movq 0x70(%r14), %rax
testq %rax, %rax
je 0x2c51a
movq 0x10(%rax), %rax
movb (%rax,%rcx), %cl
jmp 0x2c517
movq 0xe0(%rsp), %rcx
movl 0x18(%rcx), %ecx
imulq $-0x18, %rcx, %rdi
addq 0xf8(%rsp), %rdi
movl (%rdi,%r13,2), %ecx
cmpq %rcx, %rbp
jne 0x2c8d0
movslq 0x44(%r12), %r10
movq 0xd0(%rsp), %rcx
leaq (%rcx,%r10,2), %rcx
movl 0x4(%rdi,%r13,2), %edx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpq %r8, %rdx
je 0x2c4a4
movl 0x10(%rdi,%r13,2), %r8d
movl 0x14(%rdi,%r13,2), %edi
leaq (%rdi,%r10), %r9
cmpq %r8, %r9
jle 0x2c4a4
addq %r10, %r10
addq %rdi, %r10
subq %r8, %r10
movb $0x1, %dil
movq %r10, %rcx
jmp 0x2c4a6
xorl %edi, %edi
movq 0x38(%rsp), %rbx
testb %dil, %dil
je 0x2c4c5
leaq 0x25ee61(%rip), %rdi    # 0x28b318
movq 0x10(%rdi), %rdi
shrl %edx
shlq $0x4, %rdx
movl 0x8(%rdi,%rdx), %ebx
movq 0x18(%r15), %rdx
movq %rcx, (%rdx,%rbp,8)
movq 0x20(%r15), %rdx
movq %rcx, (%rdx,%rbp,8)
movl $0x80000000, %edi       # imm = 0x80000000
andl %edi, (%rax,%r13)
movq 0x28(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x4(%rax,%r13)
movq 0xe0(%rsp), %rax
movq 0x20(%rax), %rax
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl (%rax,%rbp,8), %edx
andl %edi, %edx
orl %ecx, %edx
movl %edx, (%rax,%rbp,8)
movq 0x70(%r12), %rax
testq %rax, %rax
je 0x2c51a
movq 0x10(%rax), %rax
xorl %ecx, %ecx
movb %cl, (%rax,%rbp)
movq 0x40(%r15), %rax
movq %rsi, %r14
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 0x30(%rsp), %rax
movq (%rax,%rbp,8), %rax
cmpq $-0x1, %rax
je 0x2c57d
movq 0x10(%r15), %rcx
movq 0x18(%r15), %rdx
movq (%rcx,%rbp,8), %rdi
movq (%rcx,%rax,8), %rsi
movq (%rdx,%rbp,8), %rdx
shrq $0x2, %rdx
incq %rdx
callq 0x2160
jmp 0x2c621
movq 0xe0(%rsp), %rax
movl 0x18(%rax), %eax
imulq $-0x18, %rax, %r8
movq 0xf8(%rsp), %rax
addq %r8, %rax
movl (%rax,%r13,2), %eax
cmpq %rax, %rbp
jne 0x2c892
movq 0x50(%rsp), %rax
movq 0xf8(%rsp), %rcx
addq %rcx, %rax
addq %rax, %r8
movq 0x10(%r15), %rax
movq 0x18(%r15), %rcx
movq (%rax,%rbp,8), %rdi
movq (%r15), %rsi
addq 0x48(%rsp), %rsi
movslq 0x44(%r12), %r9
movq (%rcx,%rbp,8), %rax
movq 0xf0(%rsp), %rcx
movq %rcx, 0x20(%rsp)
leaq 0x78(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdx
movq 0x70(%rsp), %rcx
callq 0x2160c6
cmpl $0x1, %eax
jne 0x2c621
movq 0xe0(%rsp), %rax
movq 0x20(%rax), %rax
orl $0x80000000, (%rax,%rbp,8) # imm = 0x80000000
movq %r14, %rsi
addq %rbx, %rsi
movq 0x18(%r15), %rax
movq 0xe0(%rsp), %rcx
movq 0x20(%rcx), %rcx
movl (%rax,%rbp,8), %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %eax
movl (%rcx,%rbp,8), %edx
movl $0x80000000, %edi       # imm = 0x80000000
andl %edi, %edx
orl %eax, %edx
movl %edx, (%rcx,%rbp,8)
incq %rbp
movq 0x50(%r15), %rax
addq $0xc, %r13
addq $0x18, 0x50(%rsp)
addq $0x8, 0x48(%rsp)
cmpq %rax, %rbp
jb 0x2c303
jmp 0x2c67a
movq %r14, %rbp
movq 0x40(%rsp), %rsi
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 0x50(%r15), %rax
movq 0x68(%rsp), %rbp
cmpq %rax, %rbp
jae 0x2c784
imulq $0x18, %rbp, %rax
movq 0xf8(%rsp), %rcx
leaq (%rax,%rcx), %rbx
addq $0x14, %rbx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x25ec43(%rip), %r12    # 0x28b318
movq %rbp, %r13
movq 0x8(%r15), %rsi
movq 0x40(%r15), %rax
movq (%rax,%r13,8), %rdi
addq %rsi, %rdi
movq 0x30(%rsp), %rcx
movq (%rcx,%r13,8), %rcx
cmpq $-0x1, %rcx
je 0x2c71c
movq (%rax,%rcx,8), %r8
movq 0x8(%rax,%rcx,8), %rdx
addq %r8, %rsi
subq %r8, %rdx
callq 0x2160
incq %r13
movq 0x50(%r15), %rax
addq $0x18, %rbx
cmpq %rax, %r13
jb 0x2c6d8
jmp 0x2c784
movq 0xe0(%rsp), %rax
movl 0x18(%rax), %eax
imulq $-0x18, %rax, %rcx
movl -0x14(%rbx,%rcx), %eax
cmpq %rax, %r13
jne 0x2c8b1
movl -0x10(%rbx,%rcx), %eax
movq 0x38(%rsp), %rdx
movq 0xd8(%rsp), %rsi
cmpq %r14, %rax
je 0x2c705
movq 0xe8(%rsp), %rdx
movslq 0x44(%rdx), %rdx
movl -0x4(%rbx,%rcx), %r8d
movl (%rbx,%rcx), %ecx
addq %rdx, %rcx
movq 0x38(%rsp), %rdx
cmpq %r8, %rcx
jle 0x2c705
movq 0x10(%r12), %rcx
shrl %eax
shlq $0x4, %rax
movl 0x8(%rcx,%rax), %edx
movq (%rcx,%rax), %rsi
jmp 0x2c705
movq 0x78(%r15), %rdi
imulq $0x18, %rax, %rsi
callq 0x2370
movq %rax, 0x78(%r15)
imulq $0x18, %rbp, %rbx
leaq (%rax,%rbx), %rdi
movq 0x50(%r15), %r14
movq %r14, %rax
subq %rbp, %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), %r13
movq %r13, %rax
subq %rbp, %rax
imulq $0x18, %rax, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
movq 0x58(%rsp), %rbx
movq %r13, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x2, %r13
movq %r13, %rsi
callq 0x2370
movq %rax, 0x8(%rbx)
movq (%rbx), %rdx
shlq $0x2, %rdx
movq %rax, %rdi
movl $0xff, %esi
callq 0x20e0
movq 0xe8(%rsp), %rbx
movq 0x60(%rbx), %rdi
movq 0xe0(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x9fb31
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq %rax, (%rbx)
movq 0x80(%r15), %rax
movq %rax, 0x10(%rbx)
movq 0x78(%r15), %rax
movq %rax, 0x8(%rbx)
leaq 0x78(%rsp), %rdi
callq 0x33667
movq 0x25d780(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x210f93(%rip), %rsi    # 0x23d7fd
leaq 0x210ec4(%rip), %rdx    # 0x23d735
movq %rbp, %rcx
movq 0x60(%rsp), %r8
xorl %eax, %eax
callq 0x22b0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x210f58(%rip), %rdi    # 0x23d7f1
leaq 0x20ca85(%rip), %rsi    # 0x239325
leaq 0x210eb4(%rip), %rcx    # 0x23d75b
movl $0x3988, %edx           # imm = 0x3988
callq 0x2110
leaq 0x210f39(%rip), %rdi    # 0x23d7f1
leaq 0x20ca66(%rip), %rsi    # 0x239325
leaq 0x210e95(%rip), %rcx    # 0x23d75b
movl $0x399a, %edx           # imm = 0x399A
callq 0x2110
leaq 0x210f1a(%rip), %rdi    # 0x23d7f1
leaq 0x20ca47(%rip), %rsi    # 0x239325
leaq 0x210e76(%rip), %rcx    # 0x23d75b
movl $0x3975, %edx           # imm = 0x3975
callq 0x2110
leaq 0x210e4f(%rip), %rdi    # 0x23d745
leaq 0x20ca28(%rip), %rsi    # 0x239325
leaq 0x210e57(%rip), %rcx    # 0x23d75b
movl $0x3959, %edx           # imm = 0x3959
callq 0x2110