// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/hlrad/lerp.cpp
// Function: CalcInterpolation(localtriangulation_t const*, float const*, interpolation_t*)
static void CalcInterpolation (const localtriangulation_t *lt, const vec3_t spot, interpolation_t *interp)
	// The interpolation function is defined over the entire plane, so CalcInterpolation never fails.
{
	vec3_t direction;
	const localtriangulation_t::Wedge *w;
	const localtriangulation_t::Wedge *wnext;

	int i;
	int j;
	vec_t angle;
	std::vector< vec_t > angles;

	if (GetDirection (spot, lt->normal, direction) <= 2 * ON_EPSILON)
	{
		// spot happens to be at the center
		interp->isbiased = false;
		interp->totalweight = 1.0;
		interp->points.resize (1);
		interp->points[0].patchnum = lt->patchnum;
		interp->points[0].weight = 1.0;
		return;
	}

	if ((int)lt->sortedwedges.size () == 0) // this local triangulation only has center patch
	{
		interp->isbiased = true;
		interp->totalweight = 1.0;
		interp->points.resize (1);
		interp->points[0].patchnum = lt->patchnum;
		interp->points[0].weight = 1.0;
		return;
	}
	
	// Find the wedge with minimum non-negative angle (counterclockwise) pass the spot
	angles.resize ((int)lt->sortedwedges.size ());
	for (i = 0; i < (int)lt->sortedwedges.size (); i++)
	{
		angle = GetAngle (lt->sortedwedges[i].leftdirection, direction, lt->normal);
		angles[i] = GetAngleDiff (angle, 0);
	}
	j = 0;
	for (i = 1; i < (int)lt->sortedwedges.size (); i++)
	{
		if (angles[i] < angles[j])
		{
			j = i;
		}
	}
	w = &lt->sortedwedges[j];
	wnext = &lt->sortedwedges[(j + 1) % (int)lt->sortedwedges.size ()];

	// Different wedge types have different interpolation methods
	switch (w->shape)
	{
#ifdef HLRAD_BILINEARINTERPOLATION
	case localtriangulation_t::Wedge::eSquareLeft:
	case localtriangulation_t::Wedge::eSquareRight:
#endif
	case localtriangulation_t::Wedge::eTriangular:
		// w->wedgenormal is undefined
		{
			vec_t frac;
			vec_t len;
			vec_t dist;
			bool istoofar;
			vec_t ratio;

			frac = GetFrac (w->leftspot, wnext->leftspot, direction, lt->normal);
			
			len = (1 - frac) * DotProduct (w->leftspot, direction) + frac * DotProduct (wnext->leftspot, direction);
			dist = DotProduct (spot, direction);
			if (len <= ON_EPSILON / 4 || dist > len + 2 * ON_EPSILON)
			{
				istoofar = true;
				ratio = 1.0;
			}
			else if (dist >= len - ON_EPSILON)
			{
				istoofar = false;
				ratio = 1.0;
			}
			else
			{
				istoofar = false;
				ratio = dist / len;
				ratio = qmax (0, qmin (ratio, 1));
			}

			if (istoofar)
			{
				interp->isbiased = true;
				interp->totalweight = 1.0;
				interp->points.resize (2);
				interp->points[0].patchnum = w->leftpatchnum;
				interp->points[0].weight = 1 - frac;
				interp->points[1].patchnum = wnext->leftpatchnum;
				interp->points[1].weight = frac;
			}
#ifdef HLRAD_BILINEARINTERPOLATION
			else if (w->shape == localtriangulation_t::Wedge::eSquareLeft)
			{
				i = w - &lt->sortedwedges[0];
				CalcInterpolation_Square (lt, i, spot, interp);
			}
			else if (w->shape == localtriangulation_t::Wedge::eSquareRight)
			{
				i = w - &lt->sortedwedges[0];
				i = (i - 1 + (int)lt->sortedwedges.size ()) % (int)lt->sortedwedges.size ();
				CalcInterpolation_Square (lt, i, spot, interp);
			}
#endif
			else
			{
				interp->isbiased = false;
				interp->totalweight = 1.0;
				interp->points.resize (3);
				interp->points[0].patchnum = lt->patchnum;
				interp->points[0].weight = 1 - ratio;
				interp->points[1].patchnum = w->leftpatchnum;
				interp->points[1].weight = ratio * (1 - frac);
				interp->points[2].patchnum = wnext->leftpatchnum;
				interp->points[2].weight = ratio * frac;
			}
		}
		break;
	case localtriangulation_t::Wedge::eConvex:
		// w->wedgenormal is the unit vector pointing from w->leftspot to wnext->leftspot
		{
			vec_t dot;
			vec_t dot1;
			vec_t dot2;
			vec_t frac;

			dot1 = DotProduct (w->leftspot, w->wedgenormal) - DotProduct (spot, w->wedgenormal);
			dot2 = DotProduct (wnext->leftspot, w->wedgenormal) - DotProduct (spot, w->wedgenormal);
			dot = 0 - DotProduct (spot, w->wedgenormal);
			// for eConvex type: dot1 < dot < dot2

			if (g_drawlerp && (dot1 > dot || dot > dot2))
			{
				Developer (DEVELOPER_LEVEL_SPAM, "Debug: triangulation: internal error 3.\n");
			}
			if (dot1 >= -NORMAL_EPSILON) // 0 <= dot1 < dot < dot2
			{
				interp->isbiased = true;
				interp->totalweight = 1.0;
				interp->points.resize (1);
				interp->points[0].patchnum = w->leftpatchnum;
				interp->points[0].weight = 1.0;
			}
			else if (dot2 <= NORMAL_EPSILON) // dot1 < dot < dot2 <= 0
			{
				interp->isbiased = true;
				interp->totalweight = 1.0;
				interp->points.resize (1);
				interp->points[0].patchnum = wnext->leftpatchnum;
				interp->points[0].weight = 1.0;
			}
			else if (dot > 0) // dot1 < 0 < dot < dot2
			{
				frac = dot1 / (dot1 - dot);
				frac = qmax (0, qmin (frac, 1));

				interp->isbiased = true;
				interp->totalweight = 1.0;
				interp->points.resize (2);
				interp->points[0].patchnum = w->leftpatchnum;
				interp->points[0].weight = 1 - frac;
				interp->points[1].patchnum = lt->patchnum;
				interp->points[1].weight = frac;
			}
			else // dot1 < dot <= 0 < dot2
			{
				frac = dot / (dot - dot2);
				frac = qmax (0, qmin (frac, 1));
			
				interp->isbiased = true;
				interp->totalweight = 1.0;
				interp->points.resize (2);
				interp->points[0].patchnum = lt->patchnum;
				interp->points[0].weight = 1 - frac;
				interp->points[1].patchnum = wnext->leftpatchnum;
				interp->points[1].weight = frac;
			}
		}
		break;
	case localtriangulation_t::Wedge::eConcave:
		{
			vec_t len;
			vec_t dist;
			vec_t ratio;

			if (DotProduct (spot, w->wedgenormal) < 0) // the spot is closer to the left edge than the right edge
			{
				len = DotProduct (w->leftspot, w->leftdirection);
				dist = DotProduct (spot, w->leftdirection);
				if (g_drawlerp && len <= ON_EPSILON)
				{
					Developer (DEVELOPER_LEVEL_SPAM, "Debug: triangulation: internal error 4.\n");
				}
				if (dist <= NORMAL_EPSILON)
				{
					interp->isbiased = true;
					interp->totalweight = 1.0;
					interp->points.resize (1);
					interp->points[0].patchnum = lt->patchnum;
					interp->points[0].weight = 1.0;
				}
				else if (dist >= len)
				{
					interp->isbiased = true;
					interp->totalweight = 1.0;
					interp->points.resize (1);
					interp->points[0].patchnum = w->leftpatchnum;
					interp->points[0].weight = 1.0;
				}
				else
				{
					ratio = dist / len;
					ratio = qmax (0, qmin (ratio, 1));

					interp->isbiased = true;
					interp->totalweight = 1.0;
					interp->points.resize (2);
					interp->points[0].patchnum = lt->patchnum;
					interp->points[0].weight = 1 - ratio;
					interp->points[1].patchnum = w->leftpatchnum;
					interp->points[1].weight = ratio;
				}
			}
			else // the spot is closer to the right edge than the left edge
			{
				len = DotProduct (wnext->leftspot, wnext->leftdirection);
				dist = DotProduct (spot, wnext->leftdirection);
				if (g_drawlerp && len <= ON_EPSILON)
				{
					Developer (DEVELOPER_LEVEL_SPAM, "Debug: triangulation: internal error 5.\n");
				}
				if (dist <= NORMAL_EPSILON)
				{
					interp->isbiased = true;
					interp->totalweight = 1.0;
					interp->points.resize (1);
					interp->points[0].patchnum = lt->patchnum;
					interp->points[0].weight = 1.0;
				}
				else if (dist >= len)
				{
					interp->isbiased = true;
					interp->totalweight = 1.0;
					interp->points.resize (1);
					interp->points[0].patchnum = wnext->leftpatchnum;
					interp->points[0].weight = 1.0;
				}
				else
				{
					ratio = dist / len;
					ratio = qmax (0, qmin (ratio, 1));

					interp->isbiased = true;
					interp->totalweight = 1.0;
					interp->points.resize (2);
					interp->points[0].patchnum = lt->patchnum;
					interp->points[0].weight = 1 - ratio;
					interp->points[1].patchnum = wnext->leftpatchnum;
					interp->points[1].weight = ratio;
				}
			}
		}
		break;
	default:
		Error ("CalcInterpolation: internal error: invalid wedge type.");
		break;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
leaq 0x44(%rdi), %r12
leaq 0x34(%rsp), %rdx
movq %rsi, %rdi
movq %r12, %rsi
callq 0x12521
cvtss2sd %xmm0, %xmm0
movsd 0x2ba7d(%rip), %xmm1    # 0x3a5d8
ucomisd %xmm0, %xmm1
jae 0xec7b
movq 0x78(%r14), %rax
subq 0x70(%r14), %rax
sarq $0x2, %rax
movabsq $0x2e8ba2e8ba2e8ba3, %rbp # imm = 0x2E8BA2E8BA2E8BA3
imulq %rbp, %rax
testl %eax, %eax
je 0xec98
movslq %eax, %rsi
leaq 0x40(%rsp), %rdi
callq 0x1392a
movq 0x70(%r14), %rdi
movq 0x78(%r14), %rax
subq %rdi, %rax
shrq $0x2, %rax
imull $0xba2e8ba3, %eax, %ecx # imm = 0xBA2E8BA3
testl %ecx, %ecx
jle 0xecf7
movq %r15, 0x18(%rsp)
movq %rbx, 0x8(%rsp)
movl $0x14, %r15d
xorl %ebx, %ebx
leaq 0x34(%rsp), %r13
addq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x125f4
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
addsd 0x2b9fb(%rip), %xmm1    # 0x3a5e0
cvtsd2ss %xmm1, %xmm1
movaps %xmm0, %xmm2
cmpltss 0x284bb(%rip), %xmm2    # 0x370b0
movaps %xmm2, %xmm3
andnps %xmm0, %xmm3
andps %xmm1, %xmm2
orps %xmm3, %xmm2
movq 0x40(%rsp), %rax
movss %xmm2, (%rax,%rbx,4)
incq %rbx
movq 0x70(%r14), %rdi
movq 0x78(%r14), %rcx
subq %rdi, %rcx
sarq $0x2, %rcx
imulq %rbp, %rcx
movslq %ecx, %rax
addq $0x2c, %r15
cmpq %rax, %rbx
jl 0xebc8
cmpl $0x2, %ecx
jl 0xecfb
movq 0x40(%rsp), %rax
movl %ecx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
xorl %r9d, %r9d
movl $0x1, %r8d
movq 0x8(%rsp), %rbx
movq 0x18(%rsp), %r15
movslq %r9d, %rdx
movss (%rax,%rdx,4), %xmm0
ucomiss (%rax,%r8,4), %xmm0
movl %r8d, %edx
ja 0xec6b
movl %r9d, %edx
incq %r8
movl %edx, %r9d
cmpq %r8, %rsi
jne 0xec56
jmp 0xed07
movb $0x0, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
addq $0x8, %rbx
movl $0x1, %esi
movq %rbx, %rdi
callq 0x1398e
jmp 0xecb3
movb $0x1, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
addq $0x8, %rbx
movl $0x1, %esi
movq %rbx, %rdi
callq 0x1398e
movl 0x50(%r14), %eax
movq (%rbx), %rcx
movl %eax, (%rcx)
movss 0x283e0(%rip), %xmm1    # 0x370a4
movl $0x4, %eax
movq (%rbx), %rcx
movss %xmm1, (%rcx,%rax)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xece8
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x42f0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edx, %edx
jmp 0xed07
xorl %edx, %edx
movq 0x8(%rsp), %rbx
movq 0x18(%rsp), %r15
movslq %edx, %rax
imulq $0x2c, %rax, %r13
incl %eax
cltd
idivl %ecx
movl (%rdi,%r13), %eax
cmpq $0x4, %rax
ja 0xf169
addq %rdi, %r13
movslq %edx, %rcx
imulq $0x2c, %rcx, %rbp
addq %rdi, %rbp
leaq 0x2b9db(%rip), %rcx     # 0x3a710
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8(%r13), %rdi
leaq 0x8(%rbp), %rsi
leaq 0x34(%rsp), %rdx
movq %r12, %rcx
callq 0x12679
movss 0x28348(%rip), %xmm8    # 0x370a4
movaps %xmm8, %xmm7
subss %xmm0, %xmm7
movss 0x34(%rsp), %xmm2
movss 0x38(%rsp), %xmm3
movss 0xc(%r13), %xmm1
mulss %xmm3, %xmm1
movss 0x8(%r13), %xmm4
mulss %xmm2, %xmm4
addss %xmm1, %xmm4
movss 0x3c(%rsp), %xmm6
movss 0x10(%r13), %xmm1
mulss %xmm6, %xmm1
addss %xmm4, %xmm1
movss 0xc(%rbp), %xmm4
mulss %xmm3, %xmm4
movss 0x8(%rbp), %xmm5
mulss %xmm2, %xmm5
addss %xmm4, %xmm5
movss 0x10(%rbp), %xmm4
mulss %xmm6, %xmm4
addss %xmm5, %xmm4
mulss %xmm0, %xmm4
mulss %xmm7, %xmm1
addss %xmm4, %xmm1
xorps %xmm4, %xmm4
cvtss2sd %xmm1, %xmm4
movsd 0x2b80e(%rip), %xmm5    # 0x3a5e8
ucomisd %xmm4, %xmm5
jae 0xee16
mulss 0x4(%r15), %xmm3
mulss (%r15), %xmm2
addss %xmm3, %xmm2
mulss 0x8(%r15), %xmm6
addss %xmm2, %xmm6
xorps %xmm2, %xmm2
cvtss2sd %xmm6, %xmm2
movsd 0x2b7d0(%rip), %xmm3    # 0x3a5d8
addsd %xmm4, %xmm3
ucomisd %xmm3, %xmm2
jbe 0xf17c
movss %xmm7, 0x18(%rsp)
movb $0x1, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
addq $0x8, %rbx
movl $0x2, %esi
movq %rbx, %rdi
movss %xmm0, 0x8(%rsp)
callq 0x1398e
movss 0x8(%rsp), %xmm1
movl 0x4(%r13), %eax
movq (%rbx), %rcx
movl %eax, (%rcx)
movq (%rbx), %rax
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x4(%rax)
movl 0x4(%rbp), %eax
movq (%rbx), %rcx
movl %eax, 0x8(%rcx)
movl $0xc, %eax
jmp 0xecc9
movss (%r15), %xmm2
movss 0x4(%r15), %xmm1
movss 0x24(%r13), %xmm0
movss %xmm1, 0x14(%rsp)
mulss %xmm1, %xmm0
movss 0x20(%r13), %xmm1
movss %xmm2, 0x18(%rsp)
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x8(%r15), %xmm2
movss 0x28(%r13), %xmm0
movss %xmm2, 0x8(%rsp)
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
leaq 0x54eab7e(%rip), %rax   # 0x54f9a41
movb (%rax), %al
jbe 0xf1c9
movss 0x14(%r13), %xmm2
movss 0x18(%r13), %xmm1
movss 0xc(%r13), %xmm0
movss %xmm1, 0x2c(%rsp)
mulss %xmm1, %xmm0
movss 0x8(%r13), %xmm1
movss %xmm2, 0x30(%rsp)
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x1c(%r13), %xmm2
movss 0x10(%r13), %xmm0
movss %xmm2, 0x28(%rsp)
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x24(%rsp)
testb %al, %al
je 0xef49
xorps %xmm0, %xmm0
cvtss2sd 0x24(%rsp), %xmm0
movsd 0x2b6c8(%rip), %xmm1    # 0x3a5f8
ucomisd %xmm0, %xmm1
jb 0xef49
leaq 0x2b8d0(%rip), %rsi     # 0x3a80d
movl $0x5, %edi
xorl %eax, %eax
callq 0xa446
movss 0x14(%rsp), %xmm1
mulss 0x2c(%rsp), %xmm1
movss 0x18(%rsp), %xmm0
mulss 0x30(%rsp), %xmm0
addss %xmm1, %xmm0
movss 0x8(%rsp), %xmm2
mulss 0x28(%rsp), %xmm2
addss %xmm0, %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd 0x28194(%rip), %xmm1    # 0x37118
ucomisd %xmm0, %xmm1
jae 0xf30a
leaq 0x8(%rbx), %r15
movss %xmm2, 0x8(%rsp)
ucomiss 0x24(%rsp), %xmm2
movb $0x1, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
jae 0xf46d
movl $0x2, %esi
movq %r15, %rdi
callq 0x1398e
movss 0x8(%rsp), %xmm2
divss 0x24(%rsp), %xmm2
movss 0x280d6(%rip), %xmm0    # 0x370a4
minss %xmm0, %xmm2
xorpd %xmm1, %xmm1
maxss %xmm2, %xmm1
movl 0x50(%r14), %eax
movq (%r15), %rcx
movl %eax, (%rcx)
subss %xmm1, %xmm0
movq (%r15), %rax
movss %xmm0, 0x4(%rax)
movl 0x4(%r13), %eax
jmp 0xf460
movss 0x20(%r13), %xmm0
movss 0x24(%r13), %xmm1
movss 0xc(%r13), %xmm2
mulss %xmm1, %xmm2
movss 0x8(%r13), %xmm3
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x28(%r13), %xmm4
movss 0x10(%r13), %xmm5
mulss %xmm4, %xmm5
addss %xmm3, %xmm5
movss 0x4(%r15), %xmm2
mulss %xmm1, %xmm2
movss (%r15), %xmm3
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x8(%r15), %xmm2
mulss %xmm4, %xmm2
addss %xmm3, %xmm2
subss %xmm2, %xmm5
movss %xmm5, 0x8(%rsp)
mulss 0xc(%rbp), %xmm1
mulss 0x8(%rbp), %xmm0
mulss 0x10(%rbp), %xmm4
addss %xmm1, %xmm0
addss %xmm0, %xmm4
subss %xmm2, %xmm4
movss %xmm4, 0x14(%rsp)
xorps %xmm0, %xmm0
subss %xmm2, %xmm0
movss %xmm0, 0x18(%rsp)
leaq 0x54ea9ad(%rip), %rax   # 0x54f9a41
cmpb $0x1, (%rax)
jne 0xf0c6
movss 0x8(%rsp), %xmm0
ucomiss 0x18(%rsp), %xmm0
ja 0xf0b3
movss 0x18(%rsp), %xmm0
ucomiss 0x14(%rsp), %xmm0
jbe 0xf0c6
leaq 0x2b72a(%rip), %rsi     # 0x3a7e4
movl $0x5, %edi
xorl %eax, %eax
callq 0xa446
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
ucomisd 0x2b529(%rip), %xmm0    # 0x3a600
jae 0xf2c3
xorps %xmm0, %xmm0
cvtss2sd 0x14(%rsp), %xmm0
movsd 0x2802a(%rip), %xmm1    # 0x37118
ucomisd %xmm0, %xmm1
jae 0xf2e7
leaq 0x8(%rbx), %r15
xorps %xmm0, %xmm0
movss 0x18(%rsp), %xmm1
ucomiss %xmm0, %xmm1
movb $0x1, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
jbe 0xf414
movl $0x2, %esi
movq %r15, %rdi
callq 0x1398e
movss 0x8(%rsp), %xmm2
movaps %xmm2, %xmm0
subss 0x18(%rsp), %xmm0
divss %xmm0, %xmm2
movss 0x27f64(%rip), %xmm0    # 0x370a4
minss %xmm0, %xmm2
xorps %xmm1, %xmm1
maxss %xmm2, %xmm1
movl 0x4(%r13), %eax
movq (%r15), %rcx
movl %eax, (%rcx)
subss %xmm1, %xmm0
movq (%r15), %rax
movss %xmm0, 0x4(%rax)
movl 0x50(%r14), %eax
jmp 0xf460
leaq 0x2b6ef(%rip), %rdi     # 0x3a85f
xorl %eax, %eax
callq 0x9f34
jmp 0xecd1
addsd 0x2b46c(%rip), %xmm4    # 0x3a5f0
ucomisd %xmm4, %xmm2
jae 0xf19f
divss %xmm1, %xmm6
minss 0x27f0e(%rip), %xmm6    # 0x370a4
xorps %xmm8, %xmm8
maxss %xmm6, %xmm8
movl (%r13), %eax
cmpl $0x4, %eax
je 0xf34a
cmpl $0x3, %eax
jne 0xf38a
subq 0x70(%r14), %r13
shrq $0x2, %r13
imull $0xba2e8ba3, %r13d, %esi # imm = 0xBA2E8BA3
jmp 0xf377
movss 0x14(%rbp), %xmm2
movss 0x18(%rbp), %xmm1
movss 0xc(%rbp), %xmm0
movss %xmm1, 0x2c(%rsp)
mulss %xmm1, %xmm0
movss 0x8(%rbp), %xmm1
movss %xmm2, 0x30(%rsp)
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss 0x1c(%rbp), %xmm2
movss 0x10(%rbp), %xmm0
movss %xmm2, 0x28(%rsp)
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x24(%rsp)
testb %al, %al
je 0xf241
xorps %xmm0, %xmm0
cvtss2sd 0x24(%rsp), %xmm0
movsd 0x2b3d0(%rip), %xmm1    # 0x3a5f8
ucomisd %xmm0, %xmm1
jb 0xf241
leaq 0x2b601(%rip), %rsi     # 0x3a836
movl $0x5, %edi
xorl %eax, %eax
callq 0xa446
movss 0x14(%rsp), %xmm1
mulss 0x2c(%rsp), %xmm1
movss 0x18(%rsp), %xmm0
mulss 0x30(%rsp), %xmm0
addss %xmm1, %xmm0
movss 0x8(%rsp), %xmm2
mulss 0x28(%rsp), %xmm2
addss %xmm0, %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd 0x27e9c(%rip), %xmm1    # 0x37118
ucomisd %xmm0, %xmm1
jae 0xf32a
leaq 0x8(%rbx), %r15
movss %xmm2, 0x8(%rsp)
ucomiss 0x24(%rsp), %xmm2
movb $0x1, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
jae 0xf480
movl $0x2, %esi
movq %r15, %rdi
callq 0x1398e
movss 0x8(%rsp), %xmm2
divss 0x24(%rsp), %xmm2
jmp 0xf434
movb $0x1, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
addq $0x8, %rbx
movl $0x1, %esi
movq %rbx, %rdi
callq 0x1398e
movl 0x4(%r13), %eax
jmp 0xecb7
movb $0x1, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
addq $0x8, %rbx
movl $0x1, %esi
movq %rbx, %rdi
callq 0x1398e
movl 0x4(%rbp), %eax
jmp 0xecb7
movb $0x1, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
addq $0x8, %rbx
movl $0x1, %esi
movq %rbx, %rdi
callq 0x1398e
jmp 0xecb3
movb $0x1, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
addq $0x8, %rbx
movl $0x1, %esi
movq %rbx, %rdi
callq 0x1398e
jmp 0xecb3
movq 0x70(%r14), %rax
movq 0x78(%r14), %rcx
subq %rax, %r13
shrq $0x2, %r13
imull $0xba2e8ba3, %r13d, %edx # imm = 0xBA2E8BA3
subq %rax, %rcx
shrq $0x2, %rcx
imull $0xba2e8ba3, %ecx, %ecx # imm = 0xBA2E8BA3
leal (%rdx,%rcx), %eax
decl %eax
cltd
idivl %ecx
movl %edx, %esi
movq %r14, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x127a7
jmp 0xecd1
movss %xmm8, 0x14(%rsp)
movss %xmm7, 0x18(%rsp)
movb $0x0, (%rbx)
movl $0x3f800000, 0x4(%rbx)  # imm = 0x3F800000
addq $0x8, %rbx
movl $0x3, %esi
movq %rbx, %rdi
movss %xmm0, 0x8(%rsp)
callq 0x1398e
movss 0x8(%rsp), %xmm1
movl 0x50(%r14), %eax
movq (%rbx), %rcx
movl %eax, (%rcx)
movss 0x27cd5(%rip), %xmm0    # 0x370a4
movss 0x14(%rsp), %xmm2
subss %xmm2, %xmm0
movq (%rbx), %rax
movss %xmm0, 0x4(%rax)
movl 0x4(%r13), %eax
movq (%rbx), %rcx
movl %eax, 0x8(%rcx)
movss 0x18(%rsp), %xmm0
mulss %xmm2, %xmm0
movq (%rbx), %rax
movss %xmm0, 0xc(%rax)
movl 0x4(%rbp), %eax
movq (%rbx), %rcx
movl %eax, 0x10(%rcx)
mulss %xmm2, %xmm1
movl $0x14, %eax
jmp 0xecc9
movl $0x2, %esi
movq %r15, %rdi
callq 0x1398e
movss 0x18(%rsp), %xmm2
movaps %xmm2, %xmm0
subss 0x14(%rsp), %xmm0
divss %xmm0, %xmm2
movss 0x27c68(%rip), %xmm0    # 0x370a4
minss %xmm0, %xmm2
xorpd %xmm1, %xmm1
maxss %xmm2, %xmm1
movl 0x50(%r14), %eax
movq (%r15), %rcx
movl %eax, (%rcx)
subss %xmm1, %xmm0
movq (%r15), %rax
movss %xmm0, 0x4(%rax)
movl 0x4(%rbp), %eax
movq (%r15), %rcx
movl %eax, 0x8(%rcx)
movl $0xc, %eax
jmp 0xf4a2
movl $0x1, %esi
movq %r15, %rdi
callq 0x1398e
movl 0x4(%r13), %eax
jmp 0xf490
movl $0x1, %esi
movq %r15, %rdi
callq 0x1398e
movl 0x4(%rbp), %eax
movq (%r15), %rcx
movl %eax, (%rcx)
movss 0x27c07(%rip), %xmm1    # 0x370a4
movl $0x4, %eax
movq %r15, %rbx
jmp 0xecc9
jmp 0xf4b0
jmp 0xf4b0
jmp 0xf4b0
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xf4ca
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x42f0
movq %rbx, %rdi
callq 0x4580