// File: /workspace/github_cpp_makefile_star2_O2/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 0x40(%rsp), %rbx
movapd %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0xa8(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rbx, %rdi
callq 0x515e
leaq 0xa0(%rsp), %rdi
callq 0x1101c
movq %r14, 0x8(%rsp)
movq %r14, %rdi
movq %r15, 0x28(%rsp)
movq %r15, %rsi
movq %rbx, %rdx
callq 0x29f28
xorl %r14d, %r14d
leaq 0xa0(%rsp), %rbx
xorl %r15d, %r15d
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rax
movq %rax, %rcx
subq %rsi, %rcx
sarq $0x5, %rcx
cmpq %r15, %rcx
jbe 0x17f5a
addq %r14, %rsi
movq %rbx, %rdi
callq 0xa262
movl $0x1, (%rax)
incq %r15
addq $0x20, %r14
jmp 0x17f27
movq 0x8(%rsp), %rcx
leaq 0x60(%rcx), %rdx
movq %rdx, 0x58(%rsp)
movq 0x28(%rsp), %rdx
addq $0x298, %rdx            # imm = 0x298
movq %rdx, 0x80(%rsp)
addq $0x8, %rcx
movq %rcx, 0x30(%rsp)
xorl %ecx, %ecx
leaq 0xf0(%rsp), %r14
leaq 0x130(%rsp), %r15
xorl %r13d, %r13d
movl %ebp, 0x1c(%rsp)
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rcx, %rax
jbe 0x182d7
movq %rcx, 0x60(%rsp)
movq %rcx, %rax
shlq $0x5, %rax
addq %rax, %rsi
movq %r14, %rdi
callq 0x33c0
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x19b24
movslq 0x10c(%rax), %r14
movq %rax, 0x10(%rsp)
movslq 0x110(%rax), %rbx
movq 0x58(%rsp), %rdi
callq 0x2b5fa
movq %rax, 0x20(%rsp)
movq %r14, 0x78(%rsp)
imulq $0x18, %r14, %rax
movq %rax, 0x68(%rsp)
imulq $0x18, %rbx, %rax
movq %rax, 0x88(%rsp)
xorl %edi, %edi
movq 0x20(%rsp), %rdx
movq (%rdx), %r8
movq 0x8(%rdx), %rax
subq %r8, %rax
sarq $0x5, %rax
cmpq %rdi, %rax
jbe 0x182b0
movq %rdi, %rax
shlq $0x5, %rax
movslq (%r8,%rax), %rbp
cmpl %ebp, 0x78(%rsp)
je 0x182a8
movq 0x28(%rsp), %rcx
movq 0x1f0(%rcx), %rcx
movq 0x68(%rsp), %rsi
movq (%rcx,%rsi), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, 0x98(%rsp)
testq %rcx, %rcx
je 0x182a8
movq %rdi, 0x70(%rsp)
addq %rax, %r8
xorl %ebx, %ebx
movq %r8, 0x90(%rsp)
movq 0x8(%r8), %rax
movq 0x10(%r8), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0x1829e
movslq (%rax,%rbx,4), %r12
movq 0x98(%rsp), %rax
movq (%rax), %rax
movq 0x88(%rsp), %rcx
movq (%rax,%rcx), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x38(%rsp)
ucomisd 0x1a00c(%rip), %xmm0    # 0x320d0
jbe 0x1828e
leaq 0x150(%rsp), %rdi
callq 0x19b8a
leaq 0xd0(%rsp), %rdi
movq 0x80(%rsp), %rsi
movl %ebp, %edx
callq 0xa0b8
movq 0x10(%rsp), %rax
movl 0x48(%rax), %r13d
movl 0x4c(%rax), %r14d
movq %r15, %rdi
leaq 0x1adb1(%rip), %rsi     # 0x32eb6
leaq 0x110(%rsp), %rdx
callq 0x9f86
movq %r15, (%rsp)
leaq 0x150(%rsp), %rdi
movq %rbp, %r8
movq %r15, %rbp
leaq 0xd0(%rsp), %r15
movq %r15, %rsi
movl %r13d, %edx
movl %r14d, %ecx
movq %r8, %r13
movl %r12d, %r9d
callq 0x19c98
movq %rbp, %r14
movq %rbp, %rdi
callq 0x3578
movq %r15, %rdi
callq 0x3578
movq 0x8(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x1b8b0
cmpq 0x30(%rsp), %rax
movq %r14, %r15
movq %r13, %rbp
je 0x181ef
leaq 0x158(%rsp), %rdi
leaq 0x1a1fd(%rip), %rsi     # 0x3237e
callq 0x106a8
testb %al, %al
je 0x18223
leaq 0x158(%rsp), %rdi
leaq 0x1a1e8(%rip), %rsi     # 0x32385
callq 0x106a8
testb %al, %al
je 0x18223
leaq 0x110(%rsp), %r12
movq %r12, %rdi
leaq 0x1a1d0(%rip), %rsi     # 0x32388
leaq 0x158(%rsp), %r14
movq %r14, %rdx
callq 0x19e19
movq %r14, %rdi
movq %r12, %rsi
callq 0x3360
movq %r12, %rdi
callq 0x3578
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x1b8b0
cmpq 0x30(%rsp), %rax
jne 0x18223
movq 0x8(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x19b24
movq %rax, %rdi
leaq 0x150(%rsp), %rsi
callq 0x19d82
leaq 0x40(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x129cc
movl 0x1c(%rsp), %eax
cmpl $0x1, %eax
je 0x18257
testl %eax, %eax
jne 0x1827e
movq 0x8(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x19b24
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movsd 0x38(%rsp), %xmm0
callq 0x23c76
jmp 0x1827e
movq 0x8(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x19b24
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movsd 0x38(%rsp), %xmm0
xorl %edx, %edx
callq 0x23e4e
leaq 0x150(%rsp), %rdi
callq 0x17b24
movb $0x1, %r13b
incq %rbx
movq 0x90(%rsp), %r8
jmp 0x1807d
movq 0x20(%rsp), %rdx
movq 0x70(%rsp), %rdi
incq %rdi
jmp 0x18015
leaq 0xf0(%rsp), %r14
movq %r14, %rdi
callq 0x3578
movq 0x60(%rsp), %rcx
incq %rcx
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rax
jmp 0x17f9e
leaq 0xa0(%rsp), %rdi
callq 0xd1fa
leaq 0x40(%rsp), %rdi
callq 0x5166
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 0x1830f
jmp 0x1833e
jmp 0x1830f
jmp 0x1833e
movq %rax, %rbx
jmp 0x18360
jmp 0x18343
jmp 0x18343
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x3578
jmp 0x1832f
jmp 0x18343
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x3578
jmp 0x18346
movq %rax, %rbx
jmp 0x18353
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x17b24
leaq 0xf0(%rsp), %rdi
callq 0x3578
leaq 0xa0(%rsp), %rdi
callq 0xd1fa
leaq 0x40(%rsp), %rdi
callq 0x5166
movq %rbx, %rdi
callq 0x34f0