// File: /workspace/github_cpp_makefile_star2_O2/neubig[P]egret/Egret/src/Forest-Berkeley-2.cpp
// Function: genUnaryNode_withoutLabel_initLevel_berkeley(BerkeleyRuleSet const&, Node&, IorO)
bool genUnaryNode_withoutLabel_initLevel_berkeley(const BerkeleyRuleSet& ruleSet, Node& node, IorO iot)
{
/*
	const vector<int>& asi=node.set_allowState_withoutLabel_for_initialLevel(1,0,0);
	
	for(int chIter=0;chIter<asi.size();chIter++)
	{
		int ch=asi[chIter];
		//cerr<<"ch:"<<ch<<endl;
		const vector<BerkeleyUnaryRule*> rules=ruleSet.getUnaryRulesByChild(ch);
		for(int ruleIter=0;ruleIter<rules.size();ruleIter++)
		{
			BerkeleyUnaryRule* rule=rules[ruleIter];
			if(rule==NULL)continue;
			int pr=rule->parentState();
			if(ch==pr)continue;
			double ruleScore=rule->getScore(0,0);
			if(ruleScore>0)
			{
				if(iot==inside)
				{
					if(node.iScore(ch)<0)cerr<<"bug"<<endl;
					if(node.iScore(pr)<0)node.iScore(pr)=0;
					node.iScore(pr)+=node.iScore(ch)*ruleScore;
				}
				else if(iot==outside)
				{
					if(node.oScore(pr)<0)continue;
					if(node.oScore(ch)<0)node.oScore(ch)=0;
					node.oScore(ch)+=node.oScore(pr)*ruleScore;
				}
			}
		}
	}
*/

		const BerkeleyStateInfoOfOneLevel& bsio=ruleSet.bsio();
		int numOfState=(int)bsio.numOfState();

vector<double> temp_iScore,temp_oScore;
temp_iScore.clear();
temp_oScore.clear();
temp_iScore.reserve(numOfState);
temp_oScore.reserve(numOfState);
for(int i=0;i<numOfState;i++)
{
	if(iot==inside)
		temp_iScore.push_back(-1E10);
	else
		temp_oScore.push_back(-1E10);
}

		for(int pr=0;pr<numOfState;pr++)
		{
			if(iot==outside)
			{
				if(node.oScore(pr)<0)continue;
			}
			for(int ch=0;ch<numOfState;ch++)	
			{
				const BerkeleyUnaryRule* rule=ruleSet.getUnaryRuleByRule(ch,pr);
				if(rule==NULL)continue;
				if(ch==pr)continue;
				double ruleScore=rule->getScore(0,0);
				if(ruleScore>0)
				{
					if(iot==inside)
					{
						if(node.iScore(ch)<0)continue;
						//if(node.iScore(pr)<0)node.iScore(pr)=0;
						//node.iScore(pr)=max(node.iScore(ch)*ruleScore,node.iScore(pr));
						if(temp_iScore[pr]<0)temp_iScore[pr]=0;
						temp_iScore[pr]=max(node.iScore(ch)*ruleScore,temp_iScore[pr]);
					
					}
					else if(iot==outside)
					{
						if(node.oScore(pr)<0)continue;
						//if(node.oScore(ch)<0)node.oScore(ch)=0;
						//node.oScore(ch)=max(node.oScore(pr)*ruleScore,node.oScore(ch));
						if(temp_oScore[ch]<0)temp_oScore[ch]=0;
						temp_oScore[ch]=max(node.oScore(pr)*ruleScore,temp_oScore[ch]);
					}
				}
			}
		}
		for(int i=0;i<numOfState;i++)
		{
			if(iot==inside)
				node.iScore(i)=max(node.iScore(i),temp_iScore[i]);
			else if(iot==outside)
				node.oScore(i)=max(node.oScore(i),temp_oScore[i]);
		}

	node.set_allowState_withoutLabel_for_initialLevel(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 $0x58, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, 0x50(%rsp)
movq 0x390(%rdi), %r14
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movapd %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movslq %r14d, %r15
movq %r15, %rsi
callq 0xc0e8
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0xc0e8
xorl %eax, %eax
testl %r14d, %r14d
cmovgl %r14d, %eax
movabsq $-0x3dfd5fa0e0000000, %r15 # imm = 0xC202A05F20000000
leaq 0x8(%rsp), %r12
leaq 0x10(%rsp), %r13
movl %eax, 0x4(%rsp)
movl %eax, %r14d
subl $0x1, %r14d
jb 0x15aed
testl %ebp, %ebp
je 0x15ad9
movq %r15, 0x8(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0xc764
jmp 0x15abd
movq %r15, 0x8(%rsp)
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0xc764
jmp 0x15abd
movq 0xe8(%rbx), %rcx
movl 0x4(%rsp), %eax
leaq (%rax,%rax,2), %rdx
xorl %esi, %esi
xorpd %xmm0, %xmm0
xorl %edi, %edi
cmpq %rax, %rdi
je 0x15beb
cmpl $0x1, %ebp
jne 0x15b22
ucomisd (%rcx,%rdi,8), %xmm0
jbe 0x15b22
incq %rdi
addq $0x3, %rsi
jmp 0x15b04
movq 0x50(%rsp), %r8
movq 0x1f0(%r8), %r8
leaq (,%rdi,8), %r9
movq 0xe8(%rbx), %r10
addq %r9, %r10
movq 0x10(%rsp), %r11
movq 0xd0(%rbx), %r15
addq 0x30(%rsp), %r9
xorl %r12d, %r12d
cmpq %r12, %rdx
je 0x15b19
cmpq %r12, %rsi
je 0x15bda
movq (%r8,%r12,8), %r14
movq (%r14,%rdi,8), %r14
testq %r14, %r14
je 0x15bda
movq (%r14), %r14
movq (%r14), %r14
movsd (%r14), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x15bda
testl %ebp, %ebp
je 0x15ba3
cmpl $0x1, %ebp
jne 0x15bda
movsd (%r10), %xmm2
ucomisd %xmm2, %xmm0
ja 0x15bda
movsd (%r11), %xmm3
ucomisd %xmm3, %xmm0
movq %r11, %r14
movq %r10, %r13
ja 0x15bbf
jmp 0x15bcd
movsd (%r15), %xmm2
ucomisd %xmm2, %xmm0
ja 0x15bda
movsd (%r9), %xmm3
ucomisd %xmm3, %xmm0
movq %r9, %r14
movq %r15, %r13
jbe 0x15bcd
andq $0x0, (%r14)
movsd (%r13), %xmm2
xorpd %xmm3, %xmm3
mulsd %xmm2, %xmm1
maxsd %xmm1, %xmm3
movsd %xmm3, (%r14)
addq $0x3, %r12
addq $0x8, %r15
addq $0x8, %r11
jmp 0x15b54
movq 0xd0(%rbx), %rcx
movq 0xe8(%rbx), %rdx
movq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x15c37
movq %rcx, %r9
movq %rdi, %r10
testl %ebp, %ebp
je 0x15c20
cmpl $0x1, %ebp
jne 0x15c32
movq %rdx, %r9
movq %rsi, %r10
movsd (%r10,%r8,8), %xmm0
maxsd (%r9,%r8,8), %xmm0
movsd %xmm0, (%r9,%r8,8)
incq %r8
jmp 0x15c06
movsd 0x1c549(%rip), %xmm0    # 0x32188
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %rbx, %rdi
callq 0x2afc6
leaq 0x10(%rsp), %rdi
callq 0x6122
leaq 0x30(%rsp), %rdi
callq 0x6122
movb $0x1, %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x15c76
jmp 0x15c76
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x6122
leaq 0x30(%rsp), %rdi
callq 0x6122
movq %rbx, %rdi
callq 0x34f0