// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlrad/qradutil.cpp
// Function: IsPositionValid(positionmap_t*, float const (&) [3], float (&) [3], bool, bool, int, float)
static bool IsPositionValid (positionmap_t *map, const vec3_t &pos_st, vec3_t &pos_out, bool usephongnormal = true, bool doedgetest = true, int hunt_size = 2, vec_t hunt_scale = 0.2)
{
	vec3_t pos;
	vec3_t pos_normal;
	vec_t hunt_offset;

	ApplyMatrix (map->textoworld, pos_st, pos);
	VectorAdd (pos, map->face_offset, pos);
	if (usephongnormal)
	{
		GetPhongNormal (map->facenum, pos, pos_normal);
	}
	else
	{
		VectorCopy (map->faceplanewithoffset.normal, pos_normal);
	}
	VectorMA (pos, DEFAULT_HUNT_OFFSET, pos_normal, pos);

	hunt_offset = DotProduct (pos, map->faceplanewithoffset.normal) - map->faceplanewithoffset.dist; // might be smaller than DEFAULT_HUNT_OFFSET

	// push the point 0.2 units around to avoid walls
	if (!HuntForWorld (pos, vec3_origin, &map->faceplanewithoffset, hunt_size, hunt_scale, hunt_offset))
	{
		return false;
	}

	if (doedgetest && !point_in_winding_noedge (*map->facewindingwithoffset, map->faceplanewithoffset, pos, DEFAULT_EDGE_WIDTH))
	{
		// if the sample has gone beyond face boundaries, be careful that it hasn't passed a wall
		vec3_t test;
#ifdef HLRAD_HULLU
		vec3_t transparency;
#endif
#ifdef HLRAD_OPAQUE_STYLE
		int opaquestyle;
#endif

		VectorCopy (pos, test);
		snap_to_winding_noedge (*map->facewindingwithoffset, map->faceplanewithoffset, test, DEFAULT_EDGE_WIDTH, 4 * DEFAULT_EDGE_WIDTH);

		if (!HuntForWorld (test, vec3_origin, &map->faceplanewithoffset, hunt_size, hunt_scale, hunt_offset))
		{
			return false;
		}

		if (TestLine (pos, test) != CONTENTS_EMPTY)
		{
			return false;
		}

		if (TestSegmentAgainstOpaqueList (pos, test
#ifdef HLRAD_HULLU
				, transparency
#endif
#ifdef HLRAD_OPAQUE_STYLE
				, opaquestyle
#endif
				) == true
#ifdef HLRAD_OPAQUE_STYLE
			|| opaquestyle != -1
#endif
			)
		{
			return false;
		}
	}

	VectorCopy (pos, pos_out);
	return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %rbx
movq %rdi, %r14
addq $0x50, %rdi
leaq 0x8(%rsp), %r12
movq %r12, %rdx
callq 0x2f8b3
movsd (%r12), %xmm0
movsd 0x8(%r14), %xmm1
addps %xmm0, %xmm1
movlps %xmm1, (%r12)
movss 0x8(%r12), %xmm0
addss 0x10(%r14), %xmm0
movss %xmm0, 0x8(%r12)
movl 0x4(%r14), %edi
leaq 0x30(%rsp), %r15
movq %r12, %rsi
movq %r15, %rdx
callq 0x19ea1
cvtps2pd (%r12), %xmm0
cvtps2pd (%r15), %xmm1
mulpd 0xa200(%rip), %xmm1     # 0x3b540
addpd %xmm0, %xmm1
cvtpd2ps %xmm1, %xmm0
movlpd %xmm0, (%r12)
xorps %xmm1, %xmm1
cvtss2sd 0x8(%r12), %xmm1
cvtss2sd 0x8(%r15), %xmm2
mulsd 0x8f9a(%rip), %xmm2     # 0x3a300
addsd %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtsd2ss %xmm2, %xmm1
movss %xmm1, 0x8(%r12)
leaq 0xa8(%r14), %r15
movapd %xmm0, %xmm2
shufps $0x55, %xmm0, %xmm2     # xmm2 = xmm2[1,1],xmm0[1,1]
mulss 0xac(%r14), %xmm2
mulss 0xa8(%r14), %xmm0
mulss 0xb0(%r14), %xmm1
addss %xmm2, %xmm0
addss %xmm0, %xmm1
subss 0xb4(%r14), %xmm1
leaq 0x7a16(%rip), %rsi      # 0x38dd0
movss 0x969e(%rip), %xmm0     # 0x3aa60
movq %r12, %rdi
movq %r15, %rdx
movl $0x2, %ecx
movss %xmm1, 0x18(%rsp)
callq 0x2f451
testq %rax, %rax
je 0x3149d
movq 0xa0(%r14), %rdi
leaq 0x8(%rsp), %rdx
movss 0x928b(%rip), %xmm0     # 0x3a680
movq %r15, %rsi
callq 0x24aa2
testb %al, %al
je 0x3141d
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rbx)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x8(%rbx)
movb $0x1, %al
jmp 0x3149f
movsd 0x8(%rsp), %xmm0
leaq 0x20(%rsp), %r12
movsd %xmm0, (%r12)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x8(%r12)
movq 0xa0(%r14), %rdi
movss 0x9236(%rip), %xmm0     # 0x3a680
movss 0x9232(%rip), %xmm1     # 0x3a684
movq %r15, %rsi
movq %r12, %rdx
callq 0x24f9f
leaq 0x796c(%rip), %rsi      # 0x38dd0
movss 0x95f4(%rip), %xmm0     # 0x3aa60
movq %r12, %rdi
movq %r15, %rdx
movl $0x2, %ecx
movss 0x18(%rsp), %xmm1
callq 0x2f451
testq %rax, %rax
je 0x3149d
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x3244c
cmpl $-0x1, %eax
je 0x314ab
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x3c(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
callq 0x256c7
movl %eax, %ecx
xorl %eax, %eax
testb %cl, %cl
jne 0x3149f
cmpl $-0x1, 0x1c(%rsp)
je 0x31401
jmp 0x3149f
nopl (%rax)