// File: /workspace/github_c_makefile_star2_O1/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 0x1b135(%rip), %rax     # 0x69ec0
movq (%rax), %rax
xorps %xmm0, %xmm0
cmpeqss 0x20(%rax), %xmm0
movss %xmm0, (%rsp)
movq %rdi, %rbx
movq 0x58(%rdi), %rax
cmpl $0x5, 0x5c(%rax)
jne 0x4eddb
movq 0x1a850(%rip), %rax     # 0x69600
movq 0x20(%rax), %r14
leaq 0xce01(%rip), %rdi      # 0x5bbbc
callq *0x48(%rax)
movss 0x5162(%rip), %xmm0     # 0x53f28
movss 0x568a(%rip), %xmm1     # 0x54458
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 0x4ee10
cmpl $0xe, %ecx
jne 0x4ee2f
testb $0x1, 0xe3c(%rax)
jne 0x4ee0b
movl $0x20, 0x5c(%rax)
movl $0x0, 0xf20(%rax)
jmp 0x4f1d5
cmpl $0x15, %ecx
jne 0x4ee2f
testb $0x1, 0xe3c(%rax)
je 0x4ee2f
movslq 0xe38(%rax), %rsi
movl $0xf, %edx
cmpl $0x0, 0x318(%rax,%rsi,4)
jne 0x4ee33
incl %ecx
movl %ecx, %edx
movl %edx, 0x5c(%rax)
cmpl $0x16, %edx
jne 0x4ee79
movl $0x0, 0xf20(%rax)
movq 0x1a7b4(%rip), %rax     # 0x69600
movq 0x20(%rax), %r14
leaq 0x8608(%rip), %rdi      # 0x5745f
callq *0x48(%rax)
movss 0x50c6(%rip), %xmm0     # 0x53f28
movss 0x55ee(%rip), %xmm1     # 0x54458
xorps %xmm2, %xmm2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
callq *%r14
jmp 0x4ee94
movq 0x1a780(%rip), %rax     # 0x69600
leaq 0xcd4a(%rip), %rdi      # 0x5bbd1
callq *0x48(%rax)
movq 0x58(%rbx), %rcx
movl %eax, 0xf20(%rcx)
movq 0x58(%rbx), %rax
movl $0x4, 0xef8(%rax)
movl 0x5c(%rax), %ecx
andl $0x1, %ecx
testb $0x1, 0x10(%rax)
movl $0x2e, %edx
movl $0xa0, %esi
cmovel %edx, %esi
movl $0x35, %edx
movl $0xa8, %edi
cmovel %edx, %edi
subl %ecx, %esi
movl %esi, 0x38(%rbx)
movl %edi, 0xef4(%rax)
movl 0x5c(%rax), %ecx
movl $0x1, %edx
cmpl $0xa, %ecx
jl 0x4eef3
movl $0x3, %edx
cmpl $0xe, %ecx
jg 0x4eef3
movl 0xe3c(%rax), %edx
andl $0x1, %edx
incl %edx
movslq 0xe38(%rax), %rcx
movl 0x318(%rax,%rcx,4), %ebp
cmpl %edx, %ebp
cmovll %ebp, %edx
testl %ebp, %ebp
je 0x4f1e4
movq %rdx, 0x8(%rsp)
movd (%rsp), %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leal 0x6(,%rax,2), %eax
movl 0x4b167(%rip), %r14d    # 0x9a094
leal (,%rax,4), %r13d
testl %r14d, %r14d
cmovel %eax, %r13d
xorl %r15d, %r15d
movl $0x7fff, %r12d          # imm = 0x7FFF
callq 0x19a20
andl %r12d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x532c(%rip), %xmm1     # 0x54288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x7c44(%rip), %xmm1     # 0x56bb0
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
mulsd 0xcbbc(%rip), %xmm0     # 0x5bb38
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe88(%rax,%r15,4)
callq 0x19a20
andl %r12d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x52e3(%rip), %xmm0     # 0x54288
cvtss2sd %xmm0, %xmm0
addsd 0x7bff(%rip), %xmm0     # 0x56bb0
addsd %xmm0, %xmm0
mulsd 0x9823(%rip), %xmm0     # 0x587e0
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe7c(%rax,%r15,4)
incq %r15
cmpq $0x3, %r15
jne 0x4ef45
testl %r14d, %r14d
movl $0x2, %eax
movl $0x8, %r14d
cmovel %eax, %r14d
testl %ebp, %ebp
movl %r13d, 0x4(%rsp)
jle 0x4f13e
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 0x19a20
andl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x5231(%rip), %xmm1     # 0x54288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x7b49(%rip), %xmm1     # 0x56bb0
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
movsd 0xcab9(%rip), %xmm1     # 0x5bb30
mulsd %xmm1, %xmm0
addsd 0xcacd(%rip), %xmm0     # 0x5bb50
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rsp)
callq 0x19a20
andl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x51e6(%rip), %xmm0     # 0x54288
cvtss2sd %xmm0, %xmm0
addsd 0x7b02(%rip), %xmm0     # 0x56bb0
addsd %xmm0, %xmm0
mulsd 0xca76(%rip), %xmm0     # 0x5bb30
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 0x6324(%rip), %xmm1     # 0x5540c
movss %xmm1, 0x1c(%rsp)
movq 0x58(%rbx), %rdi
movq 0x20(%rsp), %rsi
leaq 0x14(%rsp), %rdx
movq %r12, %rcx
movq %r13, %r8
leaq 0x28(%rsp), %r13
movq %r13, %r9
callq 0x4dde7
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 0x19a40
addq $0x10, %rsp
decl %r15d
jne 0x4f020
movq 0x1a4bb(%rip), %r14     # 0x69600
movl $0x1, %edi
callq *0xc8(%r14)
movq 0x1a400(%rip), %rax     # 0x69558
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 0x4af19(%rip), %edi     # 0x9a098
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 0x1a464(%rip), %rax     # 0x69618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0xd, %eax
jb 0x4f1d5
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 0x1abb5(%rip), %r14     # 0x69da0
movss 0x4(%r14), %xmm0
ucomiss 0x244(%rbx), %xmm0
jb 0x4f241
movq 0x1a3ff(%rip), %rax     # 0x69600
movq 0x20(%rax), %r15
leaq 0x5ae3(%rip), %rdi      # 0x54cef
callq *0x48(%rax)
movss 0x4d11(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movapd %xmm0, %xmm1
callq *%r15
movss 0x4cf5(%rip), %xmm0     # 0x53f28
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