// File: /workspace/github_cpp_makefile_star2_O1/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 0x5f45
xorl %r14d, %r14d
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x5f28
movq (%rdi), %rax
callq *0x8(%rax)
incq %r14
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
movslq %edx, %rdx
cmpq %rdx, %r14
jl 0x5f19
cmpq %rax, %rcx
je 0x5f4e
movq %rax, 0x20(%rbx)
movq (%rbx), %rsi
cmpq %rsi, 0x8(%rbx)
je 0x6350
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 0x91d2
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 0x168(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x806a
leaq 0x168(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x5bb6
leaq 0x168(%rsp), %rdi
callq 0x8202
movl $0x0, 0x14c(%rbx)
movl $0x78, %edi
callq 0x2150
movq %rax, %r14
leaq 0x138(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x806a
movl 0x14c(%rbx), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x14c(%rbx)
leaq 0x138(%rsp), %rsi
movq %r14, %rdi
callq 0x9398
leaq 0x18(%rbx), %r15
leaq 0x138(%rsp), %rdi
callq 0x8202
movq %r14, 0x30(%rsp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x6054
movq %r14, (%rsi)
addq $0x8, 0x20(%rbx)
jmp 0x6061
leaq 0x30(%rsp), %rdx
movq %r15, %rdi
callq 0x8c2e
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
movq %r15, 0x40(%rsp)
je 0x6090
movq 0x30(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rsp)
jmp 0x609d
movq %rsp, %rdi
leaq 0x30(%rsp), %rdx
callq 0x8c2e
movq 0x8(%rsp), %rax
cmpq %rax, (%rsp)
je 0x6318
leaq 0xd8(%rbx), %rcx
movq %rcx, 0x38(%rsp)
leaq 0x108(%rsp), %r13
leaq 0x78(%rsp), %r14
movq -0x8(%rax), %rcx
movq %rcx, 0x28(%rsp)
addq $-0x8, %rax
movq %rax, 0x8(%rsp)
movq 0xe8(%rbx), %rbp
cmpq 0x38(%rsp), %rbp
je 0x6309
movq %r14, %r12
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), %r14b
movq 0x28(%rsp), %rdi
callq 0x9656
movq %r13, %rdi
movq %rax, %rsi
callq 0x806a
movsbl %r14b, %esi
movq %r13, %rdx
movq %r12, %r14
movq %r12, %rcx
callq 0x5dfa
movq %r13, %rdi
callq 0x8202
leaq 0x198(%rsp), %rdi
movq %r14, %rsi
callq 0x806a
leaq 0x198(%rsp), %r14
movq %r14, %rsi
leaq 0x48(%rsp), %rdx
callq 0x5bb6
movq %r14, %rdi
callq 0x8202
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
testl %ecx, %ecx
setg %r13b
jle 0x6204
xorl %r14d, %r14d
movq (%rax,%r14,8), %r15
movq %r15, %rdi
callq 0x9656
movq 0x28(%rax), %rcx
cmpq 0x70(%rsp), %rcx
jne 0x61e4
movq 0x18(%rax), %rdi
addq $0x8, %rax
movq 0x60(%rsp), %rdx
movq %rax, %rsi
callq 0x92e4
testb %al, %al
jne 0x6207
incq %r14
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r14
setl %r13b
jl 0x61b4
jmp 0x6207
xorl %r15d, %r15d
testb $0x1, %r13b
je 0x622e
movsbl 0x20(%rbp), %esi
movq 0x28(%rsp), %rdi
movq %r15, %rdx
callq 0x9520
leaq 0x108(%rsp), %r13
movq %r12, %r14
jmp 0x62e1
movl $0x78, %edi
callq 0x2150
leaq 0x108(%rsp), %r13
movq %rax, %r15
movq %r12, %r14
leaq 0x1c8(%rsp), %r12
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x806a
movl 0x14c(%rbx), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x14c(%rbx)
movq %r15, %rdi
movq %r12, %rsi
callq 0x9398
movq %r12, %rdi
callq 0x8202
movq %r15, 0x20(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x6299
movq %r15, (%rsi)
addq $0x8, 0x8(%rsp)
jmp 0x62a6
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x8c2e
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x62bf
movq 0x20(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x20(%rbx)
jmp 0x62ce
movq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x8c2e
movsbl 0x20(%rbp), %esi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rdi
callq 0x9520
leaq 0x48(%rsp), %rdi
callq 0x8202
movq %r14, %rdi
callq 0x8202
movq %rbp, %rdi
callq 0x21c0
movq %rax, %rbp
cmpq 0x38(%rsp), %rax
jne 0x60e9
movq 0x8(%rsp), %rax
cmpq %rax, (%rsp)
jne 0x60c5
movq %rbx, %rdi
callq 0x6446
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x6336
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2160
leaq 0xa8(%rsp), %rdi
callq 0x8202
leaq 0xd8(%rsp), %rdi
callq 0x8202
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x8202
jmp 0x6377
movq %rax, %rbx
movl $0x78, %esi
movq %r14, %rdi
jmp 0x641e
movq %rax, %rbx
leaq 0x168(%rsp), %rdi
callq 0x8202
jmp 0x6423
jmp 0x63a8
movq %rax, %rbx
jmp 0x6430
movq %rax, %rbx
jmp 0x640d
movq %rax, %rbx
jmp 0x6423
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
callq 0x8202
jmp 0x63c4
jmp 0x63f6
movq %rax, %rbx
movl $0x78, %esi
movq %r15, %rdi
callq 0x2160
jmp 0x63f9
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
jmp 0x63eb
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x8202
jmp 0x63f9
jmp 0x63f6
jmp 0x63f6
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x8202
leaq 0x78(%rsp), %rdi
callq 0x8202
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x6423
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2160
leaq 0xa8(%rsp), %rdi
callq 0x8202
leaq 0xd8(%rsp), %rdi
callq 0x8202
movq %rbx, %rdi
callq 0x2260
nop