// File: /workspace/github_cpp_makefile_star2_O1/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 $0xe8, %rsp
movl %r8d, 0x14(%rsp)
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x78(%rsp)
leaq 0x60(%rsi), %rdi
leaq 0x60(%rdx), %r12
leaq 0x60(%rcx), %r13
callq 0x384f8
movq %rax, %rbp
movq %r12, %rdi
callq 0x384f8
movq %rax, 0x68(%rsp)
movq %r13, %rdi
callq 0x384f8
movl 0x14(%rsp), %r10d
movq %rbx, %r9
movq %rax, 0x70(%rsp)
movq 0x8(%rbp), %rax
movq %rbp, 0xa8(%rsp)
subq (%rbp), %rax
shrq $0x5, %rax
movq %rax, 0x60(%rsp)
testl %eax, %eax
jle 0x1ca93
movq %r15, %r8
movq %r14, %r11
movq 0x68(%rsp), %rax
movq 0x8(%rax), %rdx
subq (%rax), %rdx
shrq $0x5, %rdx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, 0x60(%rsp)
movq %rdx, 0xb8(%rsp)
andq %rax, %rdx
movq %rdx, 0xc8(%rsp)
xorl %ecx, %ecx
movsd 0x24d10(%rip), %xmm1    # 0x410d0
xorpd %xmm2, %xmm2
movq %r9, 0x98(%rsp)
movq %r14, 0x90(%rsp)
movq %r15, 0x58(%rsp)
movq 0xa8(%rsp), %rax
movq (%rax), %rsi
movq %rcx, 0xb0(%rsp)
shlq $0x5, %rcx
movq 0x8(%rsi,%rcx), %rax
cmpq %rax, 0x10(%rsi,%rcx)
je 0x1ca7d
movq %rsi, %rdx
addq %rcx, %rdx
movq %rdx, 0xc0(%rsp)
movslq (%rdx), %rcx
movq %rcx, 0x80(%rsp)
movq $0x0, 0x40(%rsp)
cmpl $0x0, 0xb8(%rsp)
jle 0x1ca50
movq 0x40(%rsp), %rcx
movslq (%rax,%rcx,4), %rdx
xorl %ecx, %ecx
movq %rdx, 0x28(%rsp)
movq 0x68(%rsp), %rax
movq (%rax), %rdi
movq %rcx, 0xd0(%rsp)
shlq $0x5, %rcx
movq 0x8(%rdi,%rcx), %rax
cmpq %rax, 0x10(%rdi,%rcx)
je 0x1ca37
movq %rdi, %rsi
addq %rcx, %rsi
movq %rsi, 0xd8(%rsp)
movslq (%rsi), %rcx
movq %rcx, 0x88(%rsp)
xorl %esi, %esi
movq %rsi, 0xe0(%rsp)
movslq (%rax,%rsi,4), %rax
movq %rax, 0xa0(%rsp)
cmpb $0x1, 0x90(%r9)
jne 0x1c76d
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x5, %rcx
movq %rcx, 0x18(%rsp)
testl %ecx, %ecx
jle 0x1ca0c
movq 0x18(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
movq 0x70(%rsp), %rax
movq (%rax), %r14
movq %rcx, 0x50(%rsp)
movq %rcx, %rax
shlq $0x5, %rax
movslq (%r14,%rax), %r15
movq 0x78(%rsp), %rcx
movq 0x1d8(%rcx), %rcx
movq 0x80(%rsp), %rdx
leaq (%rdx,%rdx,2), %rsi
movq 0x28(%rsp), %rdx
movq %rsi, 0x8(%rsp)
movq (%rcx,%rsi,8), %rcx
movq 0x88(%rsp), %rsi
leaq (%rsi,%rsi,2), %rsi
movq %rsi, 0x20(%rsp)
movq (%rcx,%rsi,8), %rcx
movq (%rcx,%r15,8), %rcx
movq %rcx, 0x38(%rsp)
testq %rcx, %rcx
je 0x1c755
addq %rax, %r14
movq 0x8(%r14), %rax
cmpq %rax, 0x10(%r14)
je 0x1c755
xorl %ebp, %ebp
movq %r15, 0x48(%rsp)
movslq (%rax,%rbp,4), %r12
movq 0x38(%rsp), %rax
movq (%rax), %rax
leaq (%rdx,%rdx,2), %rbx
movq (%rax,%rbx,8), %rax
movq 0xa0(%rsp), %rcx
leaq (%rcx,%rcx,2), %r13
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm3
ucomisd %xmm1, %xmm3
jbe 0x1c73a
cmpl $0x1, %r10d
je 0x1c68c
testl %r10d, %r10d
jne 0x1c73a
movq 0xb8(%r8), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
ucomisd (%rax,%rbx,8), %xmm2
ja 0x1c5c2
movq 0xb8(%r11), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rax
ucomisd (%rax,%r13,8), %xmm2
jbe 0x1c62e
movl $0x4, %edx
movq 0x39a22(%rip), %r15     # 0x55ff0
movq %r15, %rdi
leaq 0x24da1(%rip), %rsi     # 0x41379
movsd %xmm3, 0x30(%rsp)
callq 0x3350
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r15, %rdi
movq 0x48(%rsp), %r15
callq 0x3030
movq %rax, %rdi
callq 0x31e0
movsd 0x30(%rsp), %xmm3
xorpd %xmm2, %xmm2
movq 0x58(%rsp), %r8
movq 0x90(%rsp), %r11
movq 0x98(%rsp), %r9
movq 0xb8(%r9), %rax
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %rax
leaq (%r12,%r12,2), %rcx
leaq (%rax,%rcx,8), %rax
ucomisd (%rax), %xmm2
jbe 0x1c652
movq $0x0, (%rax)
movq 0xb8(%r8), %rcx
shlq $0x3, %rbx
movq 0x8(%rsp), %rdx
addq (%rcx,%rdx,8), %rbx
movq 0xb8(%r11), %rcx
shlq $0x3, %r13
movq 0x20(%rsp), %rdx
addq (%rcx,%rdx,8), %r13
movl 0x14(%rsp), %r10d
movsd 0x24a49(%rip), %xmm1    # 0x410d0
jmp 0x1c71f
movq 0xb8(%r9), %rax
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %rsi
leaq (%r12,%r12,2), %rdi
ucomisd 0x8(%rsi,%rdi,8), %xmm2
ja 0x1c73a
movq 0xb8(%r8), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
leaq (%rcx,%rbx,8), %rdx
addq $0x8, %rdx
ucomisd (%rdx), %xmm2
jbe 0x1c6d0
movq $0x0, (%rdx)
movq 0xb8(%r11), %rax
movq 0x20(%rsp), %r8
movq (%rax,%r8,8), %r8
leaq (%r8,%r13,8), %rax
addq $0x8, %rax
ucomisd (%rax), %xmm2
jbe 0x1c6f5
movq $0x0, (%rax)
leaq (%rsi,%rdi,8), %rsi
addq $0x8, %rsi
movsd (%rsi), %xmm0
mulsd (%r8,%r13,8), %xmm0
mulsd %xmm3, %xmm0
addsd (%rdx), %xmm0
movsd %xmm0, (%rdx)
leaq (%rcx,%rbx,8), %r13
movq %rsi, %rbx
movq 0x58(%rsp), %r8
movq 0x28(%rsp), %rdx
movsd (%rbx), %xmm0
mulsd (%r13), %xmm0
mulsd %xmm3, %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
incq %rbp
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbp, %rcx
ja 0x1c54c
movq 0x50(%rsp), %rcx
incq %rcx
cmpq 0x18(%rsp), %rcx
jne 0x1c4cf
jmp 0x1ca0c
movq 0x78(%rsp), %rax
movq 0x208(%rax), %rax
movq 0x80(%rsp), %rcx
leaq (%rcx,%rcx,2), %r14
movq (%rax,%r14,8), %rcx
movq 0x88(%rsp), %rax
leaq (%rax,%rax,2), %rsi
movq (%rcx,%rsi,8), %rax
movq %rsi, 0x8(%rsp)
cmpq %rax, 0x8(%rcx,%rsi,8)
je 0x1ca0c
movq 0x8(%rsp), %rsi
leaq (%rcx,%rsi,8), %rcx
movq %rcx, 0x18(%rsp)
xorl %esi, %esi
movq %r14, 0x48(%rsp)
movq %rsi, 0x50(%rsp)
movq (%rax,%rsi,8), %rbx
testq %rbx, %rbx
je 0x1c9e8
movslq 0x84(%rbx), %rsi
testq %rsi, %rsi
jle 0x1c9e8
movslq 0x78(%rbx), %rax
movq %rax, 0x38(%rsp)
movl $0x8, %ebp
xorl %r15d, %r15d
movq %rsi, 0x30(%rsp)
movq (%rbx), %rax
leaq (%rdx,%rdx,2), %r13
movq (%rax,%r13,8), %rax
movq 0xa0(%rsp), %rcx
leaq (%rcx,%rcx,2), %r12
movq (%rax,%r12,8), %rax
movsd (%rax,%r15,8), %xmm3
ucomisd %xmm1, %xmm3
jbe 0x1c9d8
cmpl $0x1, %r10d
je 0x1c932
testl %r10d, %r10d
jne 0x1c9d8
movq 0xb8(%r8), %rax
movq (%rax,%r14,8), %rax
ucomisd (%rax,%r13,8), %xmm2
ja 0x1c85f
movq 0xb8(%r11), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
ucomisd (%rax,%r12,8), %xmm2
jbe 0x1c8d0
movl $0x3, %edx
movq 0x39785(%rip), %r14     # 0x55ff0
movq %r14, %rdi
leaq 0x253da(%rip), %rsi     # 0x41c4f
movsd %xmm3, 0x20(%rsp)
callq 0x3350
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r14, %rdi
movq 0x48(%rsp), %r14
callq 0x3030
movq %rax, %rdi
callq 0x31e0
movsd 0x20(%rsp), %xmm3
movq 0x30(%rsp), %rsi
xorpd %xmm2, %xmm2
movq 0x58(%rsp), %r8
movq 0x90(%rsp), %r11
movq 0x98(%rsp), %r9
movq 0xb8(%r9), %rax
movq 0x38(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
addq %rbp, %rax
addq $-0x8, %rax
ucomisd (%rax), %xmm2
jbe 0x1c8f8
movq $0x0, (%rax)
movq 0xb8(%r8), %rcx
shlq $0x3, %r13
addq (%rcx,%r14,8), %r13
movq 0xb8(%r11), %rcx
shlq $0x3, %r12
movq 0x8(%rsp), %rdx
addq (%rcx,%rdx,8), %r12
movl 0x14(%rsp), %r10d
movsd 0x247a8(%rip), %xmm1    # 0x410d0
movq 0x28(%rsp), %rdx
jmp 0x1c9c0
movq 0xb8(%r9), %rax
movq 0x38(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rcx
ucomisd (%rcx,%rbp), %xmm2
ja 0x1c9d8
movq 0xb8(%r8), %rax
movq (%rax,%r14,8), %rdx
leaq (%rdx,%r13,8), %rsi
addq $0x8, %rsi
ucomisd (%rsi), %xmm2
jbe 0x1c971
movq $0x0, (%rsi)
movq 0xb8(%r11), %rax
movq 0x8(%rsp), %rdi
movq (%rax,%rdi,8), %rdi
leaq (%rdi,%r12,8), %rax
addq $0x8, %rax
ucomisd (%rax), %xmm2
jbe 0x1c996
movq $0x0, (%rax)
addq %rbp, %rcx
movsd (%rcx), %xmm0
mulsd (%rdi,%r12,8), %xmm0
mulsd %xmm3, %xmm0
addsd (%rsi), %xmm0
movsd %xmm0, (%rsi)
leaq (%rdx,%r13,8), %r12
movq %rcx, %r13
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rsi
movsd (%r13), %xmm0
mulsd (%r12), %xmm0
mulsd %xmm3, %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
incq %r15
addq $0x18, %rbp
cmpq %r15, %rsi
jne 0x1c7f6
movq 0x50(%rsp), %rsi
incq %rsi
movq 0x18(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rsi, %rcx
ja 0x1c7be
movq 0xe0(%rsp), %rsi
incq %rsi
movq 0xd8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rsi, %rcx
ja 0x1c47f
movq 0xd0(%rsp), %rcx
incq %rcx
cmpq 0xc8(%rsp), %rcx
jne 0x1c440
movq 0x40(%rsp), %rsi
incq %rsi
movq 0xc0(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movq %rsi, 0x40(%rsp)
cmpq %rsi, %rcx
ja 0x1c422
movq 0xb0(%rsp), %rcx
incq %rcx
cmpq 0x60(%rsp), %rcx
jne 0x1c3d9
movq %r9, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq