// File: /workspace/github_cpp_makefile_star2_O3/codeniko[P]mossel_tov/mossel_tov.cpp
// Function: main
int main(int argc, char **argv)
{
	//parse through moss results, delimit info by tabs
	system("./parseMoss.sh"); 
	ifstream mossresults;
	mossresults.open(MOSSRESULTS);
	if (!mossresults.is_open()) {
		cerr << "ERROR: Unable to read moss results file that was generated by parseMoss.sh" << endl;
		return 1;
	}

	vector<Match> matches; //matches collection
	vector<Student> students; //collection of all students
	string line;
	while (getline(mossresults, line)) {
		Match match;
		istringstream iss(line);
		getline(iss, match.url, '\t');
		getline(iss, match.student1, '\t');
		getline(iss, match.percent1, '\t');
		getline(iss, match.student2, '\t');
		getline(iss, match.percent2, '\t');
		getline(iss, match.numIdentical, '\t');
		Student s1(match.student1, false);
		Student s2(match.student2, false);

		//insert into student vector if new student
		vector<Student>::iterator s_it1 = find(students.begin(), students.end(), s1);
		if (s_it1 == students.end())
			students.push_back(s1);

		//insert into student vector if new student
		vector<Student>::iterator s_it2 = find(students.begin(), students.end(), s2);
		if (s_it2 == students.end())
			students.push_back(s2);

		matches.push_back(match);
	}

	mossresults.close();
	
	queue<Student> q; // Queue of students that are placed into a group
	vector< vector <Student> > groups;
	vector<Student> curGroup;

	/*Process:
	 * Start with a new (unqueued) student. This will be the first student
	 * in the current group. Find all students that have a match pair with
	 * this student based on MOSS results. For each student paired, add that 
	 * student to the current group and enqueue the student if not 
	 * already enqueued. Once the queue is empty, all the students 
	 * in the current group are related based on Moss results.*/

	for (vector<Student>::iterator student_it = students.begin(); student_it != students.end(); student_it++) {
		if (student_it->queued) //student already in queue or grouped 
			continue;

		student_it->queued = true;
		q.push(*student_it);
		curGroup.clear();

		while (!q.empty()) {
			Student studentObj = q.front();
			q.pop();
			curGroup.push_back(studentObj);
			for (vector<Match>::iterator match_it = matches.begin(); match_it != matches.end(); match_it++) {
				string student_matched = match_it->hasStudent(studentObj);
				if (student_matched != "") {
					//If 2nd student is new (not queued), add student to queue and to group
					vector<Student>::iterator s2_it;
					Student s(student_matched, false);
					s2_it = find(students.begin(), students.end(), s);
					if (!s2_it->queued) {
						s2_it->queued = true;
						q.push(*s2_it);
					}
				}
			}
		}

		groups.push_back(curGroup);
	}

	genPage(matches, groups);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5c8, %rsp            # imm = 0x5C8
leaq 0x58a0(%rip), %rdi      # 0x81e1
callq 0x2170
leaq 0x3c0(%rsp), %rbx
movq %rbx, %rdi
callq 0x21d0
leaq 0x5893(%rip), %rsi      # 0x81f0
movq %rbx, %rdi
movl $0x8, %edx
callq 0x2110
leaq 0x438(%rsp), %rdi
callq 0x2070
testb %al, %al
je 0x2dac
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rax
movaps %xmm0, (%rax)
xorl %r13d, %r13d
movq %r13, 0x10(%rax)
movq %rsp, %rax
movq %r13, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r13, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x240(%rsp), %rbx
leaq 0x78(%rsp), %r15
leaq 0x18(%rsp), %r12
movq 0x3c0(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0x3c0(%rsp), %rbp
addq %rbp, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %edx
movq %rbp, %rdi
leaq 0x58(%rsp), %rsi
callq 0x22c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2dfc
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq %r13, 0xc8(%rsp)
movb %r13b, 0xd0(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq %r13, 0xe8(%rsp)
movb %r13b, 0xf0(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
movq %r13, 0x108(%rsp)
movb %r13b, 0x110(%rsp)
leaq 0x130(%rsp), %rax
movq %rax, 0x120(%rsp)
movq %r13, 0x128(%rsp)
movb %r13b, 0x130(%rsp)
leaq 0x150(%rsp), %rax
movq %rax, 0x140(%rsp)
movq %r13, 0x148(%rsp)
movb %r13b, 0x150(%rsp)
leaq 0x170(%rsp), %rax
movq %rax, 0x160(%rsp)
movq %r13, 0x168(%rsp)
movb %r13b, 0x170(%rsp)
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
movl $0x8, %edx
callq 0x2270
movq %rbx, %rdi
leaq 0x100(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
leaq 0x200(%rsp), %rbp
movq %rbx, %rdi
leaq 0xc0(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
movq %rbx, %rdi
leaq 0x120(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
movq %rbx, %rdi
leaq 0xe0(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
movq %rbx, %rdi
leaq 0x140(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
movq %rbx, %rdi
leaq 0x160(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
movq %rbp, 0x1f0(%rsp)
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x1f0(%rsp), %r14
movq %r14, %rdi
callq 0x3a80
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x3540
movq 0x1f0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2bb0
movq 0x200(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x1e0(%rsp), %rbp
movq %rbp, 0x1d0(%rsp)
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x1d0(%rsp), %r14
movq %r14, %rdi
callq 0x3a80
movq %r12, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x3540
movq 0x1d0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2c0d
movq 0x1e0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x6a18
movq 0x8(%rsp), %rsi
cmpq %rsi, %rax
jne 0x2c38
movq %rsp, %rdi
movq %r15, %rsi
callq 0x3592
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
movq %r12, %rdx
callq 0x6a18
cmpq 0x8(%rsp), %rax
jne 0x2c56
movq %rsp, %rdi
movq %r12, %rsi
callq 0x3592
leaq 0xa0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x342a
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2c87
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x2ca9
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %rbx, %rdi
movq 0x831d(%rip), %rsi      # 0xafd0
callq 0x2220
leaq 0x2b8(%rsp), %rdi
callq 0x20b0
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0x2cea
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x2d0f
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x2d34
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x2d59
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x2d7e
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x29c0
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x29c0
movq 0x823d(%rip), %rbx      # 0xaff0
leaq 0x543a(%rip), %rsi      # 0x81f4
movl $0x4a, %edx
movq %rbx, %rdi
callq 0x21e0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x820b(%rip), %rdi      # 0xaff0
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2120
jmp 0x315b
leaq 0x3c0(%rsp), %rdi
callq 0x2060
xorps %xmm0, %xmm0
leaq 0x240(%rsp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0x6dca
xorps %xmm0, %xmm0
movaps %xmm0, 0x180(%rsp)
xorl %eax, %eax
movq %rax, 0x190(%rsp)
movq %rax, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
cmpq %rax, %rsi
je 0x30ab
leaq 0x1c0(%rsp), %r15
leaq 0xc0(%rsp), %r13
leaq 0x18(%rsp), %rbp
leaq 0x1b0(%rsp), %r12
leaq 0x78(%rsp), %rbx
cmpb $0x0, 0x20(%rsi)
jne 0x309e
movb $0x1, 0x20(%rsi)
leaq 0x240(%rsp), %rdi
movq %rsi, 0x1a0(%rsp)
callq 0x6f66
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, 0x1a8(%rsp)
cmpq %rax, %rcx
je 0x3069
movq %rax, 0x198(%rsp)
leaq 0x10(%rax), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x2edf
movq (%r14), %rsi
incq %rsi
callq 0x21b0
leaq 0x28(%r14), %rax
addq $0x18, %r14
cmpq 0x1a8(%rsp), %r14
movq %rax, %r14
jne 0x2ecb
movq 0x198(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0x3069
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x3a80
movb 0x20(%r14), %al
movb %al, 0xe0(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x723a
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x3592
movq 0xa0(%rsp), %r14
cmpq 0xa8(%rsp), %r14
je 0x3044
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x337c
movq %rbp, %rdi
leaq 0x524e(%rip), %rsi      # 0x81c9
callq 0x20a0
testl %eax, %eax
je 0x301c
movq %r15, 0x1b0(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x3a80
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x3540
movq 0x1b0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2fcf
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x6a18
cmpb $0x0, 0x20(%rax)
jne 0x2ffa
movb $0x1, 0x20(%rax)
leaq 0x240(%rsp), %rdi
movq %rax, %rsi
callq 0x6f66
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x301c
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3038
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
addq $0xc0, %r14
jmp 0x2f55
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x3069
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x250(%rsp), %r14
cmpq %r14, 0x270(%rsp)
jne 0x2f06
leaq 0x180(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x3688
movq 0x8(%rsp), %rax
movq 0x1a0(%rsp), %rsi
addq $0x28, %rsi
cmpq %rax, %rsi
jne 0x2e81
leaq 0x228(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x34a4
leaq 0x210(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x36b4
leaq 0x228(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x2591
leaq 0x210(%rsp), %rdi
callq 0x374e
leaq 0x228(%rsp), %rdi
callq 0x345a
leaq 0x40(%rsp), %rdi
callq 0x3796
leaq 0x180(%rsp), %rdi
callq 0x374e
leaq 0x240(%rsp), %rdi
callq 0x3896
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x3144
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %rsp, %rdi
callq 0x3796
leaq 0xa0(%rsp), %rdi
callq 0x345a
xorl %ebx, %ebx
leaq 0x3c0(%rsp), %rdi
callq 0x2080
movl %ebx, %eax
addq $0x5c8, %rsp            # imm = 0x5C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x210(%rsp), %rdi
callq 0x374e
jmp 0x3191
movq %rax, %rbx
leaq 0x228(%rsp), %rdi
callq 0x345a
jmp 0x3312
jmp 0x327c
jmp 0x31fb
jmp 0x31fb
movq %rax, %rbx
jmp 0x3367
jmp 0x327c
movq %rax, %rbx
movq 0x1d0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3222
movq 0x1e0(%rsp), %rsi
jmp 0x321a
movq %rax, %rbx
jmp 0x3222
movq %rax, %rbx
movq 0x1f0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3249
movq 0x200(%rsp), %rsi
jmp 0x323c
jmp 0x3246
movq %rax, %rbx
jmp 0x326a
jmp 0x3203
movq %rax, %rbx
jmp 0x3336
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3222
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x3249
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x3249
movq %rax, %rbx
movq 0x7d80(%rip), %rsi      # 0xafd0
leaq 0x240(%rsp), %rdi
callq 0x2220
leaq 0x2b8(%rsp), %rdi
callq 0x20b0
leaq 0xc0(%rsp), %rdi
callq 0x35e6
jmp 0x3336
movq %rax, %rbx
jmp 0x3312
jmp 0x32ea
jmp 0x328d
movq %rax, %rbx
jmp 0x32cc
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x32cc
movq 0x88(%rsp), %rsi
jmp 0x32c4
movq %rax, %rbx
movq 0x1b0(%rsp), %rdi
cmpq %r15, %rdi
je 0x32cc
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x32ed
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x32ed
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x3312
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x40(%rsp), %rdi
callq 0x3796
leaq 0x180(%rsp), %rdi
callq 0x374e
leaq 0x240(%rsp), %rdi
callq 0x3896
leaq 0x68(%rsp), %rax
movq 0x58(%rsp), %rdi
cmpq %rax, %rdi
je 0x3352
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %rsp, %rdi
callq 0x3796
leaq 0xa0(%rsp), %rdi
callq 0x345a
leaq 0x3c0(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x22a0