// File: davinash[P]regex/src/regex.cpp
// Function: RegEx::EpsilonClosure(std::set<RegExState*, std::less<RegExState*>, std::allocator<RegExState*>>, std::set<RegExState*, std::less<RegExState*>, std::allocator<RegExState*>>&)
void RegEx::EpsilonClosure(std::set<RegExState*> startSet, std::set<RegExState*> &result) {
	std::stack<RegExState*> UnVisitedStates;	
	result.clear();	
	result = startSet; 
	StateIterator iter;
	for(iter = startSet.begin(); iter != startSet.end(); ++iter) {
		UnVisitedStates.push(*iter);
	}

	while(!UnVisitedStates.empty()) {
		RegExState* curState = UnVisitedStates.top();
		UnVisitedStates.pop();

		Table epsilonStates;
		curState->GetTransition(EPSILON, epsilonStates);

		TableIterator epsilonItr;

		for ( epsilonItr = epsilonStates.begin(); epsilonItr != epsilonStates.end(); ++epsilonItr ){
			if(result.find((*epsilonItr)) == result.end()) {
				result.insert((*epsilonItr));
				UnVisitedStates.push((*epsilonItr));
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rsi, -0xf0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xaea0
movq -0x18(%rbp), %rdi
callq 0xaed0
movq -0xf0(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0xaef0
jmp 0x8322
leaq -0x80(%rbp), %rdi
callq 0xaf20
movq -0xf0(%rbp), %rdi
callq 0xaf40
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0xf0(%rbp), %rdi
callq 0xafa0
movq %rax, -0x90(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xaf70
testb $0x1, %al
jne 0x8372
jmp 0x83a7
leaq -0x80(%rbp), %rdi
callq 0xb000
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0xafd0
jmp 0x8389
jmp 0x838b
leaq -0x80(%rbp), %rdi
callq 0xb030
jmp 0x8349
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x85a6
jmp 0x83a9
leaq -0x68(%rbp), %rdi
callq 0xb060
movb %al, -0xf1(%rbp)
jmp 0x83ba
movb -0xf1(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x83cb
jmp 0x8594
leaq -0x68(%rbp), %rdi
callq 0xb080
movq %rax, -0x100(%rbp)
jmp 0x83dd
movq -0x100(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x98(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xb0a0
jmp 0x83f9
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0xa470
movq -0x108(%rbp), %rdx
movq -0x98(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x13fd0
jmp 0x8426
leaq -0xb8(%rbp), %rdi
callq 0xb0c0
leaq -0xb0(%rbp), %rdi
callq 0xa9e0
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xaae0
movq %rax, -0xc8(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xb0e0
testb $0x1, %al
jne 0x8482
jmp 0x8583
movq -0x18(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xaa10
movq -0x118(%rbp), %rdi
movq %rax, %rsi
callq 0xb150
movq %rax, -0x110(%rbp)
jmp 0x84b1
movq -0x110(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rdi
callq 0xafa0
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xb120
testb $0x1, %al
jne 0x84eb
jmp 0x8570
movq -0x18(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xaa10
movq -0x130(%rbp), %rdi
movq %rax, %rsi
callq 0xb190
movb %dl, -0x121(%rbp)
movq %rax, -0x120(%rbp)
jmp 0x8520
movb -0x121(%rbp), %al
movq -0x120(%rbp), %rcx
movq %rcx, -0xe8(%rbp)
movb %al, -0xe0(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xaa10
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0xafd0
jmp 0x8554
jmp 0x8570
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xa530
jmp 0x85a6
jmp 0x8572
leaq -0xb8(%rbp), %rdi
callq 0xb1e0
jmp 0x8453
leaq -0xb0(%rbp), %rdi
callq 0xa530
jmp 0x83a9
leaq -0x68(%rbp), %rdi
callq 0xb200
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0xb200
movq -0x70(%rbp), %rdi
callq 0x33a0
nopl (%rax,%rax)