// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rdi, %r15
xorpd %xmm0, %xmm0
leaq 0x20(%rsp), %rbx
movapd %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
leaq 0x240(%rsp), %rcx
movl $0x0, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0x238(%rsp), %rdi
callq 0x1517c
movq %r14, 0x8(%rsp)
movq %r14, %rdi
movq %r15, 0x40(%rsp)
movq %r15, %rsi
movq %rbx, %rdx
callq 0x359e0
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
cmpq %rsi, %rax
je 0x1d1bd
xorl %r14d, %r14d
leaq 0x238(%rsp), %rbx
xorl %r15d, %r15d
addq %r14, %rsi
movq %rbx, %rdi
callq 0xb866
movl $0x1, (%rax)
incq %r15
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
movq %rax, %rcx
subq %rsi, %rcx
sarq $0x5, %rcx
addq $0x20, %r14
cmpq %r15, %rcx
ja 0x1d18c
cmpq %rsi, %rax
je 0x1d857
movl %ebp, 0x1c(%rsp)
movq 0x8(%rsp), %rax
leaq 0x60(%rax), %rcx
movq %rcx, 0xa0(%rsp)
movq 0x40(%rsp), %rbx
leaq 0x298(%rbx), %rcx
movq %rcx, 0xc8(%rsp)
addq $0x8, %rax
movq %rax, 0x48(%rsp)
xorl %r14d, %r14d
leaq 0x60(%rsp), %r15
xorl %r13d, %r13d
movq %r14, %rcx
shlq $0x5, %rcx
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movq (%rsi,%rcx), %rax
movq 0x8(%rsi,%rcx), %rdx
addq %rax, %rdx
movq %r15, %rdi
movq %rax, %rsi
callq 0x6afc
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x1fdec
movq %rax, %r15
movslq 0x10c(%rax), %r12
movslq 0x110(%rax), %rax
movq %rax, 0xd0(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x3793e
movq %r14, 0xa8(%rsp)
movq (%rax), %rdi
movq 0x8(%rax), %rcx
cmpq %rdi, %rcx
je 0x1d80f
movq %r15, 0x10(%rsp)
xorl %r8d, %r8d
movq %r12, 0xb8(%rsp)
movq %rax, 0xb0(%rsp)
movq %r8, %r15
shlq $0x5, %r15
movslq (%rdi,%r15), %r9
cmpl %r9d, %r12d
je 0x1d7f9
movq 0x1f0(%rbx), %rdx
leaq (%r12,%r12,2), %rsi
movq (%rdx,%rsi,8), %rdx
movq (%rdx,%r9,8), %rdx
movq %rdx, 0xd8(%rsp)
testq %rdx, %rdx
je 0x1d7f9
addq %rdi, %r15
movq 0x8(%r15), %rdx
movq 0x10(%r15), %rsi
cmpq %rdx, %rsi
je 0x1d7f9
movq %r9, 0x50(%rsp)
movq %r8, 0xc0(%rsp)
xorl %ebx, %ebx
movslq (%rdx,%rbx,4), %rbp
movq 0xd8(%rsp), %rax
movq (%rax), %rax
movq 0xd0(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%rbp,8), %xmm0
movsd %xmm0, 0x58(%rsp)
ucomisd 0x22db5(%rip), %xmm0    # 0x400d0
jbe 0x1d7bf
leaq 0x100(%rsp), %rdi
callq 0x1fe68
leaq 0xe0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0xb6e8
movq 0x10(%rsp), %rax
movl 0x48(%rax), %r13d
movl 0x4c(%rax), %r14d
leaq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x80(%rsp), %r12
movq %r12, %rdi
leaq 0x23b3f(%rip), %rdx     # 0x40eb6
movq %rdx, %rsi
callq 0xb7d0
movq %r12, (%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
movl %r13d, %edx
movl %r14d, %ecx
movq 0x50(%rsp), %r8
movl %ebp, %r9d
callq 0x1ffc8
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x1d3cb
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x1d3f0
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x21d54
cmpq 0x48(%rsp), %rax
je 0x1d5a5
leaq 0x108(%rsp), %rdi
leaq 0x22f74(%rip), %rsi     # 0x40390
callq 0x30c0
testl %eax, %eax
je 0x1d6be
leaq 0x108(%rsp), %rdi
leaq 0x22f5f(%rip), %rsi     # 0x40397
callq 0x30c0
testl %eax, %eax
je 0x1d6be
leaq 0x218(%rsp), %r12
movq %r12, %rdi
leaq 0x22f43(%rip), %rsi     # 0x4039a
leaq 0x108(%rsp), %r14
movq %r14, %rdx
callq 0x201d3
movq %r14, %rdi
movq %r12, %rsi
callq 0x3380
movq 0x218(%rsp), %rdi
leaq 0x228(%rsp), %rax
cmpq %rax, %rdi
je 0x1d497
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x21d54
cmpq 0x48(%rsp), %rax
jne 0x1d6be
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x1fdec
movq %rax, %r13
movb 0x100(%rsp), %al
movb %al, (%r13)
leaq 0x8(%r13), %rdi
leaq 0x108(%rsp), %rsi
callq 0x3150
leaq 0x28(%r13), %rdi
leaq 0x128(%rsp), %rsi
callq 0x3150
leaq 0x108(%rsp), %rcx
movb 0x48(%rcx), %al
movb %al, 0x50(%r13)
movq 0x40(%rcx), %rax
movq %rax, 0x48(%r13)
leaq 0x58(%r13), %rdi
leaq 0x158(%rsp), %rsi
callq 0x20524
leaq 0x70(%r13), %rdi
leaq 0x170(%rsp), %rsi
callq 0x20524
leaq 0x88(%r13), %rdi
leaq 0x188(%rsp), %rsi
callq 0x213d0
leaq 0x108(%rsp), %rax
movupd 0xb0(%rax), %xmm0
movupd %xmm0, 0xb8(%r13)
leaq 0xc8(%r13), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x208ac
leaq 0x108(%rsp), %rax
movupd 0xd8(%rax), %xmm0
movupd %xmm0, 0xe0(%r13)
movq %r13, %rdi
addq $0xf0, %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x2123a
jmp 0x1d691
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x1fdec
movq %rax, %r13
movb 0x100(%rsp), %al
movb %al, (%r13)
leaq 0x8(%r13), %rdi
leaq 0x108(%rsp), %rsi
callq 0x3150
leaq 0x28(%r13), %rdi
leaq 0x128(%rsp), %rsi
callq 0x3150
leaq 0x108(%rsp), %rcx
movb 0x48(%rcx), %al
movb %al, 0x50(%r13)
movq 0x40(%rcx), %rax
movq %rax, 0x48(%r13)
leaq 0x58(%r13), %rdi
leaq 0x158(%rsp), %rsi
callq 0x20524
leaq 0x70(%r13), %rdi
leaq 0x170(%rsp), %rsi
callq 0x20524
leaq 0x88(%r13), %rdi
leaq 0x188(%rsp), %rsi
callq 0x213d0
leaq 0x108(%rsp), %rax
movupd 0xb0(%rax), %xmm0
movupd %xmm0, 0xb8(%r13)
leaq 0xc8(%r13), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x208ac
leaq 0x108(%rsp), %rax
movupd 0xd8(%rax), %xmm0
movupd %xmm0, 0xe0(%r13)
movq %r13, %rdi
addq $0xf0, %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x2123a
leaq 0x108(%rsp), %rsi
movl 0x108(%rsi), %eax
movl %eax, 0x110(%r13)
movq 0x100(%rsi), %rax
movq %rax, 0x108(%r13)
leaq 0x20(%rsp), %rdi
callq 0x17546
movl 0x1c(%rsp), %eax
cmpl $0x1, %eax
je 0x1d6f2
testl %eax, %eax
jne 0x1d719
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x1fdec
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movsd 0x58(%rsp), %xmm0
callq 0x2d28e
jmp 0x1d719
movq 0x8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x1fdec
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movsd 0x58(%rsp), %xmm0
xorl %edx, %edx
callq 0x2d51a
leaq 0x1f0(%rsp), %rdi
callq 0x1cee0
movq 0x1c8(%rsp), %rdi
testq %rdi, %rdi
je 0x1d743
movq 0x1d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
leaq 0x188(%rsp), %rdi
callq 0x1cf88
leaq 0x170(%rsp), %rdi
callq 0x1cf34
leaq 0x158(%rsp), %rdi
callq 0x1cf34
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x1d78f
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0x1d7b4
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x8(%r15), %rdx
movq 0x10(%r15), %rsi
movb $0x1, %r13b
incq %rbx
movq %rsi, %rax
subq %rdx, %rax
sarq $0x2, %rax
cmpq %rbx, %rax
ja 0x1d2e9
movq 0xb0(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rcx
movq 0x40(%rsp), %rbx
movq 0xb8(%rsp), %r12
movq 0xc0(%rsp), %r8
incq %r8
movq %rcx, %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %r8, %rdx
ja 0x1d28e
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x1d82b
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xa8(%rsp), %r14
incq %r14
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %r14, %rax
leaq 0x60(%rsp), %r15
ja 0x1d203
jmp 0x1d85a
xorl %r13d, %r13d
leaq 0x238(%rsp), %rdi
callq 0x10d92
leaq 0x20(%rsp), %rdi
callq 0x6186
andb $0x1, %r13b
movl %r13d, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1d892
jmp 0x1d892
jmp 0x1d8f4
jmp 0x1d8f4
movq %rax, %rbx
jmp 0x1d9b6
jmp 0x1d8fc
jmp 0x1d8fc
jmp 0x1d8fc
movq %rax, %rbx
jmp 0x1d8cd
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x1d8cd
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x1d8ff
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x32e0
jmp 0x1d8ff
movq %rax, %rbx
jmp 0x1d99a
movq %rax, %rbx
leaq 0x1f0(%rsp), %rdi
callq 0x1cee0
movq 0x1c8(%rsp), %rdi
testq %rdi, %rdi
je 0x1d929
movq 0x1d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
leaq 0x188(%rsp), %rdi
callq 0x1cf88
leaq 0x170(%rsp), %rdi
callq 0x1cf34
leaq 0x158(%rsp), %rdi
callq 0x1cf34
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x1d975
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0x1d99a
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x1d9b6
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x32e0
leaq 0x238(%rsp), %rdi
callq 0x10d92
leaq 0x20(%rsp), %rdi
callq 0x6186
movq %rbx, %rdi
callq 0x3530