// File: /workspace/github_c_makefile_star2_O1/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 0x1c585(%rip), %rax     # 0x697d8
cmpl $0x6, (%rax)
jne 0x4d27d
cmpl $0x0, 0x254(%rbx)
jle 0x4d27d
leaq 0xdc45(%rip), %rdi      # 0x5aead
callq 0x189e0
movq 0x58(%rbx), %rcx
movq %rax, 0xe50(%rcx)
jmp 0x4d3d4
movq 0x58(%rbx), %rax
movss 0xf18(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x4d293
jnp 0x4d2c3
movq 0x1cb06(%rip), %rcx     # 0x69da0
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 0x58(%rbx), %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 0x4d331
testq %rcx, %rcx
je 0x4d311
movl 0x6c(%rcx), %edx
shll $0x8, %edx
movzwl %dx, %edx
jmp 0x4d313
xorl %edx, %edx
movq 0x1c23e(%rip), %rsi     # 0x69558
movq %rbx, %rdi
subq (%rsi), %rdi
shrq $0x3, %rdi
imull $0x8ce2cabd, %edi, %esi # imm = 0x8CE2CABD
decl %esi
orl %esi, %edx
movl %edx, 0x3c(%rbx)
xorl %edx, %edx
testq %rcx, %rcx
je 0x4d35b
movq 0x60(%rcx), %rdi
testq %rdi, %rdi
je 0x4d35b
callq 0x189e0
subq 0x1caf3(%rip), %rax     # 0x69e40
shrq $0x3, %rax
imull $0xf0f0f0f1, %eax, %edx # imm = 0xF0F0F0F1
movq 0x58(%rbx), %rax
movl %edx, 0xe38(%rax)
movq 0x58(%rbx), %rax
movq 0x730(%rax), %rcx
testq %rcx, %rcx
je 0x4d3ba
movl $0x1, 0xe78(%rax)
movl $0x0, 0x5c(%rax)
movq 0x1c277(%rip), %rax     # 0x69600
movq 0x40(%rcx), %rdi
callq *0x40(%rax)
movq 0x58(%rbx), %rcx
movl %eax, 0x58(%rcx)
movl $0x3, 0xef8(%rcx)
testb $0x1, 0x10(%rcx)
jne 0x4d3c3
movl $0x3e, 0x38(%rbx)
movl $0x41, 0xef4(%rcx)
jmp 0x4d3d4
movl $0x0, 0x58(%rax)
jmp 0x4d3d4
movl $0xa9, 0x38(%rbx)
movl $0xac, 0xef4(%rcx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq