// File: /workspace/github_c_makefile_star2_O1/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, 0x38(%rsp)
movl %r8d, 0x3c(%rsp)
movl %ecx, 0x40(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
movq 0x29b95(%rip), %rbp     # 0x69600
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 0x14492(%rip), %xmm0    # 0x53f28
ucomiss 0x8(%r15), %xmm0
ja 0x3feb3
movl 0x170(%rsp), %ebp
leaq 0xcc(%rsp), %r14
movq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x190d0
leaq 0xe4(%rsp), %r12
leaq 0xd8(%rsp), %r15
leaq 0xc0(%rsp), %rcx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x183a0
callq 0x19a20
movl $0x7fff, %r14d          # imm = 0x7FFF
andl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x14788(%rip), %xmm0    # 0x54288
cvtss2sd %xmm0, %xmm0
addsd 0x170a4(%rip), %xmm0    # 0x56bb0
cvtsi2sd %ebp, %xmm1
movq 0x29ae9(%rip), %rbp     # 0x69600
addsd %xmm0, %xmm0
movsd %xmm1, 0xb8(%rsp)
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x28(%rsp)
callq 0x19a20
andl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x1473f(%rip), %xmm0    # 0x54288
cvtss2sd %xmm0, %xmm0
addsd 0x1705b(%rip), %xmm0    # 0x56bb0
xorps %xmm1, %xmm1
cvtsi2sdl 0x178(%rsp), %xmm1
addsd %xmm0, %xmm0
movsd %xmm1, 0xb0(%rsp)
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
movss 0x1a7d8(%rip), %xmm0    # 0x5a35c
leaq 0x5c(%rsp), %r14
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x19770
movq %r14, %rdi
movss 0x28(%rsp), %xmm0
movq %r15, %rsi
movq %r14, %rdx
callq 0x19770
movq %r14, %rdi
movss 0x24(%rsp), %xmm0
leaq 0xc0(%rsp), %rsi
movq %r14, %rdx
callq 0x19770
movq %r13, %rdi
callq *0x68(%rbp)
testb $0x38, %al
je 0x3fbff
movss (%r13), %xmm0
movss %xmm0, 0x2c(%rsp)
movss 0x4(%r13), %xmm0
movss %xmm0, 0x30(%rsp)
movss 0x8(%r13), %xmm0
movss %xmm0, 0x34(%rsp)
movl $0x6000003, %eax        # imm = 0x6000003
movl $0x1, %r12d
jmp 0x3fc07
movl $0x600003b, %eax        # imm = 0x600003B
xorl %r12d, %r12d
movl %eax, (%rsp)
leaq 0xf0(%rsp), %r14
leaq 0x5c(%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 0x142e2(%rip), %xmm0    # 0x53f28
je 0x3feb3
leaq 0x74(%rsp), %rbp
movss (%rbp), %xmm0
movss %xmm0, 0x2c(%rsp)
movq 0x4(%rbp), %rax
movq %rax, 0x30(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18b70
testl %eax, %eax
jne 0x3fe68
movl 0xa0(%rsp), %eax
testb $0x20, %al
jne 0x3fc9d
testb $0x10, %al
jne 0x3fcc2
movl %eax, %r15d
shll $0x1c, %r15d
sarl $0x1f, %r15d
testb $0x8, %al
sete %cl
andl $0x5, %r15d
jmp 0x3fcca
movq 0x98(%rsp), %rdi
leaq 0x1a7db(%rip), %rsi     # 0x5a487
callq 0x18b20
xorl %ecx, %ecx
cmpl $0x1, %eax
movl $0x0, %r15d
adcl $0x2, %r15d
jmp 0x3fcca
movl $0x4, %r15d
xorl %ecx, %ecx
testb %cl, %cl
jne 0x3fd2b
movl $0x3, %edi
movq 0x29926(%rip), %r14     # 0x69600
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 0x5c(%rsp), %rbp
movss (%rbp), %xmm0
movss 0x4(%rbp), %xmm1
subss (%r13), %xmm0
leaq 0xcc(%rsp), %r14
movss %xmm0, (%r14)
subss 0x4(%r13), %xmm1
movss %xmm1, 0x4(%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 0xc0(%rsp), %r13
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x183a0
callq 0x19a20
movl $0x7fff, %r14d          # imm = 0x7FFF
andl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x144cd(%rip), %xmm1    # 0x54288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x16de5(%rip), %xmm1    # 0x56bb0
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
mulsd 0xb8(%rsp), %xmm0
addsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x28(%rsp)
callq 0x19a20
andl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x14487(%rip), %xmm0    # 0x54288
cvtss2sd %xmm0, %xmm0
addsd 0x16da3(%rip), %xmm0    # 0x56bb0
addsd %xmm0, %xmm0
mulsd 0xb0(%rsp), %xmm0
addsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
leaq 0x2c(%rsp), %rdi
movss 0x1a527(%rip), %xmm0    # 0x5a35c
movq %r12, %rsi
movq %rbp, %rdx
callq 0x19770
movq %rbp, %rdi
movss 0x28(%rsp), %xmm0
movq %r15, %rsi
movq %rbp, %rdx
callq 0x19770
movq %rbp, %rdi
movss 0x24(%rsp), %xmm0
movq %r13, %rsi
movq %rbp, %rdx
callq 0x19770
movl $0x6000003, (%rsp)      # imm = 0x6000003
leaq 0xf0(%rsp), %r14
leaq 0x2c(%rsp), %rsi
leaq 0x5c(%rsp), %r8
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, %r9
movq 0x2976e(%rip), %rbp     # 0x69600
callq *0x60(%rbp)
leaq 0x68(%rsp), %rdi
movl $0x9, %ecx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x1, %r12d
movss 0x14075(%rip), %xmm0    # 0x53f28
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x3fec6
testb $0x4, 0x10(%rdi)
jne 0x3ff24
ucomiss 0x70(%rsp), %xmm0
jbe 0x3ff24
movq 0xa8(%rsp), %rax
cmpl $0x0, 0x27c(%rax)
je 0x40083
movl 0x180(%rsp), %ecx
leaq 0x74(%rsp), %r8
leaq 0x80(%rsp), %r9
movl %ecx, 0x18(%rsp)
movl 0x3c(%rsp), %ecx
movl %ecx, 0x8(%rsp)
movl 0x40(%rsp), %ecx
movl %ecx, (%rsp)
movl $0x10, 0x10(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
movq 0x50(%rsp), %rcx
callq 0x190f0
testl %r12d, %r12d
je 0x40071
leaq 0x74(%rsp), %rbx
movss (%rbx), %xmm0
movss 0x4(%rbx), %xmm1
subss 0x2c(%rsp), %xmm0
leaq 0xcc(%rsp), %r14
movss %xmm0, (%r14)
subss 0x30(%rsp), %xmm1
movss %xmm1, 0x4(%r14)
movss 0x8(%rbx), %xmm0
subss 0x34(%rsp), %xmm0
movss %xmm0, 0x8(%r14)
movq %r14, %rdi
callq 0x18390
movss 0x15495(%rip), %xmm0    # 0x55410
leaq 0x44(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x19770
movq %r15, %rdi
callq *0x68(%rbp)
testb $0x38, %al
je 0x3ffb0
movss 0x44(%rsp), %xmm0
movss %xmm0, 0x74(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x78(%rsp)
jmp 0x3ffea
leaq 0x68(%rsp), %r14
movq 0x40(%r14), %r9
movl $0x38, (%rsp)
leaq 0xf0(%rsp), %r15
leaq 0x44(%rsp), %rsi
leaq 0x2c(%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)
leaq 0x2c(%rsp), %r15
movss (%r15), %xmm0
movss 0x4(%r15), %xmm1
addss 0x74(%rsp), %xmm0
leaq 0x44(%rsp), %r14
movss %xmm0, (%r14)
addss 0x78(%rsp), %xmm1
movss %xmm1, 0x4(%r14)
movss 0x8(%r15), %xmm0
addss 0x7c(%rsp), %xmm0
movss %xmm0, 0x8(%r14)
movss 0x153d4(%rip), %xmm0    # 0x55404
movq %r14, %rdi
movq %r14, %rsi
callq 0x189d0
movl $0x3, %edi
callq *0xc8(%rbp)
movl $0xb, %edi
callq *0xc8(%rbp)
movq %r15, %rdi
callq *0xf0(%rbp)
movq %rbx, %rdi
callq *0xf0(%rbp)
movq %r14, %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
leaq 0x18a56(%rip), %rsi     # 0x58ae0
movl $0x3, %edx
callq 0x181e0
testl %eax, %eax
je 0x3ff24
movl $0x3, %edi
callq *0xc8(%rbp)
movl 0x38(%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 0x3ff24
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0x18ef0
jmp 0x3ff24