// File: /workspace/github_cpp_makefile_star2_O1/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, 0x40(%rsp)
movq 0x390(%rdi), %r14
xorl %eax, %eax
movq %rax, 0x30(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq %rax, 0x10(%rsp)
movapd %xmm0, (%rsp)
cmpq %rax, 0x28(%rsp)
je 0x1afa6
movq $0x0, 0x28(%rsp)
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x1afb6
movq %rax, 0x8(%rsp)
movslq %r14d, %r15
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0xf41a
movq %rsp, %rdi
movq %r15, %rsi
callq 0xf41a
testl %r14d, %r14d
jle 0x1b049
movabsq $-0x3dfd5fa0e0000000, %r15 # imm = 0xC202A05F20000000
leaq 0x38(%rsp), %r12
movl %r14d, %r13d
testl %ebp, %ebp
je 0x1b00b
movq %r15, 0x38(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x1b02a
movq %r15, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x1b044
movq %r15, 0x38(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x1b037
movq %r15, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x1b044
movq %rsp, %rdi
movq %r12, %rdx
callq 0xfaa4
jmp 0x1b044
leaq 0x20(%rsp), %rdi
movq %r12, %rdx
callq 0xfaa4
decl %r13d
jne 0x1afe8
testl %r14d, %r14d
jle 0x1b145
movq 0xe8(%rbx), %rax
movq 0x40(%rsp), %rcx
movq 0x1f0(%rcx), %rcx
movl %r14d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorpd %xmm0, %xmm0
cmpl $0x1, %ebp
jne 0x1b084
ucomisd (%rax,%rsi,8), %xmm0
ja 0x1b139
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 0x1b121
movq (%r11), %r12
movq (%r12,%rsi,8), %r12
testq %r12, %r12
je 0x1b121
movq (%r12), %r12
movq (%r12), %r12
movsd (%r12), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x1b121
testl %ebp, %ebp
je 0x1b0f0
cmpl $0x1, %ebp
jne 0x1b121
ucomisd (%r8), %xmm0
ja 0x1b121
ucomisd (%r9), %xmm0
movq %r9, %r12
movq %r8, %r13
ja 0x1b103
jmp 0x1b10b
ucomisd (%r10), %xmm0
ja 0x1b121
ucomisd (%rdi), %xmm0
movq %rdi, %r12
movq %r10, %r13
jbe 0x1b10b
movq $0x0, (%r12)
mulsd (%r13), %xmm1
movsd (%r12), %xmm2
maxsd %xmm1, %xmm2
movsd %xmm2, (%r12)
incq %r15
addq $0x8, %r9
addq $0x8, %r10
addq $0x18, %r11
cmpq %r15, %rdx
jne 0x1b0ac
incq %rsi
cmpq %rdx, %rsi
jne 0x1b074
testl %r14d, %r14d
jle 0x1b199
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 0x1b17f
cmpl $0x1, %ebp
jne 0x1b191
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 0x1b16a
movsd 0x25fe7(%rip), %xmm0    # 0x41188
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %rbx, %rdi
callq 0x37c60
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1b1c7
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1b1de
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 0x1b1f3
jmp 0x1b1f3
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1b20c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1b223
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32e0
movq %rbx, %rdi
callq 0x3530