// File: /workspace/github_c_makefile_star2_O1/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), %rax
cmpq $0x0, 0xe50(%rax)
je 0x4de6c
cmpl $0x0, 0xe78(%rax)
je 0x4de9e
movl 0xe78(%rax), %ecx
testl %ecx, %ecx
je 0x4e044
cmpl $0x3, %ecx
je 0x4deb0
cmpl $0x1, %ecx
jne 0x4e0c8
movl $0x0, 0xe78(%rax)
movl $0x10, 0x5c(%rax)
jmp 0x4e0c8
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x187a0
cmpl $0x5, 0x5c(%rax)
jne 0x4dee6
movq 0x1b743(%rip), %rax     # 0x69600
movq 0x20(%rax), %r14
leaq 0xdcb5(%rip), %rdi      # 0x5bb7d
callq *0x48(%rax)
movss 0x6055(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x1, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r14
movq 0x58(%rbx), %rax
cmpl $0xb, 0x5c(%rax)
jne 0x4dfd8
movss 0xf18(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x4df4d
jp 0x4df4d
movq 0x1be93(%rip), %rcx     # 0x69da0
movss 0x4(%rcx), %xmm0
addss 0x5ff2(%rip), %xmm0     # 0x53f0c
cvtss2sd %xmm0, %xmm0
addsd 0x8c82(%rip), %xmm0     # 0x56ba8
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xf18(%rax)
movq 0x1b6c7(%rip), %rax     # 0x69600
leaq 0xc4a5(%rip), %rdi      # 0x5a3e5
callq *0x48(%rax)
movq 0x58(%rbx), %rcx
movl %eax, 0xf20(%rcx)
movq 0x58(%rbx), %rax
cmpl $0x0, 0xf14(%rax)
jne 0x4df94
movq 0x1be3f(%rip), %rcx     # 0x69da0
movss 0x4(%rcx), %xmm0
ucomiss 0xf18(%rax), %xmm0
jb 0x4df94
movl $0x0, 0xf20(%rax)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x186e0
movq 0x58(%rbx), %rax
movl $0x1, 0xf14(%rax)
movq 0x58(%rbx), %rax
testb $0x1, 0xe3c(%rax)
jne 0x4e0c8
cmpl $0x0, 0xf14(%rax)
je 0x4dfd8
movq 0x1bdeb(%rip), %rcx     # 0x69da0
movss 0x4(%rcx), %xmm0
ucomiss 0xf18(%rax), %xmm0
jb 0x4e0c8
movl $0xf, 0x5c(%rax)
movl $0x0, 0xf14(%rax)
movq 0x58(%rbx), %rax
cmpl $0xc, 0x5c(%rax)
jne 0x4dffe
xorl %ebp, %ebp
movl %ebp, 0xf20(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x186e0
movq 0x58(%rbx), %rax
movl %ebp, 0xf18(%rax)
movq 0x58(%rbx), %rax
movl 0x5c(%rax), %ecx
cmpl $0xf, %ecx
jne 0x4e023
movq 0x1bd8f(%rip), %rdx     # 0x69da0
movss 0xf18(%rax), %xmm0
ucomiss 0x4(%rdx), %xmm0
ja 0x4e0c8
incl %ecx
movl %ecx, 0x5c(%rax)
cmpl $0x10, %ecx
jne 0x4e0c8
xorl %ecx, %ecx
movl %ecx, 0xf18(%rax)
movl %ecx, 0xe78(%rax)
jmp 0x4e0c8
movl 0xe44(%rax), %ecx
movl 0xe3c(%rax), %edx
orl %ecx, %edx
testb $0x1, %dl
jne 0x4e093
movl 0x5c(%rax), %eax
cmpq $0x30, %rax
ja 0x4e079
movabsq $0x1008420000000, %rcx  # imm = 0x1008420000000
btq %rax, %rcx
jae 0x4e079
callq 0x19a20
testb $0xf, %al
jne 0x4e0c8
movq 0x58(%rbx), %rax
movl 0x5c(%rax), %ecx
leal 0x1(%rcx), %edx
cmpl $0x30, %ecx
movl $0x10, %ecx
cmovll %edx, %ecx
movl %ecx, 0x5c(%rax)
jmp 0x4e0c8
andl $-0x2, %ecx
movl %ecx, 0xe44(%rax)
movslq 0xe38(%rax), %rcx
cmpl $0x0, 0x318(%rax,%rcx,4)
je 0x4e0d3
movl $0x1, 0x5c(%rax)
movl $0x3, 0xe78(%rax)
movl $0x0, 0xf18(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x1bcc6(%rip), %r14     # 0x69da0
movss 0x4(%r14), %xmm0
ucomiss 0x244(%rbx), %xmm0
jb 0x4e12f
movq 0x1b510(%rip), %rax     # 0x69600
movq 0x20(%rax), %r15
leaq 0x6bf4(%rip), %rdi      # 0x54cef
callq *0x48(%rax)
movss 0x5e22(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r15
movss 0x5e07(%rip), %xmm0     # 0x53f28
addss 0x4(%r14), %xmm0
movss %xmm0, 0x244(%rbx)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x192b0