// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]optimal-seed-solver/testSpacedSeedSolver.cc
// Function: main
int main(int argc, const char* argv[]) {
	int frequency;
	map <int, unsigned long long> frequencyCounter;

	SpacedSeedSolver solver;

	if (argc != 3 && argc != 4) {
		cerr << "USAGE: ./testOptimalSolver <Ref File> <TableFile> <Mask>" << endl;
		cerr << "USAGE: ./testOptimalSolver <TableFile> <Read File>" << endl;
		exit(1);
	}

	if (argc == 4) {
		solver.generateHash(argv[1], argv[3]);
		solver.storeHash(argv[2]);
			
		return 0;
	}

	cout << "Loading tree " << argv[1] << " into memory.\n";
	solver.loadHash(argv[1]);
	cout << "Finished loading. \n";

	int seedNum;
	//cout << "Please input number of seeds: ";
	cin >> seedNum;

	//int seedLength;

	ifstream readFile;
	readFile.open(argv[2]);
	string read;
	
	char benchFileName[80];
	strcpy(benchFileName, argv[2]);
	char* benchName = strtok(benchFileName, ".");
	
	ofstream output;
	output.open( (string(benchName) + string(".space") ).c_str() );

	while (seedNum > 0) {	
		//cout << "Please input seed length: ";
		//cin >> seedLength;
		
		frequencyCounter.clear();

		//Start reading the file
		readFile.clear();
		readFile.seekg(0, ios::beg);

		//Name
		getline(readFile, read);
		//Read
		getline(readFile, read);
		//cout << "DNA: " << read << endl;

		//Solve
		frequency = solver.solveDNA(read, seedNum);
		if (frequencyCounter.find(frequency) == frequencyCounter.end() )
			frequencyCounter[frequency] = 1;
		else
			frequencyCounter[frequency]++;

		//Trash
		getline(readFile, read);
		getline(readFile, read);
			
		//Name
		getline(readFile, read);

		while (!readFile.eof()) {
			//Read
			getline(readFile, read);
			//cout << "DNA: " << read << endl;

			//Solve
			if (read.find('N') == string::npos) {
				frequency = solver.solveDNA(read, seedNum);
				if (frequencyCounter.find(frequency) == frequencyCounter.end() )
					frequencyCounter[frequency] = 1;
				else
					frequencyCounter[frequency]++;
			}

			//Trash
			getline(readFile, read);
			getline(readFile, read);
			
			//Name
			getline(readFile, read);
		}

		cout << "seedNum: " << seedNum << endl;
		output << "seedNum: " << seedNum << endl;
		for (map<int, unsigned long long>::iterator iter = frequencyCounter.begin(); iter != frequencyCounter.end(); iter++)
			output << iter->first << ": " << iter->second << endl;

		cin >> seedNum;
	}
	
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8a8, %rsp            # imm = 0x8A8
movq %rsi, %r14
movl %edi, %ebx
leaq 0xe0(%rsp), %r13
movl $0x0, (%r13)
xorl %eax, %eax
movq %rax, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq %rax, 0x20(%r13)
leaq 0x5e0(%rsp), %rdi
callq 0x467c
leal -0x5(%rbx), %eax
cmpl $-0x3, %eax
jbe 0x400c
cmpl $0x4, %ebx
jne 0x381f
movq 0x8(%r14), %rsi
leaq 0x168(%rsp), %rdi
leaq 0x188(%rsp), %rdx
callq 0x4228
movq 0x18(%r14), %rsi
leaq 0x148(%rsp), %rdi
leaq 0x390(%rsp), %rdx
callq 0x4228
leaq 0x5e0(%rsp), %rdi
leaq 0x168(%rsp), %rsi
leaq 0x148(%rsp), %rdx
callq 0x4768
leaq 0x158(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37a6
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x178(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37c7
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%r14), %rsi
leaq 0x128(%rsp), %rdi
leaq 0x188(%rsp), %rdx
callq 0x4228
leaq 0x5e0(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x49e4
leaq 0x138(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3fde
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x3fde
movq 0xa7a2(%rip), %rbx      # 0xdfc8
leaq 0x6843(%rip), %rsi      # 0xa070
movl $0xd, %edx
movq %rbx, %rdi
callq 0x32e0
movq 0x8(%r14), %r15
testq %r15, %r15
je 0x385f
movq %r15, %rdi
callq 0x3120
movq 0xa776(%rip), %rdi      # 0xdfc8
movq %r15, %rsi
movq %rax, %rdx
callq 0x32e0
jmp 0x3876
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x3430
movq 0xa74b(%rip), %rdi      # 0xdfc8
leaq 0x67fa(%rip), %rsi      # 0xa07e
movl $0xe, %edx
callq 0x32e0
movq 0x8(%r14), %rsi
leaq 0x108(%rsp), %rdi
leaq 0x188(%rsp), %rdx
callq 0x4228
leaq 0x5e0(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x4b24
leaq 0x118(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38dd
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xa6e4(%rip), %rdi      # 0xdfc8
leaq 0x67a2(%rip), %rsi      # 0xa08d
movl $0x13, %edx
callq 0x32e0
movq 0xa6dc(%rip), %rdi      # 0xdfd8
leaq 0x10(%rsp), %rsi
callq 0x3180
leaq 0x188(%rsp), %rdi
callq 0x32d0
movq 0x10(%r14), %rsi
leaq 0x188(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x3190
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x10(%r14), %rsi
leaq 0x590(%rsp), %r14
movq %r14, %rdi
callq 0x3250
leaq 0x6a14(%rip), %rsi      # 0xa36f
movq %r14, %rdi
callq 0x33e0
movq %rax, %r14
leaq 0x390(%rsp), %rdi
callq 0x3440
leaq 0xb8(%rsp), %rdi
leaq 0x17(%rsp), %rdx
movq %r14, %rsi
callq 0x4228
leaq 0x68(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x6709(%rip), %rsi      # 0xa0a1
leaq 0x6708(%rip), %rdx      # 0xa0a7
leaq 0x58(%rsp), %rdi
callq 0x43b6
leaq 0xc8(%rsp), %r15
movq -0x10(%r15), %rcx
movq -0x8(%r15), %r8
movq 0x60(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r15, %rcx
je 0x39d4
movq 0xc8(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x39ef
movl $0xf, %esi
cmpq %r14, 0x58(%rsp)
je 0x39ea
movq 0x68(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x3a03
movq 0x58(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x30e0
jmp 0x3a11
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32c0
leaq 0x28(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x3a35
movq %rsi, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x3a3b
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x20(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x18(%rsp), %rsi
leaq 0x390(%rsp), %rdi
movl $0x10, %edx
callq 0x3050
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3a8a
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x3aa1
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x3abe
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0xa8(%rsp), %r12
leaq 0x38(%rsp), %r15
cmpl $0x0, 0x10(%rsp)
jle 0x3f7d
leaq 0xd8(%rsp), %rdi
callq 0x4446
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x3430
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3390
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x34a0
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x34a0
movq %r12, 0x98(%rsp)
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x4326
movl 0x10(%rsp), %edx
leaq 0x5e0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x4c7e
movl %eax, 0xc(%rsp)
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0x3baf
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xe8(%rsp), %rcx
movq %r13, %rax
testq %rcx, %rcx
je 0x3bdd
movl 0xc(%rsp), %edx
movq %r13, %rax
xorl %esi, %esi
cmpl %edx, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x3bc6
movq %r13, %rcx
cmpq %r13, %rax
je 0x3bf3
movl 0xc(%rsp), %ecx
cmpl 0x20(%rax), %ecx
cmovlq %r13, %rax
movq %rax, %rcx
cmpq %r13, %rcx
je 0x3c0f
leaq 0xd8(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x4266
incq (%rax)
jmp 0x3c28
leaq 0xd8(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x4266
movq $0x1, (%rax)
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x34a0
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x34a0
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x34a0
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x1a8(%rsp,%rax)
jne 0x3e46
leaq (%rsp,%rax), %rdi
addq $0x188, %rdi            # imm = 0x188
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x34a0
movq %r15, %rdi
movl $0x4e, %esi
xorl %edx, %edx
callq 0x3360
cmpq $-0x1, %rax
jne 0x3dcc
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x4326
movl 0x10(%rsp), %edx
leaq 0x5e0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x4c7e
movl %eax, 0xc(%rsp)
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x3d53
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xe8(%rsp), %rcx
movq %r13, %rax
testq %rcx, %rcx
je 0x3d81
movl 0xc(%rsp), %edx
movq %r13, %rax
xorl %esi, %esi
cmpl %edx, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x3d6a
movq %r13, %rcx
cmpq %r13, %rax
je 0x3d97
movl 0xc(%rsp), %ecx
cmpl 0x20(%rax), %ecx
cmovlq %r13, %rax
movq %rax, %rcx
cmpq %r13, %rcx
je 0x3db3
leaq 0xd8(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x4266
incq (%rax)
jmp 0x3dcc
leaq 0xd8(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x4266
movq $0x1, (%rax)
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x34a0
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x34a0
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x34a0
jmp 0x3c9d
movl $0x9, %edx
movq 0xa176(%rip), %rdi      # 0xdfc8
leaq 0x624f(%rip), %rsi      # 0xa0a8
callq 0x32e0
movl 0x10(%rsp), %esi
movq 0xa15f(%rip), %rdi      # 0xdfc8
callq 0x3450
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movl $0x9, %edx
leaq 0x390(%rsp), %rdi
leaq 0x61fc(%rip), %rsi      # 0xa0a8
callq 0x32e0
movl 0x10(%rsp), %esi
leaq 0x390(%rsp), %rdi
callq 0x3450
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq 0xf0(%rsp), %r14
cmpq %r13, %r14
je 0x3f67
movl 0x20(%r14), %esi
leaq 0x390(%rsp), %rdi
callq 0x3450
movq %rax, %rbp
movl $0x2, %edx
movq %rax, %rdi
leaq 0x64c1(%rip), %rsi      # 0xa3dd
callq 0x32e0
movq 0x28(%r14), %rsi
movq %rbp, %rdi
callq 0x31b0
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq %r14, %rdi
callq 0x31e0
movq %rax, %r14
cmpq %r13, %rax
jne 0x3ef9
movq 0xa06a(%rip), %rdi      # 0xdfd8
leaq 0x10(%rsp), %rsi
callq 0x3180
jmp 0x3acb
movq 0xa03c(%rip), %rax      # 0xdfc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x398(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x390(%rsp,%rcx)
callq 0x3220
leaq 0x488(%rsp), %rdi
callq 0x30f0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x3fd1
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x188(%rsp), %rdi
callq 0x30c0
leaq 0x5e0(%rsp), %rdi
callq 0x46f8
leaq 0xd8(%rsp), %rdi
callq 0x42d6
xorl %eax, %eax
addq $0x8a8, %rsp            # imm = 0x8A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9fdd(%rip), %rdi      # 0xdff0
leaq 0x5fea(%rip), %rsi      # 0xa004
movl $0x38, %edx
callq 0x32e0
movq 0x9fc5(%rip), %rdi      # 0xdff0
callq 0x3130
movq 0x9fb9(%rip), %rdi      # 0xdff0
leaq 0x5fff(%rip), %rsi      # 0xa03d
movl $0x32, %edx
callq 0x32e0
movq 0x9fa1(%rip), %rdi      # 0xdff0
callq 0x3130
movl $0x1, %edi
callq 0x3300
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4081
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4081
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x409d
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x409d
movq %rax, %rbx
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x41d0
movq 0xc8(%rsp), %rsi
jmp 0x41bf
jmp 0x41cd
movq %rax, %rbx
jmp 0x41dd
movq %rax, %rbx
jmp 0x41f9
jmp 0x4183
jmp 0x4183
movq %rax, %rbx
leaq 0x118(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4206
movq 0x118(%rsp), %rsi
jmp 0x416c
movq %rax, %rbx
leaq 0x138(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4206
movq 0x138(%rsp), %rsi
jmp 0x416c
jmp 0x4183
jmp 0x4183
movq %rax, %rbx
leaq 0x158(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x414f
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x414f
movq %rax, %rbx
leaq 0x178(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4206
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4206
jmp 0x4183
movq %rax, %rbx
jmp 0x4213
movq %rax, %rbx
jmp 0x4206
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0x41d0
movq 0xa8(%rsp), %rsi
jmp 0x41bf
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x41d0
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x41d0
jmp 0x41cd
jmp 0x41cd
movq %rax, %rbx
leaq 0x390(%rsp), %rdi
callq 0x33c0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x41f9
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x188(%rsp), %rdi
callq 0x30c0
leaq 0x5e0(%rsp), %rdi
callq 0x46f8
leaq 0xd8(%rsp), %rdi
callq 0x42d6
movq %rbx, %rdi
callq 0x3480