// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movl %edi, %ebx
leaq 0xe0(%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 0x580(%rsp), %rdi
callq 0x4de4
cmpl $0x3, %ebx
jne 0x4068
movq 0xd818(%rip), %rbx      # 0x10fc8
leaq 0x88bc(%rip), %rsi      # 0xc073
movl $0xd, %edx
movq %rbx, %rdi
callq 0x32e0
movq 0x8(%r12), %r15
testq %r15, %r15
je 0x37ea
movq %r15, %rdi
callq 0x3120
movq 0xd7eb(%rip), %rdi      # 0x10fc8
movq %r15, %rsi
movq %rax, %rdx
callq 0x32e0
jmp 0x3801
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x3430
movq 0xd7c0(%rip), %rdi      # 0x10fc8
leaq 0x8872(%rip), %rsi      # 0xc081
movl $0xe, %edx
callq 0x32e0
movq 0x8(%r12), %rsi
leaq 0x108(%rsp), %rdi
leaq 0x128(%rsp), %rdx
callq 0x4214
leaq 0x580(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x4f62
leaq 0x118(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3869
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xd758(%rip), %rdi      # 0x10fc8
leaq 0x8819(%rip), %rsi      # 0xc090
movl $0x13, %edx
callq 0x32e0
movq 0xd750(%rip), %rdi      # 0x10fd8
leaq 0x8(%rsp), %rsi
callq 0x3180
leaq 0x128(%rsp), %rdi
callq 0x32d0
movq 0x10(%r12), %rsi
leaq 0x128(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x3190
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x10(%r12), %rsi
leaq 0x530(%rsp), %r15
movq %r15, %rdi
callq 0x3250
leaq 0x8cb6(%rip), %rsi      # 0xc59f
movq %r15, %rdi
callq 0x33e0
movq %rax, %r15
leaq 0x330(%rsp), %rdi
callq 0x3440
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %r15, %rsi
callq 0x4214
leaq 0xa8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x877e(%rip), %rsi      # 0xc0a4
leaq 0x8781(%rip), %rdx      # 0xc0ae
leaq 0x98(%rsp), %rdi
callq 0x4538
leaq 0x48(%rsp), %r12
movq -0x10(%r12), %rcx
movq -0x8(%r12), %r8
movq 0xa0(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
cmpq %r12, %rcx
je 0x3964
movq 0x48(%rsp), %rdi
movq 0x98(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x3988
movl $0xf, %edi
cmpq %r15, %rsi
je 0x3983
movq 0xa8(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x3994
leaq 0x38(%rsp), %rdi
callq 0x30e0
jmp 0x39a5
leaq 0x98(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32c0
leaq 0x20(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x39c9
movq %rsi, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x39cf
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x10(%rsp), %rsi
leaq 0x330(%rsp), %rdi
movl $0x10, %edx
callq 0x3050
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3a1e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0x3a3b
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x3a52
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x38(%rsp), %rax
movl $0x0, (%rax)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x58(%rsp), %r12
leaq 0xb8(%rsp), %r15
cmpl $0x0, 0x8(%rsp)
jle 0x3fc2
movq 0xd549(%rip), %rdi      # 0x10fd8
leaq 0x38(%rsp), %rsi
callq 0x3180
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x3aaa
movq %rax, 0x18(%rsp)
movslq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x4252
leaq 0x580(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x51b4
leaq 0xd8(%rsp), %rdi
callq 0x4bb2
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 0x3390
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3490
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3490
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x44a2
leaq 0x580(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x618e
movl %eax, 0x4(%rsp)
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x3ba9
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x3bf3
movl 0x4(%rsp), %eax
movq %r14, %r8
movq %r8, %rcx
movq %rdi, %rdx
movl 0x20(%rdi), %esi
xorl %edi, %edi
cmpl %eax, %esi
setl %dil
movq %rdx, %r8
cmovlq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x3bbd
cmpq %r14, %r8
je 0x3bf3
cmpl %eax, %esi
cmovlq %rcx, %rdx
cmpl 0x20(%rdx), %eax
jge 0x3fa8
leaq 0xd8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x4286
movq $0x1, (%rax)
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3490
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3490
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3490
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x148(%rsp,%rax)
jne 0x3e2c
leaq (%rsp,%rax), %rdi
addq $0x128, %rdi            # imm = 0x128
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3490
movq %r12, %rdi
movl $0x4e, %esi
xorl %edx, %edx
callq 0x3360
cmpq $-0x1, %rax
jne 0x3d98
leaq 0xc8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x44a2
leaq 0x580(%rsp), %rdi
movq %r15, %rsi
callq 0x618e
movl %eax, 0x4(%rsp)
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x3d35
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x3d7f
movl 0x4(%rsp), %eax
movq %r14, %r8
movq %r8, %rcx
movq %rdi, %rdx
movl 0x20(%rdi), %esi
xorl %edi, %edi
cmpl %eax, %esi
setl %dil
movq %rdx, %r8
cmovlq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x3d49
cmpq %r14, %r8
je 0x3d7f
cmpl %eax, %esi
cmovlq %rcx, %rdx
cmpl 0x20(%rdx), %eax
jge 0x3e12
leaq 0xd8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x4286
movq $0x1, (%rax)
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3490
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3490
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3490
jmp 0x3c81
leaq 0xd8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x4286
incq (%rax)
jmp 0x3d98
movl $0x9, %edx
movq 0xd190(%rip), %rdi      # 0x10fc8
leaq 0x8270(%rip), %rsi      # 0xc0af
callq 0x32e0
movl 0x8(%rsp), %esi
movq 0xd179(%rip), %rdi      # 0x10fc8
callq 0x3450
movq %rax, %r13
movl $0xe, %edx
movq %rax, %rdi
leaq 0x8253(%rip), %rsi      # 0xc0b9
callq 0x32e0
movl 0x38(%rsp), %esi
movq %r13, %rdi
callq 0x3450
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movl $0x9, %edx
leaq 0x330(%rsp), %rdi
leaq 0x81fa(%rip), %rsi      # 0xc0af
callq 0x32e0
movl 0x8(%rsp), %esi
leaq 0x330(%rsp), %rdi
callq 0x3450
movq %rax, %r13
movl $0xe, %edx
movq %rax, %rdi
leaq 0x81dc(%rip), %rsi      # 0xc0b9
callq 0x32e0
movl 0x38(%rsp), %esi
movq %r13, %rdi
callq 0x3450
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq 0xf0(%rsp), %rbp
cmpq %r14, %rbp
je 0x3f92
movl 0x20(%rbp), %esi
leaq 0x330(%rsp), %rdi
callq 0x3450
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
leaq 0x8695(%rip), %rsi      # 0xc5dc
callq 0x32e0
movq 0x28(%rbp), %rsi
movq %r13, %rdi
callq 0x31b0
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 0x31d0
movq %rbp, %rdi
callq 0x31e0
movq %rax, %rbp
cmpq %r14, %rax
jne 0x3f25
movq 0xd03f(%rip), %rdi      # 0x10fd8
leaq 0x8(%rsp), %rsi
callq 0x3180
jmp 0x3a7d
leaq 0xd8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x4286
incq (%rax)
jmp 0x3c0c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3fd9
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0xcfe0(%rip), %rax      # 0x10fc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x338(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x330(%rsp,%rcx)
callq 0x3220
leaq 0x428(%rsp), %rdi
callq 0x30f0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x402d
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x128(%rsp), %rdi
callq 0x30c0
leaq 0x580(%rsp), %rdi
callq 0x42ec
leaq 0xd8(%rsp), %rdi
callq 0x4452
xorl %eax, %eax
addq $0xa18, %rsp            # imm = 0xA18
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xcf81(%rip), %rdi      # 0x10ff0
leaq 0x7fca(%rip), %rsi      # 0xc040
movl $0x32, %edx
callq 0x32e0
movq 0xcf69(%rip), %rdi      # 0x10ff0
callq 0x3130
movl $0x1, %edi
callq 0x3300
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x40b9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x40b9
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0x40db
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x40db
movq %rax, %rbx
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x41bc
movq 0x48(%rsp), %rsi
incq %rsi
jmp 0x41b7
movq %rax, %rbx
jmp 0x41bc
movq %rax, %rbx
jmp 0x41c9
movq %rax, %rbx
jmp 0x41e5
jmp 0x414d
jmp 0x414d
movq %rax, %rbx
leaq 0x118(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x41f2
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x41f2
jmp 0x414d
movq %rax, %rbx
jmp 0x41ff
movq %rax, %rbx
jmp 0x41f2
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x41a5
movq 0x88(%rsp), %rsi
jmp 0x4194
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x41a5
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x41a5
jmp 0x41a2
jmp 0x41a2
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x41bc
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
leaq 0x330(%rsp), %rdi
callq 0x33c0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x41e5
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x128(%rsp), %rdi
callq 0x30c0
leaq 0x580(%rsp), %rdi
callq 0x42ec
leaq 0xd8(%rsp), %rdi
callq 0x4452
movq %rbx, %rdi
callq 0x3470