// File: /workspace/github_cpp_makefile_star2_O2/neubig[P]egret/Egret/src/Forest-Berkeley-2.cpp
// Function: genNewNode_withoutLabel_initLevel_berkeley(BerkeleyRuleSet const&, Node&, Node&, Node&, IorO)
Node& genNewNode_withoutLabel_initLevel_berkeley(const BerkeleyRuleSet& ruleSet,Node& n1, Node& n2, Node& n3, IorO iot)
{
	const vector<int>& asi1_inVector=n1.allowState();
	const vector<int>& asi2_inVector=n2.allowState();
	int lcSize=(int)asi1_inVector.size();
	int rcSize=(int)asi2_inVector.size();
	//if(n3.stop()-n3.start()<3)
	//	cout<<n3.start()<<" "<<n3.stop()<<" : "<<lcSize<<","<<rcSize<<" "<<ruleSet.numOfState()<<endl;
	for(int lcIter=0; lcIter<lcSize;lcIter++)
	{
		int lc=asi1_inVector[lcIter];
		for(int rcIter=0;rcIter<rcSize;rcIter++)
		{
			int rc=asi2_inVector[rcIter];
			
			//cerr<<"child pair:"<<lc<<","<<rc<<endl;
			
			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 pr=rule->parentState();
				double ruleScore=rule->getScore(0,0,0);
				if(ruleScore>-1E10)
				{
					if(iot==inside)
					{
						//cerr<<"\t parent:"<<pr<<endl;
						if(n1.iScore(lc)<0||n2.iScore(rc)<0)cerr<<"bug"<<endl;
						if(n3.iScore(pr)<0) n3.iScore(pr)=0;
						n3.iScore(pr)=max(n1.iScore(lc)*n2.iScore(rc)*ruleScore,n3.iScore(pr));
					}
					else if(iot==outside)
					{
						if(n3.oScore(pr)<0)continue;//cerr<<"bug2"<<endl;
						if(n1.oScore(lc)<0) n1.oScore(lc)=0;
						if(n2.oScore(rc)<0) n2.oScore(rc)=0;
						n1.oScore(lc)=max(n3.oScore(pr)*n2.iScore(rc)*ruleScore,n1.oScore(lc));
						n2.oScore(rc)=max(n3.oScore(pr)*n1.iScore(lc)*ruleScore,n2.oScore(rc));
					}
				}
			}	
		}
	}
	return n3;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r13
movq %rsi, %rbp
movq 0x108(%rsi), %rax
subq 0x100(%rsi), %rax
shrq $0x2, %rax
movq 0x108(%rdx), %rcx
subq 0x100(%rdx), %rcx
shrq $0x2, %rcx
xorl %esi, %esi
testl %ecx, %ecx
cmovlel %esi, %ecx
movq %rcx, 0x30(%rsp)
movq %rdi, 0x18(%rsp)
testl %eax, %eax
cmovlel %esi, %eax
movq %rax, 0x10(%rsp)
movsd 0x1c3e0(%rip), %xmm2    # 0x320d0
xorpd %xmm3, %xmm3
movq %r13, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movl %r8d, 0xc(%rsp)
cmpq 0x10(%rsp), %rsi
je 0x15f10
movq 0x100(%rbp), %rax
movslq (%rax,%rsi,4), %r10
imulq $0x18, %r10, %rax
movq %rax, 0x20(%rsp)
xorl %ecx, %ecx
movq %rsi, 0x28(%rsp)
cmpq 0x30(%rsp), %rcx
je 0x15f08
movq 0x100(%rdx), %rax
movq %rcx, 0x38(%rsp)
movslq (%rax,%rcx,4), %r12
movq 0x18(%rsp), %rax
movq 0x208(%rax), %rax
imulq $0x18, %r12, %rbx
movq 0x20(%rsp), %rcx
addq (%rax,%rcx), %rbx
xorl %r14d, %r14d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jbe 0x15ef6
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x15eee
movq (%rax), %rcx
movq (%rcx), %rcx
movq (%rcx), %rcx
movsd (%rcx), %xmm4
ucomisd %xmm2, %xmm4
jbe 0x15eee
movslq 0x78(%rax), %r15
cmpl $0x1, %r8d
je 0x15e61
testl %r8d, %r8d
jne 0x15eee
movq 0xd0(%rbp), %rax
ucomisd (%rax,%r10,8), %xmm3
ja 0x15dd0
movq 0xd0(%rdx), %rax
ucomisd (%rax,%r12,8), %xmm3
jbe 0x15e18
movq 0x36219(%rip), %rdi     # 0x4bff0
leaq 0x1ce79(%rip), %rsi     # 0x32c57
movq %r10, %r13
movsd %xmm4, 0x50(%rsp)
callq 0x32d0
movq %rax, %rdi
callq 0x3130
movsd 0x50(%rsp), %xmm4
movq %r13, %r10
xorpd %xmm3, %xmm3
movsd 0x1c2c7(%rip), %xmm2    # 0x320d0
movl 0xc(%rsp), %r8d
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %r13
movq 0xd0(%r13), %rax
movsd (%rax,%r15,8), %xmm0
ucomisd %xmm0, %xmm3
jbe 0x15e34
andq $0x0, (%rax,%r15,8)
xorpd %xmm0, %xmm0
movq 0xd0(%rbp), %rcx
movsd (%rcx,%r10,8), %xmm1
movq 0xd0(%rdx), %rcx
mulsd (%rcx,%r12,8), %xmm1
mulsd %xmm1, %xmm4
maxsd %xmm4, %xmm0
movsd %xmm0, (%rax,%r15,8)
jmp 0x15eee
movq 0xe8(%r13), %rax
ucomisd (%rax,%r15,8), %xmm3
ja 0x15eee
movq 0xe8(%rbp), %rcx
movsd (%rcx,%r10,8), %xmm0
ucomisd %xmm0, %xmm3
jbe 0x15e8c
andq $0x0, (%rcx,%r10,8)
xorpd %xmm0, %xmm0
movq 0xe8(%rdx), %rdi
ucomisd (%rdi,%r12,8), %xmm3
jbe 0x15ea6
andq $0x0, (%rdi,%r12,8)
movsd (%rcx,%r10,8), %xmm0
movsd (%rax,%r15,8), %xmm1
movq 0xd0(%rdx), %rsi
mulsd (%rsi,%r12,8), %xmm1
mulsd %xmm4, %xmm1
maxsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%r10,8)
movsd (%rax,%r15,8), %xmm0
movq 0xd0(%rbp), %rax
mulsd (%rax,%r10,8), %xmm0
mulsd %xmm4, %xmm0
movsd (%rdi,%r12,8), %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, (%rdi,%r12,8)
incq %r14
jmp 0x15d60
movq 0x38(%rsp), %rcx
incq %rcx
movq 0x28(%rsp), %rsi
jmp 0x15d29
incq %rsi
jmp 0x15d03
movq %r13, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq