// File: /workspace/github_cpp_makefile_star2_O2/neubig[P]egret/Egret/src/Forest-Berkeley-2.cpp
// Function: genNewNode_withoutLabel_berkeley(BerkeleyRuleSet const&, Node&, Node&, Node&, IorO)
Node& genNewNode_withoutLabel_berkeley(const BerkeleyRuleSet& ruleSet,Node& n1, Node& n2, Node& n3, IorO iot)
{
	const AllowStateInfo& asi1=n1.allowStateInfo();//n1.set_allowStateAndSubState_withoutLabel(1,0,0);//
	const AllowStateInfo& asi2=n2.allowStateInfo();//n2.set_allowStateAndSubState_withoutLabel(1,0,0);//
	const AllowStateInfo& asi3=n3.allowStateInfo();//n3.set_allowStateAndSubState_withoutLabel(1,0,0);//
	const vector<pair<int,vector<int> > >& asi1_inVector=asi1.allowStateAndSubStates();
	const vector<pair<int,vector<int> > >& asi2_inVector=asi2.allowStateAndSubStates();
	const vector<pair<int,vector<int> > >& asi3_inVector=asi3.allowStateAndSubStates();

	int lcSize=(int)asi1_inVector.size();
	int rcSize=(int)asi2_inVector.size();
	//if(n3.stop()-n3.start()<3)
	//	cerr<<n3.start()<<" "<<n3.stop()<<" : "<<lcSize<<","<<rcSize<<" "<<ruleSet.numOfState()<<endl;

	for(int lcIter=0; lcIter<lcSize;lcIter++)
	{
		int lc=asi1_inVector[lcIter].first;
		const vector<int>& lcSubs=asi1_inVector[lcIter].second;
		for(int lcSubIter=0;(size_t)lcSubIter<lcSubs.size();lcSubIter++)
		{
			int lcsub=lcSubs[lcSubIter];
			
			for(int rcIter=0;rcIter<rcSize;rcIter++)
			{
				int rc=asi2_inVector[rcIter].first;
				const vector<int>& rcSubs=asi2_inVector[rcIter].second;
				
				for(int rcSubIter=0;(size_t)rcSubIter<rcSubs.size();rcSubIter++)
				{
					int rcsub=rcSubs[rcSubIter];
					//here we make new node
					if(n3.useAllowState())
					{
						int prSize=(int)asi3_inVector.size();
						for(int prIter=0;prIter<prSize;prIter++)
						{
							int pr=asi3_inVector[prIter].first;
							const BerkeleyBinaryRule* rule=ruleSet.getBinaryRuleByRule(lc,rc,pr);
							if(rule==NULL) continue;

							const vector<int>& prSubs=asi3_inVector[prIter].second;
							for(int prSubIter=0;(size_t)prSubIter<prSubs.size();prSubIter++)
							{
								int prsub=prSubs[prSubIter];
								double ruleScore=rule->getScore(lcsub,rcsub,prsub);
								if(ruleScore>-1E10)
								{
									if(iot==inside)
									{
										if(n1.iScore(lc,lcsub)<0||n2.iScore(rc,rcsub)<0)cerr<<"bug3"<<endl;
										if(n3.iScore(pr,prsub)<0) n3.iScore(pr,prsub)=0;
										n3.iScore(pr,prsub)+=n1.iScore(lc,lcsub)*n2.iScore(rc,rcsub)*ruleScore;
									}
									else if(iot==outside)
									{
										if(n3.oScore(pr,prsub)<0) continue;  //cerr<<"bug4"<<endl;
										if(n1.oScore(lc,lcsub)<0) n1.oScore(lc,lcsub)=0;
										if(n2.oScore(rc,rcsub)<0) n2.oScore(rc,rcsub)=0;										
										n1.oScore(lc,lcsub)+=n3.oScore(pr,prsub)*n2.iScore(rc,rcsub)*ruleScore;
										n2.oScore(rc,rcsub)+=n3.oScore(pr,prsub)*n1.iScore(lc,lcsub)*ruleScore;
									}
								}
							}
						}
					}
					else
					{
						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 pr=rule->parentState();
							//int prsub=0;
							for(int prsub=0;prsub<prNumSubState;prsub++)
							{
								double ruleScore=rule->getScore(lcsub,rcsub,prsub);
								if(ruleScore>-1E10)
								{
									if(iot==inside)
									{
										if(n1.iScore(lc,lcsub)<0||n2.iScore(rc,rcsub)<0)cerr<<"bug"<<endl;
										if(n3.iScore(pr,prsub)<0) n3.iScore(pr,prsub)=0;
										n3.iScore(pr,prsub)+=n1.iScore(lc,lcsub)*n2.iScore(rc,rcsub)*ruleScore;
									}
									else if(iot==outside)
									{
										if(n3.oScore(pr,prsub)<0)continue;//cerr<<"bug2"<<endl;
										if(n1.oScore(lc,lcsub)<0) n1.oScore(lc,lcsub)=0;
										if(n2.oScore(rc,rcsub)<0) n2.oScore(rc,rcsub)=0;
										n1.oScore(lc,lcsub)+=n3.oScore(pr,prsub)*n2.iScore(rc,rcsub)*ruleScore;
										n2.oScore(rc,rcsub)+=n3.oScore(pr,prsub)*n1.iScore(lc,lcsub)*ruleScore;
									}
								}
							}
						}
					}
					//make new node finished
				}
			}
		}
	}
	return n3;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %r8d, 0xc(%rsp)
movq %rcx, %rbx
movq %rdi, 0x60(%rsp)
movq %rsi, 0x30(%rsp)
leaq 0x60(%rsi), %rdi
movq %rdx, 0x50(%rsp)
leaq 0x60(%rdx), %r12
leaq 0x60(%rcx), %r13
callq 0x2b5fa
movq %rax, %r14
movq %r12, %rdi
callq 0x2b5fa
movq %rax, %r15
movq %r13, %rdi
callq 0x2b5fa
movq %rbx, %r9
movq %rax, 0x58(%rsp)
movq 0x8(%r14), %rax
movq %r14, 0x90(%rsp)
subq (%r14), %rax
shrq $0x5, %rax
movq 0x8(%r15), %rcx
movq %r15, 0xb0(%rsp)
subq (%r15), %rcx
shrq $0x5, %rcx
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
movq %rcx, 0xc0(%rsp)
testl %eax, %eax
cmovlel %edx, %eax
movq %rax, 0x98(%rsp)
movsd 0x1b560(%rip), %xmm2    # 0x320d0
xorpd %xmm3, %xmm3
xorl %ecx, %ecx
movq %rbx, 0x80(%rsp)
cmpq 0x98(%rsp), %rcx
je 0x171a4
movq 0x90(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0xa0(%rsp)
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0xa8(%rsp)
movslq (%rax,%rcx), %rax
movq %rax, 0x68(%rsp)
xorl %edx, %edx
movl 0xc(%rsp), %r10d
movq 0x50(%rsp), %r11
movq 0x30(%rsp), %r8
movq 0xa8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rdx, %rcx
jbe 0x17194
movq %rdx, %rcx
movslq (%rax,%rdx,4), %rdi
xorl %eax, %eax
movq %rdi, 0x38(%rsp)
movq %rdx, 0xb8(%rsp)
cmpq 0xc0(%rsp), %rax
je 0x17189
movq %rax, %rcx
movq 0xb0(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0xc8(%rsp)
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0xd0(%rsp)
movslq (%rax,%rcx), %rax
movq %rax, 0x70(%rsp)
xorl %edx, %edx
movq 0xd0(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rdx, %rcx
jbe 0x17171
movslq (%rax,%rdx,4), %rax
movq %rax, 0x88(%rsp)
cmpb $0x1, 0x90(%r9)
movq %rdx, 0x78(%rsp)
jne 0x16f07
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x5, %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movq %rcx, 0x40(%rsp)
xorl %ecx, %ecx
cmpq 0x40(%rsp), %rcx
je 0x17169
movq 0x58(%rsp), %rax
movq (%rax), %r14
movq %rcx, 0x48(%rsp)
movq %rcx, %rax
shlq $0x5, %rax
movslq (%r14,%rax), %rdx
movq 0x60(%rsp), %rcx
movq 0x1d8(%rcx), %rcx
imulq $0x18, 0x68(%rsp), %rsi
movq %rsi, 0x18(%rsp)
movq (%rcx,%rsi), %rcx
imulq $0x18, 0x70(%rsp), %rsi
movq %rsi, 0x20(%rsp)
movq (%rcx,%rsi), %rcx
movq %rdx, 0x10(%rsp)
movq (%rcx,%rdx,8), %rbx
testq %rbx, %rbx
je 0x16ef5
addq %rax, %r14
xorl %r15d, %r15d
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r15, %rcx
jbe 0x16ef5
movslq (%rax,%r15,4), %r12
movq (%rbx), %rax
imulq $0x18, %rdi, %rbp
movq (%rax,%rbp), %rax
imulq $0x18, 0x88(%rsp), %r13
movq (%rax,%r13), %rax
movsd (%rax,%r12,8), %xmm4
ucomisd %xmm2, %xmm4
jbe 0x16eed
cmpl $0x1, %r10d
je 0x16e40
testl %r10d, %r10d
jne 0x16eed
movq 0xb8(%r8), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx), %rax
ucomisd (%rax,%rbp), %xmm3
ja 0x16d89
movq 0xb8(%r11), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx), %rax
ucomisd (%rax,%r13), %xmm3
jbe 0x16dd8
movq 0x35260(%rip), %rdi     # 0x4bff0
leaq 0x1b5e2(%rip), %rsi     # 0x32379
movsd %xmm4, 0x28(%rsp)
callq 0x32d0
movq %rax, %rdi
callq 0x3130
movsd 0x28(%rsp), %xmm4
movq 0x38(%rsp), %rdi
xorpd %xmm3, %xmm3
movsd 0x1b30f(%rip), %xmm2    # 0x320d0
movq 0x30(%rsp), %r8
movq 0x50(%rsp), %r11
movl 0xc(%rsp), %r10d
movq 0x80(%rsp), %r9
movq 0xb8(%r9), %rax
imulq $0x18, 0x10(%rsp), %rcx
movq (%rax,%rcx), %rcx
imulq $0x18, %r12, %rdx
leaq (%rcx,%rdx), %rax
movsd (%rcx,%rdx), %xmm0
ucomisd %xmm0, %xmm3
jbe 0x16e04
andq $0x0, (%rax)
xorpd %xmm0, %xmm0
movq 0xb8(%r8), %rcx
movq 0x18(%rsp), %rdx
movq (%rcx,%rdx), %rcx
movsd (%rcx,%rbp), %xmm1
movq 0xb8(%r11), %rcx
movq 0x20(%rsp), %rdx
movq (%rcx,%rdx), %rcx
mulsd (%rcx,%r13), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
jmp 0x16eed
movq 0xb8(%r9), %rax
imulq $0x18, 0x10(%rsp), %rcx
movq (%rax,%rcx), %rdx
imulq $0x18, %r12, %rsi
ucomisd 0x8(%rdx,%rsi), %xmm3
ja 0x16eed
movq 0xb8(%r8), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx), %rax
leaq (%rax,%rbp), %rcx
addq $0x8, %rcx
movsd (%rcx), %xmm0
ucomisd %xmm0, %xmm3
jbe 0x16e8b
andq $0x0, (%rcx)
xorpd %xmm0, %xmm0
movq 0xb8(%r11), %rdi
movq 0x20(%rsp), %r8
movq (%rdi,%r8), %r8
leaq (%r8,%r13), %rdi
addq $0x8, %rdi
ucomisd (%rdi), %xmm3
jbe 0x16eb1
andq $0x0, (%rdi)
movsd (%rcx), %xmm0
addq %rsi, %rdx
addq $0x8, %rdx
movsd (%rdx), %xmm1
mulsd (%r8,%r13), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rcx)
movsd (%rdx), %xmm0
mulsd (%rax,%rbp), %xmm0
mulsd %xmm4, %xmm0
addsd (%rdi), %xmm0
movsd %xmm0, (%rdi)
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %rdi
incq %r15
jmp 0x16d03
movq 0x48(%rsp), %rcx
incq %rcx
movq 0x78(%rsp), %rdx
jmp 0x16c9e
movq 0x60(%rsp), %rax
movq 0x208(%rax), %rax
imulq $0x18, 0x68(%rsp), %rsi
imulq $0x18, 0x70(%rsp), %rcx
movq (%rax,%rsi), %rbx
movq %rcx, 0x10(%rsp)
addq %rcx, %rbx
movq %rbx, 0x40(%rsp)
xorl %ebx, %ebx
movq %rsi, 0x28(%rsp)
movq 0x40(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
jbe 0x17169
movq %rbx, 0x48(%rsp)
movq (%rax,%rbx,8), %r15
testq %r15, %r15
je 0x17157
movl 0x84(%r15), %ebx
movslq 0x78(%r15), %rax
movq %rax, 0x18(%rsp)
testl %ebx, %ebx
movl $0x0, %eax
cmovlel %eax, %ebx
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpq %rbp, %rbx
je 0x17157
movq (%r15), %rax
imulq $0x18, %rdi, %r13
movq (%rax,%r13), %rax
imulq $0x18, 0x88(%rsp), %r12
movq (%rax,%r12), %rax
movsd (%rax,%rbp,8), %xmm4
ucomisd %xmm2, %xmm4
jbe 0x1714b
cmpl $0x1, %r10d
je 0x170a6
testl %r10d, %r10d
jne 0x1714b
movq 0xb8(%r8), %rax
movq (%rax,%rsi), %rax
ucomisd (%rax,%r13), %xmm3
ja 0x16ff2
movq 0xb8(%r11), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx), %rax
ucomisd (%rax,%r12), %xmm3
jbe 0x17046
movq 0x34ff7(%rip), %rdi     # 0x4bff0
leaq 0x1bc57(%rip), %rsi     # 0x32c57
movsd %xmm4, 0x20(%rsp)
callq 0x32d0
movq %rax, %rdi
callq 0x3130
movsd 0x20(%rsp), %xmm4
movq 0x28(%rsp), %rsi
movq 0x38(%rsp), %rdi
xorpd %xmm3, %xmm3
movsd 0x1b0a1(%rip), %xmm2    # 0x320d0
movq 0x30(%rsp), %r8
movq 0x50(%rsp), %r11
movl 0xc(%rsp), %r10d
movq 0x80(%rsp), %r9
movq 0xb8(%r9), %rax
imulq $0x18, 0x18(%rsp), %rcx
movq (%rax,%rcx), %rax
movsd (%rax,%r14), %xmm0
ucomisd %xmm0, %xmm3
jbe 0x1706c
andq $0x0, (%rax,%r14)
xorpd %xmm0, %xmm0
movq 0xb8(%r8), %rcx
movq (%rcx,%rsi), %rcx
movsd (%rcx,%r13), %xmm1
movq 0xb8(%r11), %rcx
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx), %rcx
mulsd (%rcx,%r12), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax,%r14)
jmp 0x1714b
movq 0xb8(%r9), %rax
imulq $0x18, 0x18(%rsp), %rcx
movq (%rax,%rcx), %rax
ucomisd 0x8(%rax,%r14), %xmm3
ja 0x1714b
movq 0xb8(%r8), %rcx
movq (%rcx,%rsi), %rcx
leaq (%rcx,%r13), %rdx
addq $0x8, %rdx
movsd (%rdx), %xmm0
ucomisd %xmm0, %xmm3
jbe 0x170e9
andq $0x0, (%rdx)
xorpd %xmm0, %xmm0
movq 0xb8(%r11), %rsi
movq 0x10(%rsp), %rdi
movq (%rsi,%rdi), %rdi
leaq (%rdi,%r12), %rsi
addq $0x8, %rsi
ucomisd (%rsi), %xmm3
jbe 0x1710f
andq $0x0, (%rsi)
movsd (%rdx), %xmm0
movsd 0x8(%rax,%r14), %xmm1
mulsd (%rdi,%r12), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rdx)
movsd 0x8(%rax,%r14), %xmm0
mulsd (%rcx,%r13), %xmm0
mulsd %xmm4, %xmm0
addsd (%rsi), %xmm0
movsd %xmm0, (%rsi)
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rsi
incq %rbp
addq $0x18, %r14
jmp 0x16f84
movq 0x48(%rsp), %rbx
incq %rbx
movq 0x78(%rsp), %rdx
jmp 0x16f37
incq %rdx
jmp 0x16c3e
movq 0xc8(%rsp), %rax
incq %rax
movq 0xb8(%rsp), %rcx
jmp 0x16bff
incq %rcx
movq %rcx, %rdx
jmp 0x16bc9
movq 0xa0(%rsp), %rcx
incq %rcx
jmp 0x16b7e
movq %r9, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop