// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1e8, %rsp            # imm = 0x1E8
movl %r8d, 0x2c(%rsp)
movq %rdi, 0x30(%rsp)
movslq 0x10c(%rsi), %rax
movq %rax, 0x70(%rsp)
movq %rsi, 0x18(%rsp)
movslq 0x110(%rsi), %rax
movq %rax, 0xa8(%rsp)
movslq 0x10c(%rdx), %rax
movq %rax, 0x68(%rsp)
movq %rdx, 0x20(%rsp)
movslq 0x110(%rdx), %rax
movq %rax, 0xa0(%rsp)
movq %rcx, 0x10(%rsp)
leaq 0x60(%rcx), %rdi
callq 0x384f8
movq (%rax), %rsi
movq %rax, 0x60(%rsp)
cmpq %rsi, 0x8(%rax)
je 0x1ec09
movq 0x30(%rsp), %rax
addq $0x298, %rax            # imm = 0x298
movq %rax, 0x88(%rsp)
movq 0x10(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x80(%rsp)
xorl %ecx, %ecx
movsd 0x228dc(%rip), %xmm0    # 0x410d0
movq %rcx, 0x78(%rsp)
movq %rcx, %rax
shlq $0x5, %rax
movslq (%rsi,%rax), %r12
movq 0x30(%rsp), %rcx
movq 0x1d8(%rcx), %rcx
movq 0x70(%rsp), %rdx
leaq (%rdx,%rdx,2), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x68(%rsp), %rdx
leaq (%rdx,%rdx,2), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%r12,8), %rdx
testq %rdx, %rdx
je 0x1ebe5
addq %rax, %rsi
movq 0x8(%rsi), %rax
cmpq %rax, 0x10(%rsi)
je 0x1ebe5
xorl %r15d, %r15d
movq %rsi, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movslq (%rax,%r15,4), %rbp
movq (%rdx), %rax
movq 0xa8(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
movq 0xa0(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%rbp,8), %xmm1
movsd %xmm1, 0x38(%rsp)
ucomisd %xmm0, %xmm1
jbe 0x1ebca
leaq 0xd0(%rsp), %rdi
callq 0x204bc
movq 0x18(%rsp), %rax
movl 0x48(%rax), %r13d
movl 0x4c(%rax), %eax
movq 0x20(%rsp), %rdx
movl 0x48(%rdx), %ecx
movl 0x4c(%rdx), %r14d
cmpl %r13d, %ecx
cmovll %ecx, %r13d
cmpl %r14d, %eax
cmovgl %eax, %r14d
movq 0x10(%rsp), %rax
cmpl 0xb0(%rax), %r13d
jne 0x1ec20
cmpl 0xb4(%rax), %r14d
jne 0x1ec20
leaq 0xb0(%rsp), %rdi
movq 0x88(%rsp), %rsi
movl %r12d, %edx
callq 0xb792
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
leaq 0x2357c(%rip), %rdx     # 0x41e96
movq %rdx, %rsi
callq 0xb8a2
movq %rbx, (%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movl %r13d, %edx
movl %r14d, %ecx
movl %r12d, %r8d
movl %ebp, %r9d
callq 0x2061c
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x1e963
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x1e988
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0x10(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x223b8
cmpq 0x80(%rsp), %rax
jne 0x1eab2
movq 0x10(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x20440
movq %rax, %rbp
movb 0xd0(%rsp), %al
movb %al, (%rbp)
leaq 0x8(%rbp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x3150
leaq 0x28(%rbp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x3150
leaq 0xd8(%rsp), %rcx
movb 0x48(%rcx), %al
movb %al, 0x50(%rbp)
movq 0x40(%rcx), %rax
movq %rax, 0x48(%rbp)
leaq 0x58(%rbp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x20b88
leaq 0x70(%rbp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x20b88
leaq 0x88(%rbp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x21a40
leaq 0xd8(%rsp), %rax
movupd 0xb0(%rax), %xmm0
movupd %xmm0, 0xb8(%rbp)
leaq 0xc8(%rbp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x20ef0
leaq 0xd8(%rsp), %rax
movupd 0xd8(%rax), %xmm0
movupd %xmm0, 0xe0(%rbp)
movq %rbp, %rdi
addq $0xf0, %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x218ca
leaq 0xd8(%rsp), %rcx
movl 0x108(%rcx), %eax
movl %eax, 0x110(%rbp)
movq 0x100(%rcx), %rax
movq %rax, 0x108(%rbp)
movl 0x2c(%rsp), %eax
cmpl $0x1, %eax
je 0x1eaeb
testl %eax, %eax
jne 0x1eb17
movq 0x10(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x20440
movq %rax, %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movsd 0x38(%rsp), %xmm0
callq 0x2d83e
jmp 0x1eb17
movq 0x10(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x20440
movq %rax, %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movsd 0x38(%rsp), %xmm0
xorl %ecx, %ecx
callq 0x2deca
leaq 0x1c0(%rsp), %rdi
callq 0x1d4e6
movq 0x198(%rsp), %rdi
testq %rdi, %rdi
je 0x1eb41
movq 0x1a8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
leaq 0x158(%rsp), %rdi
callq 0x1d582
leaq 0x140(%rsp), %rdi
callq 0x1d534
leaq 0x128(%rsp), %rdi
callq 0x1d534
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x1eb8d
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x32e0
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x1ebb2
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x32e0
movsd 0x22516(%rip), %xmm0    # 0x410d0
movq 0x98(%rsp), %rsi
movq 0x90(%rsp), %rdx
incq %r15
movq 0x8(%rsi), %rax
movq 0x10(%rsi), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r15, %rcx
ja 0x1e85b
movq 0x78(%rsp), %rcx
incq %rcx
movq 0x60(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rcx, %rax
ja 0x1e7f4
movq 0x10(%rsp), %rax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x22764(%rip), %rdi     # 0x4138b
leaq 0x22782(%rip), %rsi     # 0x413b0
leaq 0x22799(%rip), %rcx     # 0x413ce
movl $0xbc, %edx
callq 0x31a0
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x1ec63
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x32e0
jmp 0x1ec63
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x1ec8f
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x32e0
jmp 0x1ec8f
jmp 0x1ec8c
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x208b0
movq %rbx, %rdi
callq 0x3530