// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/p_weapon.c
// Function: Machinegun_Fire
void Machinegun_Fire (edict_t *ent)
{
	int	i;
	vec3_t		start;
	vec3_t		forward, right;
	vec3_t		angles;
	int			damage = 8;
	int			kick = 2;
	vec3_t		offset;

#ifdef WEAP_BALANCE_OK	
	if ((int)ctfflags->value & CTF_WEAP_BALANCE)
	{
		damage = 9; // 9/8 = 12.5% additional damage per bullet
		//we'll lose accuracy for our mod however (extra spread)
	}
#endif

	if (!(ent->client->buttons & BUTTON_ATTACK))
	{
		ent->client->machinegun_shots = 0;
		ent->client->ps.gunframe++;
		return;
	}

	if (ent->client->ps.gunframe == 5)
		ent->client->ps.gunframe = 4;
	else
		ent->client->ps.gunframe = 5;

	if (ent->client->pers.inventory[ent->client->ammo_index] < 1)
	{
		ent->client->ps.gunframe = 6;
		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=1 ; i<3 ; i++)
	{
		ent->client->kick_origin[i] = crandom() * 0.35;
		ent->client->kick_angles[i] = crandom() * 0.7;
	}
	ent->client->kick_origin[0] = crandom() * 0.35;
	ent->client->kick_angles[0] = ent->client->machinegun_shots * -1.5;

	// raise the gun as it is firing
	if (!deathmatch->value)
	{
		ent->client->machinegun_shots++;
		if (ent->client->machinegun_shots > 9)
			ent->client->machinegun_shots = 9;
	}

	// get start / end positions
	VectorAdd (ent->client->v_angle, ent->client->kick_angles, angles);
	AngleVectors (angles, forward, right, NULL);
	VectorSet(offset, 0, 8, ent->viewheight-8);
	P_ProjectSource (ent->client, ent->s.origin, offset, forward, right, start);

#ifdef WEAP_BALANCE_OK	
	if ((int)ctfflags->value & CTF_WEAP_BALANCE) //loss of accuracy
		fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD + 100, DEFAULT_BULLET_VSPREAD + 100, MOD_MACHINEGUN);
	else //id original code
		fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
#else
	fire_bullet (ent, start, forward, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);
#endif

	gi.WriteByte (svc_muzzleflash);
	gi.WriteShort (ent-g_edicts);
	gi.WriteByte (MZ_MACHINEGUN | 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]--;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq 0x58(%rdi), %rax
testb $0x1, 0xe3c(%rax)
jne 0x4dc41
movl $0x0, 0xef0(%rax)
incl 0x5c(%rax)
jmp 0x4dff4
movq %rdi, %rbx
xorl %ecx, %ecx
cmpl $0x5, 0x5c(%rax)
sete %cl
xorl $0x5, %ecx
movl %ecx, 0x5c(%rax)
movslq 0xe38(%rax), %rcx
cmpl $0x0, 0x318(%rax,%rcx,4)
jle 0x4df63
movl 0x4b426(%rip), %ebp     # 0x99094
testl %ebp, %ebp
movl $0x8, %eax
movl $0x20, %ecx
cmovel %eax, %ecx
movl %ecx, 0x4(%rsp)
xorl %r14d, %r14d
movl $0x7fff, %r15d          # imm = 0x7FFF
callq 0x19a10
andl %r15d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x55e7(%rip), %xmm1     # 0x53288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x7f67(%rip), %xmm1     # 0x55c18
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
mulsd 0xd1d7(%rip), %xmm0     # 0x5ae98
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe8c(%rax,%r14,4)
callq 0x19a10
andl %r15d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x559e(%rip), %xmm0     # 0x53288
cvtss2sd %xmm0, %xmm0
addsd 0x7f22(%rip), %xmm0     # 0x55c18
addsd %xmm0, %xmm0
mulsd 0x9cee(%rip), %xmm0     # 0x579f0
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe80(%rax,%r14,4)
incq %r14
cmpq $0x2, %r14
jne 0x4dc8a
testl %ebp, %ebp
movl $0x2, %eax
movl $0x8, %r14d
cmovel %eax, %r14d
callq 0x19a10
andl $0x7fff, %eax           # imm = 0x7FFF
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x553d(%rip), %xmm0     # 0x53288
cvtss2sd %xmm0, %xmm0
addsd 0x7ec1(%rip), %xmm0     # 0x55c18
addsd %xmm0, %xmm0
mulsd 0xd135(%rip), %xmm0     # 0x5ae98
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe88(%rax)
movl 0xef0(%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd 0xd118(%rip), %xmm0     # 0x5aea0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe7c(%rax)
movq 0x1b125(%rip), %rdx     # 0x68ec0
movq (%rdx), %rdx
movss 0x20(%rdx), %xmm1
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm1
jne 0x4ddc1
jp 0x4ddc1
leal 0x1(%rcx), %edx
cmpl $0x9, %ecx
movl $0x9, %ecx
cmovll %edx, %ecx
movl %ecx, 0xef0(%rax)
movsd 0xebc(%rax), %xmm1
movss 0xe80(%rax), %xmm2
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
addps %xmm1, %xmm0
leaq 0x18(%rsp), %rdi
movlps %xmm0, (%rdi)
movss 0xec4(%rax), %xmm0
addss 0xe84(%rax), %xmm0
movss %xmm0, 0x8(%rdi)
leaq 0x30(%rsp), %r13
leaq 0x24(%rsp), %rbp
movq %r13, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x183a0
movsd 0xd00d(%rip), %xmm0     # 0x5ae20
leaq 0x8(%rsp), %rdx
movsd %xmm0, (%rdx)
movl 0x278(%rbx), %eax
addl $-0x8, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x8(%rdx)
movq 0x58(%rbx), %rax
leaq 0x4(%rbx), %r12
movl 0x300(%rax), %edi
leaq 0x3c(%rsp), %r15
movq %r12, %rsi
movq %r13, %rcx
movq %rbp, %r8
movq %r15, %r9
callq 0x4d0c5
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movl 0x4(%rsp), %ecx
movl %r14d, %r8d
movl $0x12c, %r9d            # imm = 0x12C
pushq $0x4
pushq $0x1f4                  # imm = 0x1F4
callq 0x19a30
addq $0x10, %rsp
movq 0x1a77e(%rip), %r14     # 0x68600
movl $0x1, %edi
callq *0xc8(%r14)
movq 0x1a6c3(%rip), %rax     # 0x68558
movq %rbx, %rcx
subq (%rax), %rcx
shrq $0x3, %rcx
imull $0x8ce2cabd, %ecx, %edi # imm = 0x8CE2CABD
callq *0xd0(%r14)
movzbl 0x4b1e5(%rip), %edi     # 0x99098
shll $0x7, %edi
incl %edi
callq *0xc8(%r14)
movq %r12, %rdi
movl $0x2, %esi
callq *0xb0(%r14)
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x18ef0
movq 0x1a733(%rip), %rax     # 0x68618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0xd, %eax
movq 0x58(%rbx), %rax
jb 0x4df05
movslq 0xe38(%rax), %rcx
decl 0x318(%rax,%rcx,4)
movl $0x4, 0xef8(%rax)
movb 0x10(%rax), %bpl
callq 0x19a10
andl $0x7fff, %eax           # imm = 0x7FFF
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x535c(%rip), %xmm0     # 0x53288
cvtss2sd %xmm0, %xmm0
addsd 0xcf70(%rip), %xmm0     # 0x5aea8
cvttsd2si %xmm0, %eax
testb $0x1, %bpl
jne 0x4dfdc
movl $0x2e, %ecx
subl %eax, %ecx
movl %ecx, 0x38(%rbx)
movq 0x58(%rbx), %rax
movl $0x35, 0xef4(%rax)
jmp 0x4dff4
movl $0x6, 0x5c(%rax)
movq 0x1ae2f(%rip), %r14     # 0x68da0
movss 0x4(%r14), %xmm0
ucomiss 0x244(%rbx), %xmm0
jb 0x4dfc6
movq 0x1a679(%rip), %rax     # 0x68600
movq 0x20(%rax), %r15
leaq 0x5d9d(%rip), %rdi      # 0x53d2f
callq *0x48(%rax)
movss 0x4f8b(%rip), %xmm0     # 0x52f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r15
movss 0x4f70(%rip), %xmm0     # 0x52f28
addss 0x4(%r14), %xmm0
movss %xmm0, 0x244(%rbx)
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x192b0
movl $0xa0, %ecx
subl %eax, %ecx
movl %ecx, 0x38(%rbx)
movq 0x58(%rbx), %rax
movl $0xa8, 0xef4(%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq