// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movl %r8d, %ebp
movq %rcx, %rbx
movq %rdi, %r15
movslq 0x10c(%rsi), %r14
movq %rsi, 0x28(%rsp)
movslq 0x110(%rsi), %rax
movq %rax, 0x20(%rsp)
movslq 0x10c(%rdx), %r12
movq %rdx, 0x30(%rsp)
movslq 0x110(%rdx), %r13
leaq 0x60(%rcx), %rdi
callq 0x2b5fa
movq %rax, 0x60(%rsp)
movq %r15, 0x58(%rsp)
leaq 0x298(%r15), %rax
movq %rax, 0x80(%rsp)
movq %rbx, 0x18(%rsp)
leaq 0x8(%rbx), %rax
movq %rax, 0x78(%rsp)
xorl %ecx, %ecx
imulq $0x18, %r14, %rax
movq %rax, 0x50(%rsp)
imulq $0x18, %r12, %rax
movq %rax, 0x48(%rsp)
imulq $0x18, 0x20(%rsp), %rsi
imulq $0x18, %r13, %r15
movsd 0x1984e(%rip), %xmm0    # 0x320d0
movl %ebp, 0x3c(%rsp)
movq %r15, 0x70(%rsp)
movq 0x60(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %rcx, %rax
jbe 0x18afb
movq %rcx, 0x68(%rsp)
movq %rcx, %rax
shlq $0x5, %rax
movslq (%rdi,%rax), %r8
movq 0x58(%rsp), %rcx
movq 0x1d8(%rcx), %rcx
movq 0x50(%rsp), %rdx
movq (%rcx,%rdx), %rcx
movq 0x48(%rsp), %rdx
movq (%rcx,%rdx), %rcx
movq %r8, 0x40(%rsp)
movq (%rcx,%r8,8), %rdx
testq %rdx, %rdx
leaq 0xa0(%rsp), %rbp
je 0x18aee
addq %rax, %rdi
xorl %r8d, %r8d
movq %rdi, 0x90(%rsp)
movq %rdx, 0x88(%rsp)
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r8, %rcx
jbe 0x18aee
movslq (%rax,%r8,4), %rbx
movq (%rdx), %rax
movq (%rax,%rsi), %rax
movq (%rax,%r15), %rax
movsd (%rax,%rbx,8), %xmm1
movsd %xmm1, 0x20(%rsp)
ucomisd %xmm0, %xmm1
jbe 0x18ae6
movq %r8, 0x98(%rsp)
movq %rsi, %r15
leaq 0xe0(%rsp), %rdi
callq 0x19b8a
movq 0x28(%rsp), %rax
movl 0x48(%rax), %r12d
movl 0x4c(%rax), %eax
movq 0x30(%rsp), %rdx
movl 0x48(%rdx), %ecx
movl 0x4c(%rdx), %r14d
cmpl %r12d, %ecx
cmovll %ecx, %r12d
cmpl %r14d, %eax
cmovgl %eax, %r14d
movq 0x18(%rsp), %rax
cmpl 0xb0(%rax), %r12d
jne 0x18b12
cmpl 0xb4(%rax), %r14d
jne 0x18b12
leaq 0xc0(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0xa0b8
movq %rbp, %rdi
leaq 0x1a4f4(%rip), %rsi     # 0x32eb6
leaq 0x17(%rsp), %rdx
callq 0x9f86
movq %rbp, (%rsp)
leaq 0xe0(%rsp), %rdi
movq %rbp, %r13
leaq 0xc0(%rsp), %rbp
movq %rbp, %rsi
movl %r12d, %edx
movl %r14d, %ecx
movq 0x40(%rsp), %r8
movl %ebx, %r9d
callq 0x19c98
movq %r13, %rdi
callq 0x3578
movq %rbp, %rdi
callq 0x3578
movq 0x18(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x1b8b0
cmpq 0x78(%rsp), %rax
leaq 0xa0(%rsp), %rbp
jne 0x18a4c
movq 0x18(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x19b24
movq %rax, %rdi
leaq 0xe0(%rsp), %rsi
callq 0x19d82
movl 0x3c(%rsp), %eax
cmpl $0x1, %eax
je 0x18a85
testl %eax, %eax
jne 0x18ab1
movq 0x18(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x19b24
movq %rax, %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movsd 0x20(%rsp), %xmm0
callq 0x23adc
jmp 0x18ab1
movq 0x18(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x19b24
movq %rax, %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movsd 0x20(%rsp), %xmm0
xorl %ecx, %ecx
callq 0x23f3a
leaq 0xe0(%rsp), %rdi
callq 0x17b24
movq %r15, %rsi
movq 0x70(%rsp), %r15
movsd 0x19602(%rip), %xmm0    # 0x320d0
movq 0x90(%rsp), %rdi
movq 0x88(%rsp), %rdx
movq 0x98(%rsp), %r8
incq %r8
jmp 0x18905
movq 0x68(%rsp), %rcx
incq %rcx
jmp 0x1888b
movq 0x18(%rsp), %rax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19872(%rip), %rdi     # 0x3238b
leaq 0x19890(%rip), %rsi     # 0x323b0
leaq 0x198a7(%rip), %rcx     # 0x323ce
movl $0xbc, %edx
callq 0x31d0
movq %rax, %rbx
jmp 0x18b48
jmp 0x18b57
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x3578
leaq 0xc0(%rsp), %rdi
callq 0x3578
jmp 0x18b5a
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x17b24
movq %rbx, %rdi
callq 0x34f0