// File: /workspace/github_cpp_makefile_star2_O2/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 $0x248, %rsp            # imm = 0x248
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
xorpd %xmm0, %xmm0
leaq 0x50(%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, 0x10(%rsp)
movq %r14, %rdi
movq %r15, 0x30(%rsp)
movq %r15, %rsi
movq %rbx, %rdx
callq 0x29f28
xorl %r15d, %r15d
leaq 0xa0(%rsp), %rbx
xorl %r12d, %r12d
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rax
movq %rax, %rcx
subq %rsi, %rcx
sarq $0x5, %rcx
cmpq %r12, %rcx
jbe 0x18435
addq %r15, %rsi
movq %rbx, %rdi
callq 0xa262
movl $0x1, (%rax)
incq %r12
addq $0x20, %r15
jmp 0x18402
movl %ebp, 0x2c(%rsp)
movq 0x10(%rsp), %rdx
leaq 0x60(%rdx), %rcx
movq %rcx, 0x40(%rsp)
movq 0x30(%rsp), %rcx
addq $0x298, %rcx            # imm = 0x298
movq %rcx, 0x90(%rsp)
leaq 0x8(%rdx), %rcx
movq %rcx, 0x88(%rsp)
leaq 0xf0(%rsp), %r15
leaq 0x110(%rsp), %r14
xorl %ecx, %ecx
xorl %ebp, %ebp
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rcx, %rax
jbe 0x18730
movq %rcx, 0x70(%rsp)
movq %rcx, %rax
shlq $0x5, %rax
addq %rax, %rsi
movq %r15, %rdi
callq 0x33c0
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x19b24
movq %rax, %rcx
movslq 0x10c(%rax), %rax
movq %rcx, 0x20(%rsp)
movslq 0x110(%rcx), %rcx
imulq $0x18, %rax, %rbx
movq 0x30(%rsp), %rax
addq 0x220(%rax), %rbx
imulq $0x18, %rcx, %rax
movq %rax, 0x98(%rsp)
xorl %r13d, %r13d
movq %rbx, 0x78(%rsp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r13, %rcx
jbe 0x18711
movq (%rax,%r13,8), %rax
testq %rax, %rax
je 0x18709
movl 0x58(%rax), %ecx
movl %ecx, 0xc(%rsp)
movq %rax, 0x38(%rsp)
movl 0x60(%rax), %r12d
movq 0x10(%rsp), %rax
cmpb $0x1, 0x90(%rax)
jne 0x18541
movq 0x40(%rsp), %rdi
movl 0xc(%rsp), %esi
callq 0x2b600
testb %al, %al
je 0x18709
movq %r13, 0x80(%rsp)
testl %r12d, %r12d
movl $0x0, %eax
cmovlel %eax, %r12d
xorl %r13d, %r13d
movq 0x38(%rsp), %rbx
cmpq %r13, %r12
je 0x186f4
movq 0x10(%rsp), %rax
cmpb $0x1, 0x90(%rax)
jne 0x1858d
movq 0x40(%rsp), %rdi
movl 0xc(%rsp), %esi
movl %r13d, %edx
callq 0x2b628
testb %al, %al
je 0x186ec
movq (%rbx), %rax
movq 0x98(%rsp), %rcx
movq (%rax,%rcx), %rax
movsd (%rax,%r13,8), %xmm0
movsd %xmm0, 0x48(%rsp)
ucomisd 0x19b20(%rip), %xmm0    # 0x320d0
jbe 0x186ec
leaq 0x130(%rsp), %rdi
callq 0x19b8a
leaq 0xd0(%rsp), %rdi
movq 0x90(%rsp), %rsi
movl 0xc(%rsp), %edx
callq 0xa0b8
movq 0x20(%rsp), %rax
movl 0x48(%rax), %ebp
movl 0x4c(%rax), %r15d
movq %r14, %rdi
leaq 0x1a8c4(%rip), %rsi     # 0x32eb6
leaq 0x1f(%rsp), %rdx
callq 0x9f86
movq %r14, (%rsp)
leaq 0x130(%rsp), %rdi
movq %r14, %rbx
leaq 0xd0(%rsp), %r14
movq %r14, %rsi
movl %ebp, %edx
movl %r15d, %ecx
movl 0xc(%rsp), %r8d
movl %r13d, %r9d
callq 0x19c98
movq %rbx, %r15
movq %rbx, %rdi
callq 0x3578
movq %r14, %rdi
callq 0x3578
movq 0x10(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x1b8b0
cmpq 0x88(%rsp), %rax
movq %r15, %r14
movq 0x38(%rsp), %rbx
jne 0x18681
movq 0x10(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x19b24
movq %rax, %rdi
leaq 0x130(%rsp), %rsi
callq 0x19d82
movl 0x2c(%rsp), %eax
cmpl $0x1, %eax
je 0x186b5
testl %eax, %eax
jne 0x186dc
movq 0x10(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x19b24
movq %rax, %rdi
movq 0x20(%rsp), %rsi
movsd 0x48(%rsp), %xmm0
callq 0x23c76
jmp 0x186dc
movq 0x10(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x19b24
movq %rax, %rdi
movq 0x20(%rsp), %rsi
movsd 0x48(%rsp), %xmm0
xorl %edx, %edx
callq 0x23e4e
leaq 0x130(%rsp), %rdi
callq 0x17b24
movb $0x1, %bpl
incq %r13
jmp 0x1855d
leaq 0xf0(%rsp), %r15
movq 0x78(%rsp), %rbx
movq 0x80(%rsp), %r13
incq %r13
jmp 0x184e9
movq %r15, %rdi
callq 0x3578
movq 0x70(%rsp), %rcx
incq %rcx
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rax
jmp 0x1847b
leaq 0xa0(%rsp), %rdi
callq 0xd1fa
leaq 0x50(%rsp), %rdi
callq 0x5166
andb $0x1, %bpl
movl %ebp, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18765
jmp 0x18765
jmp 0x18794
movq %rax, %rbx
jmp 0x187b6
jmp 0x18794
movq %rax, %rbx
jmp 0x18785
jmp 0x18794
jmp 0x18799
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x3578
leaq 0xd0(%rsp), %rdi
callq 0x3578
jmp 0x1879c
movq %rax, %rbx
jmp 0x187a9
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x17b24
leaq 0xf0(%rsp), %rdi
callq 0x3578
leaq 0xa0(%rsp), %rdi
callq 0xd1fa
leaq 0x50(%rsp), %rdi
callq 0x5166
movq %rbx, %rdi
callq 0x34f0