// File: nikosgalanis[P]Vectors-Similarity-Search-and-Clustering/programs/Clustering/../../algorithms/Clustering/clustering.h
// Function: Clustering<double>::reverse_assignment()
int reverse_assignment(void) {
			// keep a vector of the new assignments
			vector<int> new_assigned(n_points, -1);
			// initial radius
			T radius = min_dist_between_centroids() / 2;
			// keep track of the changes
			int changes = 0;
			// set a threshold in order to break the loop
			int prev_unassigned = INT_MAX;
			// keep track of unassinged points
			int unassinged = INT_MAX - 1;
			// break the loop when all the balls contain no new vectors
			while (unassinged != prev_unassigned) {
				// do a range search query for every centroid
				for (int i = 0; i < k; i++) {
					list<pair<int, T>> result;
					// the type of range search depends on what the user wants
					if (assignment_method == "reverse_LSH")
						result = lsh_instant->RangeSearch(centroids.at(i), radius, 1);
					else if (assignment_method == "reverse_Hypercube")
						result = hc_instant->RangeSearch(centroids.at(i), radius, 1);

					// iterate all the results
					typename std::list<std::pair<int,T>>::iterator pair_it;
					for (pair_it = result.begin(); pair_it !=result.end(); pair_it++) {
						// get the current vector
						int curr_vec = pair_it->first;

						// if it is still unassigned
						if (new_assigned.at(curr_vec) == -1) {
							// temporarly assign it to this centroid
							new_assigned.at(curr_vec) = i;
						}
						// if it has been already assigned
						else {
							// chcek if its distance from the current centroid, is less than the previous' one
							int prev_assigned = new_assigned.at(curr_vec); 
							T prev_dist = metrics::ManhatanDistance(feature_vectors.at(curr_vec), centroids.at(prev_assigned), space_dim);
							T new_dist = pair_it->second;
							// if it is, it is closest to the current centroid, thus change the asssigned value in the temp vector
							if (new_dist < prev_dist)
								new_assigned.at(curr_vec) = i;
						}
					}
				}

				// update the unassigned vectors count
				prev_unassigned = unassinged;
				unassinged = count_unassigned(new_assigned);
				// update the radius
				radius *= 2;
			}

			// update the untracked vectors, and check for new changes
			for (int i = 0; i < n_points; i++) {
				// for each one not tracked, use direct assignment
				if (new_assigned.at(i) == UNASSIGNED)
					new_assigned.at(i) = nearest_centroid(feature_vectors.at(i));
				// check for changes
				if (assigned_centroid.at(i) != new_assigned.at(i))
					changes++;
			}

			// update the assigned vector
			assigned_centroid = new_assigned;
			return changes;
		}

// Assembly:
subq $0x228, %rsp            # imm = 0x228
movq %rdi, 0x220(%rsp)
movq 0x220(%rsp), %rax
movq %rax, 0xa8(%rsp)
movslq 0x4(%rax), %rax
movq %rax, 0xb0(%rsp)
movl $0xffffffff, 0x204(%rsp) # imm = 0xFFFFFFFF
leaq 0x203(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x83b0
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rcx
leaq 0x208(%rsp), %rdi
leaq 0x204(%rsp), %rdx
callq 0x83c0
jmp 0x14ec2
leaq 0x203(%rsp), %rdi
callq 0x8440
movq 0xa8(%rsp), %rdi
callq 0x162c0
movsd %xmm0, 0xa0(%rsp)
jmp 0x14ee7
movsd 0xa0(%rsp), %xmm0
movsd 0x62e8(%rip), %xmm1     # 0x1b1e0
divsd %xmm1, %xmm0
movsd %xmm0, 0x1e8(%rsp)
movl $0x0, 0x1e4(%rsp)
movl $0x7fffffff, 0x1e0(%rsp) # imm = 0x7FFFFFFF
movl $0x7ffffffe, 0x1dc(%rsp) # imm = 0x7FFFFFFE
movl 0x1dc(%rsp), %eax
cmpl 0x1e0(%rsp), %eax
je 0x154fc
movl $0x0, 0x1d8(%rsp)
movq 0xa8(%rsp), %rcx
movl 0x1d8(%rsp), %eax
cmpl (%rcx), %eax
jge 0x1545f
leaq 0x1c0(%rsp), %rdi
callq 0x16450
movq 0xa8(%rsp), %rdi
addq $0x10, %rdi
leaq 0x62ef(%rip), %rsi      # 0x1b26b
callq 0x8790
testb $0x1, %al
jne 0x14f8a
jmp 0x150b2
movq 0xa8(%rsp), %rdi
movq 0x80(%rdi), %rax
movq %rax, 0x90(%rsp)
addq $0x30, %rdi
movslq 0x1d8(%rsp), %rsi
callq 0x6f30
movq %rax, 0x98(%rsp)
jmp 0x14fbc
movq 0x98(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x45a0
jmp 0x14fd3
movq 0x90(%rsp), %rsi
movsd 0x1e8(%rsp), %xmm0
leaq 0x1a8(%rsp), %rdi
leaq 0x190(%rsp), %rdx
movl $0x1, %ecx
callq 0x16460
jmp 0x15000
leaq 0x1c0(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x16900
leaq 0x1a8(%rsp), %rdi
callq 0x16940
leaq 0x190(%rsp), %rdi
callq 0x3550
jmp 0x151a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0x203(%rsp), %rdi
callq 0x8440
jmp 0x156bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x156ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x1544d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x3550
jmp 0x1544d
movq 0xa8(%rsp), %rdi
addq $0x10, %rdi
leaq 0x61c9(%rip), %rsi      # 0x1b28e
callq 0x8790
testb $0x1, %al
jne 0x150d3
jmp 0x151a0
movq 0xa8(%rsp), %rdi
movq 0x98(%rdi), %rax
movq %rax, 0x80(%rsp)
addq $0x30, %rdi
movslq 0x1d8(%rsp), %rsi
callq 0x6f30
movq %rax, 0x88(%rsp)
jmp 0x15105
movq 0x88(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x45a0
jmp 0x1511c
movq 0x80(%rsp), %rsi
movsd 0x1e8(%rsp), %xmm0
leaq 0x178(%rsp), %rdi
leaq 0x160(%rsp), %rdx
movl $0x1, %ecx
callq 0x16950
jmp 0x15149
leaq 0x1c0(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x16900
leaq 0x178(%rsp), %rdi
callq 0x16940
leaq 0x160(%rsp), %rdi
callq 0x3550
jmp 0x151a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x3550
jmp 0x1544d
jmp 0x151a2
leaq 0x158(%rsp), %rdi
callq 0x17060
leaq 0x1c0(%rsp), %rdi
callq 0x17080
movq %rax, 0x150(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x158(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x170d0
movq %rax, 0x148(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x170b0
testb $0x1, %al
jne 0x15207
jmp 0x1542a
leaq 0x158(%rsp), %rdi
callq 0x17100
movl (%rax), %eax
movl %eax, 0x144(%rsp)
movslq 0x144(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xf110
movq %rax, 0x78(%rsp)
jmp 0x15239
movq 0x78(%rsp), %rax
cmpl $-0x1, (%rax)
jne 0x1527a
movl 0x1d8(%rsp), %eax
movl %eax, 0x6c(%rsp)
movslq 0x144(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xf110
movq %rax, 0x70(%rsp)
jmp 0x1526a
movq 0x70(%rsp), %rax
movl 0x6c(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x1540c
movslq 0x144(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xf110
movq %rax, 0x60(%rsp)
jmp 0x15296
movq 0xa8(%rsp), %rdi
movq 0x60(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x140(%rsp)
addq $0x48, %rdi
movslq 0x144(%rsp), %rsi
callq 0x6f30
movq %rax, 0x58(%rsp)
jmp 0x152c4
movq 0x58(%rsp), %rsi
leaq 0x120(%rsp), %rdi
callq 0x45a0
jmp 0x152d8
movq 0xa8(%rsp), %rdi
addq $0x30, %rdi
movslq 0x140(%rsp), %rsi
callq 0x6f30
movq %rax, 0x50(%rsp)
jmp 0x152f8
movq 0x50(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0x45a0
jmp 0x1530c
movq 0xa8(%rsp), %rax
movl 0x8(%rax), %edx
leaq 0x120(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x15af0
movsd %xmm0, 0x48(%rsp)
jmp 0x15334
leaq 0x108(%rsp), %rdi
callq 0x3550
leaq 0x120(%rsp), %rdi
callq 0x3550
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x138(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x17100
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x100(%rsp)
movsd 0x100(%rsp), %xmm1
movsd 0x138(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1540a
movl 0x1d8(%rsp), %eax
movl %eax, 0x3c(%rsp)
movslq 0x144(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xf110
movq %rax, 0x40(%rsp)
jmp 0x153b7
movq 0x40(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x1540a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x153fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x3550
leaq 0x120(%rsp), %rdi
callq 0x3550
jmp 0x1544d
jmp 0x1540c
jmp 0x1540e
leaq 0x158(%rsp), %rdi
xorl %esi, %esi
callq 0x17120
movq %rax, 0xf8(%rsp)
jmp 0x151d4
leaq 0x1c0(%rsp), %rdi
callq 0x16940
movl 0x1d8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1d8(%rsp)
jmp 0x14f45
leaq 0x1c0(%rsp), %rdi
callq 0x16940
jmp 0x156ae
movl 0x1dc(%rsp), %eax
movl %eax, 0x1e0(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0x208(%rsp), %rsi
callq 0x7950
jmp 0x15484
movq 0xa8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x17150
movl %eax, 0x38(%rsp)
jmp 0x1549f
movl 0x38(%rsp), %eax
movl %eax, 0x1dc(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x7a50
movsd 0x5d21(%rip), %xmm0     # 0x1b1e0
mulsd 0x1e8(%rsp), %xmm0
movsd %xmm0, 0x1e8(%rsp)
jmp 0x14f26
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x7a50
jmp 0x156ae
movl $0x0, 0xdc(%rsp)
movq 0xa8(%rsp), %rcx
movl 0xdc(%rsp), %eax
cmpl 0x4(%rcx), %eax
jge 0x15671
movslq 0xdc(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xf110
movq %rax, 0x30(%rsp)
jmp 0x1553b
movq 0x30(%rsp), %rax
cmpl $-0x1, (%rax)
jne 0x155f4
movq 0xa8(%rsp), %rdi
addq $0x48, %rdi
movslq 0xdc(%rsp), %rsi
callq 0x6f30
movq %rax, 0x28(%rsp)
jmp 0x15569
movq 0x28(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x45a0
jmp 0x1557d
movq 0xa8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x16140
movl %eax, 0x24(%rsp)
jmp 0x15598
movslq 0xdc(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xf110
movq %rax, 0x18(%rsp)
jmp 0x155b4
movq 0x18(%rsp), %rax
movl 0x24(%rsp), %ecx
movl %ecx, (%rax)
leaq 0xc0(%rsp), %rdi
callq 0x3550
jmp 0x155f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x3550
jmp 0x156ae
movq 0xa8(%rsp), %rdi
addq $0x60, %rdi
movslq 0xdc(%rsp), %rsi
callq 0xf110
movq %rax, 0x10(%rsp)
jmp 0x15614
movq 0x10(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movslq 0xdc(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xf110
movq %rax, 0x8(%rsp)
jmp 0x1563b
movl 0x4(%rsp), %eax
movq 0x8(%rsp), %rcx
cmpl (%rcx), %eax
je 0x15659
movl 0x1e4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e4(%rsp)
jmp 0x1565b
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x15507
movq 0xa8(%rsp), %rdi
addq $0x60, %rdi
leaq 0x208(%rsp), %rsi
callq 0x8450
jmp 0x1568c
movl 0x1e4(%rsp), %eax
movl %eax, (%rsp)
leaq 0x208(%rsp), %rdi
callq 0x7a50
movl (%rsp), %eax
addq $0x228, %rsp            # imm = 0x228
retq
leaq 0x208(%rsp), %rdi
callq 0x7a50
movq 0x1f8(%rsp), %rdi
callq 0x2400
nopl (%rax,%rax)