// File: /workspace/github_cpp_makefile_star2_O1/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 0x188ed(%rip), %r15     # 0x430c0
movq (%r15), %rbx
cmpq %r15, %rbx
je 0x2a850
leaq 0x15c2e(%rip), %r12     # 0x40410
leaq -0x40(%rbp), %r14
cmpl $0x2, 0xbc(%rbx)
je 0x2a848
movq 0xd0(%rbx), %rdi
callq 0x1ee1c
cmpb $0x0, (%r12)
jne 0x2a82b
movq %rbx, %rdi
callq 0x1d361
leaq 0x10(%rbx), %rdi
callq 0x125e6
testb %al, %al
je 0x2a81f
movq %rbx, %rdi
callq 0x2589b
movq 0xd0(%rbx), %rdi
callq 0x1dfda
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 0x2a7e6
leaq 0x432(%rip), %rsi       # 0x2ac89
leaq -0x40(%rbp), %r13
movq %r13, %rdi
callq 0x2af2c
leaq 0x199b7(%rip), %r12     # 0x44221
movw $0x0, (%r12)
cmpq %r13, -0x40(%rbp)
je 0x2a9c0
movl $0x1, %r14d
movq -0x30(%rbp), %rax
cmpq $0x2, %rax
je 0x2a8b3
cmpq $0x1, %rax
je 0x2a996
callq 0x41d0
movq %rax, %rcx
shrq $0x3f, %rcx
addl %eax, %ecx
andl $0xfe, %ecx
negl %ecx
addl %ecx, %eax
incl %eax
movzbl %al, %r14d
callq 0x41d0
movq %rax, %rcx
shrq $0x3f, %rcx
addq %rax, %rcx
andq $-0x2, %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
testl %r14d, %r14d
je 0x2a914
movl -0x48(%rbp), %ebx
movb $0x1, %r13b
movq -0x40(%rbp), %r15
movq 0x10(%r15), %rax
movq -0x48(%rbp), %rcx
movl %ecx, 0xbc(%rax)
incb (%r12,%rbx)
decq -0x30(%rbp)
movq %r15, %rdi
callq 0x46d0
movl $0x18, %esi
movq %r15, %rdi
callq 0x43f0
movsbl %r13b, %eax
leal 0x1(%rax), %r13d
cmpl %eax, %r14d
jg 0x2a8d8
xorl %r15d, %r15d
cmpq $0x0, -0x48(%rbp)
sete %al
testl %r14d, %r14d
je 0x2a97f
movl %r14d, %r12d
movb %al, %r15b
xorl %ebx, %ebx
cmpq $0x0, -0x48(%rbp)
sete %bl
movb $0x1, %r13b
movq -0x40(%rbp), %r14
movq 0x10(%r14), %rax
movl %r15d, 0xbc(%rax)
leaq 0x198d4(%rip), %rax     # 0x44221
incb (%rax,%rbx)
decq -0x30(%rbp)
movq %r14, %rdi
callq 0x46d0
movl $0x18, %esi
movq %r14, %rdi
callq 0x43f0
leaq -0x40(%rbp), %rax
cmpq %rax, -0x40(%rbp)
je 0x2a97f
movsbl %r13b, %eax
incb %r13b
cmpl %eax, %r12d
jg 0x2a937
leaq -0x40(%rbp), %r13
cmpq %r13, -0x40(%rbp)
leaq 0x19893(%rip), %r12     # 0x44221
jne 0x2a87b
jmp 0x2a9c0
callq 0x41d0
movq %rax, %rcx
shrq $0x3f, %rcx
addq %rax, %rcx
andq $-0x2, %rcx
subq %rcx, %rax
movq -0x40(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl %eax, 0xbc(%rcx)
movl %eax, %eax
incb (%r12,%rax)
leaq -0x58(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xb0d2(%rip), %rsi      # 0x35aa1
leaq 0xb0e8(%rip), %rdx      # 0x35abe
leaq -0x68(%rbp), %rdi
callq 0xdfec
leaq -0x68(%rbp), %rdi
callq 0xf676
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x2a9fd
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq 0x186bc(%rip), %rdi     # 0x430c0
callq 0x19ccb
leaq 0x186b0(%rip), %r14     # 0x430c0
movq %r14, %rdi
callq 0x19f7b
movq %r14, %r15
movq (%r15), %r15
cmpq %r14, %r15
je 0x2aa2d
movq %r15, %rdi
callq 0x1ca23
jmp 0x2aa1b
movq -0x40(%rbp), %rdi
cmpq %r13, %rdi
je 0x2aa4b
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x43f0
movq %rbx, %rdi
cmpq %r13, %rbx
jne 0x2aa36
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2aa7e
jmp 0x2aa7e
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x2aa81
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x2aa81
jmp 0x2aa7e
jmp 0x2aa7e
jmp 0x2aa7e
movq %rax, %rbx
movq -0x40(%rbp), %rdi
leaq -0x40(%rbp), %r15
cmpq %r15, %rdi
je 0x2aaa3
movq (%rdi), %r14
movl $0x18, %esi
callq 0x43f0
movq %r14, %rdi
cmpq %r15, %r14
jne 0x2aa8e
movq %rbx, %rdi
callq 0x4750