// File: /workspace/github_cpp_makefile_star2_O1/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 0x30943
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 0x1a89c
cvtps2pd (%r12), %xmm0
cvtps2pd (%r15), %xmm1
mulpd 0xa20d(%rip), %xmm1     # 0x3c5c0
addpd %xmm0, %xmm1
cvtpd2ps %xmm1, %xmm0
movlpd %xmm0, (%r12)
xorps %xmm1, %xmm1
cvtss2sd 0x8(%r12), %xmm1
cvtss2sd 0x8(%r15), %xmm2
mulsd 0x8f27(%rip), %xmm2     # 0x3b300
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 0x79a3(%rip), %rsi      # 0x39dd0
movss 0x967b(%rip), %xmm0     # 0x3bab0
movq %r12, %rdi
movq %r15, %rdx
movl $0x2, %ecx
movss %xmm1, 0x18(%rsp)
callq 0x304d4
testq %rax, %rax
je 0x32510
movq 0xa0(%r14), %rdi
leaq 0x8(%rsp), %rdx
movss 0x9260(%rip), %xmm0     # 0x3b6c8
movq %r15, %rsi
callq 0x2581b
testb %al, %al
je 0x32490
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rbx)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x8(%rbx)
movb $0x1, %al
jmp 0x32512
movsd 0x8(%rsp), %xmm0
leaq 0x20(%rsp), %r12
movsd %xmm0, (%r12)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x8(%r12)
movq 0xa0(%r14), %rdi
movss 0x920b(%rip), %xmm0     # 0x3b6c8
movss 0x9207(%rip), %xmm1     # 0x3b6cc
movq %r15, %rsi
movq %r12, %rdx
callq 0x25d1a
leaq 0x78f9(%rip), %rsi      # 0x39dd0
movss 0x95d1(%rip), %xmm0     # 0x3bab0
movq %r12, %rdi
movq %r15, %rdx
movl $0x2, %ecx
movss 0x18(%rsp), %xmm1
callq 0x304d4
testq %rax, %rax
je 0x32510
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x334c8
cmpl $-0x1, %eax
je 0x3251e
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 0x264b3
movl %eax, %ecx
xorl %eax, %eax
testb %cl, %cl
jne 0x32512
cmpl $-0x1, 0x1c(%rsp)
je 0x32474
jmp 0x32512