// File: FreeSlave[P]vhlt/hlcsg/brush.cpp
// Function: ExpandBrushWithHullBrush(brush_s const*, brushhull_t const*, hullbrush_t const*, brushhull_t*)
void ExpandBrushWithHullBrush (const brush_t *brush, const brushhull_t *hull0, const hullbrush_t *hb, brushhull_t *hull)
{
	const hullbrushface_t *hbf;
	const hullbrushedge_t *hbe;
	const hullbrushvertex_t *hbv;
	bface_t *f;
	vec3_t normal;
	vec3_t origin;
	bool *axialbevel;
	bool warned;

	axialbevel = (bool *)malloc (hb->numfaces * sizeof (bool));
	memset (axialbevel, 0, hb->numfaces * sizeof (bool));
	warned = false;
	
	// check for collisions of face-vertex type. face-edge type is also permitted. face-face type is excluded.
	for (f = hull0->faces; f; f = f->next)
	{
		hullbrushface_t brushface;
		VectorCopy (f->plane->normal, brushface.normal);
		VectorCopy (f->plane->origin, brushface.point);

		// check for coplanar hull brush face
		for (hbf = hb->faces; hbf < hb->faces + hb->numfaces; hbf++)
		{
			if (-DotProduct (hbf->normal, brushface.normal) < 1 - ON_EPSILON)
			{
				continue;
			}
			// now test precisely
			vec_t dotmin;
			vec_t dotmax;
			dotmin = BOGUS_RANGE;
			dotmax = -BOGUS_RANGE;
			hlassume (hbf->numvertexes >= 1, assume_first);
			for (vec3_t *v = hbf->vertexes; v < hbf->vertexes + hbf->numvertexes; v++)
			{
				vec_t dot;
				dot = DotProduct (*v, brushface.normal);
				dotmin = qmin (dotmin, dot);
				dotmax = qmax (dotmax, dot);
			}
			if (dotmax - dotmin <= EQUAL_EPSILON)
			{
				break;
			}
		}
		if (hbf < hb->faces + hb->numfaces)
		{
			if (f->bevel)
			{
				axialbevel[hbf - hb->faces] = true;
			}
			continue; // the same plane will be added in the last stage
		}
		
		// find the impact point
		vec3_t bestvertex;
		vec_t bestdist;
		bestdist = BOGUS_RANGE;
		hlassume (hb->numvertexes >= 1, assume_first);
		for (hbv = hb->vertexes; hbv < hb->vertexes + hb->numvertexes; hbv++)
		{
			if (hbv == hb->vertexes || DotProduct (hbv->point, brushface.normal) < bestdist - NORMAL_EPSILON)
			{
				bestdist = DotProduct (hbv->point, brushface.normal);
				VectorCopy (hbv->point, bestvertex);
			}
		}

		// add hull plane for this face
		VectorCopy (brushface.normal, normal);
		if (f->bevel)
		{
			VectorCopy (brushface.point, origin);
		}
		else
		{
			VectorSubtract (brushface.point, bestvertex, origin);
		}
		AddHullPlane (hull, normal, origin, true);
	}

	// check for edge-edge type. edge-face type and face-edge type are excluded.
	for (f = hull0->faces; f; f = f->next)
	{
		for (int i = 0; i < f->w->m_NumPoints; i++) // for each edge in f
		{
			hullbrushedge_t brushedge;
			VectorCopy (f->plane->normal, brushedge.normals[0]);
			VectorCopy (f->w->m_Points[(i + 1) % f->w->m_NumPoints], brushedge.vertexes[0]);
			VectorCopy (f->w->m_Points[i], brushedge.vertexes[1]);
			VectorCopy (brushedge.vertexes[0], brushedge.point);
			VectorSubtract (brushedge.vertexes[1], brushedge.vertexes[0], brushedge.delta);

			// fill brushedge.normals[1]
			int found;
			found = 0;
			for (bface_t *f2 = hull0->faces; f2; f2 = f2->next)
			{
				for (int j = 0; j < f2->w->m_NumPoints; j++)
				{
					if (VectorCompare (f2->w->m_Points[(j + 1) % f2->w->m_NumPoints], brushedge.vertexes[1]) &&
						VectorCompare (f2->w->m_Points[j], brushedge.vertexes[0]))
					{
						VectorCopy (f2->plane->normal, brushedge.normals[1]);
						found++;
					}
				}
			}
			if (found != 1)
			{
				if (!warned)
				{
					Warning("Illegal Brush (edge without opposite face): Entity %i, Brush %i\n",
#ifdef HLCSG_COUNT_NEW
						brush->originalentitynum, brush->originalbrushnum
#else
						brush->entitynum, brush->brushnum
#endif
						);
					warned = true;
				}
				continue;
			}

			// make sure the math is accurate
			vec_t len;
			len = VectorLength (brushedge.delta);
			CrossProduct (brushedge.normals[0], brushedge.normals[1], brushedge.delta);
			if (!VectorNormalize (brushedge.delta))
			{
				continue;
			}
			VectorScale (brushedge.delta, len, brushedge.delta);

			// check for each edge in the hullbrush
			for (hbe = hb->edges; hbe < hb->edges + hb->numedges; hbe++)
			{
				vec_t dot[4];
				dot[0] = DotProduct (hbe->delta, brushedge.normals[0]);
				dot[1] = DotProduct (hbe->delta, brushedge.normals[1]);
				dot[2] = DotProduct (brushedge.delta, hbe->normals[0]);
				dot[3] = DotProduct (brushedge.delta, hbe->normals[1]);
				if (dot[0] <= ON_EPSILON || dot[1] >= -ON_EPSILON || dot[2] <= ON_EPSILON || dot[3] >= -ON_EPSILON)
				{
					continue;
				}

				// in the outer loop, each edge in the brush will be iterated twice (once from f and once from the corresponding f2)
				// but since brushedge.delta are exactly the opposite between the two iterations
				// only one of them can reach here
				vec3_t e1;
				vec3_t e2;
				VectorCopy (brushedge.delta, e1);
				VectorNormalize (e1);
				VectorCopy (hbe->delta, e2);
				VectorNormalize (e2);
				CrossProduct (e1, e2, normal);
				if (!VectorNormalize (normal))
				{
					continue;
				}
				VectorSubtract (brushedge.point, hbe->point, origin);
				AddHullPlane (hull, normal, origin, true);
			}
		}
	}

	// check for vertex-face type. edge-face type and face-face type are permitted.
	for (hbf = hb->faces; hbf < hb->faces + hb->numfaces; hbf++)
	{
		// find the impact point
		vec3_t bestvertex;
		vec_t bestdist;
		bestdist = BOGUS_RANGE;
		if (!hull0->faces)
		{
			continue;
		}
		for (f = hull0->faces; f; f = f->next)
		{
			for (vec3_t *v = f->w->m_Points; v < f->w->m_Points + f->w->m_NumPoints; v++)
			{
				if (DotProduct (*v, hbf->normal) < bestdist - NORMAL_EPSILON)
				{
					bestdist = DotProduct (*v, hbf->normal);
					VectorCopy (*v, bestvertex);
				}
			}
		}

		// add hull plane for this face
		VectorSubtract (vec3_origin, hbf->normal, normal);
		if (axialbevel[hbf - hb->faces])
		{
			VectorCopy (bestvertex, origin);
		}
		else
		{
			VectorSubtract (bestvertex, hbf->point, origin);
		}
		AddHullPlane (hull, normal, origin, true);
	}

	free (axialbevel);
}

// Assembly:
subq $0x288, %rsp            # imm = 0x288
movq %rdi, 0x280(%rsp)
movq %rsi, 0x278(%rsp)
movq %rdx, 0x270(%rsp)
movq %rcx, 0x268(%rsp)
movq 0x270(%rsp), %rax
movslq (%rax), %rdi
shlq $0x0, %rdi
callq 0x4500
movq %rax, 0x208(%rsp)
movq 0x208(%rsp), %rdi
movq 0x270(%rsp), %rax
movslq (%rax), %rdx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x4210
movb $0x0, 0x207(%rsp)
movq 0x278(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x248(%rsp)
cmpq $0x0, 0x248(%rsp)
je 0x1339a
movq 0x248(%rsp), %rax
movq 0x10(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x1c0(%rsp)
movq 0x248(%rsp), %rax
movq 0x10(%rax), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x1c8(%rsp)
movq 0x248(%rsp), %rax
movq 0x10(%rax), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x1d0(%rsp)
movq 0x248(%rsp), %rax
movq 0x10(%rax), %rax
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x1d8(%rsp)
movq 0x248(%rsp), %rax
movq 0x10(%rax), %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, 0x1e0(%rsp)
movq 0x248(%rsp), %rax
movq 0x10(%rax), %rax
movsd 0x28(%rax), %xmm0
movsd %xmm0, 0x1e8(%rsp)
movq 0x270(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x260(%rsp)
movq 0x260(%rsp), %rax
movq 0x270(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq 0x270(%rsp), %rdx
movslq (%rdx), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x13081
movq 0x260(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x1c0(%rsp), %xmm2
movq 0x260(%rsp), %rax
movsd 0x8(%rax), %xmm0
mulsd 0x1c8(%rsp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x260(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd 0x1d0(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x1a7b6(%rip), %xmm0    # 0x2d670
ucomisd %xmm1, %xmm0
jbe 0x12ec5
jmp 0x13068
movsd 0x1a79b(%rip), %xmm0    # 0x2d668
movsd %xmm0, 0x1b8(%rsp)
movsd 0x1a79a(%rip), %xmm0    # 0x2d678
movsd %xmm0, 0x1b0(%rsp)
movq 0x260(%rsp), %rax
cmpl $0x1, 0x30(%rax)
setge %al
movzbl %al, %edi
andl $0x1, %edi
xorl %esi, %esi
callq 0xc400
movq 0x260(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x1a8(%rsp)
movq 0x1a8(%rsp), %rax
movq 0x260(%rsp), %rcx
movq 0x38(%rcx), %rcx
movq 0x260(%rsp), %rdx
movslq 0x30(%rdx), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x13044
movq 0x1a8(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x1c0(%rsp), %xmm2
movq 0x1a8(%rsp), %rax
movsd 0x8(%rax), %xmm0
mulsd 0x1c8(%rsp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x1a8(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd 0x1d0(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x1a0(%rsp)
movsd 0x1b8(%rsp), %xmm1
movsd 0x1a0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x12fca
movsd 0x1b8(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
jmp 0x12fd9
movsd 0x1a0(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x1b8(%rsp)
movsd 0x1b0(%rsp), %xmm0
ucomisd 0x1a0(%rsp), %xmm0
jbe 0x1300d
movsd 0x1b0(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x1301c
movsd 0x1a0(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x1b0(%rsp)
movq 0x1a8(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x1a8(%rsp)
jmp 0x12f17
movsd 0x1b0(%rsp), %xmm1
subsd 0x1b8(%rsp), %xmm1
movsd 0x1a622(%rip), %xmm0    # 0x2d680
ucomisd %xmm1, %xmm0
jb 0x13066
jmp 0x13081
jmp 0x13068
movq 0x260(%rsp), %rax
addq $0x40, %rax
movq %rax, 0x260(%rsp)
jmp 0x12e1b
movq 0x260(%rsp), %rax
movq 0x270(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq 0x270(%rsp), %rdx
movslq (%rdx), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x130e6
movq 0x248(%rsp), %rax
testb $0x1, 0x30(%rax)
je 0x130e1
movq 0x208(%rsp), %rax
movq 0x260(%rsp), %rcx
movq 0x270(%rsp), %rdx
movq 0x8(%rdx), %rdx
subq %rdx, %rcx
sarq $0x6, %rcx
movb $0x1, (%rax,%rcx)
jmp 0x13382
movsd 0x1a57a(%rip), %xmm0    # 0x2d668
movsd %xmm0, 0x178(%rsp)
movq 0x270(%rsp), %rax
cmpl $0x1, 0x20(%rax)
setge %al
movzbl %al, %edi
andl $0x1, %edi
xorl %esi, %esi
callq 0xc400
movq 0x270(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x250(%rsp)
movq 0x250(%rsp), %rax
movq 0x270(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq 0x270(%rsp), %rdx
movslq 0x20(%rdx), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x13293
movq 0x250(%rsp), %rax
movq 0x270(%rsp), %rcx
cmpq 0x28(%rcx), %rax
je 0x131dd
movq 0x250(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x1c0(%rsp), %xmm2
movq 0x250(%rsp), %rax
movsd 0x8(%rax), %xmm1
mulsd 0x1c8(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x250(%rsp), %rax
movsd 0x10(%rax), %xmm1
movsd 0x1d0(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x178(%rsp), %xmm0
movsd 0x16e99(%rip), %xmm2    # 0x2a068
subsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13278
movq 0x250(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x1c0(%rsp), %xmm2
movq 0x250(%rsp), %rax
movsd 0x8(%rax), %xmm0
mulsd 0x1c8(%rsp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x250(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd 0x1d0(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x178(%rsp)
movq 0x250(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x180(%rsp)
movq 0x250(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x188(%rsp)
movq 0x250(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x190(%rsp)
jmp 0x1327a
movq 0x250(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x250(%rsp)
jmp 0x13127
movsd 0x1c0(%rsp), %xmm0
movsd %xmm0, 0x230(%rsp)
movsd 0x1c8(%rsp), %xmm0
movsd %xmm0, 0x238(%rsp)
movsd 0x1d0(%rsp), %xmm0
movsd %xmm0, 0x240(%rsp)
movq 0x248(%rsp), %rax
testb $0x1, 0x30(%rax)
je 0x1330f
movsd 0x1d8(%rsp), %xmm0
movsd %xmm0, 0x210(%rsp)
movsd 0x1e0(%rsp), %xmm0
movsd %xmm0, 0x218(%rsp)
movsd 0x1e8(%rsp), %xmm0
movsd %xmm0, 0x220(%rsp)
jmp 0x13360
movsd 0x1d8(%rsp), %xmm0
subsd 0x180(%rsp), %xmm0
movsd %xmm0, 0x210(%rsp)
movsd 0x1e0(%rsp), %xmm0
subsd 0x188(%rsp), %xmm0
movsd %xmm0, 0x218(%rsp)
movsd 0x1e8(%rsp), %xmm0
subsd 0x190(%rsp), %xmm0
movsd %xmm0, 0x220(%rsp)
movq 0x268(%rsp), %rdi
leaq 0x230(%rsp), %rsi
leaq 0x210(%rsp), %rdx
movl $0x1, %ecx
callq 0x12bf0
movq 0x248(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x248(%rsp)
jmp 0x12d5d
movq 0x278(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x248(%rsp)
cmpq $0x0, 0x248(%rsp)
je 0x13dd7
movl $0x0, 0x174(%rsp)
movl 0x174(%rsp), %eax
movq 0x248(%rsp), %rcx
movq 0x18(%rcx), %rcx
cmpl 0x8(%rcx), %eax
jae 0x13dbd
movq 0x248(%rsp), %rax
movq 0x10(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0xe0(%rsp)
movq 0x248(%rsp), %rax
movq 0x10(%rax), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0xe8(%rsp)
movq 0x248(%rsp), %rax
movq 0x10(%rax), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0xf0(%rsp)
movq 0x248(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x174(%rsp), %eax
addl $0x1, %eax
movq 0x248(%rsp), %rcx
movq 0x18(%rcx), %rcx
xorl %edx, %edx
divl 0x8(%rcx)
movq 0x8(%rsp), %rax
movl %edx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x128(%rsp)
movq 0x248(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x174(%rsp), %eax
addl $0x1, %eax
movq 0x248(%rsp), %rcx
movq 0x18(%rcx), %rcx
xorl %edx, %edx
divl 0x8(%rcx)
movq 0x10(%rsp), %rax
movl %edx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x130(%rsp)
movq 0x248(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x18(%rsp)
movl 0x174(%rsp), %eax
addl $0x1, %eax
movq 0x248(%rsp), %rcx
movq 0x18(%rcx), %rcx
xorl %edx, %edx
divl 0x8(%rcx)
movq 0x18(%rsp), %rax
movl %edx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x138(%rsp)
movq 0x248(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movslq 0x174(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x140(%rsp)
movq 0x248(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movslq 0x174(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x148(%rsp)
movq 0x248(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movslq 0x174(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x150(%rsp)
movsd 0x128(%rsp), %xmm0
movsd %xmm0, 0x110(%rsp)
movsd 0x130(%rsp), %xmm0
movsd %xmm0, 0x118(%rsp)
movsd 0x138(%rsp), %xmm0
movsd %xmm0, 0x120(%rsp)
movsd 0x140(%rsp), %xmm0
subsd 0x128(%rsp), %xmm0
movsd %xmm0, 0x158(%rsp)
movsd 0x148(%rsp), %xmm0
subsd 0x130(%rsp), %xmm0
movsd %xmm0, 0x160(%rsp)
movsd 0x150(%rsp), %xmm0
subsd 0x138(%rsp), %xmm0
movsd %xmm0, 0x168(%rsp)
movl $0x0, 0xdc(%rsp)
movq 0x278(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0xd0(%rsp)
cmpq $0x0, 0xd0(%rsp)
je 0x1378e
movl $0x0, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
movq 0xd0(%rsp), %rcx
movq 0x18(%rcx), %rcx
cmpl 0x8(%rcx), %eax
jae 0x13774
movq 0xd0(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rdi
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movq 0xd0(%rsp), %rcx
movq 0x18(%rcx), %rcx
xorl %edx, %edx
divl 0x8(%rcx)
movl %edx, %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0xe0(%rsp), %rsi
addq $0x48, %rsi
addq $0x18, %rsi
callq 0x18f00
testb $0x1, %al
jne 0x136c8
jmp 0x1375c
movq 0xd0(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rdi
movslq 0xcc(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0xe0(%rsp), %rsi
addq $0x48, %rsi
callq 0x18f00
testb $0x1, %al
jne 0x136fe
jmp 0x1375c
movq 0xd0(%rsp), %rax
movq 0x10(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0xf8(%rsp)
movq 0xd0(%rsp), %rax
movq 0x10(%rax), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x100(%rsp)
movq 0xd0(%rsp), %rax
movq 0x10(%rax), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x108(%rsp)
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x1375e
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x1365a
jmp 0x13776
movq 0xd0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xd0(%rsp)
jmp 0x13640
cmpl $0x1, 0xdc(%rsp)
je 0x137d2
testb $0x1, 0x207(%rsp)
jne 0x137cd
movq 0x280(%rsp), %rax
movl (%rax), %esi
movq 0x280(%rsp), %rax
movl 0x4(%rax), %edx
leaq 0x19fa9(%rip), %rdi     # 0x2d767
movb $0x0, %al
callq 0xbef0
movb $0x1, 0x207(%rsp)
jmp 0x13da7
movsd 0x158(%rsp), %xmm1
movsd 0x158(%rsp), %xmm2
movsd 0x160(%rsp), %xmm0
mulsd 0x160(%rsp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x168(%rsp), %xmm0
movsd 0x168(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x42f0
movsd %xmm0, 0xc0(%rsp)
movsd 0xe8(%rsp), %xmm0
movsd 0x108(%rsp), %xmm2
movsd 0xf0(%rsp), %xmm1
mulsd 0x100(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x158(%rsp)
movsd 0xf0(%rsp), %xmm0
movsd 0xf8(%rsp), %xmm2
movsd 0xe0(%rsp), %xmm1
mulsd 0x108(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x160(%rsp)
movsd 0xe0(%rsp), %xmm0
movsd 0x100(%rsp), %xmm2
movsd 0xe8(%rsp), %xmm1
mulsd 0xf8(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x168(%rsp)
leaq 0xe0(%rsp), %rdi
addq $0x78, %rdi
callq 0x121b0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1392b
jp 0x1392b
jmp 0x13da7
movsd 0x158(%rsp), %xmm0
mulsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0x158(%rsp)
movsd 0x160(%rsp), %xmm0
mulsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0x160(%rsp)
movsd 0x168(%rsp), %xmm0
mulsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0x168(%rsp)
movq 0x270(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x258(%rsp)
movq 0x258(%rsp), %rax
movq 0x270(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0x270(%rsp), %rdx
movslq 0x10(%rdx), %rdx
imulq $0x90, %rdx, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x13da5
movq 0x258(%rsp), %rax
movsd 0x78(%rax), %xmm1
movsd 0xe0(%rsp), %xmm2
movq 0x258(%rsp), %rax
movsd 0x80(%rax), %xmm0
mulsd 0xe8(%rsp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x258(%rsp), %rax
movsd 0x88(%rax), %xmm0
movsd 0xf0(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movq 0x258(%rsp), %rax
movsd 0x78(%rax), %xmm1
movsd 0xf8(%rsp), %xmm2
movq 0x258(%rsp), %rax
movsd 0x80(%rax), %xmm0
mulsd 0x100(%rsp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x258(%rsp), %rax
movsd 0x88(%rax), %xmm0
movsd 0x108(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xa8(%rsp)
movsd 0x158(%rsp), %xmm1
movq 0x258(%rsp), %rax
movsd (%rax), %xmm2
movsd 0x160(%rsp), %xmm0
movq 0x258(%rsp), %rax
mulsd 0x8(%rax), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x168(%rsp), %xmm0
movq 0x258(%rsp), %rax
movsd 0x10(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xb0(%rsp)
movsd 0x158(%rsp), %xmm1
movq 0x258(%rsp), %rax
movsd 0x18(%rax), %xmm2
movsd 0x160(%rsp), %xmm0
movq 0x258(%rsp), %rax
mulsd 0x20(%rax), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x168(%rsp), %xmm0
movq 0x258(%rsp), %rax
movsd 0x28(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xb8(%rsp)
movsd 0x19b16(%rip), %xmm0    # 0x2d658
ucomisd 0xa0(%rsp), %xmm0
jae 0x13b8e
movsd 0xa8(%rsp), %xmm0
movsd 0x19af2(%rip), %xmm1    # 0x2d650
ucomisd %xmm1, %xmm0
jae 0x13b8e
movsd 0x19aec(%rip), %xmm0    # 0x2d658
ucomisd 0xb0(%rsp), %xmm0
jae 0x13b8e
movsd 0xb8(%rsp), %xmm0
movsd 0x19ac8(%rip), %xmm1    # 0x2d650
ucomisd %xmm1, %xmm0
jb 0x13b93
jmp 0x13d8a
movsd 0x158(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x160(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x168(%rsp), %xmm0
movsd %xmm0, 0x90(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x121b0
movq 0x258(%rsp), %rax
movsd 0x78(%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x258(%rsp), %rax
movsd 0x80(%rax), %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0x258(%rsp), %rax
movsd 0x88(%rax), %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x121b0
movsd 0x88(%rsp), %xmm0
movsd 0x70(%rsp), %xmm2
movsd 0x90(%rsp), %xmm1
mulsd 0x68(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x230(%rsp)
movsd 0x90(%rsp), %xmm0
movsd 0x60(%rsp), %xmm2
movsd 0x80(%rsp), %xmm1
mulsd 0x70(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x238(%rsp)
movsd 0x80(%rsp), %xmm0
movsd 0x68(%rsp), %xmm2
movsd 0x88(%rsp), %xmm1
mulsd 0x60(%rsp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x240(%rsp)
leaq 0x230(%rsp), %rdi
callq 0x121b0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x13d0b
jp 0x13d0b
jmp 0x13d8a
movsd 0x110(%rsp), %xmm0
movq 0x258(%rsp), %rax
subsd 0x30(%rax), %xmm0
movsd %xmm0, 0x210(%rsp)
movsd 0x118(%rsp), %xmm0
movq 0x258(%rsp), %rax
subsd 0x38(%rax), %xmm0
movsd %xmm0, 0x218(%rsp)
movsd 0x120(%rsp), %xmm0
movq 0x258(%rsp), %rax
subsd 0x40(%rax), %xmm0
movsd %xmm0, 0x220(%rsp)
movq 0x268(%rsp), %rdi
leaq 0x230(%rsp), %rsi
leaq 0x210(%rsp), %rdx
movl $0x1, %ecx
callq 0x12bf0
movq 0x258(%rsp), %rax
addq $0x90, %rax
movq %rax, 0x258(%rsp)
jmp 0x13990
jmp 0x13da7
movl 0x174(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x174(%rsp)
jmp 0x133c8
jmp 0x13dbf
movq 0x248(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x248(%rsp)
jmp 0x133ae
movq 0x270(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x260(%rsp)
movq 0x260(%rsp), %rax
movq 0x270(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq 0x270(%rsp), %rdx
movslq (%rdx), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x14119
movsd 0x19846(%rip), %xmm0    # 0x2d668
movsd %xmm0, 0x38(%rsp)
movq 0x278(%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x13e3c
jmp 0x14100
movq 0x278(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x248(%rsp)
cmpq $0x0, 0x248(%rsp)
je 0x13fce
movq 0x248(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq 0x248(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0x10(%rcx), %rcx
movq 0x248(%rsp), %rdx
movq 0x18(%rdx), %rdx
movl 0x8(%rdx), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x13fb4
movq 0x30(%rsp), %rax
movsd (%rax), %xmm0
movq 0x260(%rsp), %rax
movsd (%rax), %xmm2
movq 0x30(%rsp), %rax
movsd 0x8(%rax), %xmm1
movq 0x260(%rsp), %rax
mulsd 0x8(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x30(%rsp), %rax
movsd 0x10(%rax), %xmm1
movq 0x260(%rsp), %rax
movsd 0x10(%rax), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
movsd 0x1615f(%rip), %xmm2    # 0x2a068
subsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13f9f
movq 0x30(%rsp), %rax
movsd (%rax), %xmm1
movq 0x260(%rsp), %rax
movsd (%rax), %xmm2
movq 0x30(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq 0x260(%rsp), %rax
mulsd 0x8(%rax), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x30(%rsp), %rax
movsd 0x10(%rax), %xmm0
movq 0x260(%rsp), %rax
movsd 0x10(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x30(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x30(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x30(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
jmp 0x13fa1
movq 0x30(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x30(%rsp)
jmp 0x13e74
jmp 0x13fb6
movq 0x248(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x248(%rsp)
jmp 0x13e50
leaq 0x17ebb(%rip), %rax     # 0x2be90
movsd (%rax), %xmm0
movq 0x260(%rsp), %rax
subsd (%rax), %xmm0
movsd %xmm0, 0x230(%rsp)
leaq 0x17e9b(%rip), %rax     # 0x2be90
movsd 0x8(%rax), %xmm0
movq 0x260(%rsp), %rax
subsd 0x8(%rax), %xmm0
movsd %xmm0, 0x238(%rsp)
leaq 0x17e79(%rip), %rax     # 0x2be90
movsd 0x10(%rax), %xmm0
movq 0x260(%rsp), %rax
subsd 0x10(%rax), %xmm0
movsd %xmm0, 0x240(%rsp)
movq 0x208(%rsp), %rax
movq 0x260(%rsp), %rcx
movq 0x270(%rsp), %rdx
movq 0x8(%rdx), %rdx
subq %rdx, %rcx
sarq $0x6, %rcx
testb $0x1, (%rax,%rcx)
je 0x1408a
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x210(%rsp)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x218(%rsp)
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x220(%rsp)
jmp 0x140de
movsd 0x40(%rsp), %xmm0
movq 0x260(%rsp), %rax
subsd 0x18(%rax), %xmm0
movsd %xmm0, 0x210(%rsp)
movsd 0x48(%rsp), %xmm0
movq 0x260(%rsp), %rax
subsd 0x20(%rax), %xmm0
movsd %xmm0, 0x218(%rsp)
movsd 0x50(%rsp), %xmm0
movq 0x260(%rsp), %rax
subsd 0x28(%rax), %xmm0
movsd %xmm0, 0x220(%rsp)
movq 0x268(%rsp), %rdi
leaq 0x230(%rsp), %rsi
leaq 0x210(%rsp), %rdx
movl $0x1, %ecx
callq 0x12bf0
movq 0x260(%rsp), %rax
addq $0x40, %rax
movq %rax, 0x260(%rsp)
jmp 0x13deb
movq 0x208(%rsp), %rdi
callq 0x4470
addq $0x288, %rsp            # imm = 0x288
retq
nop