// File: 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
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movb $0x0, -0x15(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x8340
leaq -0x60(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x25300
movq -0x258(%rbp), %rdi
callq 0x8360
movq -0x260(%rbp), %rdi
callq 0x34100
movq -0x258(%rbp), %rdx
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x77d20
jmp 0x48bb8
movl $0x0, -0x70(%rbp)
movslq -0x70(%rbp), %rax
movq %rax, -0x268(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x87f0
movq %rax, %rcx
movq -0x268(%rbp), %rax
cmpq %rcx, %rax
jae 0x48c2d
movslq -0x70(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x8810
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
callq 0x1d350
movq %rax, -0x270(%rbp)
jmp 0x48c04
movq -0x270(%rbp), %rax
movl $0x1, (%rax)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x48bbf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x49284
movl $0x0, -0x74(%rbp)
movslq -0x74(%rbp), %rax
movq %rax, -0x278(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x87f0
movq %rax, %rcx
movq -0x278(%rbp), %rax
cmpq %rcx, %rax
jae 0x49258
movslq -0x74(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x8810
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
callq 0x4160
jmp 0x48c79
movq -0x10(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x4b350
movq %rax, -0x280(%rbp)
jmp 0x48c92
movq -0x280(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x4b430
movl %eax, -0x284(%rbp)
jmp 0x48cb4
movl -0x284(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x4b450
movl %eax, -0x288(%rbp)
jmp 0x48cd4
movl -0x288(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x4ba20
movq %rax, -0x290(%rbp)
jmp 0x48cf8
movq -0x290(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x45a40
movq %rax, -0x298(%rbp)
jmp 0x48d18
movq -0x298(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl $0x0, -0xbc(%rbp)
movslq -0xbc(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x18000
movq %rax, %rcx
movq -0x2a0(%rbp), %rax
cmpq %rcx, %rax
jae 0x49230
movq -0xb0(%rbp), %rdi
movslq -0xbc(%rbp), %rsi
callq 0x8940
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
jne 0x48d9a
jmp 0x4921c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4924a
movq -0xc8(%rbp), %rdi
callq 0x45c10
movl %eax, -0x2a4(%rbp)
jmp 0x48dae
movl -0x2a4(%rbp), %eax
movl %eax, -0xcc(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x45c30
movl %eax, -0x2a8(%rbp)
jmp 0x48dce
movl -0x2a8(%rbp), %eax
movl %eax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x9e60
movl %eax, -0x2ac(%rbp)
jmp 0x48dee
movl -0x2ac(%rbp), %eax
movl %eax, -0xd4(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x45c50
movb %al, -0x2ad(%rbp)
jmp 0x48e0e
movb -0x2ad(%rbp), %al
testb $0x1, %al
jne 0x48e1a
jmp 0x48e43
movq -0xb8(%rbp), %rdi
movl -0xd4(%rbp), %esi
callq 0x7a7e0
movb %al, -0x2ae(%rbp)
jmp 0x48e34
movb -0x2ae(%rbp), %al
testb $0x1, %al
jne 0x48e43
jmp 0x4921a
movl $0x0, -0xd8(%rbp)
movl -0xd8(%rbp), %eax
cmpl -0xd0(%rbp), %eax
jge 0x49218
movq -0xb8(%rbp), %rdi
callq 0x45c50
movb %al, -0x2af(%rbp)
jmp 0x48e73
movb -0x2af(%rbp), %al
testb $0x1, %al
jne 0x48e7f
jmp 0x48eae
movq -0xb8(%rbp), %rdi
movl -0xd4(%rbp), %esi
movl -0xd8(%rbp), %edx
callq 0x7a840
movb %al, -0x2b0(%rbp)
jmp 0x48e9f
movb -0x2b0(%rbp), %al
testb $0x1, %al
jne 0x48eae
jmp 0x49202
movq -0xc8(%rbp), %rdi
movl -0xa8(%rbp), %esi
movl -0xd8(%rbp), %edx
callq 0x45710
movsd %xmm0, -0x2b8(%rbp)
jmp 0x48ed0
movsd -0x2b8(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd -0xe0(%rbp), %xmm0
movsd 0x471c8(%rip), %xmm1    # 0x900b8
ucomisd %xmm1, %xmm0
jbe 0x49200
leaq -0x1f8(%rbp), %rdi
callq 0x4b470
jmp 0x48f08
movq -0x8(%rbp), %rsi
movl -0xd4(%rbp), %edx
leaq -0x218(%rbp), %rdi
callq 0x4b6f0
jmp 0x48f20
movq -0xa0(%rbp), %rdi
callq 0x4b730
movl %eax, -0x2bc(%rbp)
jmp 0x48f34
movq -0xa0(%rbp), %rdi
callq 0x4b750
movl %eax, -0x2c0(%rbp)
jmp 0x48f48
movl -0xd4(%rbp), %eax
movl %eax, -0x2d0(%rbp)
movl -0xd8(%rbp), %eax
movl %eax, -0x2cc(%rbp)
leaq -0x239(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x4660
movq -0x2c8(%rbp), %rdx
leaq 0x47ed5(%rip), %rsi     # 0x90e56
leaq -0x238(%rbp), %rdi
callq 0x1c730
jmp 0x48f8f
movl -0x2cc(%rbp), %r9d
movl -0x2d0(%rbp), %r8d
movl -0x2c0(%rbp), %ecx
movl -0x2bc(%rbp), %edx
movq %rsp, %rax
leaq -0x238(%rbp), %rsi
movq %rsi, (%rax)
leaq -0x1f8(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x4b5b0
jmp 0x48fcb
leaq -0x238(%rbp), %rdi
callq 0x4728
leaq -0x239(%rbp), %rdi
callq 0x43f0
leaq -0x218(%rbp), %rdi
callq 0x4728
movq -0x10(%rbp), %rax
movq %rax, -0x2e0(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x2d8(%rbp)
jmp 0x4900f
movq -0x2d8(%rbp), %rsi
movq -0x2e0(%rbp), %rdi
callq 0x4b7a0
movq %rax, -0x2e8(%rbp)
jmp 0x4902b
movq -0x2e8(%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 0x49065
jmp 0x4911a
movq -0x10(%rbp), %rax
movq %rax, -0x2f8(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x2f0(%rbp)
jmp 0x49085
movq -0x2f0(%rbp), %rsi
movq -0x2f8(%rbp), %rdi
callq 0x4b350
movq %rax, -0x300(%rbp)
jmp 0x490a1
movq -0x300(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x4b820
jmp 0x490b6
jmp 0x4911a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x491f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x49109
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x490fd
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 0x491f2
cmpl $0x0, -0x14(%rbp)
jne 0x4917b
movq -0x10(%rbp), %rax
movq %rax, -0x310(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x308(%rbp)
jmp 0x49140
movq -0x308(%rbp), %rsi
movq -0x310(%rbp), %rdi
callq 0x4b350
movq %rax, -0x318(%rbp)
jmp 0x4915c
movq -0x318(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movsd -0xe0(%rbp), %xmm0
callq 0x68010
jmp 0x49179
jmp 0x491e0
cmpl $0x1, -0x14(%rbp)
jne 0x491de
movq -0x10(%rbp), %rax
movq %rax, -0x328(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x320(%rbp)
jmp 0x491a1
movq -0x320(%rbp), %rsi
movq -0x328(%rbp), %rdi
callq 0x4b350
movq %rax, -0x330(%rbp)
jmp 0x491bd
movq -0x330(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movsd -0xe0(%rbp), %xmm0
xorl %edx, %edx
callq 0x682d0
jmp 0x491dc
jmp 0x491de
jmp 0x491e0
movb $0x1, -0x15(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x46ba0
jmp 0x49200
leaq -0x1f8(%rbp), %rdi
callq 0x46ba0
jmp 0x4924a
jmp 0x49202
jmp 0x49204
movl -0xd8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd8(%rbp)
jmp 0x48e4d
jmp 0x4921a
jmp 0x4921c
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x48d30
leaq -0x98(%rbp), %rdi
callq 0x4728
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x48c34
leaq -0x98(%rbp), %rdi
callq 0x4728
jmp 0x49284
movb -0x15(%rbp), %al
movb %al, -0x331(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x25780
leaq -0x30(%rbp), %rdi
callq 0x8830
movb -0x331(%rbp), %al
andb $0x1, %al
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x25780
leaq -0x30(%rbp), %rdi
callq 0x8830
movq -0x68(%rbp), %rdi
callq 0x4650
nop