// File: /workspace/github_cpp_makefile_star2_O1/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 0x58a4(%rip), %rdi      # 0x81e1
callq 0x2170
leaq 0x3c0(%rsp), %rbx
movq %rbx, %rdi
callq 0x21d0
leaq 0x5897(%rip), %rsi      # 0x81f0
movq %rbx, %rdi
movl $0x8, %edx
callq 0x2110
leaq 0x438(%rsp), %rdi
callq 0x2070
testb %al, %al
je 0x2da5
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rax
movaps %xmm0, (%rax)
xorl %r14d, %r14d
movq %r14, 0x10(%rax)
movq %rsp, %rax
movq %r14, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r14, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x240(%rsp), %r15
leaq 0x78(%rsp), %r13
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 0x2df5
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq %r14, 0xc8(%rsp)
movb %r14b, 0xd0(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq %r14, 0xe8(%rsp)
movb %r14b, 0xf0(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
movq %r14, 0x108(%rsp)
movb %r14b, 0x110(%rsp)
leaq 0x130(%rsp), %rax
movq %rax, 0x120(%rsp)
movq %r14, 0x128(%rsp)
movb %r14b, 0x130(%rsp)
leaq 0x150(%rsp), %rax
movq %rax, 0x140(%rsp)
movq %r14, 0x148(%rsp)
movb %r14b, 0x150(%rsp)
leaq 0x170(%rsp), %rax
movq %rax, 0x160(%rsp)
movq %r14, 0x168(%rsp)
movb %r14b, 0x170(%rsp)
movq %r15, %rdi
leaq 0x58(%rsp), %rsi
movl $0x8, %edx
callq 0x2270
movq %r15, %rdi
leaq 0x100(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
leaq 0x200(%rsp), %rbp
movq %r15, %rdi
leaq 0xc0(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
movq %r15, %rdi
leaq 0x120(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
movq %r15, %rdi
leaq 0xe0(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
movq %r15, %rdi
leaq 0x140(%rsp), %rsi
movl $0x9, %edx
callq 0x22c0
movq %r15, %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), %rbx
movq %rbx, %rdi
callq 0x3a54
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x3532
movq 0x1f0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2bac
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), %rbx
movq %rbx, %rdi
callq 0x3a54
movq %r12, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x3532
movq 0x1d0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2c09
movq 0x1e0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
callq 0x698a
cmpq 0x8(%rsp), %rax
jne 0x2c2c
movq %rsp, %rdi
movq %r13, %rsi
callq 0x3584
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
callq 0x698a
cmpq 0x8(%rsp), %rax
jne 0x2c4f
movq %rsp, %rdi
movq %r12, %rsi
callq 0x3584
leaq 0xa0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x3422
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2c80
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x2ca2
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %r15, %rdi
movq 0x8324(%rip), %rsi      # 0xafd0
callq 0x2220
leaq 0x2b8(%rsp), %rdi
callq 0x20b0
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0x2ce3
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x2d08
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x2d2d
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x2d52
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x2d77
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x29bc
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x29bc
movq 0x8244(%rip), %rbx      # 0xaff0
leaq 0x5441(%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 0x8212(%rip), %rdi      # 0xaff0
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2120
jmp 0x3153
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 0x6d5a
xorps %xmm0, %xmm0
movaps %xmm0, 0x180(%rsp)
xorl %eax, %eax
movq %rax, 0x190(%rsp)
movq %rax, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq (%rsp), %r14
cmpq 0x8(%rsp), %r14
je 0x30a3
leaq 0x1c0(%rsp), %r15
leaq 0xc0(%rsp), %r13
leaq 0x18(%rsp), %rbp
leaq 0x1b0(%rsp), %r12
leaq 0x78(%rsp), %rbx
cmpb $0x0, 0x20(%r14)
jne 0x3094
movb $0x1, 0x20(%r14)
leaq 0x240(%rsp), %rdi
movq %r14, %rsi
callq 0x6ef6
movq %r14, 0x1a0(%rsp)
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, 0x1a8(%rsp)
cmpq %rax, %rcx
je 0x3064
movq %rax, 0x198(%rsp)
leaq 0x10(%rax), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x2eda
movq (%r14), %rsi
incq %rsi
callq 0x21b0
leaq 0x28(%r14), %rax
addq $0x18, %r14
cmpq 0x1a8(%rsp), %r14
movq %rax, %r14
jne 0x2ec6
movq 0x198(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0x3064
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x3a54
movb 0x20(%r14), %al
movb %al, 0xe0(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x71ca
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x3584
movq 0xa0(%rsp), %r14
cmpq 0xa8(%rsp), %r14
je 0x303f
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3374
movq %rbp, %rdi
leaq 0x5253(%rip), %rsi      # 0x81c9
callq 0x20a0
testl %eax, %eax
je 0x3017
movq %r15, 0x1b0(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x3a54
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x3532
movq 0x1b0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2fca
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x698a
cmpb $0x0, 0x20(%rax)
jne 0x2ff5
movb $0x1, 0x20(%rax)
leaq 0x240(%rsp), %rdi
movq %rax, %rsi
callq 0x6ef6
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x3017
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3033
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
addq $0xc0, %r14
jmp 0x2f50
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x3064
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x250(%rsp), %r14
cmpq %r14, 0x270(%rsp)
jne 0x2f01
leaq 0x180(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x367a
movq 0x1a0(%rsp), %r14
addq $0x28, %r14
cmpq 0x8(%rsp), %r14
jne 0x2e77
leaq 0x228(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x3496
leaq 0x210(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x36a6
leaq 0x228(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x258d
leaq 0x210(%rsp), %rdi
callq 0x3740
leaq 0x228(%rsp), %rdi
callq 0x3452
leaq 0x40(%rsp), %rdi
callq 0x3782
leaq 0x180(%rsp), %rdi
callq 0x3740
leaq 0x240(%rsp), %rdi
callq 0x3878
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x313c
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %rsp, %rdi
callq 0x3782
leaq 0xa0(%rsp), %rdi
callq 0x3452
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 0x3740
jmp 0x3189
movq %rax, %rbx
leaq 0x228(%rsp), %rdi
callq 0x3452
jmp 0x330a
jmp 0x3274
jmp 0x31f3
jmp 0x31f3
movq %rax, %rbx
jmp 0x335f
jmp 0x3274
movq %rax, %rbx
movq 0x1d0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x321a
movq 0x1e0(%rsp), %rsi
jmp 0x3212
movq %rax, %rbx
jmp 0x321a
movq %rax, %rbx
movq 0x1f0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3241
movq 0x200(%rsp), %rsi
jmp 0x3234
jmp 0x323e
movq %rax, %rbx
jmp 0x3262
jmp 0x31fb
movq %rax, %rbx
jmp 0x332e
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x321a
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x3241
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x3241
movq %rax, %rbx
movq 0x7d88(%rip), %rsi      # 0xafd0
leaq 0x240(%rsp), %rdi
callq 0x2220
leaq 0x2b8(%rsp), %rdi
callq 0x20b0
leaq 0xc0(%rsp), %rdi
callq 0x35d8
jmp 0x332e
movq %rax, %rbx
jmp 0x330a
jmp 0x32e2
jmp 0x3285
movq %rax, %rbx
jmp 0x32c4
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x32c4
movq 0x88(%rsp), %rsi
jmp 0x32bc
movq %rax, %rbx
movq 0x1b0(%rsp), %rdi
cmpq %r15, %rdi
je 0x32c4
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x32e5
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x32e5
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x330a
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x21b0
leaq 0x40(%rsp), %rdi
callq 0x3782
leaq 0x180(%rsp), %rdi
callq 0x3740
leaq 0x240(%rsp), %rdi
callq 0x3878
leaq 0x68(%rsp), %rax
movq 0x58(%rsp), %rdi
cmpq %rax, %rdi
je 0x334a
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %rsp, %rdi
callq 0x3782
leaq 0xa0(%rsp), %rdi
callq 0x3452
leaq 0x3c0(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x22a0