// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/g_weapon.c
// Function: fire_rail
void fire_rail (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick)
{
	vec3_t		from;
	vec3_t		end;
	trace_t		tr;
	edict_t		*ignore;
	int			mask;
	qboolean	water;

	if (!self)	// self must not be null
		return;

#ifdef WEAP_BALANCE_OK
	if ((int)ctfflags->value & CTF_WEAP_BALANCE)
	{
		fire_lead (self, start, aimdir, 4, 0, TE_GUNSHOT, 512, 512, MOD_RAILGUN);
		fire_lead (self, start, aimdir, 4, 0, TE_GUNSHOT, 512, -512, MOD_RAILGUN);
		fire_lead (self, start, aimdir, 4, 0, TE_GUNSHOT, -512, 512, MOD_RAILGUN);
		fire_lead (self, start, aimdir, 4, 0, TE_GUNSHOT, -512, -512, MOD_RAILGUN);
	}
#endif


	VectorMA (start, 8192, aimdir, end);
	VectorCopy (start, from);
	ignore = self;
	water = false;
	mask = MASK_SHOT|CONTENTS_SLIME|CONTENTS_LAVA;
	while (ignore)
	{
		tr = gi.trace (from, NULL, NULL, end, ignore, mask);

		if (tr.contents & (CONTENTS_SLIME|CONTENTS_LAVA))
		{
			mask &= ~(CONTENTS_SLIME|CONTENTS_LAVA);
			water = true;
		}
		else
		{
			//ZOID--added so rail goes through SOLID_BBOX entities (gibs, etc)
			if ((tr.ent->svflags & SVF_MONSTER) || (tr.ent->client) ||
				(tr.ent->solid == SOLID_BBOX))
				ignore = tr.ent;
			else
				ignore = NULL;

			if ((tr.ent != self) && (tr.ent->takedamage))
				T_Damage (tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, 0, MOD_RAILGUN);
		}

		VectorCopy (tr.endpos, from);
	}

	// send gun puff / flash
	gi.WriteByte (svc_temp_entity);
	gi.WriteByte (TE_RAILTRAIL);
	gi.WritePosition (start);
	gi.WritePosition (tr.endpos);
	gi.multicast (self->s.origin, MULTICAST_PHS);
//	gi.multicast (start, MULTICAST_PHS);
	if (water)
	{
		gi.WriteByte (svc_temp_entity);
		gi.WriteByte (TE_RAILTRAIL);
		gi.WritePosition (start);
		gi.WritePosition (tr.endpos);
		gi.multicast (tr.endpos, MULTICAST_PHS);
	}

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r8, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
testq %rdi, %rdi
je 0x408f0
movq %rsi, %rbx
movq %rdi, %rbp
movss 0x18e42(%rip), %xmm0    # 0x5956c
leaq 0x3c(%rsp), %rax
movq %rsi, %rdi
movq %rdx, 0x20(%rsp)
movq %rdx, %rsi
movq %rax, %rdx
callq 0x19760
movsd (%rbx), %xmm0
leaq 0x8(%rsp), %rax
movsd %xmm0, (%rax)
movq %rbx, 0x18(%rsp)
movss 0x8(%rbx), %xmm0
movss %xmm0, 0x8(%rax)
movl $0x600001b, %r14d       # imm = 0x600001B
xorl %r15d, %r15d
leaq 0x90(%rsp), %r12
leaq 0x48(%rsp), %r13
movq %rbp, %rbx
subq $0x8, %rsp
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x44(%rsp), %r8
movq %rbx, %r9
pushq %r14
movq 0x27e68(%rip), %rax     # 0x68600
callq *0x60(%rax)
addq $0x10, %rsp
movl $0x9, %ecx
movq %r13, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
testb $0x18, 0x80(%rsp)
je 0x407e0
andl $-0x19, %r14d
movl $0x1, %r15d
movsd 0x54(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movss 0x5c(%rsp), %xmm0
movss %xmm0, 0x10(%rsp)
testq %rbx, %rbx
jne 0x40777
jmp 0x40842
movq 0x88(%rsp), %rdi
testb $0x4, 0xc8(%rdi)
jne 0x40801
cmpq $0x0, 0x58(%rdi)
jne 0x40801
cmpl $0x2, 0x108(%rdi)
jne 0x4083e
movq %rdi, %rbx
cmpq %rbp, %rdi
je 0x407c1
cmpl $0x0, 0x27c(%rdi)
je 0x407c1
movq %rbp, %rsi
movq %rbp, %rdx
movq 0x20(%rsp), %rcx
leaq 0x54(%rsp), %r8
leaq 0x60(%rsp), %r9
pushq $0xb
pushq $0x0
pushq 0x40(%rsp)
pushq 0x40(%rsp)
callq 0x190f0
addq $0x20, %rsp
jmp 0x407c1
xorl %ebx, %ebx
jmp 0x40804
movl $0x3, %edi
movq 0x27db2(%rip), %r12     # 0x68600
callq *0xc8(%r12)
movl $0x3, %edi
callq *0xc8(%r12)
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq *0xf0(%r12)
leaq 0x54(%rsp), %r14
movq %r14, %rdi
callq *0xf0(%r12)
leaq 0x4(%rbp), %rdi
movl $0x1, %esi
callq *0xb0(%r12)
testl %r15d, %r15d
je 0x408d9
movl $0x3, %edi
callq *0xc8(%r12)
movl $0x3, %edi
callq *0xc8(%r12)
movq %rbx, %rdi
callq *0xf0(%r12)
movq %r14, %rdi
callq *0xf0(%r12)
movq %r14, %rdi
movl $0x1, %esi
callq *0xb0(%r12)
cmpq $0x0, 0x58(%rbp)
je 0x408f0
movq %rbp, %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0x18ef0
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq