// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/p_weapon.c
// Function: ChangeWeapon
void ChangeWeapon (edict_t *ent)
{
	int i;

	if(matchstate == MATCH_RAILGUN_INPLAY && ent->health > 0)
	{
		ent->client->newweapon = FindItem ("railgun");
		return;
	}



	if (ent->client->grenade_time)
	{
		ent->client->grenade_time = level.time;
		ent->client->weapon_sound = 0;
		weapon_grenade_fire (ent, false);
		ent->client->grenade_time = 0;
	}

	ent->client->pers.lastweapon = ent->client->pers.weapon;
	ent->client->pers.weapon = ent->client->newweapon;
	ent->client->newweapon = NULL;
	ent->client->machinegun_shots = 0;

	// set visible model
	if (ent->s.modelindex == 255) {
		if (ent->client->pers.weapon)
			i = ((ent->client->pers.weapon->weapmodel & 0xff) << 8);
		else
			i = 0;
		ent->s.skinnum = (ent - g_edicts - 1) | i;
	}

	if (ent->client->pers.weapon && ent->client->pers.weapon->ammo)
		ent->client->ammo_index = ITEM_INDEX(FindItem(ent->client->pers.weapon->ammo));
	else
		ent->client->ammo_index = 0;

	if (!ent->client->pers.weapon)
	{	// dead
		ent->client->ps.gunindex = 0;
		return;
	}

	ent->client->weaponstate = WEAPON_ACTIVATING;
	ent->client->ps.gunframe = 0;
	ent->client->ps.gunindex = gi.modelindex(ent->client->pers.weapon->view_model);

	ent->client->anim_priority = ANIM_PAIN;
	if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
	{
			ent->s.frame = FRAME_crpain1;
			ent->client->anim_end = FRAME_crpain4;
	}
	else
	{
			ent->s.frame = FRAME_pain301;
			ent->client->anim_end = FRAME_pain304;
			
	}
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x1c297(%rip), %rax     # 0x687d8
cmpl $0x6, (%rax)
jne 0x4c56b
cmpl $0x0, 0x254(%rbx)
jle 0x4c56b
leaq 0xdc17(%rip), %rdi      # 0x5a16d
callq 0x189e0
movq 0x58(%rbx), %rcx
movq %rax, 0xe50(%rcx)
jmp 0x4c6c4
movq 0x58(%rbx), %rax
movss 0xf18(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x4c581
jnp 0x4c5b1
movq 0x1c818(%rip), %rcx     # 0x68da0
movss 0x4(%rcx), %xmm0
movss %xmm0, 0xf18(%rax)
xorl %ebp, %ebp
movl %ebp, 0xf20(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x186e0
movq 0x58(%rbx), %rax
movl %ebp, 0xf18(%rax)
movq 0x730(%rax), %rcx
movq %rcx, 0x738(%rax)
movq 0xe50(%rax), %rcx
movq %rcx, 0x730(%rax)
movq $0x0, 0xe50(%rax)
movl $0x0, 0xef0(%rax)
cmpl $0xff, 0x28(%rbx)
jne 0x4c61b
testq %rcx, %rcx
je 0x4c5fb
movl 0x6c(%rcx), %edx
shll $0x8, %edx
movzwl %dx, %edx
jmp 0x4c5fd
xorl %edx, %edx
movq 0x1bf54(%rip), %rsi     # 0x68558
movq %rbx, %rdi
subq (%rsi), %rdi
shrq $0x3, %rdi
imull $0x8ce2cabd, %edi, %esi # imm = 0x8CE2CABD
decl %esi
orl %esi, %edx
movl %edx, 0x3c(%rbx)
testq %rcx, %rcx
je 0x4c652
movq 0x60(%rcx), %rdi
testq %rdi, %rdi
je 0x4c652
callq 0x189e0
subq 0x1c80b(%rip), %rax     # 0x68e40
shrq $0x3, %rax
imull $0xf0f0f0f1, %eax, %ecx # imm = 0xF0F0F0F1
movq 0x58(%rbx), %rax
movl %ecx, 0xe38(%rax)
movq 0x730(%rax), %rcx
jmp 0x4c65c
movl $0x0, 0xe38(%rax)
testq %rcx, %rcx
je 0x4c6aa
movl $0x1, 0xe78(%rax)
movl $0x0, 0x5c(%rax)
movq 0x1bf87(%rip), %rax     # 0x68600
movq 0x40(%rcx), %rdi
callq *0x40(%rax)
movq 0x58(%rbx), %rcx
movl %eax, 0x58(%rcx)
movl $0x3, 0xef8(%rcx)
testb $0x1, 0x10(%rcx)
jne 0x4c6b3
movl $0x3e, 0x38(%rbx)
movl $0x41, 0xef4(%rcx)
jmp 0x4c6c4
movl $0x0, 0x58(%rax)
jmp 0x4c6c4
movl $0xa9, 0x38(%rbx)
movl $0xac, 0xef4(%rcx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq