// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]oatk/syncasm.c
// Function: scg_scm_utg_index
static void scg_scm_utg_index(scg_t *g)
{
    if (g->idx_u) {
        free(g->idx_u);
        g->idx_u = 0;
    }
    if (g->scm_u) {
        free(g->scm_u);
        g->scm_u = 0;
    }

    kvec_t(uint128_t) scm_u;

    if (!g->utg_asmg) return;

    size_t i, j, m, n;
    uint64_t *a;
    scg_utg_t *utg;
    
    utg = scg_a_vtx(g);
    kv_init(scm_u);
    for (i = 0, n = scg_n_vtx(g); i < n; ++i) {
        if (utg[i].del)
            continue;
        a = utg[i].a;
        for (j = 0, m = utg[i].n; j < m; ++j)
            kv_push(uint128_t, scm_u, ((uint128_t) a[j] << 78) | ((uint128_t) i << 36) | j);
    }

    if (scm_u.n == 0)
        return;

    // scm position array sorting
    qsort(scm_u.a, scm_u.n, sizeof(uint128_t), uint128_cmpfunc);

    // scm position array indexing
    uint128_t **idx_u, *p, *p_n;
    uint64_t s0, s;
    n = scg_n_scm(g);
    MYMALLOC(idx_u, n + 1);
    p = scm_u.a;
    s = scm_utg_sid(p[0]);
    p_n = p + scm_u.n;
    i = 0;
    while (i < n && p < p_n) {
        while (i <= s)
            idx_u[i++] = p;
        s0 = s;
        while (s0 == s && ++p < p_n)
            s = scm_utg_sid(p[0]);
    }
    while (i <= n)
        idx_u[i++] = p;

    assert(scm_u.a + scm_u.n == idx_u[n]);

    g->idx_u = idx_u;
    g->scm_u = scm_u.a;

#ifdef DEBUG_SCM_UTG_INDEX
    for (i = 0; i < n; ++i) {
        m = scm_utg_n(g, i);
        if (m > 0) {
            p = idx_u[i];
            s = scm_utg_sid(p[0]);
            for (j = 1; j < m; ++j) {
                if (s != scm_utg_sid(p[j])) {
                    fprintf(stderr, "[DEBUG_SCM_UTG_INDEX::%s] syncmer unitigging index error!\n", __func__);
                    exit(EXIT_FAILURE);
                }
            }
        }
    }
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rax
movq 0x18(%rdi), %rdi
testq %rdi, %rdi
movq %rax, 0x8(%rsp)
je 0x4e61
callq 0x2060
movq 0x8(%rsp), %rax
movq $0x0, 0x18(%rax)
movq 0x10(%rax), %rdi
testq %rdi, %rdi
je 0x4e7c
callq 0x2060
movq 0x8(%rsp), %rax
movq $0x0, 0x10(%rax)
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x5042
movq (%rax), %rdx
testq %rdx, %rdx
je 0x4f75
movq 0x10(%rax), %rsi
xorl %edi, %edi
xorl %eax, %eax
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %rdx, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
testb $0x40, 0x23(%rsi,%rcx,8)
jne 0x4f67
leaq (%rsi,%rcx,8), %rcx
movq (%rcx), %rbx
testq %rbx, %rbx
je 0x4f67
movq 0x8(%rcx), %rsi
movq %rbp, %r12
shrq $0x1c, %r12
movq %rbp, 0x20(%rsp)
shlq $0x24, %rbp
movq %r13, %r15
shlq $0x4, %r15
xorl %r14d, %r14d
movq %r13, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
leaq (%r14,%r13), %rcx
cmpq %rax, %rcx
jne 0x4f2f
leaq (%rax,%rax), %r13
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r13
movq %r13, %rsi
shlq $0x4, %rsi
callq 0x2360
movq 0x28(%rsp), %rsi
movq %rax, %rdi
movq %r13, %rax
movq 0x30(%rsp), %r13
movq (%rsi,%r14,8), %rcx
shlq $0xe, %rcx
orq %r12, %rcx
movq %rbp, %rdx
orq %r14, %rdx
movq %rdx, (%rdi,%r15)
movq %rcx, 0x8(%rdi,%r15)
incq %r14
addq $0x10, %r15
cmpq %r14, %rbx
jne 0x4efa
addq %r14, %r13
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rbp
incq %rbp
cmpq %rdx, %rbp
jne 0x4eac
jmp 0x4f7a
xorl %r13d, %r13d
xorl %edi, %edi
testq %r13, %r13
je 0x5042
leaq 0x792e(%rip), %rcx      # 0xc8b8
movl $0x10, %edx
movq %r13, %rsi
movq %rdi, %rbx
callq 0x20d0
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax), %r12
leaq 0x8(,%r12,8), %rdi
callq 0x2320
movq %rbx, %r9
movq %r13, %rcx
shlq $0x4, %rcx
addq %rbx, %rcx
xorl %edx, %edx
movq %rbx, %rsi
testq %r12, %r12
je 0x502a
testq %r13, %r13
jle 0x502a
movq 0x8(%r9), %rdi
shrq $0xf, %rdi
xorl %edx, %edx
movq %r9, %rsi
cmpq %rdi, %rdx
ja 0x4ff0
leaq 0x1(%rdi), %r8
movq %rsi, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %r8
jne 0x4fe4
addq $0x10, %rsi
cmpq %rcx, %rsi
jae 0x5011
movq 0x8(%rsi), %r8
shrq $0xf, %r8
cmpq %r8, %rdi
jne 0x5014
addq $0x10, %rsi
cmpq %rcx, %rsi
jb 0x4ff9
jmp 0x5014
movq %rdi, %r8
cmpq %r12, %rdx
jae 0x502a
movq %r8, %rdi
cmpq %rcx, %rsi
jb 0x4fdb
jmp 0x502a
movq %rsi, (%rax,%rdx,8)
incq %rdx
cmpq %r12, %rdx
jbe 0x5023
cmpq (%rax,%r12,8), %rcx
jne 0x5051
movq 0x8(%rsp), %rcx
movq %rax, 0x18(%rcx)
movq %r9, 0x10(%rcx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18c54(%rip), %rdi     # 0x1dcac
leaq 0x189b4(%rip), %rsi     # 0x1da13
leaq 0x18c64(%rip), %rcx     # 0x1dcca
movl $0xaa, %edx
callq 0x21d0