// File: /workspace/github_cpp_makefile_star2_O3/lotuskip[P]yuxtapa/server/cmds.cpp
// Function: shuffle_teams()
void shuffle_teams()
{
	// Gather the players who are currently playing, and kill them all:
	list<list<Player>::iterator> playing_players;
	list<Player>::iterator it;
	for(it = cur_players.begin(); it != cur_players.end(); ++it)
	{
		if(it->team != T_SPEC)
		{
			it->own_vp->move_watchers();
			if(!intermission)
			{
				Game::del_owneds(it);
				if(it->is_alive())
					kill_player(it);
				it->own_vp->clear_memory();
			}
			playing_players.push_back(it);
		}
	}

	playing_players.sort(pl_level_cmp);

	char ch, num;
	e_Team t;
	num_players[T_GREEN] = num_players[T_PURPLE] = 0;
	while(!playing_players.empty())
	{
		if(playing_players.size() == 1)
		{
			++num_players[(playing_players.front()->team = e_Team(random()%2))];
			break; // done
		}
		// else
		if(playing_players.size() == 2)
			num = 1;
		else
			num = 1 + random()%2; // 1 or 2
		t = e_Team(random()%2);
		for(ch = 0; ch < num; ++ch)
		{
			playing_players.front()->team = t;
			++num_players[t];
			playing_players.pop_front();
		}
		t = (t == T_GREEN) ? T_PURPLE : T_GREEN;
		for(ch = 0; ch < num; ++ch)
		{
			playing_players.front()->team = t;
			++num_players[t];
			playing_players.pop_front();
			// This can happen if there's an odd number of players:
			if(playing_players.empty())
				break;
		}
	} // while playing_players not empty
	
	Network::to_chat("The teams have been shuffled!");
	Game::construct_team_msgs(cur_players.end());
	Game::send_team_upds(cur_players.end());
	for(it = cur_players.begin(); it != cur_players.end(); ++it)
		Game::send_state_change(it);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq -0x40(%rbp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x18cc6(%rip), %r15     # 0x430c0
movq (%r15), %rbx
cmpq %r15, %rbx
je 0x2a477
leaq 0x15fff(%rip), %r12     # 0x40408
leaq -0x40(%rbp), %r14
cmpl $0x2, 0xbc(%rbx)
je 0x2a46f
movq 0xd0(%rbx), %rdi
callq 0x1ec86
cmpb $0x0, (%r12)
jne 0x2a452
movq %rbx, %rdi
callq 0x1d23a
leaq 0x10(%rbx), %rdi
callq 0x12496
testb %al, %al
je 0x2a446
movq %rbx, %rdi
callq 0x25636
movq 0xd0(%rbx), %rdi
callq 0x1de3c
movl $0x18, %edi
callq 0x43e0
movq %rbx, 0x10(%rax)
movq %rax, %rdi
movq %r14, %rsi
callq 0x4060
incq -0x30(%rbp)
movq (%rbx), %rbx
cmpq %r15, %rbx
jne 0x2a40d
leaq 0x414(%rip), %rsi       # 0x2a892
leaq -0x40(%rbp), %r13
movq %r13, %rdi
callq 0x2ab20
leaq 0x19d90(%rip), %r12     # 0x44221
movw $0x0, (%r12)
cmpq %r13, -0x40(%rbp)
je 0x2a5c9
movq -0x30(%rbp), %r15
callq 0x41d0
movq %rax, %r14
shrq $0x3f, %rax
addq %r14, %rax
andq $-0x2, %rax
subq %rax, %r14
movl $0x1, %ebx
cmpq $0x2, %r15
je 0x2a4fa
cmpq $0x1, %r15
je 0x2a5b3
callq 0x41d0
movq %rax, %rcx
shrq $0x3f, %rcx
addq %rax, %rcx
andq $-0x2, %rcx
subq %rcx, %rax
movl %r14d, %ebx
movl %eax, %r14d
incl %ebx
jne 0x2a4fd
movq -0x40(%rbp), %r14
jmp 0x2a5a1
movq %r14, %rax
movq %rax, -0x48(%rbp)
movl %eax, %r15d
movb $0x1, %r13b
movq -0x40(%rbp), %r12
movq 0x10(%r12), %rax
movl %r14d, 0xbc(%rax)
leaq 0x19d03(%rip), %rax     # 0x44221
incb (%rax,%r15)
decq -0x30(%rbp)
movq %r12, %rdi
callq 0x46c0
movl $0x18, %esi
movq %r12, %rdi
callq 0x43f0
movsbl %r13b, %eax
leal 0x1(%rax), %r13d
cmpl %eax, %ebx
jg 0x2a507
xorl %r12d, %r12d
cmpq $0x0, -0x48(%rbp)
sete %r12b
movq -0x40(%rbp), %r14
movb $0x1, %r15b
leaq -0x40(%rbp), %r13
movq 0x10(%r14), %rax
movl %r12d, 0xbc(%rax)
leaq 0x19cb1(%rip), %rax     # 0x44221
incb (%rax,%r12)
decq -0x30(%rbp)
movq %r14, %rdi
callq 0x46c0
movl $0x18, %esi
movq %r14, %rdi
callq 0x43f0
movq -0x40(%rbp), %r14
cmpq %r13, %r14
je 0x2a5a1
movsbl %r15b, %eax
incb %r15b
cmpl %eax, %ebx
jg 0x2a55e
cmpq %r13, %r14
leaq 0x19c76(%rip), %r12     # 0x44221
jne 0x2a4a2
jmp 0x2a5c9
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movl %r14d, 0xbc(%rax)
movl %r14d, %eax
incb (%r12,%rax)
leaq -0x58(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xb4b9(%rip), %rsi      # 0x35a91
leaq 0xb4cf(%rip), %rdx      # 0x35aae
leaq -0x68(%rbp), %rdi
callq 0xe01c
leaq -0x68(%rbp), %rdi
callq 0xf579
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x2a606
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq 0x18ab3(%rip), %rdi     # 0x430c0
callq 0x19b97
leaq 0x18aa7(%rip), %r14     # 0x430c0
movq %r14, %rdi
callq 0x19e31
movq %r14, %r15
movq (%r15), %r15
cmpq %r14, %r15
je 0x2a636
movq %r15, %rdi
callq 0x1c8ec
jmp 0x2a624
movq -0x40(%rbp), %rdi
cmpq %r13, %rdi
je 0x2a654
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x43f0
movq %rbx, %rdi
cmpq %r13, %rbx
jne 0x2a63f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2a687
jmp 0x2a687
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x2a68a
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x2a68a
jmp 0x2a687
jmp 0x2a687
jmp 0x2a687
movq %rax, %rbx
movq -0x40(%rbp), %rdi
leaq -0x40(%rbp), %r15
cmpq %r15, %rdi
je 0x2a6ac
movq (%rdi), %r14
movl $0x18, %esi
callq 0x43f0
movq %r14, %rdi
cmpq %r15, %r14
jne 0x2a697
movq %rbx, %rdi
callq 0x4740