// File: /workspace/github_cpp_makefile_star2_O3/neubig[P]egret/Egret/src/Forest-Berkeley-2.cpp
// Function: genUnaryNode_withoutLabel_berkeley(BerkeleyRuleSet const&, Node&, IorO)
bool genUnaryNode_withoutLabel_berkeley(const BerkeleyRuleSet& ruleSet, Node& node, IorO iot)
{
	if(node.useAllowState())
	{
		Node tempNode(node.start(),node.stop());
		tempNode.reset_scorePool(ruleSet.bsio());

		const AllowStateInfo& asi=node.allowStateInfo();
		const vector<pair<int,vector<int> > >& asi_inVector=asi.allowStateAndSubStates();

		for(int prIter=0;(size_t)prIter<asi_inVector.size();prIter++)
		{
			int pr=asi_inVector[prIter].first;
			
			for(int chIter=0;(size_t)chIter<asi_inVector.size();chIter++)
			{
				int ch=asi_inVector[chIter].first;	
		
				if(ch==pr)continue;

				const BerkeleyUnaryRule* rule=ruleSet.getUnaryRuleByRule(ch,pr);
				if(rule==NULL)continue;

				const vector<int>& chSubs=asi_inVector[chIter].second;
				const vector<int>& prSubs=asi_inVector[prIter].second;

				for(int chSubIter=0;(size_t)chSubIter<chSubs.size();chSubIter++)
				{
					int chsub=chSubs[chSubIter];
						
					for(int prSubIter=0;(size_t)prSubIter<prSubs.size();prSubIter++)
					{
						int prsub=prSubs[prSubIter];
						if(ch==pr&&chsub==prsub)continue;
						double ruleScore=rule->getScore(chsub,prsub);
						if(ruleScore>0)
						{
							if(iot==inside)
							{
								if(node.iScore(ch,chsub)<0)continue;
								/*if(node.iScore(pr,prsub)<0)node.iScore(pr,prsub)=0;
								node.iScore(pr,prsub)+=(node.iScore(ch,chsub)*ruleScore);
								*/
								if(tempNode.iScore(pr,prsub)<0)tempNode.iScore(pr,prsub)=0;
								tempNode.iScore(pr,prsub)+=(node.iScore(ch,chsub)*ruleScore);
							}
							else if(iot==outside)
							{
								if(node.oScore(pr,prsub)<0)continue;
								/*if(node.oScore(ch,chsub)<0)node.oScore(ch,chsub)=0;
								node.oScore(ch,chsub)+=(node.oScore(pr,prsub)*ruleScore);
								*/
								if(tempNode.oScore(ch,chsub)<0)tempNode.oScore(ch,chsub)=0;
								tempNode.oScore(ch,chsub)+=(node.oScore(pr,prsub)*ruleScore);
								if(node.oScore(ch,chsub)>1)
									cerr<<"error here "<<pr<<","<<prsub<<" -- "<<ch<<","<<chsub<<":"<<ruleScore<<endl;
							}					
						}
					}	
				}
			}
		}
		
		for(int chIter=0;(size_t)chIter<asi_inVector.size();chIter++)
		{
			int ch=asi_inVector[chIter].first;
			const vector<int>& chSubs=asi_inVector[chIter].second;
			for(int chSubIter=0;(size_t)chSubIter<chSubs.size();chSubIter++)
			{
				int chsub=chSubs[chSubIter];
				if(iot==inside)
				{
					if(node.iScore(ch,chsub)<0)
						node.iScore(ch,chsub)=tempNode.iScore(ch,chsub);
					else if(tempNode.iScore(ch,chsub)>0)
						node.iScore(ch,chsub)+=tempNode.iScore(ch,chsub);
				}
				else if(iot==outside)
				{
					if(node.oScore(ch,chsub)<0)
						node.oScore(ch,chsub)=tempNode.oScore(ch,chsub);
					else if(tempNode.oScore(ch,chsub)>0)
						node.oScore(ch,chsub)+=tempNode.oScore(ch,chsub);
				}
			}
		}
	}
	else
	{
		const BerkeleyStateInfoOfOneLevel& bsio=ruleSet.bsio();
		int numOfState=(int)bsio.numOfState();
		for(int pr=0;pr<numOfState;pr++)
		{
			for(int ch=0;ch<numOfState;ch++)	
			{
				const BerkeleyUnaryRule* rule=ruleSet.getUnaryRuleByRule(ch,pr);
				if(rule==NULL)continue;

				int ch_numOfSubState=bsio.state2numSubState(ch);
				int pr_numOfSubState=bsio.state2numSubState(pr);
				for(int chsub=0;chsub<ch_numOfSubState;chsub++)
				{
					for(int prsub=0;prsub<pr_numOfSubState;prsub++)
					{
						if(ch==pr&&chsub==prsub)continue;
						
						double ruleScore=rule->getScore(chsub,prsub);
						if(ruleScore>0)
						{
							if(iot==inside)
							{
								if(node.iScore(ch,chsub)<0)continue;
								if(node.iScore(pr,prsub)<0)node.iScore(pr,prsub)=0;
								node.iScore(pr,prsub)+=node.iScore(ch,chsub)*ruleScore;
								//cout<<ch<<","<<chsub<<" -- "<<pr<<","<<prsub<<":"<<ruleScore<<endl;
							}
							else if(iot==outside)
							{
								if(node.oScore(pr,prsub)<0)continue;
								if(node.oScore(ch,chsub)<0)node.oScore(ch,chsub)=0;
								node.oScore(ch,chsub)+=node.oScore(pr,prsub)*ruleScore;
								
							}
						}
					}
				}
			}
		}
		
	}
	const AllowStateInfo& asi=node.set_allowStateAndSubState_withoutLabel(1,0,0);
		//cout<<"allow State:"<<endl;
	//asi.print(cout);
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movl %edx, %ebp
cmpb $0x1, 0x90(%rsi)
movq %rdi, 0x30(%rsp)
movq %rsi, 0x20(%rsp)
jne 0x1b98f
movq %rsi, %rdx
leaq 0x78(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
leaq 0xd8(%rsp), %rax
movl %ecx, (%rax)
movq %rcx, 0x8(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x40(%rax)
movupd %xmm0, -0x30(%rax)
movupd %xmm0, -0x20(%rax)
movq %rcx, -0x10(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
movupd %xmm0, 0x30(%rax)
movq %rcx, 0x40(%rax)
movb $0x0, 0x28(%rax)
movupd %xmm0, 0x50(%rax)
movupd %xmm0, 0x60(%rax)
movupd %xmm0, 0x70(%rax)
movupd %xmm0, 0x80(%rax)
movupd %xmm0, 0x90(%rax)
movupd %xmm0, 0xa0(%rax)
movq 0xb0(%rsi), %rcx
movq %rcx, 0x48(%rax)
leaq 0x368(%rdi), %rsi
leaq 0x70(%rsp), %rdi
movq %rdx, %rbx
callq 0x36b6c
leaq 0x60(%rbx), %rdi
callq 0x3793e
movq (%rax), %r15
movq %rax, 0x48(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, %rcx
subq %r15, %rcx
movq 0x30(%rsp), %rsi
je 0x1bb66
movq $0x0, 0x38(%rsp)
cmpq %r15, %rdx
je 0x1b967
movq 0x38(%rsp), %rax
shlq $0x5, %rax
movq %rax, 0x50(%rsp)
movslq (%r15,%rax), %r10
xorl %eax, %eax
movq %r10, 0x18(%rsp)
movq %rax, %rcx
shlq $0x5, %rcx
movslq (%r15,%rcx), %r8
cmpl %r10d, %r8d
je 0x1b94f
movq %rcx, %rdi
movq 0x1f0(%rsi), %rcx
movq %r8, 0x40(%rsp)
leaq (%r8,%r8,2), %r8
movq %r8, 0x8(%rsp)
movq (%rcx,%r8,8), %rcx
movq (%rcx,%r10,8), %r14
testq %r14, %r14
je 0x1b94f
addq %r15, %rdi
movq 0x8(%rdi), %rsi
movq %rdi, 0x60(%rsp)
movq 0x10(%rdi), %rdi
cmpq %rsi, %rdi
je 0x1b94a
movq %rax, 0x58(%rsp)
movq 0x50(%rsp), %rax
leaq (%r15,%rax), %rcx
addq $0x8, %rcx
movq (%rcx), %rax
movq %rcx, 0x68(%rsp)
movq 0x8(%rcx), %rcx
movq %rcx, %rdx
xorl %r9d, %r9d
cmpq %rax, %rdx
je 0x1b919
movq %r9, 0x10(%rsp)
movslq (%rsi,%r9,4), %r12
xorl %ebx, %ebx
movslq (%rax,%rbx,4), %r15
movq (%r14), %rsi
leaq (%r12,%r12,2), %rdx
movq (%rsi,%rdx,8), %rsi
movsd (%rsi,%r15,8), %xmm0
movsd %xmm0, 0x28(%rsp)
ucomisd 0x24c7b(%rip), %xmm0    # 0x40360
jbe 0x1b8ec
cmpl $0x1, %ebp
je 0x1b768
testl %ebp, %ebp
jne 0x1b8ec
movq 0x20(%rsp), %rsi
movq 0xb8(%rsi), %rsi
movq 0x8(%rsp), %rdi
movq (%rsi,%rdi,8), %rdi
movsd (%rdi,%rdx,8), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
ja 0x1b8ec
movq 0x128(%rsp), %rsi
leaq (%r10,%r10,2), %r8
movq (%rsi,%r8,8), %rsi
leaq (%r15,%r15,2), %r8
leaq (%rsi,%r8,8), %rsi
movsd (%rsi), %xmm1
ucomisd %xmm1, %xmm2
jbe 0x1b755
leaq (%rdi,%rdx,8), %rdx
movq $0x0, (%rsi)
movsd (%rdx), %xmm0
xorpd %xmm1, %xmm1
mulsd 0x28(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rsi)
jmp 0x1b8ec
movq 0x20(%rsp), %rsi
movq 0xb8(%rsi), %rsi
leaq (%r10,%r10,2), %rdi
movq (%rsi,%rdi,8), %r8
leaq (%r15,%r15,2), %r9
movsd 0x8(%r8,%r9,8), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
ja 0x1b8ec
movq 0x128(%rsp), %rdi
movq 0x8(%rsp), %r11
movq (%rdi,%r11,8), %rdi
leaq (%rdi,%rdx,8), %rdi
addq $0x8, %rdi
movsd (%rdi), %xmm1
ucomisd %xmm1, %xmm2
jbe 0x1b7d0
leaq (%r8,%r9,8), %r8
addq $0x8, %r8
movq $0x0, (%rdi)
movsd (%r8), %xmm0
xorpd %xmm1, %xmm1
mulsd 0x28(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rdi)
movq 0x8(%rsp), %rdi
movq (%rsi,%rdi,8), %rsi
movsd 0x8(%rsi,%rdx,8), %xmm0
ucomisd 0x24993(%rip), %xmm0    # 0x40188
jbe 0x1b8ec
movl $0xb, %edx
movq 0x397e9(%rip), %rdi     # 0x54ff0
leaq 0x24b5a(%rip), %rsi     # 0x40368
callq 0x3350
movq 0x397d6(%rip), %rdi     # 0x54ff0
movq 0x18(%rsp), %rsi
callq 0x3500
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2483f(%rip), %rsi     # 0x40075
callq 0x3350
movq %r13, %rdi
movl %r15d, %esi
callq 0x3500
movq %rax, %r15
movl $0x4, %edx
movq %rax, %rdi
leaq 0x24b1c(%rip), %rsi     # 0x40374
callq 0x3350
movq %r15, %rdi
movq 0x40(%rsp), %rsi
callq 0x3500
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x247f9(%rip), %rsi     # 0x40075
callq 0x3350
movq %r15, %rdi
movl %r12d, %esi
callq 0x3500
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2547a(%rip), %rsi     # 0x40d18
callq 0x3350
movq %r15, %rdi
movsd 0x28(%rsp), %xmm0
callq 0x34a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31e0
movq 0x68(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movq 0x18(%rsp), %r10
incq %rbx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbx, %rdx
ja 0x1b6c2
movq 0x60(%rsp), %rdx
movq 0x8(%rdx), %rsi
movq 0x10(%rdx), %rdi
movq %rcx, %rdx
movq 0x10(%rsp), %r9
jmp 0x1b91c
movq %rax, %rdx
incq %r9
movq %rdi, %r8
subq %rsi, %r8
sarq $0x2, %r8
cmpq %r9, %r8
ja 0x1b6ae
movq 0x48(%rsp), %rax
movq (%rax), %r15
movq 0x8(%rax), %rdx
movq 0x30(%rsp), %rsi
movq 0x58(%rsp), %rax
jmp 0x1b94f
movq 0x30(%rsp), %rsi
incq %rax
movq %rdx, %rcx
subq %r15, %rcx
sarq $0x5, %rcx
cmpq %rax, %rcx
ja 0x1b634
jmp 0x1b96a
movq %r15, %rdx
movq 0x38(%rsp), %rdi
incq %rdi
movq %rdx, %rcx
subq %r15, %rcx
sarq $0x5, %rcx
movq %rdi, 0x38(%rsp)
cmpq %rdi, %rcx
ja 0x1b612
jmp 0x1bb6a
movq 0x390(%rdi), %rax
movq %rax, 0x10(%rsp)
testl %eax, %eax
jle 0x1bc52
leaq 0x368(%rdi), %rax
movq %rax, 0x40(%rsp)
movq 0x10(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
leaq (%rcx,%rcx,2), %rax
movq %rax, 0x28(%rsp)
xorl %edx, %edx
movq %rcx, 0x18(%rsp)
movq 0x1f0(%rdi), %rax
movq %rdx, 0x8(%rsp)
leaq (%rdx,%rdx,2), %r14
movq (%rax,%r14,8), %rax
movq (%rax,%rcx,8), %r15
testq %r15, %r15
je 0x1bb36
movq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x139b6
movl %eax, %r13d
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x139b6
xorpd %xmm3, %xmm3
testl %r13d, %r13d
jle 0x1bb36
movl %r13d, %ecx
movl %eax, %edx
movq 0x8(%rsp), %rsi
xorq 0x18(%rsp), %rsi
xorl %edi, %edi
testl %eax, %eax
jle 0x1bb2a
movq 0x20(%rsp), %r8
movq 0xb8(%r8), %r9
movq 0x28(%rsp), %r8
leaq (%r9,%r8,8), %r8
leaq (%r9,%r14,8), %r9
movl $0x1, %r10d
leaq (%rdi,%rdi,2), %r11
xorl %r13d, %r13d
movq %rdi, %rbx
xorq %r13, %rbx
orq %rsi, %rbx
je 0x1bb1a
movq (%r15), %rbx
movq (%rbx,%r11,8), %rbx
movsd (%rbx,%r13,8), %xmm0
ucomisd %xmm3, %xmm0
jbe 0x1bb1a
cmpl $0x1, %ebp
je 0x1bad9
testl %ebp, %ebp
jne 0x1bb1a
movq (%r9), %r12
movsd (%r12,%r11,8), %xmm1
ucomisd %xmm1, %xmm3
ja 0x1bb1a
movq (%r8), %rbx
movsd -0x8(%rbx,%r10,8), %xmm2
ucomisd %xmm2, %xmm3
jbe 0x1bac8
leaq (%r12,%r11,8), %r12
movq $0x0, -0x8(%rbx,%r10,8)
movsd (%r12), %xmm1
xorpd %xmm2, %xmm2
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, -0x8(%rbx,%r10,8)
jmp 0x1bb1a
movq (%r8), %r12
movsd (%r12,%r10,8), %xmm1
ucomisd %xmm1, %xmm3
ja 0x1bb1a
movq (%r9), %rbx
leaq (%rbx,%r11,8), %rbx
addq $0x8, %rbx
movsd (%rbx), %xmm2
ucomisd %xmm2, %xmm3
jbe 0x1bb0e
movq $0x0, (%rbx)
movsd (%r12,%r10,8), %xmm1
xorpd %xmm2, %xmm2
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, (%rbx)
incq %r13
addq $0x3, %r10
cmpq %r13, %rdx
jne 0x1ba5f
incq %rdi
cmpq %rcx, %rdi
jne 0x1ba31
movq 0x8(%rsp), %rdx
incq %rdx
cmpq 0x10(%rsp), %rdx
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rcx
jne 0x1b9d0
incq %rcx
cmpq 0x10(%rsp), %rcx
jne 0x1b9c0
jmp 0x1bc52
sarq $0x5, %rcx
testq %rcx, %rcx
je 0x1bc48
xorl %edx, %edx
xorpd %xmm0, %xmm0
movq %rdx, %r8
shlq $0x5, %r8
movq 0x8(%r15,%r8), %rsi
movq 0x10(%r15,%r8), %rdi
subq %rsi, %rdi
je 0x1bc3c
addq %r15, %r8
sarq $0x2, %rdi
movslq (%r8), %r8
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
movq 0x20(%rsp), %r9
movq 0xb8(%r9), %r9
addq %r8, %r9
addq 0x128(%rsp), %r8
cmpq $0x1, %rdi
adcq $0x0, %rdi
xorl %r10d, %r10d
movslq (%rsi,%r10,4), %rbx
cmpl $0x1, %ebp
je 0x1bbfe
testl %ebp, %ebp
jne 0x1bc34
movq (%r9), %r11
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
movsd (%r11,%rbx), %xmm1
addq %rbx, %r11
ucomisd %xmm1, %xmm0
movq (%r8), %r14
movsd (%r14,%rbx), %xmm2
jbe 0x1bc25
movsd %xmm2, (%r11)
jmp 0x1bc34
movq (%r9), %r11
shlq $0x3, %rbx
leaq (%rbx,%rbx,2), %rbx
addq %rbx, %r11
addq $0x8, %r11
movsd (%r11), %xmm1
ucomisd %xmm1, %xmm0
movq (%r8), %r14
movsd 0x8(%r14,%rbx), %xmm2
ja 0x1bbf7
ucomisd %xmm0, %xmm2
jbe 0x1bc34
addsd %xmm2, %xmm1
movsd %xmm1, (%r11)
incq %r10
cmpq %r10, %rdi
jne 0x1bbc7
incq %rdx
cmpq %rcx, %rdx
jne 0x1bb79
leaq 0x70(%rsp), %rdi
callq 0x1cc50
movsd 0x2452e(%rip), %xmm0    # 0x40188
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq 0x20(%rsp), %rdi
callq 0x36cb4
movb $0x1, %al
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1bc84
jmp 0x1bc84
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x1cc50
movq %rbx, %rdi
callq 0x3530