// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/rcut.cpp
// Function: mb_g_cc_core(mb_match_t*)
uint64_t *mb_g_cc_core(mb_match_t *ma)
{
    uint32_t i, x, y, *flag;
    uint64_t *group;
    mb_edge_t *o = NULL;
    kvec_t(uint32_t) stack; kv_init(stack);

    MALLOC(flag, ma->n_seq);
    for (i = 0; i < ma->n_seq; ++i)
        flag[i] = (uint32_t)-1;

    // connected componets
    for (i = 0; i < ma->n_seq; ++i) {
        if (flag[i] != (uint32_t)-1) continue;
        stack.n = 0;
        kv_push(uint32_t, stack, i);
        while (stack.n > 0) {
            uint32_t k, j, n;
            stack.n--;
            k = stack.a[stack.n];
            flag[k] = i;///group id
            // n = (uint32_t)ma->idx[k];
            // s = ma->idx[k] >> 32;
            o = pt_a(*ma, k); 
            n = pt_n(*ma, k);
            for (j = 0; j < n; ++j) {
                uint32_t t = ma_y(o[j]);
                if (flag[t] != (uint32_t)-1) continue;
                // if (ns == ms) PT_EXPAND(stack, ms);
                // stack[ns++] = t;
                kv_push(uint32_t, stack, t);
            }
        }
    }
    kv_destroy(stack);

    // precalculate the size of each group
    CALLOC(group, ma->n_seq);
    for (i = 0; i < ma->n_seq; ++i)
        group[i] = (uint64_t)flag[i] << 32 | i;
    radix_sort_mc64(group, group + ma->n_seq);
    for (i = 1, x = y = 0; i <= ma->n_seq; ++i) {
        if (i == ma->n_seq || group[i]>>32 != group[x]>>32) {
            uint32_t j;
            for (j = x; j < i; ++j)
                group[j] = (uint64_t)y << 32 | (uint32_t)group[j];///(group id)|first element in this group
            ++y, x = i;
        }
    }
    free(flag);
    return group;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, (%rsp)
movl 0x38(%rdi), %r15d
leaq (,%r15,4), %rdi
callq 0x2280
movq %rax, %rbx
xorl %eax, %eax
cmpq %rax, %r15
je 0x12a0ab
orl $-0x1, (%rbx,%rax,4)
incq %rax
jmp 0x12a09d
xorl %r14d, %r14d
xorl %edi, %edi
xorl %eax, %eax
movq %rbx, 0x10(%rsp)
movl %r15d, %ecx
cmpq %rcx, %r14
jae 0x12a185
cmpl $-0x1, (%rbx,%r14,4)
jne 0x12a17d
testq %rax, %rax
jne 0x12a0e1
pushq $0x8
popq %rsi
callq 0x2370
movq %rax, %rdi
pushq $0x2
popq %rax
movl %r14d, (%rdi)
pushq $0x1
popq %rbp
movq %r14, 0x8(%rsp)
testq %rbp, %rbp
je 0x12a175
movl -0x4(%rdi,%rbp,4), %ecx
decq %rbp
movl %r14d, (%rbx,%rcx,4)
movq (%rsp), %rsi
movq 0x10(%rsi), %rdx
movq (%rdx,%rcx,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x28, %rcx, %r15
addq 0x28(%rsi), %r15
imulq $0x28, %rdx, %r12
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x12a16b
movq (%r15,%r14), %r13
movl %r13d, %ecx
cmpl $-0x1, (%rbx,%rcx,4)
jne 0x12a165
cmpq %rax, %rbp
jne 0x12a15e
leaq (%rax,%rax), %rbx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rbx
leaq (,%rbx,4), %rsi
callq 0x2370
movq %rax, %rdi
movq %rbx, %rax
movq 0x10(%rsp), %rbx
movl %r13d, (%rdi,%rbp,4)
incq %rbp
addq $0x28, %r14
jmp 0x12a121
movq 0x8(%rsp), %r14
jmp 0x12a0ec
movq (%rsp), %rcx
movl 0x38(%rcx), %r15d
incq %r14
jmp 0x12a0b7
callq 0x2220
movq (%rsp), %rax
movl 0x38(%rax), %r12d
pushq $0x8
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, %r15
xorl %eax, %eax
cmpq %rax, %r12
je 0x12a1ba
movl (%rbx,%rax,4), %ecx
shlq $0x20, %rcx
addq %rax, %rcx
movq %rcx, (%r15,%rax,8)
incq %rax
jmp 0x12a1a2
leaq (%r15,%r12,8), %rsi
movq %r15, %rdi
callq 0x1224a9
movq (%rsp), %rax
movl 0x38(%rax), %eax
xorl %ecx, %ecx
pushq $0x1
popq %rdx
xorl %edi, %edi
cmpq %rax, %rdx
ja 0x12a210
movl %edi, %esi
je 0x12a1eb
movq (%r15,%rsi,8), %r8
xorq (%r15,%rdx,8), %r8
shrq $0x20, %r8
je 0x12a20b
movq %rcx, %rdi
shlq $0x20, %rdi
cmpq %rdx, %rsi
jae 0x12a207
movl (%r15,%rsi,8), %r8d
orq %rdi, %r8
movq %r8, (%r15,%rsi,8)
incq %rsi
jmp 0x12a1f2
incl %ecx
movl %edx, %edi
incq %rdx
jmp 0x12a1d4
movq %rbx, %rdi
callq 0x2220
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq