// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rdx, %r11
movq %rsi, 0x38(%rsp)
movq %rdi, %r14
movl 0x88(%rsp), %r12d
movl 0x80(%rsp), %r13d
movl %r13d, %eax
movq %r12, %rsi
subq $0x1, %rsi
jb 0x122edf
movl %eax, %edx
movl (%r9,%rdx,8), %edx
orl $-0x1, (%rcx,%rdx,4)
incl %eax
jmp 0x122ecb
andq $0x0, (%r8)
movl %r13d, %eax
movq (%r9,%rax,8), %rbx
movl %ebx, %r15d
cmpq $0x0, 0x8(%r8)
movq %r9, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movq %r8, 0x30(%rsp)
movq %r11, 0x28(%rsp)
je 0x122f10
movq 0x10(%r8), %rax
xorl %edx, %edx
jmp 0x122f3f
movq $0x2, 0x8(%r8)
movq 0x10(%r8), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq 0x28(%rsp), %r11
movq 0x30(%rsp), %r8
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r8)
movq (%r8), %rdx
leaq 0x1(%rdx), %r10
movq %r10, (%r8)
movl %ebx, (%rax,%rdx,4)
andl $0x0, (%rcx,%r15,4)
decq %r10
cmpq $-0x1, %r10
je 0x123065
movq %r10, (%r8)
movl (%rax,%r10,4), %ebx
movq 0x10(%r11), %rdx
decq %r10
cmpl $0x0, (%rdx,%rbx,8)
je 0x122f51
movq 0x38(%rsp), %rsi
movq 0x28(%rsi), %rdx
movq (%rdx,%rbx,8), %rdx
movq %rdx, 0x10(%rsp)
shrq $0x20, %rdx
imulq $0x30, %rdx, %rdx
addq 0x10(%rsi), %rdx
movq %rdx, 0x20(%rsp)
incq %r10
xorl %edx, %edx
pushq $0x1
popq %r13
cmpl 0x10(%rsp), %r13d
ja 0x123058
movl %edx, %esi
jne 0x122fb9
imulq $0x30, %rsi, %rdx
movq 0x20(%rsp), %rsi
movl 0x14(%rsi,%rdx), %ebp
jmp 0x122fd5
movl %r13d, %edi
imulq $0x30, %rdi, %rdi
imulq $0x30, %rsi, %rsi
movq 0x20(%rsp), %r15
movl 0x14(%r15,%rsi), %ebp
cmpl %ebp, 0x14(%r15,%rdi)
je 0x123050
movq 0x10(%r11), %rsi
movl %ebp, %edx
cmpl $0x0, (%rsi,%rdx,8)
je 0x12304d
movl (%rcx,%rdx,4), %edi
movl (%rcx,%rbx,4), %esi
cmpl $-0x1, %edi
je 0x122ff8
movl %r13d, %edx
cmpl %esi, %edi
jne 0x123050
jmp 0x123203
pushq $0x1
popq %rdi
subl %esi, %edi
movl %edi, (%rcx,%rdx,4)
cmpq 0x8(%r8), %r10
jne 0x12303f
leaq (%r10,%r10), %rsi
testq %r10, %r10
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r8)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x28(%rsp), %r11
movq 0x30(%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 %ebp, (%rax,%r10,4)
movq %rdx, %r10
movl %r13d, %edx
incl %r13d
jmp 0x122f9b
movl 0x80(%rsp), %r13d
jmp 0x122f4e
movq 0x30(%r14), %rbx
cmpq 0x38(%r14), %rbx
jne 0x1230a2
leaq (%rbx,%rbx), %rax
testq %rbx, %rbx
pushq $0x2
popq %rcx
cmoveq %rcx, %rax
movq %rax, 0x38(%r14)
movq 0x40(%r14), %rdi
imulq $0x38, %rax, %rsi
callq 0x2370
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r9
movq %rax, 0x40(%r14)
movq 0x30(%r14), %rsi
jmp 0x1230a9
movq 0x40(%r14), %rax
movq %rbx, %rsi
leaq 0x1(%rsi), %rdx
movq %rdx, 0x30(%r14)
imulq $0x38, %rsi, %rdx
leaq (%rax,%rdx), %r8
addq $0x8, %r8
andw $0x0, 0x8(%r8)
addq %rdx, %rax
movq %rax, 0x20(%rsp)
andq $0x0, (%r8)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r8)
movups %xmm0, 0x20(%r8)
movq (%r14), %rdi
movl %edi, -0x8(%r8)
leal (%rbx,%rbx), %esi
movq %r12, %rbp
movl %esi, 0x10(%rsp)
movq %r14, 0x40(%rsp)
subq $0x1, %rbp
jb 0x12316d
movl %r13d, %eax
movq (%r9,%rax,8), %r15
movl %r15d, %ebx
cmpl $0x0, (%rcx,%rbx,4)
jne 0x123168
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdi
jne 0x123150
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r8, %r14
callq 0x2370
movq %r14, %r8
movq 0x40(%rsp), %r14
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r14)
movq (%r14), %rdi
leaq 0x1(%rdi), %rdx
movq %rdx, (%r14)
movl %r15d, (%rax,%rdi,4)
incl (%r8)
movq 0x28(%r14), %rax
movl %esi, (%rax,%rbx,4)
movq %rdx, %rdi
incl %r13d
jmp 0x1230f2
movq 0x20(%rsp), %r8
movl %edi, 0x4(%r8)
orl $0x1, %esi
movl 0x80(%rsp), %ebp
movl %esi, 0x10(%rsp)
subq $0x1, %r12
jb 0x1232ef
movl %ebp, %eax
movq (%r9,%rax,8), %r15
movl %r15d, %ebx
cmpl $0x1, (%rcx,%rbx,4)
jne 0x1231ff
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdi
jne 0x1231e6
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r12, %r13
movq %r8, %r12
callq 0x2370
movq %r12, %r8
movq %r13, %r12
movl 0x10(%rsp), %esi
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r14)
movq (%r14), %rdi
leaq 0x1(%rdi), %rdx
movq %rdx, (%r14)
movl %r15d, (%rax,%rdi,4)
incl 0xc(%r8)
movq 0x28(%r14), %rax
movl %esi, (%rax,%rbx,4)
movq %rdx, %rdi
incl %ebp
jmp 0x123184
movl 0x80(%rsp), %r15d
subq $0x1, %r12
jb 0x1232ef
movl %r15d, 0x10(%rsp)
movl %r15d, %eax
movq (%r9,%rax,8), %r13
movq 0x30(%r14), %rbx
movq 0x40(%r14), %r15
cmpq 0x38(%r14), %rbx
jne 0x12325a
leaq (%rbx,%rbx), %rax
testq %rbx, %rbx
pushq $0x2
popq %rcx
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 0x12325d
movq %rbx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x30(%r14)
imulq $0x38, %rax, %rbp
andw $0x0, 0x10(%r15,%rbp)
andq $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 0x1232bb
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
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
movl %r13d, %edx
addq %rbp, %r15
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movl %r13d, (%rax,%rcx,4)
incl 0x8(%r15)
addl %ebx, %ebx
movq 0x28(%r14), %rax
movl %ebx, (%rax,%rdx,4)
movl %esi, 0x4(%r15)
movl 0x10(%rsp), %r15d
incl %r15d
jmp 0x12320b
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq