// File: neubig[P]egret/Egret/src/Forest-Berkeley.cpp
// Function: genNewNode_byLabel_constrained_berkeley(BerkeleyRuleSet const&, Label&, Label&, Node&, DecodeType)
Node& genNewNode_byLabel_constrained_berkeley(const BerkeleyRuleSet& ruleSet,Label& label1, Label& label2, Node& n3, DecodeType decodetype)
{
	int lc=label1.state(),lcsub=label1.subState(),rc=label2.state(),rcsub=label2.subState();
	
	const AllowStateInfo& asi=n3.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;
		const BerkeleyBinaryRule* rule=ruleSet.getBinaryRuleByRule(lc,rc,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(lcsub,rcsub,prsub);
				if(ruleScore>-1E10)
				{
					Label label;
					int _start=(int)min(label1.start(),label2.start());
					int _stop=(int)max(label1.stop(),label2.stop());
					assert(_start==n3.start()&&_stop==n3.stop());

					label.init(ruleSet.state2term(pr),_start,_stop,pr,prsub);
					
					if(n3.find(label.nt())==n3.end())
						n3[label.nt()]=label;
					
					if(decodetype==VITERBI)
						n3[label.nt()].addChildPair_viterbi(&label1,&label2,ruleScore);
					else if(decodetype==IO)
						// MAKE SURE THE RULESCORE IS IN NORMAL FORM
						n3[label.nt()].addChildPair_io(&label1,&label2,ruleScore);
				}
		}		
	}
	return n3;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4b430
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4b450
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4b430
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4b450
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rdi
callq 0x45a40
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x7a7c0
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movslq -0x4c(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x48(%rbp), %rdi
callq 0x45a60
movq %rax, %rcx
movq -0x210(%rbp), %rax
cmpq %rcx, %rax
jae 0x498b5
movq -0x48(%rbp), %rdi
movslq -0x4c(%rbp), %rsi
callq 0x45a80
movl (%rax), %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x30(%rbp), %edx
movl -0x50(%rbp), %ecx
callq 0x45bb0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x493cb
jmp 0x498a7
movq -0x48(%rbp), %rdi
movslq -0x4c(%rbp), %rsi
callq 0x45a80
addq $0x8, %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movslq -0x64(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x60(%rbp), %rdi
callq 0x16990
movq %rax, %rcx
movq -0x218(%rbp), %rax
cmpq %rcx, %rax
jae 0x498a5
movq -0x60(%rbp), %rdi
movslq -0x64(%rbp), %rsi
callq 0x457e0
movl (%rax), %eax
movl %eax, -0x68(%rbp)
movq -0x58(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x34(%rbp), %edx
movl -0x68(%rbp), %ecx
callq 0x45830
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movsd 0x46c74(%rip), %xmm1    # 0x900b8
ucomisd %xmm1, %xmm0
jbe 0x49895
leaq -0x188(%rbp), %rdi
callq 0x4b470
movq -0x10(%rbp), %rdi
callq 0x4b730
movl %eax, -0x21c(%rbp)
jmp 0x4946b
movl -0x21c(%rbp), %eax
movl %eax, -0x190(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4b730
movl %eax, -0x220(%rbp)
jmp 0x49488
movl -0x220(%rbp), %eax
movl %eax, -0x1a0(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x40620
movq %rax, -0x228(%rbp)
jmp 0x494b0
movq -0x228(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4b750
movl %eax, -0x22c(%rbp)
jmp 0x494d0
movl -0x22c(%rbp), %eax
movl %eax, -0x1a8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4b750
movl %eax, -0x230(%rbp)
jmp 0x494ed
movl -0x230(%rbp), %eax
movl %eax, -0x1ac(%rbp)
leaq -0x1a8(%rbp), %rdi
leaq -0x1ac(%rbp), %rsi
callq 0x40660
movq %rax, -0x238(%rbp)
jmp 0x49515
movq -0x238(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1a4(%rbp)
movl -0x18c(%rbp), %eax
movl %eax, -0x240(%rbp)
movq -0x20(%rbp), %rdi
callq 0x45920
movl %eax, -0x23c(%rbp)
jmp 0x49541
movl -0x240(%rbp), %ecx
movl -0x23c(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x241(%rbp)
jne 0x4958d
movl -0x1a4(%rbp), %eax
movl %eax, -0x24c(%rbp)
movq -0x20(%rbp), %rdi
callq 0x45940
movl %eax, -0x248(%rbp)
jmp 0x49576
movl -0x24c(%rbp), %eax
movl -0x248(%rbp), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x241(%rbp)
movb -0x241(%rbp), %al
testb $0x1, %al
jne 0x49599
jmp 0x4959b
jmp 0x495d1
leaq 0x46dbb(%rip), %rdi     # 0x9035d
leaq 0x46dd9(%rip), %rsi     # 0x90382
movl $0xbc, %edx
leaq 0x46deb(%rip), %rcx     # 0x903a0
callq 0x4240
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x198(%rbp)
movl %eax, -0x19c(%rbp)
jmp 0x49887
movq -0x8(%rbp), %rsi
movl -0x50(%rbp), %edx
leaq -0x1d0(%rbp), %rdi
callq 0x4b6f0
jmp 0x495e6
movl -0x18c(%rbp), %eax
movl %eax, -0x268(%rbp)
movl -0x1a4(%rbp), %eax
movl %eax, -0x264(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x260(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x25c(%rbp)
leaq -0x1f1(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x4660
movq -0x258(%rbp), %rdx
leaq 0x47825(%rip), %rsi     # 0x90e56
leaq -0x1f0(%rbp), %rdi
callq 0x1c730
jmp 0x4963f
movl -0x25c(%rbp), %r9d
movl -0x260(%rbp), %r8d
movl -0x264(%rbp), %ecx
movl -0x268(%rbp), %edx
movq %rsp, %rax
leaq -0x1f0(%rbp), %rsi
movq %rsi, (%rax)
leaq -0x188(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x4b5b0
jmp 0x4967b
leaq -0x1f0(%rbp), %rdi
callq 0x4728
leaq -0x1f1(%rbp), %rdi
callq 0x43f0
leaq -0x1d0(%rbp), %rdi
callq 0x4728
movq -0x20(%rbp), %rax
movq %rax, -0x278(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x270(%rbp)
jmp 0x496bf
movq -0x270(%rbp), %rsi
movq -0x278(%rbp), %rdi
callq 0x4b7a0
movq %rax, -0x280(%rbp)
jmp 0x496db
movq -0x280(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4b7f0
movq %rax, -0x208(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x4b770
testb $0x1, %al
jne 0x49715
jmp 0x497b7
movq -0x20(%rbp), %rax
movq %rax, -0x290(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x288(%rbp)
jmp 0x49735
movq -0x288(%rbp), %rsi
movq -0x290(%rbp), %rdi
callq 0x4b350
movq %rax, -0x298(%rbp)
jmp 0x49751
movq -0x298(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x4b820
jmp 0x49766
jmp 0x497b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x198(%rbp)
movl %eax, -0x19c(%rbp)
jmp 0x4979a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x198(%rbp)
movl %eax, -0x19c(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x4728
leaq -0x1f1(%rbp), %rdi
callq 0x43f0
leaq -0x1d0(%rbp), %rdi
callq 0x4728
jmp 0x49887
cmpl $0x0, -0x24(%rbp)
jne 0x49816
movq -0x20(%rbp), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x2a0(%rbp)
jmp 0x497dd
movq -0x2a0(%rbp), %rsi
movq -0x2a8(%rbp), %rdi
callq 0x4b350
movq %rax, -0x2b0(%rbp)
jmp 0x497f9
movq -0x2b0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movsd -0x70(%rbp), %xmm0
callq 0x67db0
jmp 0x49814
jmp 0x49879
cmpl $0x1, -0x24(%rbp)
jne 0x49877
movq -0x20(%rbp), %rax
movq %rax, -0x2c0(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x2b8(%rbp)
jmp 0x4983c
movq -0x2b8(%rbp), %rsi
movq -0x2c0(%rbp), %rdi
callq 0x4b350
movq %rax, -0x2c8(%rbp)
jmp 0x49858
movq -0x2c8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movsd -0x70(%rbp), %xmm0
xorl %ecx, %ecx
callq 0x684e0
jmp 0x49875
jmp 0x49877
jmp 0x49879
leaq -0x188(%rbp), %rdi
callq 0x46ba0
jmp 0x49895
leaq -0x188(%rbp), %rdi
callq 0x46ba0
jmp 0x498c2
jmp 0x49897
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x493e7
jmp 0x498a7
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x49370
movq -0x20(%rbp), %rax
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
movq -0x198(%rbp), %rdi
callq 0x4650
nop