// File: /workspace/github_cpp_makefile_star2_O2/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 %r8, %r15
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movl %edx, %edi
xorl %eax, %eax
cmpq %rax, %rdi
je 0x122cbd
orl $-0x1, (%rcx,%rax,4)
incq %rax
jmp 0x122caf
xorl %ebx, %ebx
movq %rdi, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
cmpq %rdi, %rbx
je 0x122e02
cmpl $-0x1, (%rcx,%rbx,4)
je 0x122ce2
incq %rbx
movq 0x8(%rsp), %rdi
jmp 0x122cc9
movq 0x10(%r12), %rax
cmpl $0x0, (%rax,%rbx,8)
je 0x122d00
andq $0x0, (%r15)
cmpq $0x0, 0x8(%r15)
movq 0x10(%r15), %rax
je 0x122d05
xorl %edx, %edx
jmp 0x122d24
movl %ebx, (%rcx,%rbx,4)
jmp 0x122cd8
movq $0x2, 0x8(%r15)
movq %rax, %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%r15)
movq (%r15), %rdx
leaq 0x1(%rdx), %r8
movq %r8, (%r15)
movl %ebx, (%rax,%rdx,4)
movq %rbx, 0x20(%rsp)
testq %r8, %r8
je 0x122cd8
leaq -0x1(%r8), %rsi
movq %rsi, (%r15)
movl -0x4(%rax,%r8,4), %edi
movl %ebx, (%rcx,%rdi,4)
movq 0x18(%rsp), %r8
movq 0x28(%r8), %rdx
movq (%rdx,%rdi,8), %rbx
movq %rbx, %rdx
shrq $0x20, %rdx
imulq $0x30, %rdx, %rbp
addq 0x10(%r8), %rbp
xorl %edx, %edx
movq %rsi, %r8
pushq $0x1
popq %r13
cmpl %ebx, %r13d
ja 0x122df8
movl %edx, %esi
jne 0x122d84
imulq $0x30, %rsi, %rdx
movl 0x14(%rbp,%rdx), %r14d
jmp 0x122d9b
movl %r13d, %edi
imulq $0x30, %rdi, %rdi
imulq $0x30, %rsi, %rsi
movl 0x14(%rbp,%rsi), %r14d
cmpl %r14d, 0x14(%rbp,%rdi)
je 0x122df0
movq 0x10(%r12), %rsi
movl %r14d, %edx
cmpl $0x0, (%rsi,%rdx,8)
je 0x122ded
cmpl $-0x1, (%rcx,%rdx,4)
jne 0x122ded
cmpq 0x8(%r15), %r8
jne 0x122ddf
leaq (%r8,%r8), %rsi
testq %r8, %r8
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%r15)
movq (%r15), %r8
leaq 0x1(%r8), %rdx
movq %rdx, (%r15)
movl %r14d, (%rax,%r8,4)
movq %rdx, %r8
movl %r13d, %edx
incl %r13d
jmp 0x122d6c
movq 0x20(%rsp), %rbx
jmp 0x122d33
pushq $0x8
popq %rsi
callq 0x2120
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rax, %r15
xorl %eax, %eax
cmpq %rax, %rdx
je 0x122e31
movl (%rsi,%rax,4), %ecx
shlq $0x20, %rcx
addq %rax, %rcx
movq %rcx, (%r15,%rax,8)
incq %rax
jmp 0x122e19
leaq (%r15,%rdx,8), %rsi
movq %r15, %rdi
callq 0x1224a9
movq 0x8(%rsp), %rdx
xorl %eax, %eax
pushq $0x1
popq %rcx
xorl %esi, %esi
cmpq %rdx, %rcx
ja 0x122e8a
movl %esi, %edx
je 0x122e60
movq (%r15,%rdx,8), %rdi
xorq (%r15,%rcx,8), %rdi
shrq $0x20, %rdi
je 0x122e80
movq %rax, %rsi
shlq $0x20, %rsi
cmpq %rcx, %rdx
jae 0x122e7c
movl (%r15,%rdx,8), %edi
orq %rsi, %rdi
movq %rdi, (%r15,%rdx,8)
incq %rdx
jmp 0x122e67
incl %eax
movl %ecx, %esi
incq %rcx
movq 0x8(%rsp), %rdx
jmp 0x122e49
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq