// File: /workspace/github_c_makefile_star2_O3/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 $0x188, %rsp            # imm = 0x188
movl %esi, 0x38(%rsp)
movq %rdi, %rbx
leaq 0x1c0(%rdi), %rax
movq %rax, 0x68(%rsp)
movsd 0x1c0(%rdi), %xmm1
leaq 0x40(%rsp), %rax
movsd %xmm1, (%rax)
movss 0x1c8(%rdi), %xmm2
movss %xmm2, 0x34(%rsp)
movss %xmm2, 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)
movaps %xmm1, 0xf0(%rsp)
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movaps %xmm1, 0xe0(%rsp)
xorl %r12d, %r12d
leaq 0x88(%rsp), %r13
xorl %eax, %eax
xorl %r15d, %r15d
movl %eax, 0x18(%rsp)
xorl %eax, %eax
movss 0x1c0(%rbx,%rax,4), %xmm1
mulss %xmm0, %xmm1
addss 0x4(%rbx,%rax,4), %xmm1
movss %xmm1, 0xd4(%rsp,%rax,4)
incq %rax
cmpq $0x3, %rax
jne 0x37471
movss %xmm0, 0x10(%rsp)
movl 0x38(%rsp), %eax
movl %eax, (%rsp)
leaq 0x140(%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 0x3112e(%rip), %rax     # 0x68600
callq *0x60(%rax)
movl $0x9, %ecx
movq %r13, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x3, %ebp
cmpl $0x0, 0x88(%rsp)
jne 0x37822
movss 0x90(%rsp), %xmm0
ucomiss 0x1c48a(%rip), %xmm0    # 0x53990
movl %r15d, %r14d
jbe 0x37546
movsd 0x94(%rsp), %xmm1
movsd %xmm1, 0x4(%rbx)
movss 0x9c(%rsp), %xmm1
movss %xmm1, 0xc(%rbx)
movsd 0x1c0(%rbx), %xmm1
movsd %xmm1, 0x40(%rsp)
movss 0x1c8(%rbx), %xmm1
movss %xmm1, 0x48(%rsp)
xorl %r14d, %r14d
ucomiss 0x1b9db(%rip), %xmm0    # 0x52f28
jne 0x37555
jnp 0x37845
movss 0xa8(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
ucomisd 0x20483(%rip), %xmm1    # 0x579f0
jbe 0x37594
movq 0xc8(%rsp), %rax
orl $0x1, %r12d
cmpl $0x3, 0x108(%rax)
jne 0x37594
movq %rax, 0x2b8(%rbx)
movl 0x64(%rax), %eax
movl %eax, 0x2c0(%rbx)
movl %r12d, %eax
orl $0x2, %r12d
ucomiss 0x1c3ee(%rip), %xmm0    # 0x53990
cmovnel %eax, %r12d
cmovpl %eax, %r12d
movq %rbx, %rdi
movq %r13, %rsi
callq 0x18a80
cmpl $0x0, 0x60(%rbx)
je 0x37845
cmpl $0x4, %r14d
jg 0x37822
movss 0x90(%rsp), %xmm1
movss 0x10(%rsp), %xmm0
mulss %xmm0, %xmm1
movss %xmm1, 0x3c(%rsp)
movslq %r14d, %rax
leaq (%rax,%rax,2), %rax
movsd 0xa0(%rsp), %xmm1
movsd %xmm1, 0x100(%rsp,%rax,4)
movss 0xa8(%rsp), %xmm1
movss %xmm1, 0x108(%rsp,%rax,4)
leal 0x1(%r14), %r15d
testl %r14d, %r14d
movl %r15d, 0x14(%rsp)
js 0x37718
movl %r15d, %r15d
xorl %r14d, %r14d
movq %r12, 0x28(%rsp)
leaq (%r14,%r14,2), %rax
leaq (%rsp,%rax,4), %rbp
addq $0x100, %rbp            # imm = 0x100
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
leaq 0x50(%rsp), %rdx
movss 0x1b8da(%rip), %xmm0    # 0x52f28
callq 0x18b50
movss 0x10(%rsp), %xmm0
movss 0x50(%rsp), %xmm1
movss %xmm1, 0x24(%rsp)
movss 0x54(%rsp), %xmm1
movss %xmm1, 0x20(%rsp)
movss 0x58(%rsp), %xmm1
movss %xmm1, 0x1c(%rsp)
leaq 0x100(%rsp), %r13
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x376d6
movq %rbp, %rdi
movq %r13, %rsi
callq 0x18b70
movss 0x10(%rsp), %xmm0
testl %eax, %eax
jne 0x376d6
movss 0x4(%r13), %xmm2
mulss 0x20(%rsp), %xmm2
movss (%r13), %xmm1
mulss 0x24(%rsp), %xmm1
addss %xmm2, %xmm1
movss 0x8(%r13), %xmm2
mulss 0x1c(%rsp), %xmm2
addss %xmm1, %xmm2
xorps %xmm1, %xmm1
ucomiss %xmm2, %xmm1
ja 0x376e4
incq %r12
addq $0xc, %r13
cmpq %r12, %r15
jne 0x37688
jmp 0x37704
cmpl %r12d, %r15d
je 0x37704
incq %r14
cmpq %r15, %r14
movq 0x28(%rsp), %r12
leaq 0x88(%rsp), %r13
jne 0x3762a
jmp 0x37724
movq 0x28(%rsp), %r12
leaq 0x88(%rsp), %r13
movl 0x14(%rsp), %r15d
jmp 0x3771b
xorl %r14d, %r14d
cmpl %r15d, %r14d
jne 0x377af
movl 0x14(%rsp), %r15d
cmpl $0x2, %r15d
jne 0x3781d
leaq 0x100(%rsp), %rdi
leaq 0x10c(%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
movss 0x10(%rsp), %xmm0
movss 0x1c0(%rbx), %xmm1
movss 0x1c4(%rbx), %xmm2
movss 0x1c8(%rbx), %xmm3
jmp 0x377d9
movss 0x24(%rsp), %xmm1
movss %xmm1, 0x1c0(%rbx)
movss 0x20(%rsp), %xmm2
movss %xmm2, 0x1c4(%rbx)
movss 0x1c(%rsp), %xmm3
movss %xmm3, 0x1c8(%rbx)
movl 0x18(%rsp), %eax
mulss 0xe0(%rsp), %xmm2
mulss 0xf0(%rsp), %xmm1
addss %xmm2, %xmm1
mulss 0x34(%rsp), %xmm3
addss %xmm1, %xmm3
xorps %xmm1, %xmm1
ucomiss %xmm3, %xmm1
jae 0x37818
subss 0x3c(%rsp), %xmm0
incl %eax
cmpl $0x4, %eax
jne 0x3746b
jmp 0x37845
movl %r12d, %ebp
jmp 0x37822
movl $0x7, %ebp
movq 0x30f3f(%rip), %rax     # 0x68768
movsd (%rax), %xmm0
movsd %xmm0, 0x1c0(%rbx)
movss 0x8(%rax), %xmm0
movss %xmm0, 0x1c8(%rbx)
movl %ebp, %r12d
movl %r12d, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq