// File: /workspace/github_c_makefile_star2_O2/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 $0x178, %rsp            # imm = 0x178
movl %esi, 0x24(%rsp)
movq %rdi, %rbx
movsd 0x1c0(%rdi), %xmm1
leaq 0x28(%rsp), %rax
movsd %xmm1, (%rax)
movss 0x1c8(%rdi), %xmm2
movss %xmm2, 0x20(%rsp)
movss %xmm2, 0x8(%rax)
andq $0x0, 0x2b8(%rdi)
leaq 0x1c0(%rdi), %rax
movq %rax, 0x50(%rsp)
leaq 0x4(%rdi), %rax
movq %rax, 0x70(%rsp)
leaq 0xcc(%rdi), %rax
movq %rax, 0x68(%rsp)
leaq 0xd8(%rdi), %rax
movq %rax, 0x60(%rsp)
movaps %xmm1, 0xe0(%rsp)
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movaps %xmm1, 0xd0(%rsp)
xorl %r13d, %r13d
leaq 0x78(%rsp), %r15
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpl $0x4, %r12d
je 0x349ca
xorl %eax, %eax
cmpq $0x3, %rax
je 0x34653
movss 0x1c0(%rbx,%rax,4), %xmm1
mulss %xmm0, %xmm1
addss 0x4(%rbx,%rax,4), %xmm1
movss %xmm1, 0xc4(%rsp,%rax,4)
incq %rax
jmp 0x3462c
movss %xmm0, 0x8(%rsp)
movl 0x24(%rsp), %eax
movl %eax, (%rsp)
leaq 0x130(%rsp), %r14
movq %r14, %rdi
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rcx
leaq 0xc4(%rsp), %r8
movq %rbx, %r9
movq 0x31f74(%rip), %rax     # 0x66600
callq *0x60(%rax)
pushq $0x9
popq %rcx
movq %r15, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
cmpl $0x0, 0x78(%rsp)
jne 0x349a7
movss 0x80(%rsp), %xmm0
ucomiss 0x1b2da(%rip), %xmm0    # 0x4f990
jbe 0x346f3
movsd 0x84(%rsp), %xmm1
movsd %xmm1, 0x4(%rbx)
movss 0x8c(%rsp), %xmm1
movss %xmm1, 0xc(%rbx)
movsd 0x1c0(%rbx), %xmm1
movsd %xmm1, 0x28(%rsp)
movss 0x1c8(%rbx), %xmm1
movss %xmm1, 0x30(%rsp)
xorl %r13d, %r13d
ucomiss 0x1a82e(%rip), %xmm0    # 0x4ef28
jne 0x34702
jnp 0x349ca
movss 0x98(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
ucomisd 0x1f2b9(%rip), %xmm1    # 0x539d0
jbe 0x3473d
movq 0xb8(%rsp), %rax
orl $0x1, %ebp
cmpl $0x3, 0x108(%rax)
jne 0x3473d
movq %rax, 0x2b8(%rbx)
movl 0x64(%rax), %eax
movl %eax, 0x2c0(%rbx)
movl %ebp, %eax
orl $0x2, %ebp
ucomiss 0x1b247(%rip), %xmm0    # 0x4f990
cmovnel %eax, %ebp
cmovpl %eax, %ebp
movq %rbx, %rdi
movq %r15, %rsi
callq 0x18b20
cmpl $0x0, 0x60(%rbx)
je 0x349ca
cmpl $0x4, %r13d
jg 0x349a7
movl %ebp, 0xc(%rsp)
movss 0x80(%rsp), %xmm1
movss 0x8(%rsp), %xmm0
mulss %xmm0, %xmm1
subss %xmm1, %xmm0
movslq %r13d, %rcx
imulq $0xc, %rcx, %rax
movsd 0x90(%rsp), %xmm1
movsd %xmm1, 0xf0(%rsp,%rax)
movss 0x98(%rsp), %xmm1
movss %xmm1, 0xf8(%rsp,%rax)
incl %r13d
xorl %r15d, %r15d
movss %xmm0, 0x8(%rsp)
movl %r12d, 0x10(%rsp)
movq %rcx, 0x58(%rsp)
cmpq %rcx, %r15
jg 0x348ab
imulq $0xc, %r15, %rax
leaq (%rsp,%rax), %rbp
addq $0xf0, %rbp
leaq 0x28(%rsp), %rdi
movq %rbp, %rsi
leaq 0x38(%rsp), %rdx
movss 0x1a731(%rip), %xmm0    # 0x4ef28
callq 0x18bf0
movss 0x8(%rsp), %xmm0
movss 0x38(%rsp), %xmm1
movss %xmm1, 0x18(%rsp)
movss 0x3c(%rsp), %xmm1
movss %xmm1, 0x1c(%rsp)
movss 0x40(%rsp), %xmm1
movss %xmm1, 0x14(%rsp)
leaq 0xf0(%rsp), %r12
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x348a6
cmpq %r14, %r15
je 0x34886
movq %rbp, %rdi
movq %r12, %rsi
callq 0x18c20
movss 0x8(%rsp), %xmm0
testl %eax, %eax
jne 0x34886
movss 0x4(%r12), %xmm2
mulss 0x1c(%rsp), %xmm2
movss (%r12), %xmm1
mulss 0x18(%rsp), %xmm1
addss %xmm2, %xmm1
movss 0x8(%r12), %xmm2
mulss 0x14(%rsp), %xmm2
addss %xmm1, %xmm2
xorps %xmm1, %xmm1
ucomiss %xmm2, %xmm1
ja 0x3488f
incq %r14
addq $0xc, %r12
jmp 0x34831
cmpl %r14d, %r13d
movl 0x10(%rsp), %r12d
je 0x348ab
incq %r15
movq 0x58(%rsp), %rcx
jmp 0x347ca
movl 0x10(%rsp), %r12d
cmpl %r15d, %r13d
jne 0x34943
cmpl $0x2, %r13d
movl 0xc(%rsp), %ebp
leaq 0x78(%rsp), %r15
jne 0x349de
leaq 0xf0(%rsp), %rdi
leaq 0xfc(%rsp), %rsi
leaq 0x44(%rsp), %r14
movq %r14, %rdx
callq 0x18c60
movss 0x48(%rsp), %xmm0
mulss 0x1c4(%rbx), %xmm0
movss 0x44(%rsp), %xmm1
mulss 0x1c0(%rbx), %xmm1
addss %xmm0, %xmm1
movss 0x4c(%rsp), %xmm0
mulss 0x1c8(%rbx), %xmm0
addss %xmm1, %xmm0
movq %r14, %rdi
movq 0x50(%rsp), %rsi
callq 0x18a70
movss 0x8(%rsp), %xmm0
movss 0x1c0(%rbx), %xmm1
movss 0x1c4(%rbx), %xmm2
movss 0x1c8(%rbx), %xmm3
jmp 0x34976
movss 0x18(%rsp), %xmm1
movss %xmm1, 0x1c0(%rbx)
movss 0x1c(%rsp), %xmm2
movss %xmm2, 0x1c4(%rbx)
movss 0x14(%rsp), %xmm3
movss %xmm3, 0x1c8(%rbx)
movl 0xc(%rsp), %ebp
leaq 0x78(%rsp), %r15
mulss 0xd0(%rsp), %xmm2
mulss 0xe0(%rsp), %xmm1
addss %xmm2, %xmm1
mulss 0x20(%rsp), %xmm3
addss %xmm1, %xmm3
incl %r12d
xorps %xmm1, %xmm1
ucomiss %xmm3, %xmm1
jb 0x34620
jmp 0x349aa
pushq $0x3
popq %rbp
movq 0x31db7(%rip), %rax     # 0x66768
movsd (%rax), %xmm0
movsd %xmm0, 0x1c0(%rbx)
movss 0x8(%rax), %xmm0
movss %xmm0, 0x1c8(%rbx)
movl %ebp, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x7
jmp 0x349a9