// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movq 0x1d0d7(%rip), %rax     # 0x66ec0
movq (%rax), %rax
xorps %xmm0, %xmm0
cmpeqss 0x20(%rax), %xmm0
movss %xmm0, 0xc(%rsp)
movq %rdi, %rbx
movq 0x58(%rdi), %rax
movl 0x5c(%rax), %ecx
cmpl $0x5, %ecx
jne 0x49e43
movq 0x1c7ef(%rip), %rax     # 0x66600
movq 0x20(%rax), %r14
leaq 0xd0b0(%rip), %rdi      # 0x56ecc
callq *0x48(%rax)
movss 0x5101(%rip), %xmm0     # 0x4ef28
movss 0x563d(%rip), %xmm1     # 0x4f46c
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 0x49e69
cmpl $0xe, %ecx
jne 0x49e88
testb $0x1, 0xe3c(%rax)
jne 0x49e83
movl $0x20, 0x5c(%rax)
andl $0x0, 0xf20(%rax)
jmp 0x4a215
testb $0x1, 0xe3c(%rax)
je 0x49eaa
movslq 0xe38(%rax), %rcx
cmpl $0x0, 0x318(%rax,%rcx,4)
je 0x49eaa
pushq $0xf
popq %rcx
jmp 0x49e8a
incl %ecx
movl %ecx, 0x5c(%rax)
movq 0x1c76c(%rip), %rax     # 0x66600
leaq 0xd046(%rip), %rdi      # 0x56ee1
callq *0x48(%rax)
movq 0x58(%rbx), %rcx
movl %eax, 0xf20(%rcx)
jmp 0x49eee
movl $0x16, 0x5c(%rax)
andl $0x0, 0xf20(%rax)
movq 0x1c741(%rip), %rax     # 0x66600
movq 0x20(%rax), %r14
leaq 0x8669(%rip), %rdi      # 0x52533
callq *0x48(%rax)
movss 0x5053(%rip), %xmm0     # 0x4ef28
movss 0x558f(%rip), %xmm1     # 0x4f46c
xorps %xmm2, %xmm2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
callq *%r14
movq 0x58(%rbx), %rcx
movl $0x4, 0xef8(%rcx)
movl 0x5c(%rcx), %eax
movl %eax, %edx
andl $0x1, %edx
testb $0x1, 0x10(%rcx)
pushq $0x2e
popq %rsi
movl $0xa0, %edi
cmovel %esi, %edi
pushq $0x35
popq %rsi
movl $0xa8, %r8d
cmovel %esi, %r8d
subl %edx, %edi
movl %edi, 0x38(%rbx)
movl %r8d, 0xef4(%rcx)
cmpl $0xa, %eax
jge 0x49f31
pushq $0x1
jmp 0x49f48
cmpl $0xe, %eax
ja 0x49f46
movl 0xe3c(%rcx), %r12d
andl $0x1, %r12d
incl %r12d
jmp 0x49f4a
pushq $0x3
popq %r12
movslq 0xe38(%rcx), %rax
movl 0x318(%rcx,%rax,4), %eax
cmpl %r12d, %eax
cmovll %eax, %r12d
testl %eax, %eax
je 0x4a224
movd 0xc(%rsp), %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leal 0x6(,%rax,2), %eax
movl 0x4d213(%rip), %ebp     # 0x97194
leal (,%rax,4), %ecx
testl %ebp, %ebp
cmovel %eax, %ecx
movl %ecx, 0x14(%rsp)
xorl %r14d, %r14d
movl $0x7fff, %r15d          # imm = 0x7FFF
cmpq $0x3, %r14
je 0x4a030
callq 0x19bf0
andl %r15d, %eax
cvtsi2ss %eax, %xmm0
movss 0x52d0(%rip), %xmm1     # 0x4f288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x7c30(%rip), %xmm1     # 0x51bf8
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
mulsd 0xce80(%rip), %xmm0     # 0x56e58
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe88(%rax,%r14,4)
callq 0x19bf0
andl %r15d, %eax
cvtsi2ss %eax, %xmm0
divss 0x528a(%rip), %xmm0     # 0x4f288
cvtss2sd %xmm0, %xmm0
addsd 0x7bee(%rip), %xmm0     # 0x51bf8
addsd %xmm0, %xmm0
mulsd 0x99ba(%rip), %xmm0     # 0x539d0
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe7c(%rax,%r14,4)
incq %r14
jmp 0x49f9a
testl %ebp, %ebp
pushq $0x2
popq %rax
pushq $0x8
popq %rcx
cmovel %eax, %ecx
movl %ecx, 0x10(%rsp)
leaq 0x4(%rbx), %rax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
testl %r12d, %r12d
movq %r12, 0x30(%rsp)
cmovgl %r12d, %r14d
leaq 0x5c(%rsp), %r12
leaq 0x50(%rsp), %r13
movl $0x7fff, %r15d          # imm = 0x7FFF
leaq 0x38(%rsp), %rbp
subl $0x1, %r14d
jb 0x4a180
movq 0x58(%rbx), %rdi
movl $0xebc, %eax            # imm = 0xEBC
addq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
leaq 0x44(%rsp), %rcx
callq 0x183d0
callq 0x19bf0
andl %r15d, %eax
cvtsi2ss %eax, %xmm0
movss 0x51e2(%rip), %xmm1     # 0x4f288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x7b42(%rip), %xmm1     # 0x51bf8
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
movsd 0xcd8a(%rip), %xmm1     # 0x56e50
mulsd %xmm1, %xmm0
addsd 0xcd9e(%rip), %xmm0     # 0x56e70
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xc(%rsp)
callq 0x19bf0
andl %r15d, %eax
cvtsi2ss %eax, %xmm0
divss 0x5198(%rip), %xmm0     # 0x4f288
cvtss2sd %xmm0, %xmm0
addsd 0x7afc(%rip), %xmm0     # 0x51bf8
addsd %xmm0, %xmm0
mulsd 0xcd48(%rip), %xmm0     # 0x56e50
cvtsd2ss %xmm0, %xmm0
andl $0x0, 0x24(%rsp)
movss 0xc(%rsp), %xmm1
movss %xmm1, 0x28(%rsp)
cvtsi2ssl 0x278(%rbx), %xmm1
addss %xmm0, %xmm1
addss 0x62db(%rip), %xmm1     # 0x5040c
movss %xmm1, 0x2c(%rsp)
movq 0x58(%rbx), %rdi
movq 0x18(%rsp), %rsi
leaq 0x24(%rsp), %rdx
movq %r12, %rcx
movq %r13, %r8
movq %rbp, %r9
callq 0x48f06
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movl 0x14(%rsp), %ecx
movl 0x10(%rsp), %r8d
movl $0x12c, %r9d            # imm = 0x12C
pushq $0x5
pushq $0x1f4                  # imm = 0x1F4
callq 0x19c20
addq $0x10, %rsp
jmp 0x4a06c
movq 0x1c479(%rip), %r14     # 0x66600
pushq $0x1
popq %rbp
movl %ebp, %edi
callq *0xc8(%r14)
movq 0x1c3be(%rip), %rcx     # 0x66558
movq %rbx, %rax
subq (%rcx), %rax
movl $0x4a8, %ecx            # imm = 0x4A8
cqto
idivq %rcx
movl %eax, %edi
callq *0xd0(%r14)
movq 0x30(%rsp), %r15
leal 0x2(%r15), %eax
movzbl 0x4cfd5(%rip), %edi     # 0x97198
shll $0x7, %edi
orl %eax, %edi
callq *0xc8(%r14)
pushq $0x2
popq %rsi
movq 0x18(%rsp), %rdi
callq *0xb0(%r14)
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x19010
movq 0x1c424(%rip), %rax     # 0x66618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0xd, %eax
jb 0x4a215
movq 0x58(%rbx), %rax
movslq 0xe38(%rax), %rcx
subl %r15d, 0x318(%rax,%rcx,4)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1cb75(%rip), %r14     # 0x66da0
movss 0x4(%r14), %xmm0
ucomiss 0x244(%rbx), %xmm0
jb 0x4a27f
movq 0x1c3bf(%rip), %rax     # 0x66600
movq 0x20(%rax), %r15
leaq 0x5ae3(%rip), %rdi      # 0x4fd2f
callq *0x48(%rax)
pushq $0x2
popq %rsi
movss 0x4cce(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movapd %xmm0, %xmm1
callq *%r15
movss 0x4cb7(%rip), %xmm0     # 0x4ef28
addss 0x4(%r14), %xmm0
movss %xmm0, 0x244(%rbx)
movq %rbx, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x19430