// File: /workspace/github_cpp_makefile_star2_O2/davinash[P]regex/src/regex.cpp
// Function: RegEx::ConvertNFAtoDFA()
void RegEx::ConvertNFAtoDFA() {
	for(int i = 0; i < (int)m_DFATable.size(); ++i)
		delete m_DFATable[i];
	m_DFATable.clear();

	if(m_NFATable.size() == 0)
		return;
	
	std::set<RegExState*> NFAStartStateSet;
	NFAStartStateSet.insert(m_NFATable[0]);

	std::set<RegExState*> DFAStartStateSet;
	EpsilonClosure(NFAStartStateSet, DFAStartStateSet);

	m_nNextStateID = 0;
	RegExState *DFAStartState = new RegExState(DFAStartStateSet, m_nNextStateID++);

	m_DFATable.push_back(DFAStartState);

	Table UnVisitedStates;
	UnVisitedStates.push_back(DFAStartState);
	while(!UnVisitedStates.empty()) {

		RegExState* CurDFAState = UnVisitedStates[UnVisitedStates.size()-1];
		UnVisitedStates.pop_back();

		std::set<char>::iterator iter;
		for(iter = m_InputSet.begin(); iter != m_InputSet.end(); ++iter) {
			std::set<RegExState*> MoveRes, EpsilonClosureRes;

			Move(*iter, CurDFAState->GetNFAState(), MoveRes);
			EpsilonClosure(MoveRes, EpsilonClosureRes);

			StateIterator MoveResItr;
			StateIterator EpsilonClosureResItr;

			bool bFound = false;
			RegExState *s   = NULL;
			for(int i = 0; i < (int)m_DFATable.size(); ++i) {
				s = m_DFATable[i];
				if(s->GetNFAState() == EpsilonClosureRes) {
					bFound = true;
					break;
				}
			}
			if(!bFound) {
				RegExState* U = new RegExState(EpsilonClosureRes, m_nNextStateID++);
				UnVisitedStates.push_back(U);
				m_DFATable.push_back(U);                                
				CurDFAState->AddTransition(*iter, U);
			} else {
				CurDFAState->AddTransition(*iter, s);
			}
		}
	}	
	ReduceDFA();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, %rbx
leaq 0x18(%rdi), %rax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
movslq %edx, %rdx
cmpq %rdx, %r14
jge 0x4b80
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x4b7b
movq (%rdi), %rax
callq *0x8(%rax)
incq %r14
jmp 0x4b52
cmpq %rax, %rcx
je 0x4b89
movq %rax, 0x20(%rbx)
movq (%rbx), %rsi
cmpq %rsi, 0x8(%rbx)
je 0x4ead
leaq 0xe0(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0xd8(%rsp), %rdi
callq 0x778e
leaq 0xb0(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x138(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x64b0
leaq 0x138(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x4928
leaq 0x138(%rsp), %rdi
callq 0x6634
andl $0x0, 0x14c(%rbx)
pushq $0x78
popq %rdi
callq 0x2180
movq %rax, %r14
leaq 0x108(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x64b0
movl 0x14c(%rbx), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x14c(%rbx)
leaq 0x108(%rsp), %rsi
movq %r14, %rdi
callq 0x7946
leaq 0x108(%rsp), %rdi
callq 0x6634
leaq 0x40(%rsp), %rsi
movq %r14, (%rsi)
movq 0x18(%rsp), %rdi
callq 0x5da4
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x40(%rsp), %rsi
callq 0x5da4
leaq 0xd8(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0x1c8(%rsp), %r13
leaq 0x78(%rsp), %r15
movq 0x28(%rsp), %rax
cmpq %rax, 0x20(%rsp)
je 0x4e81
movq -0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
addq $-0x8, %rax
movq %rax, 0x28(%rsp)
movq 0xe8(%rbx), %rax
cmpq 0x38(%rsp), %rax
je 0x4cac
andl $0x0, 0x80(%rsp)
andq $0x0, 0x88(%rsp)
movq %rax, %rcx
leaq 0x80(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %rax, 0x98(%rsp)
andq $0x0, 0xa0(%rsp)
andl $0x0, 0x50(%rsp)
andq $0x0, 0x58(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %rax, 0x68(%rsp)
andq $0x0, 0x70(%rsp)
movq %rcx, %rbp
movb 0x20(%rcx), %r12b
movq 0x8(%rsp), %rdi
callq 0x7b9e
movq %r13, %rdi
movq %rax, %rsi
callq 0x64b0
movsbl %r12b, %esi
movq %r13, %rdx
movq %r15, %r14
movq %r15, %rcx
callq 0x4a68
movq %r13, %rdi
callq 0x6634
leaq 0x168(%rsp), %rdi
movq %r14, %rsi
callq 0x64b0
leaq 0x168(%rsp), %r12
movq %r12, %rsi
leaq 0x48(%rsp), %rdx
callq 0x4928
movq %r13, %r14
movq %r12, %rdi
callq 0x6634
xorl %r13d, %r13d
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jge 0x4de7
movq (%rax,%r13,8), %r12
movq %r12, %rdi
callq 0x7b9e
movq %rax, %rdi
leaq 0x48(%rsp), %rsi
callq 0x788a
incq %r13
testb %al, %al
je 0x4d9a
movsbl 0x20(%rbp), %esi
movq 0x8(%rsp), %rdi
movq %r12, %rdx
callq 0x7aa6
movq %r14, %r13
jmp 0x4e62
pushq $0x78
popq %rdi
callq 0x2180
movq %rax, %r12
movq %r14, %r13
leaq 0x198(%rsp), %r14
movq %r14, %rdi
leaq 0x48(%rsp), %rsi
callq 0x64b0
movl 0x14c(%rbx), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x14c(%rbx)
movq %r12, %rdi
movq %r14, %rsi
callq 0x7946
movq %r14, %rdi
callq 0x6634
movq %r12, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x5da4
movq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x5da4
movsbl 0x20(%rbp), %esi
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x7aa6
leaq 0x48(%rsp), %rdi
callq 0x6634
movq %r15, %rdi
callq 0x6634
movq %rbp, %rdi
callq 0x21d0
jmp 0x4cd5
movq %rbx, %rdi
callq 0x4f92
leaq 0x20(%rsp), %rdi
callq 0x6a06
leaq 0xa8(%rsp), %rdi
callq 0x6634
leaq 0xd8(%rsp), %rdi
callq 0x6634
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x6634
jmp 0x4ed4
movq %rax, %rbx
pushq $0x78
popq %rsi
movq %r14, %rdi
callq 0x2190
jmp 0x4f6f
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x6634
jmp 0x4f6f
jmp 0x4f02
movq %rax, %rbx
jmp 0x4f7c
movq %rax, %rbx
jmp 0x4f65
movq %rax, %rbx
jmp 0x4f6f
jmp 0x4f4e
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x6634
jmp 0x4f1e
movq %rax, %rbx
pushq $0x78
popq %rsi
movq %r12, %rdi
callq 0x2190
jmp 0x4f51
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
jmp 0x4f43
movq %rax, %rbx
leaq 0x168(%rsp), %rdi
callq 0x6634
jmp 0x4f51
jmp 0x4f4e
jmp 0x4f4e
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x6634
leaq 0x78(%rsp), %rdi
callq 0x6634
leaq 0x20(%rsp), %rdi
callq 0x6a06
leaq 0xa8(%rsp), %rdi
callq 0x6634
leaq 0xd8(%rsp), %rdi
callq 0x6634
movq %rbx, %rdi
callq 0x2290
nop