// File: /workspace/github_c_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
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 0x4d15c
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x187a0
testl %eax, %eax
je 0x4d299
cmpl $0x3, %eax
je 0x4d188
cmpl $0x1, %eax
jne 0x4d418
movl $0x0, 0xe78(%rcx)
movl $0x10, 0x5c(%rcx)
jmp 0x4d418
movl 0x5c(%rcx), %eax
cmpl $0x5, %eax
jne 0x4d1c7
movq 0x1b469(%rip), %rax     # 0x68600
movq 0x20(%rax), %r14
leaq 0xdd2b(%rip), %rdi      # 0x5aecd
callq *0x48(%rax)
movss 0x5d7b(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x1, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r14
movq 0x58(%rbx), %rcx
movl 0x5c(%rcx), %eax
cmpl $0xb, %eax
jne 0x4d25f
movss 0xf18(%rcx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x4d229
jp 0x4d229
movq 0x1bbb7(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
addss 0x5d1a(%rip), %xmm0     # 0x52f10
cvtss2sd %xmm0, %xmm0
addsd 0x8a0e(%rip), %xmm0     # 0x55c10
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xf18(%rcx)
movq 0x1b3eb(%rip), %rax     # 0x68600
leaq 0xc3f1(%rip), %rdi      # 0x5960d
callq *0x48(%rax)
movq 0x58(%rbx), %rcx
movl %eax, 0xf20(%rcx)
cmpl $0x0, 0xf14(%rcx)
jne 0x4d3bc
movq 0x1bb63(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
ucomiss 0xf18(%rcx), %xmm0
jae 0x4d397
testb $0x1, 0xe3c(%rcx)
jne 0x4d418
movl 0x5c(%rcx), %eax
cmpl $0xc, %eax
jne 0x4d283
xorl %ebp, %ebp
movl %ebp, 0xf20(%rcx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x186e0
movq 0x58(%rbx), %rcx
movl %ebp, 0xf18(%rcx)
movl 0x5c(%rcx), %eax
leaq 0x5c(%rcx), %rdx
cmpl $0xf, %eax
je 0x4d3ef
incl %eax
movl %eax, (%rdx)
jmp 0x4d418
movl 0xe44(%rcx), %eax
movl 0xe3c(%rcx), %edx
orl %eax, %edx
testb $0x1, %dl
jne 0x4d2ef
movl 0x5c(%rcx), %eax
cmpq $0x30, %rax
ja 0x4d2d9
movabsq $0x1008420000000, %rdx  # imm = 0x1008420000000
btq %rax, %rdx
jae 0x4d2d9
callq 0x19a10
testb $0xf, %al
jne 0x4d418
movq 0x58(%rbx), %rcx
movl 0x5c(%rcx), %eax
leal 0x1(%rax), %edx
cmpl $0x30, %eax
movl $0x10, %eax
cmovll %edx, %eax
movl %eax, 0x5c(%rcx)
jmp 0x4d418
andl $-0x2, %eax
movl %eax, 0xe44(%rcx)
movslq 0xe38(%rcx), %rax
cmpl $0x0, 0x318(%rcx,%rax,4)
je 0x4d329
movl $0x1, 0x5c(%rcx)
movl $0x3, 0xe78(%rcx)
movl $0x0, 0xf18(%rcx)
jmp 0x4d418
movq 0x1ba70(%rip), %r14     # 0x68da0
movss 0x4(%r14), %xmm0
ucomiss 0x244(%rbx), %xmm0
jb 0x4d385
movq 0x1b2ba(%rip), %rax     # 0x68600
movq 0x20(%rax), %r15
leaq 0x69de(%rip), %rdi      # 0x53d2f
callq *0x48(%rax)
movss 0x5bcc(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r15
movss 0x5bb1(%rip), %xmm0     # 0x52f28
addss 0x4(%r14), %xmm0
movss %xmm0, 0x244(%rbx)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x192b0
movl $0x0, 0xf20(%rcx)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x186e0
movq 0x58(%rbx), %rcx
movl $0x1, 0xf14(%rcx)
testb $0x1, 0xe3c(%rcx)
jne 0x4d418
movq 0x1b9d4(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
ucomiss 0xf18(%rcx), %xmm0
jb 0x4d418
leaq 0x5c(%rcx), %rdx
movl $0xf, 0x5c(%rcx)
movl $0x0, 0xf14(%rcx)
movq 0x1b9aa(%rip), %rax     # 0x68da0
movss 0xf18(%rcx), %xmm0
ucomiss 0x4(%rax), %xmm0
ja 0x4d418
movl $0x10, (%rdx)
xorl %eax, %eax
movl %eax, 0xf18(%rcx)
movl %eax, 0xe78(%rcx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq