// File: /workspace/github_cpp_makefile_star2_O3/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, %ebp
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, 0x78(%rsp)
leaq 0x60(%rsi), %rdi
movq %rdx, 0x28(%rsp)
leaq 0x60(%rdx), %r12
leaq 0x60(%rcx), %r13
callq 0x3793e
movq %rax, %r15
movq %r12, %rdi
callq 0x3793e
movq %rax, 0x68(%rsp)
movq %r13, %rdi
callq 0x3793e
movq %rbx, %r11
movq %rax, 0x70(%rsp)
movq 0x8(%r15), %rax
movq %r15, 0xa0(%rsp)
subq (%r15), %rax
shrq $0x5, %rax
movq %rax, 0x60(%rsp)
testl %eax, %eax
jle 0x1c48c
movq %r14, %r10
movl %ebp, %r9d
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 %edx, %edx
movsd 0x24385(%rip), %xmm2    # 0x400d0
xorpd %xmm3, %xmm3
movq %r11, 0x90(%rsp)
movl %ebp, 0x14(%rsp)
movq %r14, 0x58(%rsp)
movq 0xa0(%rsp), %rax
movq (%rax), %rcx
movq %rdx, 0xa8(%rsp)
shlq $0x5, %rdx
movq 0x8(%rcx,%rdx), %rax
movq %rcx, %rsi
movq 0x10(%rcx,%rdx), %rcx
cmpq %rax, %rcx
je 0x1c476
addq %rdx, %rsi
movq %rsi, 0xb0(%rsp)
movslq (%rsi), %rdx
movq %rdx, 0x80(%rsp)
xorl %esi, %esi
cmpl $0x0, 0xb8(%rsp)
jle 0x1c460
movq %rsi, 0xc0(%rsp)
movslq (%rax,%rsi,4), %rbx
xorl %ecx, %ecx
movq %rbx, 0x98(%rsp)
movq 0x68(%rsp), %rax
movq (%rax), %rsi
movq %rcx, 0xd0(%rsp)
shlq $0x5, %rcx
movq 0x8(%rsi,%rcx), %rax
cmpq %rax, 0x10(%rsi,%rcx)
je 0x1c42f
movq %rsi, %rdx
addq %rcx, %rdx
movq %rdx, 0xd8(%rsp)
movslq (%rdx), %rcx
movq %rcx, 0x88(%rsp)
xorl %edx, %edx
movq %rdx, 0xe0(%rsp)
movslq (%rax,%rdx,4), %r8
cmpb $0x1, 0x90(%r11)
movq %r8, 0x40(%rsp)
jne 0x1c12f
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x5, %rcx
movq %rcx, 0x30(%rsp)
testl %ecx, %ecx
jle 0x1c404
movq 0x30(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x30(%rsp)
xorl %ecx, %ecx
movq 0x70(%rsp), %rax
movq (%rax), %rdx
movq %rcx, 0x48(%rsp)
movq %rcx, %rax
shlq $0x5, %rax
movq %rdx, %rsi
movslq (%rdx,%rax), %rdi
movq 0x78(%rsp), %rcx
movq 0x1d8(%rcx), %rcx
movq 0x80(%rsp), %rdx
leaq (%rdx,%rdx,2), %rdx
movq %rdx, 0x20(%rsp)
movq (%rcx,%rdx,8), %rcx
movq 0x88(%rsp), %rdx
leaq (%rdx,%rdx,2), %rdx
movq %rdx, 0x8(%rsp)
movq (%rcx,%rdx,8), %rcx
movq %rdi, 0x18(%rsp)
movq (%rcx,%rdi,8), %r15
testq %r15, %r15
je 0x1c117
addq %rax, %rsi
movq 0x8(%rsi), %rax
movq %rsi, 0x38(%rsp)
movq 0x10(%rsi), %rcx
cmpq %rax, %rcx
je 0x1c117
xorl %ebp, %ebp
movslq (%rax,%rbp,4), %r12
movq (%r15), %rdx
leaq (%rbx,%rbx,2), %r14
movq (%rdx,%r14,8), %rdx
leaq (%r8,%r8,2), %r13
movq (%rdx,%r13,8), %rdx
movsd (%rdx,%r12,8), %xmm4
ucomisd %xmm2, %xmm4
jbe 0x1c101
cmpl $0x1, %r9d
je 0x1c03b
testl %r9d, %r9d
jne 0x1c101
movq 0xb8(%r10), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rax
ucomisd (%rax,%r14,8), %xmm3
ja 0x1bf42
movq 0x28(%rsp), %rax
movq 0xb8(%rax), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
ucomisd (%rax,%r13,8), %xmm3
jbe 0x1bfbb
movl $0x4, %edx
movq 0x390a2(%rip), %rbx     # 0x54ff0
movq %rbx, %rdi
leaq 0x24421(%rip), %rsi     # 0x40379
movsd %xmm4, 0x50(%rsp)
callq 0x3350
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %rbx, %rdi
movq 0x98(%rsp), %rbx
callq 0x3030
movq %rax, %rdi
callq 0x31e0
movsd 0x50(%rsp), %xmm4
movq 0x40(%rsp), %r8
xorpd %xmm3, %xmm3
movsd 0x24127(%rip), %xmm2    # 0x400d0
movq 0x58(%rsp), %r10
movl 0x14(%rsp), %r9d
movq 0x90(%rsp), %r11
movq 0xb8(%r11), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
leaq (%r12,%r12,2), %rcx
leaq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
ucomisd %xmm0, %xmm3
jbe 0x1bfec
movq $0x0, (%rax)
xorpd %xmm0, %xmm0
movq 0xb8(%r10), %rcx
movq 0x20(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd (%rcx,%r14,8), %xmm1
movq 0x28(%rsp), %rcx
movq 0xb8(%rcx), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
mulsd (%rcx,%r13,8), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
movq 0x38(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
jmp 0x1c101
movq 0xb8(%r11), %rdx
movq 0x18(%rsp), %rsi
leaq (%rsi,%rsi,2), %rsi
movq (%rdx,%rsi,8), %rdi
leaq (%r12,%r12,2), %r8
ucomisd 0x8(%rdi,%r8,8), %xmm3
ja 0x1c0fc
movq 0xb8(%r10), %rdx
movq 0x20(%rsp), %rsi
movq (%rdx,%rsi,8), %rdx
leaq (%rdx,%r14,8), %rsi
addq $0x8, %rsi
movsd (%rsi), %xmm0
ucomisd %xmm0, %xmm3
jbe 0x1c08d
movq $0x0, (%rsi)
xorpd %xmm0, %xmm0
movq 0x28(%rsp), %r9
movq 0xb8(%r9), %r9
movq 0x8(%rsp), %r10
movq (%r9,%r10,8), %r10
leaq (%r10,%r13,8), %r9
addq $0x8, %r9
ucomisd (%r9), %xmm3
jbe 0x1c0bc
movq $0x0, (%r9)
movsd (%rsi), %xmm0
leaq (%rdi,%r8,8), %rdi
addq $0x8, %rdi
movsd (%rdi), %xmm1
mulsd (%r10,%r13,8), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsi)
movsd (%rdi), %xmm0
mulsd (%rdx,%r14,8), %xmm0
mulsd %xmm4, %xmm0
addsd (%r9), %xmm0
movsd %xmm0, (%r9)
movl 0x14(%rsp), %r9d
movq 0x58(%rsp), %r10
movq 0x40(%rsp), %r8
incq %rbp
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbp, %rdx
ja 0x1bed3
movq 0x48(%rsp), %rcx
incq %rcx
cmpq 0x30(%rsp), %rcx
jne 0x1be55
jmp 0x1c404
movq 0x78(%rsp), %rax
movq 0x208(%rax), %rax
movq 0x80(%rsp), %rcx
leaq (%rcx,%rcx,2), %rsi
movq (%rax,%rsi,8), %rdx
movq 0x88(%rsp), %rax
leaq (%rax,%rax,2), %rcx
movq (%rdx,%rcx,8), %rax
movq %rcx, 0x8(%rsp)
movq 0x8(%rdx,%rcx,8), %rcx
cmpq %rax, %rcx
je 0x1c404
movq 0x8(%rsp), %rdi
leaq (%rdx,%rdi,8), %rdx
movq %rdx, 0x30(%rsp)
xorl %edi, %edi
movq %rsi, 0x38(%rsp)
movq (%rax,%rdi,8), %rbp
testq %rbp, %rbp
je 0x1c3ee
movslq 0x84(%rbp), %rdx
movq %rdx, 0x18(%rsp)
testq %rdx, %rdx
jle 0x1c3ee
movq %rdi, 0x48(%rsp)
movslq 0x78(%rbp), %rax
movq %rax, 0x20(%rsp)
movl $0x1, %r14d
xorl %r15d, %r15d
movq 0x18(%rsp), %rdi
movq (%rbp), %rax
leaq (%rbx,%rbx,2), %r13
movq (%rax,%r13,8), %rax
leaq (%r8,%r8,2), %r12
movq (%rax,%r12,8), %rax
movsd (%rax,%r15,8), %xmm4
ucomisd %xmm2, %xmm4
jbe 0x1c3cd
cmpl $0x1, %r9d
je 0x1c31d
testl %r9d, %r9d
jne 0x1c3cd
movq 0xb8(%r10), %rax
movq (%rax,%rsi,8), %rax
ucomisd (%rax,%r13,8), %xmm3
ja 0x1c22c
movq 0x28(%rsp), %rax
movq 0xb8(%rax), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
ucomisd (%rax,%r12,8), %xmm3
jbe 0x1c2af
movl $0x3, %edx
movq 0x38db8(%rip), %rbx     # 0x54ff0
movq %rbx, %rdi
leaq 0x24a1d(%rip), %rsi     # 0x40c5f
movsd %xmm4, 0x50(%rsp)
callq 0x3350
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %rbx, %rdi
movq 0x98(%rsp), %rbx
callq 0x3030
movq %rax, %rdi
callq 0x31e0
movsd 0x50(%rsp), %xmm4
movq 0x18(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %r8
xorpd %xmm3, %xmm3
movsd 0x23e33(%rip), %xmm2    # 0x400d0
movq 0x58(%rsp), %r10
movl 0x14(%rsp), %r9d
movq 0x90(%rsp), %r11
movq 0xb8(%r11), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
movsd -0x8(%rax,%r14,8), %xmm0
ucomisd %xmm0, %xmm3
jbe 0x1c2dd
movq $0x0, -0x8(%rax,%r14,8)
xorpd %xmm0, %xmm0
movq 0xb8(%r10), %rcx
movq (%rcx,%rsi,8), %rcx
movsd (%rcx,%r13,8), %xmm1
movq 0x28(%rsp), %rcx
movq 0xb8(%rcx), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
mulsd (%rcx,%r12,8), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x8(%rax,%r14,8)
jmp 0x1c3cd
movq 0xb8(%r11), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
ucomisd (%rax,%r14,8), %xmm3
ja 0x1c3cd
movq 0xb8(%r10), %rcx
movq (%rcx,%rsi,8), %rcx
leaq (%rcx,%r13,8), %rdx
addq $0x8, %rdx
movsd (%rdx), %xmm0
ucomisd %xmm0, %xmm3
jbe 0x1c365
movq $0x0, (%rdx)
xorpd %xmm0, %xmm0
movq 0x28(%rsp), %rsi
movq 0xb8(%rsi), %rsi
movq 0x8(%rsp), %rdi
movq (%rsi,%rdi,8), %rdi
leaq (%rdi,%r12,8), %rsi
addq $0x8, %rsi
ucomisd (%rsi), %xmm3
jbe 0x1c393
movq $0x0, (%rsi)
movsd (%rdx), %xmm0
movsd (%rax,%r14,8), %xmm1
mulsd (%rdi,%r12,8), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rdx)
movsd (%rax,%r14,8), %xmm0
mulsd (%rcx,%r13,8), %xmm0
mulsd %xmm4, %xmm0
addsd (%rsi), %xmm0
movsd %xmm0, (%rsi)
movq 0x38(%rsp), %rsi
movq 0x18(%rsp), %rdi
incq %r15
addq $0x3, %r14
cmpq %r15, %rdi
jne 0x1c1c1
movq 0x30(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movq 0x48(%rsp), %rdi
incq %rdi
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rdi, %rdx
ja 0x1c183
movq 0xe0(%rsp), %rdx
incq %rdx
movq 0xd8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rdx, %rcx
ja 0x1be08
movq 0xd0(%rsp), %rcx
incq %rcx
cmpq 0xc8(%rsp), %rcx
jne 0x1bdc9
movq 0xb0(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
movq 0xc0(%rsp), %rsi
incq %rsi
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
ja 0x1bda5
movq 0xa8(%rsp), %rdx
incq %rdx
cmpq 0x60(%rsp), %rdx
jne 0x1bd60
movq %r11, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop