// File: /workspace/github_c_makefile_star2_O2/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 0x3d2f1
movq %rsi, %rbx
movq %rdi, %r14
movss 0x18400(%rip), %xmm0    # 0x5554c
leaq 0x3c(%rsp), %rax
movq %rsi, %rdi
movq %rdx, 0x20(%rsp)
movq %rdx, %rsi
movq %rax, %rdx
callq 0x19940
movsd (%rbx), %xmm0
leaq 0x8(%rsp), %rax
movsd %xmm0, (%rax)
movq %rbx, 0x18(%rsp)
leaq 0x8(%rbx), %rax
xorl %r15d, %r15d
movl $0x600001b, %r13d       # imm = 0x600001B
leaq 0x90(%rsp), %r12
leaq 0x48(%rsp), %rbp
movq %r14, %rbx
movss (%rax), %xmm0
movss %xmm0, 0x10(%rsp)
testq %rbx, %rbx
je 0x3d263
subq $0x8, %rsp
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x44(%rsp), %r8
movq %rbx, %r9
pushq %r13
movq 0x29439(%rip), %rax     # 0x66600
callq *0x60(%rax)
addq $0x10, %rsp
pushq $0x9
popq %rcx
movq %rbp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
testb $0x18, 0x80(%rsp)
je 0x3d201
andl $-0x19, %r13d
pushq $0x1
popq %rax
movl %eax, %r15d
movsd 0x54(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x5c(%rsp), %rax
jmp 0x3d193
movq 0x88(%rsp), %rdi
testb $0x4, 0xc8(%rdi)
jne 0x3d222
cmpq $0x0, 0x58(%rdi)
jne 0x3d222
cmpl $0x2, 0x108(%rdi)
jne 0x3d25f
movq %rdi, %rbx
cmpq %r14, %rdi
je 0x3d1ee
cmpl $0x0, 0x27c(%rdi)
je 0x3d1ee
movq %r14, %rsi
movq %r14, %rdx
movq 0x20(%rsp), %rcx
leaq 0x54(%rsp), %r8
leaq 0x60(%rsp), %r9
pushq $0xb
pushq $0x0
pushq 0x40(%rsp)
pushq 0x40(%rsp)
callq 0x19260
addq $0x20, %rsp
jmp 0x3d1ee
xorl %ebx, %ebx
jmp 0x3d225
pushq $0x3
popq %rbx
movl %ebx, %edi
movq 0x29391(%rip), %rbp     # 0x66600
callq *0xc8(%rbp)
movl %ebx, %edi
callq *0xc8(%rbp)
movq 0x18(%rsp), %r13
movq %r13, %rdi
callq *0xf0(%rbp)
leaq 0x54(%rsp), %r12
movq %r12, %rdi
callq *0xf0(%rbp)
leaq 0x4(%r14), %rdi
pushq $0x1
popq %rsi
callq *0xb0(%rbp)
testl %r15d, %r15d
je 0x3d2dc
pushq $0x3
popq %rbx
movl %ebx, %edi
callq *0xc8(%rbp)
movl %ebx, %edi
callq *0xc8(%rbp)
movq %r13, %rdi
callq *0xf0(%rbp)
movq %r12, %rdi
callq *0xf0(%rbp)
pushq $0x1
popq %rsi
movq %r12, %rdi
callq *0xb0(%rbp)
cmpq $0x0, 0x58(%r14)
je 0x3d2f1
pushq $0x2
popq %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x19010
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq