// File: /workspace/github_c_makefile_star2_O2/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 0x2a921(%rip), %rbp     # 0x66600
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 0x1321e(%rip), %xmm0    # 0x4ef28
ucomiss 0x8(%r15), %xmm0
ja 0x3c0d4
movl 0x170(%rsp), %ebp
leaq 0xc0(%rsp), %r14
movq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x19240
leaq 0xe4(%rsp), %r12
leaq 0xd8(%rsp), %r15
leaq 0xcc(%rsp), %rcx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x183d0
callq 0x19bf0
movl $0x7fff, %r14d          # imm = 0x7FFF
andl %r14d, %eax
cvtsi2ss %eax, %xmm0
divss 0x13517(%rip), %xmm0    # 0x4f288
cvtss2sd %xmm0, %xmm0
addsd 0x15e7b(%rip), %xmm0    # 0x51bf8
cvtsi2sd %ebp, %xmm1
movq 0x2a878(%rip), %rbp     # 0x66600
addsd %xmm0, %xmm0
movsd %xmm1, 0xb8(%rsp)
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
callq 0x19bf0
andl %r14d, %eax
cvtsi2ss %eax, %xmm0
divss 0x134d1(%rip), %xmm0    # 0x4f288
cvtss2sd %xmm0, %xmm0
addsd 0x15e35(%rip), %xmm0    # 0x51bf8
cvtsi2sdl 0x178(%rsp), %xmm1
addsd %xmm0, %xmm0
movsd %xmm1, 0xb0(%rsp)
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
movss 0x1975d(%rip), %xmm0    # 0x5554c
leaq 0x58(%rsp), %r14
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x19940
movq %r14, %rdi
movss 0x24(%rsp), %xmm0
movq %r15, %rsi
movq %r14, %rdx
callq 0x19940
movq %r14, %rdi
movss 0x20(%rsp), %xmm0
leaq 0xcc(%rsp), %rsi
movq %r14, %rdx
callq 0x19940
movq %r13, %rdi
callq *0x68(%rbp)
testb $0x38, %al
je 0x3be5c
pushq $0x1
popq %r12
movsd (%r13), %xmm0
movsd %xmm0, 0x28(%rsp)
movss 0x8(%r13), %xmm0
movss %xmm0, 0x30(%rsp)
movl $0x6000003, %eax        # imm = 0x6000003
jmp 0x3be64
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)
pushq $0x9
popq %rcx
leaq 0x68(%rsp), %rax
movq %rax, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
testb $0x38, 0x38(%rax)
movss 0x13087(%rip), %xmm0    # 0x4ef28
je 0x3c0d4
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 0x18c20
testl %eax, %eax
jne 0x3c08d
movl 0xa0(%rsp), %eax
testb $0x20, %al
jne 0x3beec
testb $0x10, %al
jne 0x3bf0c
testb $0x8, %al
je 0x3bf65
pushq $0x5
jmp 0x3bf0e
movq 0x98(%rsp), %rdi
leaq 0x19794(%rip), %rsi     # 0x5568f
callq 0x18bc0
xorl %r15d, %r15d
cmpl $0x1, %eax
adcl $0x2, %r15d
jmp 0x3bf10
pushq $0x4
popq %r15
pushq $0x3
popq %rdi
movq 0x2a6e6(%rip), %r14     # 0x66600
callq *0xc8(%r14)
pushq $0xa
popq %rdi
callq *0xc8(%r14)
pushq $0x8
popq %rdi
callq *0xc8(%r14)
movq %rbp, %rdi
callq *0xf0(%r14)
leaq 0x80(%rsp), %rdi
callq *0xf8(%r14)
movl %r15d, %edi
callq *0xc8(%r14)
pushq $0x2
popq %rsi
movq %rbp, %rdi
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 0x19240
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 0x183d0
callq 0x19bf0
movl $0x7fff, %r14d          # imm = 0x7FFF
andl %r14d, %eax
cvtsi2ss %eax, %xmm0
movss 0x132a5(%rip), %xmm1    # 0x4f288
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x15c05(%rip), %xmm1    # 0x51bf8
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
mulsd 0xb8(%rsp), %xmm0
addsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
callq 0x19bf0
andl %r14d, %eax
cvtsi2ss %eax, %xmm0
divss 0x13262(%rip), %xmm0    # 0x4f288
cvtss2sd %xmm0, %xmm0
addsd 0x15bc6(%rip), %xmm0    # 0x51bf8
addsd %xmm0, %xmm0
mulsd 0xb0(%rsp), %xmm0
addsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
movss 0x194f2(%rip), %xmm0    # 0x5554c
movq %r12, %rsi
movq %rbp, %rdx
callq 0x19940
movq %rbp, %rdi
movss 0x24(%rsp), %xmm0
movq %r15, %rsi
movq %rbp, %rdx
callq 0x19940
movq %rbp, %rdi
movss 0x20(%rsp), %xmm0
movq %r13, %rsi
movq %rbp, %rdx
callq 0x19940
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 0x2a549(%rip), %rbp     # 0x66600
callq *0x60(%rbp)
pushq $0x9
popq %rcx
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
pushq $0x1
popq %r12
movss 0x12e54(%rip), %xmm0    # 0x4ef28
movq 0x98(%rsp), %rax
testq %rax, %rax
je 0x3c0eb
testb $0x4, 0x10(%rax)
jne 0x3c1a9
ucomiss 0x70(%rsp), %xmm0
jbe 0x3c1a9
movq 0xa8(%rsp), %rdi
cmpl $0x0, 0x27c(%rdi)
je 0x3c148
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 0x19260
jmp 0x3c1a9
cmpb $0x73, (%rax)
jne 0x3c159
cmpb $0x6b, 0x1(%rax)
jne 0x3c159
cmpb $0x79, 0x2(%rax)
je 0x3c1a9
pushq $0x3
popq %rdi
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)
pushq $0x2
popq %rsi
movq %r14, %rdi
callq *0xb0(%rbp)
cmpq $0x0, 0x58(%rbx)
je 0x3c1a9
pushq $0x2
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19010
testl %r12d, %r12d
je 0x3c2d1
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 0x183c0
movss 0x1421f(%rip), %xmm0    # 0x50410
leaq 0x40(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x19940
movq %r15, %rdi
callq *0x68(%rbp)
testb $0x38, %al
je 0x3c228
movsd 0x40(%rsp), %xmm1
movsd %xmm1, 0x74(%rsp)
movss 0x48(%rsp), %xmm0
movss %xmm0, 0x7c(%rsp)
jmp 0x3c26c
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)
pushq $0x9
popq %rcx
movq %r14, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movsd 0xc(%r14), %xmm1
movss 0x14(%r14), %xmm0
leaq 0x28(%rsp), %r15
movsd (%r15), %xmm2
addps %xmm1, %xmm2
leaq 0x40(%rsp), %r14
movlps %xmm2, (%r14)
addss 0x8(%r15), %xmm0
movss %xmm0, 0x8(%r14)
movss 0x1416a(%rip), %xmm0    # 0x50400
movq %r14, %rdi
movq %r14, %rsi
callq 0x18a70
pushq $0x3
popq %rdi
callq *0xc8(%rbp)
pushq $0xb
popq %rdi
callq *0xc8(%rbp)
movq %r15, %rdi
callq *0xf0(%rbp)
movq %rbx, %rdi
callq *0xf0(%rbp)
pushq $0x2
popq %rsi
movq %r14, %rdi
callq *0xb0(%rbp)
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq