// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq 0x1c5d5(%rip), %rax     # 0x827d8
cmpl $0x6, (%rax)
jne 0x66238
movq -0x8(%rbp), %rax
cmpl $0x0, 0x254(%rax)
jle 0x66238
leaq 0x10c19(%rip), %rdi     # 0x76e35
callq 0x18a90
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq %rcx, 0xe50(%rax)
jmp 0x664c3
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movss 0xf18(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x66254
jp 0x66254
jmp 0x662a0
movq 0x1cb45(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movss %xmm0, 0xf18(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0xf20(%rax)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x18750
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0xf18(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x730(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq %rcx, 0x738(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq 0xe50(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq %rcx, 0x730(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq $0x0, 0xe50(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0xef0(%rax)
movq -0x8(%rbp), %rax
cmpl $0xff, 0x28(%rax)
jne 0x66375
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpq $0x0, 0x730(%rax)
je 0x6633f
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x730(%rax), %rax
movl 0x6c(%rax), %eax
andl $0xff, %eax
shll $0x8, %eax
movl %eax, -0xc(%rbp)
jmp 0x66346
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x1c207(%rip), %rcx     # 0x82558
movq (%rcx), %rcx
subq %rcx, %rax
movl $0x4a8, %ecx            # imm = 0x4A8
cqto
idivq %rcx
subq $0x1, %rax
movslq -0xc(%rbp), %rcx
orq %rcx, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x3c(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpq $0x0, 0x730(%rax)
je 0x663db
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x730(%rax), %rax
cmpq $0x0, 0x60(%rax)
je 0x663db
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x730(%rax), %rax
movq 0x60(%rax), %rdi
callq 0x18a90
movq 0x1ca84(%rip), %rcx     # 0x82e40
subq %rcx, %rax
movl $0x88, %ecx
cqto
idivq %rcx
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0xe38(%rax)
jmp 0x663ed
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0xe38(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpq $0x0, 0x730(%rax)
jne 0x66413
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0x58(%rax)
jmp 0x664c3
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x1, 0xe78(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0x5c(%rax)
movq 0x1c1c5(%rip), %rax     # 0x82600
movq 0x40(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq 0x730(%rcx), %rcx
movq 0x40(%rcx), %rdi
callq *%rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0x58(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x3, 0xef8(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movzbl 0x10(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x664a6
movq -0x8(%rbp), %rax
movl $0xa9, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0xac, 0xef4(%rax)
jmp 0x664c3
movq -0x8(%rbp), %rax
movl $0x3e, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x41, 0xef4(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)