// File: FreeSlave[P]vhlt/hlbsp/writebsp.cpp
// Function: FinishBSPFile()
void            FinishBSPFile()
{
    Verbose("--- FinishBSPFile ---\n");

#ifdef ZHLT_MAX_MAP_LEAFS
	if (g_dmodels[0].visleafs > MAX_MAP_LEAFS_ENGINE)
	{
		Warning ("Number of world leaves(%d) exceeded MAX_MAP_LEAFS(%d)\nIf you encounter problems when running your map, consider this the most likely cause.\n", g_dmodels[0].visleafs, MAX_MAP_LEAFS_ENGINE);
	}
#endif
#ifdef ZHLT_WARNWORLDFACES
	if (g_dmodels[0].numfaces > MAX_MAP_WORLDFACES)
	{
		Warning ("Number of world faces(%d) exceeded %d. Some faces will disappear in game.\nTo reduce world faces, change some world brushes (including func_details) to func_walls.\n", g_dmodels[0].numfaces, MAX_MAP_WORLDFACES);
	}
#endif
#ifdef HLBSP_MERGECLIPNODE
	Developer (DEVELOPER_LEVEL_MESSAGE, "count_mergedclipnodes = %d\n", count_mergedclipnodes);
	if (!g_noclipnodemerge)
	{
#ifdef ZHLT_XASH2
		int total = 0;
		for (int hull = 1; hull < MAX_MAP_HULLS; hull++)
		{
			total += g_numclipnodes[hull - 1];
		}
		Log ("Reduced %d clipnodes to %d\n", total + count_mergedclipnodes, total);
#else
		Log ("Reduced %d clipnodes to %d\n", g_numclipnodes + count_mergedclipnodes, g_numclipnodes);
#endif
	}
#endif
	if(!g_noopt)
	{
#ifdef HLCSG_HLBSP_REDUCETEXTURE
		{
			Log ("Reduced %d texinfos to %d\n", g_numtexinfo, g_nummappedtexinfo);
			for (int i = 0; i < g_nummappedtexinfo; i++)
			{
				g_texinfo[i] = g_mappedtexinfo[i];
			}
			g_numtexinfo = g_nummappedtexinfo;
		}
		{
			dmiptexlump_t *l = (dmiptexlump_t *)g_dtexdata;
			int &g_nummiptex = l->nummiptex;
			bool *Used = (bool *)calloc (g_nummiptex, sizeof(bool));
			int Num = 0, Size = 0;
			int *Map = (int *)malloc (g_nummiptex * sizeof(int));
			int i;
			hlassume (Used != NULL && Map != NULL, assume_NoMemory);
			int *lumpsizes = (int *)malloc (g_nummiptex * sizeof (int));
			const int newdatasizemax = g_texdatasize - ((byte *)&l->dataofs[g_nummiptex] - (byte *)l);
			byte *newdata = (byte *)malloc (newdatasizemax);
			int newdatasize = 0;
			hlassume (lumpsizes != NULL && newdata != NULL, assume_NoMemory);
			int total = 0;
			for (i = 0; i < g_nummiptex; i++)
			{
				if (l->dataofs[i] == -1)
				{
					lumpsizes[i] = -1;
					continue;
				}
				lumpsizes[i] = g_texdatasize - l->dataofs[i];
				for (int j = 0; j < g_nummiptex; j++)
				{
					int lumpsize = l->dataofs[j] - l->dataofs[i];
					if (l->dataofs[j] == -1 || lumpsize < 0 || lumpsize == 0 && j <= i)
						continue;
					if (lumpsize < lumpsizes[i])
						lumpsizes[i] = lumpsize;
				}
				total += lumpsizes[i];
			}
			if (total != newdatasizemax)
			{
				Warning ("Bad texdata structure.\n");
				goto skipReduceTexdata;
			}
			for (i = 0; i < g_numtexinfo; i++)
			{
				texinfo_t *t = &g_texinfo[i];
				if (t->miptex < 0 || t->miptex >= g_nummiptex)
				{
					Warning ("Bad miptex number %d.\n", t->miptex);
					goto skipReduceTexdata;
				}
				Used[t->miptex] = true;
			}
			for (i = 0; i < g_nummiptex; i++)
			{
				const int MAXWADNAME = 16;
				char name[MAXWADNAME];
				int j, k;
				if (l->dataofs[i] < 0)
					continue;
				if (Used[i] == true)
				{
					miptex_t *m = (miptex_t *)((byte *)l + l->dataofs[i]);
					if (m->name[0] != '+' && m->name[0] != '-')
						continue;
					safe_strncpy (name, m->name, MAXWADNAME);
					if (name[1] == '\0')
						continue;
					for (j = 0; j < 20; j++)
					{
						if (j < 10)
							name[1] = '0' + j;
						else
							name[1] = 'A' + j - 10;
						for (k = 0; k < g_nummiptex; k++)
						{
							if (l->dataofs[k] < 0)
								continue;
							miptex_t *m2 = (miptex_t *)((byte *)l + l->dataofs[k]);
							if (!strcasecmp (name, m2->name))
								Used[k] = true;
						}
					}
				}
			}
			for (i = 0; i < g_nummiptex; i++)
			{
				if (Used[i])
				{
					Map[i] = Num;
					Num++;
				}
				else
				{
					Map[i] = -1;
				}
			}
			for (i = 0; i < g_numtexinfo; i++)
			{
				texinfo_t *t = &g_texinfo[i];
				t->miptex = Map[t->miptex];
			}
			Size += (byte *)&l->dataofs[Num] - (byte *)l;
			for (i = 0; i < g_nummiptex; i++)
			{
				if (Used[i])
				{
					if (lumpsizes[i] == -1)
					{
						l->dataofs[Map[i]] = -1;
					}
					else
					{
						memcpy ((byte *)newdata + newdatasize, (byte *)l + l->dataofs[i], lumpsizes[i]);
						l->dataofs[Map[i]] = Size;
						newdatasize += lumpsizes[i];
						Size += lumpsizes[i];
					}
				}
			}
			memcpy (&l->dataofs[Num], newdata, newdatasize);
			Log ("Reduced %d texdatas to %d (%d bytes to %d)\n", g_nummiptex, Num, g_texdatasize, Size);
			g_nummiptex = Num;
			g_texdatasize = Size;
			skipReduceTexdata:;
			free (lumpsizes);
			free (newdata);
			free (Used);
			free (Map);
		}
		Log ("Reduced %d planes to %d\n", g_numplanes, gNumMappedPlanes);
#endif
		for(int counter = 0; counter < gNumMappedPlanes; counter++)
		{
			g_dplanes[counter] = gMappedPlanes[counter];
		}
		g_numplanes = gNumMappedPlanes;
	}
#ifdef HLCSG_HLBSP_REDUCETEXTURE
	else
	{
		hlassume (g_numtexinfo < MAX_MAP_TEXINFO, assume_MAX_MAP_TEXINFO);
		hlassume (g_numplanes < MAX_MAP_PLANES, assume_MAX_MAP_PLANES);
	}
#endif
#ifdef HLBSP_BRINKHACK
	if (!g_nobrink)
	{
		Log ("FixBrinks:\n");
#ifdef ZHLT_XASH2
		dclipnode_t *clipnodes[MAX_MAP_HULLS - 1];
		int numclipnodes[MAX_MAP_HULLS - 1];
		for (int hull = 1; hull < MAX_MAP_HULLS; hull++)
		{
			clipnodes[hull - 1] = (dclipnode_t *)malloc (MAX_MAP_CLIPNODES * sizeof (dclipnode_t));
			hlassume (clipnodes[hull - 1] != NULL, assume_NoMemory);
		}
#else
		dclipnode_t *clipnodes; //[MAX_MAP_CLIPNODES]
		int numclipnodes;
		clipnodes = (dclipnode_t *)malloc (MAX_MAP_CLIPNODES * sizeof (dclipnode_t));
		hlassume (clipnodes != NULL, assume_NoMemory);
#endif
		void *(*brinkinfo)[NUM_HULLS]; //[MAX_MAP_MODELS]
		int (*headnode)[NUM_HULLS]; //[MAX_MAP_MODELS]
		brinkinfo = (void *(*)[NUM_HULLS])malloc (MAX_MAP_MODELS * sizeof (void *[NUM_HULLS]));
		hlassume (brinkinfo != NULL, assume_NoMemory);
		headnode = (int (*)[NUM_HULLS])malloc (MAX_MAP_MODELS * sizeof (int [NUM_HULLS]));
		hlassume (headnode != NULL, assume_NoMemory);

		int i, j, level;
		for (i = 0; i < g_nummodels; i++)
		{
			dmodel_t *m = &g_dmodels[i];
			Developer (DEVELOPER_LEVEL_MESSAGE, " model %d\n", i);
			for (j = 1; j < NUM_HULLS; j++)
			{
#ifdef ZHLT_XASH2
				brinkinfo[i][j] = CreateBrinkinfo (g_dclipnodes[j - 1], m->headnode[j]);
#else
				brinkinfo[i][j] = CreateBrinkinfo (g_dclipnodes, m->headnode[j]);
#endif
			}
		}
		for (level = BrinkAny; level > BrinkNone; level--)
		{
#ifdef ZHLT_XASH2
			for (int hull = 1; hull < MAX_MAP_HULLS; hull++)
			{
				numclipnodes[hull - 1] = 0;
			}
#else
			numclipnodes = 0;
#endif
#ifdef HLBSP_MERGECLIPNODE
			count_mergedclipnodes = 0;
#endif
			for (i = 0; i < g_nummodels; i++)
			{
				for (j = 1; j < NUM_HULLS; j++)
				{
#ifdef ZHLT_XASH2
					if (!FixBrinks (brinkinfo[i][j], (bbrinklevel_e) level, headnode[i][j], clipnodes[j - 1], MAX_MAP_CLIPNODES, numclipnodes[j - 1], numclipnodes[j - 1]))
#else
					if (!FixBrinks (brinkinfo[i][j], (bbrinklevel_e) level, headnode[i][j], clipnodes, MAX_MAP_CLIPNODES, numclipnodes, numclipnodes))
#endif
					{
						break;
					}
				}
				if (j < NUM_HULLS)
				{
					break;
				}
			}
			if (i == g_nummodels)
			{
				break;
			}
		}
		for (i = 0; i < g_nummodels; i++)
		{
			for (j = 1; j < NUM_HULLS; j++)
			{
				DeleteBrinkinfo (brinkinfo[i][j]);
			}
		}
		if (level == BrinkNone)
		{
			Warning ("No brinks have been fixed because clipnode data is almost full.");
		}
		else
		{
			if (level != BrinkAny)
			{
				Warning ("Not all brinks have been fixed because clipnode data is almost full.");
			}
#ifdef HLBSP_MERGECLIPNODE
			Developer (DEVELOPER_LEVEL_MESSAGE, "count_mergedclipnodes = %d\n", count_mergedclipnodes);
#endif
#ifdef ZHLT_XASH2
			int g_numclipnodes_total = 0;
			int numclipnodes_total = 0;
			for (int hull = 1; hull < MAX_MAP_HULLS; hull++)
			{
				g_numclipnodes_total += g_numclipnodes[hull - 1];
				numclipnodes_total += numclipnodes[hull - 1];
			}
			Log ("Increased %d clipnodes to %d.\n", g_numclipnodes_total, numclipnodes_total);
			for (int hull = 1; hull < MAX_MAP_HULLS; hull++)
			{
				g_numclipnodes[hull - 1] = numclipnodes[hull - 1];
				memcpy (g_dclipnodes[hull - 1], clipnodes[hull - 1], numclipnodes[hull - 1] * sizeof (dclipnode_t));
			}
#else
			Log ("Increased %d clipnodes to %d.\n", g_numclipnodes, numclipnodes);
			g_numclipnodes = numclipnodes;
			memcpy (g_dclipnodes, clipnodes, numclipnodes * sizeof (dclipnode_t));
#endif
			for (i = 0; i < g_nummodels; i++)
			{
				dmodel_t *m = &g_dmodels[i];
				for (j = 1; j < NUM_HULLS; j++)
				{
					m->headnode[j] = headnode[i][j];
				}
			}
		}
		free (brinkinfo);
		free (headnode);
#ifdef ZHLT_XASH2
		for (int hull = 1; hull < MAX_MAP_HULLS; hull++)
		{
			free (clipnodes[hull - 1]);
		}
#else
		free (clipnodes);
#endif
	}
#endif
	
#ifdef ZHLT_HIDDENSOUNDTEXTURE
	for (int i = 0; i < g_numtexinfo; i++)
	{
		g_texinfo[i].flags &= ~TEX_SHOULDHIDE;
	}
#endif
#ifdef ZHLT_64BIT_FIX
#ifdef PLATFORM_CAN_CALC_EXTENT
	WriteExtentFile (g_extentfilename);
#else
	Warning ("The " PLATFORM_VERSIONSTRING " version of hlbsp couldn't create extent file. The lack of extent file may cause hlrad error.");
#endif
#endif
	if (g_chart)
    {
        PrintBSPFileSizes();
    }

#ifdef HLCSG_HLBSP_DOUBLEPLANE
#undef dplane_t // this allow us to temporarily access the raw data directly without the layer of indirection
#undef g_dplanes
	for (int i = 0; i < g_numplanes; i++)
	{
		plane_t *mp = &g_mapplanes[i];
		dplane_t *dp = &g_dplanes[i];
		VectorCopy (mp->normal, dp->normal);
		dp->dist = mp->dist;
		dp->type = mp->type;
	}
#define dplane_t plane_t
#define g_dplanes g_mapplanes
#endif
    WriteBSPFile(g_bspfilename);
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
leaq 0x8ac7(%rip), %rdi      # 0x3be75
movb $0x0, %al
callq 0xba90
leaq 0x14084(%rip), %rax     # 0x47440
cmpl $0x2000, 0x34(%rax)     # imm = 0x2000
jle 0x333e2
leaq 0x14074(%rip), %rax     # 0x47440
movl 0x34(%rax), %esi
leaq 0x8ab6(%rip), %rdi      # 0x3be8c
movl $0x2000, %edx           # imm = 0x2000
movb $0x0, %al
callq 0xb980
leaq 0x14057(%rip), %rax     # 0x47440
cmpl $0x8000, 0x3c(%rax)     # imm = 0x8000
jle 0x3340f
leaq 0x14047(%rip), %rax     # 0x47440
movl 0x3c(%rax), %esi
leaq 0x8b16(%rip), %rdi      # 0x3bf19
movl $0x8000, %edx           # imm = 0x8000
movb $0x0, %al
callq 0xb980
movl 0x4a3878b(%rip), %edx   # 0x4a6bba0
movl $0x3, %edi
leaq 0x8b9c(%rip), %rsi      # 0x3bfbd
movb $0x0, %al
callq 0xbb80
leaq 0x20bc5f2(%rip), %rax   # 0x20efa21
testb $0x1, (%rax)
jne 0x3345a
leaq 0x1cbbf85(%rip), %rax   # 0x1cef3c0
movl (%rax), %esi
addl 0x4a3875d(%rip), %esi   # 0x4a6bba0
leaq 0x1cbbf76(%rip), %rax   # 0x1cef3c0
movl (%rax), %edx
leaq 0x8b86(%rip), %rdi      # 0x3bfd9
movb $0x0, %al
callq 0xb060
leaq 0x20bc5bf(%rip), %rax   # 0x20efa20
testb $0x1, (%rax)
jne 0x33e72
leaq 0x117bf4b(%rip), %rax   # 0x11af3bc
movl (%rax), %esi
movl 0x4a3872f(%rip), %edx   # 0x4a6bba8
leaq 0x8b75(%rip), %rdi      # 0x3bff5
movb $0x0, %al
callq 0xb060
movl $0x0, 0x114(%rsp)
movl 0x114(%rsp), %eax
cmpl 0x4a38709(%rip), %eax   # 0x4a6bba8
jge 0x334ea
movslq 0x114(%rsp), %rax
leaq 0x4a38700(%rip), %rsi   # 0x4a6bbb0
imulq $0x28, %rax, %rax
addq %rax, %rsi
movslq 0x114(%rsp), %rax
leaq 0x117befa(%rip), %rdi   # 0x11af3c0
imulq $0x28, %rax, %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x4260
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0x33492
movl 0x4a386b8(%rip), %ecx   # 0x4a6bba8
leaq 0x117bec5(%rip), %rax   # 0x11af3bc
movl %ecx, (%rax)
leaq 0x81bf68(%rip), %rax    # 0x84f468
movq (%rax), %rax
movq %rax, 0x108(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rax
movslq (%rax), %rdi
movl $0x1, %esi
callq 0x41e0
movq %rax, 0xf8(%rsp)
movl $0x0, 0xf4(%rsp)
movl $0x0, 0xf0(%rsp)
movq 0x100(%rsp), %rax
movslq (%rax), %rdi
shlq $0x2, %rdi
callq 0x43e0
movq %rax, 0xe8(%rsp)
xorl %eax, %eax
cmpq $0x0, 0xf8(%rsp)
movb %al, 0xf(%rsp)
je 0x3358b
cmpq $0x0, 0xe8(%rsp)
setne %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbe90
movq 0x100(%rsp), %rax
movslq (%rax), %rdi
shlq $0x2, %rdi
callq 0x43e0
movq %rax, 0xd8(%rsp)
leaq 0x81bea2(%rip), %rax    # 0x84f464
movslq (%rax), %rax
movq 0x108(%rsp), %rcx
addq $0x4, %rcx
movq 0x100(%rsp), %rdx
movslq (%rdx), %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movq 0x108(%rsp), %rdx
subq %rdx, %rcx
subq %rcx, %rax
movl %eax, 0xd4(%rsp)
movslq 0xd4(%rsp), %rdi
callq 0x43e0
movq %rax, 0xc8(%rsp)
movl $0x0, 0xc4(%rsp)
xorl %eax, %eax
cmpq $0x0, 0xd8(%rsp)
movb %al, 0xe(%rsp)
je 0x33639
cmpq $0x0, 0xc8(%rsp)
setne %al
movb %al, 0xe(%rsp)
movb 0xe(%rsp), %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbe90
movl $0x0, 0xc0(%rsp)
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
movq 0x100(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x337f0
movq 0x108(%rsp), %rax
movslq 0xe4(%rsp), %rcx
cmpl $-0x1, 0x4(%rax,%rcx,4)
jne 0x336ad
movq 0xd8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x337da
leaq 0x81bdb0(%rip), %rax    # 0x84f464
movl (%rax), %edx
movq 0x108(%rsp), %rax
movslq 0xe4(%rsp), %rcx
subl 0x4(%rax,%rcx,4), %edx
movq 0xd8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
movq 0x100(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x337b9
movq 0x108(%rsp), %rax
movslq 0xbc(%rsp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movq 0x108(%rsp), %rcx
movslq 0xe4(%rsp), %rdx
subl 0x4(%rcx,%rdx,4), %eax
movl %eax, 0xb8(%rsp)
movq 0x108(%rsp), %rax
movslq 0xbc(%rsp), %rcx
cmpl $-0x1, 0x4(%rax,%rcx,4)
je 0x33769
cmpl $0x0, 0xb8(%rsp)
jl 0x33769
cmpl $0x0, 0xb8(%rsp)
jne 0x3376b
movl 0xbc(%rsp), %eax
cmpl 0xe4(%rsp), %eax
jg 0x3376b
jmp 0x337a3
movl 0xb8(%rsp), %eax
movq 0xd8(%rsp), %rcx
movslq 0xe4(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x337a1
movl 0xb8(%rsp), %edx
movq 0xd8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x337a3
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x336e8
movq 0xd8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movl (%rax,%rcx,4), %eax
addl 0xc0(%rsp), %eax
movl %eax, 0xc0(%rsp)
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x33663
movl 0xc0(%rsp), %eax
cmpl 0xd4(%rsp), %eax
je 0x33813
leaq 0x8809(%rip), %rdi      # 0x3c010
movb $0x0, %al
callq 0xb980
jmp 0x33dbf
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
leaq 0x117bb90(%rip), %rcx   # 0x11af3bc
cmpl (%rcx), %eax
jge 0x338c3
movslq 0xe4(%rsp), %rcx
leaq 0x117bb7d(%rip), %rax   # 0x11af3c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
cmpl $0x0, 0x20(%rax)
jl 0x33877
movq 0xb0(%rsp), %rax
movl 0x20(%rax), %eax
movq 0x100(%rsp), %rcx
cmpl (%rcx), %eax
jl 0x33895
movq 0xb0(%rsp), %rax
movl 0x20(%rax), %esi
leaq 0x879f(%rip), %rdi      # 0x3c028
movb $0x0, %al
callq 0xb980
jmp 0x33dbf
movq 0xf8(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq 0x20(%rcx), %rcx
movb $0x1, (%rax,%rcx)
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x3381e
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
movq 0x100(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x33ac5
movl $0x10, 0xac(%rsp)
movq 0x108(%rsp), %rax
movslq 0xe4(%rsp), %rcx
cmpl $0x0, 0x4(%rax,%rcx,4)
jge 0x3390c
jmp 0x33aaf
movq 0xf8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movb (%rax,%rcx), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x33aad
movq 0x108(%rsp), %rax
movq 0x108(%rsp), %rcx
movslq 0xe4(%rsp), %rdx
movslq 0x4(%rcx,%rdx,4), %rcx
addq %rcx, %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
je 0x3397a
movq 0x80(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x3397a
jmp 0x33aaf
leaq 0x90(%rsp), %rdi
movq 0x80(%rsp), %rsi
movl $0x10, %edx
callq 0x9580
movsbl 0x91(%rsp), %eax
cmpl $0x0, %eax
jne 0x339a6
jmp 0x33aaf
movl $0x0, 0x8c(%rsp)
cmpl $0x14, 0x8c(%rsp)
jge 0x33aab
cmpl $0xa, 0x8c(%rsp)
jge 0x339dc
movl 0x8c(%rsp), %eax
addl $0x30, %eax
movb %al, 0x91(%rsp)
jmp 0x339f0
movl 0x8c(%rsp), %eax
addl $0x41, %eax
subl $0xa, %eax
movb %al, 0x91(%rsp)
movl $0x0, 0x88(%rsp)
movl 0x88(%rsp), %eax
movq 0x100(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x33a93
movq 0x108(%rsp), %rax
movslq 0x88(%rsp), %rcx
cmpl $0x0, 0x4(%rax,%rcx,4)
jge 0x33a2b
jmp 0x33a7d
movq 0x108(%rsp), %rax
movq 0x108(%rsp), %rcx
movslq 0x88(%rsp), %rdx
movslq 0x4(%rcx,%rdx,4), %rcx
addq %rcx, %rax
movq %rax, 0x78(%rsp)
leaq 0x90(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x4320
cmpl $0x0, %eax
jne 0x33a7b
movq 0xf8(%rsp), %rax
movslq 0x88(%rsp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x33a7d
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0x339fb
jmp 0x33a95
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x339b1
jmp 0x33aad
jmp 0x33aaf
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x338ce
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
movq 0x100(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x33b55
movq 0xf8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x33b26
movl 0xf4(%rsp), %edx
movq 0xe8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0xf4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf4(%rsp)
jmp 0x33b3d
movq 0xe8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x33b3f
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x33ad0
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
leaq 0x117b84e(%rip), %rcx   # 0x11af3bc
cmpl (%rcx), %eax
jge 0x33bbc
movslq 0xe4(%rsp), %rcx
leaq 0x117b83f(%rip), %rax   # 0x11af3c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x70(%rsp)
movq 0xe8(%rsp), %rax
movq 0x70(%rsp), %rcx
movslq 0x20(%rcx), %rcx
movl (%rax,%rcx,4), %ecx
movq 0x70(%rsp), %rax
movl %ecx, 0x20(%rax)
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x33b60
movq 0x108(%rsp), %rcx
addq $0x4, %rcx
movslq 0xf4(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rcx
movq 0x108(%rsp), %rax
subq %rax, %rcx
movslq 0xf0(%rsp), %rax
addq %rcx, %rax
movl %eax, 0xf0(%rsp)
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
movq 0x100(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x33d3e
movq 0xf8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x33d26
movq 0xd8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
jne 0x33c6f
movq 0x108(%rsp), %rax
movq 0xe8(%rsp), %rcx
movslq 0xe4(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl $0xffffffff, 0x4(%rax,%rcx,4) # imm = 0xFFFFFFFF
jmp 0x33d24
movq 0xc8(%rsp), %rdi
movslq 0xc4(%rsp), %rax
addq %rax, %rdi
movq 0x108(%rsp), %rsi
movq 0x108(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movslq 0x4(%rax,%rcx,4), %rax
addq %rax, %rsi
movq 0xd8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movslq (%rax,%rcx,4), %rdx
callq 0x4260
movl 0xf0(%rsp), %edx
movq 0x108(%rsp), %rax
movq 0xe8(%rsp), %rcx
movslq 0xe4(%rsp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl %edx, 0x4(%rax,%rcx,4)
movq 0xd8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movl (%rax,%rcx,4), %eax
addl 0xc4(%rsp), %eax
movl %eax, 0xc4(%rsp)
movq 0xd8(%rsp), %rax
movslq 0xe4(%rsp), %rcx
movl (%rax,%rcx,4), %eax
addl 0xf0(%rsp), %eax
movl %eax, 0xf0(%rsp)
jmp 0x33d26
jmp 0x33d28
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x33bff
movq 0x108(%rsp), %rdi
addq $0x4, %rdi
movslq 0xf4(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq 0xc8(%rsp), %rsi
movslq 0xc4(%rsp), %rdx
callq 0x4260
movq 0x100(%rsp), %rax
movl (%rax), %esi
movl 0xf4(%rsp), %edx
leaq 0x81b6de(%rip), %rax    # 0x84f464
movl (%rax), %ecx
movl 0xf0(%rsp), %r8d
leaq 0x82a8(%rip), %rdi      # 0x3c03f
movb $0x0, %al
callq 0xb060
movl 0xf4(%rsp), %ecx
movq 0x100(%rsp), %rax
movl %ecx, (%rax)
movl 0xf0(%rsp), %ecx
leaq 0x81b6a7(%rip), %rax    # 0x84f464
movl %ecx, (%rax)
movq 0xd8(%rsp), %rdi
callq 0x4370
movq 0xc8(%rsp), %rdi
callq 0x4370
movq 0xf8(%rsp), %rdi
callq 0x4370
movq 0xe8(%rsp), %rdi
callq 0x4370
leaq 0xafb5ba(%rip), %rax    # 0xb2f3b4
movl (%rax), %esi
movl 0x4a37da2(%rip), %edx   # 0x4a6bba4
leaq 0x8262(%rip), %rdi      # 0x3c06b
movb $0x0, %al
callq 0xb060
movl $0x0, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
cmpl 0x4a37d82(%rip), %eax   # 0x4a6bba4
jge 0x33e61
movslq 0x6c(%rsp), %rax
leaq 0x4b77d60(%rip), %rsi   # 0x4babb90
shlq $0x6, %rax
addq %rax, %rsi
movslq 0x6c(%rsp), %rax
leaq 0x20bbbed(%rip), %rdi   # 0x20efa30
shlq $0x6, %rax
addq %rax, %rdi
movl $0x40, %edx
callq 0x4260
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x33e18
movl 0x4a37d3d(%rip), %ecx   # 0x4a6bba4
leaq 0xafb546(%rip), %rax    # 0xb2f3b4
movl %ecx, (%rax)
jmp 0x33eb2
leaq 0x117b543(%rip), %rax   # 0x11af3bc
cmpl $0x7fff, (%rax)         # imm = 0x7FFF
setl %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x26, %esi
callq 0xbe90
leaq 0xafb51b(%rip), %rax    # 0xb2f3b4
cmpl $0x8000, (%rax)         # imm = 0x8000
setl %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x23, %esi
callq 0xbe90
leaq 0x20bbb6c(%rip), %rax   # 0x20efa25
testb $0x1, (%rax)
jne 0x3427e
leaq 0x81bb(%rip), %rdi      # 0x3c084
movb $0x0, %al
callq 0xb060
movl $0x3fff8, %edi          # imm = 0x3FFF8
callq 0x43e0
movq %rax, 0x60(%rsp)
cmpq $0x0, 0x60(%rsp)
setne %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbe90
movl $0x4000, %edi           # imm = 0x4000
callq 0x43e0
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x50(%rsp)
setne %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbe90
movl $0x2000, %edi           # imm = 0x2000
callq 0x43e0
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
setne %al
movzbl %al, %edi
andl $0x1, %edi
movl $0x1, %esi
callq 0xbe90
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
leaq 0x134d5(%rip), %rcx     # 0x47430
cmpl (%rcx), %eax
jge 0x33ff7
movslq 0x44(%rsp), %rcx
leaq 0x134d1(%rip), %rax     # 0x47440
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movl 0x44(%rsp), %edx
movl $0x3, %edi
leaq 0x8105(%rip), %rsi      # 0x3c090
movb $0x0, %al
callq 0xbb80
movl $0x1, 0x40(%rsp)
cmpl $0x4, 0x40(%rsp)
jge 0x33fe5
movq 0x30(%rsp), %rax
movslq 0x40(%rsp), %rcx
movl 0x24(%rax,%rcx,4), %esi
leaq 0x1cbb41a(%rip), %rdi   # 0x1cef3d0
callq 0x19000
movq %rax, %rdx
movq 0x50(%rsp), %rax
movslq 0x44(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x40(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x33f9a
jmp 0x33fe7
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x33f50
movl $0x5, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jle 0x340f2
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x4a37b84(%rip)   # 0x4a6bba0
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
leaq 0x13401(%rip), %rcx     # 0x47430
cmpl (%rcx), %eax
jge 0x340cf
movl $0x1, 0x40(%rsp)
cmpl $0x4, 0x40(%rsp)
jge 0x340b4
movq 0x50(%rsp), %rax
movslq 0x44(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movl 0x3c(%rsp), %esi
movq 0x48(%rsp), %rdx
movslq 0x44(%rsp), %rax
shlq $0x4, %rax
addq %rax, %rdx
movslq 0x40(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdx
movq 0x60(%rsp), %rcx
movl 0x5c(%rsp), %r9d
movl $0x7fff, %r8d           # imm = 0x7FFF
leaq 0x5c(%rsp), %rax
movq %rax, (%rsp)
callq 0x19880
testb $0x1, %al
jne 0x340a5
jmp 0x340b4
jmp 0x340a7
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x3403f
cmpl $0x4, 0x40(%rsp)
jge 0x340bd
jmp 0x340cf
jmp 0x340bf
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x34024
movl 0x44(%rsp), %eax
leaq 0x13356(%rip), %rcx     # 0x47430
cmpl (%rcx), %eax
jne 0x340e0
jmp 0x340f2
jmp 0x340e2
movl 0x3c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x33fff
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
leaq 0x1332b(%rip), %rcx     # 0x47430
cmpl (%rcx), %eax
jge 0x34153
movl $0x1, 0x40(%rsp)
cmpl $0x4, 0x40(%rsp)
jge 0x34144
movq 0x50(%rsp), %rax
movslq 0x44(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x199f0
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x34111
jmp 0x34146
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x340fa
cmpl $0x0, 0x3c(%rsp)
jne 0x3416d
leaq 0x7f3a(%rip), %rdi      # 0x3c09b
movb $0x0, %al
callq 0xb980
jmp 0x34260
cmpl $0x5, 0x3c(%rsp)
je 0x34182
leaq 0x7f60(%rip), %rdi      # 0x3c0db
movb $0x0, %al
callq 0xb980
movl 0x4a37a18(%rip), %edx   # 0x4a6bba0
movl $0x3, %edi
leaq 0x7e29(%rip), %rsi      # 0x3bfbd
movb $0x0, %al
callq 0xbb80
leaq 0x1cbb21e(%rip), %rax   # 0x1cef3c0
movl (%rax), %esi
movl 0x5c(%rsp), %edx
leaq 0x7f71(%rip), %rdi      # 0x3c120
movb $0x0, %al
callq 0xb060
movl 0x5c(%rsp), %ecx
leaq 0x1cbb1ff(%rip), %rax   # 0x1cef3c0
movl %ecx, (%rax)
movq 0x60(%rsp), %rsi
movslq 0x5c(%rsp), %rdx
shlq $0x3, %rdx
leaq 0x1cbb1f8(%rip), %rdi   # 0x1cef3d0
callq 0x4260
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
leaq 0x13240(%rip), %rcx     # 0x47430
cmpl (%rcx), %eax
jge 0x3425e
movslq 0x44(%rsp), %rcx
leaq 0x13240(%rip), %rax     # 0x47440
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movl $0x1, 0x40(%rsp)
cmpl $0x4, 0x40(%rsp)
jge 0x3424f
movq 0x48(%rsp), %rax
movslq 0x44(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq 0x40(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x28(%rsp), %rax
movslq 0x40(%rsp), %rcx
movl %edx, 0x24(%rax,%rcx,4)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x34214
jmp 0x34251
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x341e5
jmp 0x34260
movq 0x50(%rsp), %rdi
callq 0x4370
movq 0x48(%rsp), %rdi
callq 0x4370
movq 0x60(%rsp), %rdi
callq 0x4370
leaq 0x20ba79b(%rip), %rdi   # 0x20eea20
callq 0x6360
leaq 0x20bb796(%rip), %rax   # 0x20efa27
testb $0x1, (%rax)
je 0x3429b
callq 0x6d60
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
leaq 0xafb106(%rip), %rcx    # 0xb2f3b4
cmpl (%rcx), %eax
jge 0x34364
movslq 0x24(%rsp), %rcx
leaq 0x20bb76e(%rip), %rax   # 0x20efa30
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movslq 0x24(%rsp), %rcx
leaq 0xafb0e6(%rip), %rax    # 0xb2f3c0
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movsd (%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x10(%rsp), %rax
movss %xmm0, (%rax)
movq 0x18(%rsp), %rax
movsd 0x8(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x10(%rsp), %rax
movss %xmm0, 0x4(%rax)
movq 0x18(%rsp), %rax
movsd 0x10(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x10(%rsp), %rax
movss %xmm0, 0x8(%rax)
movq 0x18(%rsp), %rax
movsd 0x30(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x10(%rsp), %rax
movss %xmm0, 0xc(%rax)
movq 0x18(%rsp), %rax
movl 0x38(%rax), %ecx
movq 0x10(%rsp), %rax
movl %ecx, 0x10(%rax)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x342a3
leaq 0x20b66b5(%rip), %rdi   # 0x20eaa20
callq 0x5b50
addq $0x118, %rsp            # imm = 0x118
retq
nopl (%rax,%rax)