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

	OptimalSolver solver;

	if (argc == 3) {
		cout << "Loading tree " << argv[1] << " into memory.\n";
		solver.loadTree(argv[1]);
		cout << "Finished loading. \n";

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

		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(".hobbes") ).c_str() );

		while (seedNum > 0) {
			frequencyCounter.clear();

			readFile.clear();
			readFile.seekg(0, ios::beg);

			//Name
			getline(readFile, read);
			//Read
			getline(readFile, read);
			solver.init(read.length(), seedNum);
			//		cout << "DNA: " << read << endl;

			//Solve
			frequency = solver.solveDNA(read);
			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);
					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<unsigned int, unsigned long long>::iterator iter = frequencyCounter.begin(); iter != frequencyCounter.end(); iter++)
				output << iter->first << ": " << iter->second << endl;

			cin >> seedNum;
		}


	}
	else if (argc == 1) {
		cout << "input seedNum and readLength: " << endl;
		int seedNum;
		int readLength;
		cin >> seedNum;
		string dummy = "";
		while (seedNum > 0) {
			cin >> readLength;
			solver.init(readLength, seedNum);
			solver.feedL0();
			solver.solveDNA(dummy);
			cin >> seedNum;
		}
	}
	else
	{
		cerr << "USAGE: ./testOptimalSolver <Tree File> <Read File>" << endl;
		exit(1);
	}

//	cout << "Loading tree " << argv[1] << " into memory.\n";
//	solver.loadTree(argv[1]);
//	cout << "Finished loading. \n";
//
//	int seedNum;
//	unsigned int frequency;
//	//cout << "Please input number of seeds: ";
//	cin >> seedNum;
//
//	ifstream readFile;
//	readFile.open(argv[2]);
//	string read;
//
//	while (seedNum > 0) {
//		frequencyCounter.clear();
//
//		readFile.clear();
//		readFile.seekg(0, ios::beg);
//
//		//Name
//		getline(readFile, read);
//		//Read
//		getline(readFile, read);
//		solver.init(read.length(), seedNum);
//		//		cout << "DNA: " << read << endl;
//
//		//Solve
//		frequency = solver.solveDNA(read);
//		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);
//				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;
//		for (map<unsigned int, unsigned long long>::iterator iter = frequencyCounter.begin(); iter != frequencyCounter.end(); iter++)
//			cout << iter->first << ": " << iter->second << endl;
//
//		cin >> seedNum;
//	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x938, %rsp            # imm = 0x938
movq %rsi, %r14
movl %edi, %ebx
leaq 0x38(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x5a0(%rsp), %rdi
callq 0x41b4
cmpl $0x1, %ebx
je 0x3aaf
cmpl $0x3, %ebx
jne 0x3be2
movq 0xb906(%rip), %rdi      # 0xefc8
leaq 0x693b(%rip), %rsi      # 0xa004
callq 0x3230
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x3230
leaq 0x6931(%rip), %rsi      # 0xa012
movq %rax, %rdi
callq 0x3230
movq 0x8(%r14), %rsi
leaq 0xc0(%rsp), %rdi
leaq 0x198(%rsp), %rdx
callq 0x3cfa
leaq 0x5a0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x425c
leaq 0xc0(%rsp), %rdi
callq 0x3110
movq 0xb89d(%rip), %rdi      # 0xefc8
leaq 0x68ef(%rip), %rsi      # 0xa021
callq 0x3230
movq 0xb89a(%rip), %rdi      # 0xefd8
leaq 0x8(%rsp), %rsi
callq 0x3150
leaq 0x198(%rsp), %rdi
callq 0x3280
movq 0x10(%r14), %rsi
leaq 0x198(%rsp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x3160
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x10(%r14), %rsi
leaq 0x140(%rsp), %r14
movq %r14, %rdi
callq 0x3220
leaq 0x6ee7(%rip), %rsi      # 0xa67f
movq %r14, %rdi
callq 0x33a0
movq %rax, %r14
leaq 0x3a0(%rsp), %rdi
callq 0x3410
leaq 0x80(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %r14, %rsi
callq 0x3cfa
leaq 0x6869(%rip), %rsi      # 0xa035
leaq 0x60(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x3cfa
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x3d35
movq 0xa0(%rsp), %rsi
leaq 0x3a0(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x3040
leaq 0xa0(%rsp), %rdi
callq 0x3110
leaq 0x60(%rsp), %rdi
callq 0x3110
leaq 0x80(%rsp), %rdi
callq 0x3110
leaq 0x30(%rsp), %r13
leaq 0x10(%rsp), %r15
leaq 0x120(%rsp), %r12
leaq 0x3a0(%rsp), %rbp
cmpl $0x0, 0x8(%rsp)
jle 0x3b93
movq %r13, %rdi
callq 0x3ee4
movq 0x198(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x3400
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3340
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
movl 0x18(%rsp), %esi
movl 0x8(%rsp), %edx
leaq 0x5a0(%rsp), %rdi
callq 0x42f0
leaq 0xe0(%rsp), %rdi
movq %r15, %rsi
callq 0x3350
leaq 0x5a0(%rsp), %rdi
leaq 0xe0(%rsp), %r14
movq %r14, %rsi
callq 0x46f8
movl %eax, 0x4(%rsp)
movq %r14, %rdi
callq 0x3110
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3f12
leaq 0x38(%rsp), %rcx
cmpq %rcx, %rax
je 0x3908
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3d9c
incq (%rax)
jmp 0x391c
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3d9c
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 0x198(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x1b8(%rsp,%rax)
jne 0x39ff
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3080
movq %r15, %rdi
pushq $0x4e
popq %rsi
xorl %edx, %edx
callq 0x3310
cmpq $-0x1, %rax
jne 0x39d9
movq %r12, %rdi
movq %r15, %rsi
callq 0x3350
leaq 0x5a0(%rsp), %rdi
movq %r12, %rsi
callq 0x46f8
movl %eax, 0x4(%rsp)
movq %r12, %rdi
callq 0x3110
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3f12
leaq 0x38(%rsp), %rcx
cmpq %rcx, %rax
je 0x39c5
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3d9c
incq (%rax)
jmp 0x39d9
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3d9c
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 0x393d
movq 0xb5c2(%rip), %rdi      # 0xefc8
leaq 0x6630(%rip), %rsi      # 0xa03d
callq 0x3230
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x3420
movq %rax, %rdi
callq 0x3120
movq %rbp, %rdi
leaq 0x660d(%rip), %rsi      # 0xa03d
callq 0x3230
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x3420
movq %rax, %rdi
callq 0x3120
movq 0x48(%rsp), %r13
leaq 0x38(%rsp), %rax
cmpq %rax, %r13
je 0x3a94
movl 0x20(%r13), %esi
movq %rbp, %rdi
callq 0x3190
movq %rax, %rdi
leaq 0x6c7f(%rip), %rsi      # 0xa6ed
callq 0x3230
movq 0x28(%r13), %rsi
movq %rax, %rdi
callq 0x3180
movq %rax, %rdi
callq 0x3120
movq %r13, %rdi
callq 0x31a0
movq %rax, %r13
jmp 0x3a4e
movq 0xb53d(%rip), %rdi      # 0xefd8
leaq 0x8(%rsp), %rsi
callq 0x3150
leaq 0x30(%rsp), %r13
jmp 0x384b
movq 0xb512(%rip), %rdi      # 0xefc8
leaq 0x658a(%rip), %rsi      # 0xa047
callq 0x3230
movq %rax, %rdi
callq 0x3120
movq 0xb507(%rip), %rdi      # 0xefd8
leaq 0x3a0(%rsp), %rsi
callq 0x3150
leaq 0x6b16(%rip), %rsi      # 0xa5fb
leaq 0x198(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x3cfa
movq 0xb4da(%rip), %rbx      # 0xefd8
leaq 0x140(%rsp), %r14
leaq 0x5a0(%rsp), %r15
leaq 0x100(%rsp), %r12
leaq 0x198(%rsp), %r13
leaq 0x3a0(%rsp), %rbp
cmpl $0x0, 0x3a0(%rsp)
jle 0x3b84
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3150
movl 0x140(%rsp), %esi
movl 0x3a0(%rsp), %edx
movq %r15, %rdi
callq 0x42f0
movq %r15, %rdi
callq 0x45d8
movq %r12, %rdi
movq %r13, %rsi
callq 0x3350
movq %r15, %rdi
movq %r12, %rsi
callq 0x46f8
movq %r12, %rdi
callq 0x3110
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3150
jmp 0x3b26
leaq 0x198(%rsp), %rdi
callq 0x3110
jmp 0x3bb7
leaq 0x3a0(%rsp), %rdi
callq 0x3380
leaq 0x10(%rsp), %rdi
callq 0x3110
leaq 0x198(%rsp), %rdi
callq 0x30c0
leaq 0x5a0(%rsp), %rdi
callq 0x41ec
leaq 0x30(%rsp), %rdi
callq 0x3df6
xorl %eax, %eax
addq $0x938, %rsp            # imm = 0x938
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb407(%rip), %rdi      # 0xeff0
leaq 0x6476(%rip), %rsi      # 0xa066
callq 0x3230
movq %rax, %rdi
callq 0x3120
pushq $0x1
popq %rdi
callq 0x32b0
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x3110
jmp 0x3c1a
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x3110
jmp 0x3c29
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x3ca9
jmp 0x3cb4
movq %rax, %rbx
jmp 0x3cc4
movq %rax, %rbx
jmp 0x3cce
jmp 0x3c64
jmp 0x3c64
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
jmp 0x3c95
jmp 0x3c64
jmp 0x3c64
jmp 0x3c64
movq %rax, %rbx
jmp 0x3ce8
movq %rax, %rbx
jmp 0x3cdb
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
jmp 0x3ca9
jmp 0x3cb4
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x3110
jmp 0x3c8d
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x3110
jmp 0x3cdb
jmp 0x3cb4
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x3110
jmp 0x3cb7
jmp 0x3cb4
jmp 0x3cb4
movq %rax, %rbx
leaq 0x3a0(%rsp), %rdi
callq 0x3380
leaq 0x10(%rsp), %rdi
callq 0x3110
leaq 0x198(%rsp), %rdi
callq 0x30c0
leaq 0x5a0(%rsp), %rdi
callq 0x41ec
leaq 0x30(%rsp), %rdi
callq 0x3df6
movq %rbx, %rdi
callq 0x3450