// File: /workspace/github_cpp_makefile_star2_O3/lotuskip[P]yuxtapa/server/game.cpp
// Function: Game::class_switch(std::_List_iterator<Player>, e_Class)
void Game::class_switch(const list<Player>::iterator pit, e_Class newcl)
{
	if(newcl == NO_CLASS) // going spectator / resetting spectating state
	{
		if(pit->team != T_SPEC)
		{
			pit->own_vp->move_watchers();
			if(pit->is_alive())
				kill_player(pit); /* see player_left_team; it won't call this
				after we've set the team to spec! */
			--num_players[pit->team];
			pit->team = T_SPEC;
			player_left_team(pit);
			pit->cl = pit->next_cl = NO_CLASS;
			send_state_change(pit);
			pit->own_vp->set_losr(SPEC_LOS_RAD);
		}

		// place own viewpoint at the location of the viewn viewpoint:
		pit->own_vp->set_pos(pit->viewn_vp->get_pos());
		follow_change(pit, pit);
	}
	else if(newcl != pit->cl || newcl != pit->next_cl)
	{
		e_Team newteam = (pit->team != T_SPEC) ? pit->team
			: e_Team(num_players[T_PURPLE] < num_players[T_GREEN]);
		
		/* Class limit checking. In case the desired class is unavailable,
		 * human players (or what we think are human players...) just get
		 * a message and nothing happens. But for bots we just give some
		 * other class. */
		string s;
		while(check_class_limit(newteam, newcl))
		{
			// In case teams are even and player is joining a team, check
			// the other team, too:
			if(pit->team == T_SPEC && num_players[T_PURPLE] == num_players[T_GREEN]
				&& !check_class_limit(T_PURPLE, newcl))
			{
				newteam = T_PURPLE;
				break; // okay to join the purple team with this class
			}
			// else
			if(pit->botpid == -1) // not bot
			{
				s = "That class is not available.";
				Network::construct_msg(s, C_FIREB_TRAP_LIT);
				Network::send_to_player(*pit);
				return;
			}
			// else
			if((newcl = e_Class(newcl+1)) == NO_CLASS)
				newcl = C_ARCHER;
		}
		// if here, okay to change class/team
		if(pit->team == T_SPEC)
		{
			// Currently a spectator: join the weaker team (or green)
			++num_players[(pit->team = newteam)];
			post_join_msg(pit);
			if(!intermission)
			{
				send_times(pit);
				pit->stats_i->time_specced += time(NULL)
					- pit->last_switched_cl;
				time(&(pit->last_switched_cl));
			}
			send_team_upds(cur_players.end());
			// The ex-spectator might be following a now-enemy:
			if(pit->viewn_vp->get_owner()->team != pit->team)
				follow_change(pit, pit);
			pit->own_vp->clear_memory();
		}

		pit->next_cl = newcl; // will set pit->cl = pit->next_cl at spawn
		post_spawn_msg(pit);
		if(!pit->is_alive())
			send_state_change(pit);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
cmpl $0xb, %esi
jne 0x1cb1c
cmpl $0x2, 0xbc(%rbx)
jne 0x1cbf3
movq 0xd0(%rbx), %rdi
jmp 0x1cc5c
movl %esi, %r15d
cmpl %esi, 0xc0(%rbx)
jne 0x1cb34
cmpl %r15d, 0xc4(%rbx)
je 0x1cdc4
leaq 0x10(%rbx), %rax
movq %rax, -0x38(%rbp)
movl 0xbc(%rbx), %r13d
movb 0x276d9(%rip), %al      # 0x44222
movb 0x276d1(%rip), %r14b    # 0x44221
xorl %r12d, %r12d
movb %al, -0x29(%rbp)
cmpb %r14b, %al
setb %r12b
cmpl $0x2, %r13d
movl %r12d, -0x30(%rbp)
cmovnel %r13d, %r12d
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl %r12d, %edi
movl %r15d, %esi
callq 0x1ce6c
testb %al, %al
movb %r14b, -0x2a(%rbp)
je 0x1cc8a
cmpl $0x2, %r13d
setne %al
cmpb %r14b, -0x29(%rbp)
setne %r14b
orb %al, %r14b
testb %r14b, %r14b
jne 0x1cbbf
movl $0x1, %edi
movl %r15d, %esi
callq 0x1ce6c
testb %al, %al
je 0x1cceb
cmpl $-0x1, 0x174(%rbx)
je 0x1ccae
incl %r15d
cmpl $0xb, %r15d
movl $0x0, %eax
cmovel %eax, %r15d
movl %r12d, %edi
movl %r15d, %esi
callq 0x1ce6c
movl %r13d, %ecx
testb %al, %al
jne 0x1cba5
jmp 0x1cc8d
leaq 0x10(%rbx), %r14
movq 0xd0(%rbx), %rdi
callq 0x1ec86
movq %r14, %rdi
callq 0x12496
testb %al, %al
je 0x1cc17
movq %rbx, %rdi
callq 0x25636
movl 0xbc(%rbx), %eax
leaq 0x275fd(%rip), %rcx     # 0x44221
decb (%rax,%rcx)
movl $0x2, 0xbc(%rbx)
movq %rbx, %rdi
callq 0x1ce07
movabsq $0xb0000000b, %rax      # imm = 0xB0000000B
movq %rax, 0xc0(%rbx)
movq %rbx, %rdi
callq 0x1c8ec
movq 0xd0(%rbx), %rdi
movb $0xa, (%rdi)
movq 0xd8(%rbx), %rax
movl 0x2(%rax), %eax
leaq -0x58(%rbp), %rsi
movl %eax, (%rsi)
callq 0x1eb62
leaq -0x58(%rbp), %rdi
callq 0x2b7a6
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x1c4fa
jmp 0x1cdc4
movl %r13d, %ecx
cmpl $0x2, %ecx
jne 0x1cd87
movb -0x2a(%rbp), %al
cmpb %al, -0x29(%rbp)
leaq 0x2757e(%rip), %rax     # 0x44221
adcq $0x0, %rax
movb (%rax), %dl
movl -0x30(%rbp), %eax
jmp 0x1ccf3
leaq 0x123a7(%rip), %rcx     # 0x2f05c
leaq -0x58(%rbp), %rdi
movl $0x1c, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x4630
leaq -0x58(%rbp), %rdi
movl $0x39, %esi
callq 0xf3f0
leaq 0x2444b(%rip), %rsi     # 0x41128
movq -0x38(%rbp), %rdi
callq 0xf719
jmp 0x1cdab
movl $0x1, %eax
movb -0x29(%rbp), %dl
movl %eax, 0xbc(%rbx)
movl %eax, %eax
leaq 0x2751f(%rip), %rcx     # 0x44221
incb %dl
movb %dl, (%rax,%rcx)
movq %rbx, %rdi
callq 0x1ced8
leaq 0x236f2(%rip), %rax     # 0x40408
cmpb $0x0, (%rax)
jne 0x1cd4b
movq %rbx, %rdi
callq 0x1b056
xorl %edi, %edi
callq 0x43b0
leaq 0xc8(%rbx), %rdi
subq 0xc8(%rbx), %rax
movq 0x90(%rbx), %rcx
addq %rax, 0xb8(%rcx)
callq 0x43b0
leaq 0x2636e(%rip), %rdi     # 0x430c0
callq 0x19e31
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %rax
movl 0xbc(%rax), %eax
cmpl 0xbc(%rbx), %eax
je 0x1cd7b
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x1c4fa
movq 0xd0(%rbx), %rdi
callq 0x1de3c
movl %r15d, 0xc4(%rbx)
movq %rbx, %rdi
callq 0x1cffb
movq -0x38(%rbp), %rdi
callq 0x12496
testb %al, %al
jne 0x1cdab
movq %rbx, %rdi
callq 0x1c8ec
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x1cdc4
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1cde3
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x2b7a6
jmp 0x1cdff
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x1cdff
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
movq %rbx, %rdi
callq 0x4740