// File: /workspace/github_cpp_makefile_star2_O1/neubig[P]egret/Egret/src/Forest-Berkeley.cpp
// Function: genUnaryNode_byLabel_constrained_berkeley(BerkeleyRuleSet const&, Node&, DecodeType)
bool genUnaryNode_byLabel_constrained_berkeley(const BerkeleyRuleSet& ruleSet, Node& node, DecodeType decodetype)
{
	bool mark=false;
	vector<string> ntPool;
	map<string,int> ntMap;
	ntPool.clear();
	ntMap.clear();
	node.setUnaryInOrder_berkeley(ruleSet,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 ch=oldLb.state();
		int chsub=oldLb.subState();

		const AllowStateInfo& asi=node.allowStateInfo();
		const vector<pair<int,vector<int> > >& allowStateAndSubStates=asi.allowStateAndSubStates();

		for(int i=0;(size_t)i<allowStateAndSubStates.size();i++)
		{
			int pr=allowStateAndSubStates[i].first;
			if(ch==pr)continue;
			const BerkeleyUnaryRule* rule=ruleSet.getUnaryRuleByRule(ch,pr);
			if(rule==NULL)continue;

			const vector<int>& subStates=allowStateAndSubStates[i].second;
			for(int j=0;(size_t)j<subStates.size();j++)
			{
				int prsub=subStates[j];
				double ruleScore=rule->getScore(chsub,prsub);
				if(ruleScore>-1E10)
				{
					Label label;
					label.init(ruleSet.state2term(pr),oldLb.start(),oldLb.stop(),pr,prsub);
					
					if(node.find(label.nt())==node.end())
					{
						node[label.nt()]=label;
						ntPool.push_back(label.nt());
					}
					else if(label.nt()!="ROOT_0"&&label.nt()!="S1")
					{
						label.nt()="u*"+label.nt();
						if(node.find(label.nt())==node.end())
						{
							node[label.nt()]=label;
							ntPool.push_back(label.nt());
						}
					}
					
					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 $0x268, %rsp            # imm = 0x268
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 0x240(%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), %r14
cmpq %rbx, %r14
je 0x1d774
leaq 0x10(%rbx), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x1d75f
movq (%r15), %rsi
incq %rsi
callq 0x32e0
leaq 0x20(%r15), %rax
addq $0x10, %r15
cmpq %r14, %r15
movq %rax, %r15
jne 0x1d74b
movq %rbx, 0x18(%rsp)
leaq 0x238(%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 0x1d7dd
xorl %r14d, %r14d
leaq 0x238(%rsp), %rbx
xorl %r15d, %r15d
addq %r14, %rsi
movq %rbx, %rdi
callq 0xb932
movl $0x1, (%rax)
incq %r15
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %r14
cmpq %r15, %rax
ja 0x1d7af
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x1de53
movq 0x8(%rsp), %rcx
leaq 0x60(%rcx), %rdx
movq %rdx, 0x98(%rsp)
movq 0x30(%rsp), %rdx
addq $0x298, %rdx            # imm = 0x298
movq %rdx, 0xc0(%rsp)
addq $0x8, %rcx
movq %rcx, 0x48(%rsp)
xorl %edx, %edx
leaq 0x58(%rsp), %rbx
xorl %r15d, %r15d
movl %ebp, 0x44(%rsp)
movq %rdx, 0xa0(%rsp)
movq %rdx, %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 %rbx, %rdi
callq 0x6a88
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x20440
movslq 0x10c(%rax), %rbx
movq %rax, 0x38(%rsp)
movslq 0x110(%rax), %rax
movq %rax, 0xc8(%rsp)
movq 0x98(%rsp), %rdi
callq 0x384f8
movq (%rax), %rdi
cmpq %rdi, 0x8(%rax)
je 0x1de0b
xorl %esi, %esi
movq %rbx, 0xb0(%rsp)
movq %rax, 0xa8(%rsp)
movq %rsi, %rax
shlq $0x5, %rax
movslq (%rdi,%rax), %rbp
cmpl %ebp, %ebx
movq %rsi, 0xb8(%rsp)
je 0x1ddd9
movq 0x30(%rsp), %rcx
movq 0x1f0(%rcx), %rcx
leaq (%rbx,%rbx,2), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, 0xd8(%rsp)
testq %rcx, %rcx
je 0x1ddd9
addq %rax, %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
je 0x1ddd9
movq %rdi, 0xd0(%rsp)
xorl %r12d, %r12d
movslq (%rax,%r12,4), %rbx
movq 0xd8(%rsp), %rax
movq (%rax), %rax
movq 0xc8(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x50(%rsp)
ucomisd 0x23794(%rip), %xmm0    # 0x410d0
jbe 0x1ddb6
leaq 0x100(%rsp), %rdi
callq 0x204bc
leaq 0xe0(%rsp), %rdi
movq 0xc0(%rsp), %rsi
movl %ebp, %edx
callq 0xb792
movq 0x38(%rsp), %rax
movl 0x48(%rax), %r15d
movl 0x4c(%rax), %r14d
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x78(%rsp), %r13
movq %r13, %rdi
leaq 0x24507(%rip), %rdx     # 0x41e96
movq %rdx, %rsi
callq 0xb8a2
movq %r13, (%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
movl %r15d, %edx
movl %r14d, %ecx
movl %ebp, %r8d
movl %ebx, %r9d
callq 0x2061c
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x1d9de
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x1da03
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x223b8
cmpq 0x48(%rsp), %rax
je 0x1dbae
leaq 0x108(%rsp), %rdi
leaq 0x2394f(%rip), %rsi     # 0x4137e
callq 0x30c0
testl %eax, %eax
je 0x1dcbd
leaq 0x108(%rsp), %rdi
leaq 0x2393a(%rip), %rsi     # 0x41385
callq 0x30c0
testl %eax, %eax
je 0x1dcbd
leaq 0x218(%rsp), %r14
movq %r14, %rdi
leaq 0x2391e(%rip), %rsi     # 0x41388
leaq 0x108(%rsp), %rbx
movq %rbx, %rdx
callq 0x20828
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3380
movq 0x218(%rsp), %rdi
leaq 0x228(%rsp), %rax
cmpq %rax, %rdi
je 0x1daaa
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x223b8
cmpq 0x48(%rsp), %rax
jne 0x1dcbd
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x20440
movq %rax, %r15
movb 0x100(%rsp), %al
movb %al, (%r15)
leaq 0x8(%r15), %rdi
leaq 0x108(%rsp), %rsi
callq 0x3150
leaq 0x28(%r15), %rdi
leaq 0x128(%rsp), %rsi
callq 0x3150
leaq 0x148(%rsp), %rcx
movb 0x8(%rcx), %al
movb %al, 0x50(%r15)
movq (%rcx), %rax
movq %rax, 0x48(%r15)
leaq 0x58(%r15), %rdi
leaq 0x158(%rsp), %rsi
callq 0x20b88
leaq 0x70(%r15), %rdi
leaq 0x170(%rsp), %rsi
callq 0x20b88
leaq 0x88(%r15), %rdi
leaq 0x188(%rsp), %rsi
callq 0x21a40
leaq 0x1b8(%rsp), %rax
movupd (%rax), %xmm0
movupd %xmm0, 0xb8(%r15)
leaq 0xc8(%r15), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x20ef0
leaq 0x1e0(%rsp), %rax
movupd (%rax), %xmm0
movupd %xmm0, 0xe0(%r15)
movq %r15, %rdi
addq $0xf0, %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x218ca
jmp 0x1dc90
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x20440
movq %rax, %r15
movb 0x100(%rsp), %al
movb %al, (%r15)
leaq 0x8(%r15), %rdi
leaq 0x108(%rsp), %rsi
callq 0x3150
leaq 0x28(%r15), %rdi
leaq 0x128(%rsp), %rsi
callq 0x3150
leaq 0x148(%rsp), %rcx
movb 0x8(%rcx), %al
movb %al, 0x50(%r15)
movq (%rcx), %rax
movq %rax, 0x48(%r15)
leaq 0x58(%r15), %rdi
leaq 0x158(%rsp), %rsi
callq 0x20b88
leaq 0x70(%r15), %rdi
leaq 0x170(%rsp), %rsi
callq 0x20b88
leaq 0x88(%r15), %rdi
leaq 0x188(%rsp), %rsi
callq 0x21a40
leaq 0x1b8(%rsp), %rax
movupd (%rax), %xmm0
movupd %xmm0, 0xb8(%r15)
leaq 0xc8(%r15), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x20ef0
leaq 0x1e0(%rsp), %rax
movupd (%rax), %xmm0
movupd %xmm0, 0xe0(%r15)
movq %r15, %rdi
addq $0xf0, %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x218ca
leaq 0x108(%rsp), %rsi
movl 0x108(%rsi), %eax
movl %eax, 0x110(%r15)
movq 0x100(%rsi), %rax
movq %rax, 0x108(%r15)
leaq 0x10(%rsp), %rdi
callq 0x17a82
movl 0x44(%rsp), %eax
cmpl $0x1, %eax
je 0x1dcf1
testl %eax, %eax
jne 0x1dd18
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x20440
movq %rax, %rdi
movq 0x38(%rsp), %rsi
movsd 0x50(%rsp), %xmm0
callq 0x2daa6
jmp 0x1dd18
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x20440
movq %rax, %rdi
movq 0x38(%rsp), %rsi
movsd 0x50(%rsp), %xmm0
xorl %edx, %edx
callq 0x2dd7c
leaq 0x1f0(%rsp), %rdi
callq 0x1d4e6
movq 0x1c8(%rsp), %rdi
testq %rdi, %rdi
je 0x1dd42
movq 0x1d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
leaq 0x188(%rsp), %rdi
callq 0x1d582
leaq 0x170(%rsp), %rdi
callq 0x1d534
leaq 0x158(%rsp), %rdi
callq 0x1d534
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x1dd8e
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0x1ddb3
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x32e0
movb $0x1, %r15b
incq %r12
movq 0xd0(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r12, %rcx
ja 0x1d90a
movq 0xb8(%rsp), %rsi
incq %rsi
movq 0xa8(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rcx
subq %rdi, %rcx
sarq $0x5, %rcx
cmpq %rsi, %rcx
movq 0xb0(%rsp), %rbx
ja 0x1d8aa
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x1de27
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xa0(%rsp), %rdx
incq %rdx
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq %rdx, %rcx
leaq 0x58(%rsp), %rbx
ja 0x1d829
jmp 0x1de56
xorl %r15d, %r15d
leaq 0x238(%rsp), %rdi
callq 0x10ef2
leaq 0x10(%rsp), %rdi
callq 0x611e
andb $0x1, %r15b
movl %r15d, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1de8e
jmp 0x1de8e
jmp 0x1deed
jmp 0x1deed
movq %rax, %rbx
jmp 0x1dfad
jmp 0x1def5
jmp 0x1def5
jmp 0x1def5
movq %rax, %rbx
jmp 0x1dec6
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x1dec6
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x1def8
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x32e0
jmp 0x1def8
movq %rax, %rbx
jmp 0x1df91
movq %rax, %rbx
leaq 0x1f0(%rsp), %rdi
callq 0x1d4e6
leaq 0x170(%rsp), %r14
movq 0x58(%r14), %rdi
testq %rdi, %rdi
je 0x1df26
movq 0x1d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
leaq 0x188(%rsp), %rdi
callq 0x1d582
movq %r14, %rdi
callq 0x1d534
leaq 0x158(%rsp), %r14
movq %r14, %rdi
callq 0x1d534
movq -0x30(%r14), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x1df6c
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0x1df91
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x1dfad
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x32e0
leaq 0x238(%rsp), %rdi
callq 0x10ef2
leaq 0x10(%rsp), %rdi
callq 0x611e
movq %rbx, %rdi
callq 0x3530