// File: /workspace/github_cpp_makefile_star2_O3/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 0x468c
leal -0x5(%rbx), %eax
cmpl $-0x3, %eax
jbe 0x4015
cmpl $0x4, %ebx
jne 0x381f
movq 0x8(%r14), %rsi
leaq 0x168(%rsp), %rdi
leaq 0x188(%rsp), %rdx
callq 0x422e
movq 0x18(%r14), %rsi
leaq 0x148(%rsp), %rdi
leaq 0x390(%rsp), %rdx
callq 0x422e
leaq 0x5e0(%rsp), %rdi
leaq 0x168(%rsp), %rsi
leaq 0x148(%rsp), %rdx
callq 0x4778
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 0x422e
leaq 0x5e0(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x49fe
leaq 0x138(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3fe7
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x3fe7
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 0x422e
leaq 0x5e0(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x4b3e
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 0x6a04(%rip), %rsi      # 0xa35f
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 0x422e
leaq 0x88(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x6706(%rip), %rsi      # 0xa0a1
leaq 0x6705(%rip), %rdx      # 0xa0a7
leaq 0x78(%rsp), %rdi
callq 0x43c2
leaq 0xc8(%rsp), %r15
movq -0x10(%r15), %rcx
movq -0x8(%r15), %r8
movq 0x80(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
cmpq %r15, %rcx
je 0x39da
movq 0xc8(%rsp), %rdi
movq 0x78(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x39fb
movl $0xf, %edi
cmpq %r14, %rsi
je 0x39f6
movq 0x88(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x3a0a
leaq 0xb8(%rsp), %rdi
callq 0x30e0
jmp 0x3a18
leaq 0x78(%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 0x3a3c
movq %rsi, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x3a42
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 0x3a91
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0x3aab
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x3ac8
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0xa8(%rsp), %r12
leaq 0x38(%rsp), %r15
cmpl $0x0, 0x10(%rsp)
jle 0x3f86
leaq 0xd8(%rsp), %rdi
callq 0x4458
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 0x432c
movl 0x10(%rsp), %edx
leaq 0x5e0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x4c98
movl %eax, 0xc(%rsp)
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0x3bb9
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x3c03
movl 0xc(%rsp), %eax
movq %r13, %r8
movq %r8, %rcx
movq %rdi, %rdx
movl 0x20(%rdi), %esi
xorl %edi, %edi
cmpl %eax, %esi
setl %dil
movq %rdx, %r8
cmovlq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x3bcd
cmpq %r13, %r8
je 0x3c03
cmpl %eax, %esi
cmovlq %rcx, %rdx
cmpl 0x20(%rdx), %eax
jge 0x3f6c
leaq 0xd8(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x426c
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 0x3e35
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 0x3da1
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x432c
movl 0x10(%rsp), %edx
leaq 0x5e0(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x4c98
movl %eax, 0xc(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x3d3e
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x3d88
movl 0xc(%rsp), %eax
movq %r13, %r8
movq %r8, %rcx
movq %rdi, %rdx
movl 0x20(%rdi), %esi
xorl %edi, %edi
cmpl %eax, %esi
setl %dil
movq %rdx, %r8
cmovlq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x3d52
cmpq %r13, %r8
je 0x3d88
cmpl %eax, %esi
cmovlq %rcx, %rdx
cmpl 0x20(%rdx), %eax
jge 0x3e1b
leaq 0xd8(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x426c
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 0x3c91
leaq 0xd8(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x426c
incq (%rax)
jmp 0x3da1
movl $0x9, %edx
movq 0xa187(%rip), %rdi      # 0xdfc8
leaq 0x6260(%rip), %rsi      # 0xa0a8
callq 0x32e0
movl 0x10(%rsp), %esi
movq 0xa170(%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 0x620d(%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 0x3f56
movl 0x20(%r14), %esi
leaq 0x390(%rsp), %rdi
callq 0x3450
movq %rax, %rbp
movl $0x2, %edx
movq %rax, %rdi
leaq 0x64c2(%rip), %rsi      # 0xa3cd
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 0x3ee8
movq 0xa07b(%rip), %rdi      # 0xdfd8
leaq 0x10(%rsp), %rsi
callq 0x3180
jmp 0x3ad5
leaq 0xd8(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x426c
incq (%rax)
jmp 0x3c1c
movq 0xa033(%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 0x3fda
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x188(%rsp), %rdi
callq 0x30c0
leaq 0x5e0(%rsp), %rdi
callq 0x4708
leaq 0xd8(%rsp), %rdi
callq 0x42dc
xorl %eax, %eax
addq $0x8a8, %rsp            # imm = 0x8A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9fd4(%rip), %rdi      # 0xdff0
leaq 0x5fe1(%rip), %rsi      # 0xa004
movl $0x38, %edx
callq 0x32e0
movq 0x9fbc(%rip), %rdi      # 0xdff0
callq 0x3130
movq 0x9fb0(%rip), %rdi      # 0xdff0
leaq 0x5ff6(%rip), %rsi      # 0xa03d
movl $0x32, %edx
callq 0x32e0
movq 0x9f98(%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 0x408a
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x408a
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0x40a9
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x40a9
movq %rax, %rbx
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x41d6
movq 0xc8(%rsp), %rsi
jmp 0x41c5
jmp 0x41d3
movq %rax, %rbx
jmp 0x41e3
movq %rax, %rbx
jmp 0x41ff
jmp 0x418f
jmp 0x418f
movq %rax, %rbx
leaq 0x118(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x420c
movq 0x118(%rsp), %rsi
jmp 0x4178
movq %rax, %rbx
leaq 0x138(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x420c
movq 0x138(%rsp), %rsi
jmp 0x4178
jmp 0x418f
jmp 0x418f
movq %rax, %rbx
leaq 0x158(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x415b
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x415b
movq %rax, %rbx
leaq 0x178(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x420c
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x420c
jmp 0x418f
movq %rax, %rbx
jmp 0x4219
movq %rax, %rbx
jmp 0x420c
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r12, %rdi
je 0x41d6
movq 0xa8(%rsp), %rsi
jmp 0x41c5
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x41d6
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x41d6
jmp 0x41d3
jmp 0x41d3
movq %rax, %rbx
leaq 0x390(%rsp), %rdi
callq 0x33c0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x41ff
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x188(%rsp), %rdi
callq 0x30c0
leaq 0x5e0(%rsp), %rdi
callq 0x4708
leaq 0xd8(%rsp), %rdi
callq 0x42dc
movq %rbx, %rdi
callq 0x3480