// File: /workspace/github_cpp_makefile_star2_O1/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), %rbx
movq 0x8(%rdi), %r14
cmpq %r14, %rbx
je 0x3ed2
leaq 0x88(%rbx), %rax
cmpq %r14, %rax
je 0x3ed2
movl $0x88, %r13d
callq 0x20a0
cltq
movq %r13, %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, %r13
je 0x3ebc
leaq (%rbx,%r13), %rdi
addq %rbx, %rsi
callq 0x41d3
leaq (%rbx,%r13), %rax
addq $0x88, %rax
addq $0x88, %r13
cmpq %r14, %rax
jne 0x3e7c
movq (%r12), %rsi
movq 0x8(%r12), %rax
subq %rsi, %rax
movq %rax, %rbp
sarq $0x3, %rbp
movabsq $-0xf0f0f0f0f0f0f0f, %rcx # imm = 0xF0F0F0F0F0F0F0F1
imulq %rcx, %rbp
cmpq $0x2, %rbp
jb 0x40a2
leaq 0x18(%rsp), %r13
movq $-0x88, %r14
leaq -0x1(%rbp), %r15
movq %r15, %rbx
shlq $0x7, %rbx
leaq (%rbx,%rbp,8), %rdi
addq $-0x8, %rdi
addq %rsi, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x3d88
addq $-0x2, %rbp
cmpq %rbp, %rax
je 0x3f58
movq (%r12), %rcx
movq %rax, %rdx
shlq $0x7, %rdx
leaq (%rdx,%rax,8), %rdi
addq %rcx, %rdi
movq %rbp, %rax
shlq $0x7, %rax
leaq (%rax,%rbp,8), %rsi
addq %rcx, %rsi
callq 0x41d3
movq (%r12), %rdx
leaq (%rbx,%r15,8), %rbx
leaq (%rdx,%rbx), %rsi
movq %rbp, %rax
shlq $0x7, %rax
leaq (%rax,%rbp,8), %rbp
addq %rbp, %rdx
movq %r13, %rdi
callq 0x4be8
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x52b4
movq %r13, %rdi
callq 0x4406
addq (%r12), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x450c
addq (%r12), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x74e6
movq %r13, %rdi
movsd 0x60c0(%rip), %xmm0     # 0xa078
callq 0x751e
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x40ea
movq 0x8(%r12), %rsi
addq %r14, %rsi
movq %rsi, 0x8(%r12)
movq %r12, %rdi
callq 0x515e
movq 0x8(%r12), %rsi
addq %r14, %rsi
movq %rsi, 0x8(%r12)
movq %r12, %rdi
callq 0x515e
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x4011
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x402d
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4049
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x4060
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x4077
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq (%r12), %rsi
movq 0x8(%r12), %rax
subq %rsi, %rax
movq %rax, %rbp
sarq $0x3, %rbp
movabsq $-0xf0f0f0f0f0f0f0f, %rcx # imm = 0xF0F0F0F0F0F0F0F1
imulq %rcx, %rbp
cmpq $0x1, %rbp
ja 0x3f09
cmpq $0x88, %rax
jne 0x40b3
movq (%rsp), %rdi
callq 0x40ea
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 0x4406
jmp 0x40e1
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x411a
movq %rbx, %rdi
callq 0x2370
nop