// File: /workspace/github_c_makefile_star2_O0/QwazyWabbitWOS[P]lmctf60/p_weapon.c
// Function: Weapon_Generic
void Weapon_Generic (edict_t *ent, int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_DEACTIVATE_LAST, int *pause_frames, int *fire_frames, void (*fire)(edict_t *ent))
{
	int		n;
	ent->client->isfiring = 0; // By default, we aren't firing;

	if(ent->deadflag || ent->s.modelindex != 255) // VWep animations screw up corpses
	{
		return;
	}

	if (ent->client->weaponstate == WEAPON_DROPPING)
	{
		if (ent->client->ps.gunframe == FRAME_DEACTIVATE_LAST)
		{
			ChangeWeapon (ent);
			return;
		}
		else if ((FRAME_DEACTIVATE_LAST - ent->client->ps.gunframe) == 4)
		{
			ent->client->anim_priority = ANIM_REVERSE;
			if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
			{
				ent->s.frame = FRAME_crpain4+1;
				ent->client->anim_end = FRAME_crpain1;
			}
			else
			{
				ent->s.frame = FRAME_pain304+1;
				ent->client->anim_end = FRAME_pain301;
				
			}
		}

		ent->client->ps.gunframe++;
		return;
	}

	if (ent->client->weaponstate == WEAPON_ACTIVATING)
	{
		if (fastswitch->value) {
			ent->client->ps.gunframe = FRAME_ACTIVATE_LAST;
		}

		if (ent->client->ps.gunframe == FRAME_ACTIVATE_LAST)
		{
			ent->client->weaponstate = WEAPON_READY;
			ent->client->ps.gunframe = FRAME_IDLE_FIRST;
			return;
		}

		ent->client->ps.gunframe++;
		return;
	}

	if ((ent->client->newweapon) && (ent->client->weaponstate != WEAPON_FIRING))
	{
		ent->client->weaponstate = WEAPON_DROPPING;
		if (fastswitch->value) {
			ChangeWeapon(ent);
			return;
		} else {
			ent->client->ps.gunframe = FRAME_DEACTIVATE_FIRST;
		}

		if ((FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) < 4)
		{
			ent->client->anim_priority = ANIM_REVERSE;
			if(ent->client->ps.pmove.pm_flags & PMF_DUCKED)
			{
				ent->s.frame = FRAME_crpain4+1;
				ent->client->anim_end = FRAME_crpain1;
			}
			else
			{
				ent->s.frame = FRAME_pain304+1;
				ent->client->anim_end = FRAME_pain301;
				
			}
		}
		return;
	}

	if (ent->client->weaponstate == WEAPON_READY)
	{
		if ( ((ent->client->latched_buttons|ent->client->buttons) & BUTTON_ATTACK) )
		{
			ent->client->latched_buttons &= ~BUTTON_ATTACK;
			if ((!ent->client->ammo_index) || 
				( ent->client->pers.inventory[ent->client->ammo_index] >= ent->client->pers.weapon->quantity))
			{
				ent->client->ps.gunframe = FRAME_FIRE_FIRST;
				ent->client->weaponstate = WEAPON_FIRING;

				// start the animation
				ent->client->anim_priority = ANIM_ATTACK;
				if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
				{
					ent->s.frame = FRAME_crattak1-1;
					ent->client->anim_end = FRAME_crattak9;
				}
				else
				{
					ent->s.frame = FRAME_attack1-1;
					ent->client->anim_end = FRAME_attack8;
				}
			}
			else
			{
				if (level.time >= ent->pain_debounce_time)
				{
					gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
					ent->pain_debounce_time = level.time + 1;
				}
				NoAmmoWeaponChange (ent);
			}
		}
		else
		{
			if (ent->client->ps.gunframe == FRAME_IDLE_LAST)
			{
				ent->client->ps.gunframe = FRAME_IDLE_FIRST;
				return;
			}

			if (pause_frames)
			{
				for (n = 0; pause_frames[n]; n++)
				{
					if (ent->client->ps.gunframe == pause_frames[n])
					{
						if (rand()&15)
							return;
					}
				}
			}

			ent->client->ps.gunframe++;
			return;
		}
	}

	if (ent->client->weaponstate == WEAPON_FIRING)
	{
		for (n = 0; fire_frames[n]; n++)
		{
			if (ent->client->ps.gunframe == fire_frames[n])
			{
				if (ent->client->quad_framenum > level.framenum)
					gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage3.wav"), 1, ATTN_NORM, 0);

				ent->client->isfiring = 1; // We are firing this frame
				fire (ent);
				break;
			}
		}

		if (!fire_frames[n]) {
			ent->client->ps.gunframe++;
			if (ent->client->newweapon && fastswitch->value) {
				ent->client->weapon_sound = 0;
				ChangeWeapon(ent);
				return;
			}
		} else {
			if (ent->client->newweapon && fastswitch->value) {
				ent->client->weapon_sound = 0;
				ChangeWeapon(ent);
				return;
			}
		}

		if (ent->client->ps.gunframe == FRAME_IDLE_FIRST+1)
			ent->client->weaponstate = WEAPON_READY;

		//bat - Change the weapon right away!
		if ((ent->client->ammo_index) && 
			( ent->client->pers.inventory[ent->client->ammo_index] < ent->client->pers.weapon->quantity))
		{
			if (level.time >= ent->pain_debounce_time)
			{
				gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
				ent->pain_debounce_time = level.time + 1;
			}
			NoAmmoWeaponChange (ent);
		}

	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq %r9, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0xf70(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x260(%rax)
jne 0x66e61
movq -0x8(%rbp), %rax
cmpl $0xff, 0x28(%rax)
je 0x66e66
jmp 0x67584
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x2, 0xe78(%rax)
jne 0x66f28
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x5c(%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x66e99
movq -0x8(%rbp), %rdi
callq 0x18820
jmp 0x67584
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
subl 0x5c(%rcx), %eax
cmpl $0x4, %eax
jne 0x66f10
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x6, 0xef8(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movzbl 0x10(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x66ef1
movq -0x8(%rbp), %rax
movl $0xad, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0xa9, 0xef4(%rax)
jmp 0x66f0e
movq -0x8(%rbp), %rax
movl $0x42, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x3e, 0xef4(%rax)
jmp 0x66f10
jmp 0x66f12
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x5c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x67584
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x1, 0xe78(%rax)
jne 0x66fb0
movq 0x1bc60(%rip), %rax     # 0x82ba0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x66f54
jp 0x66f54
jmp 0x66f62
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0x5c(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x5c(%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x66f9a
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0xe78(%rax)
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0x5c(%rax)
jmp 0x67584
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x5c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x67584
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpq $0x0, 0xe50(%rax)
je 0x670a0
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x3, 0xe78(%rax)
je 0x670a0
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x2, 0xe78(%rax)
movq 0x1bbac(%rip), %rax     # 0x82ba0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x67008
jp 0x67008
jmp 0x67016
movq -0x8(%rbp), %rdi
callq 0x18820
jmp 0x67584
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0x5c(%rax)
movl -0x18(%rbp), %eax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
subl %ecx, %eax
cmpl $0x4, %eax
jge 0x6709b
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x6, 0xef8(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movzbl 0x10(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6707c
movq -0x8(%rbp), %rax
movl $0xad, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0xa9, 0xef4(%rax)
jmp 0x67099
movq -0x8(%rbp), %rax
movl $0x42, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x3e, 0xef4(%rax)
jmp 0x6709b
jmp 0x67584
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x0, 0xe78(%rax)
jne 0x672e8
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0xe44(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
orl 0xe3c(%rcx), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x67253
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0xe44(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0xe44(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x0, 0xe38(%rax)
je 0x6713b
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
movslq 0xe38(%rcx), %rcx
movl 0x318(%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq 0x730(%rcx), %rcx
cmpl 0x5c(%rcx), %eax
jl 0x671c5
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0x5c(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x3, 0xe78(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x4, 0xef8(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movzbl 0x10(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x671a3
movq -0x8(%rbp), %rax
movl $0x9f, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0xa8, 0xef4(%rax)
jmp 0x671c0
movq -0x8(%rbp), %rax
movl $0x2d, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x35, 0xef4(%rax)
jmp 0x6724e
movq 0x1bbd4(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq -0x8(%rbp), %rax
ucomiss 0x244(%rax), %xmm0
jb 0x67245
movq 0x1b41b(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq 0x9af3(%rip), %rdi      # 0x70cef
movq 0x1b3fd(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0x38(%rbp), %rdi
movl %eax, %edx
movq -0x30(%rbp), %rax
movl $0x2, %esi
movss 0x8ccf(%rip), %xmm1     # 0x6feec
xorps %xmm2, %xmm2
movaps %xmm1, %xmm0
callq *%rax
movss 0x8cbf(%rip), %xmm0     # 0x6feec
movq 0x1bb6c(%rip), %rax     # 0x82da0
addss 0x4(%rax), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x244(%rax)
movq -0x8(%rbp), %rdi
callq 0x194b0
jmp 0x672e6
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x5c(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x67279
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0x5c(%rax)
jmp 0x67584
cmpq $0x0, -0x20(%rbp)
je 0x672d0
movl $0x0, -0x24(%rbp)
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x672ce
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x5c(%rax), %eax
movq -0x20(%rbp), %rcx
movslq -0x24(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x672c1
callq 0x19c80
andl $0xf, %eax
cmpl $0x0, %eax
je 0x672bf
jmp 0x67584
jmp 0x672c1
jmp 0x672c3
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x67287
jmp 0x672d0
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x5c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x67584
jmp 0x672e8
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x3, 0xe78(%rax)
jne 0x67584
movl $0x0, -0x24(%rbp)
movq 0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x673c7
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x5c(%rax), %eax
movq 0x10(%rbp), %rcx
movslq -0x24(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x673b7
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movss 0xf04(%rax), %xmm0
movq 0x1ba57(%rip), %rax     # 0x82da0
cvtsi2ssl (%rax), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x67399
movq 0x1b2a7(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq 0xc6f5(%rip), %rdi      # 0x73a65
movq 0x1b289(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0x48(%rbp), %rdi
movl %eax, %edx
movq -0x40(%rbp), %rax
movl $0x3, %esi
movss 0x8b5b(%rip), %xmm1     # 0x6feec
xorps %xmm2, %xmm2
movaps %xmm1, %xmm0
callq *%rax
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x1, 0xf70(%rax)
movq 0x18(%rbp), %rax
movq -0x8(%rbp), %rdi
callq *%rax
jmp 0x673c7
jmp 0x673b9
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x67304
movq 0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x67435
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x5c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5c(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpq $0x0, 0xe50(%rax)
je 0x67433
movq 0x1b7a1(%rip), %rax     # 0x82ba0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x67413
jp 0x67413
jmp 0x67433
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0xf20(%rax)
movq -0x8(%rbp), %rdi
callq 0x18820
jmp 0x67584
jmp 0x67484
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpq $0x0, 0xe50(%rax)
je 0x67482
movq 0x1b752(%rip), %rax     # 0x82ba0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x67462
jp 0x67462
jmp 0x67482
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0xf20(%rax)
movq -0x8(%rbp), %rdi
callq 0x18820
jmp 0x67584
jmp 0x67484
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x5c(%rax), %eax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x674ae
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0xe78(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x0, 0xe38(%rax)
je 0x67582
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
movslq 0xe38(%rcx), %rcx
movl 0x318(%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq 0x730(%rcx), %rcx
cmpl 0x5c(%rcx), %eax
jge 0x67582
movq 0x1b8a0(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq -0x8(%rbp), %rax
ucomiss 0x244(%rax), %xmm0
jb 0x67579
movq 0x1b0e7(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq 0x97bf(%rip), %rdi      # 0x70cef
movq 0x1b0c9(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0x58(%rbp), %rdi
movl %eax, %edx
movq -0x50(%rbp), %rax
movl $0x2, %esi
movss 0x899b(%rip), %xmm1     # 0x6feec
xorps %xmm2, %xmm2
movaps %xmm1, %xmm0
callq *%rax
movss 0x898b(%rip), %xmm0     # 0x6feec
movq 0x1b838(%rip), %rax     # 0x82da0
addss 0x4(%rax), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x244(%rax)
movq -0x8(%rbp), %rdi
callq 0x194b0
jmp 0x67584
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)