// File: /workspace/github_cpp_makefile_star2_O1/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 %r8, %r12
movq %rcx, %r8
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
movl 0x78(%rsp), %ecx
movl 0x70(%rsp), %esi
movl %ecx, %eax
movq %rax, 0x10(%rsp)
testl %ecx, %ecx
je 0x161022
movq 0x10(%rsp), %rax
movl %esi, %ecx
movl %ecx, %edi
movl (%r9,%rdi,8), %edi
movl $0xffffffff, (%r8,%rdi,4) # imm = 0xFFFFFFFF
incl %ecx
decq %rax
jne 0x16100d
movq $0x0, (%r12)
movl %esi, %eax
movq %r9, 0x8(%rsp)
movq (%r9,%rax,8), %rbx
movl %ebx, %r15d
cmpq $0x0, 0x8(%r12)
movq %r8, 0x20(%rsp)
jne 0x16106d
movq $0x2, 0x8(%r12)
movq 0x10(%r12), %rdi
movl $0x8, %esi
movq %rdx, %r13
callq 0x2370
movq %r13, %rdx
movq 0x20(%rsp), %r8
movq %rax, 0x10(%r12)
movq (%r12), %rcx
movq 0x10(%r12), %rsi
movq %rcx, %rax
incq %rax
movq %rax, (%r12)
movl %ebx, (%rsi,%rcx,4)
movl $0x0, (%r8,%r15,4)
jne 0x16124c
movq 0x30(%r14), %rdx
movq 0x38(%r14), %rax
movq %rdx, 0x28(%rsp)
cmpq %rax, %rdx
jne 0x1610cd
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x38(%r14)
movq 0x40(%r14), %rdi
imulq $0x38, %rax, %rsi
callq 0x2370
movq 0x20(%rsp), %r8
movq %rax, 0x40(%r14)
movq 0x30(%r14), %rcx
movq 0x40(%r14), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x30(%r14)
imulq $0x38, %rcx, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x18(%rsp)
movw $0x0, 0x10(%rax,%rcx)
movq $0x0, 0x8(%rax,%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax,%rcx)
movups %xmm0, 0x28(%rax,%rcx)
movl (%r14), %edx
movl %edx, (%rax,%rcx)
cmpl $0x0, 0x78(%rsp)
movq 0x8(%rsp), %rsi
je 0x1611ab
leaq (%rax,%rcx), %rdi
addq $0x8, %rdi
movq 0x28(%rsp), %rax
leal (%rax,%rax), %r15d
movq 0x10(%rsp), %r13
movl 0x70(%rsp), %ebp
movq %rdi, 0x30(%rsp)
movl %ebp, %eax
movq (%rsi,%rax,8), %rbx
movl %ebx, %r12d
cmpl $0x0, (%r8,%r12,4)
jne 0x1611a4
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x161189
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %r8
movq 0x8(%rsp), %rsi
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movl %ebx, (%rcx,%rax,4)
incl (%rdi)
movq 0x28(%r14), %rax
movl %r15d, (%rax,%r12,4)
incl %ebp
decq %r13
jne 0x16113c
movl (%r14), %eax
movq 0x18(%rsp), %rcx
movl %eax, 0x4(%rcx)
cmpl $0x0, 0x78(%rsp)
movl 0x70(%rsp), %ebp
movq 0x10(%rsp), %r15
je 0x16148f
movq 0x28(%rsp), %rax
leal 0x1(,%rax,2), %ebx
movl %ebp, %eax
movq (%rsi,%rax,8), %r13
movl %r13d, %r12d
cmpl $0x1, (%r8,%r12,4)
jne 0x161240
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x16121e
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x20(%rsp), %r8
movq 0x8(%rsp), %rsi
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movl %r13d, (%rcx,%rax,4)
movq 0x18(%rsp), %rax
incl 0xc(%rax)
movq 0x28(%r14), %rax
movl %ebx, (%rax,%r12,4)
incl %ebp
decq %r15
jne 0x1611d6
jmp 0x16148f
movq %rdx, 0x28(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, (%r12)
movq 0x10(%r12), %rcx
movl -0x4(%rcx,%rax,4), %r9d
movq 0x10(%rdx), %rax
cmpl $0x0, (%rax,%r9,8)
je 0x161374
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax,%r9,8), %r13
testl %r13d, %r13d
je 0x161374
movq %r13, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %r15
shlq $0x4, %r15
movq 0x18(%rsp), %rax
addq 0x10(%rax), %r15
xorl %eax, %eax
movl $0x1, %ebx
movq %r9, 0x30(%rsp)
movl %eax, %ecx
cmpl %ebx, %r13d
je 0x1612d5
movl %ebx, %esi
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
movl 0x14(%r15,%rsi), %edi
leaq (%rcx,%rcx,2), %rsi
shlq $0x4, %rsi
cmpl 0x14(%r15,%rsi), %edi
je 0x161369
leaq (%rcx,%rcx,2), %rax
shlq $0x4, %rax
movl 0x14(%r15,%rax), %ebp
movq 0x10(%rdx), %rax
cmpl $0x0, (%rax,%rbp,8)
movl %ebx, %eax
je 0x161369
movl (%r8,%rbp,4), %ecx
cmpl $-0x1, %ecx
je 0x161304
movl %ebx, %eax
cmpl (%r8,%r9,4), %ecx
jne 0x161369
jmp 0x161386
movl $0x1, %eax
subl (%r8,%r9,4), %eax
movl %eax, (%r8,%rbp,4)
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0x161353
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %r8
movq %rax, 0x10(%r12)
movq (%r12), %rax
movq 0x10(%r12), %rcx
leaq 0x1(%rax), %rsi
movq %rsi, (%r12)
movl %ebp, (%rcx,%rax,4)
movl %ebx, %eax
incl %ebx
cmpl %r13d, %ebx
jbe 0x1612ac
movq (%r12), %rax
testq %rax, %rax
jne 0x161251
jmp 0x161091
cmpl $0x0, 0x78(%rsp)
movq 0x8(%rsp), %rsi
movl 0x70(%rsp), %eax
movq 0x10(%rsp), %rcx
je 0x16148f
movq %rcx, 0x10(%rsp)
movl %eax, %r15d
movl %eax, %eax
movq (%rsi,%rax,8), %r12
movq 0x30(%r14), %rbx
movq 0x38(%r14), %rax
cmpq %rax, %rbx
jne 0x1613e4
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x38(%r14)
movq 0x40(%r14), %rdi
imulq $0x38, %rcx, %rsi
callq 0x2370
movq 0x8(%rsp), %rsi
movq %rax, 0x40(%r14)
movq 0x30(%r14), %rax
movq 0x40(%r14), %r13
leaq 0x1(%rax), %rcx
movq %rcx, 0x30(%r14)
imulq $0x38, %rax, %rbp
movw $0x0, 0x10(%r13,%rbp)
movq $0x0, 0x8(%r13,%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r13,%rbp)
movups %xmm0, 0x28(%r13,%rbp)
movq (%r14), %rcx
movl %ecx, (%r13,%rbp)
movq 0x8(%r14), %rax
cmpq %rax, %rcx
jne 0x161453
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x8(%rsp), %rsi
movq %rax, 0x10(%r14)
addq %rbp, %r13
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movl %r12d, (%rcx,%rax,4)
incl 0x8(%r13)
movl %r12d, %eax
addl %ebx, %ebx
movq 0x28(%r14), %rcx
movl %ebx, (%rcx,%rax,4)
movl %edx, 0x4(%r13)
movl %r15d, %eax
incl %eax
movq 0x10(%rsp), %rcx
decq %rcx
jne 0x16139f
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq