// File: /workspace/github_cpp_makefile_star2_O3/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, -0x2c(%rbp)
movq %rsi, %r12
movq %rdi, %r14
movq %rsi, -0x38(%rbp)
movq %rsi, %rdi
callq 0x947c
movq %rax, %r15
movq %r12, %rdi
callq 0x94b0
movslq %eax, %rbx
leaq -0x58(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x92d6
movq 0x8(%r12), %r13
subq (%r12), %r13
sarq $0x5, %r13
movq %r12, %rdi
callq 0x60b2
cmpq %rbx, %r13
jbe 0x4a07
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
callq 0x92d6
movq -0x38(%rbp), %rdi
callq 0x94b0
movslq %eax, %rsi
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %rdx
subq %rcx, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rdx
jbe 0x4a2c
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 0x66bc
leaq -0x70(%rbp), %rdi
callq 0x60b2
movq 0x98f2(%rip), %rdi      # 0xdfd8
leaq 0x5c2e(%rip), %rsi      # 0xa31b
movl $0x1e, %edx
callq 0x2220
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x98d2(%rip), %rdi      # 0xdfd8
callq 0x2220
movq %rax, %r15
leaq 0x5a6f(%rip), %rsi      # 0xa184
movl $0x2, %edx
movq %rax, %rdi
callq 0x2220
movq -0x38(%rbp), %rdi
callq 0x94b0
movq %r15, %rdi
movl %eax, %esi
callq 0x22d0
movq %rax, %r15
leaq 0x5a45(%rip), %rsi      # 0xa184
movl $0x2, %edx
movq %rax, %rdi
callq 0x2220
movq -0x38(%rbp), %rdi
callq 0x9444
movq %r15, %rdi
movl %eax, %esi
callq 0x22d0
movq %rax, %r15
leaq 0x58d4(%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 0x66bc
leaq 0x10(%r14), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x67f8
movq %rax, %r15
leaq 0x28(%rax), %r13
testq %rax, %rax
movq %r13, %rax
cmoveq %r15, %rax
movq %rax, -0x80(%rbp)
movq -0xc0(%rbp), %rdi
cmpq %r12, %rdi
je 0x47f6
callq 0x21a0
testq %r15, %r15
je 0x4a3a
movq (%r13), %r15
cmpq %r13, %r15
je 0x49d5
movslq -0x2c(%rbp), %rax
movq 0x97c1(%rip), %rbx      # 0xdfd8
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
movq %rax, -0x78(%rbp)
movl $0x58, %edi
callq 0x21e0
movq %rax, %r13
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %r12
movq %r12, %rdi
callq 0x66bc
leaq 0x10(%r15), %rdx
movq -0x38(%rbp), %rcx
movq %r13, %rdi
movq %r12, %rsi
movl -0x2c(%rbp), %r8d
xorl %r9d, %r9d
callq 0x9308
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x488a
callq 0x21a0
movq %r13, -0x70(%rbp)
movl $0x42, %edx
movq %rbx, %rdi
leaq 0x5a9d(%rip), %rsi      # 0xa33a
callq 0x2220
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x22d0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x5ce2(%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 -0x2c(%rbp), %esi
callq 0x532a
movq 0x80(%r14), %rdi
addq -0x78(%rbp), %rdi
testl %eax, %eax
js 0x498a
movl %eax, %esi
movq (%rdi), %rax
movq 0x8(%rdi), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x49f9
movq (%rax,%rsi,8), %rdi
callq 0x943a
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x49a2
movq -0x38(%rbp), %rcx
movq %rcx, (%rsi)
addq $0x8, 0x8(%rax)
jmp 0x49ae
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x49bf
movq -0x70(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x49c8
movq %rax, %rdi
leaq -0x38(%rbp), %rdx
callq 0x7442
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x49c8
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x49c8
leaq -0x70(%rbp), %rdx
callq 0x7442
movq (%r15), %r15
cmpq -0x80(%rbp), %r15
jne 0x4823
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x49e7
callq 0x21a0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5c15(%rip), %rdi      # 0xa615
xorl %eax, %eax
callq 0x2280
movq 0x95ca(%rip), %rdi      # 0xdfd8
leaq 0x58e6(%rip), %rsi      # 0xa2fb
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
movl $0x1, %edi
callq 0x2230
leaq 0x5be2(%rip), %rdi      # 0xa615
xorl %eax, %eax
callq 0x2280
movq 0x9597(%rip), %rdi      # 0xdfd8
leaq 0x5935(%rip), %rsi      # 0xa37d
movl $0x25, %edx
callq 0x2220
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x9577(%rip), %rdi      # 0xdfd8
callq 0x2220
movq %rax, %rbx
leaq 0x5933(%rip), %rsi      # 0xa3a3
movl $0x2e, %edx
movq %rax, %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x20f0
jmp 0x4a22
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
cmpq %r12, %rdi
jne 0x4acf
jmp 0x4adb
jmp 0x4ad8
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x60b2
jmp 0x4aed
jmp 0x4ad8
jmp 0x4ad8
movq %rax, %rbx
jmp 0x4acc
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x4acc
callq 0x21a0
movq %r13, %rdi
callq 0x21a0
jmp 0x4adb
jmp 0x4ad8
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x4aed
callq 0x21a0
movq %rbx, %rdi
callq 0x22f0
nop