// File: /workspace/github_cpp_makefile_star2_O2/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 0x20(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x5e0(%rsp), %rdi
callq 0x41c4
leal -0x5(%rbx), %eax
cmpl $-0x3, %eax
jbe 0x3bc5
cmpl $0x4, %ebx
jne 0x3777
movq 0x8(%r14), %rsi
leaq 0x128(%rsp), %rdi
leaq 0x188(%rsp), %rdx
callq 0x3d08
movq 0x18(%r14), %rsi
leaq 0x108(%rsp), %rdi
leaq 0x390(%rsp), %rdx
callq 0x3d08
leaq 0x5e0(%rsp), %rdi
leaq 0x128(%rsp), %rsi
leaq 0x108(%rsp), %rdx
callq 0x4282
leaq 0x108(%rsp), %rdi
callq 0x3110
leaq 0x128(%rsp), %rdi
callq 0x3110
movq 0x10(%r14), %rsi
leaq 0xe8(%rsp), %rdi
leaq 0x188(%rsp), %rdx
callq 0x3d08
leaq 0x5e0(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x4474
leaq 0xe8(%rsp), %rdi
callq 0x3110
jmp 0x3b9a
movq 0xa84a(%rip), %rdi      # 0xdfc8
leaq 0x58eb(%rip), %rsi      # 0x9070
callq 0x3230
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x3230
leaq 0x58e1(%rip), %rsi      # 0x907e
movq %rax, %rdi
callq 0x3230
movq 0x8(%r14), %rsi
leaq 0xc8(%rsp), %rdi
leaq 0x188(%rsp), %rdx
callq 0x3d08
leaq 0x5e0(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x4522
leaq 0xc8(%rsp), %rdi
callq 0x3110
movq 0xa7e1(%rip), %rdi      # 0xdfc8
leaq 0x589f(%rip), %rsi      # 0x908d
callq 0x3230
movq 0xa7de(%rip), %rdi      # 0xdfd8
leaq 0xc(%rsp), %rsi
callq 0x3160
leaq 0x188(%rsp), %rdi
callq 0x3280
movq 0x10(%r14), %rsi
leaq 0x188(%rsp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x3170
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x10(%r14), %rsi
leaq 0x590(%rsp), %r14
movq %r14, %rdi
callq 0x3220
leaq 0x5ad8(%rip), %rsi      # 0x932f
movq %r14, %rdi
callq 0x33b0
movq %rax, %r14
leaq 0x390(%rsp), %rdi
callq 0x3420
leaq 0x68(%rsp), %rdi
leaq 0x13(%rsp), %rdx
movq %r14, %rsi
callq 0x3d08
leaq 0x5819(%rip), %rsi      # 0x90a1
leaq 0x48(%rsp), %rdi
leaq 0x12(%rsp), %rdx
callq 0x3d08
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x3d43
movq 0x88(%rsp), %rsi
leaq 0x390(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x3040
leaq 0x88(%rsp), %rdi
callq 0x3110
leaq 0x48(%rsp), %rdi
callq 0x3110
leaq 0x68(%rsp), %rdi
callq 0x3110
leaq 0x18(%rsp), %r12
leaq 0xa8(%rsp), %r15
leaq 0x14(%rsp), %rbp
cmpl $0x0, 0xc(%rsp)
jle 0x3b73
movq %r12, %rdi
callq 0x3ef2
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x3410
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3350
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
leaq 0x168(%rsp), %rdi
movq %r15, %rsi
callq 0x3360
movl 0xc(%rsp), %edx
leaq 0x5e0(%rsp), %rdi
leaq 0x168(%rsp), %r14
movq %r14, %rsi
callq 0x4652
movl %eax, 0x14(%rsp)
movq %r14, %rdi
callq 0x3110
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3f20
leaq 0x20(%rsp), %rcx
cmpq %rcx, %rax
leaq 0x390(%rsp), %r14
je 0x39ad
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3daa
pushq $0x4e
popq %r13
incq (%rax)
jmp 0x39c3
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3daa
pushq $0x4e
popq %r13
movq $0x1, (%rax)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x1a8(%rsp,%rax)
jne 0x3ac1
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
movq %r15, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x3320
cmpq $-0x1, %rax
jne 0x3a9b
leaq 0x148(%rsp), %rdi
movq %r15, %rsi
callq 0x3360
movl 0xc(%rsp), %edx
leaq 0x5e0(%rsp), %rdi
leaq 0x148(%rsp), %r14
movq %r14, %rsi
callq 0x4652
movl %eax, 0x14(%rsp)
movq %r14, %rdi
callq 0x3110
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3f20
leaq 0x20(%rsp), %rcx
cmpq %rcx, %rax
je 0x3a81
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3daa
leaq 0x390(%rsp), %r14
incq (%rax)
jmp 0x3a9b
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3daa
leaq 0x390(%rsp), %r14
movq $0x1, (%rax)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
jmp 0x39e4
movq 0xa500(%rip), %rdi      # 0xdfc8
leaq 0x55d9(%rip), %rsi      # 0x90a8
callq 0x3230
movl 0xc(%rsp), %esi
movq %rax, %rdi
callq 0x3430
movq %rax, %rdi
callq 0x3120
movq %r14, %rdi
leaq 0x55b6(%rip), %rsi      # 0x90a8
callq 0x3230
movl 0xc(%rsp), %esi
movq %rax, %rdi
callq 0x3430
movq %rax, %rdi
callq 0x3120
movq 0x30(%rsp), %r12
leaq 0x20(%rsp), %rax
cmpq %rax, %r12
je 0x3b58
movl 0x20(%r12), %esi
movq %r14, %rdi
callq 0x3430
movq %rax, %rdi
leaq 0x586c(%rip), %rsi      # 0x939d
callq 0x3230
movq 0x28(%r12), %rsi
movq %rax, %rdi
callq 0x3190
movq %rax, %rdi
callq 0x3120
movq %r12, %rdi
callq 0x31b0
movq %rax, %r12
jmp 0x3b10
movq 0xa479(%rip), %rdi      # 0xdfd8
leaq 0xc(%rsp), %rsi
callq 0x3160
leaq 0x18(%rsp), %r12
jmp 0x38f9
leaq 0x390(%rsp), %rdi
callq 0x3390
leaq 0xa8(%rsp), %rdi
callq 0x3110
leaq 0x188(%rsp), %rdi
callq 0x30c0
leaq 0x5e0(%rsp), %rdi
callq 0x4244
leaq 0x18(%rsp), %rdi
callq 0x3e04
xorl %eax, %eax
addq $0x8a8, %rsp            # imm = 0x8A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa424(%rip), %rdi      # 0xdff0
leaq 0x5431(%rip), %rsi      # 0x9004
callq 0x3230
movq %rax, %rdi
callq 0x3120
movq 0xa409(%rip), %rdi      # 0xdff0
leaq 0x544f(%rip), %rsi      # 0x903d
callq 0x3230
movq %rax, %rdi
callq 0x3120
pushq $0x1
popq %rdi
callq 0x32b0
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3110
jmp 0x3c18
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3110
jmp 0x3c27
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x3cb4
jmp 0x3cbf
movq %rax, %rbx
jmp 0x3ccf
movq %rax, %rbx
jmp 0x3cdc
jmp 0x3c93
jmp 0x3c93
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x3c85
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x3c85
jmp 0x3c93
jmp 0x3c93
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3110
jmp 0x3c7d
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x3110
jmp 0x3ce9
jmp 0x3c93
movq %rax, %rbx
jmp 0x3cf6
movq %rax, %rbx
jmp 0x3ce9
movq %rax, %rbx
leaq 0x168(%rsp), %rdi
jmp 0x3cb4
jmp 0x3cbf
jmp 0x3cbf
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x3110
jmp 0x3cc2
jmp 0x3cbf
jmp 0x3cbf
movq %rax, %rbx
leaq 0x390(%rsp), %rdi
callq 0x3390
leaq 0xa8(%rsp), %rdi
callq 0x3110
leaq 0x188(%rsp), %rdi
callq 0x30c0
leaq 0x5e0(%rsp), %rdi
callq 0x4244
leaq 0x18(%rsp), %rdi
callq 0x3e04
movq %rbx, %rdi
callq 0x3460