// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movl %edi, %ebx
leaq 0xa0(%rsp), %r14
movl $0x0, (%r14)
xorl %eax, %eax
movq %rax, 0x8(%r14)
movq %r14, 0x10(%r14)
movq %r14, 0x18(%r14)
movq %rax, 0x20(%r14)
leaq 0x540(%rsp), %rdi
callq 0x4568
cmpl $0x1, %ebx
je 0x37a6
cmpl $0x3, %ebx
jne 0x4040
movq 0xd863(%rip), %rbx      # 0x10fc8
leaq 0x8898(%rip), %rsi      # 0xc004
movl $0xd, %edx
movq %rbx, %rdi
callq 0x32e0
movq 0x8(%r12), %r15
testq %r15, %r15
je 0x38fd
movq %r15, %rdi
callq 0x3120
movq 0xd832(%rip), %rdi      # 0x10fc8
movq %r15, %rsi
movq %rax, %rdx
callq 0x32e0
jmp 0x3914
movq 0xd81b(%rip), %rbx      # 0x10fc8
leaq 0x8896(%rip), %rsi      # 0xc04a
movl $0x1e, %edx
movq %rbx, %rdi
callq 0x32e0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq 0xd7e9(%rip), %rdi      # 0x10fc8
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq 0xd7e5(%rip), %rdi      # 0x10fd8
leaq 0x340(%rsp), %rsi
callq 0x3170
leaq 0xf8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x8d18(%rip), %rdx      # 0xc52b
leaq 0xe8(%rsp), %rdi
movq %rdx, %rsi
callq 0x42a2
movq 0xd7ae(%rip), %rbx      # 0x10fd8
leaq 0x2f0(%rsp), %r14
leaq 0x540(%rsp), %r15
leaq 0xe8(%rsp), %r12
movq 0xd77f(%rip), %r13      # 0x10fc8
leaq 0x340(%rsp), %rbp
cmpl $0x0, 0x340(%rsp)
jle 0x38cf
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3170
movq %r15, %rdi
movl $0xa, %esi
callq 0x4d0e
movl 0x2f0(%rsp), %esi
movl 0x340(%rsp), %edx
movq %r15, %rdi
callq 0x481e
movq %r15, %rdi
callq 0x4bfe
movq %r15, %rdi
movq %r12, %rsi
callq 0x5c22
movq %r15, %rdi
callq 0x5c42
movq %r15, %rdi
callq 0x5d4e
movq %r15, %rdi
movq %r13, %rsi
callq 0x5e74
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f98
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3170
jmp 0x3851
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0x4012
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4012
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x3430
movq 0xd6ad(%rip), %rdi      # 0x10fc8
leaq 0x86f0(%rip), %rsi      # 0xc012
movl $0xe, %edx
callq 0x32e0
movq 0x8(%r12), %rsi
leaq 0xc8(%rsp), %rdi
leaq 0xe8(%rsp), %rdx
callq 0x41a4
leaq 0x540(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x470c
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x397c
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xd645(%rip), %rdi      # 0x10fc8
leaq 0x8697(%rip), %rsi      # 0xc021
movl $0x13, %edx
callq 0x32e0
movq 0xd63d(%rip), %rdi      # 0x10fd8
leaq 0x10(%rsp), %rsi
callq 0x3170
leaq 0xe8(%rsp), %rdi
callq 0x32d0
movq 0x10(%r12), %rsi
leaq 0xe8(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x3180
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x10(%r12), %rsi
leaq 0x2f0(%rsp), %r15
movq %r15, %rdi
callq 0x3250
leaq 0x8bb3(%rip), %rsi      # 0xc5af
movq %r15, %rdi
callq 0x33d0
movq %rax, %r15
leaq 0x340(%rsp), %rdi
callq 0x3440
leaq 0x78(%rsp), %rdi
leaq 0x17(%rsp), %rdx
movq %r15, %rsi
callq 0x41a4
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x85ff(%rip), %rsi      # 0xc035
leaq 0x8602(%rip), %rdx      # 0xc03f
leaq 0x38(%rsp), %rdi
callq 0x42a2
leaq 0x88(%rsp), %r12
movq -0x10(%r12), %rcx
movq -0x8(%r12), %r8
movq 0x40(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r12, %rcx
je 0x3a74
movq 0x88(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x3a8f
movl $0xf, %esi
cmpq %r15, 0x38(%rsp)
je 0x3a8a
movq 0x48(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x3aa0
movq 0x38(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x30e0
jmp 0x3aae
leaq 0x38(%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 0x3ad2
movq %rsi, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x3ad8
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 0x340(%rsp), %rdi
movl $0x10, %edx
callq 0x3050
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3b27
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x3b3e
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x78(%rsp), %rdi
cmpq %r12, %rdi
je 0x3b58
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xd469(%rip), %r12      # 0x10fc8
leaq 0x58(%rsp), %rbp
cmpl $0x0, 0x10(%rsp)
jle 0x3fa4
movl $0x9, %edx
movq %r12, %rdi
leaq 0x84c2(%rip), %rsi      # 0xc040
callq 0x32e0
movl 0x10(%rsp), %esi
movq %r12, %rdi
callq 0x3450
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movl $0x9, %edx
leaq 0x340(%rsp), %rdi
leaq 0x8473(%rip), %rsi      # 0xc040
callq 0x32e0
movl 0x10(%rsp), %esi
leaq 0x340(%rsp), %rdi
callq 0x3450
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
leaq 0x98(%rsp), %rdi
callq 0x4332
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x3430
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3380
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x34a0
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x34a0
movl 0x60(%rsp), %esi
movl 0x10(%rsp), %edx
leaq 0x540(%rsp), %rdi
callq 0x481e
leaq 0x540(%rsp), %rdi
movq %rbp, %rsi
callq 0x5c22
movl %eax, 0xc(%rsp)
movq 0xa8(%rsp), %rdx
movq %r14, %rcx
testq %rdx, %rdx
je 0x3cdd
movq %r14, %rcx
xorl %esi, %esi
cmpl %eax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x3cc6
movq %r14, %rdx
cmpq %r14, %rcx
je 0x3cef
cmpl 0x20(%rcx), %eax
cmovbq %r14, %rcx
movq %rcx, %rdx
cmpq %r14, %rdx
je 0x3d0b
leaq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x41e2
incq (%rax)
jmp 0x3d24
leaq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x41e2
movq $0x1, (%rax)
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x34a0
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x34a0
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x34a0
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x108(%rsp,%rax)
jne 0x3eee
leaq (%rsp,%rax), %rdi
addq $0xe8, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x34a0
movq %rbp, %rdi
movl $0x4e, %esi
xorl %edx, %edx
callq 0x3350
cmpq $-0x1, %rax
jne 0x3e74
leaq 0x540(%rsp), %rdi
movq %rbp, %rsi
callq 0x5c22
movl %eax, 0xc(%rsp)
movq 0xa8(%rsp), %rdx
movq %r14, %rcx
testq %rdx, %rdx
je 0x3e2d
movq %r14, %rcx
xorl %esi, %esi
cmpl %eax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x3e16
movq %r14, %rdx
cmpq %r14, %rcx
je 0x3e3f
cmpl 0x20(%rcx), %eax
cmovbq %r14, %rcx
movq %rcx, %rdx
cmpq %r14, %rdx
je 0x3e5b
leaq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x41e2
incq (%rax)
jmp 0x3e74
leaq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x41e2
movq $0x1, (%rax)
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x34a0
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x34a0
movq 0xe8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x34a0
jmp 0x3d99
movq 0xb0(%rsp), %r13
cmpq %r14, %r13
je 0x3f69
movl 0x20(%r13), %esi
leaq 0x340(%rsp), %rdi
callq 0x31b0
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
leaq 0x86ff(%rip), %rsi      # 0xc61d
callq 0x32e0
movq 0x28(%r13), %rsi
movq %r15, %rdi
callq 0x31a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %r13, %rdi
callq 0x31d0
movq %rax, %r13
cmpq %r14, %rax
jne 0x3efb
movq 0xd068(%rip), %rdi      # 0x10fd8
leaq 0x10(%rsp), %rsi
callq 0x3170
leaq 0x540(%rsp), %rdi
movq %r12, %rsi
callq 0x5f98
leaq 0x540(%rsp), %rdi
leaq 0x340(%rsp), %rsi
callq 0x5f98
jmp 0x3b64
leaq 0x340(%rsp), %rdi
callq 0x3390
movq 0xd008(%rip), %rax      # 0x10fc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x348(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x340(%rsp,%rcx)
callq 0x3210
leaq 0x438(%rsp), %rdi
callq 0x30f0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x4005
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0xe8(%rsp), %rdi
callq 0x30c0
leaq 0x540(%rsp), %rdi
callq 0x45da
leaq 0x98(%rsp), %rdi
callq 0x4252
xorl %eax, %eax
addq $0x948, %rsp            # imm = 0x948
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xcfa9(%rip), %rdi      # 0x10ff0
leaq 0x801b(%rip), %rsi      # 0xc069
movl $0x32, %edx
callq 0x32e0
movq 0xcf91(%rip), %rdi      # 0x10ff0
callq 0x3130
movl $0x1, %edi
callq 0x3300
jmp 0x4148
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4096
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4096
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x40b2
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x40b2
movq %rax, %rbx
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x414b
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x414b
jmp 0x4148
movq %rax, %rbx
jmp 0x4158
movq %rax, %rbx
jmp 0x4174
jmp 0x4115
jmp 0x4115
jmp 0x4115
movq %rax, %rbx
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4181
movq 0xd8(%rsp), %rsi
jmp 0x413a
jmp 0x4115
jmp 0x4115
movq %rax, %rbx
jmp 0x418e
movq %rax, %rbx
jmp 0x4181
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0x4181
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4181
jmp 0x4148
jmp 0x4148
movq %rax, %rbx
leaq 0x340(%rsp), %rdi
callq 0x33b0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x4174
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0xe8(%rsp), %rdi
callq 0x30c0
leaq 0x540(%rsp), %rdi
callq 0x45da
leaq 0x98(%rsp), %rdi
callq 0x4252
movq %rbx, %rdi
callq 0x3480
nop