// File: /workspace/github_cpp_makefile_star2_O1/neubig[P]egret/Egret/src/Forest-Berkeley.cpp
// Function: genUnaryNode_byLabel_unconstrained_berkeley(BerkeleyRuleSet const&, Node&, DecodeType)
bool genUnaryNode_byLabel_unconstrained_berkeley(const BerkeleyRuleSet& brSet, Node& node, DecodeType decodetype)
{
	bool mark=false;
	vector<string> ntPool;
	map<string,int> ntMap;
	ntPool.clear();
	ntMap.clear();
	node.setUnaryInOrder_berkeley(brSet,ntPool);

	for(int i=0;(size_t)i<ntPool.size();i++)
		ntMap[ntPool[i]]=1;

	for(int i=0;(size_t)i<ntPool.size();i++)
	{
		string rightPart=ntPool[i];
		//cout<<"here:"<<i<<","<<rightPart<<endl;
		Label& oldLb=node[rightPart];

		int state=oldLb.state();
		int chsub=oldLb.subState();
		
		const vector<BerkeleyUnaryRule*>& rules=brSet.getUnaryRulesByChild(state);
		const AllowStateInfo& asi=node.allowStateInfo();
		for(int k=0;(size_t)k<rules.size();k++)
		{
			BerkeleyUnaryRule* rule=rules[k];
			if(rule==NULL)continue;
			int chNumSubState=rule->childNumSubState();
			int prNumSubState=rule->parentNumSubState();
			int parentState=rule->parentState();

			if(!asi.inUse()||asi.isAllow(parentState))
			{
				for(int prsub=0;prsub<prNumSubState;prsub++)
				{
					if(!asi.inUse()||asi.isAllow(parentState,prsub))
					//for(int chsub=0;chsub<chNumSubState;chsub++)
					{
						double ruleScore=rule->getScore(chsub,prsub);
						if(ruleScore>-1E10)
						{
							Label label;
							label.init(brSet.state2term(parentState),oldLb.start(),oldLb.stop(),parentState,prsub);
							
							if(node.find(label.nt())==node.end())
								node[label.nt()]=label;
							
							if(decodetype==VITERBI)
							{   // MAKE SURE THE RULESCORE IS IN LOG FORM
								node[label.nt()].addChild_viterbi(&oldLb,ruleScore);
							}
							else if(decodetype==IO)
							{
								//node[label.nt()].addChild_io_berkeley(&oldLb,ruleScore,io);
								node[label.nt()].addChild_io(&oldLb,ruleScore);
							}
							mark=true;
						}
					}
				}
			}
		}
	}
	return mark;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movl %edx, %ebp
movq %rsi, 0x8(%rsp)
movq %rdi, 0x30(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
leaq 0x210(%rsp), %rcx
movl $0x0, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r15
cmpq %rbx, %r15
je 0x1e057
leaq 0x10(%rbx), %r12
movq -0x10(%r12), %rdi
cmpq %rdi, %r12
je 0x1e041
movq (%r12), %rsi
incq %rsi
callq 0x32e0
leaq 0x20(%r12), %rax
addq $0x10, %r12
cmpq %r15, %r12
movq %rax, %r12
jne 0x1e02b
movq %rbx, 0x18(%rsp)
leaq 0x208(%rsp), %rdi
callq 0x15398
leaq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x36530
movq 0x10(%rsp), %rsi
cmpq %rsi, 0x18(%rsp)
je 0x1e0c0
xorl %r15d, %r15d
leaq 0x208(%rsp), %rbx
xorl %r12d, %r12d
addq %r15, %rsi
movq %rbx, %rdi
callq 0xb932
movl $0x1, (%rax)
incq %r12
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %r15
cmpq %r12, %rax
ja 0x1e092
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x1e5c2
movq 0x8(%rsp), %rdx
leaq 0x60(%rdx), %rcx
movq %rcx, 0x48(%rsp)
movq 0x30(%rsp), %rcx
addq $0x298, %rcx            # imm = 0x298
movq %rcx, 0xb8(%rsp)
leaq 0x8(%rdx), %rcx
movq %rcx, 0xb0(%rsp)
xorl %ebx, %ebx
leaq 0x58(%rsp), %r15
xorl %r12d, %r12d
movl %ebp, 0x44(%rsp)
movq %rbx, %rcx
shlq $0x5, %rcx
leaq 0x68(%rsp), %rdx
movq %rdx, 0x58(%rsp)
movq (%rax,%rcx), %rsi
movq 0x8(%rax,%rcx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x6a88
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x20440
movq %rbx, 0x98(%rsp)
movslq 0x10c(%rax), %rdx
movq 0x30(%rsp), %rcx
movq 0x220(%rcx), %rcx
leaq (%rdx,%rdx,2), %rdx
movq (%rcx,%rdx,8), %rsi
cmpq %rsi, 0x8(%rcx,%rdx,8)
je 0x1e57a
leaq (%rcx,%rdx,8), %rcx
movq %rcx, 0xa0(%rsp)
movq %rax, 0x38(%rsp)
movslq 0x110(%rax), %rax
movq %rax, 0xc0(%rsp)
xorl %ebx, %ebx
movq (%rsi,%rbx,8), %rax
testq %rax, %rax
movq %rbx, 0xa8(%rsp)
je 0x1e550
movl 0x58(%rax), %r13d
movq %rax, 0xc8(%rsp)
movl 0x60(%rax), %r15d
movq 0x8(%rsp), %rax
cmpb $0x1, 0x90(%rax)
jne 0x1e1df
movq 0x48(%rsp), %rdi
movl %r13d, %esi
callq 0x384fe
testl %r15d, %r15d
setg %cl
andb %cl, %al
cmpb $0x1, %al
je 0x1e1e8
jmp 0x1e550
testl %r15d, %r15d
jle 0x1e550
cmpl $0x2, %r15d
movl $0x1, %eax
cmovll %eax, %r15d
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
cmpb $0x1, 0x90(%rax)
jne 0x1e21c
movq 0x48(%rsp), %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x38540
testb %al, %al
je 0x1e544
movq 0xc8(%rsp), %rax
movq (%rax), %rax
movq 0xc0(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x50(%rsp)
ucomisd 0x22e86(%rip), %xmm0    # 0x410d0
jbe 0x1e544
leaq 0xf0(%rsp), %rdi
callq 0x204bc
leaq 0xd0(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movl %r13d, %edx
callq 0xb792
movq 0x38(%rsp), %rax
movl 0x48(%rax), %r12d
movl 0x4c(%rax), %ebp
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x78(%rsp), %r14
movq %r14, %rdi
leaq 0x23bf9(%rip), %rdx     # 0x41e96
movq %rdx, %rsi
callq 0xb8a2
movq %r14, (%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
movl %r12d, %edx
movl %ebp, %ecx
movl %r13d, %r8d
movl %ebx, %r9d
callq 0x2061c
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x1e2eb
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x1e310
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x8(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x223b8
cmpq 0xb0(%rsp), %rax
jne 0x1e44b
movq 0x8(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x20440
movq %rax, %r12
movb 0xf0(%rsp), %al
movb %al, (%r12)
leaq 0x8(%r12), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x3150
leaq 0x28(%r12), %rdi
leaq 0x118(%rsp), %rsi
callq 0x3150
leaq 0xf8(%rsp), %rcx
movb 0x48(%rcx), %al
movb %al, 0x50(%r12)
movq 0x40(%rcx), %rax
movq %rax, 0x48(%r12)
leaq 0x58(%r12), %rdi
leaq 0x148(%rsp), %rsi
callq 0x20b88
leaq 0x70(%r12), %rdi
leaq 0x160(%rsp), %rsi
callq 0x20b88
leaq 0x88(%r12), %rdi
leaq 0x178(%rsp), %rsi
callq 0x21a40
leaq 0xf8(%rsp), %rax
movupd 0xb0(%rax), %xmm0
movupd %xmm0, 0xb8(%r12)
leaq 0xc8(%r12), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x20ef0
leaq 0xf8(%rsp), %rax
movupd 0xd8(%rax), %xmm0
movupd %xmm0, 0xe0(%r12)
movq %r12, %rdi
addq $0xf0, %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x218ca
leaq 0xf8(%rsp), %rcx
movl 0x108(%rcx), %eax
movl %eax, 0x110(%r12)
movq 0x100(%rcx), %rax
movq %rax, 0x108(%r12)
movl 0x44(%rsp), %eax
cmpl $0x1, %eax
je 0x1e47f
testl %eax, %eax
jne 0x1e4a6
movq 0x8(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x20440
movq %rax, %rdi
movq 0x38(%rsp), %rsi
movsd 0x50(%rsp), %xmm0
callq 0x2daa6
jmp 0x1e4a6
movq 0x8(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x20440
movq %rax, %rdi
movq 0x38(%rsp), %rsi
movsd 0x50(%rsp), %xmm0
xorl %edx, %edx
callq 0x2dd7c
leaq 0x1e0(%rsp), %rdi
callq 0x1d4e6
movq 0x1b8(%rsp), %rdi
testq %rdi, %rdi
je 0x1e4d0
movq 0x1c8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
leaq 0x178(%rsp), %rdi
callq 0x1d582
leaq 0x160(%rsp), %rdi
callq 0x1d534
leaq 0x148(%rsp), %rdi
callq 0x1d534
movq 0x118(%rsp), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0x1e51c
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x1e541
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x32e0
movb $0x1, %r12b
incq %rbx
cmpq %rbx, %r15
jne 0x1e1f7
movq 0xa8(%rsp), %rbx
incq %rbx
movq 0xa0(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rcx
subq %rsi, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0x1e18e
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x1e596
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x98(%rsp), %rbx
incq %rbx
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %rbx, %rcx
leaq 0x58(%rsp), %r15
ja 0x1e10c
jmp 0x1e5c5
xorl %r12d, %r12d
leaq 0x208(%rsp), %rdi
callq 0x10ef2
leaq 0x10(%rsp), %rdi
callq 0x611e
andb $0x1, %r12b
movl %r12d, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1e5fb
jmp 0x1e5fb
jmp 0x1e65a
movq %rax, %rbx
jmp 0x1e71a
jmp 0x1e65a
jmp 0x1e65a
jmp 0x1e662
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x1e633
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x32e0
jmp 0x1e633
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x1e665
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x32e0
jmp 0x1e665
movq %rax, %rbx
jmp 0x1e6fe
movq %rax, %rbx
leaq 0x1e0(%rsp), %rdi
callq 0x1d4e6
leaq 0x160(%rsp), %r14
movq 0x58(%r14), %rdi
testq %rdi, %rdi
je 0x1e693
movq 0x1c8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
leaq 0x178(%rsp), %rdi
callq 0x1d582
movq %r14, %rdi
callq 0x1d534
leaq 0x148(%rsp), %r14
movq %r14, %rdi
callq 0x1d534
movq -0x30(%r14), %rdi
leaq 0x128(%rsp), %rax
cmpq %rax, %rdi
je 0x1e6d9
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x1e6fe
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x1e71a
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x32e0
leaq 0x208(%rsp), %rdi
callq 0x10ef2
leaq 0x10(%rsp), %rdi
callq 0x611e
movq %rbx, %rdi
callq 0x3530