// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq 0x18(%rdi), %rdi
testq %rdi, %rdi
je 0x3da0
callq 0x2060
andq $0x0, 0x18(%rbx)
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x3db3
callq 0x2060
andq $0x0, 0x10(%rbx)
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x3f4e
movq %rbx, 0x8(%rsp)
movq (%rax), %rcx
movq 0x10(%rax), %rdx
xorl %ebx, %ebx
xorl %esi, %esi
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rcx, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
cmpq %rcx, %rbx
movq %rsi, 0x10(%rsp)
je 0x3ea3
imulq $0x28, %rbx, %rax
testb $0x40, 0x23(%rdx,%rax)
jne 0x3e9b
addq %rdx, %rax
movq (%rax), %rdx
movq 0x8(%rax), %rdi
movq %rbx, %r8
shrq $0x1c, %r8
movq %rbx, 0x28(%rsp)
shlq $0x24, %rbx
leaq (%rsi,%rsi), %rbp
xorl %r13d, %r13d
movq %rdi, 0x30(%rsp)
leaq (%rsi,%r13), %rax
cmpq %r13, %rdx
je 0x3e89
cmpq %r12, %rax
jne 0x3e66
testq %rax, %rax
movq %rbp, %r12
pushq $0x2
popq %rax
cmoveq %rax, %r12
movq %r12, %rsi
shlq $0x4, %rsi
movq %r14, %rdi
movq %rdx, %r14
movq %r8, %r15
callq 0x2350
movq %r15, %r8
movq 0x30(%rsp), %rdi
movq %r14, %rdx
movq 0x10(%rsp), %rsi
movq %rax, %r14
movq (%rdi,%r13,8), %rax
shlq $0xe, %rax
orq %r8, %rax
movq %rbx, %rcx
orq %r13, %rcx
movq %rcx, (%r14,%rbp,8)
movq %rax, 0x8(%r14,%rbp,8)
incq %r13
addq $0x2, %rbp
jmp 0x3e23
movq %rax, %rsi
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %rbx
incq %rbx
jmp 0x3de0
testq %rsi, %rsi
movq 0x8(%rsp), %rbx
je 0x3f4e
leaq 0x5f78(%rip), %rcx      # 0x9e30
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x20d0
movq (%rbx), %rax
movq (%rax), %rbx
leaq 0x8(,%rbx,8), %rdi
callq 0x2310
movq 0x10(%rsp), %r8
movq 0x8(%r14), %rsi
shrq $0xf, %rsi
shlq $0x4, %r8
addq %r14, %r8
xorl %ecx, %ecx
movq %r14, %rdx
cmpq %rbx, %rcx
jae 0x3f36
cmpq %r8, %rdx
jb 0x3f02
jmp 0x3f36
movq %rdx, (%rax,%rcx,8)
incq %rcx
cmpq %rsi, %rcx
jbe 0x3efb
addq $0x10, %rdx
movq %rsi, %rdi
cmpq %rdi, %rsi
jne 0x3f26
cmpq %r8, %rdx
jae 0x3eef
movq 0x8(%rdx), %rdi
shrq $0xf, %rdi
addq $0x10, %rdx
jmp 0x3f0e
addq $-0x10, %rdx
movq %rdi, %rsi
jmp 0x3eef
movq %rdx, (%rax,%rcx,8)
incq %rcx
cmpq %rbx, %rcx
jbe 0x3f2f
cmpq (%rax,%rbx,8), %r8
jne 0x3f5d
movq 0x8(%rsp), %rcx
movq %rax, 0x18(%rcx)
movq %r14, 0x10(%rcx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x15d48(%rip), %rdi     # 0x19cac
leaq 0x15aa8(%rip), %rsi     # 0x19a13
leaq 0x15d58(%rip), %rcx     # 0x19cca
movl $0xaa, %edx
callq 0x21d0