// File: /workspace/github_cpp_makefile_star2_O1/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 0x1cce5
cmpl $0x2, 0xbc(%rbx)
je 0x1ccb0
leaq 0x10(%rbx), %r14
movq 0xd0(%rbx), %rdi
callq 0x1ee1c
movq %r14, %rdi
callq 0x125e6
testb %al, %al
je 0x1cc6b
movq %rbx, %rdi
callq 0x2589b
movl 0xbc(%rbx), %eax
leaq 0x275a9(%rip), %rcx     # 0x44221
decb (%rax,%rcx)
movl $0x2, 0xbc(%rbx)
movq %rbx, %rdi
callq 0x1cf17
movabsq $0xb0000000b, %rax      # imm = 0xB0000000B
movq %rax, 0xc0(%rbx)
movq %rbx, %rdi
callq 0x1ca23
movq 0xd0(%rbx), %rax
movb $0xa, (%rax)
movq 0xd0(%rbx), %rdi
movq 0xd8(%rbx), %rax
movl 0x2(%rax), %eax
leaq -0x58(%rbp), %rsi
movl %eax, (%rsi)
callq 0x1ecfc
leaq -0x58(%rbp), %rdi
callq 0x2bbf6
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x1c631
jmp 0x1ced8
movl %esi, %r15d
cmpl %esi, 0xc0(%rbx)
jne 0x1ccfd
cmpl %r15d, 0xc4(%rbx)
je 0x1ced8
leaq 0x10(%rbx), %r14
movl 0xbc(%rbx), %r13d
movb 0x27514(%rip), %al      # 0x44222
xorl %r12d, %r12d
cmpb 0x2750a(%rip), %al      # 0x44221
setb %r12b
cmpl $0x2, %r13d
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 0x1cf7c
testb %al, %al
je 0x1cdfb
movq %r14, -0x38(%rbp)
movl %r13d, -0x2c(%rbp)
cmpl $0x2, %r13d
setne %al
movb 0x274c3(%rip), %cl      # 0x44221
cmpb %cl, 0x274be(%rip)      # 0x44222
setne %r13b
orb %al, %r13b
xorl %r14d, %r14d
testb %r13b, %r13b
jne 0x1cd84
movl $0x1, %edi
movl %r15d, %esi
callq 0x1cf7c
testb %al, %al
je 0x1cded
cmpl $-0x1, 0x174(%rbx)
je 0x1cda9
incl %r15d
cmpl $0xb, %r15d
cmovel %r14d, %r15d
movl %r12d, %edi
movl %r15d, %esi
callq 0x1cf7c
testb %al, %al
jne 0x1cd6e
jmp 0x1cdf3
leaq 0x122ac(%rip), %rcx     # 0x2f05c
leaq -0x58(%rbp), %rdi
movl $0x1c, %r8d
xorl %esi, %esi
xorl %edx, %edx
leaq -0x48(%rbp), %r14
callq 0x4640
movq -0x38(%rbp), %rbx
leaq -0x58(%rbp), %rdi
movl $0x39, %esi
callq 0xf4ed
leaq 0x24348(%rip), %rsi     # 0x41128
movq %rbx, %rdi
callq 0xf816
jmp 0x1cec3
movl $0x1, %r12d
movq -0x38(%rbp), %r14
movl -0x2c(%rbp), %r13d
cmpl $0x2, %r13d
movq %r14, %r13
leaq -0x48(%rbp), %r14
jne 0x1cea0
movl %r12d, 0xbc(%rbx)
movl %r12d, %eax
leaq 0x27404(%rip), %rcx     # 0x44221
incb (%rax,%rcx)
movq %rbx, %rdi
callq 0x1cfed
leaq 0x235e1(%rip), %rax     # 0x40410
cmpb $0x0, (%rax)
jne 0x1ce64
movq %rbx, %rdi
callq 0x1b1bc
xorl %edi, %edi
callq 0x43b0
leaq 0xc8(%rbx), %rdi
subq 0xc8(%rbx), %rax
movq 0x90(%rbx), %rcx
addq %rax, 0xb8(%rcx)
callq 0x43b0
leaq 0x26255(%rip), %rdi     # 0x430c0
callq 0x19f7b
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %rax
movl 0xbc(%rax), %eax
cmpl 0xbc(%rbx), %eax
je 0x1ce94
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x1c631
movq 0xd0(%rbx), %rdi
callq 0x1dfda
movl %r15d, 0xc4(%rbx)
movq %rbx, %rdi
callq 0x1d110
movq %r13, %rdi
callq 0x125e6
testb %al, %al
jne 0x1cec3
movq %rbx, %rdi
callq 0x1ca23
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x1ced8
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 0x1cef7
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x2bbf6
jmp 0x1cf0f
movq %rax, %rbx
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x1cf0f
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
movq %rbx, %rdi
callq 0x4750