// File: /workspace/github_cpp_makefile_star2_O3/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, 0x4(%rsp)
movss %xmm0, (%rsp)
movq %rcx, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, %r14
movl 0x135c(%r8), %ebp
movq %r8, 0x70(%rsp)
movq 0x1360(%r8), %rdi
callq 0x2f342
movq %rax, 0x78(%rsp)
movl $0x10, %edi
callq 0x4400
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa6ed
movabsq $0x100000064, %rax      # imm = 0x100000064
movq %rax, (%rbx)
movl $0x188, %edi            # imm = 0x188
callq 0x4400
movq %rax, %r15
movq %rbx, 0x10(%rsp)
movq %rax, 0x8(%rbx)
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa6ed
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movl %ebp, 0x34(%rsp)
movl %ebp, 0x18(%r15)
xorl %ebx, %ebx
movl %ebx, 0x1c(%r15)
movb $0x1, 0x20(%r15)
leaq 0x24(%r15), %rsi
leaq 0x1df81(%rip), %r13     # 0x38dd0
movss 0x1c24d(%rip), %xmm0    # 0x370a4
movq %r13, %rdi
callq 0x2fac5
leaq 0x54(%r15), %rsi
movq %r13, %rdi
movss 0x1c236(%rip), %xmm0    # 0x370a4
callq 0x2fac5
movss (%rsp), %xmm1
movss %xmm1, 0x84(%r15)
movss 0x4(%rsp), %xmm0
movss %xmm0, 0x88(%r15)
movl %ebx, 0x8c(%r15)
movss %xmm1, 0x90(%r15)
movss %xmm0, 0x94(%r15)
leaq 0x9c(%r15), %rsi
movsd 0x1fc38(%rip), %xmm0    # 0x3aaf0
movups %xmm0, 0x98(%r15)
movss (%r12), %xmm0
movss %xmm0, 0xa8(%r15)
movsd 0x1fd29(%rip), %xmm0    # 0x3ac00
movsd %xmm0, 0xb0(%r15)
movl $0x80000000, %eax       # imm = 0x80000000
movl %eax, 0xb8(%r15)
movss 0x8(%r12), %xmm0
movaps 0x1c186(%rip), %xmm1    # 0x37080
xorps %xmm1, %xmm0
movss %xmm0, 0xbc(%r15)
movsd 0x1fbe2(%rip), %xmm0    # 0x3aaf0
movsd %xmm0, 0xc4(%r15)
movl %ebx, 0xcc(%r15)
movss 0x4(%r12), %xmm0
movss %xmm0, 0xd0(%r15)
movsd 0x1fcda(%rip), %xmm0    # 0x3ac10
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 0x172c1
movq 0x140(%r15), %rdi
movq 0x160(%r15), %rax
cmpl %ebx, 0x8(%rdi)
je 0x1afe2
cmpl $0x0, 0x8(%rax)
je 0x1afe7
movl 0x17c(%r15), %eax
testl %eax, %eax
movss 0x4(%rsp), %xmm3
movss (%rsp), %xmm4
jle 0x1b035
movq 0x180(%r15), %rcx
movq %rcx, %rdx
movl 0x8(%rdx), %esi
cmpl 0x18(%r15), %esi
jne 0x1afc7
movb $0x1, 0xc(%rdx)
movq 0x180(%r15), %rcx
movl 0x17c(%r15), %eax
addq $0xa8, %rdx
movslq %eax, %rsi
imulq $0xa8, %rsi, %rsi
addq %rcx, %rsi
cmpq %rsi, %rdx
jb 0x1afac
jmp 0x1b035
testq %rax, %rax
je 0x1affc
movq (%rax), %rcx
movq %rax, %rdi
callq *0x8(%rcx)
movq 0x140(%r15), %rdi
testq %rdi, %rdi
je 0x1b002
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x180(%r15), %rdi
callq 0x4370
movq %r15, %rdi
callq 0x4370
movq 0x10(%rsp), %rax
movq $0x0, 0x8(%rax)
movl $0x0, 0x4(%rax)
movss 0x4(%rsp), %xmm3
movss (%rsp), %xmm4
movq %r14, 0x40(%rsp)
movsd 0x1f5fe(%rip), %xmm6    # 0x3a640
movaps 0x1f2f7(%rip), %xmm5    # 0x3a340
movsd 0x1f5a7(%rip), %xmm7    # 0x3a5f8
movq 0x10(%rsp), %r15
movq 0x8(%r15), %r13
testq %r13, %r13
je 0x1baa2
xorl %eax, %eax
movq %r13, %rcx
movslq 0x17c(%rcx), %rsi
testq %rsi, %rsi
jle 0x1b14d
movq 0x180(%rcx), %rdx
imulq $0xa8, %rsi, %rsi
addq %rdx, %rsi
cmpb $0x0, 0xc(%rdx)
jne 0x1b10c
testb $0x1, %al
je 0x1b104
xorps %xmm0, %xmm0
cvtss2sd 0x40(%rdx), %xmm0
ucomisd %xmm0, %xmm6
seta %dil
xorps %xmm1, %xmm1
cvtss2sd 0x40(%r14), %xmm1
ucomisd %xmm1, %xmm6
seta %r8b
cmpb %r8b, %dil
je 0x1b0c7
ucomisd %xmm0, %xmm6
jbe 0x1b10c
ucomisd %xmm1, %xmm6
jbe 0x1b104
jmp 0x1b10c
movb 0x34(%rdx), %r8b
movb 0x34(%r14), %dil
cmpb %dil, %r8b
jne 0x1b0fa
movss 0x38(%rdx), %xmm0
movss 0x38(%r14), %xmm1
movaps %xmm0, %xmm2
subss %xmm1, %xmm2
andps %xmm5, %xmm2
cvtss2sd %xmm2, %xmm2
ucomisd %xmm7, %xmm2
jbe 0x1b11e
ucomiss %xmm0, %xmm1
ja 0x1b104
jmp 0x1b10c
testb %r8b, %r8b
je 0x1b10c
testb %dil, %dil
jne 0x1b10c
movb $0x1, %al
movq %rcx, %rbx
movq %rdx, %r14
addq $0xa8, %rdx
cmpq %rsi, %rdx
jb 0x1b089
jmp 0x1b14d
movss 0x3c(%rdx), %xmm0
movss 0x3c(%r14), %xmm1
movaps %xmm0, %xmm2
subss %xmm1, %xmm2
andps %xmm5, %xmm2
cvtss2sd %xmm2, %xmm2
ucomisd %xmm7, %xmm2
jbe 0x1b144
ucomiss %xmm1, %xmm0
ja 0x1b104
jmp 0x1b10c
movl (%rdx), %edi
cmpl (%r14), %edi
jl 0x1b104
jmp 0x1b10c
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x1b068
testb $0x1, %al
je 0x1b73c
movl $0x188, %edi            # imm = 0x188
callq 0x4400
movq %rax, %r12
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa6ed
movq $0x0, (%r12)
movq %rbx, 0x8(%r12)
movq %r14, 0x10(%r12)
movl 0x8(%r14), %eax
movl %eax, 0x18(%r12)
movss 0x40(%r14), %xmm0
movss %xmm0, 0x1c(%r12)
movb 0x34(%r14), %al
movb %al, 0x20(%r12)
leaq 0x48(%r14), %rdi
leaq 0x24(%rbx), %rsi
leaq 0x24(%r12), %r15
movq %r15, %rdx
callq 0x2fa0b
leaq 0x54(%rbx), %rdi
leaq 0x78(%r14), %rsi
leaq 0x54(%r12), %rbp
movq %rbp, %rdx
callq 0x2fa0b
movss 0x84(%rbx), %xmm0
leaq 0x84(%r12), %rsi
movss %xmm0, 0x84(%r12)
movss 0x88(%rbx), %xmm0
movss %xmm0, 0x88(%r12)
movss 0x8c(%rbx), %xmm0
movss %xmm0, 0x8c(%r12)
leaq 0x90(%r12), %rdx
movq %r15, %rdi
callq 0x2f8b3
movl $0x9c, %eax
leaq (%rbx,%rax), %rsi
leaq (%r12,%rax), %rdi
movl $0x14, %ecx
rep  movsl (%rsi), %es:(%rdi)
movq %r12, 0x18(%rsp)
leaq 0xf8(%r12), %r15
movl $0x4, %r13d
leaq -0x5c(%r15), %rsi
movss -0x50(%r15), %xmm0
leaq -0xc(%r15), %rdx
movq %rbp, %rdi
movq %r15, %rcx
callq 0x2f951
movsd -0xc(%r15), %xmm2
movaps %xmm2, %xmm0
mulps %xmm2, %xmm0
cvtps2pd %xmm0, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movss -0x4(%r15), %xmm1
movaps %xmm1, %xmm0
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm3, %xmm0
sqrtsd %xmm0, %xmm0
ucomisd 0x1f3ca(%rip), %xmm0    # 0x3a670
jne 0x1b2ae
jnp 0x1b4cf
cvtps2pd %xmm2, %xmm2
movsd 0x1eeaf(%rip), %xmm3    # 0x3a168
divsd %xmm0, %xmm3
cvtss2sd %xmm1, %xmm1
mulsd %xmm3, %xmm1
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd %xmm2, %xmm3
cvtpd2ps %xmm3, %xmm2
cvtsd2ss %xmm1, %xmm1
movlpd %xmm2, -0xc(%r15)
movss %xmm1, -0x4(%r15)
xorps %xmm1, %xmm1
cvtss2sd (%r15), %xmm1
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, (%r15)
addq $0x14, %r15
decq %r13
jne 0x1b251
movq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x172c1
movq 0x140(%r12), %rdi
movq 0x160(%r12), %rax
movl 0x8(%rdi), %ecx
testq %rcx, %rcx
movl $0x0, %ebp
je 0x1b4f3
cmpl $0x0, 0x8(%rax)
movq 0x10(%rsp), %r15
je 0x1b4fd
shlq $0x2, %rcx
leaq (%rcx,%rcx,4), %rdi
callq 0x4400
movq %rax, %r13
xorl %edi, %edi
testq %rax, %rax
setne %dil
movl $0x1, %esi
callq 0xa6ed
movq 0x140(%r12), %rcx
movl 0x8(%rcx), %eax
testl %eax, %eax
je 0x1b567
movsd 0x14c(%r12), %xmm0
movss 0x148(%r12), %xmm1
movq 0x10(%rcx), %rcx
movaps %xmm1, %xmm2
shufps $0xd4, %xmm0, %xmm2     # xmm2 = xmm2[0,1],xmm0[1,3]
shufps $0xe2, %xmm0, %xmm2     # xmm2 = xmm2[2,0],xmm0[2,3]
negl %eax
xorl %r12d, %r12d
movl $0x1, %edx
movsd 0x1bd6a(%rip), %xmm7    # 0x37118
leal -0x1(%rdx), %esi
movl %eax, %edi
addl %edx, %edi
movl %edx, %edi
cmovel %ebp, %edi
leaq (%rdi,%rdi,2), %r8
movss (%rcx,%r8,4), %xmm3
movslq %esi, %rsi
leaq (%rsi,%rsi,2), %rdi
subss (%rcx,%rdi,4), %xmm3
movslq %r12d, %rsi
leaq (%rsi,%rsi,4), %r9
leaq (%r13,%r9,4), %rsi
movsd 0x4(%rcx,%r8,4), %xmm4
movsd 0x4(%rcx,%rdi,4), %xmm5
subps %xmm5, %xmm4
movaps %xmm3, %xmm5
shufps $0xd4, %xmm4, %xmm5     # xmm5 = xmm5[0,1],xmm4[1,3]
shufps $0x52, %xmm4, %xmm5     # xmm5 = xmm5[2,0],xmm4[1,1]
mulps %xmm0, %xmm5
movaps %xmm1, %xmm6
mulss %xmm4, %xmm6
mulps %xmm2, %xmm4
subps %xmm5, %xmm4
movlps %xmm4, (%r13,%r9,4)
mulss %xmm0, %xmm3
subss %xmm6, %xmm3
movss %xmm3, 0x8(%r13,%r9,4)
movaps %xmm4, %xmm5
mulps %xmm4, %xmm5
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
movaps %xmm4, %xmm6
mulss %xmm4, %xmm6
addss %xmm5, %xmm6
movaps %xmm3, %xmm5
mulss %xmm3, %xmm5
addss %xmm6, %xmm5
cvtss2sd %xmm5, %xmm5
sqrtsd %xmm5, %xmm5
ucomisd %xmm5, %xmm7
jbe 0x1b45a
movl $0x0, 0x8(%rsi)
movq $0x0, (%rsi)
jmp 0x1b4ba
cvtps2pd %xmm4, %xmm4
cvtss2sd %xmm3, %xmm3
divsd %xmm5, %xmm3
cvtsd2ss %xmm3, %xmm3
xorps %xmm6, %xmm6
cvtsd2ss %xmm5, %xmm6
unpcklpd %xmm5, %xmm5            # xmm5 = xmm5[0,0]
divpd %xmm5, %xmm4
cvtpd2ps %xmm4, %xmm4
movss %xmm3, 0x8(%rsi)
movlpd %xmm4, (%rsi)
ucomiss 0x1bc24(%rip), %xmm6    # 0x370b0
jne 0x1b490
jnp 0x1b4ba
leaq (%rcx,%rdi,4), %rdi
movapd %xmm4, %xmm5
shufps $0x55, %xmm4, %xmm5     # xmm5 = xmm5[1,1],xmm4[1,1]
mulss 0x4(%rdi), %xmm5
mulss (%rdi), %xmm4
mulss 0x8(%rdi), %xmm3
addss %xmm5, %xmm4
addss %xmm4, %xmm3
movss %xmm3, 0xc(%rsi)
incl %r12d
leal (%rax,%rdx), %esi
incl %esi
incl %edx
cmpl $0x1, %esi
jne 0x1b3ae
jmp 0x1b56a
movq 0x18(%rsp), %r12
movl 0x18(%r12), %edx
movl $0x6, %edi
leaq 0x1ff06(%rip), %rsi     # 0x3b3eb
xorl %eax, %eax
callq 0xa446
movq 0x10(%rsp), %r15
jmp 0x1b526
testq %rax, %rax
movq 0x10(%rsp), %r15
je 0x1b513
movq (%rax), %rcx
movq %rax, %rdi
callq *0x8(%rcx)
movq 0x140(%r12), %rdi
testq %rdi, %rdi
je 0x1b519
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x180(%r12), %rdi
callq 0x4370
movq %r12, %rdi
callq 0x4370
movb $0x1, 0xc(%r14)
movl 0x4(%r15), %eax
movss 0x4(%rsp), %xmm3
movss (%rsp), %xmm4
movaps 0x1edf7(%rip), %xmm5    # 0x3a340
movsd 0x1f0ef(%rip), %xmm6    # 0x3a640
movsd 0x1f09f(%rip), %xmm7    # 0x3a5f8
cmpl (%r15), %eax
jl 0x1b056
jmp 0x1b738
xorl %r12d, %r12d
movq %r13, 0x20(%rsp)
movq 0x8(%r15), %r13
testq %r13, %r13
je 0x1b637
movl %r12d, %eax
movq %rax, 0x28(%rsp)
movl %r12d, 0xc(%rsp)
movl $0x20, %edi
callq 0x42e0
movq %rax, %r15
movq 0x140(%r13), %rsi
movq %rax, %rdi
callq 0xc1f2
testl %r12d, %r12d
jle 0x1b5d9
movq 0x20(%rsp), %rbp
movq 0x28(%rsp), %r12
cmpl $0x0, 0x8(%r15)
je 0x1b5e4
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movss 0x1f46d(%rip), %xmm0    # 0x3aa38
callq 0xcf28
addq $0x14, %rbp
decq %r12
jne 0x1b5b4
cmpl $0x0, 0x8(%r15)
setne %bpl
jmp 0x1b5e6
xorl %ebp, %ebp
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movq (%r13), %r13
testq %r13, %r13
movl 0xc(%rsp), %r12d
je 0x1b602
testb %bpl, %bpl
je 0x1b589
movq 0x20(%rsp), %rdi
callq 0x4370
testb %bpl, %bpl
movq 0x10(%rsp), %r15
je 0x1b641
movq 0x18(%rsp), %r12
movq 0x160(%r12), %rdi
testq %rdi, %rdi
je 0x1b506
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x1b506
movq 0x20(%rsp), %rdi
callq 0x4370
movb $0x1, 0xc(%r14)
movl 0x4(%r15), %eax
movq 0x18(%rsp), %r9
testq %r9, %r9
movss 0x4(%rsp), %xmm3
movss (%rsp), %xmm4
movaps 0x1ecdc(%rip), %xmm5    # 0x3a340
movsd 0x1efd4(%rip), %xmm6    # 0x3a640
movsd 0x1ef84(%rip), %xmm7    # 0x3a5f8
je 0x1b559
movq 0x8(%r15), %rcx
movq %rcx, (%r9)
movq %r9, 0x8(%r15)
incl %eax
movl %eax, 0x4(%r15)
movl 0x17c(%r9), %edx
movq %r9, %rcx
testl %edx, %edx
jle 0x1b6d8
movq 0x180(%r9), %rsi
movq %rsi, %rdi
movl 0x8(%rdi), %r8d
cmpl 0x18(%rcx), %r8d
jne 0x1b6bf
movb $0x1, 0xc(%rdi)
movq 0x180(%r9), %rsi
movl 0x17c(%r9), %edx
addq $0xa8, %rdi
movslq %edx, %r8
imulq $0xa8, %r8, %r8
addq %rsi, %r8
cmpq %r8, %rdi
jb 0x1b6a3
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x1b695
movq %r9, %rcx
movl 0x17c(%rcx), %edx
testl %edx, %edx
jle 0x1b72b
movq 0x180(%rcx), %rsi
movq %rsi, %rdi
movl 0x8(%rdi), %r8d
cmpl 0x18(%r9), %r8d
jne 0x1b712
movb $0x1, 0xc(%rdi)
movq 0x180(%rcx), %rsi
movl 0x17c(%rcx), %edx
addq $0xa8, %rdi
movslq %edx, %r8
imulq $0xa8, %r8, %r8
addq %rsi, %r8
cmpq %r8, %rdi
jb 0x1b6f7
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x1b6e3
jmp 0x1b559
movq 0x8(%r15), %r13
testq %r13, %r13
je 0x1baa2
leaq 0x60(%rsp), %rbx
leaq 0xa8(%rsp), %r15
leaq 0xd8(%rsp), %r12
leaq 0x84(%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 0xb(%rsp), %rax
pushq %rax
pushq %rbx
callq 0x30c13
addq $0x10, %rsp
testb %al, %al
je 0x1b7fd
movb 0xb(%rsp), %al
testb $0x1, %r14b
movss 0x4(%rsp), %xmm3
movss (%rsp), %xmm4
movaps 0x1eb80(%rip), %xmm2    # 0x3a340
movss 0xc(%rsp), %xmm5
je 0x1b81a
movb 0x20(%rsp), %cl
andb $0x1, %cl
cmpb %cl, %al
jne 0x1b810
movss 0x60(%rsp), %xmm0
movaps %xmm0, %xmm1
subss %xmm5, %xmm1
andps %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd 0x1ede9(%rip), %xmm1    # 0x3a5d8
jbe 0x1b87f
ucomiss %xmm0, %xmm5
seta %cl
jmp 0x1b815
movss 0x4(%rsp), %xmm3
movss (%rsp), %xmm4
movss 0xc(%rsp), %xmm5
jmp 0x1b86a
movl %eax, %ecx
xorb $0x1, %cl
testb $0x1, %cl
je 0x1b86a
movsd 0xa8(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
movss 0xb0(%rsp), %xmm0
movss %xmm0, 0x18(%rsp)
movss 0xd8(%rsp), %xmm0
movss %xmm0, 0x38(%rsp)
movss 0x84(%rsp), %xmm0
movss %xmm0, 0x3c(%rsp)
movb $0x1, %r14b
movss 0x60(%rsp), %xmm5
movb %al, 0x20(%rsp)
movq %r13, 0x28(%rsp)
movss %xmm5, 0xc(%rsp)
movq (%r13), %r13
testq %r13, %r13
jne 0x1b765
jmp 0x1b8b3
movb 0x20(%r13), %dl
movq 0x28(%rsp), %rsi
movb 0x20(%rsi), %cl
cmpb %cl, %dl
jne 0x1b89e
movl 0x18(%r13), %ecx
cmpl 0x18(%rsi), %ecx
setl %cl
jmp 0x1b815
xorb $0x1, %cl
movzbl %cl, %ecx
testb %dl, %dl
movl $0x0, %edx
cmovel %edx, %ecx
jmp 0x1b815
testb $0x1, %r14b
movq 0x10(%rsp), %r15
je 0x1baa2
movq 0x28(%rsp), %r12
movl 0x18(%r12), %edi
leaq 0xa8(%rsp), %r14
movq %r14, %rsi
callq 0x2fb8e
leaq 0xd8(%rsp), %rsi
movq %r14, %rdi
callq 0x2fc2c
testb %al, %al
jne 0x1b9c8
movl 0x18(%r12), %r15d
callq 0xb321
leaq 0x1fac7(%rip), %rdi     # 0x3b3cc
movl %r15d, %esi
xorl %eax, %eax
callq 0x9c46
movl $0x20, %edi
callq 0x42e0
movq %rax, %r14
leaq (%r15,%r15,4), %rsi
shlq $0x2, %rsi
addq 0x2b6bd(%rip), %rsi     # 0x46fe8
movss 0x1f101(%rip), %xmm0    # 0x3aa34
movq %rax, %rdi
callq 0xc54a
cmpl $0x0, 0x8(%r14)
je 0x1b9a1
leaq (%r15,%r15,2), %rax
shlq $0x2, %rax
addq 0x2b627(%rip), %rax     # 0x46f78
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 0x1b955
movq %r14, %rdi
callq 0xb6ac
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
callq 0xb332
xorl %edi, %edi
movl $0x1e, %esi
callq 0xa6ed
movq 0x10(%rsp), %r15
movb 0x20(%rsp), %bl
andb $0x1, %bl
leaq 0x84(%rsp), %rsi
movss 0x38(%rsp), %xmm0
movss %xmm0, (%rsi)
movss 0x3c(%rsp), %xmm0
movss %xmm0, 0x4(%rsi)
movl $0x0, 0x8(%rsi)
leaq 0xd8(%rsp), %rdi
leaq 0x60(%rsp), %r14
movq %r14, %rdx
callq 0x2f8b3
movsd (%r14), %xmm0
movq 0x40(%rsp), %rdx
movsd %xmm0, (%rdx)
movss 0x8(%r14), %xmm1
movss %xmm1, 0x8(%rdx)
movslq 0x18(%r12), %rax
leaq (%rax,%rax,2), %rax
leaq 0x541bfbf(%rip), %rcx   # 0x54379f0
movss (%rcx,%rax,4), %xmm2
addss %xmm0, %xmm2
movss %xmm2, (%rdx)
movslq 0x18(%r12), %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(%rdx)
movslq 0x18(%r12), %rax
leaq (%rax,%rax,2), %rax
addss 0x8(%rcx,%rax,4), %xmm1
movss %xmm1, 0x8(%rdx)
movq 0x48(%rsp), %rax
movaps 0x90(%rsp), %xmm0
movlps %xmm0, (%rax)
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x8(%rax)
movl 0x18(%r12), %eax
movq 0x50(%rsp), %rcx
movl %eax, (%rcx)
movq 0x58(%rsp), %rax
movb %bl, (%rax)
movl $0x3, %ebp
jmp 0x1bbaf
movq 0x70(%rsp), %rsi
movslq 0x135c(%rsi), %rax
xorl %ecx, %ecx
movq 0x40(%rsp), %rdx
movss 0xf18(%rsi,%rcx,4), %xmm0
mulss %xmm4, %xmm0
addss 0xef4(%rsi,%rcx,4), %xmm0
movss 0xf24(%rsi,%rcx,4), %xmm1
mulss %xmm3, %xmm1
addss %xmm0, %xmm1
movss %xmm1, (%rdx,%rcx,4)
incq %rcx
cmpq $0x3, %rcx
jne 0x1bab5
leaq (%rax,%rax,2), %rax
leaq 0x541befb(%rip), %rcx   # 0x54379f0
movss (%rdx), %xmm0
movss 0x4(%rdx), %xmm1
addss (%rcx,%rax,4), %xmm0
movss %xmm0, (%rdx)
addss 0x4(%rcx,%rax,4), %xmm1
movss %xmm1, 0x4(%rdx)
movss 0x8(%rdx), %xmm1
addss 0x8(%rcx,%rax,4), %xmm1
movss %xmm1, 0x8(%rdx)
cvtss2sd %xmm0, %xmm0
movq 0x78(%rsp), %rcx
xorps %xmm1, %xmm1
cvtss2sd (%rcx), %xmm1
movsd 0x1e7c6(%rip), %xmm2    # 0x3a300
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movq 0x48(%rsp), %rax
movss %xmm0, (%rax)
xorps %xmm0, %xmm0
cvtss2sd 0x4(%rdx), %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(%rdx), %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 0x34(%rsp), %ecx
movl %ecx, (%rax)
movq 0x58(%rsp), %rax
movb $0x1, (%rax)
xorl %ebp, %ebp
movq 0x8(%r15), %r14
testq %r14, %r14
je 0x1bbfb
movq (%r14), %rbx
movq 0x160(%r14), %rdi
testq %rdi, %rdi
je 0x1bbcd
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x140(%r14), %rdi
testq %rdi, %rdi
je 0x1bbdf
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x180(%r14), %rdi
callq 0x4370
movq %r14, %rdi
callq 0x4370
movq %rbx, %r14
testq %rbx, %rbx
jne 0x1bbb8
movq %r15, %rdi
callq 0x4370
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 0x1bc2f
movq %rax, %rbx
movl $0x20, %esi
movq %r15, %rdi
callq 0x42f0
movq %rbx, %rdi
callq 0x4580