// File: richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::cleanupFiles(char const*)
void Swarm::cleanupFiles(const char * path) {
	// TODO: Should we fork to do this? ...yes.
	DIR* dp;
	dirent* de;
	errno = 0;

	vector<string> filesToDel;

	dp = opendir(path);

	if (dp)
	{
		while (true)
		{
			//cout << "about to readdir" << endl;
			errno = 0;
			de = readdir( dp );
			if (de == NULL) break;
			//cout << "read " << de->d_name << endl;
			if (boost::regex_match(string( de->d_name ),boost::regex(".+xml$|.+species$|.+cdat$|.+gdat$|.+net$|.+BNG_OUT"))) {
				//cout << "found a file";
				filesToDel.push_back( string(de->d_name) );
			}
		}
		closedir( dp );
	}
	else {
		cout << "Warning: Couldn't open " << path << " to delete un-needed simulation files." << endl;
	}

	//for (auto i: filesToDel) {
	for (auto i = filesToDel.begin(); i != filesToDel.end(); ++i) {
		string fullPath = string(path) + "/" + *i;
		remove(fullPath.c_str());
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x30ba0
movl $0x0, (%rax)
leaq -0x38(%rbp), %rdi
callq 0x448b0
movq -0x10(%rbp), %rdi
callq 0x2ff80
movq %rax, -0x128(%rbp)
jmp 0x1050b9
movq -0x128(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1052a0
jmp 0x1050d1
jmp 0x1050d3
callq 0x30ba0
movl $0x0, (%rax)
movq -0x18(%rbp), %rdi
callq 0x304a0
movq %rax, -0x130(%rbp)
jmp 0x1050f0
movq -0x130(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x105118
jmp 0x105293
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x105473
movq -0x20(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x140(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x30a70
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x44470
jmp 0x105150
leaq 0xdd154(%rip), %rsi     # 0x1e22ab
leaq -0x80(%rbp), %rdi
xorl %edx, %edx
callq 0x43f20
jmp 0x105164
leaq -0x68(%rbp), %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
callq 0x9c920
movb %al, -0x141(%rbp)
jmp 0x10517b
leaq -0x80(%rbp), %rdi
callq 0x441d0
leaq -0x68(%rbp), %rdi
callq 0x311e8
leaq -0x69(%rbp), %rdi
callq 0x311c0
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0x1051a5
jmp 0x10528e
movq -0x20(%rbp), %rax
addq $0x13, %rax
movq %rax, -0x158(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x30a70
movq -0x158(%rbp), %rsi
movq -0x150(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x44470
jmp 0x1051e3
leaq -0x38(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xb39c0
jmp 0x1051f5
leaq -0xa0(%rbp), %rdi
callq 0x311e8
leaq -0xa1(%rbp), %rdi
callq 0x311c0
jmp 0x10528e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x105249
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x105240
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x441d0
leaq -0x68(%rbp), %rdi
callq 0x311e8
leaq -0x69(%rbp), %rdi
callq 0x311c0
jmp 0x105473
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x10527d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x311e8
leaq -0xa1(%rbp), %rdi
callq 0x311c0
jmp 0x105473
jmp 0x1050d1
movq -0x18(%rbp), %rdi
callq 0x2ff00
jmp 0x10529e
jmp 0x105308
movq 0x1cfca9(%rip), %rdi    # 0x2d4f50
leaq 0xdd030(%rip), %rsi     # 0x1e22de
callq 0x2ff50
movq %rax, -0x160(%rbp)
jmp 0x1052bc
movq -0x160(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2ff50
movq %rax, -0x168(%rbp)
jmp 0x1052d5
movq -0x168(%rbp), %rdi
leaq 0xdd013(%rip), %rsi     # 0x1e22f6
callq 0x2ff50
movq %rax, -0x170(%rbp)
jmp 0x1052f1
movq -0x170(%rbp), %rdi
movq 0x1cfcc9(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x105306
jmp 0x105308
leaq -0x38(%rbp), %rdi
callq 0x458f0
movq %rax, -0xb0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x45920
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x45860
testb $0x1, %al
jne 0x105344
jmp 0x105461
movq -0x10(%rbp), %rax
movq %rax, -0x180(%rbp)
leaq -0x119(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x30a70
movq -0x180(%rbp), %rsi
movq -0x178(%rbp), %rdx
leaq -0x118(%rbp), %rdi
callq 0x44470
jmp 0x10537e
leaq 0xdcfce(%rip), %rdx     # 0x1e2353
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x441f0
jmp 0x10539a
leaq -0xb0(%rbp), %rdi
callq 0x8aed0
movq %rax, %rdx
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x44760
jmp 0x1053be
leaq -0xf8(%rbp), %rdi
callq 0x311e8
leaq -0x118(%rbp), %rdi
callq 0x311e8
leaq -0x119(%rbp), %rdi
callq 0x311c0
leaq -0xd8(%rbp), %rdi
callq 0x2f290
movq %rax, %rdi
callq 0x2f510
leaq -0xd8(%rbp), %rdi
callq 0x311e8
leaq -0xb0(%rbp), %rdi
callq 0x8aef0
jmp 0x105318
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x105453
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x105447
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x311e8
leaq -0x118(%rbp), %rdi
callq 0x311e8
leaq -0x119(%rbp), %rdi
callq 0x311c0
jmp 0x105473
leaq -0x38(%rbp), %rdi
callq 0x448d0
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x448d0
movq -0x40(%rbp), %rdi
callq 0x30170
nopw %cs:(%rax,%rax)