// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: renew_u2g_cov(ul_resolve_t*, telo_end_t*)
void renew_u2g_cov(ul_resolve_t *uidx, telo_end_t *te)
{
    ul2ul_idx_t *idx = &(uidx->uovl); uinfo_srt_warp_t *x;
    ma_ug_t *i_ug = idx->i_ug, *raw = uidx->l1_ug; uint64_t k, z, iug_occ, m, l, *a, a_n; 
    free(idx->cc.uc); free(idx->cc.hc); free(idx->cc.raw_uc); 
    free(idx->cc.iug_idx); free(idx->cc.iug_b); free(idx->cc.iug_a); 
    if(te) {
        free(idx->telo); idx->telo = NULL;
    }
    memset(&(idx->cc), 0, sizeof(idx->cc));

    MALLOC(idx->cc.uc, i_ug->u.n); ///number of ul (contained+non-contained)
    MALLOC(idx->cc.raw_uc, i_ug->u.n); ///number of ul (non-contained)
    MALLOC(idx->cc.hc, i_ug->u.n); ///number of HiFi reads
    if(te) MALLOC(idx->telo, i_ug->u.n); ///is telo

    kt_for(uidx->str_b.n_thread, worker_renew_u2g_cov, uidx, i_ug->u.n);

    CALLOC(idx->cc.iug_a, i_ug->u.n); ///integer sequence of each integer unitig
    CALLOC(idx->cc.iug_idx, raw->u.n+1); ///idx for integer sequences
    // fprintf(stderr, "malloc::[M::%s::] i_ug->u.n:%u\n", __func__, (uint32_t)i_ug->u.n);
    for (k = iug_occ = 0; k < i_ug->u.n; k++) {
        // fprintf(stderr, "-[M::%s::] k::%lu, i_ug->u.n:%u\n", __func__, k, (uint32_t)i_ug->u.n);
        gen_raw_ug_seq(uidx, uidx->pstr.str.a, &(i_ug->u.a[k]), raw, &(idx->cc.iug_a[k]), k);
        iug_occ += idx->cc.iug_a[k].n; x = &(idx->cc.iug_a[k]);
        for (z = 0; z < x->n; z++) idx->cc.iug_idx[x->a[z].v>>1]++;

        if(te) {
            idx->telo[k] = 0;
            for (z = 0; z < x->n; z++) {
                if(gen_utg_telo(&(raw->u.a[x->a[z].v>>1]), te)) break;
            }
            if(z < x->n) idx->telo[k] = 1;
        }
    }

    MALLOC(idx->cc.iug_b, iug_occ); ///idx for integer sequences
    for (k = l = 0; k < raw->u.n+1; k++) {
        m = idx->cc.iug_idx[k];
        idx->cc.iug_idx[k] = l;
        l += m;
        if(m > 0) idx->cc.iug_b[l-1] = 0;
    }
    assert(l == iug_occ);

    for (k = 0; k < i_ug->u.n; k++) {
        x = &(idx->cc.iug_a[k]);
        for (z = 0; z < x->n; z++) {
            a = idx->cc.iug_b + idx->cc.iug_idx[x->a[z].v>>1];
            a_n = idx->cc.iug_idx[(x->a[z].v>>1)+1] - idx->cc.iug_idx[x->a[z].v>>1];
            if(a_n) {
                if(a[a_n-1] == a_n-1) a[a_n-1] = (k<<32)|z;///id of unitig | offset within the unitig
                else a[a[a_n-1]++] = (k<<32)|z;
            }        
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x230(%rdi), %r14
movq 0x18(%rdi), %rax
movq %rax, 0x8(%rsp)
leaq 0x248(%rdi), %r12
movq 0x248(%rdi), %rdi
callq 0x2220
movq 0x250(%rbx), %rdi
callq 0x2220
movq 0x258(%rbx), %rdi
callq 0x2220
movq 0x268(%rbx), %rdi
callq 0x2220
movq 0x270(%rbx), %rdi
callq 0x2220
movq 0x260(%rbx), %rdi
callq 0x2220
testq %r15, %r15
je 0x1d925a
movq 0x2a8(%rbx), %rdi
callq 0x2220
andq $0x0, 0x2a8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%r12)
movups %xmm0, 0x10(%r12)
movups %xmm0, (%r12)
movq (%r14), %r12
leaq (,%r12,4), %r13
movq %r13, %rdi
callq 0x2280
movq %rax, 0x248(%rbx)
movq %r13, %rdi
callq 0x2280
movq %rax, 0x258(%rbx)
movq %r13, %rdi
callq 0x2280
movq %rax, 0x250(%rbx)
testq %r15, %r15
je 0x1d92ba
movq %r12, %rdi
callq 0x2280
movq %rax, 0x2a8(%rbx)
movl 0x1e0(%rbx), %edi
leaq 0x21d(%rip), %rsi       # 0x1d94e4
movq %rbx, %rdx
movq %r12, %rcx
callq 0xc67c0
movq (%r14), %r12
pushq $0x18
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x260(%rbx)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
incq %rdi
pushq $0x4
popq %rsi
callq 0x2120
movq %rax, 0x268(%rbx)
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r14, 0x10(%rsp)
cmpq %r12, %rbp
jae 0x1d93e3
movq %r13, 0x20(%rsp)
imulq $0x28, %rbp, %rdx
addq 0x10(%r14), %rdx
movq 0x1d0(%rbx), %rsi
imulq $0x18, %rbp, %r14
movq 0x260(%rbx), %r8
addq %r14, %r8
movq %rbx, %rdi
movq 0x8(%rsp), %rcx
callq 0x1d8c63
movq 0x260(%rbx), %rax
leaq (%rax,%r14), %r13
movq (%rax,%r14), %rcx
xorl %eax, %eax
movq %rcx, 0x18(%rsp)
subq $0x1, %rcx
jb 0x1d9378
movq 0x268(%rbx), %rdx
movq 0x10(%r13), %rsi
movl (%rsi,%rax), %esi
shrl %esi
incl (%rdx,%rsi,4)
addq $0x10, %rax
jmp 0x1d9359
testq %r15, %r15
je 0x1d93c9
movq 0x2a8(%rbx), %rax
movb $0x0, (%rax,%rbp)
movq (%r13), %r12
incq %r12
xorl %r14d, %r14d
decq %r12
je 0x1d93c9
movq 0x10(%r13), %rax
movl (%rax,%r14), %eax
addq $0x10, %r14
shrl %eax
imulq $0x28, %rax, %rdi
movq 0x8(%rsp), %rax
addq 0x10(%rax), %rdi
movq %r15, %rsi
callq 0x1d7892
testl %eax, %eax
je 0x1d9392
movq 0x2a8(%rbx), %rax
movb $0x1, (%rax,%rbp)
movq 0x20(%rsp), %r13
addq 0x18(%rsp), %r13
incq %rbp
movq 0x10(%rsp), %r14
movq (%r14), %r12
jmp 0x1d930b
leaq (,%r13,8), %rdi
callq 0x2280
movq %rax, 0x270(%rbx)
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
incq %rcx
xorl %esi, %esi
xorl %edx, %edx
cmpq %rcx, %rdx
jae 0x1d9431
movq 0x268(%rbx), %r8
movl (%r8,%rdx,4), %r9d
leaq (%rsi,%r9), %rdi
movl %esi, (%r8,%rdx,4)
testq %r9, %r9
je 0x1d9429
andq $0x0, -0x8(%rax,%rdi,8)
incq %rdx
movq %rdi, %rsi
jmp 0x1d9406
cmpq %r13, %rsi
jne 0x1d94c5
xorl %ecx, %ecx
cmpq %r12, %rcx
jae 0x1d94b6
imulq $0x18, %rcx, %rdx
addq 0x260(%rbx), %rdx
movq %rcx, %rsi
shlq $0x20, %rsi
xorl %edi, %edi
xorl %r8d, %r8d
cmpq (%rdx), %r8
jae 0x1d94b1
movq 0x268(%rbx), %r10
movq 0x10(%rdx), %r9
movl (%r9,%rdi), %r11d
shrl %r11d
movl (%r10,%r11,4), %r9d
movl 0x4(%r10,%r11,4), %r10d
subl %r9d, %r10d
je 0x1d94a8
leaq (%rax,%r9,8), %r11
leaq (%r11,%r10,8), %r9
addq $-0x8, %r9
decq %r10
movq (%r9), %r14
cmpq %r10, %r14
je 0x1d949f
leaq 0x1(%r14), %r10
movq %r10, (%r9)
leaq (%r11,%r14,8), %r9
movq %r8, %r10
orq %rsi, %r10
movq %r10, (%r9)
incq %r8
addq $0x10, %rdi
jmp 0x1d9458
incq %rcx
jmp 0x1d943c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x22c0b(%rip), %rdi     # 0x1fc0d7
leaq 0x1e006(%rip), %rsi     # 0x1f74d9
leaq 0x22c0a(%rip), %rcx     # 0x1fc0e4
movl $0x40db, %edx           # imm = 0x40DB
callq 0x2110