// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/g_weapon.c
// Function: fire_lead
static void fire_lead (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int te_impact, int hspread, int vspread, int mod)
{
	trace_t		tr;
	vec3_t		dir;
	vec3_t		forward, right, up;
	vec3_t		end;
	float		r;
	float		u;
	vec3_t		water_start;
	qboolean	water = false;
	int			content_mask = MASK_SHOT | MASK_WATER;

	tr = gi.trace (self->s.origin, NULL, NULL, start, self, MASK_SHOT);
	if (!(tr.fraction < 1.0))
	{
		vectoangles (aimdir, dir);
		AngleVectors (dir, forward, right, up);

		r = crandom()*hspread;
		u = crandom()*vspread;
		VectorMA (start, 8192, forward, end);
		VectorMA (end, r, right, end);
		VectorMA (end, u, up, end);

		if (gi.pointcontents (start) & MASK_WATER)
		{
			water = true;
			VectorCopy (start, water_start);
			content_mask &= ~MASK_WATER;
		}

		tr = gi.trace (start, NULL, NULL, end, self, content_mask);

		// see if we hit water
		if (tr.contents & MASK_WATER)
		{
			int		color;

			water = true;
			VectorCopy (tr.endpos, water_start);

			if (!VectorCompare (start, tr.endpos))
			{
				if (tr.contents & CONTENTS_WATER)
				{
					if (strcmp(tr.surface->name, "*brwater") == 0)
						color = SPLASH_BROWN_WATER;
					else
						color = SPLASH_BLUE_WATER;
				}
				else if (tr.contents & CONTENTS_SLIME)
					color = SPLASH_SLIME;
				else if (tr.contents & CONTENTS_LAVA)
					color = SPLASH_LAVA;
				else
					color = SPLASH_UNKNOWN;

				if (color != SPLASH_UNKNOWN)
				{
					gi.WriteByte (svc_temp_entity);
					gi.WriteByte (TE_SPLASH);
					gi.WriteByte (8);
					gi.WritePosition (tr.endpos);
					gi.WriteDir (tr.plane.normal);
					gi.WriteByte (color);
					gi.multicast (tr.endpos, MULTICAST_PVS);
				}

				// change bullet's course when it enters water
				VectorSubtract (end, start, dir);
				vectoangles (dir, dir);
				AngleVectors (dir, forward, right, up);
				r = crandom()*hspread*2;
				u = crandom()*vspread*2;
				VectorMA (water_start, 8192, forward, end);
				VectorMA (end, r, right, end);
				VectorMA (end, u, up, end);
			}

			// re-trace ignoring water this time
			tr = gi.trace (water_start, NULL, NULL, end, self, MASK_SHOT);
		}
	}

	// send gun puff / flash
	if (!((tr.surface) && (tr.surface->flags & SURF_SKY)))
	{
		if (tr.fraction < 1.0)
		{
			if (tr.ent->takedamage)
			{
				T_Damage (tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, DAMAGE_BULLET, mod);
			}
			else
			{
				if (strncmp (tr.surface->name, "sky", 3) != 0)
				{
					gi.WriteByte (svc_temp_entity);
					gi.WriteByte (te_impact);
					gi.WritePosition (tr.endpos);
					gi.WriteDir (tr.plane.normal);
					gi.multicast (tr.endpos, MULTICAST_PVS);

					if (self->client)
						PlayerNoise(self, tr.endpos, PNOISE_IMPACT);
				}
			}
		}
	}

	// if went through water, determine where the end and make a bubble trail
	if (water)
	{
		vec3_t	pos;

		VectorSubtract (tr.endpos, water_start, dir);
		VectorNormalize (dir);
		VectorMA (tr.endpos, -2, dir, pos);
		if (gi.pointcontents (pos) & MASK_WATER)
			VectorCopy (pos, tr.endpos);
		else
			tr = gi.trace (pos, NULL, NULL, water_start, tr.ent, MASK_WATER);

		VectorAdd (water_start, tr.endpos, pos);
		VectorScale (pos, 0.5, pos);

		gi.WriteByte (svc_temp_entity);
		gi.WriteByte (TE_BUBBLETRAIL);
		gi.WritePosition (water_start);
		gi.WritePosition (tr.endpos);
		gi.multicast (pos, MULTICAST_PVS);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %r9d, 0x34(%rsp)
movl %r8d, 0x38(%rsp)
movl %ecx, 0x3c(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
movq 0x293f0(%rip), %rbp     # 0x68600
leaq 0x4(%rdi), %rsi
movl $0x6000003, (%rsp)      # imm = 0x6000003
xorl %r12d, %r12d
leaq 0x68(%rsp), %r15
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r13, %r8
movq %rbx, %r9
callq *0x60(%rbp)
movss 0x13ced(%rip), %xmm0    # 0x52f28
ucomiss 0x8(%r15), %xmm0
ja 0x3f628
movl 0x170(%rsp), %ebp
leaq 0xc0(%rsp), %r14
movq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x190d0
leaq 0xe4(%rsp), %r12
leaq 0xd8(%rsp), %r15
leaq 0xcc(%rsp), %rcx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x183a0
callq 0x19a10
movl $0x7fff, %r14d          # imm = 0x7FFF
andl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x13fe3(%rip), %xmm0    # 0x53288
cvtss2sd %xmm0, %xmm0
addsd 0x16967(%rip), %xmm0    # 0x55c18
cvtsi2sd %ebp, %xmm1
movq 0x29344(%rip), %rbp     # 0x68600
addsd %xmm0, %xmm0
movsd %xmm1, 0xb8(%rsp)
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
callq 0x19a10
andl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x13f9a(%rip), %xmm0    # 0x53288
cvtss2sd %xmm0, %xmm0
addsd 0x1691e(%rip), %xmm0    # 0x55c18
xorps %xmm1, %xmm1
cvtsi2sdl 0x178(%rsp), %xmm1
addsd %xmm0, %xmm0
movsd %xmm1, 0xb0(%rsp)
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
movss 0x1a243(%rip), %xmm0    # 0x5956c
leaq 0x58(%rsp), %r14
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x19760
movq %r14, %rdi
movss 0x24(%rsp), %xmm0
movq %r15, %rsi
movq %r14, %rdx
callq 0x19760
movq %r14, %rdi
movss 0x20(%rsp), %xmm0
leaq 0xcc(%rsp), %rsi
movq %r14, %rdx
callq 0x19760
movq %r13, %rdi
callq *0x68(%rbp)
testb $0x38, %al
je 0x3f398
movsd (%r13), %xmm0
movsd %xmm0, 0x28(%rsp)
movss 0x8(%r13), %xmm0
movss %xmm0, 0x30(%rsp)
movl $0x6000003, %eax        # imm = 0x6000003
movl $0x1, %r12d
jmp 0x3f3a0
movl $0x600003b, %eax        # imm = 0x600003B
xorl %r12d, %r12d
movl %eax, (%rsp)
leaq 0xf0(%rsp), %r14
leaq 0x58(%rsp), %r8
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, %r9
callq *0x60(%rbp)
leaq 0x68(%rsp), %rax
movl $0x9, %ecx
movq %rax, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
testb $0x38, 0x38(%rax)
movss 0x13b49(%rip), %xmm0    # 0x52f28
je 0x3f628
leaq 0x74(%rsp), %rbp
movsd (%rbp), %xmm0
movsd %xmm0, 0x28(%rsp)
movss 0x8(%rbp), %xmm0
movss %xmm0, 0x30(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18b70
testl %eax, %eax
jne 0x3f5dd
movl 0xa0(%rsp), %eax
testb $0x20, %al
jne 0x3f434
movl $0x4, %r15d
testb $0x10, %al
jne 0x3f452
movl $0x5, %r15d
testb $0x8, %al
jne 0x3f452
jmp 0x3f4af
movq 0x98(%rsp), %rdi
leaq 0x1a26c(%rip), %rsi     # 0x596af
callq 0x18b20
xorl %r15d, %r15d
cmpl $0x1, %eax
adcl $0x2, %r15d
movl $0x3, %edi
movq 0x291a2(%rip), %r14     # 0x68600
callq *0xc8(%r14)
movl $0xa, %edi
callq *0xc8(%r14)
movl $0x8, %edi
callq *0xc8(%r14)
movq %rbp, %rdi
callq *0xf0(%r14)
leaq 0x80(%rsp), %rdi
callq *0xf8(%r14)
movl %r15d, %edi
callq *0xc8(%r14)
movq %rbp, %rdi
movl $0x2, %esi
callq *0xb0(%r14)
leaq 0x58(%rsp), %rbp
movsd (%rbp), %xmm0
movsd (%r13), %xmm1
subps %xmm1, %xmm0
leaq 0xc0(%rsp), %r14
movlps %xmm0, (%r14)
movss 0x8(%rbp), %xmm0
subss 0x8(%r13), %xmm0
movss %xmm0, 0x8(%r14)
movq %r14, %rdi
movq %r14, %rsi
callq 0x190d0
leaq 0xe4(%rsp), %r12
leaq 0xd8(%rsp), %r15
leaq 0xcc(%rsp), %r13
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x183a0
callq 0x19a10
movl $0x7fff, %r14d          # imm = 0x7FFF
andl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x13d58(%rip), %xmm1    # 0x53288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x166d8(%rip), %xmm1    # 0x55c18
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
mulsd 0xb8(%rsp), %xmm0
addsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
callq 0x19a10
andl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x13d12(%rip), %xmm0    # 0x53288
cvtss2sd %xmm0, %xmm0
addsd 0x16696(%rip), %xmm0    # 0x55c18
addsd %xmm0, %xmm0
mulsd 0xb0(%rsp), %xmm0
addsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
movss 0x19fc2(%rip), %xmm0    # 0x5956c
movq %r12, %rsi
movq %rbp, %rdx
callq 0x19760
movq %rbp, %rdi
movss 0x24(%rsp), %xmm0
movq %r15, %rsi
movq %rbp, %rdx
callq 0x19760
movq %rbp, %rdi
movss 0x20(%rsp), %xmm0
movq %r13, %rsi
movq %rbp, %rdx
callq 0x19760
movl $0x6000003, (%rsp)      # imm = 0x6000003
leaq 0xf0(%rsp), %r14
leaq 0x28(%rsp), %rsi
leaq 0x58(%rsp), %r8
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, %r9
movq 0x28ff9(%rip), %rbp     # 0x68600
callq *0x60(%rbp)
leaq 0x68(%rsp), %rdi
movl $0x9, %ecx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %r12d
movss 0x13900(%rip), %xmm0    # 0x52f28
movq 0x98(%rsp), %rax
testq %rax, %rax
je 0x3f63f
testb $0x4, 0x10(%rax)
jne 0x3f703
ucomiss 0x70(%rsp), %xmm0
jbe 0x3f703
movq 0xa8(%rsp), %rdi
cmpl $0x0, 0x27c(%rdi)
je 0x3f69c
movl 0x180(%rsp), %eax
leaq 0x74(%rsp), %r8
leaq 0x80(%rsp), %r9
movl %eax, 0x18(%rsp)
movl 0x38(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, (%rsp)
movl $0x10, 0x10(%rsp)
movq %rbx, %rsi
movq %rbx, %rdx
movq 0x50(%rsp), %rcx
callq 0x190f0
jmp 0x3f703
cmpb $0x73, (%rax)
jne 0x3f6ad
cmpb $0x6b, 0x1(%rax)
jne 0x3f6ad
cmpb $0x79, 0x2(%rax)
je 0x3f703
movl $0x3, %edi
callq *0xc8(%rbp)
movl 0x34(%rsp), %edi
callq *0xc8(%rbp)
leaq 0x74(%rsp), %r14
movq %r14, %rdi
callq *0xf0(%rbp)
leaq 0x80(%rsp), %rdi
callq *0xf8(%rbp)
movq %r14, %rdi
movl $0x2, %esi
callq *0xb0(%rbp)
cmpq $0x0, 0x58(%rbx)
je 0x3f703
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0x18ef0
testl %r12d, %r12d
je 0x3f833
leaq 0x74(%rsp), %rbx
movsd (%rbx), %xmm0
movsd 0x28(%rsp), %xmm1
subps %xmm1, %xmm0
leaq 0xc0(%rsp), %r14
movlps %xmm0, (%r14)
movss 0x8(%rbx), %xmm0
subss 0x30(%rsp), %xmm0
movss %xmm0, 0x8(%r14)
movq %r14, %rdi
callq 0x18390
movss 0x14cc5(%rip), %xmm0    # 0x54410
leaq 0x40(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x19760
movq %r15, %rdi
callq *0x68(%rbp)
testb $0x38, %al
je 0x3f782
movsd 0x40(%rsp), %xmm1
movsd %xmm1, 0x74(%rsp)
movss 0x48(%rsp), %xmm0
movss %xmm0, 0x7c(%rsp)
jmp 0x3f7c8
leaq 0x68(%rsp), %r14
movq 0x40(%r14), %r9
movl $0x38, (%rsp)
leaq 0xf0(%rsp), %r15
leaq 0x40(%rsp), %rsi
leaq 0x28(%rsp), %r8
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x60(%rbp)
movl $0x9, %ecx
movq %r14, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movsd 0xc(%r14), %xmm1
movss 0x14(%r14), %xmm0
leaq 0x28(%rsp), %r14
movsd (%r14), %xmm2
addps %xmm1, %xmm2
leaq 0x40(%rsp), %r15
movlps %xmm2, (%r15)
addss 0x8(%r14), %xmm0
movss %xmm0, 0x8(%r15)
movss 0x14c0e(%rip), %xmm0    # 0x54400
movq %r15, %rdi
movq %r15, %rsi
callq 0x189d0
movl $0x3, %edi
callq *0xc8(%rbp)
movl $0xb, %edi
callq *0xc8(%rbp)
movq %r14, %rdi
callq *0xf0(%rbp)
movq %rbx, %rdi
callq *0xf0(%rbp)
movq %r15, %rdi
movl $0x2, %esi
callq *0xb0(%rbp)
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq