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

	OptimalSolverLN 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(".optimalLN") ).c_str() );
#ifdef FREQ
		ofstream freqOutput;
		freqOutput.open( (string(benchName) + string(".optimalLN_freq") ).c_str() );
#endif

		while (seedNum > 0) {
			cout << "seedNum: " << seedNum << endl;
			output << "seedNum: " << seedNum << endl;
#ifdef FREQ
			freqOutput << "seedNum: " << seedNum << endl;
#endif

			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);
#ifdef FREQ
					solver.backtrack();
					solver.sortOfFreq();
					solver.printFreqs(freqOutput);
					solver.printLength(freqOutput);
#endif
					if (frequencyCounter.find(frequency) == frequencyCounter.end() )
						frequencyCounter[frequency] = 1;
					else
						frequencyCounter[frequency]++;
				}

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

				//Name
				getline(readFile, read);
			}

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

			cin >> seedNum;

			solver.printStats(cout);
			solver.printStats(output);
		}
		output.close();
#ifdef FREQ
		freqOutput.close();
#endif

	}
	else if (argc == 1) {
		cout << "input seedNum and readLength: " << endl;
		int seedNum;
		int readLength;
		cin >> seedNum;
		string dummy = "";
		while (seedNum > 0) {
			cin >> readLength;
			solver.setMinLength(10);
			solver.init(readLength, seedNum);
			solver.feedL0();
			solver.solveDNA(dummy);
			solver.backtrack();
			solver.sortOfFreq();
			solver.printFreqs(cout);
			solver.printStats(cout);
			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 $0x948, %rsp            # imm = 0x948
movq %rsi, %r14
movl %edi, %ebx
leaq 0x18(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x540(%rsp), %rdi
callq 0x41c4
cmpl $0x1, %ebx
je 0x3ac7
cmpl $0x3, %ebx
jne 0x3c23
movq 0xd8e6(%rip), %rdi      # 0x10fc8
leaq 0x791b(%rip), %rsi      # 0xb004
callq 0x3240
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x3240
leaq 0x7911(%rip), %rsi      # 0xb012
movq %rax, %rdi
callq 0x3240
movq 0x8(%r14), %rsi
leaq 0xc0(%rsp), %rdi
leaq 0x138(%rsp), %rdx
callq 0x3d08
leaq 0x540(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x4336
leaq 0xc0(%rsp), %rdi
callq 0x3110
movq 0xd87d(%rip), %rdi      # 0x10fc8
leaq 0x78cf(%rip), %rsi      # 0xb021
callq 0x3240
movq 0xd87a(%rip), %rdi      # 0x10fd8
leaq 0x8(%rsp), %rsi
callq 0x3150
leaq 0x138(%rsp), %rdi
callq 0x3290
movq 0x10(%r14), %rsi
leaq 0x138(%rsp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x3160
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x10(%r14), %rsi
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
callq 0x3230
leaq 0x7dbf(%rip), %rsi      # 0xb577
movq %r14, %rdi
callq 0x33b0
movq %rax, %r14
leaq 0x340(%rsp), %rdi
callq 0x3430
leaq 0x80(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %r14, %rsi
callq 0x3d08
leaq 0x7849(%rip), %rsi      # 0xb035
leaq 0x60(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x3d08
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x3d43
movq 0xa0(%rsp), %rsi
leaq 0x340(%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
movq 0xd770(%rip), %r13      # 0x10fc8
leaq 0x340(%rsp), %r12
leaq 0x40(%rsp), %rbp
pushq $0x4e
popq %r14
leaq 0x7d75(%rip), %r15      # 0xb5e5
cmpl $0x0, 0x8(%rsp)
jle 0x3bc7
movq %r13, %rdi
leaq 0x77bb(%rip), %rsi      # 0xb040
callq 0x3240
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x3440
movq %rax, %rdi
callq 0x3120
movq %r12, %rdi
leaq 0x7798(%rip), %rsi      # 0xb040
callq 0x3240
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x3440
movq %rax, %rdi
callq 0x3120
leaq 0x10(%rsp), %rdi
callq 0x3ef2
movq 0x138(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x3420
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3350
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3080
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3080
movl 0x48(%rsp), %esi
movl 0x8(%rsp), %edx
leaq 0x540(%rsp), %rdi
callq 0x43de
leaq 0x540(%rsp), %rdi
movq %rbp, %rsi
callq 0x54ca
movl %eax, 0x4(%rsp)
leaq 0x10(%rsp), %r13
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3f20
leaq 0x18(%rsp), %rcx
cmpq %rcx, %rax
je 0x395a
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3daa
incq (%rax)
jmp 0x396e
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3daa
movq $0x1, (%rax)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3080
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3080
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3080
leaq 0x10(%rsp), %r13
movq 0x138(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x158(%rsp,%rax)
jne 0x3a43
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3080
movq %rbp, %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x3320
cmpq $-0x1, %rax
jne 0x3a1d
leaq 0x540(%rsp), %rdi
movq %rbp, %rsi
callq 0x54ca
movl %eax, 0x4(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3f20
leaq 0x18(%rsp), %rcx
cmpq %rcx, %rax
je 0x3a09
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3daa
incq (%rax)
jmp 0x3a1d
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
callq 0x3daa
movq $0x1, (%rax)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3080
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3080
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3080
jmp 0x3994
movq 0x28(%rsp), %r13
leaq 0x18(%rsp), %rax
cmpq %rax, %r13
je 0x3a8a
movl 0x20(%r13), %esi
movq %r12, %rdi
callq 0x3190
movq %rax, %rdi
movq %r15, %rsi
callq 0x3240
movq 0x28(%r13), %rsi
movq %rax, %rdi
callq 0x3180
movq %rax, %rdi
callq 0x3120
movq %r13, %rdi
callq 0x31b0
movq %rax, %r13
jmp 0x3a48
movq 0xd547(%rip), %rdi      # 0x10fd8
leaq 0x8(%rsp), %rsi
callq 0x3150
movq 0xd526(%rip), %r13      # 0x10fc8
leaq 0x540(%rsp), %rdi
movq %r13, %rsi
callq 0x57a6
leaq 0x540(%rsp), %rdi
movq %r12, %rsi
callq 0x57a6
jmp 0x3870
movq 0xd4fa(%rip), %rdi      # 0x10fc8
leaq 0x7575(%rip), %rsi      # 0xb04a
callq 0x3240
movq %rax, %rdi
callq 0x3120
movq 0xd4ef(%rip), %rdi      # 0x10fd8
leaq 0x340(%rsp), %rsi
callq 0x3150
leaq 0x79f6(%rip), %rsi      # 0xb4f3
leaq 0x138(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x3d08
movq 0xd4c2(%rip), %rbx      # 0x10fd8
leaq 0x540(%rsp), %r15
pushq $0xa
popq %rbp
leaq 0x138(%rsp), %r12
movq 0xd498(%rip), %r13      # 0x10fc8
leaq 0x340(%rsp), %r14
cmpl $0x0, 0x340(%rsp)
jle 0x3bb8
movq %rbx, %rdi
leaq 0xe0(%rsp), %rsi
callq 0x3150
movq %r15, %rdi
movl %ebp, %esi
callq 0x4874
movl 0xe0(%rsp), %esi
movl 0x340(%rsp), %edx
movq %r15, %rdi
callq 0x43de
movq %r15, %rdi
callq 0x4780
movq %r15, %rdi
movq %r12, %rsi
callq 0x54ca
movq %r15, %rdi
callq 0x54ea
movq %r15, %rdi
callq 0x55f2
movq %r15, %rdi
movq %r13, %rsi
callq 0x56dc
movq %r15, %rdi
movq %r13, %rsi
callq 0x57a6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3150
jmp 0x3b38
leaq 0x138(%rsp), %rdi
callq 0x3110
jmp 0x3bf8
leaq 0x340(%rsp), %rdi
callq 0x3370
leaq 0x340(%rsp), %rdi
callq 0x3390
leaq 0x40(%rsp), %rdi
callq 0x3110
leaq 0x138(%rsp), %rdi
callq 0x30c0
leaq 0x540(%rsp), %rdi
callq 0x4232
leaq 0x10(%rsp), %rdi
callq 0x3e04
xorl %eax, %eax
addq $0x948, %rsp            # imm = 0x948
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd3c6(%rip), %rdi      # 0x10ff0
leaq 0x7438(%rip), %rsi      # 0xb069
callq 0x3240
movq %rax, %rdi
callq 0x3120
pushq $0x1
popq %rdi
callq 0x32c0
jmp 0x3cc2
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x3110
jmp 0x3c5d
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x3110
jmp 0x3c6c
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x3110
jmp 0x3cc5
jmp 0x3cc2
movq %rax, %rbx
jmp 0x3cd2
movq %rax, %rbx
jmp 0x3cdc
jmp 0x3ca3
jmp 0x3ca3
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
jmp 0x3cb5
jmp 0x3ca3
jmp 0x3ca3
jmp 0x3ca3
movq %rax, %rbx
jmp 0x3cf6
movq %rax, %rbx
jmp 0x3ce9
jmp 0x3cc2
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x3110
jmp 0x3ce9
jmp 0x3cc2
jmp 0x3cc2
jmp 0x3cc2
movq %rax, %rbx
leaq 0x340(%rsp), %rdi
callq 0x3390
leaq 0x40(%rsp), %rdi
callq 0x3110
leaq 0x138(%rsp), %rdi
callq 0x30c0
leaq 0x540(%rsp), %rdi
callq 0x4232
leaq 0x10(%rsp), %rdi
callq 0x3e04
movq %rbx, %rdi
callq 0x3470