// File: /workspace/github_c_makefile_star2_O1/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 $0x50, %rsp
movss %xmm0, 0x4(%rsp)
testq %rsi, %rsi
je 0x4297a
movq %rsi, %r14
movq %rdi, %rbx
movss 0x1fc(%rdi), %xmm0
movss 0x17e3b(%rip), %xmm1    # 0x5a508
divss %xmm1, %xmm0
mulss %xmm1, %xmm0
callq 0x18a50
movaps %xmm0, %xmm1
movss 0x17e17(%rip), %xmm0    # 0x5a4fc
movss %xmm1, 0xc(%rsp)
addss %xmm1, %xmm0
callq 0x18a50
movss %xmm0, 0x8(%rsp)
movss 0x4(%r14), %xmm4
movss 0x8(%r14), %xmm2
subss 0x4(%rbx), %xmm4
movss 0x124f9(%rip), %xmm0    # 0x54c0c
xorl %eax, %eax
ucomiss %xmm4, %xmm0
seta %al
subss 0x8(%rbx), %xmm2
movss 0x117ec(%rip), %xmm3    # 0x53f14
xorl %ecx, %ecx
ucomiss %xmm3, %xmm2
seta %cl
leaq 0x17df1(%rip), %rdx     # 0x5a528
movss (%rdx,%rax,4), %xmm1
cmpltss %xmm4, %xmm3
andnps %xmm1, %xmm3
leaq 0x17de5(%rip), %rax     # 0x5a530
movss (%rax,%rcx,4), %xmm1
movaps %xmm2, 0x30(%rsp)
cmpltss %xmm0, %xmm2
movss 0x17dae(%rip), %xmm5    # 0x5a510
andps %xmm2, %xmm5
andnps %xmm1, %xmm2
orps %xmm2, %xmm5
movaps %xmm3, 0x10(%rsp)
ucomiss 0x14489(%rip), %xmm3    # 0x56c00
movaps %xmm4, 0x40(%rsp)
movaps %xmm5, 0x20(%rsp)
jne 0x42785
jnp 0x427ed
ucomiss 0x14474(%rip), %xmm5    # 0x56c00
jne 0x42790
jnp 0x427ed
movss 0x17a7c(%rip), %xmm0    # 0x5a214
ucomiss 0x11775(%rip), %xmm4    # 0x53f14
jbe 0x427b6
cmpeqss %xmm5, %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leaq 0x17d8c(%rip), %rcx     # 0x5a540
jmp 0x427c9
cmpeqss %xmm5, %xmm0
movd %xmm0, %eax
andl $0x1, %eax
leaq 0x17d6f(%rip), %rcx     # 0x5a538
movss (%rcx,%rax,4), %xmm0
ucomiss 0x8(%rsp), %xmm0
jne 0x427d7
jnp 0x427ed
movq %rbx, %rdi
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x4297a
callq 0x19a20
testb $0x1, %al
jne 0x42812
movaps 0x11743(%rip), %xmm0    # 0x53f40
movaps 0x30(%rsp), %xmm2
andps %xmm0, %xmm2
movaps 0x40(%rsp), %xmm1
andps %xmm0, %xmm1
ucomiss %xmm1, %xmm2
jbe 0x42819
movaps 0x20(%rsp), %xmm0
jmp 0x42828
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
ucomiss 0x143d1(%rip), %xmm0    # 0x56c00
jne 0x42833
jnp 0x42852
ucomiss 0x8(%rsp), %xmm0
jne 0x4283c
jnp 0x42852
movq %rbx, %rdi
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x4297a
movaps 0x10(%rsp), %xmm0
ucomiss 0x143a2(%rip), %xmm0    # 0x56c00
jne 0x42862
jnp 0x4288b
movaps 0x10(%rsp), %xmm0
ucomiss 0x8(%rsp), %xmm0
jne 0x42870
jnp 0x4288b
movq %rbx, %rdi
movaps 0x10(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x4297a
movss 0xc(%rsp), %xmm0
ucomiss 0x14368(%rip), %xmm0    # 0x56c00
jne 0x4289c
jnp 0x428b8
movq %rbx, %rdi
movss 0xc(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x4297a
callq 0x19a20
testb $0x1, %al
jne 0x428fa
movl $0x168, %ebp            # imm = 0x168
addl $-0x2d, %ebp
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
movss 0x8(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jne 0x428dd
jnp 0x428f3
movq %rbx, %rdi
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x4297a
cmpl $0x2c, %ebp
jg 0x428c6
jmp 0x42930
movl $0xffffffd3, %ebp       # imm = 0xFFFFFFD3
addl $0x2d, %ebp
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
movss 0x8(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jne 0x42916
jnp 0x42928
movq %rbx, %rdi
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x4297a
cmpl $0x10e, %ebp            # imm = 0x10E
jbe 0x428ff
movss 0x8(%rsp), %xmm0
ucomiss 0x142c3(%rip), %xmm0    # 0x56c00
jne 0x42941
jnp 0x42959
movq %rbx, %rdi
movss 0x8(%rsp), %xmm0
movss 0x4(%rsp), %xmm1
callq 0x18200
testl %eax, %eax
jne 0x4297a
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x1fc(%rbx)
movq %rbx, %rdi
callq 0x19130
testl %eax, %eax
jne 0x4297a
orb $0x1, 0x11d(%rbx)
addq $0x50, %rsp
popq %rbx
popq %r14
popq %rbp
retq