// File: 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
movq %rsp, %rbp
subq $0x3f0, %rsp            # imm = 0x3F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movb $0x0, -0x15(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x8340
leaq -0x60(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x25300
movq -0x288(%rbp), %rdi
callq 0x8360
movq -0x290(%rbp), %rdi
callq 0x34100
movq -0x288(%rbp), %rdx
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x77d20
jmp 0x482a8
movl $0x0, -0x70(%rbp)
movslq -0x70(%rbp), %rax
movq %rax, -0x298(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x87f0
movq %rax, %rcx
movq -0x298(%rbp), %rax
cmpq %rcx, %rax
jae 0x4831d
movslq -0x70(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x8810
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
callq 0x1d350
movq %rax, -0x2a0(%rbp)
jmp 0x482f4
movq -0x2a0(%rbp), %rax
movl $0x1, (%rax)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x482af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x48b2b
movl $0x0, -0x74(%rbp)
movslq -0x74(%rbp), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x87f0
movq %rax, %rcx
movq -0x2a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x48aff
movslq -0x74(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x8810
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
callq 0x4160
jmp 0x48369
movq -0x10(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x4b350
movq %rax, -0x2b0(%rbp)
jmp 0x48382
movq -0x2b0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x4b430
movl %eax, -0x2b4(%rbp)
jmp 0x483a4
movl -0x2b4(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x4b450
movl %eax, -0x2b8(%rbp)
jmp 0x483c4
movl -0x2b8(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x45a40
movq %rax, -0x2c0(%rbp)
jmp 0x483e2
movq -0x2c0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x7a7c0
movq %rax, -0x2c8(%rbp)
jmp 0x48405
movq -0x2c8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl $0x0, -0xbc(%rbp)
movslq -0xbc(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x45a60
movq %rax, %rcx
movq -0x2d0(%rbp), %rax
cmpq %rcx, %rax
jae 0x48ad7
movq -0xb8(%rbp), %rdi
movslq -0xbc(%rbp), %rsi
callq 0x45a80
movl (%rax), %eax
movl %eax, -0xc0(%rbp)
movl -0xa4(%rbp), %eax
cmpl -0xc0(%rbp), %eax
jne 0x48489
jmp 0x48ac3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x48af1
movq -0x8(%rbp), %rdi
movl -0xa4(%rbp), %esi
movl -0xc0(%rbp), %edx
callq 0x456e0
movq %rax, -0x2d8(%rbp)
jmp 0x484a7
movq -0x2d8(%rbp), %rax
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
jne 0x484c4
jmp 0x48ac3
movq -0xb8(%rbp), %rdi
movslq -0xbc(%rbp), %rsi
callq 0x45a80
addq $0x8, %rax
movq %rax, -0xd0(%rbp)
movl $0x0, -0xd4(%rbp)
movslq -0xd4(%rbp), %rax
movq %rax, -0x2e0(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x16990
movq %rax, %rcx
movq -0x2e0(%rbp), %rax
cmpq %rcx, %rax
jae 0x48ac1
movq -0xd0(%rbp), %rdi
movslq -0xd4(%rbp), %rsi
callq 0x457e0
movl (%rax), %eax
movl %eax, -0xd8(%rbp)
movq -0xc8(%rbp), %rdi
movl -0xa8(%rbp), %esi
movl -0xd8(%rbp), %edx
callq 0x45710
movsd %xmm0, -0x2e8(%rbp)
jmp 0x48556
movsd -0x2e8(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd -0xe0(%rbp), %xmm0
movsd 0x47b42(%rip), %xmm1    # 0x900b8
ucomisd %xmm1, %xmm0
jbe 0x48aab
leaq -0x1f8(%rbp), %rdi
callq 0x4b470
jmp 0x4858e
movq -0x8(%rbp), %rsi
movl -0xc0(%rbp), %edx
leaq -0x218(%rbp), %rdi
callq 0x4b6f0
jmp 0x485a6
movq -0xa0(%rbp), %rdi
callq 0x4b730
movl %eax, -0x2ec(%rbp)
jmp 0x485ba
movq -0xa0(%rbp), %rdi
callq 0x4b750
movl %eax, -0x2f0(%rbp)
jmp 0x485ce
movl -0xc0(%rbp), %eax
movl %eax, -0x300(%rbp)
movl -0xd8(%rbp), %eax
movl %eax, -0x2fc(%rbp)
leaq -0x239(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x4660
movq -0x2f8(%rbp), %rdx
leaq 0x4884f(%rip), %rsi     # 0x90e56
leaq -0x238(%rbp), %rdi
callq 0x1c730
jmp 0x48615
movl -0x2fc(%rbp), %r9d
movl -0x300(%rbp), %r8d
movl -0x2f0(%rbp), %ecx
movl -0x2ec(%rbp), %edx
movq %rsp, %rax
leaq -0x238(%rbp), %rsi
movq %rsi, (%rax)
leaq -0x1f8(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x4b5b0
jmp 0x48651
leaq -0x238(%rbp), %rdi
callq 0x4728
leaq -0x239(%rbp), %rdi
callq 0x43f0
leaq -0x218(%rbp), %rdi
callq 0x4728
movq -0x10(%rbp), %rax
movq %rax, -0x310(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x308(%rbp)
jmp 0x48695
movq -0x308(%rbp), %rsi
movq -0x310(%rbp), %rdi
callq 0x4b7a0
movq %rax, -0x318(%rbp)
jmp 0x486b1
movq -0x318(%rbp), %rax
movq %rax, -0x248(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4b7f0
movq %rax, -0x250(%rbp)
leaq -0x248(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x4b770
testb $0x1, %al
jne 0x486eb
jmp 0x487ca
movq -0x10(%rbp), %rax
movq %rax, -0x328(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x320(%rbp)
jmp 0x4870b
movq -0x320(%rbp), %rsi
movq -0x328(%rbp), %rdi
callq 0x4b350
movq %rax, -0x330(%rbp)
jmp 0x48727
movq -0x330(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x4b820
jmp 0x4873c
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x338(%rbp)
jmp 0x48751
movq -0x338(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x37000
jmp 0x48763
jmp 0x489c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x48a9d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x487b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x487ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x4728
leaq -0x239(%rbp), %rdi
callq 0x43f0
leaq -0x218(%rbp), %rdi
callq 0x4728
jmp 0x48a9d
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x340(%rbp)
jmp 0x487df
movq -0x340(%rbp), %rdi
leaq 0x47b63(%rip), %rsi     # 0x90350
callq 0x30fb0
movb %al, -0x341(%rbp)
jmp 0x487fa
movb -0x341(%rbp), %al
testb $0x1, %al
jne 0x48809
jmp 0x489c3
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x350(%rbp)
jmp 0x4881e
movq -0x350(%rbp), %rdi
leaq 0x47b2b(%rip), %rsi     # 0x90357
callq 0x30fb0
movb %al, -0x351(%rbp)
jmp 0x48839
movb -0x351(%rbp), %al
testb $0x1, %al
jne 0x48848
jmp 0x489c3
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x360(%rbp)
jmp 0x4885d
movq -0x360(%rbp), %rdx
leaq 0x47aef(%rip), %rsi     # 0x9035a
leaq -0x270(%rbp), %rdi
callq 0x4b910
jmp 0x48879
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x368(%rbp)
jmp 0x4888e
movq -0x368(%rbp), %rdi
leaq -0x270(%rbp), %rsi
movq %rsi, -0x380(%rbp)
callq 0x4470
movq -0x380(%rbp), %rdi
callq 0x4728
movq -0x10(%rbp), %rax
movq %rax, -0x378(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x370(%rbp)
jmp 0x488d4
movq -0x370(%rbp), %rsi
movq -0x378(%rbp), %rdi
callq 0x4b7a0
movq %rax, -0x388(%rbp)
jmp 0x488f0
movq -0x388(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4b7f0
movq %rax, -0x280(%rbp)
leaq -0x278(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x4b770
testb $0x1, %al
jne 0x4892a
jmp 0x489c1
movq -0x10(%rbp), %rax
movq %rax, -0x398(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x390(%rbp)
jmp 0x4894a
movq -0x390(%rbp), %rsi
movq -0x398(%rbp), %rdi
callq 0x4b350
movq %rax, -0x3a0(%rbp)
jmp 0x48966
movq -0x3a0(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x4b820
jmp 0x4897b
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x3a8(%rbp)
jmp 0x48990
movq -0x3a8(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x37000
jmp 0x489a2
jmp 0x489c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x4728
jmp 0x48a9d
jmp 0x489c3
jmp 0x489c5
cmpl $0x0, -0x14(%rbp)
jne 0x48a26
movq -0x10(%rbp), %rax
movq %rax, -0x3b8(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x3b0(%rbp)
jmp 0x489eb
movq -0x3b0(%rbp), %rsi
movq -0x3b8(%rbp), %rdi
callq 0x4b350
movq %rax, -0x3c0(%rbp)
jmp 0x48a07
movq -0x3c0(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movsd -0xe0(%rbp), %xmm0
callq 0x68010
jmp 0x48a24
jmp 0x48a8b
cmpl $0x1, -0x14(%rbp)
jne 0x48a89
movq -0x10(%rbp), %rax
movq %rax, -0x3d0(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x3c8(%rbp)
jmp 0x48a4c
movq -0x3c8(%rbp), %rsi
movq -0x3d0(%rbp), %rdi
callq 0x4b350
movq %rax, -0x3d8(%rbp)
jmp 0x48a68
movq -0x3d8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movsd -0xe0(%rbp), %xmm0
xorl %edx, %edx
callq 0x682d0
jmp 0x48a87
jmp 0x48a89
jmp 0x48a8b
movb $0x1, -0x15(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x46ba0
jmp 0x48aab
leaq -0x1f8(%rbp), %rdi
callq 0x46ba0
jmp 0x48af1
jmp 0x48aad
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x484ec
jmp 0x48ac3
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x4841d
leaq -0x98(%rbp), %rdi
callq 0x4728
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x48324
leaq -0x98(%rbp), %rdi
callq 0x4728
jmp 0x48b2b
movb -0x15(%rbp), %al
movb %al, -0x3d9(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x25780
leaq -0x30(%rbp), %rdi
callq 0x8830
movb -0x3d9(%rbp), %al
andb $0x1, %al
addq $0x3f0, %rsp            # imm = 0x3F0
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x25780
leaq -0x30(%rbp), %rdi
callq 0x8830
movq -0x68(%rbp), %rdi
callq 0x4650
nopw %cs:(%rax,%rax)