// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/rcut.cpp
// Function: assgin_mb_node(mb_nodes_t*, kv_u_trans_t*, mc_match_t*, unsigned int*, kvec_t_u32_warp*, unsigned long*, unsigned int, unsigned int)
void assgin_mb_node(mb_nodes_t *x, kv_u_trans_t *ref, mc_match_t* ma, uint32_t *fg, kvec_t_u32_warp *sk, uint64_t *cc, uint32_t cc_off, uint32_t cc_size)
{
	uint32_t i, v, n, st, j, t, pass, uid;
	u_trans_t *o = NULL;
	mb_node_t *p = NULL;
	for (i = 0; i < cc_size; ++i)
	{
		v = (uint32_t)cc[cc_off + i];///node id
		fg[v] = (uint32_t)-1;
	}

	sk->a.n = 0;
	v = (uint32_t)cc[cc_off];
	kv_push(uint32_t, sk->a, v);
	fg[v] = 0;
	pass = 1;
	while (sk->a.n > 0)
	{
		sk->a.n--;
		v = sk->a.a[sk->a.n];
		if(pt_n(*ma, v) == 0) continue;
		o = u_trans_a(*ref, v); 
		n = u_trans_n(*ref, v);
		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)
				{
					st = j;
					continue;
				} 
				
				if (fg[t] == (uint32_t)-1)///uncolor
				{
					fg[t] = 1 - fg[v];
					kv_push(uint32_t, sk->a, t);
				}
				else if(fg[t] == fg[v]) ///color
				{
					pass = 0;
					break;
				} 
				st = j;
			}
		}
		if(pass == 0) break;
	}
	
	if(pass)
	{
		uid = x->u.n;
		kv_pushp(mb_node_t, x->u, &p);
		p->z[0] = p->z[1] = p->z[2] = p->z[3] = 0;
		p->s[0] = p->s[1] = 0;
		p->occ[0] = p->occ[1] = 0;

		for (i = 0, p->a[0] = x->bid.n; i < cc_size; ++i)
		{
			v = (uint32_t)cc[cc_off + i];///node id
			if(fg[v] == 0)
			{
				kv_push(uint32_t, x->bid, v);
				p->occ[0]++;
				x->idx.a[v] = (uid<<1);
			}
		}

		for (i = 0, p->a[1] = x->bid.n; i < cc_size; ++i)
		{
			v = (uint32_t)cc[cc_off + i];///node id
			if(fg[v] == 1)
			{
				kv_push(uint32_t, x->bid, v);
				p->occ[1]++;
				x->idx.a[v] = (uid<<1) + 1;
			}
		}
	}
	else
	{
		for (i = 0; i < cc_size; ++i)
		{
			v = (uint32_t)cc[cc_off + i];///node id
			uid = x->u.n;
			kv_pushp(mb_node_t, x->u, &p);
			p->z[0] = p->z[1] = p->z[2] = p->z[3] = 0;
			p->s[0] = p->s[1] = 0;
			p->occ[0] = p->occ[1] = 0;

			p->a[0] = x->bid.n;
			kv_push(uint32_t, x->bid, v);
			p->occ[0]++;
			x->idx.a[v] = (uid<<1);

			p->a[1] = x->bid.n;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r11
movq %rsi, 0x28(%rsp)
movq %rdi, %r14
movl 0x78(%rsp), %eax
movl 0x70(%rsp), %esi
movl %eax, %edi
testl %eax, %eax
je 0x16791d
movq %rdi, %rax
movl %esi, %r10d
movl %r10d, %edx
movl (%r9,%rdx,8), %edx
movl $0xffffffff, (%rcx,%rdx,4) # imm = 0xFFFFFFFF
incl %r10d
decq %rax
jne 0x167907
movq %rdi, 0x30(%rsp)
movq $0x0, (%r8)
movl %esi, %eax
movq (%r9,%rax,8), %r15
movl %r15d, %ebx
cmpq $0x0, 0x8(%r8)
movq %r9, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movq %r11, 0x20(%rsp)
je 0x167963
movq 0x10(%r8), %rax
movl %r15d, (%rax)
movl $0x0, (%rcx,%rbx,4)
movl $0x1, %r10d
jmp 0x1679ae
movq $0x2, 0x8(%r8)
movq 0x10(%r8), %rdi
movl $0x8, %esi
callq 0x2370
movq 0x20(%rsp), %r11
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r8)
movq (%r8), %rdx
movq %rdx, %r10
incq %r10
movq %r10, (%r8)
movl %r15d, (%rax,%rdx,4)
movl $0x0, (%rcx,%rbx,4)
je 0x167ac8
movq %r10, %rdx
decq %r10
movq %r10, (%r8)
movl -0x4(%rax,%rdx,4), %ebx
movq 0x10(%r11), %rdx
cmpl $0x0, (%rdx,%rbx,8)
je 0x167abf
movq 0x28(%rsp), %rsi
movq 0x28(%rsi), %rdx
movq (%rdx,%rbx,8), %r12
testl %r12d, %r12d
je 0x167abf
movq %r12, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rbp
shlq $0x4, %rbp
addq 0x10(%rsi), %rbp
xorl %edx, %edx
movl $0x1, %r13d
movl %edx, %esi
cmpl %r13d, %r12d
jne 0x167a10
leaq (%rsi,%rsi,2), %rdx
shlq $0x4, %rdx
movl 0x14(%rbp,%rdx), %r15d
jmp 0x167a33
movl %r13d, %edi
leaq (%rdi,%rdi,2), %rdi
shlq $0x4, %rdi
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
movl 0x14(%rbp,%rsi), %r15d
cmpl %r15d, 0x14(%rbp,%rdi)
je 0x167ab3
movq 0x10(%r11), %rsi
movl %r15d, %edx
cmpl $0x0, (%rsi,%rdx,8)
je 0x167ab0
movl (%rcx,%rdx,4), %edi
movl (%rcx,%rbx,4), %esi
cmpl $-0x1, %edi
je 0x167a57
movl %r13d, %edx
cmpl %esi, %edi
jne 0x167ab3
jmp 0x167b0e
movl $0x1, %edi
subl %esi, %edi
movl %edi, (%rcx,%rdx,4)
cmpq 0x8(%r8), %r10
jne 0x167aa2
leaq (%r10,%r10), %rsi
testq %r10, %r10
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r8)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x20(%rsp), %r11
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r8)
movq (%r8), %r10
leaq 0x1(%r10), %rdx
movq %rdx, (%r8)
movl %r15d, (%rax,%r10,4)
movq %rdx, %r10
movl %r13d, %edx
incl %r13d
cmpl %r12d, %r13d
jbe 0x1679fa
testq %r10, %r10
jne 0x1679ae
movq 0x30(%r14), %rbx
cmpq 0x38(%r14), %rbx
jne 0x167c04
leaq (%rbx,%rbx), %rax
testq %rbx, %rbx
movl $0x2, %ecx
cmovneq %rax, %rcx
movq %rcx, 0x38(%r14)
movq 0x40(%r14), %rdi
imulq $0x38, %rcx, %rsi
callq 0x2370
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r9
movq %rax, 0x40(%r14)
movq 0x30(%r14), %rsi
jmp 0x167c0b
cmpl $0x0, 0x78(%rsp)
movl 0x70(%rsp), %eax
je 0x167d7f
movl %eax, %ebx
movl %eax, %eax
movq (%r9,%rax,8), %r13
movq 0x30(%r14), %r12
movq 0x40(%r14), %r15
cmpq 0x38(%r14), %r12
jne 0x167b60
leaq (%r12,%r12), %rax
testq %r12, %r12
movl $0x2, %ecx
cmoveq %rcx, %rax
movq %rax, 0x38(%r14)
imulq $0x38, %rax, %rsi
movq %r15, %rdi
callq 0x2370
movq %rax, %r15
movq %rax, 0x40(%r14)
movq 0x30(%r14), %rax
jmp 0x167b63
movq %r12, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x30(%r14)
imulq $0x38, %rax, %rbp
movw $0x0, 0x10(%r15,%rbp)
movq $0x0, 0x8(%r15,%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r15,%rbp)
movups %xmm0, 0x28(%r15,%rbp)
movq (%r14), %rcx
movl %ecx, (%r15,%rbp)
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x167bc7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movq 0x8(%rsp), %r9
addq %rbp, %r15
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movl %r13d, (%rax,%rcx,4)
incl 0x8(%r15)
movl %r13d, %eax
addl %r12d, %r12d
movq 0x28(%r14), %rcx
movl %r12d, (%rcx,%rax,4)
movl %edx, 0x4(%r15)
movl %ebx, %eax
incl %eax
decq 0x30(%rsp)
jne 0x167b1d
jmp 0x167d7f
movq 0x40(%r14), %rax
movq %rbx, %rsi
movl 0x70(%rsp), %r12d
imulq $0x38, %rsi, %rdx
incq %rsi
leaq (%rax,%rdx), %r8
movq %rsi, 0x30(%r14)
movw $0x0, 0x10(%rax,%rdx)
movq $0x0, 0x8(%rax,%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax,%rdx)
movups %xmm0, 0x28(%rax,%rdx)
movq (%r14), %rdi
movl %edi, (%rax,%rdx)
cmpl $0x0, 0x78(%rsp)
je 0x167d7b
leaq (%rax,%rdx), %rsi
addq $0x8, %rsi
movq %rbx, 0x28(%rsp)
leal (%rbx,%rbx), %ebp
movq 0x30(%rsp), %rbx
movq %r8, 0x10(%rsp)
movq %rsi, 0x20(%rsp)
movl %r12d, %eax
movq (%r9,%rax,8), %r13
movl %r13d, %r15d
cmpl $0x0, (%rcx,%r15,4)
jne 0x167cda
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdi
jne 0x167cc2
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r14)
movq (%r14), %rdi
leaq 0x1(%rdi), %rdx
movq %rdx, (%r14)
movl %r13d, (%rax,%rdi,4)
incl (%rsi)
movq 0x28(%r14), %rax
movl %ebp, (%rax,%r15,4)
movq %rdx, %rdi
incl %r12d
decq %rbx
jne 0x167c6c
movl %edi, 0x4(%r8)
cmpl $0x0, 0x78(%rsp)
movl 0x70(%rsp), %eax
je 0x167d7f
movq 0x28(%rsp), %rdx
leal 0x1(,%rdx,2), %ebx
movl $0x2, %r13d
movl %eax, %ebp
movl %eax, %eax
movq (%r9,%rax,8), %r12
movl %r12d, %r15d
cmpl $0x1, (%rcx,%r15,4)
jne 0x167d6e
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdi
jne 0x167d54
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
cmoveq %r13, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r14)
movq (%r14), %rdi
leaq 0x1(%rdi), %rdx
movq %rdx, (%r14)
movl %r12d, (%rax,%rdi,4)
incl 0xc(%r8)
movq 0x28(%r14), %rax
movl %ebx, (%rax,%r15,4)
movq %rdx, %rdi
movl %ebp, %eax
incl %eax
decq 0x30(%rsp)
jne 0x167d07
jmp 0x167d7f
movl %edi, 0x4(%r8)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq