// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/rcut.cpp
// Function: mb_nodes_core(kv_u_trans_t*, mc_match_t*, unsigned int, unsigned int*, kvec_t_u32_warp*)
uint64_t *mb_nodes_core(kv_u_trans_t *ref, mc_match_t* ma, uint32_t occ, uint32_t *fg, kvec_t_u32_warp *sk)
{
	uint32_t i, x, y;
	uint64_t *group;
	u_trans_t *o = NULL;

	for (i = 0; i < occ; ++i)
		fg[i] = (uint32_t)-1;

	// connected componets
	for (i = 0; i < occ; ++i) {
		if (fg[i] != (uint32_t)-1) continue;
		if (pt_n(*ma, i) == 0) 
		{
			fg[i] = i;///group id
			continue;
		}
		sk->a.n = 0;
		kv_push(uint32_t, sk->a, i);
		while (sk->a.n > 0) {
			uint32_t k, j, st, n, t;
			sk->a.n--;
			k = sk->a.a[sk->a.n];
			fg[k] = i;///group id
			o = u_trans_a(*ref, k); 
			n = u_trans_n(*ref, k);
			for (st = 0, j = 1; j <= n; ++j)
			{
				if(j == n || o[j].tn != o[st].tn)
				{
					t = o[st].tn;
					if ((pt_n(*ma, t) != 0) && (fg[t] == (uint32_t)-1))
					{
						kv_push(uint32_t, sk->a, t);
					}
					st = j;
				}
			}
		}
	}

	// precalculate the size of each group
	CALLOC(group, occ);
	for (i = 0; i < occ; ++i)
		group[i] = (uint64_t)fg[i] << 32 | i;
	radix_sort_mc64(group, group + occ);
	for (i = 1, x = y = 0; i <= occ; ++i) {
		if (i == occ || 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;
		}
	}
	return group;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, 0x10(%rsp)
movl %edx, %ebx
movl %edx, 0xc(%rsp)
testl %edx, %edx
movq %rcx, (%rsp)
je 0x160f2b
movq %r8, %r15
movq %rsi, %r12
leaq (,%rbx,4), %rdx
movq %rcx, %rdi
movl $0xff, %esi
callq 0x20e0
movq (%rsp), %rdi
xorl %r14d, %r14d
movq %rbx, 0x18(%rsp)
cmpl $-0x1, (%rdi,%r14,4)
je 0x160dd6
incq %r14
movq 0x18(%rsp), %rbx
cmpq %rbx, %r14
jne 0x160dbd
jmp 0x160f2b
movq 0x10(%r12), %rax
cmpl $0x0, (%rax,%r14,8)
je 0x160f22
movq $0x0, (%r15)
cmpq $0x0, 0x8(%r15)
jne 0x160e12
movq $0x2, 0x8(%r15)
movq 0x10(%r15), %rdi
movl $0x8, %esi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0x10(%r15)
movq (%r15), %rcx
movq 0x10(%r15), %rdx
movq %rcx, %rax
incq %rax
movq %rax, (%r15)
movl %r14d, (%rdx,%rcx,4)
je 0x160dc4
movq %r14, 0x20(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, (%r15)
movq 0x10(%r15), %rcx
movl -0x4(%rcx,%rax,4), %eax
movl %r14d, (%rdi,%rax,4)
movq 0x10(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx,%rax,8), %rbx
testl %ebx, %ebx
je 0x160f0c
movq %rbx, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %r13
shlq $0x4, %r13
movq 0x10(%rsp), %rax
addq 0x10(%rax), %r13
movl $0x1, %ebp
xorl %eax, %eax
movl %eax, %ecx
cmpl %ebp, %ebx
je 0x160e98
movl %ebp, %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movl 0x14(%r13,%rdx), %edx
leaq (%rcx,%rcx,2), %rsi
shlq $0x4, %rsi
cmpl 0x14(%r13,%rsi), %edx
je 0x160f02
leaq (%rcx,%rcx,2), %rax
shlq $0x4, %rax
movl 0x14(%r13,%rax), %r14d
movq 0x10(%r12), %rax
cmpl $0x0, (%rax,%r14,8)
movl %ebp, %eax
je 0x160f02
cmpl $-0x1, (%rdi,%r14,4)
movl %ebp, %eax
jne 0x160f02
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x160eee
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x2, %rsi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0x10(%r15)
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movl %r14d, (%rcx,%rax,4)
movl %ebp, %eax
incl %ebp
cmpl %ebx, %ebp
jbe 0x160e74
movq (%r15), %rax
testq %rax, %rax
movq 0x20(%rsp), %r14
jne 0x160e2d
jmp 0x160dc4
movl %r14d, (%rdi,%r14,4)
jmp 0x160dc4
movl $0x8, %esi
movq %rbx, %rdi
callq 0x2120
movq (%rsp), %rdx
movq %rax, %r15
movl 0xc(%rsp), %ebp
testl %ebp, %ebp
je 0x160f5f
xorl %eax, %eax
movl (%rdx,%rax,4), %ecx
shlq $0x20, %rcx
addq %rax, %rcx
movq %rcx, (%r15,%rax,8)
incq %rax
cmpq %rax, %rbx
jne 0x160f49
leaq (%r15,%rbx,8), %rsi
movq %r15, %rdi
callq 0x1604f0
testl %ebp, %ebp
je 0x160fc5
incl %ebp
cmpl $0x3, %ebp
movl $0x2, %eax
cmovael %ebp, %eax
xorl %esi, %esi
movl $0x1, %ecx
xorl %edx, %edx
movl %esi, %edi
cmpq %rbx, %rcx
je 0x160f9a
movq (%r15,%rdi,8), %r8
xorq (%r15,%rcx,8), %r8
shrq $0x20, %r8
je 0x160fbd
cmpq %rdi, %rcx
jbe 0x160fb9
movq %rdx, %rsi
shlq $0x20, %rsi
movl (%r15,%rdi,8), %r8d
orq %rsi, %r8
movq %r8, (%r15,%rdi,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x160fa6
incl %edx
movl %ecx, %esi
incq %rcx
cmpq %rax, %rcx
jne 0x160f85
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq