// File: 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
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x268(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x268(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, -0x26c(%rbp)
addq $0x18, %rdi
callq 0xa5d0
movq %rax, %rcx
movl -0x26c(%rbp), %eax
cmpl %ecx, %eax
jge 0x8795
movq -0x268(%rbp), %rdi
addq $0x18, %rdi
movslq -0xc(%rbp), %rsi
callq 0xa5f0
movq (%rax), %rax
movq %rax, -0x278(%rbp)
cmpq $0x0, %rax
je 0x8788
movq -0x278(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x878a
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x8731
movq -0x268(%rbp), %rdi
addq $0x18, %rdi
callq 0xa610
movq -0x268(%rbp), %rdi
callq 0xa5d0
cmpq $0x0, %rax
jne 0x87bc
jmp 0x8e3d
leaq -0x40(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0xb220
movq -0x268(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xa5f0
movq -0x290(%rbp), %rdi
movq %rax, %rsi
callq 0xb190
movb %dl, -0x281(%rbp)
movq %rax, -0x280(%rbp)
jmp 0x87fa
movb -0x281(%rbp), %al
movq -0x280(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movb %al, -0x58(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xb220
leaq -0xc0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xb240
jmp 0x882c
movq -0x268(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x82e0
jmp 0x8848
leaq -0xc0(%rbp), %rdi
callq 0xb270
movq -0x268(%rbp), %rax
movl $0x0, 0x14c(%rax)
movl $0x78, %edi
callq 0x3250
movq %rax, -0x298(%rbp)
jmp 0x8878
movb $0x1, -0xf9(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xb240
jmp 0x8894
movq -0x298(%rbp), %rdi
movq -0x268(%rbp), %rax
movl 0x14c(%rax), %edx
movl %edx, %ecx
incl %ecx
movl %ecx, 0x14c(%rax)
leaq -0xf8(%rbp), %rsi
callq 0x13cd0
jmp 0x88c0
movb $0x0, -0xf9(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0xb270
movq -0x298(%rbp), %rax
movq -0x268(%rbp), %rdi
movq %rax, -0xc8(%rbp)
addq $0x18, %rdi
leaq -0xc8(%rbp), %rsi
callq 0xabe0
jmp 0x88fa
leaq -0x118(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0xa470
movq -0x2a0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xabe0
jmp 0x8922
jmp 0x8924
leaq -0x118(%rbp), %rdi
callq 0xb290
xorb $-0x1, %al
testb $0x1, %al
jne 0x893b
jmp 0x8e0e
leaq -0x118(%rbp), %rdi
callq 0xa5d0
movq %rax, %rsi
subq $0x1, %rsi
leaq -0x118(%rbp), %rdi
callq 0xa5f0
movq (%rax), %rax
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
callq 0xb2d0
leaq -0x128(%rbp), %rdi
callq 0xb300
movq -0x268(%rbp), %rdi
addq $0xd0, %rdi
callq 0xb320
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x268(%rbp), %rdi
addq $0xd0, %rdi
callq 0xb380
movq %rax, -0x138(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0xb350
testb $0x1, %al
jne 0x89da
jmp 0x8e09
leaq -0x168(%rbp), %rdi
callq 0xb220
leaq -0x198(%rbp), %rdi
callq 0xb220
leaq -0x128(%rbp), %rdi
callq 0xb3b0
movb (%rax), %al
movb %al, -0x2a9(%rbp)
movq -0x120(%rbp), %rdi
callq 0x14080
movq %rax, -0x2a8(%rbp)
jmp 0x8a1b
movq -0x2a8(%rbp), %rsi
leaq -0x1c8(%rbp), %rdi
callq 0xb240
jmp 0x8a30
movq -0x268(%rbp), %rdi
movb -0x2a9(%rbp), %al
movsbl %al, %esi
leaq -0x1c8(%rbp), %rdx
leaq -0x168(%rbp), %rcx
callq 0x85c0
jmp 0x8a55
leaq -0x1c8(%rbp), %rdi
callq 0xb270
leaq -0x1f8(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0xb240
jmp 0x8a76
movq -0x268(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
leaq -0x198(%rbp), %rdx
callq 0x82e0
jmp 0x8a92
leaq -0x1f8(%rbp), %rdi
callq 0xb270
leaq -0x200(%rbp), %rdi
callq 0xaf20
leaq -0x208(%rbp), %rdi
callq 0xaf20
movb $0x0, -0x209(%rbp)
movq $0x0, -0x218(%rbp)
movl $0x0, -0x21c(%rbp)
movq -0x268(%rbp), %rdi
movl -0x21c(%rbp), %eax
movl %eax, -0x2b0(%rbp)
addq $0x18, %rdi
callq 0xa5d0
movq %rax, %rcx
movl -0x2b0(%rbp), %eax
cmpl %ecx, %eax
jge 0x8c63
movq -0x268(%rbp), %rdi
addq $0x18, %rdi
movslq -0x21c(%rbp), %rsi
callq 0xa5f0
movq (%rax), %rax
movq %rax, -0x218(%rbp)
movq -0x218(%rbp), %rdi
callq 0x14080
movq %rax, -0x2b8(%rbp)
jmp 0x8b35
movq -0x2b8(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0xb3d0
movb %al, -0x2b9(%rbp)
jmp 0x8b50
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x8b5f
jmp 0x8c4d
movb $0x1, -0x209(%rbp)
jmp 0x8c63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8e5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8e52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xb270
jmp 0x8e52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8bd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0xb270
testb $0x1, -0xf9(%rbp)
jne 0x8bdb
jmp 0x8bec
movq -0x298(%rbp), %rdi
movl $0x78, %esi
callq 0x3260
jmp 0x8e52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8e46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8def
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0xb270
jmp 0x8def
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0xb270
jmp 0x8def
jmp 0x8c4f
movl -0x21c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x21c(%rbp)
jmp 0x8ad2
testb $0x1, -0x209(%rbp)
jne 0x8d92
movl $0x78, %edi
callq 0x3250
movq %rax, -0x2c8(%rbp)
jmp 0x8c83
movb $0x1, -0x259(%rbp)
leaq -0x258(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0xb240
jmp 0x8c9f
movq -0x2c8(%rbp), %rdi
movq -0x268(%rbp), %rax
movl 0x14c(%rax), %edx
movl %edx, %ecx
incl %ecx
movl %ecx, 0x14c(%rax)
leaq -0x258(%rbp), %rsi
callq 0x13cd0
jmp 0x8ccb
movb $0x0, -0x259(%rbp)
leaq -0x258(%rbp), %rdi
callq 0xb270
movq -0x2c8(%rbp), %rax
movq %rax, -0x228(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0xabe0
jmp 0x8d01
movq -0x268(%rbp), %rdi
addq $0x18, %rdi
leaq -0x228(%rbp), %rsi
callq 0xabe0
jmp 0x8d1a
movq -0x120(%rbp), %rax
movq %rax, -0x2d0(%rbp)
leaq -0x128(%rbp), %rdi
callq 0xb3b0
movq -0x2d0(%rbp), %rdi
movsbl (%rax), %esi
movq -0x228(%rbp), %rdx
callq 0x13ec0
jmp 0x8d4c
jmp 0x8dc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8d74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x258(%rbp), %rdi
callq 0xb270
testb $0x1, -0x259(%rbp)
jne 0x8d7f
jmp 0x8d90
movq -0x2c8(%rbp), %rdi
movl $0x78, %esi
callq 0x3260
jmp 0x8def
movq -0x120(%rbp), %rax
movq %rax, -0x2d8(%rbp)
leaq -0x128(%rbp), %rdi
callq 0xb3b0
movq -0x2d8(%rbp), %rdi
movsbl (%rax), %esi
movq -0x218(%rbp), %rdx
callq 0x13ec0
jmp 0x8dc4
jmp 0x8dc6
leaq -0x198(%rbp), %rdi
callq 0xb270
leaq -0x168(%rbp), %rdi
callq 0xb270
leaq -0x128(%rbp), %rdi
callq 0xb400
jmp 0x89a4
leaq -0x198(%rbp), %rdi
callq 0xb270
leaq -0x168(%rbp), %rdi
callq 0xb270
jmp 0x8e46
jmp 0x8924
movq -0x268(%rbp), %rdi
callq 0x8e70
jmp 0x8e1c
leaq -0x118(%rbp), %rdi
callq 0xa530
leaq -0x90(%rbp), %rdi
callq 0xb270
leaq -0x40(%rbp), %rdi
callq 0xb270
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
leaq -0x118(%rbp), %rdi
callq 0xa530
leaq -0x90(%rbp), %rdi
callq 0xb270
leaq -0x40(%rbp), %rdi
callq 0xb270
movq -0x48(%rbp), %rdi
callq 0x33a0