// File: 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
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x10(%rbp), %rdi
callq 0x116d0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x11730
cltq
movq %rax, -0xf8(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x114b0
leaq -0x38(%rbp), %rdi
callq 0x6c90
movq %rax, -0x100(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x6f60
movq -0x100(%rbp), %rcx
movq -0xf8(%rbp), %rax
cmpq %rcx, %rax
jb 0x4dd5
movq 0x17228(%rip), %rdi     # 0x1bfd8
leaq 0xe530(%rip), %rsi      # 0x132e7
callq 0x21c0
movq %rax, %rdi
movq 0x17202(%rip), %rsi     # 0x1bfc8
callq 0x21f0
movl $0x1, %edi
callq 0x2220
movq -0x20(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x114b0
movq -0x10(%rbp), %rdi
callq 0x11730
movl %eax, -0x10c(%rbp)
jmp 0x4df3
movl -0x10c(%rbp), %eax
movslq %eax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x7090
movq %rax, -0x118(%rbp)
jmp 0x4e0e
movq -0x118(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x20f0
jmp 0x4e20
leaq -0x70(%rbp), %rdi
callq 0x6f60
movq 0x171a8(%rip), %rdi     # 0x1bfd8
leaq 0xe4d0(%rip), %rsi      # 0x13307
callq 0x21c0
movq %rax, -0x120(%rbp)
jmp 0x4e45
movq -0x120(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x21a0
movq %rax, -0x128(%rbp)
jmp 0x4e5e
movq -0x128(%rbp), %rdi
leaq 0xe304(%rip), %rsi      # 0x13170
callq 0x21c0
movq %rax, -0x130(%rbp)
jmp 0x4e7a
movq -0x10(%rbp), %rdi
callq 0x11730
movl %eax, -0x134(%rbp)
jmp 0x4e8b
movl -0x134(%rbp), %esi
movq -0x130(%rbp), %rdi
callq 0x2330
movq %rax, -0x140(%rbp)
jmp 0x4ea6
movq -0x140(%rbp), %rdi
leaq 0xe2bc(%rip), %rsi      # 0x13170
callq 0x21c0
movq %rax, -0x148(%rbp)
jmp 0x4ec2
movq -0x10(%rbp), %rdi
callq 0x11680
movl %eax, -0x14c(%rbp)
jmp 0x4ed3
movl -0x14c(%rbp), %esi
movq -0x148(%rbp), %rdi
callq 0x2330
movq %rax, -0x158(%rbp)
jmp 0x4eee
movq -0x158(%rbp), %rdi
leaq 0xe12d(%rip), %rsi      # 0x13029
callq 0x21c0
movq %rax, -0x160(%rbp)
jmp 0x4f0a
movq -0x160(%rbp), %rdi
movq 0x170b0(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x4f1f
leaq -0xa8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x20f0
jmp 0x4f31
movq -0x108(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x46e0
movq %rax, -0x168(%rbp)
jmp 0x4f4d
leaq -0xa8(%rbp), %rdi
callq 0x2140
movq -0x168(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x5261
movq -0x88(%rbp), %rdi
callq 0x7470
movq %rax, -0xb0(%rbp)
movq -0x88(%rbp), %rdi
callq 0x74d0
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x74a0
testb $0x1, %al
jne 0x4fb7
jmp 0x525f
movl $0x58, %edi
callq 0x21d0
movq %rax, -0x170(%rbp)
jmp 0x4fca
movb $0x1, -0xe1(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x20f0
jmp 0x4fe3
leaq -0xb0(%rbp), %rdi
callq 0x7970
movq -0x170(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
movl -0x14(%rbp), %r8d
leaq -0xe0(%rbp), %rsi
xorl %r9d, %r9d
callq 0x11520
jmp 0x5012
movb $0x0, -0xe1(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x2140
movq -0x170(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq 0x16f9e(%rip), %rdi     # 0x1bfd8
leaq 0xe2e5(%rip), %rsi      # 0x13326
callq 0x21c0
movq %rax, -0x178(%rbp)
jmp 0x504f
movq -0x178(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2330
movq %rax, -0x180(%rbp)
jmp 0x5067
movq -0x180(%rbp), %rdi
leaq 0xe518(%rip), %rsi      # 0x1358d
callq 0x21c0
movq %rax, -0x188(%rbp)
jmp 0x5083
movq -0x108(%rbp), %rdi
addq $0x98, %rdi
callq 0x6c90
movq -0x188(%rbp), %rdi
movq %rax, %rsi
callq 0x2080
movq %rax, -0x190(%rbp)
jmp 0x50ae
movq -0x190(%rbp), %rdi
movq 0x16f0c(%rip), %rsi     # 0x1bfc8
callq 0x21f0
movq %rax, -0x198(%rbp)
jmp 0x50ca
movq -0x198(%rbp), %rdi
movq 0x16ef0(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x50df
movq -0x108(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0xc0(%rbp), %rdx
callq 0x5c80
movl %eax, -0x19c(%rbp)
jmp 0x50fd
movl -0x19c(%rbp), %eax
movl %eax, -0xe8(%rbp)
cmpl $0x0, -0xe8(%rbp)
jge 0x51ca
movq -0x108(%rbp), %rdi
subq $-0x80, %rdi
movslq -0x14(%rbp), %rsi
callq 0x7990
movq %rax, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x79b0
jmp 0x513b
jmp 0x5243
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x6f60
jmp 0x52ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x52e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x2140
jmp 0x52e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x51ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x2140
testb $0x1, -0xe1(%rbp)
jne 0x51b9
jmp 0x51c5
movq -0x170(%rbp), %rdi
callq 0x21b0
jmp 0x52e3
movq -0x108(%rbp), %rdi
subq $-0x80, %rdi
movslq -0x14(%rbp), %rsi
callq 0x7990
movq %rax, %rdi
movslq -0xe8(%rbp), %rsi
callq 0x7a40
movq %rax, -0x1a8(%rbp)
jmp 0x51f6
movq -0x1a8(%rbp), %rax
movq (%rax), %rdi
callq 0x11660
movq %rax, -0x1b0(%rbp)
jmp 0x520e
movq -0x1b0(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x79b0
jmp 0x5220
movq -0xc0(%rbp), %rax
movq %rax, -0x1b8(%rbp)
cmpq $0x0, %rax
je 0x5241
movq -0x1b8(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x5243
jmp 0x5245
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0x7520
movq %rax, -0xf0(%rbp)
jmp 0x4f88
jmp 0x52d1
movq 0x16d70(%rip), %rdi     # 0x1bfd8
leaq 0xe0fa(%rip), %rsi      # 0x13369
callq 0x21c0
movq %rax, -0x1c0(%rbp)
jmp 0x527d
movq -0x1c0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x21a0
movq %rax, -0x1c8(%rbp)
jmp 0x5296
movq -0x1c8(%rbp), %rdi
leaq 0xe0eb(%rip), %rsi      # 0x1338f
callq 0x21c0
movq %rax, -0x1d0(%rbp)
jmp 0x52b2
movq -0x1d0(%rbp), %rdi
movq 0x16d08(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x52c7
movl $0x1, %edi
callq 0x2220
leaq -0x58(%rbp), %rdi
callq 0x2140
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x2140
movq -0x78(%rbp), %rdi
callq 0x2340
nopw %cs:(%rax,%rax)