// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/common/bspfile.cpp
// Function: GetFaceExtents(int, int*, int*)
void GetFaceExtents (int facenum, int mins_out[2], int maxs_out[2])
{
	CorrectFPUPrecision ();

	dface_t *f;
	float mins[2], maxs[2], val;
	int i, j, e;
	dvertex_t *v;
	texinfo_t *tex;
	int bmins[2], bmaxs[2];

	f = &g_dfaces[facenum];

	mins[0] = mins[1] = 999999;
	maxs[0] = maxs[1] = -99999;

#ifdef ZHLT_EMBEDLIGHTMAP
	tex = &g_texinfo[ParseTexinfoForFace (f)];
#else
	tex = &g_texinfo[f->texinfo];
#endif

	for (i = 0; i < f->numedges; i++)
	{
		e = g_dsurfedges[f->firstedge + i];
		if (e >= 0)
		{
			v = &g_dvertexes[g_dedges[e].v[0]];
		}
		else
		{
			v = &g_dvertexes[g_dedges[-e].v[1]];
		}
		for (j = 0; j < 2; j++)
		{
			// The old code: val = v->point[0] * tex->vecs[j][0] + v->point[1] * tex->vecs[j][1] + v->point[2] * tex->vecs[j][2] + tex->vecs[j][3];
			//   was meant to be compiled for x86 under MSVC (prior to VS 11), so the intermediate values were stored as 64-bit double by default.
			// The new code will produce the same result as the old code, but it's portable for different platforms.
			// See this article for details: Intermediate Floating-Point Precision by Bruce-Dawson http://www.altdevblogaday.com/2012/03/22/intermediate-floating-point-precision/

			// The essential reason for having this ugly code is to get exactly the same value as the counterpart of game engine.
			// The counterpart of game engine is the function CalcFaceExtents in HLSDK.
			// So we must also know how Valve compiles HLSDK. I think Valve compiles HLSDK with VC6.0 in the past.
			val = CalculatePointVecsProduct (v->point, tex->vecs[j]);
			if (val < mins[j])
			{
				mins[j] = val;
			}
			if (val > maxs[j])
			{
				maxs[j] = val;
			}
		}
	}

	for (i = 0; i < 2; i++)
	{
		bmins[i] = (int)floor (mins[i] / TEXTURE_STEP);
		bmaxs[i] = (int)ceil (maxs[i] / TEXTURE_STEP);
	}

	for (i = 0; i < 2; i++)
	{
		mins_out[i] = bmins[i];
		maxs_out[i] = bmaxs[i];
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movslq %edi, %rax
imulq $0x14, %rax, %rbx
leaq 0x1b89cfd(%rip), %r14   # 0x1b8f430
leaq (%r14,%rbx), %rdi
movsd 0x13901(%rip), %xmm0    # 0x19040
movsd %xmm0, 0x10(%rsp)
movsd 0x13903(%rip), %xmm0    # 0x19050
movsd %xmm0, 0x8(%rsp)
movq %rdi, 0x30(%rsp)
callq 0x5893
cltq
imulq $0x28, %rax, %rax
leaq 0x1189cb6(%rip), %rcx   # 0x118f420
addq %rax, %rcx
movq %rcx, 0x28(%rsp)
movl 0x8(%rbx,%r14), %eax
xorl %ebx, %ebx
testw %ax, %ax
cmovlel %ebx, %eax
movzwl %ax, %r14d
leaq 0x1d09ca6(%rip), %r15   # 0x1d0f430
cmpl %r14d, %ebx
je 0x5818
movq 0x30(%rsp), %rax
movslq 0x4(%rax), %rax
movslq %ebx, %rcx
addq %rax, %rcx
leaq 0x1e23ca7(%rip), %rax   # 0x1e29450
movslq (%rax,%rcx,4), %rax
movl %eax, %ecx
negl %ecx
testq %rax, %rax
leaq (%r15,%rax,4), %rax
leaq 0x2(%r15,%rcx,4), %rcx
cmovnsq %rax, %rcx
movzwl (%rcx), %eax
imulq $0xc, %rax, %r12
leaq 0x1009c61(%rip), %rax   # 0x100f430
addq %rax, %r12
movq 0x28(%rsp), %r13
xorl %ebp, %ebp
cmpq $0x2, %rbp
je 0x5811
movq %r12, %rdi
movq %r13, %rsi
callq 0x5613
movss 0x10(%rsp,%rbp,4), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x57fb
movss %xmm0, 0x10(%rsp,%rbp,4)
ucomiss 0x8(%rsp,%rbp,4), %xmm0
jbe 0x5808
movss %xmm0, 0x8(%rsp,%rbp,4)
incq %rbp
addq $0x10, %r13
jmp 0x57d9
incl %ebx
jmp 0x578a
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0x585f
movss 0x10(%rsp,%rbx,4), %xmm0
movss 0x13832(%rip), %xmm1    # 0x19060
mulss %xmm1, %xmm0
callq 0x4170
cvttss2si %xmm0, %eax
movl %eax, 0x40(%rsp,%rbx,4)
movss 0x8(%rsp,%rbx,4), %xmm0
mulss 0x13813(%rip), %xmm0    # 0x19060
callq 0x41f0
cvttss2si %xmm0, %eax
movl %eax, 0x38(%rsp,%rbx,4)
incq %rbx
jmp 0x581a
xorl %eax, %eax
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rsi
cmpq $0x2, %rax
je 0x5884
movl 0x40(%rsp,%rax,4), %ecx
movl %ecx, (%rsi,%rax,4)
movl 0x38(%rsp,%rax,4), %ecx
movl %ecx, (%rdx,%rax,4)
incq %rax
jmp 0x586b
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq