// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rdi, %r15
cmpb $0x1, 0x90(%rsi)
movl %edx, 0x1c(%rsp)
movq %rsi, 0x28(%rsp)
jne 0x1c02b
movq %rsi, %r12
movl 0xb0(%rsi), %ebx
movl 0xb4(%rsi), %ebp
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)
movq 0x38(%rax), %r14
testq %r14, %r14
je 0x1bc56
movq %r15, %r13
xorl %r15d, %r15d
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x1bc3e
movq 0x18(%r15), %rsi
subq %rdi, %rsi
callq 0x32e0
addq $0x20, %r15
cmpq %r14, %r15
jne 0x1bc29
movq $0x0, 0x110(%rsp)
movq %r13, %r15
leaq 0x70(%rsp), %rdi
xorpd %xmm0, %xmm0
movupd %xmm0, 0x108(%rdi)
movupd %xmm0, 0xf8(%rdi)
movupd %xmm0, 0xe8(%rdi)
movupd %xmm0, 0xd8(%rdi)
movupd %xmm0, 0xc8(%rdi)
movupd %xmm0, 0xb8(%rdi)
movl %ebx, 0xb0(%rdi)
movl %ebp, 0xb4(%rdi)
leaq 0x368(%r15), %rsi
callq 0x376e6
leaq 0x60(%r12), %rdi
callq 0x384f8
movq (%rax), %r12
movq 0x8(%rax), %rcx
subq %r12, %rcx
je 0x1c1c6
movq %r15, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq %rax, 0x58(%rsp)
movq (%rax), %rcx
cmpq %rcx, 0x8(%rax)
je 0x1c002
movq 0x38(%rsp), %rdx
shlq $0x5, %rdx
movq %rdx, 0x50(%rsp)
movslq (%r12,%rdx), %rdx
movq %rdx, 0x8(%rsp)
xorl %esi, %esi
movq %rsi, 0x60(%rsp)
shlq $0x5, %rsi
movslq (%rcx,%rsi), %rdx
movq %rdx, 0x48(%rsp)
cmpl 0x8(%rsp), %edx
je 0x1bfde
movq 0x40(%rsp), %rax
movq 0x1f0(%rax), %rax
movq 0x48(%rsp), %rdx
leaq (%rdx,%rdx,2), %rdx
movq %rdx, 0x10(%rsp)
movq (%rax,%rdx,8), %rax
movq 0x8(%rsp), %rdx
movq (%rax,%rdx,8), %r15
testq %r15, %r15
je 0x1bfde
movq %rsi, %rdi
addq %rcx, %rdi
movq 0x8(%rdi), %rax
movq %rdi, 0x68(%rsp)
cmpq %rax, 0x10(%rdi)
je 0x1bfde
movq 0x50(%rsp), %rdx
leaq (%rcx,%rdx), %rbx
addq $0x8, %rbx
movq $0x0, 0x20(%rsp)
movq (%rbx), %rcx
cmpq %rcx, 0x8(%rbx)
je 0x1bfb4
movq 0x20(%rsp), %rdx
movslq (%rax,%rdx,4), %r12
xorl %ebp, %ebp
movslq (%rcx,%rbp,4), %r14
movq (%r15), %rcx
leaq (%r12,%r12,2), %rax
movq (%rcx,%rax,8), %rcx
movsd (%rcx,%r14,8), %xmm0
movsd %xmm0, 0x30(%rsp)
ucomisd 0x255b0(%rip), %xmm0    # 0x41360
jbe 0x1bf9a
movl 0x1c(%rsp), %ecx
cmpl $0x1, %ecx
je 0x1be30
testl %ecx, %ecx
jne 0x1bf9a
movq 0x28(%rsp), %rcx
movq 0xb8(%rcx), %rcx
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
xorpd %xmm0, %xmm0
ucomisd (%rcx,%rax,8), %xmm0
ja 0x1bf9a
movq 0x128(%rsp), %rdx
movq 0x8(%rsp), %rsi
leaq (%rsi,%rsi,2), %rsi
movq (%rdx,%rsi,8), %rdx
leaq (%r14,%r14,2), %rsi
leaq (%rdx,%rsi,8), %rdx
ucomisd (%rdx), %xmm0
jbe 0x1be15
movq $0x0, (%rdx)
leaq (%rcx,%rax,8), %rax
movsd 0x30(%rsp), %xmm0
mulsd (%rax), %xmm0
addsd (%rdx), %xmm0
movsd %xmm0, (%rdx)
jmp 0x1bf9a
movq 0x28(%rsp), %rcx
movq 0xb8(%rcx), %rcx
movq 0x8(%rsp), %rdx
leaq (%rdx,%rdx,2), %rdx
movq (%rcx,%rdx,8), %rdx
leaq (%r14,%r14,2), %rsi
xorpd %xmm0, %xmm0
ucomisd 0x8(%rdx,%rsi,8), %xmm0
ja 0x1bf9a
movq 0x128(%rsp), %rdi
movq 0x10(%rsp), %r8
movq (%rdi,%r8,8), %rdi
leaq (%rdi,%rax,8), %rdi
addq $0x8, %rdi
ucomisd (%rdi), %xmm0
jbe 0x1be83
movq $0x0, (%rdi)
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movsd (%rdx), %xmm0
mulsd 0x30(%rsp), %xmm0
addsd (%rdi), %xmm0
movsd %xmm0, (%rdi)
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movsd 0x8(%rcx,%rax,8), %xmm0
ucomisd 0x252d4(%rip), %xmm0    # 0x41188
jbe 0x1bf9a
movl $0xb, %edx
movq 0x3a12a(%rip), %rdi     # 0x55ff0
leaq 0x2549b(%rip), %rsi     # 0x41368
callq 0x3350
movq 0x3a117(%rip), %rdi     # 0x55ff0
movq 0x8(%rsp), %rsi
callq 0x3500
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x25180(%rip), %rsi     # 0x41075
callq 0x3350
movq %r13, %rdi
movl %r14d, %esi
callq 0x3500
movq %rax, %r14
movl $0x4, %edx
movq %rax, %rdi
leaq 0x2545d(%rip), %rsi     # 0x41374
callq 0x3350
movq %r14, %rdi
movq 0x48(%rsp), %rsi
callq 0x3500
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2513a(%rip), %rsi     # 0x41075
callq 0x3350
movq %r14, %rdi
movl %r12d, %esi
callq 0x3500
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x25dab(%rip), %rsi     # 0x41d08
callq 0x3350
movq %r14, %rdi
movsd 0x30(%rsp), %xmm0
callq 0x34a0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31e0
incq %rbp
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
subq %rcx, %rax
sarq $0x2, %rax
cmpq %rbp, %rax
ja 0x1bd8d
movq 0x20(%rsp), %rsi
incq %rsi
movq 0x68(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movq %rsi, 0x20(%rsp)
cmpq %rsi, %rcx
ja 0x1bd75
movq 0x60(%rsp), %rsi
incq %rsi
movq 0x58(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdx
subq %rcx, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rdx
ja 0x1bcfa
movq 0x38(%rsp), %rsi
incq %rsi
movq (%rax), %r12
movq 0x8(%rax), %rcx
subq %r12, %rcx
sarq $0x5, %rcx
movq %rsi, 0x38(%rsp)
cmpq %rsi, %rcx
ja 0x1bcd4
jmp 0x1c1ca
movq 0x390(%r15), %rax
movq %rax, 0x8(%rsp)
testl %eax, %eax
jle 0x1c2c1
movl %edx, %ebp
leaq 0x368(%r15), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x8(%rsp)
xorl %ecx, %ecx
movq %r15, 0x40(%rsp)
leaq (%rcx,%rcx,2), %rax
movq %rax, 0x30(%rsp)
xorl %r12d, %r12d
movq %rcx, 0x10(%rsp)
movq 0x1f0(%r15), %rax
leaq (%r12,%r12,2), %rbx
movq (%rax,%rbx,8), %rax
movq (%rax,%rcx,8), %r14
testq %r14, %r14
je 0x1c19b
movq 0x20(%rsp), %r15
movq %r15, %rdi
movl %r12d, %esi
callq 0x13ba2
movl %eax, %r13d
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0x13ba2
xorpd %xmm1, %xmm1
testl %r13d, %r13d
jle 0x1c19b
movl %r13d, %ecx
movl %eax, %edx
movq %r12, %rsi
xorq 0x10(%rsp), %rsi
xorl %edi, %edi
testl %eax, %eax
jle 0x1c18f
movq 0x28(%rsp), %r8
movq 0xb8(%r8), %r9
movq 0x30(%rsp), %r8
leaq (%r9,%r8,8), %r8
leaq (%r9,%rbx,8), %r9
movl $0x8, %r10d
xorl %r11d, %r11d
movq %rdi, %r15
xorq %r11, %r15
orq %rsi, %r15
je 0x1c17f
movq (%r14), %r13
leaq (%rdi,%rdi,2), %r15
movq (%r13,%r15,8), %r13
movsd (%r13,%r11,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1c17f
cmpl $0x1, %ebp
je 0x1c140
testl %ebp, %ebp
jne 0x1c17f
movq (%r9), %r13
ucomisd (%r13,%r15,8), %xmm1
ja 0x1c17f
leaq (%r13,%r15,8), %r13
movq (%r8), %r15
addq %r10, %r15
addq $-0x8, %r15
jmp 0x1c161
movq (%r8), %r13
ucomisd (%r13,%r10), %xmm1
ja 0x1c17f
addq %r10, %r13
movq (%r9), %rbp
leaq 0x8(,%r15,8), %r15
addq %rbp, %r15
movl 0x1c(%rsp), %ebp
ucomisd (%r15), %xmm1
jbe 0x1c16f
movq $0x0, (%r15)
mulsd (%r13), %xmm0
addsd (%r15), %xmm0
movsd %xmm0, (%r15)
incq %r11
addq $0x18, %r10
cmpq %r11, %rdx
jne 0x1c0f6
incq %rdi
cmpq %rcx, %rdi
jne 0x1c0cc
incq %r12
cmpq 0x8(%rsp), %r12
movq 0x40(%rsp), %r15
movq 0x10(%rsp), %rcx
jne 0x1c074
incq %rcx
cmpq 0x8(%rsp), %rcx
jne 0x1c063
jmp 0x1c2c1
sarq $0x5, %rcx
testq %rcx, %rcx
movq 0x28(%rsp), %r15
movl 0x1c(%rsp), %ebp
je 0x1c2b7
xorl %edx, %edx
xorpd %xmm0, %xmm0
movq %rdx, %r8
shlq $0x5, %r8
movq 0x8(%r12,%r8), %rsi
movq 0x10(%r12,%r8), %rdi
subq %rsi, %rdi
je 0x1c2ab
addq %r12, %r8
sarq $0x2, %rdi
movslq (%r8), %r8
shlq $0x3, %r8
leaq (%r8,%r8,2), %r8
movq 0xb8(%r15), %r9
addq %r8, %r9
addq 0x128(%rsp), %r8
cmpq $0x1, %rdi
adcq $0x0, %rdi
xorl %r10d, %r10d
movslq (%rsi,%r10,4), %r11
cmpl $0x1, %ebp
je 0x1c259
testl %ebp, %ebp
jne 0x1c2a3
movq (%r9), %r14
leaq (%r11,%r11,2), %rbx
leaq (%r14,%rbx,8), %r11
movsd (%r11), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1c27f
movq (%r8), %r14
movsd (%r14,%rbx,8), %xmm1
jmp 0x1c29e
movq (%r9), %r14
leaq (%r11,%r11,2), %rbx
leaq (%r14,%rbx,8), %r11
addq $0x8, %r11
movsd (%r11), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1c28a
movq (%r8), %r14
movsd 0x8(%r14,%rbx,8), %xmm1
jmp 0x1c29e
movq (%r8), %r14
movsd (%r14,%rbx,8), %xmm2
jmp 0x1c294
movq (%r8), %r14
movsd 0x8(%r14,%rbx,8), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x1c2a3
addsd %xmm2, %xmm1
movsd %xmm1, (%r11)
incq %r10
cmpq %r10, %rdi
jne 0x1c22b
incq %rdx
cmpq %rcx, %rdx
jne 0x1c1e2
leaq 0x70(%rsp), %rdi
callq 0x1d256
movsd 0x24ebf(%rip), %xmm0    # 0x41188
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq 0x28(%rsp), %rdi
callq 0x3782c
movb $0x1, %al
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1c2f3
jmp 0x1c2f3
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x1d256
movq %rbx, %rdi
callq 0x3530