// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, %r14
movq %rsi, -0x30(%rbp)
movq %rsi, %rdi
callq 0x9488
movq %rax, %r15
movq -0x30(%rbp), %rdi
callq 0x94bc
cltq
movq %rax, -0x38(%rbp)
leaq -0x58(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x92e6
movq 0x8(%r12), %r13
subq (%r12), %r13
sarq $0x5, %r13
movq %r12, %rdi
callq 0x60da
cmpq -0x38(%rbp), %r13
jbe 0x4a17
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
callq 0x92e6
movq -0x30(%rbp), %rdi
callq 0x94bc
movslq %eax, %rsi
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %rdx
subq %rcx, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rdx
jbe 0x4a3c
shlq $0x5, %rsi
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%rcx,%rsi), %rax
movq 0x8(%rcx,%rsi), %rdx
addq %rax, %rdx
leaq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x66d0
leaq -0x70(%rbp), %rdi
callq 0x60da
movq 0x990d(%rip), %rdi      # 0xdfd8
leaq 0x5c49(%rip), %rsi      # 0xa31b
movl $0x1e, %edx
callq 0x2220
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x98ed(%rip), %rdi      # 0xdfd8
callq 0x2220
movq %rax, %r15
leaq 0x5a8a(%rip), %rsi      # 0xa184
movl $0x2, %edx
movq %rax, %rdi
callq 0x2220
movq -0x30(%rbp), %rdi
callq 0x94bc
movq %r15, %rdi
movl %eax, %esi
callq 0x22d0
movq %rax, %r15
leaq 0x5a60(%rip), %rsi      # 0xa184
movl $0x2, %edx
movq %rax, %rdi
callq 0x2220
movq -0x30(%rbp), %rdi
callq 0x9450
movq %r15, %rdi
movl %eax, %esi
callq 0x22d0
movq %rax, %r15
leaq 0x58ef(%rip), %rsi      # 0xa03d
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
leaq -0xb0(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x66d0
leaq 0x10(%r14), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x6804
movq %rax, %r15
addq $0x28, %rax
testq %r15, %r15
cmoveq %r15, %rax
movq %rax, -0x80(%rbp)
movq -0xc0(%rbp), %rdi
cmpq %r12, %rdi
je 0x47d8
callq 0x21a0
testq %r15, %r15
je 0x4a4a
movq -0x80(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x38(%rbp)
cmpq %rax, %rcx
je 0x49e5
movslq %ebx, %rax
movq 0x97d9(%rip), %r12      # 0xdfd8
leaq (%rax,%rax,2), %rax
movq %rax, -0x78(%rbp)
movl $0x58, %edi
callq 0x21e0
movq %rax, %r13
movq %r14, %r15
movq %r12, %r14
movl %ebx, %r12d
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rbx
movq %rbx, %rdi
callq 0x66d0
movq -0x38(%rbp), %rax
leaq 0x10(%rax), %rdx
movq -0x30(%rbp), %rcx
movq %r13, %rdi
movq %rbx, %rsi
movl %r12d, %ebx
movl %r12d, %r8d
xorl %r9d, %r9d
callq 0x9318
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
movq %r14, %r12
je 0x4880
callq 0x21a0
movq %r13, -0x70(%rbp)
movl $0x42, %edx
movq %r12, %rdi
leaq 0x5aa7(%rip), %rsi      # 0xa33a
callq 0x2220
movq %r15, %r14
movq %r12, %rdi
movl %ebx, %esi
callq 0x22d0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x5cea(%rip), %rsi      # 0xa5a1
callq 0x2220
movq 0xa0(%r14), %rsi
subq 0x98(%r14), %rsi
sarq $0x5, %rsi
movq %r13, %rdi
callq 0x2140
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq -0x70(%rbp), %rdx
movq %r14, %rdi
movl %ebx, %esi
callq 0x533c
testl %eax, %eax
js 0x4983
movq 0x80(%r14), %rcx
movl %eax, %esi
movq -0x78(%rbp), %rdx
movq (%rcx,%rdx,8), %rax
movq 0x8(%rcx,%rdx,8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x4a09
movq (%rax,%rsi,8), %rdi
callq 0x9446
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x49aa
movq -0x30(%rbp), %rcx
movq %rcx, (%rsi)
addq $0x8, 0x8(%rax)
jmp 0x49b6
movq 0x80(%r14), %rax
movq -0x78(%rbp), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x49c7
movq -0x70(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x49d0
movq %rax, %rdi
leaq -0x30(%rbp), %rdx
callq 0x744e
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x49d0
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x49d0
leaq -0x70(%rbp), %rdx
callq 0x744e
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
cmpq -0x80(%rbp), %rax
jne 0x4807
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x49f7
callq 0x21a0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5c05(%rip), %rdi      # 0xa615
xorl %eax, %eax
callq 0x2280
movq 0x95ba(%rip), %rdi      # 0xdfd8
leaq 0x58d6(%rip), %rsi      # 0xa2fb
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
movl $0x1, %edi
callq 0x2230
leaq 0x5bd2(%rip), %rdi      # 0xa615
xorl %eax, %eax
callq 0x2280
movq 0x9587(%rip), %rdi      # 0xdfd8
leaq 0x5925(%rip), %rsi      # 0xa37d
movl $0x25, %edx
callq 0x2220
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x9567(%rip), %rdi      # 0xdfd8
callq 0x2220
movq %rax, %rbx
leaq 0x5923(%rip), %rsi      # 0xa3a3
movl $0x2e, %edx
movq %rax, %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x20f0
jmp 0x4a32
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r12, %rdi
jne 0x4adf
jmp 0x4aeb
jmp 0x4ae8
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x60da
jmp 0x4afd
jmp 0x4ae8
jmp 0x4ae8
movq %rax, %rbx
jmp 0x4adc
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x4adc
callq 0x21a0
movq %r13, %rdi
callq 0x21a0
jmp 0x4aeb
jmp 0x4ae8
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x4afd
callq 0x21a0
movq %rbx, %rdi
callq 0x22f0
nop