// File: /workspace/github_cpp_makefile_star2_O3/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 0x4574
cmpl $0x1, %ebx
je 0x37a6
cmpl $0x3, %ebx
jne 0x404a
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 0x8d00(%rip), %rdx      # 0xc513
leaq 0xe8(%rsp), %rdi
movq %rdx, %rsi
callq 0x42ac
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 0x4d22
movl 0x2f0(%rsp), %esi
movl 0x340(%rsp), %edx
movq %r15, %rdi
callq 0x482e
movq %r15, %rdi
callq 0x4c12
movq %r15, %rdi
movq %r12, %rsi
callq 0x5ce2
movq %r15, %rdi
callq 0x5d02
movq %r15, %rdi
callq 0x5e0c
movq %r15, %rdi
movq %r13, %rsi
callq 0x5f32
movq %r15, %rdi
movq %r13, %rsi
callq 0x6056
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3170
jmp 0x3851
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0x401c
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x401c
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 0x41ae
leaq 0x540(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x471c
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 0x8b9b(%rip), %rsi      # 0xc597
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 0x41ae
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x85ff(%rip), %rsi      # 0xc035
leaq 0x8602(%rip), %rdx      # 0xc03f
leaq 0x38(%rsp), %rdi
callq 0x42ac
leaq 0x88(%rsp), %r12
movq -0x10(%r12), %rcx
movq -0x8(%r12), %r8
movq 0x40(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
cmpq %r12, %rcx
je 0x3a74
movq 0x88(%rsp), %rdi
movq 0x38(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x3a92
movl $0xf, %edi
cmpq %r15, %rsi
je 0x3a8d
movq 0x48(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x3a9e
leaq 0x78(%rsp), %rdi
callq 0x30e0
jmp 0x3aac
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 0x3ad0
movq %rsi, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x3ad6
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 0x3b25
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x3b3c
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x78(%rsp), %rdi
cmpq %r12, %rdi
je 0x3b56
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xd46b(%rip), %r12      # 0x10fc8
leaq 0x58(%rsp), %rbp
cmpl $0x0, 0x10(%rsp)
jle 0x3fae
movl $0x9, %edx
movq %r12, %rdi
leaq 0x84c4(%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 0x8475(%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 0x4342
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 0x482e
leaq 0x540(%rsp), %rdi
movq %rbp, %rsi
callq 0x5ce2
movl %eax, 0xc(%rsp)
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x3cf7
movq %r14, %r8
movq %r8, %rcx
movq %rdi, %rdx
movl 0x20(%rdi), %esi
xorl %edi, %edi
cmpl %eax, %esi
setb %dil
movq %rdx, %r8
cmovbq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x3cc1
cmpq %r14, %r8
je 0x3cf7
cmpl %eax, %esi
cmovbq %rcx, %rdx
cmpl 0x20(%rdx), %eax
jae 0x3f94
leaq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x41ec
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 0x3ede
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 0x3e4a
leaq 0x540(%rsp), %rdi
movq %rbp, %rsi
callq 0x5ce2
movl %eax, 0xc(%rsp)
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x3e31
movq %r14, %r8
movq %r8, %rcx
movq %rdi, %rdx
movl 0x20(%rdi), %esi
xorl %edi, %edi
cmpl %eax, %esi
setb %dil
movq %rdx, %r8
cmovbq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x3dfb
cmpq %r14, %r8
je 0x3e31
cmpl %eax, %esi
cmovbq %rcx, %rdx
cmpl 0x20(%rdx), %eax
jae 0x3ec4
leaq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x41ec
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 0x3d85
leaq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x41ec
incq (%rax)
jmp 0x3e4a
movq 0xb0(%rsp), %r13
cmpq %r14, %r13
je 0x3f59
movl 0x20(%r13), %esi
leaq 0x340(%rsp), %rdi
callq 0x31b0
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
leaq 0x86f7(%rip), %rsi      # 0xc605
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 0x3eeb
movq 0xd078(%rip), %rdi      # 0x10fd8
leaq 0x10(%rsp), %rsi
callq 0x3170
leaq 0x540(%rsp), %rdi
movq %r12, %rsi
callq 0x6056
leaq 0x540(%rsp), %rdi
leaq 0x340(%rsp), %rsi
callq 0x6056
jmp 0x3b62
leaq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x41ec
incq (%rax)
jmp 0x3d10
leaq 0x340(%rsp), %rdi
callq 0x3390
movq 0xcffe(%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 0x400f
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0xe8(%rsp), %rdi
callq 0x30c0
leaq 0x540(%rsp), %rdi
callq 0x45e6
leaq 0x98(%rsp), %rdi
callq 0x425c
xorl %eax, %eax
addq $0x948, %rsp            # imm = 0x948
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xcf9f(%rip), %rdi      # 0x10ff0
leaq 0x8011(%rip), %rsi      # 0xc069
movl $0x32, %edx
callq 0x32e0
movq 0xcf87(%rip), %rdi      # 0x10ff0
callq 0x3130
movl $0x1, %edi
callq 0x3300
jmp 0x4152
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x40a0
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x40a0
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x40bc
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x40bc
movq %rax, %rbx
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4155
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4155
jmp 0x4152
movq %rax, %rbx
jmp 0x4162
movq %rax, %rbx
jmp 0x417e
jmp 0x411f
jmp 0x411f
jmp 0x411f
movq %rax, %rbx
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x418b
movq 0xd8(%rsp), %rsi
jmp 0x4144
jmp 0x411f
jmp 0x411f
movq %rax, %rbx
jmp 0x4198
movq %rax, %rbx
jmp 0x418b
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0x418b
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x418b
jmp 0x4152
jmp 0x4152
movq %rax, %rbx
leaq 0x340(%rsp), %rdi
callq 0x33b0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x417e
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0xe8(%rsp), %rdi
callq 0x30c0
leaq 0x540(%rsp), %rdi
callq 0x45e6
leaq 0x98(%rsp), %rdi
callq 0x425c
movq %rbx, %rdi
callq 0x3480
nop