// File: /workspace/github_cpp_makefile_star2_O2/matteorr[P]EarleyParser/EarleyParser.cpp
// Function: EarleyParser::completer(State*, int)
void EarleyParser::completer( State* stateCompleted, int positionInputString )
{
	cout << "[DEBUG]: complete [" << stateCompleted->getNonTerminal() << "][" << stateCompleted->getProductionProgress() << "][" << stateCompleted->getInputStringProgress() << "]" << endl;
	//string nonTerminal = stateCompleted->getNonTerminal();
	//int inputStringProgress = stateCompleted->getInputStringProgress();
	//cout << "test input string progress: " << inputStringProgress << endl << endl;
	//vector<State>::iterator itTest = this->earleyParserChart[ stateCompleted->getInputStringProgress() ].begin();
	//cout << "test iterator: " << itTest->getNonTerminal() << endl << endl;

	if( stateCompleted->getInputStringProgress() >= this->earleyParserChart.size() ){
		cout << "[ERROR]: COMPLETER OVERFLOW" << endl;
		exit(1);
	}
	for( vector<State*>::iterator it = this->earleyParserChart[ stateCompleted->getInputStringProgress() ].begin();
			it != this->earleyParserChart[ stateCompleted->getInputStringProgress() ].end(); it++ )
	{
		if( (*it)->getProductionPointer()->getProductionContent().size() <= (*it)->getProductionProgress() ) continue;
		if( stateCompleted->getNonTerminal() == (*it)->getProductionPointer()->getProductionContent().at( (*it)->getProductionProgress() ) )
		{
			//cout << "before constructor in complete" << endl;
			State* stateToInsert = new State( (*it)->getNonTerminal(), (*it)->getProductionPointer(), stateCompleted, (*it)->getInputStringProgress(), (*it)->getProductionProgress() + 1 );
			this->earleyParserChart[ positionInputString ].push_back( stateToInsert );
			//cout << "after push back in complete" << endl;
		}
		//cout << "destructor called in complete" << endl;
	}

	//cout << "[DEBUG]: completed [" << stateCompleted.getNonTerminal() << "]" << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %r15d
movq %rsi, %r13
movq %rdi, -0x30(%rbp)
movq 0x905c(%rip), %rdi      # 0xcfd8
leaq 0x4526(%rip), %rsi      # 0x84a9
callq 0x21c0
movq %rax, %r14
leaq -0x50(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x780c
movq %r14, %rdi
movq %r12, %rsi
callq 0x2190
leaq 0x41d8(%rip), %rsi      # 0x8184
movq %rax, %rdi
callq 0x21c0
movq %rax, %r14
movq %r13, %rdi
callq 0x785a
movq %r14, %rdi
movl %eax, %esi
callq 0x22b0
leaq 0x41b4(%rip), %rsi      # 0x8184
movq %rax, %rdi
callq 0x21c0
movq %rax, %r14
movq %r13, %rdi
callq 0x7802
movq %r14, %rdi
movl %eax, %esi
callq 0x22b0
leaq 0x4049(%rip), %rsi      # 0x803d
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x2100
leaq -0x50(%rbp), %rdi
callq 0x20f0
movq %r13, %rdi
callq 0x7802
movslq %eax, %rcx
movq -0x30(%rbp), %r14
movq 0x88(%r14), %rax
subq 0x80(%r14), %rax
pushq $0x18
popq %rsi
cqto
idivq %rsi
cmpq %rcx, %rax
jbe 0x41b1
movq %r13, %rdi
callq 0x7802
cltq
movq 0x80(%r14), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rbx
movslq %r15d, %rax
imulq $0x18, %rax, %rax
movq %rax, -0x58(%rbp)
movq %r13, %rdi
callq 0x7802
cltq
movq -0x30(%rbp), %rcx
movq 0x80(%rcx), %rcx
imulq $0x18, %rax, %rax
cmpq 0x8(%rcx,%rax), %rbx
je 0x41a2
movq %r13, %r15
movq (%rbx), %rdi
callq 0x7828
movq %r12, %rdi
movq %rax, %rsi
callq 0x76d8
movq -0x50(%rbp), %r13
movq -0x48(%rbp), %r14
movq (%rbx), %rdi
callq 0x785a
subq %r13, %r14
sarq $0x5, %r14
movslq %eax, %r13
movq %r12, %rdi
callq 0x4ba2
cmpq %r13, %r14
movq %r15, %r13
jbe 0x4199
movq %r12, %rdi
movq %r13, %rsi
callq 0x780c
movq (%rbx), %rdi
callq 0x7828
leaq -0x90(%rbp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x76d8
movq (%rbx), %rdi
callq 0x785a
movslq %eax, %rsi
movq %r14, %rdi
callq 0x4c0a
movq %r12, %rdi
movq %rax, %rsi
callq 0x4e25
movq %r14, %rdi
movl %eax, %r14d
callq 0x4ba2
movq %r12, %rdi
callq 0x20f0
testb %r14b, %r14b
je 0x4199
pushq $0x58
popq %rdi
callq 0x21d0
movq %rax, %r15
movq (%rbx), %rsi
leaq -0x78(%rbp), %rdi
callq 0x780c
movq (%rbx), %rdi
callq 0x7828
movq %rax, %r12
movq (%rbx), %rdi
callq 0x7802
movl %eax, %r14d
movq (%rbx), %rdi
callq 0x785a
incl %eax
movq %r15, %rdi
leaq -0x78(%rbp), %rsi
movq %r12, %rdx
movq %r13, %rcx
movl %r14d, %r8d
movl %eax, %r9d
callq 0x770c
leaq -0x78(%rbp), %rdi
callq 0x20f0
movq %r15, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq 0x80(%rax), %rdi
addq -0x58(%rbp), %rdi
leaq -0x50(%rbp), %r12
movq %r12, %rsi
callq 0x4de0
addq $0x8, %rbx
jmp 0x405f
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8e20(%rip), %rdi      # 0xcfd8
leaq 0x42fe(%rip), %rsi      # 0x84bd
callq 0x21c0
movq %rax, %rdi
callq 0x2100
pushq $0x1
popq %rdi
callq 0x2200
movq %rax, %rbx
jmp 0x41e7
jmp 0x41ff
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x20f0
movq %r15, %rdi
callq 0x21a0
jmp 0x421c
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x4ba2
jmp 0x421c
movq %rax, %rbx
jmp 0x4213
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x4ba2
leaq -0x50(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x22c0