// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq 0x9065(%rip), %r14      # 0xdfd8
leaq 0x552f(%rip), %rsi      # 0xa4a9
movl $0x13, %edx
movq %r14, %rdi
callq 0x2220
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x944e
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r14, %rdi
callq 0x2220
movq %rax, %r12
leaq 0x51d3(%rip), %rsi      # 0xa184
movl $0x2, %edx
movq %rax, %rdi
callq 0x2220
movq %r13, %rdi
callq 0x94b0
movq %r12, %rdi
movl %eax, %esi
callq 0x22d0
movq %rax, %r12
leaq 0x51aa(%rip), %rsi      # 0xa184
movl $0x2, %edx
movq %rax, %rdi
callq 0x2220
movq %r13, %rdi
callq 0x9444
movq %r12, %rdi
movl %eax, %esi
callq 0x22d0
movq %rax, %r12
leaq 0x503a(%rip), %rsi      # 0xa03d
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x504a
callq 0x21a0
movq %r13, %rdi
callq 0x9444
cltq
movq 0x88(%rbx), %rcx
subq 0x80(%rbx), %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rax, %rdx
jbe 0x529b
movq %r13, %rdi
callq 0x9444
cltq
movq 0x80(%rbx), %rcx
leaq (%rax,%rax,2), %rax
movq %rbx, %r14
movq (%rcx,%rax,8), %rbx
movq %r13, %rdi
callq 0x9444
cltq
movq %r14, -0x50(%rbp)
movq 0x80(%r14), %rcx
leaq (%rax,%rax,2), %rax
cmpq 0x8(%rcx,%rax,8), %rbx
je 0x527e
movslq %r15d, %rax
leaq -0x48(%rbp), %r15
leaq (%rax,%rax,2), %rax
movq %rax, -0x58(%rbp)
movq (%rbx), %rdi
callq 0x947c
movq %r15, %rdi
movq %rax, %rsi
callq 0x92d6
movq -0x48(%rbp), %r12
movq -0x40(%rbp), %r14
movq (%rbx), %rdi
callq 0x94b0
subq %r12, %r14
sarq $0x5, %r14
movslq %eax, %r12
movq %r15, %rdi
callq 0x60b2
cmpq %r12, %r14
jbe 0x5256
movq %r15, %rdi
movq %r13, %rsi
callq 0x944e
movq (%rbx), %rdi
callq 0x947c
leaq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x92d6
movq (%rbx), %rdi
callq 0x94b0
movslq %eax, %rsi
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rdx
jbe 0x528d
shlq $0x5, %rsi
movq -0x40(%rbp), %rdx
cmpq 0x8(%rax,%rsi), %rdx
jne 0x5177
testq %rdx, %rdx
je 0x517c
addq %rsi, %rax
movq (%rax), %rsi
movq -0x48(%rbp), %rdi
callq 0x21f0
testl %eax, %eax
sete %r14b
jmp 0x517f
xorl %r14d, %r14d
jmp 0x517f
movb $0x1, %r14b
leaq -0x70(%rbp), %rdi
callq 0x60b2
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x519a
callq 0x21a0
testb %r14b, %r14b
je 0x5256
movq %r13, %r15
movl $0x58, %edi
callq 0x21e0
movq %rax, %r13
movq (%rbx), %rsi
leaq -0x90(%rbp), %rdi
callq 0x944e
movq (%rbx), %rdi
callq 0x947c
movq %rax, %r12
movq (%rbx), %rdi
callq 0x9444
movl %eax, %r14d
movq (%rbx), %rdi
callq 0x94b0
incl %eax
movq %r13, %rdi
leaq -0x90(%rbp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %r14d, %r8d
movl %eax, %r9d
callq 0x9308
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x5212
callq 0x21a0
movq %r13, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x58(%rbp), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5244
movq %r13, (%rsi)
addq $0x8, 0x8(%rdi)
movq %r15, %r13
leaq -0x48(%rbp), %r15
jmp 0x5256
leaq -0x48(%rbp), %r14
movq %r14, %rdx
callq 0x7442
movq %r15, %r13
movq %r14, %r15
addq $0x8, %rbx
movq %r13, %rdi
callq 0x9444
cltq
movq -0x50(%rbp), %rcx
movq 0x80(%rcx), %rcx
leaq (%rax,%rax,2), %rax
cmpq 0x8(%rcx,%rax,8), %rbx
jne 0x50cc
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5381(%rip), %rdi      # 0xa615
xorl %eax, %eax
callq 0x2280
movq 0x8d36(%rip), %rdi      # 0xdfd8
leaq 0x5214(%rip), %rsi      # 0xa4bd
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
movl $0x1, %edi
callq 0x2230
movq %rax, %rbx
jmp 0x52fa
jmp 0x52c7
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x60b2
jmp 0x5310
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x5318
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x52fa
callq 0x21a0
movq %r13, %rdi
jmp 0x531d
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x60b2
jmp 0x5322
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x5322
callq 0x21a0
movq %rbx, %rdi
callq 0x22f0