// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/p_weapon.c
// Function: Chaingun_Fire
void Chaingun_Fire (edict_t *ent)
{
	int			i;
	int			shots;
	vec3_t		start;
	vec3_t		forward, right, up;
	float		r, u;
	vec3_t		offset;
	int			damage;
	int			kick = 2;

	if (deathmatch->value)
		damage = 6;
	else
		damage = 8;

	if (ent->client->ps.gunframe == 5)
		gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnu1a.wav"), 1, ATTN_IDLE, 0);

	if ((ent->client->ps.gunframe == 14) && !(ent->client->buttons & BUTTON_ATTACK))
	{
		ent->client->ps.gunframe = 32;
		ent->client->weapon_sound = 0;
		return;
	}
	else if ((ent->client->ps.gunframe == 21) && (ent->client->buttons & BUTTON_ATTACK)
		&& ent->client->pers.inventory[ent->client->ammo_index])
	{
		ent->client->ps.gunframe = 15;
	}
	else
	{
		ent->client->ps.gunframe++;
	}

	if (ent->client->ps.gunframe == 22)
	{
		ent->client->weapon_sound = 0;
		gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/chngnd1a.wav"), 1, ATTN_IDLE, 0);
	}
	else
	{
		ent->client->weapon_sound = gi.soundindex("weapons/chngnl1a.wav");
	}

	ent->client->anim_priority = ANIM_ATTACK;
	if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
	{
		ent->s.frame = FRAME_crattak1 - (ent->client->ps.gunframe & 1);
		ent->client->anim_end = FRAME_crattak9;
	}
	else
	{
		ent->s.frame = FRAME_attack1 - (ent->client->ps.gunframe & 1);
		ent->client->anim_end = FRAME_attack8;
	}

	if (ent->client->ps.gunframe <= 9)
		shots = 1;
	else if (ent->client->ps.gunframe <= 14)
	{
		if (ent->client->buttons & BUTTON_ATTACK)
			shots = 2;
		else
			shots = 1;
	}
	else
		shots = 3;

	if (ent->client->pers.inventory[ent->client->ammo_index] < shots)
		shots = ent->client->pers.inventory[ent->client->ammo_index];

	if (!shots)
	{
		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 (is_quad)
	{
		damage *= 4;
		kick *= 4;
	}

	for (i=0 ; i<3 ; i++)
	{
		ent->client->kick_origin[i] = crandom() * 0.35;
		ent->client->kick_angles[i] = crandom() * 0.7;
	}

	for (i=0 ; i<shots ; i++)
	{
		// get start / end positions
		AngleVectors (ent->client->v_angle, forward, right, up);
		r = 7 + crandom()*4;
		u = crandom()*4;
		VectorSet(offset, 0, r, u + ent->viewheight-8);
		P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);

		fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_CHAINGUN);
	}

	// send muzzle flash
	gi.WriteByte (svc_muzzleflash);
	gi.WriteShort (ent-g_edicts);
	gi.WriteByte ((MZ_CHAINGUN1 + shots - 1) | is_silenced);
	gi.multicast (ent->s.origin, MULTICAST_PVS);

	PlayerNoise(ent, start, PNOISE_WEAPON);

	if (! ( (int)dmflags->value & DF_INFINITE_AMMO ) )
		ent->client->pers.inventory[ent->client->ammo_index] -= shots;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq 0x1ae6f(%rip), %rax     # 0x68ec0
movq (%rax), %rax
xorps %xmm0, %xmm0
cmpeqss 0x20(%rax), %xmm0
movss %xmm0, (%rsp)
movq %rdi, %rbx
movq 0x58(%rdi), %rax
movl 0x5c(%rax), %ecx
cmpl $0x5, %ecx
jne 0x4e0aa
movq 0x1a588(%rip), %rax     # 0x68600
movq 0x20(%rax), %r14
leaq 0xce89(%rip), %rdi      # 0x5af0c
callq *0x48(%rax)
movss 0x4e9a(%rip), %xmm0     # 0x52f28
movss 0x53d6(%rip), %xmm1     # 0x5346c
xorps %xmm2, %xmm2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
callq *%r14
movq 0x58(%rbx), %rax
movl 0x5c(%rax), %ecx
cmpl $0x15, %ecx
je 0x4e0e0
cmpl $0xe, %ecx
jne 0x4e148
movl $0xf, %ecx
testb $0x1, 0xe3c(%rax)
jne 0x4e14a
movl $0x20, 0x5c(%rax)
movl $0x0, 0xf20(%rax)
jmp 0x4e4ad
testb $0x1, 0xe3c(%rax)
je 0x4e0ff
movslq 0xe38(%rax), %rdx
movl $0xf, %ecx
cmpl $0x0, 0x318(%rax,%rdx,4)
jne 0x4e14a
movl $0x16, 0x5c(%rax)
movl $0x0, 0xf20(%rax)
movq 0x1a4e9(%rip), %rax     # 0x68600
movq 0x20(%rax), %r14
leaq 0x8431(%rip), %rdi      # 0x56553
callq *0x48(%rax)
movss 0x4dfb(%rip), %xmm0     # 0x52f28
movss 0x5337(%rip), %xmm1     # 0x5346c
xorps %xmm2, %xmm2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
callq *%r14
movq 0x58(%rbx), %rcx
jmp 0x4e168
incl %ecx
movl %ecx, 0x5c(%rax)
movq 0x1a4ac(%rip), %rax     # 0x68600
leaq 0xcdc6(%rip), %rdi      # 0x5af21
callq *0x48(%rax)
movq 0x58(%rbx), %rcx
movl %eax, 0xf20(%rcx)
movl $0x4, 0xef8(%rcx)
movl 0x5c(%rcx), %eax
movl %eax, %edx
andl $0x1, %edx
testb $0x1, 0x10(%rcx)
movl $0x2e, %esi
movl $0xa0, %edi
cmovel %esi, %edi
movl $0x35, %esi
movl $0xa8, %r8d
cmovel %esi, %r8d
subl %edx, %edi
movl %edi, 0x38(%rbx)
movl %r8d, 0xef4(%rcx)
movl $0x1, %edx
cmpl $0xa, %eax
jl 0x4e1c5
movl $0x3, %edx
cmpl $0xe, %eax
ja 0x4e1c5
movl 0xe3c(%rcx), %edx
andl $0x1, %edx
incl %edx
movslq 0xe38(%rcx), %rax
movl 0x318(%rcx,%rax,4), %ebp
cmpl %edx, %ebp
cmovll %ebp, %edx
testl %ebp, %ebp
je 0x4e4bc
movq %rdx, 0x8(%rsp)
movd (%rsp), %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leal 0x6(,%rax,2), %eax
movl 0x4ae95(%rip), %r14d    # 0x99094
leal (,%rax,4), %r13d
testl %r14d, %r14d
cmovel %eax, %r13d
xorl %r15d, %r15d
movl $0x7fff, %r12d          # imm = 0x7FFF
callq 0x19a10
andl %r12d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x505a(%rip), %xmm1     # 0x53288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x79da(%rip), %xmm1     # 0x55c18
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
mulsd 0xcc4a(%rip), %xmm0     # 0x5ae98
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe88(%rax,%r15,4)
callq 0x19a10
andl %r12d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x5011(%rip), %xmm0     # 0x53288
cvtss2sd %xmm0, %xmm0
addsd 0x7995(%rip), %xmm0     # 0x55c18
addsd %xmm0, %xmm0
mulsd 0x9761(%rip), %xmm0     # 0x579f0
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe7c(%rax,%r15,4)
incq %r15
cmpq $0x3, %r15
jne 0x4e217
testl %r14d, %r14d
movl $0x2, %eax
movl $0x8, %r14d
cmovel %eax, %r14d
testl %ebp, %ebp
movl %r13d, 0x4(%rsp)
jle 0x4e416
leaq 0x4(%rbx), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %rax
cmpl $0x2, %eax
movl $0x1, %r15d
cmovgel %eax, %r15d
leaq 0x4c(%rsp), %r12
movl $0x7fff, %ebp           # imm = 0x7FFF
movq 0x58(%rbx), %rdi
movl $0xebc, %eax            # imm = 0xEBC
addq %rax, %rdi
movq %r12, %rsi
leaq 0x40(%rsp), %r13
movq %r13, %rdx
leaq 0x34(%rsp), %rcx
callq 0x183a0
callq 0x19a10
andl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x4f5f(%rip), %xmm1     # 0x53288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x78df(%rip), %xmm1     # 0x55c18
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
movsd 0xcb47(%rip), %xmm1     # 0x5ae90
mulsd %xmm1, %xmm0
addsd 0xcb5b(%rip), %xmm0     # 0x5aeb0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rsp)
callq 0x19a10
andl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x4f14(%rip), %xmm0     # 0x53288
cvtss2sd %xmm0, %xmm0
addsd 0x7898(%rip), %xmm0     # 0x55c18
addsd %xmm0, %xmm0
mulsd 0xcb04(%rip), %xmm0     # 0x5ae90
cvtsd2ss %xmm0, %xmm0
movl $0x0, 0x14(%rsp)
movss (%rsp), %xmm1
movss %xmm1, 0x18(%rsp)
xorps %xmm1, %xmm1
cvtsi2ssl 0x278(%rbx), %xmm1
addss %xmm0, %xmm1
addss 0x6052(%rip), %xmm1     # 0x5440c
movss %xmm1, 0x1c(%rsp)
movq 0x58(%rbx), %rax
movl 0x300(%rax), %edi
movq 0x20(%rsp), %rsi
leaq 0x14(%rsp), %rdx
movq %r12, %rcx
movq %r13, %r8
leaq 0x28(%rsp), %r13
movq %r13, %r9
callq 0x4d0c5
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
movl 0x4(%rsp), %ecx
movl %r14d, %r8d
movl $0x12c, %r9d            # imm = 0x12C
pushq $0x5
pushq $0x1f4                  # imm = 0x1F4
callq 0x19a30
addq $0x10, %rsp
decl %r15d
jne 0x4e2f2
movq 0x1a1e3(%rip), %r14     # 0x68600
movl $0x1, %edi
callq *0xc8(%r14)
movq 0x1a128(%rip), %rax     # 0x68558
movq %rbx, %rcx
subq (%rax), %rcx
shrq $0x3, %rcx
imull $0x8ce2cabd, %ecx, %edi # imm = 0x8CE2CABD
callq *0xd0(%r14)
movq 0x8(%rsp), %r15
leal 0x2(%r15), %eax
movzbl 0x4ac41(%rip), %edi     # 0x99098
shll $0x7, %edi
orl %eax, %edi
callq *0xc8(%r14)
leaq 0x4(%rbx), %rdi
movl $0x2, %esi
callq *0xb0(%r14)
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x18ef0
movq 0x1a18c(%rip), %rax     # 0x68618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0xd, %eax
jb 0x4e4ad
movq 0x58(%rbx), %rax
movslq 0xe38(%rax), %rcx
subl %r15d, 0x318(%rax,%rcx,4)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1a8dd(%rip), %r14     # 0x68da0
movss 0x4(%r14), %xmm0
ucomiss 0x244(%rbx), %xmm0
jb 0x4e519
movq 0x1a127(%rip), %rax     # 0x68600
movq 0x20(%rax), %r15
leaq 0x584b(%rip), %rdi      # 0x53d2f
callq *0x48(%rax)
movss 0x4a39(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movapd %xmm0, %xmm1
callq *%r15
movss 0x4a1d(%rip), %xmm0     # 0x52f28
addss 0x4(%r14), %xmm0
movss %xmm0, 0x244(%rbx)
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x192b0