// File: neubig[P]egret/Egret/src/Forest-Berkeley.cpp
// Function: genNewNode_byLabel_unconstrained_berkeley(BerkeleyRuleSet const&, Label&, Label&, Node&, DecodeType)
Node& genNewNode_byLabel_unconstrained_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 vector<BerkeleyBinaryRule*>& rules=ruleSet.getBinaryRulesByChilds(lc,rc);
	for(int i=0;(size_t)i<rules.size();i++)
	{
		BerkeleyBinaryRule* rule=rules[i];
		if(rule==NULL)continue;

		int prNumSubState=rule->parentNumSubState();
		int parentState=rule->parentState();

		for(int prsub=0;prsub<prNumSubState;prsub++)
		{
			double ruleScore=rule->getScore(lcsub,rcsub,prsub);
			if(ruleScore>-1E10)
			{
				string label_nt=ruleSet.state2term(parentState)+"_"+intToString(prsub);
				if(n3.find(label_nt)==n3.end())
				{
					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(parentState),_start,_stop,parentState,prsub);

					n3[label.nt()]=label;
				}
				// MAKE SURE THE RULESCORE IS IN NORMAL FORM
				if(decodetype==VITERBI)
					n3[label_nt].addChildPair_viterbi(&label1,&label2,ruleScore);
				else if(decodetype==IO)
					//n3[label.nt()].addChildPair_io_berkeley(&label1,&label2,ruleScore,io);
					n3[label_nt].addChildPair_io(&label1,&label2,ruleScore);
					//cout<<label11.nt()<<label31.nt()<<label21.nt()<<endl;
			}	
		}
	}

	return n3;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
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 -0x8(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x30(%rbp), %edx
callq 0x45800
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movslq -0x44(%rbp), %rax
movq %rax, -0x288(%rbp)
movq -0x40(%rbp), %rdi
callq 0x143b0
movq %rax, %rcx
movq -0x288(%rbp), %rax
cmpq %rcx, %rax
jae 0x49ef5
movq -0x40(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x8900
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x49980
jmp 0x49ee7
movq -0x50(%rbp), %rdi
callq 0x45bf0
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rdi
callq 0x9890
movl %eax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x49ee5
movq -0x50(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x34(%rbp), %edx
movl -0x5c(%rbp), %ecx
callq 0x45830
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd 0x466e9(%rip), %xmm1    # 0x900b8
ucomisd %xmm1, %xmm0
jbe 0x49ed5
movq -0x8(%rbp), %rsi
movl -0x58(%rbp), %edx
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x4b6f0
movq -0x290(%rbp), %rsi
leaq 0x4678a(%rip), %rdx     # 0x9018b
leaq -0xa8(%rbp), %rdi
callq 0x21540
jmp 0x49a0f
movl -0x5c(%rbp), %esi
leaq -0xf8(%rbp), %rdi
callq 0x8fae0
jmp 0x49a20
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x7e90
jmp 0x49a3c
leaq -0xf8(%rbp), %rdi
callq 0x4728
leaq -0xa8(%rbp), %rdi
callq 0x4728
leaq -0xc8(%rbp), %rdi
callq 0x4728
movq -0x20(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x4b7a0
movq %rax, -0x298(%rbp)
jmp 0x49a79
movq -0x298(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4b7f0
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x4b770
testb $0x1, %al
jne 0x49ab3
jmp 0x49e3d
leaq -0x220(%rbp), %rdi
callq 0x4b470
jmp 0x49ac1
movq -0x10(%rbp), %rdi
callq 0x4b730
movl %eax, -0x29c(%rbp)
jmp 0x49ad2
movl -0x29c(%rbp), %eax
movl %eax, -0x228(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4b730
movl %eax, -0x2a0(%rbp)
jmp 0x49aef
movl -0x2a0(%rbp), %eax
movl %eax, -0x22c(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x22c(%rbp), %rsi
callq 0x40620
movq %rax, -0x2a8(%rbp)
jmp 0x49b17
movq -0x2a8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x224(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4b750
movl %eax, -0x2ac(%rbp)
jmp 0x49b37
movl -0x2ac(%rbp), %eax
movl %eax, -0x234(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4b750
movl %eax, -0x2b0(%rbp)
jmp 0x49b54
movl -0x2b0(%rbp), %eax
movl %eax, -0x238(%rbp)
leaq -0x234(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x40660
movq %rax, -0x2b8(%rbp)
jmp 0x49b7c
movq -0x2b8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x230(%rbp)
movl -0x224(%rbp), %eax
movl %eax, -0x2c0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x45920
movl %eax, -0x2bc(%rbp)
jmp 0x49ba8
movl -0x2c0(%rbp), %ecx
movl -0x2bc(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x2c1(%rbp)
jne 0x49bf4
movl -0x230(%rbp), %eax
movl %eax, -0x2cc(%rbp)
movq -0x20(%rbp), %rdi
callq 0x45940
movl %eax, -0x2c8(%rbp)
jmp 0x49bdd
movl -0x2cc(%rbp), %eax
movl -0x2c8(%rbp), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x2c1(%rbp)
movb -0x2c1(%rbp), %al
testb $0x1, %al
jne 0x49c00
jmp 0x49c05
jmp 0x49cb5
leaq 0x46751(%rip), %rdi     # 0x9035d
leaq 0x4676f(%rip), %rsi     # 0x90382
movl $0xe6, %edx
leaq 0x467ee(%rip), %rcx     # 0x9040d
callq 0x4240
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x49c76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x49c6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x4728
leaq -0xa8(%rbp), %rdi
callq 0x4728
leaq -0xc8(%rbp), %rdi
callq 0x4728
jmp 0x49f02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x49ec7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x49e2c
movq -0x8(%rbp), %rsi
movl -0x58(%rbp), %edx
leaq -0x258(%rbp), %rdi
callq 0x4b6f0
jmp 0x49cca
movl -0x224(%rbp), %eax
movl %eax, -0x2e8(%rbp)
movl -0x230(%rbp), %eax
movl %eax, -0x2e4(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x2e0(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x2dc(%rbp)
leaq -0x279(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x4660
movq -0x2d8(%rbp), %rdx
leaq 0x47141(%rip), %rsi     # 0x90e56
leaq -0x278(%rbp), %rdi
callq 0x1c730
jmp 0x49d23
movl -0x2dc(%rbp), %r9d
movl -0x2e0(%rbp), %r8d
movl -0x2e4(%rbp), %ecx
movl -0x2e8(%rbp), %edx
movq %rsp, %rax
leaq -0x278(%rbp), %rsi
movq %rsi, (%rax)
leaq -0x220(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x4b5b0
jmp 0x49d5f
leaq -0x278(%rbp), %rdi
callq 0x4728
leaq -0x279(%rbp), %rdi
callq 0x43f0
leaq -0x258(%rbp), %rdi
callq 0x4728
movq -0x20(%rbp), %rax
movq %rax, -0x2f8(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x4b7d0
movq %rax, -0x2f0(%rbp)
jmp 0x49da3
movq -0x2f0(%rbp), %rsi
movq -0x2f8(%rbp), %rdi
callq 0x4b350
movq %rax, -0x300(%rbp)
jmp 0x49dbf
movq -0x300(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x4b820
jmp 0x49dd4
leaq -0x220(%rbp), %rdi
callq 0x46ba0
jmp 0x49e3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x49e14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x4728
leaq -0x279(%rbp), %rdi
callq 0x43f0
leaq -0x258(%rbp), %rdi
callq 0x4728
leaq -0x220(%rbp), %rdi
callq 0x46ba0
jmp 0x49ec7
cmpl $0x0, -0x24(%rbp)
jne 0x49e79
movq -0x20(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x4b350
movq %rax, -0x308(%rbp)
jmp 0x49e5c
movq -0x308(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movsd -0x68(%rbp), %xmm0
callq 0x67db0
jmp 0x49e77
jmp 0x49eb9
cmpl $0x1, -0x24(%rbp)
jne 0x49eb7
movq -0x20(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x4b350
movq %rax, -0x310(%rbp)
jmp 0x49e98
movq -0x310(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movsd -0x68(%rbp), %xmm0
xorl %ecx, %ecx
callq 0x684e0
jmp 0x49eb5
jmp 0x49eb7
jmp 0x49eb9
leaq -0x88(%rbp), %rdi
callq 0x4728
jmp 0x49ed5
leaq -0x88(%rbp), %rdi
callq 0x4728
jmp 0x49f02
jmp 0x49ed7
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x4999f
jmp 0x49ee7
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x49939
movq -0x20(%rbp), %rax
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
movq -0xd0(%rbp), %rdi
callq 0x4650
nop