// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r12
movq 0x390(%rdi), %r14
xorl %eax, %eax
leaq 0x20(%rsp), %rdi
movq %rax, 0x10(%rdi)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdi)
movq %rax, 0x10(%rsp)
movapd %xmm0, (%rsp)
movslq %r14d, %r15
movq %r15, %rsi
callq 0xf2d4
movq %rsp, %rdi
movq %r15, %rsi
callq 0xf2d4
testl %r14d, %r14d
jle 0x1aae3
movq %r12, 0x40(%rsp)
movabsq $-0x3dfd5fa0e0000000, %r15 # imm = 0xC202A05F20000000
leaq 0x38(%rsp), %r12
movl %r14d, %r13d
testl %ebp, %ebp
je 0x1a93f
movq %r15, 0x38(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x1a95e
movq %r15, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x1a978
movq %r15, 0x38(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x1a96b
movq %r15, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x1a978
movq %rsp, %rdi
movq %r12, %rdx
callq 0xf936
jmp 0x1a978
leaq 0x20(%rsp), %rdi
movq %r12, %rdx
callq 0xf936
decl %r13d
jne 0x1a91c
testl %r14d, %r14d
movq 0x40(%rsp), %rcx
jle 0x1aae3
movq 0xe8(%rbx), %rax
movq 0x1f0(%rcx), %rcx
movl %r14d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorpd %xmm0, %xmm0
cmpl $0x1, %ebp
jne 0x1a9b8
ucomisd (%rax,%rsi,8), %xmm0
ja 0x1aa83
leaq (,%rsi,8), %rdi
movq 0xe8(%rbx), %r8
addq %rdi, %r8
movq (%rsp), %r9
movq 0xd0(%rbx), %r10
addq 0x20(%rsp), %rdi
movq %rcx, %r11
xorl %r15d, %r15d
cmpq %r15, %rsi
je 0x1aa6b
movq (%r11), %r12
movq (%r12,%rsi,8), %r12
testq %r12, %r12
je 0x1aa6b
movq (%r12), %r12
movq (%r12), %r12
movsd (%r12), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1aa6b
testl %ebp, %ebp
je 0x1aa30
cmpl $0x1, %ebp
jne 0x1aa6b
movsd (%r8), %xmm2
ucomisd %xmm2, %xmm0
ja 0x1aa6b
movsd (%r9), %xmm3
ucomisd %xmm3, %xmm0
movq %r9, %r12
movq %r8, %r13
ja 0x1aa4b
jmp 0x1aa5d
movsd (%r10), %xmm2
ucomisd %xmm2, %xmm0
ja 0x1aa6b
movsd (%rdi), %xmm3
ucomisd %xmm3, %xmm0
movq %rdi, %r12
movq %r10, %r13
jbe 0x1aa5d
movq $0x0, (%r12)
movsd (%r13), %xmm2
xorpd %xmm3, %xmm3
mulsd %xmm2, %xmm1
maxsd %xmm1, %xmm3
movsd %xmm3, (%r12)
incq %r15
addq $0x8, %r9
addq $0x8, %r10
addq $0x18, %r11
cmpq %r15, %rdx
jne 0x1a9e0
incq %rsi
cmpq %rdx, %rsi
jne 0x1a9a8
testl %r14d, %r14d
jle 0x1aae3
movq 0xd0(%rbx), %rax
movq 0xe8(%rbx), %rcx
movq (%rsp), %rdx
movq 0x20(%rsp), %rsi
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorl %edi, %edi
movq %rax, %r8
movq %rsi, %r9
testl %ebp, %ebp
je 0x1aac9
cmpl $0x1, %ebp
jne 0x1aadb
movq %rcx, %r8
movq %rdx, %r9
movsd (%r9,%rdi,8), %xmm0
maxsd (%r8,%rdi,8), %xmm0
movsd %xmm0, (%r8,%rdi,8)
incq %rdi
cmpq %rdi, %r14
jne 0x1aab4
movsd 0x2569d(%rip), %xmm0    # 0x40188
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %rbx, %rdi
callq 0x370ce
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1ab11
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1ab28
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
movb $0x1, %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1ab3d
jmp 0x1ab3d
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1ab56
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1ab6d
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
movq %rbx, %rdi
callq 0x3530