// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rsi, 0x70(%rsp)
movq %rdi, %r15
movq 0xe8(%rsp), %r13
movq 0xd8(%rsp), %rdi
movq 0x50(%r15), %r14
callq 0x2090
movq %rax, 0x38(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x32e2d
movq %rbx, 0x50(%r15)
movq 0x40(%r15), %rax
movq (%rax,%r14,8), %rax
movq %rax, 0x40(%rsp)
movq 0x269880(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x21e28d(%rip), %rsi    # 0x2499f7
leaq 0x21e2a8(%rip), %rdx    # 0x249a19
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 (%r12), %rdi
imulq $0xc, 0x50(%r15), %rsi
callq 0x2370
movq %r12, 0x28(%rsp)
movq %rax, (%r12)
movq 0x70(%r13), %rax
testq %rax, %rax
je 0x2b843
cmpq %r14, (%rax)
jne 0x2be82
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 0xf8(%rsp), %r12
movq 0x50(%r15), %rax
cmpq %rax, %r14
movq %r14, 0x68(%rsp)
jae 0x2bc17
imulq $0xc, %r14, %r13
imulq $0x18, %r14, %rax
movq %rax, 0x50(%rsp)
leaq (,%r14,8), %rax
movq %rax, 0x48(%rsp)
movq %r14, %rbp
movq 0x28(%rsp), %r11
movq 0x30(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq (%r15), %rax
andq $0x0, (%rax,%rbp,8)
movq 0x28(%r15), %rax
xorl %ecx, %ecx
movb %cl, (%rax,%rbp)
movq (%r11), %rax
andl $0x7fffffff, (%rax,%r13) # imm = 0x7FFFFFFF
movq (%r11), %rax
movb %cl, 0x8(%rax,%r13)
movq (%rdi,%rbp,8), %rbx
cmpq $-0x1, %rbx
je 0x2b91c
movq (%r15), %r14
movq (%r14,%rbx,8), %rcx
testq %rcx, %rcx
je 0x2b9aa
movq (%rcx), %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 0x30(%rsp), %rdi
movq (%rdi,%rbp,8), %rbx
movq 0x28(%rsp), %r11
movq (%r11), %rax
jmp 0x2b9af
movq 0xe0(%rsp), %rcx
movl 0x18(%rcx), %ecx
imulq $-0x18, %rcx, %r8
addq %r12, %r8
movl (%r8,%r13,2), %ecx
cmpq %rcx, %rbp
jne 0x2be63
movq 0xe8(%rsp), %rcx
movslq 0x44(%rcx), %rdx
movq 0xd0(%rsp), %rcx
leaq (%rcx,%rdx,2), %rcx
movl 0x4(%r8,%r13,2), %r10d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmpq %rdi, %r10
je 0x2ba61
movl 0x10(%r8,%r13,2), %edi
movl 0x14(%r8,%r13,2), %r8d
leaq (%r8,%rdx), %r9
movq 0x38(%rsp), %rbx
cmpq %rdi, %r9
jle 0x2ba66
addq %rdx, %rdx
addq %r8, %rdx
subq %rdi, %rdx
leaq 0x26a986(%rip), %rcx    # 0x296318
movq 0x10(%rcx), %rcx
shrl %r10d
shlq $0x4, %r10
movl 0x8(%rcx,%r10), %ebx
movq %rdx, %rcx
jmp 0x2ba66
movq 0x28(%rsp), %r11
movq 0x18(%r15), %rcx
movq (%rcx,%rbx,8), %rdx
movq %rdx, (%rcx,%rbp,8)
movq (%rdi,%rbp,8), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x20(%r15), %rdx
movq %rcx, (%rdx,%rbp,8)
imulq $0xc, (%rdi,%rbp,8), %rcx
movl (%rax,%rcx), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
movl (%rax,%r13), %edx
movl $0x80000000, %r8d       # imm = 0x80000000
andl %r8d, %edx
orl %ecx, %edx
movl %edx, (%rax,%r13)
movq (%r11), %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 (%r11), %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), %rax
movq 0x70(%rax), %rax
testq %rax, %rax
je 0x2ba57
movq 0x10(%rax), %rax
movb (%rax,%rcx), %cl
movq 0xf8(%rsp), %r12
jmp 0x2baba
movq 0xf8(%rsp), %r12
jmp 0x2babd
movq 0x38(%rsp), %rbx
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 (%r11), %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 0xe8(%rsp), %rax
movq 0x70(%rax), %rax
testq %rax, %rax
je 0x2babd
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 0x2bb20
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 0x2bbbc
movq 0xe0(%rsp), %rax
movl 0x18(%rax), %eax
imulq $-0x18, %rax, %r8
leaq (%r12,%r8), %rax
movl (%rax,%r13,2), %eax
cmpq %rax, %rbp
jne 0x2be25
movq 0x50(%rsp), %rax
addq %r12, %rax
addq %rax, %r8
movq 0x10(%r15), %rax
movq 0x18(%r15), %rcx
movq (%rax,%rbp,8), %rdi
movq (%r15), %rsi
addq 0x48(%rsp), %rsi
movq 0xe8(%rsp), %rax
movslq 0x44(%rax), %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 0x2214bb
cmpl $0x1, %eax
jne 0x2bbbc
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
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %r11
jb 0x2b893
jmp 0x2bc1f
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 0x2bd21
imulq $0x18, %rbp, %rax
leaq (%rax,%r12), %rbx
addq $0x14, %rbx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x26a6a6(%rip), %r12    # 0x296318
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 0x2bcb9
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 0x2bc75
jmp 0x2bd21
movq 0xe0(%rsp), %rax
movl 0x18(%rax), %eax
imulq $-0x18, %rax, %rcx
movl -0x14(%rbx,%rcx), %eax
cmpq %rax, %r13
jne 0x2be44
movl -0x10(%rbx,%rcx), %eax
movq 0x38(%rsp), %rdx
movq 0xd8(%rsp), %rsi
cmpq %r14, %rax
je 0x2bca2
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 0x2bca2
movq 0x10(%r12), %rcx
shrl %eax
shlq $0x4, %rax
movl 0x8(%rcx,%rax), %edx
movq (%rcx,%rax), %rsi
jmp 0x2bca2
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 0xa02e3
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq %rax, (%rbx)
movups 0x78(%r15), %xmm0
movups %xmm0, 0x8(%rbx)
leaq 0x78(%rsp), %rdi
callq 0x32d68
movq 0x2691ed(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x21dce4(%rip), %rsi    # 0x249ae1
leaq 0x21dc15(%rip), %rdx    # 0x249a19
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 0x21dca9(%rip), %rdi    # 0x249ad5
leaq 0x2197d6(%rip), %rsi    # 0x245609
leaq 0x21dc05(%rip), %rcx    # 0x249a3f
movl $0x3988, %edx           # imm = 0x3988
callq 0x2110
leaq 0x21dc8a(%rip), %rdi    # 0x249ad5
leaq 0x2197b7(%rip), %rsi    # 0x245609
leaq 0x21dbe6(%rip), %rcx    # 0x249a3f
movl $0x399a, %edx           # imm = 0x399A
callq 0x2110
leaq 0x21dc6b(%rip), %rdi    # 0x249ad5
leaq 0x219798(%rip), %rsi    # 0x245609
leaq 0x21dbc7(%rip), %rcx    # 0x249a3f
movl $0x3975, %edx           # imm = 0x3975
callq 0x2110
leaq 0x21dba0(%rip), %rdi    # 0x249a29
leaq 0x219779(%rip), %rsi    # 0x245609
leaq 0x21dba8(%rip), %rcx    # 0x249a3f
movl $0x3959, %edx           # imm = 0x3959
callq 0x2110