// File: /workspace/github_cpp_makefile_star2_O3/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
movl %edx, %ebx
testl %edx, %edx
je 0x1678aa
movq %r8, %r15
movq %rsi, %r12
movq %rdi, %r14
movl %edx, 0xc(%rsp)
leaq (,%rbx,4), %rdx
movq %rcx, %rdi
movl $0xff, %esi
movq %rcx, (%rsp)
callq 0x20e0
movq (%rsp), %r8
xorl %r13d, %r13d
movq %r14, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
cmpl $-0x1, (%r8,%r13,4)
jne 0x1677f9
movq 0x10(%r12), %rax
cmpl $0x0, (%rax,%r13,8)
je 0x1676d7
movq $0x0, (%r15)
cmpq $0x0, 0x8(%r15)
movq 0x10(%r15), %rax
je 0x1676e0
movl %r13d, (%rax)
movl $0x1, %ecx
jmp 0x167713
movl %r13d, (%r8,%r13,4)
jmp 0x1677f9
movq $0x2, 0x8(%r15)
movl $0x8, %esi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x10(%r15)
movq (%r15), %rdx
movq %rdx, %rcx
incq %rcx
movq %rcx, (%r15)
movl %r13d, (%rax,%rdx,4)
je 0x1677f9
movq %r13, 0x20(%rsp)
movq %rcx, %rdx
decq %rcx
movq %rcx, (%r15)
movl -0x4(%rax,%rdx,4), %edx
movl %r13d, (%r8,%rdx,4)
movq 0x28(%r14), %rsi
movq (%rsi,%rdx,8), %rbx
testl %ebx, %ebx
je 0x1677e6
movq %rbx, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %r13
shlq $0x4, %r13
addq 0x10(%r14), %r13
movl $0x1, %ebp
xorl %edx, %edx
movl %edx, %esi
cmpl %ebp, %ebx
jne 0x167768
leaq (%rsi,%rsi,2), %rdx
shlq $0x4, %rdx
movl 0x14(%r13,%rdx), %r14d
jmp 0x167786
movl %ebp, %edi
leaq (%rdi,%rdi,2), %rdi
shlq $0x4, %rdi
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
movl 0x14(%r13,%rsi), %r14d
cmpl %r14d, 0x14(%r13,%rdi)
je 0x1677dc
movq 0x10(%r12), %rsi
movl %r14d, %edx
cmpl $0x0, (%rsi,%rdx,8)
je 0x1677da
cmpl $-0x1, (%r8,%rdx,4)
jne 0x1677da
cmpq 0x8(%r15), %rcx
jne 0x1677cc
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x10(%r15)
movq (%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movl %r14d, (%rax,%rcx,4)
movq %rdx, %rcx
movl %ebp, %edx
incl %ebp
cmpl %ebx, %ebp
jbe 0x167753
testq %rcx, %rcx
movq 0x18(%rsp), %r14
movq 0x20(%rsp), %r13
jne 0x167718
incq %r13
movq 0x10(%rsp), %rbx
cmpq %rbx, %r13
jne 0x1676a4
movl $0x8, %esi
movq %rbx, %rdi
callq 0x2120
movq %rax, %r15
movl 0xc(%rsp), %ebp
testl %ebp, %ebp
je 0x1678bc
xorl %eax, %eax
movq (%rsp), %rdx
movl (%rdx,%rax,4), %ecx
shlq $0x20, %rcx
addq %rax, %rcx
movq %rcx, (%r15,%rax,8)
incq %rax
cmpq %rax, %rbx
jne 0x16782c
leaq (%r15,%rbx,8), %rsi
movq %r15, %rdi
callq 0x166e19
testl %ebp, %ebp
je 0x1678c8
incl %ebp
cmpl $0x3, %ebp
movl $0x2, %eax
cmovael %ebp, %eax
xorl %edi, %edi
movl $0x1, %ecx
xorl %edx, %edx
movl %edi, %esi
cmpq %rbx, %rcx
je 0x16787d
movq (%r15,%rsi,8), %r8
xorq (%r15,%rcx,8), %r8
shrq $0x20, %r8
je 0x1678a0
cmpq %rcx, %rsi
jae 0x16789c
movq %rdx, %rdi
shlq $0x20, %rdi
movl (%r15,%rsi,8), %r8d
orq %rdi, %r8
movq %r8, (%r15,%rsi,8)
incq %rsi
cmpq %rsi, %rcx
jne 0x167889
incl %edx
movl %ecx, %edi
incq %rcx
cmpq %rax, %rcx
jne 0x167868
jmp 0x1678c8
movl $0x8, %esi
movq %rbx, %rdi
callq 0x2120
movq %rax, %r15
xorl %ebx, %ebx
leaq (%r15,%rbx,8), %rsi
movq %r15, %rdi
callq 0x166e19
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq