// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/hlrad/lightmap.cpp
// Function: SetSampleFromST(float*, float*, int*, bool*, lightinfo_t const*, float, float, float const (*) [2], eModelLightmodes)
static light_flag_t SetSampleFromST(vec_t* const point,
#ifdef HLRAD_GROWSAMPLE
									vec_t* const position, // a valid world position for light tracing
									int* const surface, // the face used for phong normal and patch interpolation
#endif
#ifdef HLRAD_AVOIDWALLBLEED
									bool *nudged,
#endif
									const lightinfo_t* const l, const vec_t original_s, const vec_t original_t,
#ifdef HLRAD_GROWSAMPLE
#ifdef HLRAD_BLUR_MINIMALSQUARE
									const vec_t square[2][2], // {smin, tmin}, {smax, tmax}
#else
									const vec_t reach, // the size of the square that grows
#endif
#endif
									eModelLightmodes lightmode)
{
#ifdef HLRAD_GROWSAMPLE
	light_flag_t LuxelFlag;
	int facenum;
	dface_t *face;
	const dplane_t*	faceplane;
	samplefraginfo_t *fraginfo;
	samplefrag_t *f;

	facenum = l->surfnum;
	face = l->face;
	faceplane = getPlaneFromFace (face);
	
	fraginfo = CreateSampleFrag (facenum, original_s, original_t, 
#ifdef HLRAD_BLUR_MINIMALSQUARE
		square,
#else
		reach, 
#endif
		100);
	
	bool found;
	samplefrag_t *bestfrag;
	vec3_t bestpos;
	vec_t bests, bestt;
	vec_t best_dist;
#ifdef HLRAD_AVOIDWALLBLEED
	bool best_nudged;
#endif

	found = false;
	for (f = fraginfo->head; f; f = f->next)
	{
		vec3_t pos;
		vec_t s, t;
		vec_t dist;

#ifdef HLRAD_AVOIDWALLBLEED
		bool nudged_one;
#endif
		if (!FindNearestPosition (f->facenum, f->mywinding, f->mywindingplane, f->myorigin[0], f->myorigin[1], pos, &s, &t, &dist
#ifdef HLRAD_AVOIDWALLBLEED
									, &nudged_one
#endif
									))
		{
			continue;
		}

		bool better;

		if (!found)
		{
			better = true;
		}
#ifdef HLRAD_AVOIDWALLBLEED
		else if (nudged_one != best_nudged)
		{
			better = !nudged_one;
		}
#endif
		else if (fabs (dist - best_dist) > 2 * ON_EPSILON)
		{
			better = (dist < best_dist);
		}
		else if (f->noseam != bestfrag->noseam)
		{
			better = (f->noseam && !bestfrag->noseam);
		}
		else
		{
			better = (f->facenum < bestfrag->facenum);
		}

		if (better)
		{
			found = true;
			bestfrag = f;
			VectorCopy (pos, bestpos);
			bests = s;
			bestt = t;
			best_dist = dist;
#ifdef HLRAD_AVOIDWALLBLEED
			best_nudged = nudged_one;
#endif
		}
	}
	
	if (found)
	{
		matrix_t worldtotex, textoworld;
		vec3_t tex;

		TranslateWorldToTex (bestfrag->facenum, worldtotex);
		if (!InvertMatrix (worldtotex, textoworld))
		{
			const unsigned facenum = bestfrag->facenum;
			ThreadLock ();
			Log ("Malformed face (%d) normal @ \n", facenum);
			Winding* w = new Winding (g_dfaces[facenum]);
			for (int x = 0; x < w->m_NumPoints; x++)
			{
				VectorAdd (w->m_Points[x], g_face_offset[facenum], w->m_Points[x]);
			}
			w->Print ();
			delete w;
			ThreadUnlock ();
			hlassume (false, assume_MalformedTextureFace);
		}
		
		// point
		tex[0] = bests;
		tex[1] = bestt;
		tex[2] = 0.0;
		{vec3_t v; ApplyMatrix (textoworld, tex, v); VectorCopy (v, point);}
		VectorAdd (point, g_face_offset[bestfrag->facenum], point);
		// position
		VectorCopy (bestpos, position);
		// surface
		*surface = bestfrag->facenum;
#ifdef HLRAD_AVOIDWALLBLEED
		// whether nudged to fit
		*nudged = best_nudged;
#endif
		// returned value
		LuxelFlag = LightNormal;
	}
	else
	{
		SetSurfFromST (l, point, original_s, original_t);
		VectorMA (point, DEFAULT_HUNT_OFFSET, faceplane->normal, position);
		*surface = facenum;
#ifdef HLRAD_AVOIDWALLBLEED
		*nudged = true;
#endif
		LuxelFlag = LightOutside;
	}

	DeleteSampleFrag (fraginfo);
	
	return LuxelFlag;

#else
	light_flag_t	LuxelFlag = LightOutside;
	int				huntsize = 3;
	vec_t			huntscale = 0.2;
	vec_t			width = DEFAULT_EDGE_WIDTH;

	int				facenum = l->surfnum;
	const vec_t*	face_delta = g_face_offset[facenum];

	const dface_t*	f = &g_dfaces[facenum];
	const dplane_t*	p = getPlaneFromFace (f);
	Winding			*wd = new Winding (*f);
	{
		int				j;
		for (j = 0; j < wd->m_NumPoints; j++)
		{
			VectorAdd (wd->m_Points[j], face_delta, wd->m_Points[j]);
		}
	}

	const vec_t*	face_centroid = g_face_centroids[facenum];
	vec_t			mids, midt;
	SetSTFromSurf (l, face_centroid, mids, midt);

	vec3_t			surf_original;
	dleaf_t*		leaf_original;
	SetSurfFromST (l, surf_original, original_s, original_t);
	leaf_original = HuntForWorld (surf_original, face_delta, p, 1, 0.0, DEFAULT_HUNT_OFFSET);

	int				facenum_tosnap = PointInFace (l, surf_original);
	const dface_t*	f_tosnap = &g_dfaces[facenum_tosnap];
	const dplane_t*	p_tosnap = getPlaneFromFace (f_tosnap);
#ifdef HLRAD_SMOOTH_TEXNORMAL
	vec3_t			snapdir;
	if (!GetIntertexnormal (facenum, facenum_tosnap, snapdir))
	{
		facenum_tosnap = facenum;
		f_tosnap = f;
		p_tosnap = p;
	}
#endif

	vec3_t			surf_direct;
	dleaf_t*		leaf_direct;
	VectorCopy (surf_original, surf_direct);
	{
		vec_t dist;
		vec_t scale;
#ifdef HLRAD_SMOOTH_TEXNORMAL
		scale = DotProduct (snapdir, p_tosnap->normal);
#else
		scale = DotProduct (l->texnormal, p_tosnap->normal);
#endif
		dist = DotProduct (surf_direct, p_tosnap->normal) - DotProduct (face_delta, p_tosnap->normal) - p_tosnap->dist - DEFAULT_HUNT_OFFSET;
#ifdef HLRAD_SMOOTH_TEXNORMAL
		VectorMA (surf_direct, - dist / scale, snapdir, surf_direct);
#else
		VectorMA (surf_direct, - dist / scale, l->texnormal, surf_direct);
#endif
	}
	leaf_direct = HuntForWorld (surf_direct, face_delta, p_tosnap, huntsize, huntscale, DEFAULT_HUNT_OFFSET);

	if (LuxelFlag == LightOutside)
	{
		if (leaf_direct && point_in_winding_noedge (*wd, *p, surf_direct, width))
		{
			LuxelFlag = LightNormal;
			VectorCopy (surf_direct, point);
		}
	}

	if (LuxelFlag == LightOutside)
	{
		bool	blocked_direct;
		bool	blocked_inwinding;
		bool	blocked_inwinding_noedge;
		vec3_t	surf_inwinding;
		vec3_t	surf_inwinding_noedge;
		dleaf_t*leaf_inwinding;
		dleaf_t*leaf_inwinding_noedge;
#ifdef HLRAD_HULLU
		vec3_t transparency = { 1.0, 1.0, 1.0 };
#endif
#ifdef HLRAD_OPAQUE_STYLE
		int opaquestyle;
#endif
		{
			blocked_direct = (leaf_direct == NULL);
			if (!point_in_winding (*wd, *p, surf_original))
			{
				VectorCopy (surf_original, surf_inwinding);
				snap_to_winding (*wd, *p, surf_inwinding);
				leaf_inwinding = HuntForWorld (surf_inwinding, face_delta, p, huntsize, huntscale, DEFAULT_HUNT_OFFSET);
				if ( blocked_direct
					|| !leaf_inwinding
					|| TestLine (surf_direct, surf_inwinding) != CONTENTS_EMPTY
					|| TestSegmentAgainstOpaqueList (surf_direct, surf_inwinding
	#ifdef HLRAD_HULLU
						, transparency
	#endif
	#ifdef HLRAD_OPAQUE_STYLE
						, opaquestyle
	#endif
						) == true
	#ifdef HLRAD_OPAQUE_STYLE
					|| opaquestyle != -1
	#endif
	#ifdef HLRAD_TRANSLUCENT
					|| l->translucent_b
	#endif
					)
				{
					blocked_direct = true;
				}
			}
			else
			{
				VectorCopy (surf_original, surf_inwinding);
				leaf_inwinding = leaf_original;
			}
			blocked_inwinding = (leaf_inwinding == NULL);
			if (!point_in_winding_noedge (*wd, *p, surf_inwinding, width))
			{
				VectorCopy (surf_inwinding, surf_inwinding_noedge);
				snap_to_winding_noedge (*wd, *p, surf_inwinding_noedge, width, 4 * width);
				leaf_inwinding_noedge = HuntForWorld (surf_inwinding_noedge, face_delta, p, huntsize, huntscale, DEFAULT_HUNT_OFFSET);
				if ( blocked_inwinding
					|| !leaf_inwinding_noedge
					|| TestLine (surf_inwinding, surf_inwinding_noedge) != CONTENTS_EMPTY
					|| TestSegmentAgainstOpaqueList (surf_inwinding, surf_inwinding_noedge
	#ifdef HLRAD_HULLU
						, transparency
	#endif
	#ifdef HLRAD_OPAQUE_STYLE
						, opaquestyle
	#endif
						) == true
	#ifdef HLRAD_OPAQUE_STYLE
					|| opaquestyle != -1
	#endif
					)
				{
					blocked_inwinding = true;
				}
			}
			else
			{
				VectorCopy (surf_inwinding, surf_inwinding_noedge);
				leaf_inwinding_noedge = leaf_inwinding;
			}
			blocked_inwinding_noedge = (leaf_inwinding_noedge == NULL);
			if (blocked_inwinding_noedge == true)
			{
				blocked_inwinding = true;
			}
			if (blocked_inwinding == true)
			{
				blocked_direct = true;
			}
		}
		if (!blocked_direct)
		{
			LuxelFlag = LightNormal;
			VectorCopy (surf_direct, point);
		}
		else if (!blocked_inwinding)
		{
			LuxelFlag = LightPulledInside;
			VectorCopy (surf_inwinding, point);
		}
		else if (!blocked_inwinding_noedge)
		{
			LuxelFlag = LightPulledInside;
			VectorCopy (surf_inwinding_noedge, point);
		}
	}

	if (LuxelFlag == LightOutside)
	{
		// this part is very slow
		const int numnudges = 13;
		vec_t nudgelist[numnudges][2] = {{0,0},{0.6,0},{0,0.6},{-0.6,0},{0,-0.6},{1.1,1.1},{1.1,-1.1},{-1.1,1.1},{-1.1,-1.1},{1.6,0},{0,1.6},{-1.6,0},{0,-1.6}};
		vec_t nudgescale_s, nudgescale_t;
		nudgescale_s = original_s <= mids? TEXTURE_STEP: -TEXTURE_STEP;
		nudgescale_t = original_t <= midt? TEXTURE_STEP: -TEXTURE_STEP;
		int i;
		for (i = 0; i < numnudges; i++)
		{
			vec_t s1 = original_s + nudgelist[i][0] * nudgescale_s;
			vec_t t1 = original_t + nudgelist[i][1] * nudgescale_t;
			vec3_t surf;
			SetSurfFromST(l, surf, s1, t1);
			if (point_in_winding (*wd, *p, surf) && HuntForWorld (surf, face_delta, p, 2, 0.5, DEFAULT_HUNT_OFFSET) && point_in_winding (*wd, *p, surf))
			{
				LuxelFlag = LightSimpleNudge;
				VectorCopy (surf, point);
				break;
			}
		}
	}

	if (LuxelFlag == LightOutside)
	{
		VectorCopy (surf_original, point);
	}

	delete wd;
	return LuxelFlag;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r9, %r12
movss %xmm1, 0xc(%rsp)
movss %xmm0, 0x8(%rsp)
movq %rcx, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, 0x90(%rsp)
movl 0x135c(%r8), %ebp
movq %r8, 0x88(%rsp)
movq 0x1360(%r8), %rdi
callq 0x303c5
movq %rax, 0x80(%rsp)
movl $0x10, %edi
callq 0x4410
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa7c9
movabsq $0x100000064, %rax      # imm = 0x100000064
movq %rax, (%rbx)
movl $0x188, %edi            # imm = 0x188
callq 0x4410
movq %rax, %r15
movq %rbx, 0x18(%rsp)
movq %rax, 0x8(%rbx)
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa7c9
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movl %ebp, 0x44(%rsp)
movl %ebp, 0x18(%r15)
xorl %ebx, %ebx
movl %ebx, 0x1c(%r15)
movb $0x1, 0x20(%r15)
leaq 0x24(%r15), %rsi
leaq 0x1e5c4(%rip), %r13     # 0x39dd0
movss 0x1c924(%rip), %xmm0    # 0x38138
movq %r13, %rdi
callq 0x30b55
leaq 0x54(%r15), %rsi
movq %r13, %rdi
movss 0x1c90d(%rip), %xmm0    # 0x38138
callq 0x30b55
movss 0x8(%rsp), %xmm1
movss %xmm1, 0x84(%r15)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x88(%r15)
movl %ebx, 0x8c(%r15)
movss %xmm1, 0x90(%r15)
movss %xmm0, 0x94(%r15)
leaq 0x9c(%r15), %rsi
movsd 0x202ca(%rip), %xmm0    # 0x3bb40
movups %xmm0, 0x98(%r15)
movss (%r12), %xmm0
movss %xmm0, 0xa8(%r15)
movsd 0x203cb(%rip), %xmm0    # 0x3bc60
movsd %xmm0, 0xb0(%r15)
movl $0x80000000, %eax       # imm = 0x80000000
movl %eax, 0xb8(%r15)
movss 0x8(%r12), %xmm0
movaps 0x1c7d8(%rip), %xmm1    # 0x38090
xorps %xmm1, %xmm0
movss %xmm0, 0xbc(%r15)
movsd 0x20274(%rip), %xmm0    # 0x3bb40
movsd %xmm0, 0xc4(%r15)
movl %ebx, 0xcc(%r15)
movss 0x4(%r12), %xmm0
movss %xmm0, 0xd0(%r15)
movsd 0x2037c(%rip), %xmm0    # 0x3bc70
movsd %xmm0, 0xd8(%r15)
movl %eax, 0xe0(%r15)
movss 0xc(%r12), %xmm0
xorps %xmm1, %xmm0
movss %xmm0, 0xe4(%r15)
leaq 0xec(%r15), %rdi
movl $0x14, %ecx
rep  movsl (%rsi), %es:(%rdi)
movq %r15, %rdi
callq 0x17c24
movq 0x140(%r15), %rax
cmpl %ebx, 0x8(%rax)
je 0x1b99b
movq 0x160(%r15), %rax
cmpl $0x0, 0x8(%rax)
je 0x1b99b
cmpl $0x0, 0x17c(%r15)
movq 0x18(%rsp), %rbx
movss 0xc(%rsp), %xmm3
movss 0x8(%rsp), %xmm4
jle 0x1b9f3
movq 0x180(%r15), %rax
movl 0x8(%rax), %ecx
cmpl 0x18(%r15), %ecx
jne 0x1b979
movb $0x1, 0xc(%rax)
addq $0xa8, %rax
movslq 0x17c(%r15), %rcx
imulq $0xa8, %rcx, %rcx
addq 0x180(%r15), %rcx
cmpq %rcx, %rax
jb 0x1b96c
jmp 0x1b9f3
movq 0x160(%r15), %rdi
testq %rdi, %rdi
je 0x1b9ad
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x140(%r15), %rdi
testq %rdi, %rdi
movq 0x18(%rsp), %rbx
je 0x1b9c4
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x180(%r15), %rdi
callq 0x4380
movq %r15, %rdi
callq 0x4380
movq $0x0, 0x8(%rbx)
movl $0x0, 0x4(%rbx)
movss 0xc(%rsp), %xmm3
movss 0x8(%rsp), %xmm4
movsd 0x1fc95(%rip), %xmm6    # 0x3b690
movsd 0x1fc8d(%rip), %xmm7    # 0x3b690
movaps 0x1f936(%rip), %xmm5    # 0x3b340
movsd 0x1fc35(%rip), %xmm8    # 0x3b648
movl 0x4(%rbx), %eax
cmpl (%rbx), %eax
jge 0x1c1fd
movq 0x8(%rbx), %rax
xorl %r15d, %r15d
testq %rax, %rax
je 0x1bb36
movslq 0x17c(%rax), %rdx
testq %rdx, %rdx
jle 0x1bb2e
movq 0x180(%rax), %rcx
imulq $0xa8, %rdx, %rdx
addq %rcx, %rdx
cmpb $0x0, 0xc(%rcx)
jne 0x1bb1e
testb $0x1, %r15b
je 0x1bb15
xorps %xmm0, %xmm0
cvtss2sd 0x40(%rcx), %xmm0
ucomisd %xmm0, %xmm6
seta %sil
xorps %xmm1, %xmm1
cvtss2sd 0x40(%r12), %xmm1
ucomisd %xmm1, %xmm6
seta %dil
cmpb %dil, %sil
je 0x1ba9e
cmpnltpd %xmm7, %xmm1
cmpltpd %xmm7, %xmm0
andpd %xmm1, %xmm0
movd %xmm0, %esi
jmp 0x1bb0f
movb 0x34(%rcx), %sil
movb 0x34(%r12), %dil
cmpb %dil, %sil
jne 0x1bad2
movss 0x38(%rcx), %xmm0
movss 0x38(%r12), %xmm1
movaps %xmm0, %xmm2
subss %xmm1, %xmm2
andps %xmm5, %xmm2
cvtss2sd %xmm2, %xmm2
ucomisd %xmm8, %xmm2
jbe 0x1badb
ucomiss %xmm0, %xmm1
jmp 0x1baff
xorb $0x1, %dil
andb %dil, %sil
jmp 0x1bb0f
movss 0x3c(%rcx), %xmm0
movss 0x3c(%r12), %xmm1
movaps %xmm0, %xmm2
subss %xmm1, %xmm2
andps %xmm5, %xmm2
cvtss2sd %xmm2, %xmm2
ucomisd %xmm8, %xmm2
jbe 0x1bb05
ucomiss %xmm1, %xmm0
seta %sil
jmp 0x1bb0f
movl (%rcx), %esi
cmpl (%r12), %esi
setl %sil
testb $0x1, %sil
je 0x1bb1e
movb $0x1, %r15b
movq %rax, %r14
movq %rcx, %r12
addq $0xa8, %rcx
cmpq %rdx, %rcx
jb 0x1ba4f
movq (%rax), %rax
jmp 0x1ba25
testb $0x1, %r15b
je 0x1c1fd
movl $0x188, %edi            # imm = 0x188
callq 0x4410
movq %rax, %rbp
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa7c9
movq $0x0, (%rbp)
movq %r14, 0x8(%rbp)
movq %r12, 0x10(%rbp)
movl 0x8(%r12), %eax
movl %eax, 0x18(%rbp)
movss 0x40(%r12), %xmm0
movss %xmm0, 0x1c(%rbp)
movb 0x34(%r12), %al
movb %al, 0x20(%rbp)
leaq 0x48(%r12), %rdi
leaq 0x24(%r14), %rsi
leaq 0x24(%rbp), %r13
movq %r13, %rdx
callq 0x30a9b
leaq 0x54(%r14), %rdi
movq %r12, 0x20(%rsp)
leaq 0x78(%r12), %rsi
leaq 0x54(%rbp), %r12
movq %r12, %rdx
callq 0x30a9b
movss 0x84(%r14), %xmm0
leaq 0x84(%rbp), %rsi
movss %xmm0, 0x84(%rbp)
movss 0x88(%r14), %xmm0
movss %xmm0, 0x88(%rbp)
movss 0x8c(%r14), %xmm0
movss %xmm0, 0x8c(%rbp)
leaq 0x90(%rbp), %rdx
movq %r13, %rdi
callq 0x30943
movl $0x9c, %eax
movq %r14, 0x28(%rsp)
leaq (%r14,%rax), %rsi
movq %r12, %r14
leaq (%rbp,%rax), %rdi
movl $0x14, %ecx
rep  movsl (%rsi), %es:(%rdi)
movq %rbp, %r13
addq $0xf8, %r13
movl $0x4, %r12d
leaq -0x5c(%r13), %rsi
movss -0x50(%r13), %xmm0
leaq -0xc(%r13), %rdx
movq %r14, %rdi
movq %r13, %rcx
callq 0x309e1
movsd -0xc(%r13), %xmm0
mulps %xmm0, %xmm0
cvtps2pd %xmm0, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movss -0x4(%r13), %xmm0
mulss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x1f68c(%rip), %xmm0    # 0x3b308
jb 0x1bc89
xorps %xmm9, %xmm9
sqrtsd %xmm0, %xmm9
jmp 0x1bc93
callq 0x4240
movapd %xmm0, %xmm9
ucomisd 0x1f66c(%rip), %xmm9    # 0x3b308
movss 0xc(%rsp), %xmm3
movss 0x8(%rsp), %xmm4
movaps 0x1f691(%rip), %xmm5    # 0x3b340
movsd 0x1f9d9(%rip), %xmm6    # 0x3b690
movsd 0x1f9d1(%rip), %xmm7    # 0x3b690
movsd 0x1f980(%rip), %xmm8    # 0x3b648
jne 0x1bccc
jnp 0x1bd28
movsd 0x1f494(%rip), %xmm0    # 0x3b168
divsd %xmm9, %xmm0
cvtps2pd -0xc(%r13), %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
mulpd %xmm1, %xmm2
cvtpd2ps %xmm2, %xmm1
movlpd %xmm1, -0xc(%r13)
xorps %xmm1, %xmm1
cvtss2sd -0x4(%r13), %xmm1
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, -0x4(%r13)
xorps %xmm0, %xmm0
cvtss2sd (%r13), %xmm0
divsd %xmm9, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r13)
jmp 0x1bd80
movl 0x18(%rbp), %edx
movl $0x6, %edi
leaq 0x20734(%rip), %rsi     # 0x3c46b
xorl %eax, %eax
movsd %xmm9, 0x10(%rsp)
callq 0xa52e
movq %rbp, %rdi
callq 0x4380
movsd 0x10(%rsp), %xmm9
movsd 0x1f8eb(%rip), %xmm8    # 0x3b648
movsd 0x1f92b(%rip), %xmm7    # 0x3b690
movsd 0x1f923(%rip), %xmm6    # 0x3b690
movaps 0x1f5cc(%rip), %xmm5    # 0x3b340
movss 0x8(%rsp), %xmm4
movss 0xc(%rsp), %xmm3
ucomisd 0x1f57f(%rip), %xmm9    # 0x3b308
jne 0x1bd91
jnp 0x1bf85
addq $0x14, %r13
decq %r12
jne 0x1bc31
movq %rbp, %rdi
callq 0x17c24
movq 0x140(%rbp), %rax
movl 0x8(%rax), %eax
testq %rax, %rax
je 0x1bf93
movq 0x160(%rbp), %rcx
cmpl $0x0, 0x8(%rcx)
je 0x1bf93
shlq $0x2, %rax
leaq (%rax,%rax,4), %rdi
callq 0x4410
xorl %edi, %edi
movq %rax, 0x30(%rsp)
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa7c9
movq 0x140(%rbp), %rcx
movl 0x8(%rcx), %eax
testl %eax, %eax
je 0x1c0c0
movl $0x0, 0x10(%rsp)
xorl %r12d, %r12d
movq 0x30(%rsp), %rdi
movl %r12d, %edx
movq 0x10(%rcx), %rcx
movslq %r12d, %rsi
leal 0x1(%rdx), %r12d
cmpl %eax, %r12d
movl %r12d, %eax
movl $0x0, %edx
cmovel %edx, %eax
leaq (%rax,%rax,2), %rax
movss (%rcx,%rax,4), %xmm0
leaq (%rsi,%rsi,2), %r13
subss (%rcx,%r13,4), %xmm0
movslq 0x10(%rsp), %rdx
leaq (%rdx,%rdx,4), %r14
movss 0x148(%rbp), %xmm1
movsd 0x4(%rcx,%rax,4), %xmm2
movsd 0x4(%rcx,%r13,4), %xmm3
subps %xmm3, %xmm2
movsd 0x14c(%rbp), %xmm3
movaps %xmm0, %xmm4
shufps $0xd4, %xmm2, %xmm4     # xmm4 = xmm4[0,1],xmm2[1,3]
shufps $0x52, %xmm2, %xmm4     # xmm4 = xmm4[2,0],xmm2[1,1]
mulps %xmm3, %xmm4
movaps %xmm1, %xmm5
shufps $0xd4, %xmm3, %xmm5     # xmm5 = xmm5[0,1],xmm3[1,3]
shufps $0x52, %xmm3, %xmm5     # xmm5 = xmm5[2,0],xmm3[1,1]
mulps %xmm2, %xmm5
subps %xmm4, %xmm5
movlps %xmm5, (%rdi,%r14,4)
mulss %xmm1, %xmm2
mulss %xmm3, %xmm0
subss %xmm2, %xmm0
movss %xmm0, 0x8(%rdi,%r14,4)
movaps %xmm5, %xmm1
mulps %xmm5, %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
mulss %xmm5, %xmm5
addss %xmm1, %xmm5
mulss %xmm0, %xmm0
addss %xmm5, %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd 0x1f442(%rip), %xmm0    # 0x3b308
jb 0x1bece
sqrtsd %xmm0, %xmm0
jmp 0x1bed8
callq 0x4240
movq 0x30(%rsp), %rdi
leaq (%rdi,%r14,4), %rax
movsd 0x1c22c(%rip), %xmm1    # 0x38110
ucomisd %xmm0, %xmm1
jbe 0x1befa
movl $0x0, 0x8(%rax)
movq $0x0, (%rax)
jmp 0x1bf6d
cvtps2pd (%rax), %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
divpd %xmm2, %xmm1
cvtpd2ps %xmm1, %xmm1
movlpd %xmm1, (%rax)
xorps %xmm2, %xmm2
cvtss2sd 0x8(%rax), %xmm2
divsd %xmm0, %xmm2
cvtsd2ss %xmm2, %xmm2
movss %xmm2, 0x8(%rax)
cvtsd2ss %xmm0, %xmm0
ucomiss 0x1c213(%rip), %xmm0    # 0x38144
jne 0x1bf35
jnp 0x1bf6d
movq 0x140(%rbp), %rcx
movq 0x10(%rcx), %rcx
movapd %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
mulss 0x4(%rcx,%r13,4), %xmm0
mulss (%rcx,%r13,4), %xmm1
mulss 0x8(%rcx,%r13,4), %xmm2
addss %xmm0, %xmm1
addss %xmm1, %xmm2
movss %xmm2, 0xc(%rax)
incl 0x10(%rsp)
movq 0x140(%rbp), %rcx
movl 0x8(%rcx), %eax
cmpl %eax, %r12d
jb 0x1be11
jmp 0x1c0cd
xorl %ebp, %ebp
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r12
jmp 0x1c003
movq 0x160(%rbp), %rdi
testq %rdi, %rdi
je 0x1bfa5
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x140(%rbp), %rdi
testq %rdi, %rdi
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r12
je 0x1bfc1
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x180(%rbp), %rdi
callq 0x4380
movq %rbp, %rdi
xorl %ebp, %ebp
callq 0x4380
movss 0xc(%rsp), %xmm3
movss 0x8(%rsp), %xmm4
movaps 0x1f356(%rip), %xmm5    # 0x3b340
movsd 0x1f69e(%rip), %xmm6    # 0x3b690
movsd 0x1f696(%rip), %xmm7    # 0x3b690
movsd 0x1f645(%rip), %xmm8    # 0x3b648
movb $0x1, 0xc(%r12)
testq %rbp, %rbp
je 0x1c0b1
movq 0x8(%rbx), %rax
movq %rax, (%rbp)
movq %rbp, 0x8(%rbx)
incl 0x4(%rbx)
movq %rbp, %rax
cmpl $0x0, 0x17c(%rbp)
jle 0x1c061
movq 0x180(%rbp), %rcx
movl 0x8(%rcx), %edx
cmpl 0x18(%rax), %edx
jne 0x1c040
movb $0x1, 0xc(%rcx)
addq $0xa8, %rcx
movslq 0x17c(%rbp), %rdx
imulq $0xa8, %rdx, %rdx
addq 0x180(%rbp), %rdx
cmpq %rdx, %rcx
jb 0x1c034
movq (%rax), %rax
testq %rax, %rax
jne 0x1c024
movq %rbp, %rax
cmpl $0x0, 0x17c(%rax)
jle 0x1c0a9
movq 0x180(%rax), %rcx
movl 0x8(%rcx), %edx
cmpl 0x18(%rbp), %edx
jne 0x1c088
movb $0x1, 0xc(%rcx)
addq $0xa8, %rcx
movslq 0x17c(%rax), %rdx
imulq $0xa8, %rdx, %rdx
addq 0x180(%rax), %rdx
cmpq %rdx, %rcx
jb 0x1c07c
movq (%rax), %rax
testq %rax, %rax
jne 0x1c06c
testb $0x1, %r15b
jne 0x1ba13
jmp 0x1c1fd
movl $0x0, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movq 0x8(%rbx), %r12
testq %r12, %r12
je 0x1c1b8
movl 0x10(%rsp), %eax
movq %rax, 0x70(%rsp)
xorl %r14d, %r14d
movl $0x20, %edi
callq 0x42f0
movq %rax, %r13
movq %r12, 0x38(%rsp)
movq 0x140(%r12), %rsi
movq %rax, %rdi
callq 0xc3be
cmpl $0x0, 0x10(%rsp)
jle 0x1c13e
movq 0x30(%rsp), %r12
movq 0x70(%rsp), %rbx
cmpl $0x0, 0x8(%r13)
je 0x1c13e
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
movss 0x1f958(%rip), %xmm0    # 0x3ba88
callq 0xd0d2
addq $0x14, %r12
decq %rbx
jne 0x1c119
cmpl $0x0, 0x8(%r13)
movzbl %r14b, %r14d
movl $0x1, %eax
cmovnel %eax, %r14d
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
movq 0x38(%rsp), %r12
movq (%r12), %r12
testq %r12, %r12
je 0x1c172
testb $0x1, %r14b
je 0x1c0e6
movq 0x30(%rsp), %rdi
callq 0x4380
testb $0x1, %r14b
je 0x1c1c7
movq 0x160(%rbp), %rdi
testq %rdi, %rdi
movq 0x18(%rsp), %rbx
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r12
je 0x1c1a3
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x140(%rbp), %rdi
testq %rdi, %rdi
jne 0x1bfbb
jmp 0x1bfc1
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r12
jmp 0x1bfd2
movq 0x18(%rsp), %rbx
movss 0xc(%rsp), %xmm3
movss 0x8(%rsp), %xmm4
movaps 0x1f161(%rip), %xmm5    # 0x3b340
movsd 0x1f4a9(%rip), %xmm6    # 0x3b690
movsd 0x1f4a1(%rip), %xmm7    # 0x3b690
movsd 0x1f450(%rip), %xmm8    # 0x3b648
jmp 0x1bf87
movq 0x8(%rbx), %r13
xorl %ebp, %ebp
testq %r13, %r13
je 0x1c37b
leaq 0xa8(%rsp), %r15
leaq 0xd8(%rsp), %r12
leaq 0x9c(%rsp), %rbp
xorl %r14d, %r14d
movl 0x18(%r13), %edi
movq 0x160(%r13), %rsi
leaq 0x168(%r13), %rdx
movss 0x90(%r13), %xmm0
movss 0x94(%r13), %xmm1
movq %r15, %rcx
movq %r12, %r8
movq %rbp, %r9
leaq 0x7(%rsp), %rax
pushq %rax
leaq 0x68(%rsp), %rax
pushq %rax
callq 0x31c79
addq $0x10, %rsp
testb %al, %al
je 0x1c2c5
movb $0x1, %al
testb $0x1, %r14b
movss 0xc(%rsp), %xmm3
movss 0x8(%rsp), %xmm4
movaps 0x1f0ba(%rip), %xmm2    # 0x3b340
movss 0x10(%rsp), %xmm5
je 0x1c2db
movb 0x7(%rsp), %al
movl %ebx, %ecx
andb $0x1, %cl
cmpb %cl, %al
jne 0x1c2d9
movss 0x60(%rsp), %xmm0
movaps %xmm0, %xmm1
subss %xmm5, %xmm1
andps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd 0x1f371(%rip), %xmm1    # 0x3b628
jbe 0x1c341
ucomiss %xmm0, %xmm5
seta %al
jmp 0x1c2db
movss 0xc(%rsp), %xmm3
movss 0x8(%rsp), %xmm4
movss 0x10(%rsp), %xmm5
jmp 0x1c32c
xorb $0x1, %al
testb %al, %al
je 0x1c32c
movsd 0xa8(%rsp), %xmm0
movaps %xmm0, 0x70(%rsp)
movss 0xb0(%rsp), %xmm0
movss %xmm0, 0x30(%rsp)
movss 0xd8(%rsp), %xmm0
movss %xmm0, 0x28(%rsp)
movss 0x9c(%rsp), %xmm0
movss %xmm0, 0x20(%rsp)
movss 0x60(%rsp), %xmm5
movb $0x1, %r14b
movb 0x7(%rsp), %bl
movq %r13, 0x38(%rsp)
movss %xmm5, 0x10(%rsp)
movq (%r13), %r13
testq %r13, %r13
jne 0x1c227
jmp 0x1c374
movb 0x20(%r13), %cl
movq 0x38(%rsp), %rdx
movb 0x20(%rdx), %al
cmpb %al, %cl
jne 0x1c360
movl 0x18(%r13), %eax
cmpl 0x18(%rdx), %eax
setl %al
jmp 0x1c2db
xorb $0x1, %al
movzbl %al, %eax
testb %cl, %cl
movl $0x0, %ecx
cmovel %ecx, %eax
jmp 0x1c2db
andb $0x1, %bl
movl %ebx, %ebp
jmp 0x1c37e
xorl %r14d, %r14d
testb $0x1, %r14b
movq 0x90(%rsp), %r12
movq 0x88(%rsp), %rdx
je 0x1c573
movq 0x38(%rsp), %r15
movl 0x18(%r15), %edi
leaq 0xa8(%rsp), %r14
movq %r14, %rsi
callq 0x30c1e
leaq 0xd8(%rsp), %rsi
movq %r14, %rdi
callq 0x30cbc
testb %al, %al
movq 0x18(%rsp), %rbx
jne 0x1c4a1
movl 0x18(%r15), %r15d
callq 0xb411
leaq 0x2006e(%rip), %rdi     # 0x3c44c
movl %r15d, %esi
xorl %eax, %eax
callq 0x9d2e
movl $0x20, %edi
callq 0x42f0
movq %rax, %r14
leaq (%r15,%r15,4), %rsi
shlq $0x2, %rsi
addq 0x2bbdc(%rip), %rsi     # 0x47fe0
movss 0x1f678(%rip), %xmm0    # 0x3ba84
movq %rax, %rdi
callq 0xc700
cmpl $0x0, 0x8(%r14)
je 0x1c47a
leaq (%r15,%r15,2), %rax
shlq $0x2, %rax
addq 0x2bb4e(%rip), %rax     # 0x47f78
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x10(%r14), %rsi
movss (%rsi,%rcx), %xmm0
addss (%rax), %xmm0
movss %xmm0, (%rsi,%rcx)
movq 0x10(%r14), %rsi
movss 0x4(%rsi,%rcx), %xmm0
addss 0x4(%rax), %xmm0
movss %xmm0, 0x4(%rsi,%rcx)
movq 0x10(%r14), %rsi
movss 0x8(%rsi,%rcx), %xmm0
addss 0x8(%rax), %xmm0
movss %xmm0, 0x8(%rsi,%rcx)
incq %rdx
movl 0x8(%r14), %esi
addq $0xc, %rcx
cmpq %rsi, %rdx
jb 0x1c42e
movq %r14, %rdi
callq 0xb7a0
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
callq 0xb422
xorl %edi, %edi
movl $0x1e, %esi
callq 0xa7c9
movq 0x38(%rsp), %r15
leaq 0x9c(%rsp), %rsi
movss 0x28(%rsp), %xmm0
movss %xmm0, (%rsi)
movss 0x20(%rsp), %xmm0
movss %xmm0, 0x4(%rsi)
movl $0x0, 0x8(%rsi)
leaq 0xd8(%rsp), %rdi
leaq 0x60(%rsp), %r14
movq %r14, %rdx
callq 0x30943
movsd (%r14), %xmm0
movsd %xmm0, (%r12)
movss 0x8(%r14), %xmm1
movss %xmm1, 0x8(%r12)
movslq 0x18(%r15), %rax
leaq (%rax,%rax,2), %rax
leaq 0x541c4ef(%rip), %rcx   # 0x54389f0
movss (%rcx,%rax,4), %xmm2
addss %xmm0, %xmm2
movss %xmm2, (%r12)
movslq 0x18(%r15), %rax
leaq (%rax,%rax,2), %rax
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
addss 0x4(%rcx,%rax,4), %xmm0
movss %xmm0, 0x4(%r12)
movslq 0x18(%r15), %rax
leaq (%rax,%rax,2), %rax
addss 0x8(%rcx,%rax,4), %xmm1
movss %xmm1, 0x8(%r12)
movq 0x48(%rsp), %rax
movaps 0x70(%rsp), %xmm0
movlps %xmm0, (%rax)
movss 0x30(%rsp), %xmm0
movss %xmm0, 0x8(%rax)
movl 0x18(%r15), %eax
movq 0x50(%rsp), %rcx
movl %eax, (%rcx)
movq 0x58(%rsp), %rax
movb %bpl, (%rax)
movl $0x3, %ebp
jmp 0x1c68f
movslq 0x135c(%rdx), %rax
xorl %ecx, %ecx
movq 0x18(%rsp), %rbx
movss 0xf18(%rdx,%rcx,4), %xmm0
mulss %xmm4, %xmm0
addss 0xef4(%rdx,%rcx,4), %xmm0
movss 0xf24(%rdx,%rcx,4), %xmm1
mulss %xmm3, %xmm1
addss %xmm0, %xmm1
movss %xmm1, (%r12,%rcx,4)
incq %rcx
cmpq $0x3, %rcx
jne 0x1c581
leaq (%rax,%rax,2), %rax
leaq 0x541c42e(%rip), %rcx   # 0x54389f0
movss (%r12), %xmm0
movss 0x4(%r12), %xmm1
addss (%rcx,%rax,4), %xmm0
movss %xmm0, (%r12)
addss 0x4(%rcx,%rax,4), %xmm1
movss %xmm1, 0x4(%r12)
movss 0x8(%r12), %xmm1
addss 0x8(%rcx,%rax,4), %xmm1
movss %xmm1, 0x8(%r12)
cvtss2sd %xmm0, %xmm0
movq 0x80(%rsp), %rcx
xorps %xmm1, %xmm1
cvtss2sd (%rcx), %xmm1
movsd 0x1ecea(%rip), %xmm2    # 0x3b300
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movq 0x48(%rsp), %rax
movss %xmm0, (%rax)
xorps %xmm0, %xmm0
cvtss2sd 0x4(%r12), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%rcx), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x4(%rax)
xorps %xmm0, %xmm0
cvtss2sd 0x8(%r12), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x8(%rcx), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x8(%rax)
movq 0x50(%rsp), %rax
movl 0x44(%rsp), %ecx
movl %ecx, (%rax)
movq 0x58(%rsp), %rax
movb $0x1, (%rax)
xorl %ebp, %ebp
movq 0x8(%rbx), %r14
testq %r14, %r14
je 0x1c6e7
movq (%r14), %rbx
movq 0x160(%r14), %rdi
testq %rdi, %rdi
je 0x1c6ad
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x140(%r14), %rdi
testq %rdi, %rdi
je 0x1c6bf
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x180(%r14), %rdi
callq 0x4380
movq %r14, %rdi
callq 0x4380
movq %rbx, %r14
testq %rbx, %rbx
jne 0x1c698
movq 0x18(%rsp), %rax
movq %rbx, 0x8(%rax)
movq %rax, %rbx
movq %rbx, %rdi
callq 0x4380
movl %ebp, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
jmp 0x1c71b
movq %rax, %rbx
movl $0x20, %esi
movq %r13, %rdi
callq 0x4300
movq %rbx, %rdi
callq 0x4590