// File: /workspace/github_cpp_makefile_star2_O3/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
movq 0x18(%rdi), %rax
movq 0x20(%rdi), %rcx
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
testl %edx, %edx
jle 0x5f47
xorl %r14d, %r14d
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x5f32
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
incq %r14
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
movslq %edx, %rdx
cmpq %rdx, %r14
jl 0x5f1b
cmpq %rax, %rcx
je 0x5f50
movq %rax, 0x20(%rbx)
movq (%rbx), %rsi
cmpq %rsi, 0x8(%rbx)
je 0x631a
leaq 0xe0(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq 0xd8(%rsp), %rdi
callq 0x9194
leaq 0xb0(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq 0x138(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x8060
leaq 0x138(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x5bd2
leaq 0x138(%rsp), %rdi
callq 0x81f8
movl $0x0, 0x14c(%rbx)
movl $0x78, %edi
callq 0x2150
movq %rax, %r14
leaq 0x108(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x8060
movl 0x14c(%rbx), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x14c(%rbx)
leaq 0x108(%rsp), %rsi
movq %r14, %rdi
callq 0x9350
leaq 0x18(%rbx), %r15
leaq 0x108(%rsp), %rdi
callq 0x81f8
movq %r14, 0x38(%rsp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x6056
movq %r14, (%rsi)
addq $0x8, 0x20(%rbx)
jmp 0x6063
leaq 0x38(%rsp), %rdx
movq %r15, %rdi
callq 0x8bf2
movq %r15, 0x40(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leaq 0x38(%rsp), %rdx
xorl %esi, %esi
callq 0x8bf2
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq %rcx, %rax
je 0x62e1
leaq 0xd8(%rbx), %rdx
movq %rdx, 0x30(%rsp)
leaq 0x168(%rsp), %r13
leaq 0x78(%rsp), %r14
leaq 0x1c8(%rsp), %r12
movq -0x8(%rcx), %rdx
movq %rdx, 0x28(%rsp)
addq $-0x8, %rcx
movq %rcx, 0x18(%rsp)
movq 0xe8(%rbx), %rbp
cmpq 0x30(%rsp), %rbp
je 0x62d8
xorl %ecx, %ecx
movl %ecx, 0x80(%rsp)
movq %rcx, 0x88(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %rax, 0x98(%rsp)
movq %rcx, 0xa0(%rsp)
movl %ecx, 0x50(%rsp)
movq %rcx, 0x58(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %rax, 0x68(%rsp)
movq %rcx, 0x70(%rsp)
movb 0x20(%rbp), %r15b
movq 0x28(%rsp), %rdi
callq 0x9610
movq %r13, %rdi
movq %rax, %rsi
callq 0x8060
movsbl %r15b, %esi
movq %r13, %rdx
movq %r14, %rcx
callq 0x5dfc
movq %r13, %rdi
callq 0x81f8
movq %r12, %rdi
movq %r14, %rsi
callq 0x8060
movq %r12, %rsi
leaq 0x48(%rsp), %rdx
callq 0x5bd2
movq %r12, %rdi
callq 0x81f8
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
testl %ecx, %ecx
jle 0x61e1
xorl %r13d, %r13d
movq (%rax,%r13,8), %r15
movq %r15, %rdi
callq 0x9610
movq 0x28(%rax), %rcx
cmpq 0x70(%rsp), %rcx
jne 0x61c7
movq 0x18(%rax), %rdi
addq $0x8, %rax
movq 0x60(%rsp), %rdx
movq %rax, %rsi
callq 0x92a6
testb %al, %al
jne 0x628d
incq %r13
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jl 0x6193
movl $0x78, %edi
callq 0x2150
leaq 0x198(%rsp), %r13
movq %rax, %r15
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
callq 0x8060
movl 0x14c(%rbx), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x14c(%rbx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x9350
movq %r13, %rdi
callq 0x81f8
movq %r15, 0x8(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x6241
movq %r15, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x6250
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x8bf2
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x6269
movq 0x8(%rsp), %rdx
movq %rdx, (%rsi)
addq $0x8, 0x20(%rbx)
jmp 0x627d
movq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x8bf2
movq 0x8(%rsp), %rdx
movsbl 0x20(%rbp), %esi
movq 0x28(%rsp), %rdi
callq 0x94d8
jmp 0x629e
movsbl 0x20(%rbp), %esi
movq 0x28(%rsp), %rdi
movq %r15, %rdx
callq 0x94d8
leaq 0x48(%rsp), %rdi
callq 0x81f8
movq %r14, %rdi
callq 0x81f8
movq %rbp, %rdi
callq 0x21c0
movq %rax, %rbp
cmpq 0x30(%rsp), %rax
leaq 0x168(%rsp), %r13
jne 0x60df
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq %rcx, %rax
jne 0x60bb
movq %rbx, %rdi
callq 0x6410
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6300
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2160
leaq 0xa8(%rsp), %rdi
callq 0x81f8
leaq 0xd8(%rsp), %rdi
callq 0x81f8
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 0x81f8
jmp 0x6341
movq %rax, %rbx
movl $0x78, %esi
movq %r14, %rdi
jmp 0x63e9
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x81f8
jmp 0x63ee
jmp 0x636d
movq %rax, %rbx
jmp 0x63fb
movq %rax, %rbx
jmp 0x63ee
movq %rax, %rbx
jmp 0x63d7
jmp 0x63c0
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x81f8
jmp 0x638e
movq %rax, %rbx
movl $0x78, %esi
movq %r15, %rdi
callq 0x2160
jmp 0x63c3
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
jmp 0x63b5
movq %rax, %rbx
leaq 0x168(%rsp), %rdi
callq 0x81f8
jmp 0x63c3
jmp 0x63c0
jmp 0x63c0
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x81f8
leaq 0x78(%rsp), %rdi
callq 0x81f8
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x63ee
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2160
leaq 0xa8(%rsp), %rdi
callq 0x81f8
leaq 0xd8(%rsp), %rdi
callq 0x81f8
movq %rbx, %rdi
callq 0x2260