// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/p_weapon.c
// Function: Weapon_Grenade
void Weapon_Grenade (edict_t *ent)
{
	if ((ent->client->newweapon) && (ent->client->weaponstate == WEAPON_READY))
	{
		ChangeWeapon (ent);
		return;
	}

	if (ent->client->weaponstate == WEAPON_ACTIVATING)
	{
		ent->client->weaponstate = WEAPON_READY;
		ent->client->ps.gunframe = 16;
		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->pers.inventory[ent->client->ammo_index])
			{
				ent->client->ps.gunframe = 1;
				ent->client->weaponstate = WEAPON_FIRING;
				ent->client->grenade_time = 0;
			}
			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);
			}
			return;
		}

		if ((ent->client->ps.gunframe == 29) || (ent->client->ps.gunframe == 34) || (ent->client->ps.gunframe == 39) || (ent->client->ps.gunframe == 48))
		{
			if (rand()&15)
				return;
		}

		if (++ent->client->ps.gunframe > 48)
			ent->client->ps.gunframe = 16;
		return;
	}

	if (ent->client->weaponstate == WEAPON_FIRING)
	{
		if (ent->client->ps.gunframe == 5)
			gi.sound(ent, CHAN_WEAPON, gi.soundindex("weapons/hgrena1b.wav"), 1, ATTN_NORM, 0);

		if (ent->client->ps.gunframe == 11)
		{
			if (!ent->client->grenade_time)
			{
				ent->client->grenade_time = level.time + GRENADE_TIMER + 0.2;
				ent->client->weapon_sound = gi.soundindex("weapons/hgrenc1b.wav");
			}

			// they waited too long, detonate it in their hand
			if (!ent->client->grenade_blew_up && level.time >= ent->client->grenade_time)
			{
				ent->client->weapon_sound = 0;
				weapon_grenade_fire (ent, true);
				ent->client->grenade_blew_up = true;
			}

			if (ent->client->buttons & BUTTON_ATTACK)
				return;

			if (ent->client->grenade_blew_up)
			{
				if (level.time >= ent->client->grenade_time)
				{
					ent->client->ps.gunframe = 15;
					ent->client->grenade_blew_up = false;
				}
				else
				{
					return;
				}
			}
		}

		if (ent->client->ps.gunframe == 12)
		{
			ent->client->weapon_sound = 0;
			weapon_grenade_fire (ent, false);
			ent->client->grenade_time = 0;
		}

		if ((ent->client->ps.gunframe == 15) && (level.time < ent->client->grenade_time))
			return;

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

		if (ent->client->ps.gunframe == 16)
		{
			ent->client->grenade_time = 0;
			ent->client->weaponstate = WEAPON_READY;
		}
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x58(%rdi), %rcx
cmpq $0x0, 0xe50(%rcx)
setne %dl
movl 0xe78(%rcx), %eax
testl %eax, %eax
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x48f9c
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x18800
testl %eax, %eax
je 0x490d4
cmpl $0x3, %eax
je 0x48fc5
cmpl $0x1, %eax
jne 0x4923f
andl $0x0, 0xe78(%rcx)
movl $0x10, 0x5c(%rcx)
jmp 0x4923f
movl 0x5c(%rcx), %eax
cmpl $0x5, %eax
jne 0x49002
movq 0x1d62c(%rip), %rax     # 0x66600
movq 0x20(%rax), %r14
leaq 0xdeae(%rip), %rdi      # 0x56e8d
callq *0x48(%rax)
pushq $0x1
popq %rsi
movss 0x5f3b(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r14
movq 0x58(%rbx), %rcx
movl 0x5c(%rcx), %eax
cmpl $0xb, %eax
jne 0x4909a
movss 0xf18(%rcx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x49064
jp 0x49064
movq 0x1dd7c(%rip), %rax     # 0x66da0
movss 0x4(%rax), %xmm0
addss 0x5edb(%rip), %xmm0     # 0x4ef0c
cvtss2sd %xmm0, %xmm0
addsd 0x8bb3(%rip), %xmm0     # 0x51bf0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xf18(%rcx)
movq 0x1d5b0(%rip), %rax     # 0x66600
leaq 0xc596(%rip), %rdi      # 0x555ed
callq *0x48(%rax)
movq 0x58(%rbx), %rcx
movl %eax, 0xf20(%rcx)
cmpl $0x0, 0xf14(%rcx)
jne 0x491e6
movq 0x1dd28(%rip), %rax     # 0x66da0
movss 0x4(%rax), %xmm0
ucomiss 0xf18(%rcx), %xmm0
jae 0x491c6
testb $0x1, 0xe3c(%rcx)
jne 0x4923f
movl 0x5c(%rcx), %eax
cmpl $0xc, %eax
jne 0x490be
andl $0x0, 0xf20(%rcx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x18730
movq 0x58(%rbx), %rcx
andl $0x0, 0xf18(%rcx)
movl 0x5c(%rcx), %eax
leaq 0x5c(%rcx), %rdx
cmpl $0xf, %eax
je 0x49216
incl %eax
movl %eax, (%rdx)
jmp 0x4923f
movl 0xe44(%rcx), %eax
movl 0xe3c(%rcx), %edx
orl %eax, %edx
testb $0x1, %dl
jne 0x49128
movl 0x5c(%rcx), %eax
cmpq $0x30, %rax
ja 0x49114
movabsq $0x1008420000000, %rdx  # imm = 0x1008420000000
btq %rax, %rdx
jae 0x49114
callq 0x19bf0
testb $0xf, %al
jne 0x4923f
movq 0x58(%rbx), %rcx
movl 0x5c(%rcx), %eax
leal 0x1(%rax), %edx
cmpl $0x30, %eax
pushq $0x10
popq %rax
cmovll %edx, %eax
movl %eax, 0x5c(%rcx)
jmp 0x4923f
andl $-0x2, %eax
movl %eax, 0xe44(%rcx)
movslq 0xe38(%rcx), %rax
cmpl $0x0, 0x318(%rcx,%rax,4)
je 0x4915f
movl $0x1, 0x5c(%rcx)
movl $0x3, 0xe78(%rcx)
andl $0x0, 0xf18(%rcx)
jmp 0x4923f
movq 0x1dc3a(%rip), %r14     # 0x66da0
movss 0x4(%r14), %xmm0
ucomiss 0x244(%rbx), %xmm0
jb 0x491b9
movq 0x1d484(%rip), %rax     # 0x66600
movq 0x20(%rax), %r15
leaq 0x6ba8(%rip), %rdi      # 0x4fd2f
callq *0x48(%rax)
pushq $0x2
popq %rsi
movss 0x5d93(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r15
movss 0x5d7d(%rip), %xmm0     # 0x4ef28
addss 0x4(%r14), %xmm0
movss %xmm0, 0x244(%rbx)
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x19430
andl $0x0, 0xf20(%rcx)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x18730
movq 0x58(%rbx), %rcx
movl $0x1, 0xf14(%rcx)
testb $0x1, 0xe3c(%rcx)
jne 0x4923f
movq 0x1dbaa(%rip), %rax     # 0x66da0
movss 0x4(%rax), %xmm0
ucomiss 0xf18(%rcx), %xmm0
jb 0x4923f
leaq 0x5c(%rcx), %rdx
movl $0xf, 0x5c(%rcx)
andl $0x0, 0xf14(%rcx)
movq 0x1db83(%rip), %rax     # 0x66da0
movss 0xf18(%rcx), %xmm0
ucomiss 0x4(%rax), %xmm0
ja 0x4923f
movl $0x10, (%rdx)
andl $0x0, 0xf18(%rcx)
andl $0x0, 0xe78(%rcx)
popq %rbx
popq %r14
popq %r15
retq