// File: /workspace/github_c_makefile_star2_O2/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 %rbx
movq %rdi, %rbx
movq 0x1e3e1(%rip), %rax     # 0x667d8
cmpl $0x6, (%rax)
jne 0x48421
cmpl $0x0, 0x254(%rbx)
jle 0x48421
leaq 0xdd51(%rip), %rdi      # 0x5615d
callq 0x18a80
movq 0x58(%rbx), %rcx
movq %rax, 0xe50(%rcx)
jmp 0x4856c
movq 0x58(%rbx), %rcx
movss 0xf18(%rcx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x48437
jnp 0x48467
movq 0x1e962(%rip), %rax     # 0x66da0
movss 0x4(%rax), %xmm0
movss %xmm0, 0xf18(%rcx)
andl $0x0, 0xf20(%rcx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x18730
movq 0x58(%rbx), %rcx
andl $0x0, 0xf18(%rcx)
movq 0x730(%rcx), %rax
movq %rax, 0x738(%rcx)
movq 0xe50(%rcx), %rsi
movq %rsi, 0x730(%rcx)
andq $0x0, 0xe50(%rcx)
andl $0x0, 0xef0(%rcx)
cmpl $0xff, 0x28(%rbx)
jne 0x484cc
testq %rsi, %rsi
je 0x484ab
movl 0x6c(%rsi), %eax
shll $0x8, %eax
movzwl %ax, %edi
jmp 0x484ad
xorl %edi, %edi
movq 0x1e0a4(%rip), %rdx     # 0x66558
movq %rbx, %rax
subq (%rdx), %rax
movl $0x4a8, %r8d            # imm = 0x4A8
cqto
idivq %r8
decl %eax
orl %eax, %edi
movl %edi, 0x3c(%rbx)
testq %rsi, %rsi
je 0x48503
movq 0x60(%rsi), %rdi
testq %rdi, %rdi
je 0x48503
callq 0x18a80
subq 0x1e95a(%rip), %rax     # 0x66e40
movl $0x88, %ecx
cqto
idivq %rcx
movq 0x58(%rbx), %rcx
movl %eax, 0xe38(%rcx)
movq 0x730(%rcx), %rsi
jmp 0x4850a
andl $0x0, 0xe38(%rcx)
testq %rsi, %rsi
je 0x48555
movl $0x1, 0xe78(%rcx)
andl $0x0, 0x5c(%rcx)
movq 0x1e0dc(%rip), %rax     # 0x66600
movq 0x40(%rsi), %rdi
callq *0x40(%rax)
movq 0x58(%rbx), %rcx
movl %eax, 0x58(%rcx)
movl $0x3, 0xef8(%rcx)
testb $0x1, 0x10(%rcx)
jne 0x4855b
movl $0x3e, 0x38(%rbx)
movl $0x41, 0xef4(%rcx)
jmp 0x4856c
andl $0x0, 0x58(%rcx)
jmp 0x4856c
movl $0xa9, 0x38(%rbx)
movl $0xac, 0xef4(%rcx)
popq %rbx
retq