// File: 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:
subq $0xb88, %rsp            # imm = 0xB88
movl $0x0, 0xb84(%rsp)
movl %edi, 0xb80(%rsp)
movq %rsi, 0xb78(%rsp)
leaq 0xb48(%rsp), %rdi
callq 0x43e0
leaq 0x6b0(%rsp), %rdi
callq 0x7a10
jmp 0x38dd
cmpl $0x3, 0xb80(%rsp)
je 0x3956
movq 0x1f702(%rip), %rdi     # 0x22ff0
leaq 0x1570f(%rip), %rsi     # 0x19004
callq 0x32c0
movq %rax, 0xe0(%rsp)
jmp 0x3904
movq 0xe0(%rsp), %rdi
movq 0x1f6a5(%rip), %rsi     # 0x22fb8
callq 0x3310
jmp 0x391a
movl $0x1, %edi
callq 0x33a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
jmp 0x43c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
jmp 0x43b7
movq 0x1f66b(%rip), %rdi     # 0x22fc8
leaq 0x156d3(%rip), %rsi     # 0x19037
callq 0x32c0
movq %rax, 0xd8(%rsp)
jmp 0x3973
movq 0xd8(%rsp), %rdi
movq 0xb78(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x32c0
movq %rax, 0xd0(%rsp)
jmp 0x3996
movq 0xd0(%rsp), %rdi
leaq 0x156a0(%rip), %rsi     # 0x19045
callq 0x32c0
jmp 0x39ac
movq 0xb78(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xc0(%rsp)
leaq 0x67f(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x35d0
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
leaq 0x680(%rsp), %rdi
callq 0x43f0
jmp 0x39f4
leaq 0x6b0(%rsp), %rdi
leaq 0x680(%rsp), %rsi
callq 0x7c10
jmp 0x3a0b
leaq 0x680(%rsp), %rdi
callq 0x31c0
leaq 0x67f(%rsp), %rdi
callq 0x3330
movq 0x1f59c(%rip), %rdi     # 0x22fc8
leaq 0x15621(%rip), %rsi     # 0x19054
callq 0x32c0
jmp 0x3a3a
movq 0x1f597(%rip), %rdi     # 0x22fd8
leaq 0x678(%rsp), %rsi
callq 0x31b0
jmp 0x3a50
leaq 0x468(%rsp), %rdi
callq 0x3370
jmp 0x3a5f
movq 0xb78(%rsp), %rax
movq 0x10(%rax), %rsi
leaq 0x468(%rsp), %rdi
movl $0x8, %edx
callq 0x31d0
jmp 0x3a7f
leaq 0x448(%rsp), %rdi
callq 0x3480
movq 0xb78(%rsp), %rax
movq 0x10(%rax), %rsi
leaq 0x3f0(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x32b0
movq 0xb8(%rsp), %rdi
leaq 0x15c91(%rip), %rsi     # 0x1974d
callq 0x34f0
movq %rax, 0x3e8(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x3570
jmp 0x3ad8
movq 0x3e8(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x1a7(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x35d0
movq 0xa8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
leaq 0x1a8(%rsp), %rdi
callq 0x43f0
jmp 0x3b1c
leaq 0x17f(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x35d0
movq 0xa0(%rsp), %rdx
leaq 0x15528(%rip), %rsi     # 0x19068
leaq 0x180(%rsp), %rdi
callq 0x43f0
jmp 0x3b4f
leaq 0x1c8(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
leaq 0x180(%rsp), %rdx
callq 0x44b0
jmp 0x3b6e
leaq 0x1c8(%rsp), %rdi
callq 0x3140
movq %rax, %rsi
leaq 0x1e8(%rsp), %rdi
movl $0x10, %edx
callq 0x3060
jmp 0x3b92
leaq 0x1c8(%rsp), %rdi
callq 0x31c0
leaq 0x180(%rsp), %rdi
callq 0x31c0
leaq 0x17f(%rsp), %rdi
callq 0x3330
leaq 0x1a8(%rsp), %rdi
callq 0x31c0
leaq 0x1a7(%rsp), %rdi
callq 0x3330
movl $0x0, 0x178(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x45a0
cmpl $0x0, 0x678(%rsp)
jle 0x431b
movq 0x1f3d8(%rip), %rdi     # 0x22fd8
leaq 0x178(%rsp), %rsi
callq 0x31b0
jmp 0x3c0f
leaq 0x160(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x45b0
movq 0x98(%rsp), %rdi
movslq 0x678(%rsp), %rsi
leaq 0x178(%rsp), %rdx
callq 0x45d0
jmp 0x3c43
leaq 0x6b0(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x7e10
jmp 0x3c5a
leaq 0xb48(%rsp), %rdi
callq 0x4690
movq 0x468(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x468(%rsp,%rax), %rdi
xorl %esi, %esi
callq 0x3550
jmp 0x3c84
xorl %edx, %edx
movl %edx, %esi
leaq 0x468(%rsp), %rdi
callq 0x3470
jmp 0x3c97
leaq 0x468(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x30b0
jmp 0x3cae
leaq 0x468(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x30b0
jmp 0x3cc5
leaq 0x140(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x3150
jmp 0x3cdc
leaq 0x6b0(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x9170
movl %eax, 0x94(%rsp)
jmp 0x3cfa
movl 0x94(%rsp), %eax
movl %eax, 0x674(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x31c0
leaq 0xb48(%rsp), %rdi
leaq 0x674(%rsp), %rsi
callq 0x46c0
movq %rax, 0x88(%rsp)
jmp 0x3d34
movq 0x88(%rsp), %rax
movq %rax, 0x138(%rsp)
leaq 0xb48(%rsp), %rdi
callq 0x46f0
movq %rax, 0x130(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x46a0
testb $0x1, %al
jne 0x3d77
jmp 0x3f00
leaq 0xb48(%rsp), %rdi
leaq 0x674(%rsp), %rsi
callq 0x4720
movq %rax, 0x80(%rsp)
jmp 0x3d96
movq 0x80(%rsp), %rax
movq $0x1, (%rax)
jmp 0x3f2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
jmp 0x3de1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
leaq 0x680(%rsp), %rdi
callq 0x31c0
leaq 0x67f(%rsp), %rdi
callq 0x3330
jmp 0x43b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
jmp 0x43aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
jmp 0x439d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
jmp 0x3eaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
jmp 0x3e95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
jmp 0x3e88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x31c0
leaq 0x180(%rsp), %rdi
callq 0x31c0
leaq 0x17f(%rsp), %rdi
callq 0x3330
leaq 0x1a8(%rsp), %rdi
callq 0x31c0
leaq 0x1a7(%rsp), %rdi
callq 0x3330
jmp 0x4390
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
jmp 0x4383
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x31c0
jmp 0x4383
leaq 0xb48(%rsp), %rdi
leaq 0x674(%rsp), %rsi
callq 0x4720
movq %rax, 0x78(%rsp)
jmp 0x3f1c
movq 0x78(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
leaq 0x468(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x30b0
jmp 0x3f42
leaq 0x468(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x30b0
jmp 0x3f59
leaq 0x468(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x30b0
jmp 0x3f70
jmp 0x3f72
movq 0x468(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x468(%rsp,%rax), %rdi
callq 0x3600
movb %al, 0x77(%rsp)
jmp 0x3f91
movb 0x77(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3fa0
jmp 0x4141
leaq 0x468(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x30b0
jmp 0x3fb7
leaq 0x448(%rsp), %rdi
movl $0x4e, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3420
cmpq $-0x1, %rax
jne 0x40f7
leaq 0x110(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x3150
jmp 0x3fee
leaq 0x6b0(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x9170
movl %eax, 0x70(%rsp)
jmp 0x4009
movl 0x70(%rsp), %eax
movl %eax, 0x674(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x31c0
leaq 0xb48(%rsp), %rdi
leaq 0x674(%rsp), %rsi
callq 0x46c0
movq %rax, 0x68(%rsp)
jmp 0x403d
movq 0x68(%rsp), %rax
movq %rax, 0x108(%rsp)
leaq 0xb48(%rsp), %rdi
callq 0x46f0
movq %rax, 0x100(%rsp)
leaq 0x108(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x46a0
testb $0x1, %al
jne 0x407a
jmp 0x40ca
leaq 0xb48(%rsp), %rdi
leaq 0x674(%rsp), %rsi
callq 0x4720
movq %rax, 0x60(%rsp)
jmp 0x4096
movq 0x60(%rsp), %rax
movq $0x1, (%rax)
jmp 0x40f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6a8(%rsp)
movl %eax, 0x6a4(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x31c0
jmp 0x4383
leaq 0xb48(%rsp), %rdi
leaq 0x674(%rsp), %rsi
callq 0x4720
movq %rax, 0x58(%rsp)
jmp 0x40e6
movq 0x58(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x40f7
leaq 0x468(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x30b0
jmp 0x410e
leaq 0x468(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x30b0
jmp 0x4125
leaq 0x468(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0x30b0
jmp 0x413c
jmp 0x3f72
movq 0x1ee80(%rip), %rdi     # 0x22fc8
leaq 0x14f24(%rip), %rsi     # 0x19073
callq 0x32c0
movq %rax, 0x50(%rsp)
jmp 0x415b
movq 0x50(%rsp), %rdi
movl 0x678(%rsp), %esi
callq 0x35a0
movq %rax, 0x48(%rsp)
jmp 0x4173
movq 0x48(%rsp), %rdi
leaq 0x14efe(%rip), %rsi     # 0x1907d
callq 0x32c0
movq %rax, 0x40(%rsp)
jmp 0x418b
movq 0x40(%rsp), %rdi
movl 0x178(%rsp), %esi
callq 0x35a0
movq %rax, 0x38(%rsp)
jmp 0x41a3
movq 0x38(%rsp), %rdi
movq 0x1ee09(%rip), %rsi     # 0x22fb8
callq 0x3310
jmp 0x41b6
leaq 0x14eb6(%rip), %rsi     # 0x19073
leaq 0x1e8(%rsp), %rdi
callq 0x32c0
movq %rax, 0x30(%rsp)
jmp 0x41d1
movq 0x30(%rsp), %rdi
movl 0x678(%rsp), %esi
callq 0x35a0
movq %rax, 0x28(%rsp)
jmp 0x41e9
movq 0x28(%rsp), %rdi
leaq 0x14e88(%rip), %rsi     # 0x1907d
callq 0x32c0
movq %rax, 0x20(%rsp)
jmp 0x4201
movq 0x20(%rsp), %rdi
movl 0x178(%rsp), %esi
callq 0x35a0
movq %rax, 0x18(%rsp)
jmp 0x4219
movq 0x18(%rsp), %rdi
movq 0x1ed93(%rip), %rsi     # 0x22fb8
callq 0x3310
jmp 0x422c
leaq 0xb48(%rsp), %rdi
callq 0x4810
movq %rax, 0xf8(%rsp)
leaq 0xb48(%rsp), %rdi
callq 0x46f0
movq %rax, 0xf0(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x4840
testb $0x1, %al
jne 0x4274
jmp 0x4300
leaq 0xf8(%rsp), %rdi
callq 0x4860
movl (%rax), %esi
leaq 0x1e8(%rsp), %rdi
callq 0x35a0
movq %rax, 0x10(%rsp)
jmp 0x4297
movq 0x10(%rsp), %rdi
leaq 0x154d3(%rip), %rsi     # 0x19776
callq 0x32c0
movq %rax, 0x8(%rsp)
jmp 0x42af
leaq 0xf8(%rsp), %rdi
callq 0x4860
movq 0x8(%rsp), %rdi
movq 0x8(%rax), %rsi
callq 0x32a0
movq %rax, (%rsp)
jmp 0x42d0
movq (%rsp), %rdi
movq 0x1ecdd(%rip), %rsi     # 0x22fb8
callq 0x3310
jmp 0x42e2
jmp 0x42e4
leaq 0xf8(%rsp), %rdi
xorl %esi, %esi
callq 0x4880
movq %rax, 0xe8(%rsp)
jmp 0x4241
movq 0x1ecd1(%rip), %rdi     # 0x22fd8
leaq 0x678(%rsp), %rsi
callq 0x31b0
jmp 0x4316
jmp 0x3beb
movl $0x0, 0xb84(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x48c0
leaq 0x1e8(%rsp), %rdi
callq 0x34c0
leaq 0x448(%rsp), %rdi
callq 0x31c0
leaq 0x468(%rsp), %rdi
callq 0x30f0
leaq 0x6b0(%rsp), %rdi
callq 0x4920
leaq 0xb48(%rsp), %rdi
callq 0x4a00
movl 0xb84(%rsp), %eax
addq $0xb88, %rsp            # imm = 0xB88
retq
leaq 0x160(%rsp), %rdi
callq 0x48c0
leaq 0x1e8(%rsp), %rdi
callq 0x34c0
leaq 0x448(%rsp), %rdi
callq 0x31c0
leaq 0x468(%rsp), %rdi
callq 0x30f0
leaq 0x6b0(%rsp), %rdi
callq 0x4920
leaq 0xb48(%rsp), %rdi
callq 0x4a00
movq 0x6a8(%rsp), %rdi
callq 0x35c0
nop