// File: /workspace/github_c_makefile_star2_O1/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 0x411bd
movq %rsi, %rbx
movq %rdi, %r13
movss 0x19360(%rip), %xmm0    # 0x5a35c
leaq 0x3c(%rsp), %rax
movq %rsi, %rdi
movq %rdx, 0x20(%rsp)
movq %rdx, %rsi
movq %rax, %rdx
callq 0x19770
movss (%rbx), %xmm0
leaq 0xc(%rsp), %rax
movss %xmm0, (%rax)
movss 0x4(%rbx), %xmm0
movss %xmm0, 0x4(%rax)
movq %rbx, 0x18(%rsp)
movss 0x8(%rbx), %xmm0
movss %xmm0, 0x8(%rax)
movl $0x600001b, %r14d       # imm = 0x600001B
xorl %ebp, %ebp
leaq 0x90(%rsp), %r15
leaq 0x48(%rsp), %r12
movq %r13, %rbx
subq $0x8, %rsp
movq %r15, %rdi
leaq 0x14(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x44(%rsp), %r8
movq %rbx, %r9
pushq %r14
movq 0x2858d(%rip), %rax     # 0x69600
callq *0x60(%rax)
addq $0x10, %rsp
movl $0x9, %ecx
movq %r12, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
testb $0x18, 0x80(%rsp)
je 0x410b8
andl $-0x19, %r14d
movl $0x1, %ebp
movss 0x54(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
testq %rbx, %rbx
jne 0x41052
jmp 0x4111a
movq 0x88(%rsp), %rdi
testb $0x4, 0xc8(%rdi)
jne 0x410d9
cmpq $0x0, 0x58(%rdi)
jne 0x410d9
cmpl $0x2, 0x108(%rdi)
jne 0x41116
movq %rdi, %rbx
cmpq %r13, %rdi
je 0x4109b
cmpl $0x0, 0x27c(%rdi)
je 0x4109b
movq %r13, %rsi
movq %r13, %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 0x4109b
xorl %ebx, %ebx
jmp 0x410dc
movl $0x3, %edi
movq 0x284da(%rip), %r15     # 0x69600
callq *0xc8(%r15)
movl $0x3, %edi
callq *0xc8(%r15)
movq 0x18(%rsp), %r14
movq %r14, %rdi
callq *0xf0(%r15)
leaq 0x54(%rsp), %rbx
movq %rbx, %rdi
callq *0xf0(%r15)
leaq 0x4(%r13), %rdi
movl $0x1, %esi
callq *0xb0(%r15)
testl %ebp, %ebp
je 0x411a6
movl $0x3, %edi
callq *0xc8(%r15)
movl $0x3, %edi
callq *0xc8(%r15)
movq %r14, %rdi
callq *0xf0(%r15)
movq %rbx, %rdi
callq *0xf0(%r15)
movq %rbx, %rdi
movl $0x1, %esi
callq *0xb0(%r15)
cmpq $0x0, 0x58(%r13)
je 0x411bd
movq %r13, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0x18ef0
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq