// File: /workspace/github_c_makefile_star2_O3/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 %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
movss %xmm0, 0x4(%rsp)
testq %rsi, %rsi
je 0x41f91
movq %rsi, %r14
movq %rdi, %rbx
movss 0x1fc(%rdi), %xmm0
movss 0x17a67(%rip), %xmm1    # 0x5974c
divss %xmm1, %xmm0
mulss %xmm1, %xmm0
callq 0x18a50
movaps %xmm0, %xmm1
movss 0x17a43(%rip), %xmm0    # 0x59740
movss %xmm1, 0xc(%rsp)
addss %xmm1, %xmm0
callq 0x18a50
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 0x111eb(%rip), %xmm3    # 0x52f14
xorl %eax, %eax
ucomiss %xmm3, %xmm1
seta %al
movss 0x11f03(%rip), %xmm2    # 0x53c3c
xorl %ecx, %ecx
ucomiss %xmm4, %xmm2
seta %cl
movss %xmm0, 0x8(%rsp)
leaq 0x17a1a(%rip), %rdx     # 0x59768
movss (%rdx,%rcx,4), %xmm0
cmpltss %xmm4, %xmm3
andnps %xmm0, %xmm3
leaq 0x17a0e(%rip), %rcx     # 0x59770
movss (%rcx,%rax,4), %xmm0
cmpltss %xmm2, %xmm1
movss 0x179e0(%rip), %xmm2    # 0x59754
andps %xmm1, %xmm2
andnps %xmm0, %xmm1
orps %xmm1, %xmm2
movaps %xmm3, 0x20(%rsp)
ucomiss 0x13ecb(%rip), %xmm3    # 0x55c54
movaps %xmm2, 0x10(%rsp)
movaps %xmm4, 0x30(%rsp)
jne 0x41d97
jnp 0x41dff
ucomiss 0x13eb6(%rip), %xmm2    # 0x55c54
jne 0x41da2
jnp 0x41dff
movss 0x1767a(%rip), %xmm0    # 0x59424
ucomiss 0x11163(%rip), %xmm4    # 0x52f14
jbe 0x41dc8
cmpeqss %xmm2, %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leaq 0x179ba(%rip), %rcx     # 0x59780
jmp 0x41ddb
cmpeqss %xmm2, %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leaq 0x1799d(%rip), %rcx     # 0x59778
movss (%rcx,%rax,4), %xmm0
ucomiss 0x8(%rsp), %xmm0
jne 0x41de9
jnp 0x41dff
movq %rbx, %rdi
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x41f91
callq 0x19a10
movdqa 0x30(%rsp), %xmm1
pand 0x1112e(%rip), %xmm1    # 0x52f40
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
ucomiss %xmm1, %xmm0
seta %cl
orb %al, %cl
testb $0x1, %cl
jne 0x41e30
movaps 0x20(%rsp), %xmm0
movaps 0x10(%rsp), %xmm2
jmp 0x41e3a
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm2
ucomiss 0x13e13(%rip), %xmm0    # 0x55c54
jne 0x41e45
jnp 0x41e6e
ucomiss 0x8(%rsp), %xmm0
jne 0x41e4e
jnp 0x41e6e
movq %rbx, %rdi
movss 0x4(%rsp), %xmm1
movaps %xmm2, 0x10(%rsp)
callq 0x18200
movaps 0x10(%rsp), %xmm2
testl %eax, %eax
jne 0x41f91
ucomiss 0x13ddf(%rip), %xmm2    # 0x55c54
jne 0x41e79
jnp 0x41e9b
ucomiss 0x8(%rsp), %xmm2
jne 0x41e82
jnp 0x41e9b
movq %rbx, %rdi
movaps %xmm2, %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x41f91
movss 0xc(%rsp), %xmm0
ucomiss 0x13dac(%rip), %xmm0    # 0x55c54
jne 0x41eac
jnp 0x41ec8
movq %rbx, %rdi
movss 0xc(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x41f91
callq 0x19a10
testb $0x1, %al
jne 0x41f11
movl $0x13b, %r14d           # imm = 0x13B
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
movss 0x8(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jne 0x41eec
jnp 0x41f02
movq %rbx, %rdi
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x41f91
leal -0x2d(%r14), %eax
cmpl $0x2c, %r14d
movl %eax, %r14d
jg 0x41ed7
jmp 0x41f47
movl $0xffffffd3, %ebp       # imm = 0xFFFFFFD3
addl $0x2d, %ebp
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
movss 0x8(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jne 0x41f2d
jnp 0x41f3f
movq %rbx, %rdi
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x41f91
cmpl $0x10e, %ebp            # imm = 0x10E
jbe 0x41f16
movss 0x8(%rsp), %xmm0
ucomiss 0x13d00(%rip), %xmm0    # 0x55c54
jne 0x41f58
jnp 0x41f70
movq %rbx, %rdi
movss 0x8(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x41f91
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x1fc(%rbx)
movq %rbx, %rdi
callq 0x19130
testl %eax, %eax
jne 0x41f91
orb $0x1, 0x11d(%rbx)
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq