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

	BasicSolver solver;

	if (argc != 3) {
		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;
	//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(".analyzeBasic") ).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;
		solver.init(read.length(), seedNum, seedLength);

		//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 << " | seedLength: " << seedLength << endl;
		output << "seedNum: " << seedNum << " | seedLength: " << seedLength << 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 $0x8e8, %rsp            # imm = 0x8E8
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 0x580(%rsp), %rdi
callq 0x40d4
cmpl $0x3, %ebx
jne 0x3b2b
movq 0xa92f(%rip), %rdi      # 0xdfc8
leaq 0x5997(%rip), %rsi      # 0x9037
callq 0x3220
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x3220
leaq 0x598d(%rip), %rsi      # 0x9045
movq %rax, %rdi
callq 0x3220
movq 0x8(%r14), %rsi
leaq 0xc8(%rsp), %rdi
leaq 0x128(%rsp), %rdx
callq 0x3c18
leaq 0x580(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x40e6
leaq 0xc8(%rsp), %rdi
callq 0x3110
movq 0xa8c6(%rip), %rdi      # 0xdfc8
leaq 0x594b(%rip), %rsi      # 0x9054
callq 0x3220
movq 0xa8c3(%rip), %rdi      # 0xdfd8
leaq 0xc(%rsp), %rsi
callq 0x3150
leaq 0x128(%rsp), %rdi
callq 0x3270
movq 0x10(%r14), %rsi
leaq 0x128(%rsp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x3160
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x10(%r14), %rsi
leaq 0x330(%rsp), %r14
movq %r14, %rdi
callq 0x3210
leaq 0x5bd0(%rip), %rsi      # 0x933f
movq %r14, %rdi
callq 0x3390
movq %rax, %r14
leaq 0x380(%rsp), %rdi
callq 0x3400
leaq 0x88(%rsp), %rdi
leaq 0x17(%rsp), %rdx
movq %r14, %rsi
callq 0x3c18
leaq 0x58c5(%rip), %rsi      # 0x9068
leaq 0x68(%rsp), %rdi
leaq 0x16(%rsp), %rdx
callq 0x3c18
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0x3c53
movq 0xa8(%rsp), %rsi
leaq 0x380(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x3040
leaq 0xa8(%rsp), %rdi
callq 0x3110
leaq 0x68(%rsp), %rdi
callq 0x3110
leaq 0x88(%rsp), %rdi
callq 0x3110
movq 0xa7c9(%rip), %r15      # 0xdfd8
leaq 0x48(%rsp), %r13
leaq 0x108(%rsp), %rbp
leaq 0x380(%rsp), %r14
leaq 0x5b82(%rip), %r12      # 0x93ad
cmpl $0x0, 0xc(%rsp)
jle 0x3adc
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3150
leaq 0x18(%rsp), %rdi
callq 0x3e02
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x33f0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3330
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3080
movl 0x50(%rsp), %esi
movl 0xc(%rsp), %edx
movl 0x10(%rsp), %ecx
leaq 0x580(%rsp), %rdi
callq 0x4130
leaq 0xe8(%rsp), %rdi
movq %r13, %rsi
callq 0x3340
leaq 0x580(%rsp), %rdi
leaq 0xe8(%rsp), %r15
movq %r15, %rsi
callq 0x4144
movl %eax, 0x8(%rsp)
movq %r15, %rdi
callq 0x3110
leaq 0x18(%rsp), %r15
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3e30
leaq 0x20(%rsp), %rcx
cmpq %rcx, %rax
je 0x3900
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3cba
incq (%rax)
jmp 0x3914
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3cba
movq $0x1, (%rax)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3080
leaq 0x18(%rsp), %r15
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x148(%rsp,%rax)
jne 0x39fc
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3080
movq %r13, %rdi
pushq $0x4e
popq %rsi
xorl %edx, %edx
callq 0x3300
cmpq $-0x1, %rax
jne 0x39d6
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3340
leaq 0x580(%rsp), %rdi
movq %rbp, %rsi
callq 0x4144
movl %eax, 0x8(%rsp)
movq %rbp, %rdi
callq 0x3110
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3e30
leaq 0x20(%rsp), %rcx
cmpq %rcx, %rax
je 0x39c2
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3cba
incq (%rax)
jmp 0x39d6
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3cba
movq $0x1, (%rax)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3080
jmp 0x393a
movq 0xa5c5(%rip), %rdi      # 0xdfc8
leaq 0x566c(%rip), %rsi      # 0x9076
callq 0x3220
movl 0xc(%rsp), %esi
movq %rax, %rdi
callq 0x3410
movq %rax, %rdi
leaq 0x565b(%rip), %rsi      # 0x9080
callq 0x3220
movl 0x10(%rsp), %esi
movq %rax, %rdi
callq 0x3410
movq %rax, %rdi
callq 0x3120
movq %r14, %rdi
leaq 0x562e(%rip), %rsi      # 0x9076
callq 0x3220
movl 0xc(%rsp), %esi
movq %rax, %rdi
callq 0x3410
movq %rax, %rdi
leaq 0x561d(%rip), %rsi      # 0x9080
callq 0x3220
movl 0x10(%rsp), %esi
movq %rax, %rdi
callq 0x3410
movq %rax, %rdi
callq 0x3120
movq 0x30(%rsp), %r15
leaq 0x20(%rsp), %rax
cmpq %rax, %r15
je 0x3ac3
movl 0x20(%r15), %esi
movq %r14, %rdi
callq 0x3410
movq %rax, %rdi
movq %r12, %rsi
callq 0x3220
movq 0x28(%r15), %rsi
movq %rax, %rdi
callq 0x3180
movq %rax, %rdi
callq 0x3120
movq %r15, %rdi
callq 0x31a0
movq %rax, %r15
jmp 0x3a81
movq 0xa50e(%rip), %r15      # 0xdfd8
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0x3150
jmp 0x382b
leaq 0x380(%rsp), %rdi
callq 0x3370
leaq 0x48(%rsp), %rdi
callq 0x3110
leaq 0x128(%rsp), %rdi
callq 0x30c0
leaq 0x580(%rsp), %rdi
callq 0x40e0
leaq 0x18(%rsp), %rdi
callq 0x3d14
xorl %eax, %eax
addq $0x8e8, %rsp            # imm = 0x8E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa4be(%rip), %rdi      # 0xdff0
leaq 0x54cb(%rip), %rsi      # 0x9004
callq 0x3220
movq %rax, %rdi
callq 0x3120
pushq $0x1
popq %rdi
callq 0x32a0
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3110
jmp 0x3b63
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x3110
jmp 0x3b72
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x3bc6
jmp 0x3bd1
movq %rax, %rbx
jmp 0x3be1
movq %rax, %rbx
jmp 0x3beb
jmp 0x3ba5
jmp 0x3ba5
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x3110
jmp 0x3bf8
jmp 0x3ba5
movq %rax, %rbx
jmp 0x3c05
movq %rax, %rbx
jmp 0x3bf8
jmp 0x3bd1
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x3bc6
jmp 0x3bd1
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3110
jmp 0x3bd4
jmp 0x3bd1
jmp 0x3bd1
movq %rax, %rbx
leaq 0x380(%rsp), %rdi
callq 0x3370
leaq 0x48(%rsp), %rdi
callq 0x3110
leaq 0x128(%rsp), %rdi
callq 0x30c0
leaq 0x580(%rsp), %rdi
callq 0x40e0
leaq 0x18(%rsp), %rdi
callq 0x3d14
movq %rbx, %rdi
callq 0x3430
nop