// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/rcut.cpp
// Function: mc_g_cc_core(mc_match_t*)
uint64_t *mc_g_cc_core(mc_match_t *ma)
{
	uint32_t i, x, y, *flag;
	uint64_t *group;
	mc_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 0x124faf
orl $-0x1, (%rbx,%rax,4)
incq %rax
jmp 0x124fa1
xorl %r14d, %r14d
xorl %edi, %edi
xorl %eax, %eax
movq %rbx, 0x10(%rsp)
movl %r15d, %ecx
cmpq %rcx, %r14
jae 0x12508a
cmpl $-0x1, (%rbx,%r14,4)
jne 0x125082
testq %rax, %rax
jne 0x124fe5
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 0x12507a
movl -0x4(%rdi,%rbp,4), %ecx
decq %rbp
movl %r14d, (%rbx,%rcx,4)
movq (%rsp), %rsi
movq 0x10(%rsi), %rdx
movq (%rdx,%rcx,8), %r12
movl %r12d, %r15d
shrq $0x1c, %r12
andq $-0x10, %r12
addq 0x28(%rsi), %r12
shlq $0x4, %r15
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x125070
movq (%r12,%r14), %r13
movl %r13d, %ecx
cmpl $-0x1, (%rbx,%rcx,4)
jne 0x12506a
cmpq %rax, %rbp
jne 0x125063
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 $0x10, %r14
jmp 0x125026
movq 0x8(%rsp), %r14
jmp 0x124ff0
movq (%rsp), %rcx
movl 0x38(%rcx), %r15d
incq %r14
jmp 0x124fbb
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 0x1250bf
movl (%rbx,%rax,4), %ecx
shlq $0x20, %rcx
addq %rax, %rcx
movq %rcx, (%r15,%rax,8)
incq %rax
jmp 0x1250a7
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 0x125115
movl %edi, %esi
je 0x1250f0
movq (%r15,%rsi,8), %r8
xorq (%r15,%rdx,8), %r8
shrq $0x20, %r8
je 0x125110
movq %rcx, %rdi
shlq $0x20, %rdi
cmpq %rdx, %rsi
jae 0x12510c
movl (%r15,%rsi,8), %r8d
orq %rdi, %r8
movq %r8, (%r15,%rsi,8)
incq %rsi
jmp 0x1250f7
incl %ecx
movl %edx, %edi
incq %rdx
jmp 0x1250d9
movq %rbx, %rdi
callq 0x2220
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq