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

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

	int threshold = 0;
	vector<int> thresholds;

	while (seedNum > 0) {
		cin >> threshold;
		thresholds.clear();
		thresholds.resize(seedNum, threshold);
		solver.setThresholdVec(thresholds);

		frequencyCounter.clear();

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

		//Name
		getline(readFile, read);
		//Read
		getline(readFile, read);
		//cout << "DNA: " << read << endl;

		//Solve
		frequency = solver.solve(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.solve(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 << " | threshold: " << threshold << endl;
		output << "seedNum: " << seedNum << " | threshold: " << threshold << 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 $0xa18, %rsp            # imm = 0xA18
movq %rsi, %r14
movl %edi, %ebx
leaq 0x40(%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 0x4550
cmpl $0x3, %ebx
jne 0x3ba9
movq 0xc8ef(%rip), %rdi      # 0xffc8
leaq 0x6957(%rip), %rsi      # 0xa037
callq 0x3250
movq 0x8(%r14), %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x694d(%rip), %rsi      # 0xa045
movq %rax, %rdi
callq 0x3250
movq 0x8(%r14), %rsi
leaq 0xc8(%rsp), %rdi
leaq 0x128(%rsp), %rdx
callq 0x3ca8
leaq 0x580(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x46a8
leaq 0xc8(%rsp), %rdi
callq 0x3110
movq 0xc886(%rip), %rdi      # 0xffc8
leaq 0x690b(%rip), %rsi      # 0xa054
callq 0x3250
movq 0xc883(%rip), %rdi      # 0xffd8
leaq 0x8(%rsp), %rsi
callq 0x3170
leaq 0x128(%rsp), %rdi
callq 0x32a0
movq 0x10(%r14), %rsi
leaq 0x128(%rsp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x3180
leaq 0xb8(%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 0x3240
leaq 0x6d9d(%rip), %rsi      # 0xa54f
movq %r14, %rdi
callq 0x33d0
movq %rax, %r14
leaq 0x380(%rsp), %rdi
callq 0x3440
leaq 0x68(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %r14, %rsi
callq 0x3ca8
leaq 0x6885(%rip), %rsi      # 0xa068
leaq 0x88(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x3ca8
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x3ce3
movq 0x10(%rsp), %rsi
leaq 0x380(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x3040
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x3110
leaq 0x88(%rsp), %rdi
callq 0x3110
leaq 0x68(%rsp), %r15
movq %r15, %rdi
callq 0x3110
andl $0x0, (%r15)
andq $0x0, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
leaq 0xa8(%rsp), %r12
leaq 0x108(%rsp), %r13
leaq 0x380(%rsp), %r15
leaq 0x6d15(%rip), %rbp      # 0xa58c
cmpl $0x0, 0x8(%rsp)
jle 0x3b4d
movq 0xc74f(%rip), %rdi      # 0xffd8
leaq 0x68(%rsp), %rsi
callq 0x3170
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x38a4
movq %rax, 0x18(%rsp)
movslq 0x8(%rsp), %rsi
movq %r14, %rdi
leaq 0x68(%rsp), %rdx
callq 0x3d4a
leaq 0x580(%rsp), %rdi
movq %r14, %rsi
callq 0x47c2
leaq 0x38(%rsp), %rdi
callq 0x4280
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x3430
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3370
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3080
leaq 0xe8(%rsp), %rdi
movq %r12, %rsi
callq 0x3380
leaq 0x580(%rsp), %rdi
leaq 0xe8(%rsp), %r14
movq %r14, %rsi
callq 0x5250
movl %eax, 0x4(%rsp)
movq %r14, %rdi
callq 0x3110
leaq 0x38(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x42ae
leaq 0x40(%rsp), %rcx
cmpq %rcx, %rax
je 0x3969
leaq 0x38(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x3d7e
incq (%rax)
jmp 0x397f
leaq 0x38(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x3d7e
movq $0x1, (%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3080
leaq 0x580(%rsp), %r14
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x148(%rsp,%rax)
jne 0x3a6b
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3080
movq %r12, %rdi
pushq $0x4e
popq %rsi
xorl %edx, %edx
callq 0x3340
cmpq $-0x1, %rax
jne 0x3a45
movq %r13, %rdi
movq %r12, %rsi
callq 0x3380
movq %r14, %rdi
movq %r13, %rsi
callq 0x5250
movl %eax, 0x4(%rsp)
movq %r13, %rdi
callq 0x3110
leaq 0x38(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x42ae
leaq 0x40(%rsp), %rcx
cmpq %rcx, %rax
je 0x3a2f
leaq 0x38(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x3d7e
incq (%rax)
jmp 0x3a45
leaq 0x38(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x3d7e
movq $0x1, (%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3080
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3080
jmp 0x39a8
movq 0xc556(%rip), %rdi      # 0xffc8
leaq 0x65fa(%rip), %rsi      # 0xa073
callq 0x3250
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x3450
movq %rax, %rdi
leaq 0x65e9(%rip), %rsi      # 0xa07d
callq 0x3250
movl 0x68(%rsp), %esi
movq %rax, %rdi
callq 0x3450
movq %rax, %rdi
callq 0x3120
movq %r15, %rdi
leaq 0x65bc(%rip), %rsi      # 0xa073
callq 0x3250
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x3450
movq %rax, %rdi
leaq 0x65ab(%rip), %rsi      # 0xa07d
callq 0x3250
movl 0x68(%rsp), %esi
movq %rax, %rdi
callq 0x3450
movq %rax, %rdi
callq 0x3120
movq 0x50(%rsp), %r14
leaq 0x40(%rsp), %rax
cmpq %rax, %r14
je 0x3b32
movl 0x20(%r14), %esi
movq %r15, %rdi
callq 0x3450
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3250
movq 0x28(%r14), %rsi
movq %rax, %rdi
callq 0x31a0
movq %rax, %rdi
callq 0x3120
movq %r14, %rdi
callq 0x31d0
movq %rax, %r14
jmp 0x3af0
movq 0xc49f(%rip), %rdi      # 0xffd8
leaq 0x8(%rsp), %rsi
callq 0x3170
leaq 0x10(%rsp), %r14
jmp 0x3877
leaq 0x10(%rsp), %rdi
callq 0x3f42
leaq 0x380(%rsp), %rdi
callq 0x33b0
leaq 0xa8(%rsp), %rdi
callq 0x3110
leaq 0x128(%rsp), %rdi
callq 0x30c0
leaq 0x580(%rsp), %rdi
callq 0x3dcc
leaq 0x38(%rsp), %rdi
callq 0x3eea
xorl %eax, %eax
addq $0xa18, %rsp            # imm = 0xA18
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc440(%rip), %rdi      # 0xfff0
leaq 0x644d(%rip), %rsi      # 0xa004
callq 0x3250
movq %rax, %rdi
callq 0x3120
pushq $0x1
popq %rdi
callq 0x32d0
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3110
jmp 0x3bde
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3110
jmp 0x3bf0
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x3110
jmp 0x3c61
movq %rax, %rbx
jmp 0x3c61
movq %rax, %rbx
jmp 0x3c6e
movq %rax, %rbx
jmp 0x3c7b
jmp 0x3c28
jmp 0x3c28
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x3110
jmp 0x3c88
jmp 0x3c28
movq %rax, %rbx
jmp 0x3c95
movq %rax, %rbx
jmp 0x3c88
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x3c49
jmp 0x3c54
jmp 0x3c54
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3110
jmp 0x3c57
jmp 0x3c54
jmp 0x3c54
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3f42
leaq 0x380(%rsp), %rdi
callq 0x33b0
leaq 0xa8(%rsp), %rdi
callq 0x3110
leaq 0x128(%rsp), %rdi
callq 0x30c0
leaq 0x580(%rsp), %rdi
callq 0x3dcc
leaq 0x38(%rsp), %rdi
callq 0x3eea
movq %rbx, %rdi
callq 0x3470
nop