// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/m_move.c
// Function: SV_NewChaseDir
void SV_NewChaseDir (edict_t *actor, edict_t *enemy, float dist)
{
	float	deltax,deltay;
	float	d[3];
	float	tdir, olddir, turnaround;
	
	//FIXME: how did we get here with no enemy
	if (!enemy)
		return;
	
	olddir = anglemod( (actor->ideal_yaw/45)*45.0f );
	turnaround = anglemod(olddir - 180);
	
	deltax = enemy->s.origin[0] - actor->s.origin[0];
	deltay = enemy->s.origin[1] - actor->s.origin[1];
	if (deltax>10)
		d[1]= 0;
	else if (deltax<-10)
		d[1]= 180;
	else
		d[1]= DI_NODIR;
	if (deltay<-10)
		d[2]= 270;
	else if (deltay>10)
		d[2]= 90;
	else
		d[2]= DI_NODIR;
	
	// try direct route
	if (d[1] != DI_NODIR && d[2] != DI_NODIR)
	{
		if (d[1] == 0)
			tdir = d[2] == 90 ? 45 : 315;
		else
			tdir = d[2] == 90 ? 135 : 215;
		
		if (tdir != turnaround && SV_StepDirection(actor, tdir, dist))
			return;
	}
	
	// try other directions
	if ( ((rand()&3) & 1) ||  fabsf(deltay) > fabsf(deltax))
	{
		tdir=d[1];
		d[1]=d[2];
		d[2]=tdir;
	}
	
	if (d[1]!=DI_NODIR && d[1]!=turnaround 
		&& SV_StepDirection(actor, d[1], dist))
		return;
	
	if (d[2]!=DI_NODIR && d[2]!=turnaround
		&& SV_StepDirection(actor, d[2], dist))
		return;
	
	/* there is no direct path to the player, so pick another direction */
	
	if (olddir!=DI_NODIR && SV_StepDirection(actor, olddir, dist))
		return;
	
	if (rand()&1) 	/*randomly determine direction of search*/
	{
		for (tdir=0 ; tdir<=315 ; tdir += 45)
			if (tdir!=turnaround && SV_StepDirection(actor, tdir, dist) )
				return;
	}
	else
	{
		for (tdir=315 ; tdir >=0 ; tdir -= 45)
			if (tdir!=turnaround && SV_StepDirection(actor, tdir, dist) )
				return;
	}
	
	if (turnaround != DI_NODIR && SV_StepDirection(actor, turnaround, dist) )
		return;
	
	actor->ideal_yaw = olddir;		// can't move
	
	// if a bridge was pulled out from underneath a monster, it may not have
	// a valid standing position at all
	
	if (!M_CheckBottom (actor))
		SV_FixCheckBottom (actor);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x48, %rsp
movss %xmm0, 0x4(%rsp)
testq %rsi, %rsi
je 0x3e916
movq %rsi, %r14
movq %rdi, %rbx
movss 0x1fc(%rdi), %xmm0
movss 0x170e3(%rip), %xmm1    # 0x5572c
divss %xmm1, %xmm0
mulss %xmm1, %xmm0
callq 0x18af0
movaps %xmm0, %xmm1
movss 0x170bf(%rip), %xmm0    # 0x55720
movss %xmm1, 0xc(%rsp)
addss %xmm1, %xmm0
callq 0x18af0
movsd 0x4(%r14), %xmm4
movsd 0x4(%rbx), %xmm1
subps %xmm1, %xmm4
movaps %xmm4, %xmm1
shufps $0x55, %xmm4, %xmm1     # xmm1 = xmm1[1,1],xmm4[1,1]
movss 0x10887(%rip), %xmm3    # 0x4ef14
xorl %eax, %eax
ucomiss %xmm3, %xmm1
seta %al
movss 0x1159f(%rip), %xmm2    # 0x4fc3c
xorl %ecx, %ecx
ucomiss %xmm4, %xmm2
seta %cl
movss %xmm0, 0x8(%rsp)
leaq 0x1709e(%rip), %rdx     # 0x55750
movss (%rdx,%rcx,4), %xmm0
cmpltss %xmm4, %xmm3
andnps %xmm0, %xmm3
leaq 0x17092(%rip), %rcx     # 0x55758
movss (%rcx,%rax,4), %xmm0
cmpltss %xmm2, %xmm1
movss 0x1705c(%rip), %xmm2    # 0x55734
andps %xmm1, %xmm2
andnps %xmm0, %xmm1
orps %xmm1, %xmm2
movaps %xmm3, 0x20(%rsp)
ucomiss 0x13547(%rip), %xmm3    # 0x51c34
movaps %xmm2, 0x10(%rsp)
movaps %xmm4, 0x30(%rsp)
jne 0x3e6fb
jnp 0x3e763
ucomiss 0x13532(%rip), %xmm2    # 0x51c34
jne 0x3e706
jnp 0x3e763
movss 0x16cf6(%rip), %xmm0    # 0x55404
ucomiss 0x107ff(%rip), %xmm4    # 0x4ef14
jbe 0x3e72c
cmpeqss %xmm2, %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leaq 0x1703e(%rip), %rcx     # 0x55768
jmp 0x3e73f
cmpeqss %xmm2, %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leaq 0x17021(%rip), %rcx     # 0x55760
movss (%rcx,%rax,4), %xmm0
ucomiss 0x8(%rsp), %xmm0
jne 0x3e74d
jnp 0x3e763
movq %rbx, %rdi
movss 0x4(%rsp), %xmm1
callq 0x18220
testl %eax, %eax
jne 0x3e916
callq 0x19bf0
movdqa 0x30(%rsp), %xmm1
pand 0x107ca(%rip), %xmm1    # 0x4ef40
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
ucomiss %xmm1, %xmm0
seta %cl
orb %al, %cl
testb $0x1, %cl
jne 0x3e794
movaps 0x20(%rsp), %xmm0
movaps 0x10(%rsp), %xmm2
jmp 0x3e79e
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm2
ucomiss 0x1348f(%rip), %xmm0    # 0x51c34
jne 0x3e7a9
jnp 0x3e7d2
ucomiss 0x8(%rsp), %xmm0
jne 0x3e7b2
jnp 0x3e7d2
movq %rbx, %rdi
movss 0x4(%rsp), %xmm1
movaps %xmm2, 0x10(%rsp)
callq 0x18220
movaps 0x10(%rsp), %xmm2
testl %eax, %eax
jne 0x3e916
ucomiss 0x1345b(%rip), %xmm2    # 0x51c34
jne 0x3e7dd
jnp 0x3e7ff
ucomiss 0x8(%rsp), %xmm2
jne 0x3e7e6
jnp 0x3e7ff
movq %rbx, %rdi
movaps %xmm2, %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18220
testl %eax, %eax
jne 0x3e916
movss 0xc(%rsp), %xmm0
ucomiss 0x13428(%rip), %xmm0    # 0x51c34
jne 0x3e810
jnp 0x3e82c
movq %rbx, %rdi
movss 0xc(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18220
testl %eax, %eax
jne 0x3e916
callq 0x19bf0
testb $0x1, %al
jne 0x3e885
movss 0x16ef3(%rip), %xmm0    # 0x55730
ucomiss 0x1114c(%rip), %xmm0    # 0x4f990
jb 0x3e8cc
ucomiss 0x8(%rsp), %xmm0
jne 0x3e853
jnp 0x3e87b
movq %rbx, %rdi
movss %xmm0, 0x10(%rsp)
movss 0x10(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18220
movss 0x10(%rsp), %xmm0
testl %eax, %eax
jne 0x3e916
addss 0x16eb5(%rip), %xmm0    # 0x55738
jmp 0x3e83d
xorps %xmm0, %xmm0
movss 0x16ea0(%rip), %xmm1    # 0x55730
ucomiss %xmm0, %xmm1
jb 0x3e8cc
ucomiss 0x8(%rsp), %xmm0
jne 0x3e89e
jnp 0x3e8c2
movq %rbx, %rdi
movss %xmm0, 0x10(%rsp)
movss 0x10(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18220
movss 0x10(%rsp), %xmm0
testl %eax, %eax
jne 0x3e916
addss 0x16e62(%rip), %xmm0    # 0x5572c
jmp 0x3e888
movss 0x8(%rsp), %xmm0
ucomiss 0x1335b(%rip), %xmm0    # 0x51c34
jne 0x3e8dd
jnp 0x3e8f5
movq %rbx, %rdi
movss 0x8(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18220
testl %eax, %eax
jne 0x3e916
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x1fc(%rbx)
movq %rbx, %rdi
callq 0x192a0
testl %eax, %eax
jne 0x3e916
orb $0x1, 0x11d(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r14
retq