// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
addq $0x1f0, %rax            # imm = 0x1F0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rdi
callq 0x2210
cmpq $0x0, -0x10(%rbp)
je 0x3728ad
movq -0x18(%rbp), %rax
movq 0xb8(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
movq $0x0, 0xb8(%rax)
movq -0x18(%rbp), %rdi
addq $0x58, %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2100
movq -0x28(%rbp), %rax
movq (%rax), %rdi
shlq $0x2, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
shlq $0x2, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
shlq $0x2, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x60(%rax)
cmpq $0x0, -0x10(%rbp)
je 0x372937
movq -0x28(%rbp), %rax
movq (%rax), %rdi
shlq $0x0, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0xb8(%rax)
movq -0x8(%rbp), %rax
movq 0x1e0(%rax), %rax
movl %eax, %edi
movq -0x8(%rbp), %rdx
movq -0x28(%rbp), %rax
movq (%rax), %rcx
leaq 0x40a(%rip), %rsi       # 0x372d60
callq 0x16d710
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x18, %esi
callq 0x2140
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
addq $0x1, %rdi
movl $0x4, %esi
callq 0x2140
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x78(%rax)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x372b20
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x1d0(%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
imulq $0x28, -0x38(%rbp), %rax
addq %rax, %rdx
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x70(%rax), %r8
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %r8
movq -0x38(%rbp), %r9
callq 0x371a60
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x372a70
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x40(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x372a2b
cmpq $0x0, -0x10(%rbp)
je 0x372b0d
movq -0x18(%rbp), %rax
movq 0xb8(%rax), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x372aeb
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl %eax
movl %eax, %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x36ef30
cmpl $0x0, %eax
je 0x372adb
jmp 0x372aeb
jmp 0x372add
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x372a96
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x372b0b
movq -0x18(%rbp), %rax
movq 0xb8(%rax), %rax
movq -0x38(%rbp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x372b0d
jmp 0x372b0f
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3729a7
movq -0x48(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x80(%rax)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x372bc5
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x50(%rbp)
jbe 0x372bb5
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x58(%rbp), %rcx
subq $0x1, %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x372bb7
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x372b4b
movq -0x58(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x372bd1
jmp 0x372bf0
leaq 0x28228(%rip), %rdi     # 0x39ae00
leaq 0x235da(%rip), %rsi     # 0x3961b9
movl $0x40db, %edx           # imm = 0x40DB
leaq 0x28222(%rip), %rcx     # 0x39ae0d
callq 0x2130
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x372d5a
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x372d47
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x78(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq -0x40(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
movl (%rdx), %edx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,4), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x40(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
shrl %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
movq 0x78(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq -0x40(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
movl (%rdx), %edx
shrl %edx
movl %edx, %edx
subl (%rcx,%rdx,4), %eax
movl %eax, %eax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x372d34
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq -0x68(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x372d03
movq -0x38(%rbp), %rdx
shlq $0x20, %rdx
orq -0x40(%rbp), %rdx
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
subq $0x1, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x372d32
movq -0x38(%rbp), %rdx
shlq $0x20, %rdx
orq -0x40(%rbp), %rdx
movq -0x60(%rbp), %rax
movq -0x60(%rbp), %rsi
movq -0x68(%rbp), %rdi
subq $0x1, %rdi
movq (%rsi,%rdi,8), %rcx
movq %rcx, %r8
addq $0x1, %r8
movq %r8, (%rsi,%rdi,8)
movq %rdx, (%rax,%rcx,8)
jmp 0x372d34
jmp 0x372d36
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x372c25
jmp 0x372d49
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x372bf8
addq $0x70, %rsp
popq %rbp
retq