// File: /workspace/github_cpp_makefile_star2_O2/Caproner[P]Naive_Compiler/Grammar/Grammar.cpp
// Function: Grammar::Handle_Analysis(int)
bool Grammar::Handle_Analysis(int pos)
{
	while(!(this->Status_Stack.empty()))
		this->Status_Stack.pop();
	while(!(this->Symbol_Stack.empty()))
	{
		TreeNode *p=this->Symbol_Stack.top();
		this->Symbol_Stack.pop();
		this->Delete(p);
	}
	
	Word_List &WL=this->Handle_List[pos];
	WL.List.push_back(Word(14,0));
	this->Status_Stack.push(0);
	
	int cur=0;
	
	bool ret=true;
	
	#ifdef TEST
	int Count=1;
	#endif
	
	while(true)
	{
		#ifdef TEST
		printf("%d: ",Count++);
		#endif
		if(cur==WL.List.size())
		{
			ret=false;
			break;
		}
		char &C=this->Number_to_Symbol[WL.List[cur].Number];
		int &S=this->Status_Stack.top();
		if(this->ACTION.find(std::make_pair(C,S))==this->ACTION.end())
		{
			ret=false;
			break;
		}
		int Status_Code=this->ACTION[std::make_pair(C,S)];
		#ifdef TEST
		printf("Find ACTION[%c,%d] = %d, ",C,S,Status_Code);
		#endif
		if(Status_Code==0)
		{
			#ifdef TEST
			printf("Accept!\n");
			#endif
			break;
		}
		else if(Status_Code>0)
		{
			#ifdef TEST
			printf("Push_Back %d\n",Status_Code);
			#endif
			this->Status_Stack.push(Status_Code);
			TreeNode *p=new TreeNode;
			p->Next.clear();
			p->Parent=NULL;
			p->Node_Word=WL.List[cur];
			this->Symbol_Stack.push(p);
			cur++;
		}
		else
		{
			Status_Code=-Status_Code;
			char U_Symbol=this->Grammars[Status_Code][0];
			#ifdef TEST
			printf("Reduce: %s, ",this->Grammars[Status_Code].c_str());
			#endif
			int len=this->Grammars[Status_Code].length();
			TreeNode *p=new TreeNode;
			p->Next.clear();
			p->Parent=NULL;
			p->Node_Word=Word(13,0);
			for(int i=0;i<len-2;i++)
			{
				if(this->Symbol_Stack.empty())
				{
					ret=false;
					break;
				}
				TreeNode *q=this->Symbol_Stack.top();
				this->Symbol_Stack.pop();
				p->Next.push_back(q);
				q->Parent=p;
				this->Status_Stack.pop();
			}
			if(!ret)break;
			std::reverse(p->Next.begin(),p->Next.end());
			if(this->GOTO.find(std::make_pair(U_Symbol,this->Status_Stack.top()))==this->GOTO.end())
			{
				ret=false;
				break;
			}
			#ifdef TEST
			printf("Push_Back GOTO[%c,%d]=%d\n",U_Symbol,this->Status_Stack.top(),this->GOTO[std::make_pair(U_Symbol,this->Status_Stack.top())]);
			#endif
			this->Status_Stack.push(this->GOTO[std::make_pair(U_Symbol,this->Status_Stack.top())]);
			this->Symbol_Stack.push(p);
		}
	}
	if(ret)
	{
		this->Grammar_Forest.forest.push_back(this->Symbol_Stack.top());
		this->Symbol_Stack.pop();
	}
	else
	{
		while(!(this->Symbol_Stack.empty()))
		{
			TreeNode *p=this->Symbol_Stack.top();
			this->Symbol_Stack.pop();
			this->Delete(p);
		}
	}
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %esi, %ebp
movq %rdi, %r14
leaq 0xa8(%rdi), %r15
movq 0xd8(%r14), %rax
cmpq 0xb8(%r14), %rax
je 0x3d7c
movq %r15, %rdi
callq 0x477c
jmp 0x3d62
leaq 0xf8(%r14), %rbx
movl $0x200, %r13d           # imm = 0x200
movq 0x128(%r14), %rax
cmpq 0x108(%r14), %rax
je 0x3dc9
cmpq 0x130(%r14), %rax
jne 0x3db0
movq 0x140(%r14), %rax
movq -0x8(%rax), %rax
addq %r13, %rax
movq -0x8(%rax), %r12
movq %rbx, %rdi
callq 0x47d2
movq %r14, %rdi
movq %r12, %rsi
callq 0x3cf0
jmp 0x3d89
movslq %ebp, %rax
imulq $0x18, %rax, %r12
addq (%r14), %r12
leaq 0x8(%rsp), %r13
movl $0xe, (%r13)
andq $0x0, 0x8(%r13)
movq %r12, %rdi
movq %r13, %rsi
callq 0x4828
andl $0x0, (%r13)
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x4928
leaq 0x148(%r14), %rax
movq %rax, 0x50(%rsp)
leaq 0x48(%r14), %rax
movq %rax, 0x38(%rsp)
leaq 0x50(%r14), %rax
movq %rax, 0x48(%rsp)
leaq 0x78(%r14), %rax
movq %rax, 0x20(%rsp)
leaq 0x80(%r14), %rax
movq %rax, 0x40(%rsp)
xorl %eax, %eax
movq %r12, 0x30(%rsp)
movl %eax, 0x18(%rsp)
movslq %eax, %r13
movq (%r12), %rsi
movq 0x8(%r12), %rax
subq %rsi, %rax
sarq $0x4, %rax
cmpq %r13, %rax
je 0x4136
shlq $0x4, %r13
addq %r13, %rsi
movq 0x50(%rsp), %rdi
callq 0x4538
movq %rax, %rbp
movq 0xd8(%r14), %r12
cmpq 0xe0(%r14), %r12
jne 0x3e93
movq 0xf0(%r14), %rax
movq -0x8(%rax), %r12
movl $0x200, %eax            # imm = 0x200
addq %rax, %r12
movzbl (%rbp), %eax
movl -0x4(%r12), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4df0
cmpq 0x48(%rsp), %rax
je 0x4136
movzbl (%rbp), %eax
movl -0x4(%r12), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4586
movl (%rax), %ebp
movl %ebp, 0x1c(%rsp)
testl %ebp, %ebp
je 0x40cd
jle 0x3f4c
movq %r15, %rdi
leaq 0x1c(%rsp), %rsi
callq 0x5156
pushq $0x30
popq %rdi
callq 0x21a0
andl $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movups %xmm0, 0x18(%rax)
andq $0x0, 0x28(%rax)
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %r12
movq (%r12), %rcx
movups (%rcx,%r13), %xmm0
movups %xmm0, (%rax)
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0x51f2
movl 0x18(%rsp), %eax
incl %eax
jmp 0x3e3c
movl %ebp, %eax
negl %eax
movl %eax, 0x1c(%rsp)
movq 0x30(%r14), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rdx
movzbl (%rdx), %edx
movq %rdx, 0x28(%rsp)
movl 0x8(%rcx,%rax), %r13d
pushq $0x30
popq %rdi
callq 0x21a0
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
andq $0x0, 0x20(%rax)
movq %rax, 0x8(%rsp)
andq $0x0, 0x28(%rax)
movl $0xd, (%rax)
andq $0x0, 0x8(%rax)
cmpl $0x3, %r13d
pushq $0x2
popq %rax
cmovll %eax, %r13d
addl $-0x2, %r13d
movl $0x200, %r12d           # imm = 0x200
subl $0x1, %r13d
jb 0x4014
movq 0x128(%r14), %rax
cmpq 0x108(%r14), %rax
je 0x40c9
cmpq 0x130(%r14), %rax
jne 0x3fdc
movq 0x140(%r14), %rax
movq -0x8(%rax), %rax
addq %r12, %rax
movq -0x8(%rax), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
callq 0x47d2
movq 0x8(%rsp), %rdi
addq $0x10, %rdi
movq %rsp, %rsi
callq 0x45ec
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
movq %rax, 0x28(%rcx)
movq %r15, %rdi
callq 0x477c
jmp 0x3fab
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
callq 0x552d
movq 0xd8(%r14), %rax
cmpq 0xe0(%r14), %rax
jne 0x4044
movq 0xf0(%r14), %rax
movq -0x8(%rax), %rax
addq %r12, %rax
movl -0x4(%rax), %eax
shlq $0x20, %rax
addq 0x28(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x4df0
cmpq 0x40(%rsp), %rax
je 0x40c9
movq 0xd8(%r14), %rax
cmpq 0xe0(%r14), %rax
jne 0x4086
movq 0xf0(%r14), %rax
movq -0x8(%rax), %rax
addq %r12, %rax
movl -0x4(%rax), %eax
shlq $0x20, %rax
addq 0x28(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x4586
movq %r15, %rdi
movq %rax, %rsi
callq 0x5156
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0x51f2
movq 0x30(%rsp), %r12
movl 0x18(%rsp), %eax
jmp 0x3e3c
testl %ebp, %ebp
jne 0x4136
leaq 0x18(%r14), %rdi
movq 0x128(%r14), %rsi
cmpq 0x130(%r14), %rsi
jne 0x40f1
movq 0x140(%r14), %rax
movl $0x200, %esi            # imm = 0x200
addq -0x8(%rax), %rsi
addq $-0x8, %rsi
callq 0x45ec
movq %rbx, %rdi
callq 0x47d2
movb $0x1, %al
jmp 0x4148
cmpq 0x130(%r14), %rax
jne 0x411f
movq 0x140(%r14), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %r15
movq %rbx, %rdi
callq 0x47d2
movq %r14, %rdi
movq %r15, %rsi
callq 0x3cf0
movq 0x128(%r14), %rax
cmpq 0x108(%r14), %rax
jne 0x4106
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop