// File: 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
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x68d0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6900
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6800
movq -0x8(%rbp), %rdi
callq 0x67b0
movq %rax, -0x38(%rbp)
cmpq $0x2, %rax
jb 0x6487
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
subq $0x1, %rsi
callq 0x6930
movq %rax, %rdi
movq -0x8(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x61a0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x2, %rcx
cmpq %rcx, %rax
je 0x6343
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x6930
movq %rax, -0x1f0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
subq $0x2, %rsi
callq 0x6930
movq -0x1f0(%rbp), %rdi
movq %rax, %rsi
callq 0x6950
movq -0x18(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
decq %rsi
callq 0x6930
movq %rax, -0x208(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $-0x2, %rsi
callq 0x6930
movq -0x208(%rbp), %rsi
movq %rax, %rdx
leaq -0x150(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x69e0
movq -0x200(%rbp), %rdi
movq -0x1f8(%rbp), %rsi
callq 0x69b0
jmp 0x63a8
leaq -0x150(%rbp), %rdi
callq 0x6a20
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $-0x2, %rsi
callq 0x6930
movq %rax, %rsi
leaq -0x1e8(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x6a50
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
decq %rsi
callq 0x6930
movq -0x210(%rbp), %rdi
movq %rax, %rsi
callq 0x14160
jmp 0x63fc
leaq -0x1e8(%rbp), %rdi
movsd 0x15c35(%rip), %xmm0    # 0x1c040
callq 0x141f0
jmp 0x6412
movq -0x10(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x6650
jmp 0x6424
movq -0x8(%rbp), %rdi
callq 0x6b10
movq -0x8(%rbp), %rdi
callq 0x6b10
leaq -0x1e8(%rbp), %rdi
callq 0x66c0
jmp 0x62c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x6a20
jmp 0x64c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x66c0
jmp 0x64c6
movq -0x8(%rbp), %rdi
callq 0x67b0
cmpq $0x1, %rax
jne 0x64bd
movq -0x20(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6930
movq -0x218(%rbp), %rdi
movq %rax, %rsi
callq 0x6650
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
movq -0x158(%rbp), %rdi
callq 0x3440
nopw %cs:(%rax,%rax)
nopl (%rax)