// File: /workspace/github_c_makefile_star2_O1/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 0x4e974
movl $0x0, 0xef0(%rax)
incl 0x5c(%rax)
jmp 0x4ed2e
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 0x4ec9d
movl 0x4b6f3(%rip), %ebp     # 0x9a094
testl %ebp, %ebp
movl $0x8, %eax
movl $0x20, %ecx
cmovel %eax, %ecx
movl %ecx, 0x8(%rsp)
xorl %r14d, %r14d
movl $0x7fff, %r15d          # imm = 0x7FFF
callq 0x19a20
andl %r15d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x58b4(%rip), %xmm1     # 0x54288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x81cc(%rip), %xmm1     # 0x56bb0
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
mulsd 0xd144(%rip), %xmm0     # 0x5bb38
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe8c(%rax,%r14,4)
callq 0x19a20
andl %r15d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x586b(%rip), %xmm0     # 0x54288
cvtss2sd %xmm0, %xmm0
addsd 0x8187(%rip), %xmm0     # 0x56bb0
addsd %xmm0, %xmm0
mulsd 0x9dab(%rip), %xmm0     # 0x587e0
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe80(%rax,%r14,4)
incq %r14
cmpq $0x2, %r14
jne 0x4e9bd
testl %ebp, %ebp
movl $0x2, %eax
movl $0x8, %r14d
cmovel %eax, %r14d
callq 0x19a20
andl $0x7fff, %eax           # imm = 0x7FFF
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x580a(%rip), %xmm0     # 0x54288
cvtss2sd %xmm0, %xmm0
addsd 0x8126(%rip), %xmm0     # 0x56bb0
addsd %xmm0, %xmm0
mulsd 0xd0a2(%rip), %xmm0     # 0x5bb38
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe88(%rax)
movl 0xef0(%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd 0xd085(%rip), %xmm0     # 0x5bb40
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe7c(%rax)
movq 0x1b3f2(%rip), %rdx     # 0x69ec0
movq (%rdx), %rdx
movss 0x20(%rdx), %xmm1
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm1
jne 0x4eaf4
jp 0x4eaf4
leal 0x1(%rcx), %edx
cmpl $0x9, %ecx
movl $0x9, %ecx
cmovll %edx, %ecx
movl %ecx, 0xef0(%rax)
addss 0xebc(%rax), %xmm0
leaq 0x18(%rsp), %rdi
movss %xmm0, (%rdi)
movss 0xec0(%rax), %xmm0
addss 0xe80(%rax), %xmm0
movss %xmm0, 0x4(%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
movabsq $0x4100000000000000, %rax # imm = 0x4100000000000000
leaq 0xc(%rsp), %rdx
movq %rax, (%rdx)
movl 0x278(%rbx), %eax
addl $-0x8, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x8(%rdx)
movq 0x58(%rbx), %rdi
leaq 0x4(%rbx), %r12
leaq 0x3c(%rsp), %r15
movq %r12, %rsi
movq %r13, %rcx
movq %rbp, %r8
movq %r15, %r9
callq 0x4dde7
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movl 0x8(%rsp), %ecx
movl %r14d, %r8d
movl $0x12c, %r9d            # imm = 0x12C
pushq $0x4
pushq $0x1f4                  # imm = 0x1F4
callq 0x19a40
addq $0x10, %rsp
movq 0x1aa48(%rip), %r14     # 0x69600
movl $0x1, %edi
callq *0xc8(%r14)
movq 0x1a98d(%rip), %rax     # 0x69558
movq %rbx, %rcx
subq (%rax), %rcx
shrq $0x3, %rcx
imull $0x8ce2cabd, %ecx, %edi # imm = 0x8CE2CABD
callq *0xd0(%r14)
movzbl 0x4b4af(%rip), %edi     # 0x9a098
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 0x1a9fd(%rip), %rax     # 0x69618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0xd, %eax
jb 0x4ec3b
movq 0x58(%rbx), %rax
movslq 0xe38(%rax), %rcx
decl 0x318(%rax,%rcx,4)
movq 0x58(%rbx), %rax
movl $0x4, 0xef8(%rax)
movb 0x10(%rax), %bpl
callq 0x19a20
andl $0x7fff, %eax           # imm = 0x7FFF
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x5622(%rip), %xmm0     # 0x54288
cvtss2sd %xmm0, %xmm0
addsd 0xced6(%rip), %xmm0     # 0x5bb48
cvttsd2si %xmm0, %eax
testb $0x1, %bpl
jne 0x4ed16
movl $0x2e, %ecx
subl %eax, %ecx
movl %ecx, 0x38(%rbx)
movq 0x58(%rbx), %rax
movl $0x35, 0xef4(%rax)
jmp 0x4ed2e
movl $0x6, 0x5c(%rax)
movq 0x1b0f5(%rip), %r14     # 0x69da0
movss 0x4(%r14), %xmm0
ucomiss 0x244(%rbx), %xmm0
jb 0x4ed00
movq 0x1a93f(%rip), %rax     # 0x69600
movq 0x20(%rax), %r15
leaq 0x6023(%rip), %rdi      # 0x54cef
callq *0x48(%rax)
movss 0x5251(%rip), %xmm0     # 0x53f28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl $0x2, %esi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r15
movss 0x5236(%rip), %xmm0     # 0x53f28
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