// File: /workspace/github_c_makefile_star2_O1/QwazyWabbitWOS[P]lmctf60/p_client.c
// Function: ClientBegin
void ClientBegin (edict_t *ent)
{
	int 	i;
	char	message[MAX_INFO_STRING];
	
	ent->client = game.clients + (ent - g_edicts - 1);

	//sprintf(DBuffer, "cb0 t %d p %d r %d", ent->client->ctf.teamnum,
	//	ent->client->pers.spectator, ent->client->resp.spectator);
	//Debug_Show(DBuffer);
	//ctf_BSafePrint(PRINT_HIGH, DBuffer);

	//if(ent->client->ctf.teamnum <= CTF_TEAM_OBSERVER)
	//{
	//	ent->client->pers.spectator = 1;
	//	ent->client->resp.spectator = 1;
	//}
	//else
	//{
	//	ent->client->pers.spectator = 0;
	//	ent->client->resp.spectator = 0;
	//}


	if (deathmatch->value)
	{
		ClientBeginDeathmatch (ent);
		return;
	}

	// if there is already a body waiting for us (a loadgame), just
	// take it, otherwise spawn one from scratch
	if (ent->inuse == true)
	{
		// the client has cleared the client side viewangles upon
		// connecting to the server, which is different than the
		// state when the game is saved, so we need to compensate
		// with deltaangles
		for (i=0 ; i<3 ; i++)
			ent->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(ent->client->ps.viewangles[i]);
	}
	else
	{
		// a spawn point will completely reinitialize the entity
		// except for the persistent data that was initialized at
		// ClientConnect() time
		G_InitEdict (ent);
		ent->classname = "player";
		InitClientResp (ent->client);
		PutClientInServer (ent);
	}


	//sprintf(DBuffer, "cb1 t %d p %d r %d", ent->client->ctf.teamnum,
	//	ent->client->pers.spectator, ent->client->resp.spectator);
	//Debug_Show(DBuffer);

	if (level.intermissiontime)
	{
		MoveClientToIntermission (ent);
	}
	else
	{
		// send effect if in a multiplayer game
		if (game.maxclients > 1)
		{
			gi.WriteByte (svc_muzzleflash);
			gi.WriteShort (ent-g_edicts);
			gi.WriteByte (MZ_LOGIN);
			gi.multicast (ent->s.origin, MULTICAST_PVS);

			sprintf(message, "%s entered the game\n", ent->client->pers.netname);
			ctf_BSafePrint(PRINT_HIGH, message);
		}
	}

	// make sure all view stuff is valid
	ClientEndServerFrame (ent);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, %rbx
movq 0x238a1(%rip), %rbp     # 0x69d40
movq 0x230b2(%rip), %r13     # 0x69558
movq %rdi, %rdx
subq (%r13), %rdx
movq 0x408(%rbp), %rax
shrq $0x3, %rdx
movabsq $0x6a86036fad87bc40, %rcx # imm = 0x6A86036FAD87BC40
imulq %rdx, %rcx
leaq (%rax,%rcx), %rdx
addq $-0x9140, %rdx          # imm = 0xFFFF6EC0
movq %rdx, 0x58(%rdi)
movq 0x239e4(%rip), %rdx     # 0x69ec0
movq (%rdx), %rdx
movss 0x20(%rdx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x464ee
jnp 0x46507
movq %rbx, %rdi
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x18ea0
cmpl $0x1, 0x60(%rbx)
jne 0x46551
addq %rcx, %rax
movq $-0x2449, %rcx          # imm = 0xDBB7
movss 0xe801(%rip), %xmm0     # 0x54d20
movss 0xe7fd(%rip), %xmm1     # 0x54d24
movss (%rax,%rcx,4), %xmm2
mulss %xmm0, %xmm2
divss %xmm1, %xmm2
cvttss2si %xmm2, %edx
movw %dx, -0x489a(%rax,%rcx,2)
incq %rcx
cmpq $-0x2446, %rcx          # imm = 0xDBBA
jne 0x46527
jmp 0x465eb
movq %rbx, %rdi
callq 0x18dd0
leaq 0xee33(%rip), %rax      # 0x55393
movq %rax, 0x138(%rbx)
movq 0x58(%rbx), %r14
leaq 0x1100(%r14), %r15
leaq 0x4ba2f(%rip), %rdi     # 0x91fa8
movl $0x8038, %edx           # imm = 0x8038
movq %r15, %rsi
callq 0x18c80
leaq 0x758(%r14), %r12
movl $0x6b0, %edx            # imm = 0x6B0
movq %r12, %rdi
xorl %esi, %esi
callq 0x18880
movq 0x237fd(%rip), %rax     # 0x69da0
movl (%rax), %eax
movl %eax, 0xdf0(%r14)
movq 0x235a5(%rip), %rax     # 0x69b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
testb $0x4, %al
je 0x465cc
cmpl $-0x4, (%r15)
ja 0x465cc
movl $0x0, (%r15)
addq $0xc0, %r14
movl $0x698, %edx            # imm = 0x698
movq %r12, %rdi
movq %r14, %rsi
callq 0x18c80
movq %rbx, %rdi
callq 0x18a20
movq 0x237ae(%rip), %rax     # 0x69da0
movss 0xc8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x46604
jnp 0x4660e
movq %rbx, %rdi
callq 0x190e0
jmp 0x46688
cmpl $0x2, 0x610(%rbp)
jl 0x46688
movq 0x22fe2(%rip), %r14     # 0x69600
movl $0x1, %edi
callq *0xc8(%r14)
movq %rbx, %rax
subq (%r13), %rax
shrq $0x3, %rax
imull $0x8ce2cabd, %eax, %edi # imm = 0x8CE2CABD
callq *0xd0(%r14)
movl $0x9, %edi
callq *0xc8(%r14)
leaq 0x4(%rbx), %rdi
movl $0x2, %esi
callq *0xb0(%r14)
movl $0x2c0, %edx            # imm = 0x2C0
addq 0x58(%rbx), %rdx
leaq 0x14b8f(%rip), %rsi     # 0x5b1fd
movq %rsp, %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x19700
movl $0x2, %edi
movq %r14, %rsi
callq 0x19270
movq %rbx, %rdi
callq 0x18b00
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq