// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x2270
movq %rax, -0x20(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jae 0x21b37e
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x21b359
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jae 0x21b536
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x21b3a7
jmp 0x21b528
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0x21b3f5
cmpq $0x0, -0x40(%rbp)
je 0x21b3cd
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x21b3d8
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x21b3d8
movq -0x68(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, -0x38(%rbp)
movl -0xc(%rbp), %edx
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x21b410
cmpq $0x0, -0x48(%rbp)
jbe 0x21b526
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
movl -0xc(%rbp), %edx
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x4c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x21b521
movq -0x30(%rbp), %rax
movl -0x50(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movl -0x58(%rbp), %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x21b4b0
jmp 0x21b513
jmp 0x21b4b2
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0x21b4f8
cmpq $0x0, -0x40(%rbp)
je 0x21b4d0
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x21b4db
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x21b4db
movq -0x70(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, -0x38(%rbp)
movl -0x58(%rbp), %edx
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
movl %edx, (%rax,%rcx,4)
jmp 0x21b513
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x21b481
jmp 0x21b410
jmp 0x21b528
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x21b385
movq -0x38(%rbp), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, %edi
movl $0x8, %esi
callq 0x2140
movq %rax, -0x28(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jae 0x21b595
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %edx
shlq $0x20, %rdx
movl -0xc(%rbp), %eax
orq %rax, %rdx
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x21b55d
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x216280
movl $0x1, -0xc(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x10(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x38(%rcx), %eax
ja 0x21b660
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x38(%rcx), %eax
je 0x21b604
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x28(%rbp), %rcx
movl -0x10(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x21b650
movl -0x10(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x21b641
movl -0x14(%rbp), %eax
movl %eax, %edx
shlq $0x20, %rdx
movq -0x28(%rbp), %rax
movl -0x5c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
orq %rax, %rdx
movq -0x28(%rbp), %rax
movl -0x5c(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x21b60a
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x21b652
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x21b5c5
movq -0x20(%rbp), %rdi
callq 0x2210
movq -0x28(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)