// File: /workspace/github_cpp_makefile_star2_O2/matteorr[P]EarleyParser/EarleyParser.cpp
// Function: EarleyParser::predictor(State*, int)
void EarleyParser::predictor( State* stateToExpand, int positionInputString )
{
	Production* productionInStateToExpand = stateToExpand->getProductionPointer();

	if( stateToExpand->getProductionProgress() >= productionInStateToExpand->getProductionContent().size() ){
		cout << "[ERROR]: overflow in predictor!" << endl;
		exit(1);
	}
	string nonTerminalToExpand = productionInStateToExpand->getProductionContent().at( stateToExpand->getProductionProgress() );

	cout << "[DEBUG]: predictor expanding [" << nonTerminalToExpand << "][" << stateToExpand->getProductionProgress() << "][" << stateToExpand->getInputStringProgress() << "]" << endl;

	list<Production>* pointerToListOfProductions = this->getProduction( nonTerminalToExpand );

	if( pointerToListOfProductions != NULL )
	{
		for( list<Production>::iterator it = pointerToListOfProductions->begin(); it != pointerToListOfProductions->end(); it++ )
		{
			State *stateToInsert = new State( nonTerminalToExpand, &(*it), stateToExpand, positionInputString, 0 );

			cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!POSITION INPUT STRING: " << positionInputString << " " << this->inputVector.size() << endl <<endl;

			int positionOfState = this->stateExists( positionInputString, stateToInsert );
			if(  positionOfState < 0 ){
				/*
				 * state not already in the chart
				 */

				this->earleyParserChart[ positionInputString ].push_back( stateToInsert );
				//cout << "[DEBUG]: predictor expanded [" << nonTerminalToExpand << "]" << endl;
			}else{
				/*
				 * state already in chart
				 * pushes back the state from which it comes inside it's backtrace state vector
				 */
				this->earleyParserChart[ positionInputString ].at( positionOfState )->getBacktraceStateVector()->push_back( stateToExpand );
				delete stateToInsert;
			}
		}
	}else{
		/*
		 * do nothing
		 */
		cout << "[DEBUG]: ERROR prediction to expand [" << nonTerminalToExpand << "] in state not found in prediction hash table " << endl;
		exit(1);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %edx, %ebx
movq %rsi, %r12
movq %rdi, %r14
movq %rsi, -0x40(%rbp)
movq %rsi, %rdi
callq 0x7828
movq %rax, %r15
movq %r12, %rdi
callq 0x785a
cltq
movq %rax, -0x38(%rbp)
leaq -0x78(%rbp), %r13
movq %r13, %rdi
movq %r15, -0x30(%rbp)
movq %r15, %rsi
callq 0x76d8
movq 0x8(%r13), %r15
subq (%r13), %r15
sarq $0x5, %r15
movq %r13, %rdi
callq 0x4ba2
cmpq -0x38(%rbp), %r15
jbe 0x3be2
leaq -0x58(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x76d8
movq %r12, %rdi
callq 0x785a
movq %r12, %r15
movslq %eax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x4c0a
leaq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x2250
leaq -0x58(%rbp), %rdi
callq 0x4ba2
movq 0x95d2(%rip), %rdi      # 0xcfd8
leaq 0x490e(%rip), %rsi      # 0x831b
callq 0x21c0
leaq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x2190
leaq 0x475f(%rip), %rsi      # 0x8184
movq %rax, %rdi
callq 0x21c0
movq %rax, %r12
movq %r15, %rdi
callq 0x785a
movq %r12, %rdi
movl %eax, %esi
callq 0x22b0
leaq 0x473b(%rip), %rsi      # 0x8184
movq %rax, %rdi
callq 0x21c0
movq %rax, %r12
movq %r15, %rdi
callq 0x7802
movq %r12, %rdi
movl %eax, %esi
callq 0x22b0
leaq 0x45d0(%rip), %rsi      # 0x803d
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x2100
leaq -0x98(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2250
leaq -0x98(%rbp), %rsi
movq %r14, %rdi
callq 0x35ca
movq %rax, %r15
leaq -0x98(%rbp), %rdi
callq 0x20f0
testq %r15, %r15
je 0x3c05
movslq %ebx, %rax
leaq -0xb8(%rbp), %r13
imulq $0x18, %rax, %rax
movq %rax, -0x30(%rbp)
movq %r15, -0x38(%rbp)
movq (%r15), %r15
cmpq -0x38(%rbp), %r15
je 0x3bc7
pushq $0x58
popq %rdi
callq 0x21d0
movq %rax, %r12
movq %r13, %rdi
leaq -0x78(%rbp), %rsi
callq 0x2250
leaq 0x10(%r15), %rdx
movq -0x40(%rbp), %rcx
movq %r12, %rdi
movq %r13, %rsi
movl %ebx, %r8d
xorl %r9d, %r9d
callq 0x770c
movq %r13, %rdi
callq 0x20f0
movq %r12, -0x58(%rbp)
movq 0x94be(%rip), %rdi      # 0xcfd8
leaq 0x4819(%rip), %rsi      # 0x833a
callq 0x21c0
movq %rax, %rdi
movl %ebx, %esi
callq 0x22b0
movq %rax, %rdi
leaq 0x4a67(%rip), %rsi      # 0x85a1
callq 0x21c0
movq 0xa0(%r14), %rsi
subq 0x98(%r14), %rsi
sarq $0x5, %rsi
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
movq -0x58(%rbp), %rdx
movq %r14, %rdi
movl %ebx, %esi
callq 0x4224
movq 0x80(%r14), %rdi
addq -0x30(%rbp), %rdi
testl %eax, %eax
js 0x3bb9
movl %eax, %esi
callq 0x4e04
movq (%rax), %rdi
callq 0x77f8
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
callq 0x4de0
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x3aca
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x3aca
leaq -0x58(%rbp), %rsi
callq 0x4de0
jmp 0x3aca
leaq -0x78(%rbp), %rdi
callq 0x20f0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x93ef(%rip), %rdi      # 0xcfd8
leaq 0x470b(%rip), %rsi      # 0x82fb
callq 0x21c0
movq %rax, %rdi
callq 0x2100
pushq $0x1
popq %rdi
callq 0x2200
movq 0x93cc(%rip), %rdi      # 0xcfd8
leaq 0x476a(%rip), %rsi      # 0x837d
callq 0x21c0
leaq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x2190
leaq 0x4778(%rip), %rsi      # 0x83a3
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x2100
jmp 0x3bfd
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x20f0
jmp 0x3c83
jmp 0x3c80
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x4ba2
jmp 0x3c8c
jmp 0x3c80
movq %rax, %rbx
jmp 0x3c74
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x21a0
jmp 0x3c83
jmp 0x3c80
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x22c0