// File: /workspace/github_cpp_makefile_star2_O2/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 $0x178, %rsp            # imm = 0x178
movl %edx, %ebp
movq %rdi, %r15
cmpb $0x1, 0x90(%rsi)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x38(%rsp)
jne 0x16806
movq %rsi, %rbx
movl 0xb0(%rsi), %esi
movl 0xb4(%rbx), %edx
leaq 0x60(%rsp), %r14
movq %r14, %rdi
callq 0x17826
leaq 0x368(%r15), %rsi
movq %r14, %rdi
callq 0x2abb4
leaq 0x60(%rbx), %rdi
callq 0x2b5fa
movq (%rax), %r12
movq 0x8(%rax), %rdx
xorl %esi, %esi
movq %rax, 0x40(%rsp)
movq %rdx, %rcx
subq %r12, %rcx
sarq $0x5, %rcx
cmpq %rsi, %rcx
jbe 0x169bd
movq %rsi, %rcx
shlq $0x5, %rcx
movq %rcx, 0x50(%rsp)
movslq (%r12,%rcx), %rdi
xorl %r8d, %r8d
movq %rsi, 0x48(%rsp)
movq %rdi, (%rsp)
movq %rdx, %rcx
subq %r12, %rcx
sarq $0x5, %rcx
cmpq %r8, %rcx
jbe 0x167fe
movq %r8, %rcx
shlq $0x5, %rcx
movq %rcx, 0x20(%rsp)
movslq (%r12,%rcx), %r9
cmpl %edi, %r9d
je 0x167f6
movq 0x1f0(%r15), %rcx
imulq $0x18, %r9, %r10
movq %r10, 0x8(%rsp)
movq (%rcx,%r10), %rcx
movq (%rcx,%rdi,8), %rbx
testq %rbx, %rbx
je 0x167f6
movq %r9, 0x28(%rsp)
movq %r8, 0x58(%rsp)
addq %r12, 0x20(%rsp)
movq 0x50(%rsp), %rax
leaq (%r12,%rax), %r13
addq $0x8, %r13
xorl %edx, %edx
movq 0x20(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rdx, %rcx
jbe 0x167d7
movq %rdx, 0x30(%rsp)
movslq (%rax,%rdx,4), %r12
xorl %r14d, %r14d
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r14, %rcx
jbe 0x167ca
movslq (%rax,%r14,4), %r15
movq (%rbx), %rcx
imulq $0x18, %r12, %rax
movq (%rcx,%rax), %rcx
movsd (%rcx,%r15,8), %xmm0
movsd %xmm0, 0x18(%rsp)
ucomisd 0x1bd48(%rip), %xmm0    # 0x32360
jbe 0x167c2
cmpl $0x1, %ebp
je 0x1669d
testl %ebp, %ebp
jne 0x167c2
movq 0x10(%rsp), %rcx
movq 0xb8(%rcx), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx), %rdx
movsd (%rdx,%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x167c2
movq 0x118(%rsp), %rcx
imulq $0x18, (%rsp), %rsi
movq (%rcx,%rsi), %rsi
imulq $0x18, %r15, %rdi
leaq (%rsi,%rdi), %rcx
movsd (%rsi,%rdi), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x1668a
andq $0x0, (%rcx)
addq %rax, %rdx
movsd (%rdx), %xmm0
xorpd %xmm1, %xmm1
mulsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rcx)
jmp 0x167c2
movq 0x10(%rsp), %rcx
movq 0xb8(%rcx), %rcx
imulq $0x18, (%rsp), %rdx
movq (%rcx,%rdx), %rsi
imulq $0x18, %r15, %rdi
movsd 0x8(%rsi,%rdi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x167c2
movq 0x118(%rsp), %rdx
movq 0x8(%rsp), %r8
movq (%rdx,%r8), %rdx
addq %rax, %rdx
addq $0x8, %rdx
movsd (%rdx), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
jbe 0x16703
andq $0x0, (%rdx)
addq %rdi, %rsi
addq $0x8, %rsi
movsd (%rsi), %xmm0
xorpd %xmm1, %xmm1
mulsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rdx)
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx), %rcx
movsd 0x8(%rcx,%rax), %xmm0
ucomisd 0x1ba60(%rip), %xmm0    # 0x32188
jbe 0x167c2
movq 0x358bb(%rip), %rdi     # 0x4bff0
leaq 0x1bc2c(%rip), %rsi     # 0x32368
callq 0x32d0
movq %rax, %rdi
movq (%rsp), %rsi
callq 0x34d0
movq %rax, %rdi
leaq 0x1b8f4(%rip), %rsi     # 0x3204b
callq 0x32d0
movq %rax, %rdi
movl %r15d, %esi
callq 0x34d0
movq %rax, %rdi
leaq 0x1bc03(%rip), %rsi     # 0x32374
callq 0x32d0
movq %rax, %rdi
movq 0x28(%rsp), %rsi
callq 0x34d0
movq %rax, %rdi
leaq 0x1b8be(%rip), %rsi     # 0x3204b
callq 0x32d0
movq %rax, %rdi
movl %r12d, %esi
callq 0x34d0
movq %rax, %rdi
leaq 0x1c569(%rip), %rsi     # 0x32d10
callq 0x32d0
movq %rax, %rdi
movsd 0x18(%rsp), %xmm0
callq 0x3490
movq %rax, %rdi
callq 0x3130
incq %r14
jmp 0x165dd
movq 0x30(%rsp), %rdx
incq %rdx
jmp 0x165b4
movq 0x40(%rsp), %rax
movq (%rax), %r12
movq 0x8(%rax), %rdx
movq 0x38(%rsp), %r15
movq 0x48(%rsp), %rsi
movq (%rsp), %rdi
movq 0x58(%rsp), %r8
incq %r8
jmp 0x16549
incq %rsi
jmp 0x1651a
leaq 0x368(%r15), %rax
movq %rax, 0x28(%rsp)
movq 0x390(%r15), %rax
movl %eax, %ecx
movq %rcx, 0x30(%rsp)
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movq %rax, 0x20(%rsp)
xorl %ecx, %ecx
cmpq 0x20(%rsp), %rcx
je 0x16a8c
imulq $0x18, %rcx, %rax
movq %rax, 0x18(%rsp)
xorl %edx, %edx
movq %rcx, (%rsp)
cmpq 0x30(%rsp), %rdx
je 0x169b5
movq 0x1f0(%r15), %rax
movq %rdx, 0x8(%rsp)
imulq $0x18, %rdx, %r14
movq (%rax,%r14), %rax
movq (%rax,%rcx,8), %r15
testq %r15, %r15
je 0x1699f
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %r12
movl %r12d, %esi
callq 0xf990
movl %eax, %r13d
movq %rbx, %rdi
movq (%rsp), %rbx
movl %ebx, %esi
callq 0xf990
xorpd %xmm3, %xmm3
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
testl %r13d, %r13d
cmovlel %ecx, %r13d
movq %r12, %rcx
xorq %rbx, %rcx
xorl %edx, %edx
cmpq %r13, %rdx
movq 0x10(%rsp), %rsi
je 0x1699f
movq 0xb8(%rsi), %rsi
movq 0x18(%rsp), %rdi
addq %rsi, %rdi
addq %r14, %rsi
imulq $0x18, %rdx, %r8
xorl %r9d, %r9d
cmpq %rax, %r9
je 0x16997
movq %r9, %r10
xorq %rdx, %r10
orq %rcx, %r10
je 0x1698f
movq (%r15), %r10
movq (%r10,%r8), %r10
movsd (%r10,%r9,8), %xmm0
ucomisd %xmm3, %xmm0
jbe 0x1698f
cmpl $0x1, %ebp
je 0x16945
testl %ebp, %ebp
jne 0x1698f
movq (%rsi), %r11
movsd (%r11,%r8), %xmm1
ucomisd %xmm1, %xmm3
ja 0x1698f
movq (%rdi), %r12
imulq $0x18, %r9, %rbx
leaq (%r12,%rbx), %r10
movsd (%r12,%rbx), %xmm2
ucomisd %xmm2, %xmm3
jbe 0x16982
andq $0x0, (%r10)
addq %r8, %r11
jmp 0x16979
movq (%rdi), %r11
imulq $0x18, %r9, %r12
movsd 0x8(%r11,%r12), %xmm1
ucomisd %xmm1, %xmm3
ja 0x1698f
movq (%rsi), %r10
addq %r8, %r10
addq $0x8, %r10
movsd (%r10), %xmm2
ucomisd %xmm2, %xmm3
jbe 0x16982
andq $0x0, (%r10)
addq %r12, %r11
addq $0x8, %r11
movsd (%r11), %xmm1
xorpd %xmm2, %xmm2
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, (%r10)
incq %r9
jmp 0x168de
incq %rdx
jmp 0x168b7
movq 0x8(%rsp), %rdx
incq %rdx
movq 0x38(%rsp), %r15
movq (%rsp), %rcx
jmp 0x16848
incq %rcx
jmp 0x1682e
xorl %edx, %edx
xorpd %xmm0, %xmm0
cmpq %rcx, %rdx
je 0x16a7d
movq %rdx, %rdi
shlq $0x5, %rdi
movslq (%r12,%rdi), %r8
movq 0x8(%r12,%rdi), %rsi
movq 0x10(%r12,%rdi), %rdi
subq %rsi, %rdi
sarq $0x2, %rdi
imulq $0x18, %r8, %r8
movq 0x10(%rsp), %r9
movq 0xb8(%r9), %r9
addq %r8, %r9
addq 0x118(%rsp), %r8
xorl %r10d, %r10d
cmpq %r10, %rdi
je 0x16a75
movslq (%rsi,%r10,4), %rbx
cmpl $0x1, %ebp
je 0x16a3e
testl %ebp, %ebp
jne 0x16a70
movq (%r9), %r11
imulq $0x18, %rbx, %rbx
movsd (%r11,%rbx), %xmm1
addq %rbx, %r11
ucomisd %xmm1, %xmm0
movq (%r8), %r14
movsd (%r14,%rbx), %xmm2
jbe 0x16a61
movsd %xmm2, (%r11)
jmp 0x16a70
movq (%r9), %r11
imulq $0x18, %rbx, %rbx
addq %rbx, %r11
addq $0x8, %r11
movsd (%r11), %xmm1
ucomisd %xmm1, %xmm0
movq (%r8), %r14
movsd 0x8(%r14,%rbx), %xmm2
ja 0x16a37
ucomisd %xmm0, %xmm2
jbe 0x16a70
addsd %xmm2, %xmm1
movsd %xmm1, (%r11)
incq %r10
jmp 0x16a06
incq %rdx
jmp 0x169c3
leaq 0x60(%rsp), %rdi
callq 0x178a4
movq 0x10(%rsp), %rsi
movsd 0x1b6f4(%rip), %xmm0    # 0x32188
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rsi, %rdi
callq 0x2accc
movb $0x1, %al
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x16aba
jmp 0x16aba
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x178a4
movq %rbx, %rdi
callq 0x34f0