// File: /workspace/github_c_makefile_star2_O1/QwazyWabbitWOS[P]lmctf60/g_phys.c
// Function: SV_FlyMove
int SV_FlyMove (edict_t *ent, float time, int mask)
{
	edict_t		*hit;
	int			bumpcount, numbumps;
	vec3_t		dir;
	float		d;
	int			numplanes;
	vec3_t		planes[MAX_CLIP_PLANES];
	vec3_t		primal_velocity, original_velocity, new_velocity;
	int			i, j;
	trace_t		trace;
	vec3_t		end;
	float		time_left;
	int			blocked;
	
	numbumps = 4;
	
	blocked = 0;
	VectorCopy (ent->velocity, original_velocity);
	VectorCopy (ent->velocity, primal_velocity);
	numplanes = 0;
	
	time_left = time;

	ent->groundentity = NULL;
	for (bumpcount=0 ; bumpcount<numbumps ; bumpcount++)
	{
		for (i=0 ; i<3 ; i++)
			end[i] = ent->s.origin[i] + time_left * ent->velocity[i];

		trace = gi.trace (ent->s.origin, ent->mins, ent->maxs, end, ent, mask);

		if (trace.allsolid)
		{	// entity is trapped in another solid
			VectorCopy (vec3_origin, ent->velocity);
			return 3;
		}

		if (trace.fraction > 0)
		{	// actually covered some distance
			VectorCopy (trace.endpos, ent->s.origin);
			VectorCopy (ent->velocity, original_velocity);
			numplanes = 0;
		}

		if (trace.fraction == 1)
			 break;		// moved the entire distance

		hit = trace.ent;

		if (trace.plane.normal[2] > 0.7)
		{
			blocked |= 1;		// floor
			if ( hit->solid == SOLID_BSP)
			{
				ent->groundentity = hit;
				ent->groundentity_linkcount = hit->linkcount;
			}
		}
		if (!trace.plane.normal[2])
		{
			blocked |= 2;		// step
		}

//
// run the impact function
//
		SV_Impact (ent, &trace);
		if (!ent->inuse)
			break;		// removed by the impact function

		
		time_left -= time_left * trace.fraction;
		
	// cliped to another plane
		if (numplanes >= MAX_CLIP_PLANES)
		{	// this shouldn't really happen
			VectorCopy (vec3_origin, ent->velocity);
			return 3;
		}

		VectorCopy (trace.plane.normal, planes[numplanes]);
		numplanes++;

//
// modify original_velocity so it parallels all of the clip planes
//
		for (i=0 ; i<numplanes ; i++)
		{
			ClipVelocity (original_velocity, planes[i], new_velocity, 1);

			for (j=0 ; j<numplanes ; j++)
				if ((j != i) && !VectorCompare (planes[i], planes[j]))
				{
					if (DotProduct (new_velocity, planes[j]) < 0)
						break;	// not ok
				}
			if (j == numplanes)
				break;
		}
		
		if (i != numplanes)
		{	// go along this plane
			VectorCopy (new_velocity, ent->velocity);
		}
		else
		{	// go along the crease
			if (numplanes != 2)
			{
//				gi.dprintf ("clip velocity, numplanes == %i\n",numplanes);
				VectorCopy (vec3_origin, ent->velocity);
				return 7;
			}
			CrossProduct (planes[0], planes[1], dir);
			d = DotProduct (dir, ent->velocity);
			VectorScale (dir, d, ent->velocity);
		}

//
// if original velocity is against the original velocity, stop dead
// to avoid tiny occilations in sloping corners
//
		if (DotProduct (ent->velocity, primal_velocity) <= 0)
		{
			VectorCopy (vec3_origin, ent->velocity);
			return blocked;
		}
	}

	return blocked;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movl %esi, %r15d
movq %rdi, %rbx
leaq 0x1c0(%rdi), %rax
movq %rax, 0x68(%rsp)
movss 0x1c0(%rdi), %xmm1
leaq 0x44(%rsp), %rax
movss %xmm1, 0x2c(%rsp)
movss %xmm1, (%rax)
movss 0x1c4(%rdi), %xmm1
movss %xmm1, 0x28(%rsp)
movss %xmm1, 0x4(%rax)
movss 0x1c8(%rdi), %xmm1
movss %xmm1, 0x24(%rsp)
movss %xmm1, 0x8(%rax)
movq $0x0, 0x2b8(%rdi)
leaq 0x4(%rdi), %rax
movq %rax, 0x80(%rsp)
leaq 0xcc(%rdi), %rax
movq %rax, 0x78(%rsp)
leaq 0xd8(%rdi), %rax
movq %rax, 0x70(%rsp)
xorl %r12d, %r12d
xorl %eax, %eax
xorl %r13d, %r13d
movl %esi, 0xc(%rsp)
movl %eax, 0x34(%rsp)
xorl %eax, %eax
movaps %xmm0, %xmm1
movss 0x1c0(%rbx,%rax,4), %xmm0
mulss %xmm1, %xmm0
addss 0x4(%rbx,%rax,4), %xmm0
movss %xmm0, 0xd4(%rsp,%rax,4)
incq %rax
cmpq $0x3, %rax
jne 0x37c88
movss %xmm1, 0x10(%rsp)
movl %r15d, (%rsp)
leaq 0x120(%rsp), %r14
movq %r14, %rdi
movq 0x80(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rcx
leaq 0xd4(%rsp), %r8
movq %rbx, %r9
movq 0x3191a(%rip), %rax     # 0x69600
callq *0x60(%rax)
movl $0x9, %ecx
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x3, %ebp
cmpl $0x0, 0x88(%rsp)
jne 0x38036
movss 0x90(%rsp), %xmm0
ucomiss 0x1cc41(%rip), %xmm0    # 0x54960
movl %r13d, %r14d
jbe 0x37d7b
movss 0x94(%rsp), %xmm1
movss %xmm1, 0x4(%rbx)
movss 0x98(%rsp), %xmm1
movss %xmm1, 0x8(%rbx)
movss 0x9c(%rsp), %xmm1
movss %xmm1, 0xc(%rbx)
movss 0x1c0(%rbx), %xmm1
movss %xmm1, 0x44(%rsp)
movss 0x1c4(%rbx), %xmm1
movss %xmm1, 0x48(%rsp)
movss 0x1c8(%rbx), %xmm1
movss %xmm1, 0x4c(%rsp)
xorl %r14d, %r14d
ucomiss 0x1c1a6(%rip), %xmm0    # 0x53f28
jne 0x37d8a
jnp 0x38066
movss 0xa8(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
ucomisd 0x20a3e(%rip), %xmm1    # 0x587e0
jbe 0x37dc9
movq 0xc8(%rsp), %rax
orl $0x1, %r12d
cmpl $0x3, 0x108(%rax)
jne 0x37dc9
movq %rax, 0x2b8(%rbx)
movl 0x64(%rax), %eax
movl %eax, 0x2c0(%rbx)
movl %r12d, %eax
orl $0x2, %r12d
ucomiss 0x1cb89(%rip), %xmm0    # 0x54960
cmovnel %eax, %r12d
cmovpl %eax, %r12d
movq %rbx, %rdi
leaq 0x88(%rsp), %rsi
callq 0x18a80
cmpl $0x0, 0x60(%rbx)
je 0x38066
cmpl $0x4, %r14d
jg 0x38036
movss 0x90(%rsp), %xmm0
mulss 0x10(%rsp), %xmm0
movss %xmm0, 0x30(%rsp)
movss 0xa0(%rsp), %xmm0
movslq %r14d, %rax
leaq (%rax,%rax,2), %rax
movss %xmm0, 0xe0(%rsp,%rax,4)
movq 0xa4(%rsp), %rcx
movq %rcx, 0xe4(%rsp,%rax,4)
leal 0x1(%r14), %r13d
testl %r14d, %r14d
js 0x37f2c
movq %r12, 0x50(%rsp)
movl %r13d, %r12d
xorl %r14d, %r14d
movl %r13d, 0x14(%rsp)
leaq (%r14,%r14,2), %rax
leaq (%rsp,%rax,4), %rbp
addq $0xe0, %rbp
leaq 0x44(%rsp), %rdi
movq %rbp, %rsi
leaq 0x18(%rsp), %rdx
movss 0x1c0a6(%rip), %xmm0    # 0x53f28
callq 0x18b50
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x40(%rsp)
movss 0x1c(%rsp), %xmm0
movss %xmm0, 0x3c(%rsp)
movss 0x20(%rsp), %xmm0
movss %xmm0, 0x38(%rsp)
leaq 0xe0(%rsp), %r13
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x37efe
movq %rbp, %rdi
movq %r13, %rsi
callq 0x18b70
testl %eax, %eax
jne 0x37efe
movss 0x4(%r13), %xmm0
mulss 0x3c(%rsp), %xmm0
movss (%r13), %xmm1
mulss 0x40(%rsp), %xmm1
addss %xmm0, %xmm1
movss 0x8(%r13), %xmm0
mulss 0x38(%rsp), %xmm0
addss %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
ja 0x37f25
incq %r15
addq $0xc, %r13
cmpq %r15, %r12
jne 0x37eb6
movl 0x14(%rsp), %r13d
movl %r13d, %r15d
cmpl %r13d, %r15d
je 0x37f34
incq %r14
cmpq %r12, %r14
jne 0x37e5e
jmp 0x37f31
movl 0x14(%rsp), %r13d
jmp 0x37f12
xorl %r14d, %r14d
jmp 0x37f3e
movl %r13d, %r14d
movl 0xc(%rsp), %r15d
movq 0x50(%rsp), %r12
cmpl %r13d, %r14d
jne 0x37fab
cmpl $0x2, %r13d
jne 0x38031
leaq 0xe0(%rsp), %rdi
leaq 0xec(%rsp), %rsi
leaq 0x5c(%rsp), %r14
movq %r14, %rdx
callq 0x18ba0
movss 0x60(%rsp), %xmm0
mulss 0x1c4(%rbx), %xmm0
movss 0x5c(%rsp), %xmm1
mulss 0x1c0(%rbx), %xmm1
addss %xmm0, %xmm1
movss 0x64(%rsp), %xmm0
mulss 0x1c8(%rbx), %xmm0
addss %xmm1, %xmm0
movq %r14, %rdi
movq 0x68(%rsp), %rsi
callq 0x189d0
jmp 0x37fd5
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x1c0(%rbx)
movss 0x1c(%rsp), %xmm0
movss %xmm0, 0x1c4(%rbx)
movss 0x20(%rsp), %xmm0
movss %xmm0, 0x1c8(%rbx)
movss 0x1c4(%rbx), %xmm0
mulss 0x28(%rsp), %xmm0
movss 0x1c0(%rbx), %xmm1
mulss 0x2c(%rsp), %xmm1
addss %xmm0, %xmm1
movss 0x1c8(%rbx), %xmm0
mulss 0x24(%rsp), %xmm0
addss %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
movl 0x34(%rsp), %eax
jae 0x3802c
movss 0x10(%rsp), %xmm0
subss 0x30(%rsp), %xmm0
incl %eax
cmpl $0x4, %eax
jne 0x37c7f
jmp 0x38066
movl %r12d, %ebp
jmp 0x38036
movl $0x7, %ebp
movq 0x3172b(%rip), %rax     # 0x69768
movss (%rax), %xmm0
movss %xmm0, 0x1c0(%rbx)
movss 0x4(%rax), %xmm0
movss %xmm0, 0x1c4(%rbx)
movss 0x8(%rax), %xmm0
movss %xmm0, 0x1c8(%rbx)
movl %ebp, %r12d
movl %r12d, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq