// File: /workspace/github_cpp_makefile_star2_O2/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 -0x50(%rbp), %rbx
movq %rbx, 0x8(%rbx)
movq %rbx, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0x1c4fc(%rip), %r15     # 0x400b0
leaq 0x19845(%rip), %r12     # 0x3d400
leaq -0x30(%rbp), %r14
movq %r15, %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq %r15, %rax
je 0x23c2e
cmpl $0x2, 0xbc(%rax)
je 0x23bc2
movq 0xd0(%rax), %rdi
callq 0x19584
cmpb $0x0, (%r12)
jne 0x23c1d
movq -0x30(%rbp), %rdi
callq 0x17b0c
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0xe68e
testb %al, %al
je 0x23c0d
movq -0x30(%rbp), %rdi
callq 0x1fe5c
movq -0x30(%rbp), %rax
movq 0xd0(%rax), %rdi
callq 0x188f6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x24118
movq -0x30(%rbp), %rax
jmp 0x23bc2
leaq 0x311(%rip), %rsi       # 0x23f46
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x24128
leaq 0x1d5c9(%rip), %rax     # 0x41211
andw $0x0, (%rax)
cmpq %rbx, -0x50(%rbp)
je 0x23d33
movq -0x40(%rbp), %rax
pushq $0x1
popq %rcx
movl %ecx, %r14d
cmpq $0x2, %rax
je 0x23c83
cmpq $0x1, %rax
je 0x23d0c
callq 0x41e0
cqto
pushq $0x2
popq %rcx
idivq %rcx
movq %rdx, %r14
incl %r14d
callq 0x41e0
cqto
pushq $0x2
popq %rcx
idivq %rcx
movq %rdx, %r15
movl %r15d, %r13d
xorl %r12d, %r12d
cmpl %r12d, %r14d
jbe 0x23cc5
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl %r15d, 0xbc(%rax)
leaq 0x1d55d(%rip), %rax     # 0x41211
incb (%rax,%r13)
movq %rbx, %rdi
callq 0x242f6
incl %r12d
jmp 0x23c99
xorl %r13d, %r13d
testq %r15, %r15
sete %r13b
pushq $-0x1
popq %r15
incl %r15d
cmpl %r15d, %r14d
jbe 0x23c4c
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl %r13d, 0xbc(%rax)
leaq 0x1d51c(%rip), %rax     # 0x41211
incb (%rax,%r13)
movq %rbx, %rdi
callq 0x242f6
cmpq %rbx, -0x50(%rbp)
jne 0x23cd3
jmp 0x23c4c
callq 0x41e0
cqto
pushq $0x2
popq %rcx
idivq %rcx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl %edx, 0xbc(%rax)
movl %edx, %eax
leaq 0x1d4e1(%rip), %rcx     # 0x41211
incb (%rcx,%rax)
leaq 0xbdaa(%rip), %rsi      # 0x2fae4
leaq -0x70(%rbp), %rdi
leaq -0x31(%rbp), %rdx
callq 0xb292
leaq -0x70(%rbp), %rdi
callq 0xc248
leaq -0x70(%rbp), %rdi
callq 0x47e8
leaq 0x1c350(%rip), %rdi     # 0x400b0
callq 0x150cc
leaq 0x1c344(%rip), %rbx     # 0x400b0
movq %rbx, %rdi
callq 0x152e9
movq %rbx, %rax
movq (%rax), %rdi
movq %rdi, -0x30(%rbp)
cmpq %rbx, %rdi
je 0x23d8e
callq 0x1732d
movq -0x30(%rbp), %rax
jmp 0x23d77
leaq -0x50(%rbp), %rdi
callq 0x24304
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x23dbe
jmp 0x23dbe
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x47e8
jmp 0x23dc1
jmp 0x23dbe
jmp 0x23dbe
jmp 0x23dbe
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x24304
movq %rbx, %rdi
callq 0x4710