// File: /workspace/github_cpp_makefile_star2_O3/cooljacket[P]Dormitory-distribution/main.cpp
// Function: CombGroupIntoPairs(std::vector<Student, std::allocator<Student>>&, std::vector<Student, std::allocator<Student>>&, std::vector<std::pair<Student, Student>, std::allocator<std::pair<Student, Student>>>&, std::vector<Student, std::allocator<Student>>&)
void CombGroupIntoPairs(vector<Student>& group, vector<Student>& comb, vector<pair<Student, Student> >& pairs, vector<Student>& special) {
	random_shuffle(group.begin(), group.end());
	size_t len;
	while ((len = group.size()) >= 2) {
		// 给当前group里最后一个人配对，将配对的结果也交换到group的最后，方便删除
		size_t goal = findNearestExclude(group[len-1], group, len);
		if (goal != len-2)
			swap(group[goal], group[len-2]);
		pairs.push_back(make_pair(group[len-1], group[len-2]));

		// 两者取平均作为组合的特征
		Student tmp(group[len-2]);
		tmp += group[len-1];
		tmp /= 2;
		comb.push_back(tmp);

		// 将两个人从group中删掉
		group.pop_back();
		group.pop_back();
	}

	if (group.size() == 1)
		special.push_back(group[0]);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rcx, (%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
movq (%rdi), %r15
movq 0x8(%rdi), %rbp
cmpq %rbp, %r15
je 0x3e42
leaq 0x88(%r15), %rax
cmpq %rbp, %rax
je 0x3e45
movl $0x88, %ebx
callq 0x20a0
cltq
movq %rbx, %rcx
sarq $0x3, %rcx
movabsq $-0xf0f0f0f0f0f0f0f, %rdx # imm = 0xF0F0F0F0F0F0F0F1
imulq %rdx, %rcx
incq %rcx
cqto
idivq %rcx
movq %rdx, %rax
shlq $0x7, %rax
leaq (%rax,%rdx,8), %rsi
cmpq %rsi, %rbx
je 0x3e21
leaq (%r15,%rbx), %rdi
addq %r15, %rsi
callq 0x414b
leaq (%r15,%rbx), %rax
addq $0x88, %rax
addq $0x88, %rbx
cmpq %rbp, %rax
jne 0x3de1
movq (%r12), %r15
movq 0x8(%r12), %rbp
jmp 0x3e45
movq %r15, %rbp
subq %r15, %rbp
movq %rbp, %rbx
sarq $0x3, %rbx
movabsq $-0xf0f0f0f0f0f0f0f, %rax # imm = 0xF0F0F0F0F0F0F0F1
imulq %rax, %rbx
cmpq $0x2, %rbx
jb 0x4010
leaq 0x18(%rsp), %r13
leaq -0x1(%rbx), %r14
movq %r14, %rbp
shlq $0x7, %rbp
leaq -0x8(,%rbx,8), %rdi
addq %rbp, %rdi
addq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x3cee
addq $-0x2, %rbx
cmpq %rbx, %rax
je 0x3ebe
movq (%r12), %rcx
movq %rax, %rdx
shlq $0x7, %rdx
leaq (%rdx,%rax,8), %rdi
addq %rcx, %rdi
movq %rbx, %rax
shlq $0x7, %rax
leaq (%rax,%rbx,8), %rsi
addq %rcx, %rsi
callq 0x414b
movq (%r12), %rdx
leaq (%rbp,%r14,8), %rbp
leaq (%rdx,%rbp), %rsi
movq %rbx, %rax
shlq $0x7, %rax
leaq (%rax,%rbx,8), %rbx
addq %rbx, %rdx
movq %r13, %rdi
callq 0x4be8
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x529a
movq %r13, %rdi
callq 0x43f0
addq (%r12), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x44f6
addq (%r12), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x74ee
movq %r13, %rdi
movsd 0x6159(%rip), %xmm0     # 0xa078
callq 0x7526
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x405c
movq 0x8(%r12), %rsi
movq $-0x88, %rbx
addq %rbx, %rsi
movq %rsi, 0x8(%r12)
movq %r12, %rdi
callq 0x514c
movq 0x8(%r12), %rsi
addq %rbx, %rsi
movq %rsi, 0x8(%r12)
movq %r12, %rdi
callq 0x514c
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x3f7f
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x3f9b
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x3fb7
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3fce
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x3fe5
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq (%r12), %r15
movq 0x8(%r12), %rbp
subq %r15, %rbp
movq %rbp, %rbx
sarq $0x3, %rbx
movabsq $-0xf0f0f0f0f0f0f0f, %rax # imm = 0xF0F0F0F0F0F0F0F1
imulq %rax, %rbx
cmpq $0x1, %rbx
ja 0x3e6c
cmpq $0x88, %rbp
jne 0x4025
movq (%rsp), %rdi
movq %r15, %rsi
callq 0x405c
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x43f0
jmp 0x4053
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x408c
movq %rbx, %rdi
callq 0x2370
nop