// File: /workspace/github_c_makefile_star2_O2/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 0x49a0b
andl $0x0, 0xef0(%rax)
incl 0x5c(%rax)
jmp 0x49d96
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 0x49d07
movl 0x4d75b(%rip), %r14d    # 0x97194
testl %r14d, %r14d
pushq $0x8
popq %rbp
pushq $0x20
popq %rax
cmovel %ebp, %eax
movl %eax, 0x4(%rsp)
xorl %r15d, %r15d
movl $0x7fff, %r12d          # imm = 0x7FFF
cmpq $0x2, %r15
je 0x49ae8
callq 0x19bf0
andl %r12d, %eax
cvtsi2ss %eax, %xmm0
movss 0x5818(%rip), %xmm1     # 0x4f288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x8178(%rip), %xmm1     # 0x51bf8
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
mulsd 0xd3c8(%rip), %xmm0     # 0x56e58
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe8c(%rax,%r15,4)
callq 0x19bf0
andl %r12d, %eax
cvtsi2ss %eax, %xmm0
divss 0x57d2(%rip), %xmm0     # 0x4f288
cvtss2sd %xmm0, %xmm0
addsd 0x8136(%rip), %xmm0     # 0x51bf8
addsd %xmm0, %xmm0
mulsd 0x9f02(%rip), %xmm0     # 0x539d0
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe80(%rax,%r15,4)
incq %r15
jmp 0x49a52
testl %r14d, %r14d
pushq $0x2
popq %rax
cmovel %eax, %ebp
callq 0x19bf0
andl $0x7fff, %eax           # imm = 0x7FFF
cvtsi2ss %eax, %xmm0
divss 0x5781(%rip), %xmm0     # 0x4f288
cvtss2sd %xmm0, %xmm0
addsd 0x80e5(%rip), %xmm0     # 0x51bf8
addsd %xmm0, %xmm0
mulsd 0xd339(%rip), %xmm0     # 0x56e58
cvtsd2ss %xmm0, %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xe88(%rax)
movl 0xef0(%rax), %ecx
cvtsi2sd %ecx, %xmm0
mulsd 0xd31f(%rip), %xmm0     # 0x56e60
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe7c(%rax)
movq 0x1d36c(%rip), %rdx     # 0x66ec0
movq (%rdx), %rdx
movss 0x20(%rdx), %xmm1
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm1
jne 0x49b78
jp 0x49b78
leal 0x1(%rcx), %edx
cmpl $0x9, %ecx
pushq $0x9
popq %rcx
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), %r14
movq %r13, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x183d0
movsd 0xd216(%rip), %xmm0     # 0x56de0
leaq 0x8(%rsp), %rdx
movsd %xmm0, (%rdx)
movl 0x278(%rbx), %eax
addl $-0x8, %eax
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 %r14, %r8
movq %r15, %r9
callq 0x48f06
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movl 0x4(%rsp), %ecx
movl %ebp, %r8d
movl $0x12c, %r9d            # imm = 0x12C
pushq $0x4
pushq $0x1f4                  # imm = 0x1F4
callq 0x19c20
popq %rax
popq %rcx
movq 0x1c9d2(%rip), %r14     # 0x66600
pushq $0x1
popq %rbp
movl %ebp, %edi
callq *0xc8(%r14)
movq 0x1c917(%rip), %rcx     # 0x66558
movq %rbx, %rax
subq (%rcx), %rax
movl $0x4a8, %ecx            # imm = 0x4A8
cqto
idivq %rcx
movl %eax, %edi
callq *0xd0(%r14)
movzbl 0x4d537(%rip), %edi     # 0x97198
shll $0x7, %edi
incl %edi
callq *0xc8(%r14)
pushq $0x2
popq %rsi
movq %r12, %rdi
callq *0xb0(%r14)
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x19010
movq 0x1c98a(%rip), %rax     # 0x66618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
btl $0xd, %eax
movq 0x58(%rbx), %rax
jb 0x49cae
movslq 0xe38(%rax), %rcx
decl 0x318(%rax,%rcx,4)
movl $0x4, 0xef8(%rax)
movb 0x10(%rax), %bpl
callq 0x19bf0
andl $0x7fff, %eax           # imm = 0x7FFF
cvtsi2ss %eax, %xmm0
divss 0x55b6(%rip), %xmm0     # 0x4f288
cvtss2sd %xmm0, %xmm0
addsd 0xd18a(%rip), %xmm0     # 0x56e68
cvttsd2si %xmm0, %eax
testb $0x1, %bpl
jne 0x49d7e
pushq $0x2e
popq %rcx
subl %eax, %ecx
movl %ecx, 0x38(%rbx)
movq 0x58(%rbx), %rax
movl $0x35, 0xef4(%rax)
jmp 0x49d96
movl $0x6, 0x5c(%rax)
movq 0x1d08b(%rip), %r14     # 0x66da0
movss 0x4(%r14), %xmm0
ucomiss 0x244(%rbx), %xmm0
jb 0x49d68
movq 0x1c8d5(%rip), %rax     # 0x66600
movq 0x20(%rax), %r15
leaq 0x5ff9(%rip), %rdi      # 0x4fd2f
callq *0x48(%rax)
pushq $0x2
popq %rsi
movss 0x51e4(%rip), %xmm0     # 0x4ef28
xorps %xmm2, %xmm2
movq %rbx, %rdi
movl %eax, %edx
movaps %xmm0, %xmm1
callq *%r15
movss 0x51ce(%rip), %xmm0     # 0x4ef28
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 0x19430
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