// File: /workspace/github_cpp_makefile_star2_O2/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 0x2bb9d
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 0x17782
cvtps2pd (%r12), %xmm0
cvtps2pd (%r15), %xmm1
mulpd 0x9209(%rip), %xmm1     # 0x36530
addpd %xmm0, %xmm1
cvtpd2ps %xmm1, %xmm0
movlpd %xmm0, (%r12)
cvtss2sd 0x8(%r12), %xmm1
cvtss2sd 0x8(%r15), %xmm2
mulsd 0x7f16(%rip), %xmm2     # 0x35260
addsd %xmm1, %xmm2
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 0x6995(%rip), %rsi      # 0x33d30
pushq $0x2
popq %rcx
movss 0x864a(%rip), %xmm0     # 0x359f0
movq %r12, %rdi
movq %r15, %rdx
movss %xmm1, 0x18(%rsp)
callq 0x2b7fc
testq %rax, %rax
je 0x2d47a
movq 0xa0(%r14), %rdi
leaq 0x8(%rsp), %rdx
movss 0x8254(%rip), %xmm0     # 0x35628
movq %r15, %rsi
callq 0x21939
testb %al, %al
je 0x2d3fc
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rbx)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x8(%rbx)
movb $0x1, %al
jmp 0x2d47c
movsd 0x8(%rsp), %xmm0
leaq 0x20(%rsp), %r12
movsd %xmm0, (%r12)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x8(%r12)
movq 0xa0(%r14), %rdi
movss 0x81ff(%rip), %xmm0     # 0x35628
movss 0x81fb(%rip), %xmm1     # 0x3562c
movq %r15, %rsi
movq %r12, %rdx
callq 0x21e42
leaq 0x68ed(%rip), %rsi      # 0x33d30
pushq $0x2
popq %rcx
movss 0x85a2(%rip), %xmm0     # 0x359f0
movq %r12, %rdi
movq %r15, %rdx
movss 0x18(%rsp), %xmm1
callq 0x2b7fc
testq %rax, %rax
je 0x2d47a
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x2e2c5
cmpl $-0x1, %eax
je 0x2d488
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 0x2248d
movl %eax, %ecx
xorl %eax, %eax
testb %cl, %cl
jne 0x2d47c
cmpl $-0x1, 0x1c(%rsp)
je 0x2d3e0
jmp 0x2d47c
nop