// File: /workspace/github_cpp_makefile_star2_O2/FreeSlave[P]vhlt/ripent/ripent.cpp
// Function: ParseEntityData(char const*, int, char const*, int, char const*, int)
void ParseEntityData(const char *cTab, int iTabLength, const char *cNewLine, int iNewLineLength, const char *cTerminator, int iTerminatorLength)
{
	CEntityList EntityList;		// Parsed entities.

	int iIndex = 0;				// Current char in g_dentdata.
	int iLine = 0;				// Current line in g_dentdata.

	char cError[256] = "";

	try
	{
		//
		// Parse entity data.
		//

		Log("\nParsing entity data.\n");

		while(true)
		{
			// Parse the start of an entity.
			if(!ScanForToken('{', iIndex, iLine, false, false))
			{
				if(iIndex == g_entdatasize)
				{
					// We read all the entities.
					break;
				}
				else
				{
					sprintf_s(cError, "expected token %s on line %d.", "{", iLine);
					throw cError;
				}
			}

			CEntityPairList *EntityPairList = new CEntityPairList();

			// Parse the rest of the entity.
			while(true)
			{
				// Parse the key and value.
				for(int j = 0; j < 2; j++)
				{
					int iStart;
					// Parse the start of a string.
					if(!ScanForToken('\"', iIndex, iLine, false, false, &iStart))
					{
						sprintf_s(cError, "expected token %s on line %d.", "\"", iLine);
						throw cError;
					}

					int iEnd;
					// Parse the end of a string.
					if(!ScanForToken('\"', iIndex, iLine, true, true, &iEnd))
					{
						sprintf_s(cError, "expected token %s on line %d.", "\"", iLine);
						throw cError;
					}

					// Extract the string.
					int iLength = iEnd - iStart - 1;
					char *cString = new char[iLength + 1];
					memcpy(cString, &g_dentdata[iStart + 1], iLength);
					cString[iLength] = '\0';

					// Save it.
					EntityPairList->push_back(cString);
				}

				// Parse the end of an entity.
				if(!ScanForToken('}', iIndex, iLine, false, false))
				{
					if(g_dentdata[iIndex] == '\"')
					{
						// We arn't done the entity yet.
						continue;
					}
					else
					{
						sprintf_s(cError, "expected token %s on line %d.", "}", iLine);
						throw cError;
					}
				}

				// We read the entity.
				EntityList.push_back(EntityPairList);
				break;
			}
		}

#ifdef ZHLT_64BIT_FIX
		Log("%d entities parsed.\n", (int)EntityList.size());
#else
		Log("%d entities parsed.\n", EntityList.size());
#endif

		//
		// Calculate new data length.
		//

		int iNewLength = 0;

		for(CEntityList::iterator i = EntityList.begin(); i != EntityList.end(); ++i)
		{
			// Opening brace.
			iNewLength += 1;

			// New line.
			iNewLength += iNewLineLength;

			CEntityPairList *EntityPairList = *i;

			for(CEntityPairList::iterator j = EntityPairList->begin(); j != EntityPairList->end(); ++j)
			{
				// Tab.
				iNewLength += iTabLength;

				// String.
				iNewLength += 1;
				iNewLength += (int)strlen(*j);
				iNewLength += 1;

				// String seperator.
				iNewLength += 1;

				++j;

				// String.
				iNewLength += 1;
				iNewLength += (int)strlen(*j);
				iNewLength += 1;

				// New line.
				iNewLength += iNewLineLength;
			}

			// Closing brace.
			iNewLength += 1;

			// New line.
			iNewLength += iNewLineLength;
		}

		// Terminator.
		iNewLength += iTerminatorLength;

		//
		// Check our parsed data.
		//

		assume(iNewLength != 0, "No entity data.");
		assume(iNewLength < sizeof(g_dentdata), "Entity data size exceedes dentdata limit.");

		//
		// Clear current data.
		//

		g_entdatasize = 0;

		//
		// Fill new data.
		//

		Log("Formating entity data.\n\n");

		for(CEntityList::iterator i = EntityList.begin(); i != EntityList.end(); ++i)
		{
			// Opening brace.
			g_dentdata[g_entdatasize] = '{';
			g_entdatasize += 1;

			// New line.
			memcpy(&g_dentdata[g_entdatasize], cNewLine, iNewLineLength);
			g_entdatasize += iNewLineLength;

			CEntityPairList *EntityPairList = *i;

			for(CEntityPairList::iterator j = EntityPairList->begin(); j != EntityPairList->end(); ++j)
			{
				// Tab.
				memcpy(&g_dentdata[g_entdatasize], cTab, iTabLength);
				g_entdatasize += iTabLength;

				// String.
				g_dentdata[g_entdatasize] = '\"';
				g_entdatasize += 1;
				memcpy(&g_dentdata[g_entdatasize], *j, strlen(*j));
				g_entdatasize += (int)strlen(*j);
				g_dentdata[g_entdatasize] = '\"';
				g_entdatasize += 1;

				// String seperator.
				g_dentdata[g_entdatasize] = ' ';
				g_entdatasize += 1;

				++j;

				// String.
				g_dentdata[g_entdatasize] = '\"';
				g_entdatasize += 1;
				memcpy(&g_dentdata[g_entdatasize], *j, strlen(*j));
				g_entdatasize += (int)strlen(*j);
				g_dentdata[g_entdatasize] = '\"';
				g_entdatasize += 1;

				// New line.
				memcpy(&g_dentdata[g_entdatasize], cNewLine, iNewLineLength);
				g_entdatasize += iNewLineLength;
			}

			// Closing brace.
			g_dentdata[g_entdatasize] = '}';
			g_entdatasize += 1;

			// New line.
			memcpy(&g_dentdata[g_entdatasize], cNewLine, iNewLineLength);
			g_entdatasize += iNewLineLength;
		}

		// Terminator.
		memcpy(&g_dentdata[g_entdatasize], cTerminator, iTerminatorLength);
		g_entdatasize += iTerminatorLength;

		//
		// Delete entity data.
		//

		for(CEntityList::iterator i = EntityList.begin(); i != EntityList.end(); ++i)
		{
			CEntityPairList *EntityPairList = *i;

			for(CEntityPairList::iterator j = EntityPairList->begin(); j != EntityPairList->end(); ++j)
			{
				delete []*j;
			}

			delete EntityPairList;
		}

		//return true;
	}
	catch(...)
	{
		//
		// Delete entity data.
		//

		for(CEntityList::iterator i = EntityList.begin(); i != EntityList.end(); ++i)
		{
			CEntityPairList *EntityPairList = *i;

			for(CEntityPairList::iterator j = EntityPairList->begin(); j != EntityPairList->end(); ++j)
			{
				delete []*j;
			}

			delete EntityPairList;
		}

		// If we threw the error cError wont be null, this is
		// a message, print it.
		if(*cError != '\0')
		{
			Error(cError);
		}
		Error("unknowen exception.");

		//return false;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movl %r9d, 0x1c(%rsp)
movq %r8, 0x60(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x28(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
movq %rsi, 0x20(%rsp)
andl $0x0, 0x4(%rsp)
movq %rdi, 0x78(%rsp)
andl $0x0, (%rsp)
leaq 0x90(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x3170
leaq 0x5342(%rip), %rdi      # 0x103e0
xorl %eax, %eax
callq 0x7620
leaq 0x4(%rsp), %rbx
movq %rsp, %r14
pushq $0x22
popq %rbp
pushq $0x7b
popq %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xaf84
testb %al, %al
je 0xb1e6
pushq $0x18
popq %rdi
callq 0x3290
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
movq %rax, 0x50(%rsp)
xorl %r15d, %r15d
cmpl $0x2, %r15d
jne 0xb12b
pushq $0x7d
popq %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xaf84
testb %al, %al
jne 0xb1d2
movslq 0x4(%rsp), %rax
leaq 0x814226(%rip), %rcx    # 0x81f340
cmpb $0x22, (%rcx,%rax)
movl $0x0, %r15d
je 0xb0ea
jmp 0xb5c0
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0x34(%rsp), %r9
callq 0xaf84
testb %al, %al
je 0xb57c
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
pushq $0x1
popq %rcx
movl %ecx, %r8d
leaq 0x30(%rsp), %r9
callq 0xaf84
testb %al, %al
je 0xb538
movq %rbx, %r14
movl %ebp, %ebx
movslq 0x30(%rsp), %r12
movslq 0x34(%rsp), %rbp
subq %rbp, %r12
movq %r12, %rdi
callq 0x3040
movq %rax, %r13
leaq -0x1(%r12), %rdx
movq %rax, 0x88(%rsp)
leaq 0x8141a5(%rip), %rax    # 0x81f340
leaq (%rax,%rbp), %rsi
incq %rsi
movq %r13, %rdi
callq 0x3200
movb $0x0, -0x1(%r13,%r12)
movq 0x50(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0xc9f0
incl %r15d
movl %ebx, %ebp
movq %r14, %rbx
movq %rsp, %r14
jmp 0xb0ea
leaq 0x38(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xc9fc
jmp 0xb0b0
movl 0x4(%rsp), %eax
leaq 0x814143(%rip), %rcx    # 0x81f334
cmpl (%rcx), %eax
jne 0xb601
movl 0x48(%rsp), %esi
leaq 0x5217(%rip), %rdi      # 0x1041b
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x7620
movq 0x10(%rsp), %rax
leal 0x1(%rax), %r15d
movq 0x20(%rsp), %rax
leal 0x4(%rax), %r12d
leaq 0x38(%rsp), %rcx
movq (%rcx), %rcx
leaq 0x38(%rsp), %rax
cmpq %rax, %rcx
je 0xb278
movq %rcx, 0x8(%rsp)
movq 0x10(%rcx), %r13
movq %r13, %rbp
movq (%rbp), %rbp
addl %r15d, %r14d
cmpq %r13, %rbp
je 0xb26e
movq 0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rbx
movq (%rbp), %rbp
movq 0x10(%rbp), %rdi
callq 0x3130
addl %r12d, %r14d
addl %ebx, %r14d
addl %eax, %r14d
jmp 0xb23e
addl %r15d, %r14d
movq 0x8(%rsp), %rcx
jmp 0xb225
addl 0x1c(%rsp), %r14d
je 0xb2a4
cmpl $0x200000, %r14d        # imm = 0x200000
leaq 0x8140b3(%rip), %r15    # 0x81f340
jb 0xb2d3
leaq 0x5210(%rip), %r8       # 0x104a6
movl $0x117, %ecx            # imm = 0x117
leaq 0x51e4(%rip), %rsi      # 0x10486
jmp 0xb2be
leaq 0x51cb(%rip), %r8       # 0x10476
movl $0x116, %ecx            # imm = 0x116
leaq 0x519d(%rip), %rsi      # 0x10454
leaq 0x814082(%rip), %r15    # 0x81f340
leaq 0x516b(%rip), %rdi      # 0x10430
leaq 0x5198(%rip), %rdx      # 0x10464
xorl %eax, %eax
callq 0x79bf
leaq 0x81405a(%rip), %rax    # 0x81f334
andl $0x0, (%rax)
leaq 0x51ec(%rip), %rdi      # 0x104d0
xorl %eax, %eax
callq 0x7620
leaq 0x38(%rsp), %r12
movq (%r12), %rcx
leaq 0x814039(%rip), %rax    # 0x81f334
movl (%rax), %ebx
movslq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movslq 0x20(%rsp), %rax
movq %rax, 0x70(%rsp)
movq %rcx, 0x58(%rsp)
movq %rcx, %r13
movslq %ebx, %r14
leaq (%r14,%r15), %rdi
cmpq %r12, %r13
je 0xb4d3
movb $0x7b, (%rdi)
leal 0x1(%r14), %eax
leaq 0x813ffd(%rip), %rbx    # 0x81f334
movl %eax, (%rbx)
leaq (%r14,%r15), %rdi
incq %rdi
movq 0x28(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3200
movq 0x10(%rsp), %rax
leal (%r14,%rax), %r12d
incl %r12d
movl %r12d, (%rbx)
movq %r13, 0x68(%rsp)
movq 0x10(%r13), %rbp
movq %rbp, 0x80(%rsp)
movq (%rbp), %rbp
movslq %r12d, %rax
leaq (%rax,%r15), %rdi
cmpq 0x80(%rsp), %rbp
je 0xb48a
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x3200
movq 0x20(%rsp), %rcx
leal (%r12,%rcx), %eax
movslq %eax, %r13
leaq 0x813f96(%rip), %rax    # 0x81f340
leaq 0x1(%rax,%r13), %r15
movb $0x22, %al
movb %al, -0x1(%r15)
leal 0x1(%r12,%rcx), %eax
leaq 0x813f73(%rip), %r14    # 0x81f334
movl %eax, (%r14)
movq 0x10(%rbp), %r12
movq %r12, %rdi
callq 0x3130
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x3200
movq 0x10(%rbp), %rdi
callq 0x3130
leal (%rax,%r13), %ecx
incl %ecx
movslq %ecx, %rbx
leaq 0x813f49(%rip), %rcx    # 0x81f340
leaq 0x3(%rcx,%rbx), %r15
movw $0x2022, -0x3(%r15)     # imm = 0x2022
leaq 0x2(%rbx), %rcx
movl %ecx, (%r14)
movq (%rbp), %rbp
movb $0x22, %cl
movb %cl, -0x1(%r15)
leal 0x4(%rax,%r13), %eax
movl %eax, (%r14)
movq 0x10(%rbp), %r12
movq %r12, %rdi
callq 0x3130
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x3200
movq 0x10(%rbp), %rdi
callq 0x3130
leal (%rax,%rbx), %ecx
addl $0x3, %ecx
movslq %ecx, %r15
leaq 0x813ef1(%rip), %rcx    # 0x81f340
leaq 0x1(%rcx,%r15), %rdi
movb $0x22, %cl
movb %cl, -0x1(%rdi)
leal 0x4(%rax,%rbx), %eax
movl %eax, (%r14)
movq 0x28(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3200
movq 0x10(%rsp), %rax
leal (%rax,%r15), %r12d
incl %r12d
leaq 0x813ebe(%rip), %r15    # 0x81f340
movl %r12d, (%r14)
jmp 0xb36f
movb $0x7d, (%rdi)
leal 0x1(%r12), %ecx
leaq 0x813e9b(%rip), %r14    # 0x81f334
movl %ecx, (%r14)
leaq (%rax,%r15), %rdi
incq %rdi
movq 0x28(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3200
movq 0x10(%rsp), %rax
leal (%r12,%rax), %ebx
incl %ebx
movl %ebx, (%r14)
movq 0x68(%rsp), %r13
movq (%r13), %r13
leaq 0x38(%rsp), %r12
jmp 0xb319
movl 0x1c(%rsp), %ebp
movslq %ebp, %rdx
movq 0x60(%rsp), %rsi
callq 0x3200
addl %ebp, %ebx
leaq 0x813e47(%rip), %rax    # 0x81f334
movl %ebx, (%rax)
pushq $0x18
popq %rbx
movq 0x58(%rsp), %r13
cmpq %r12, %r13
je 0xb6cb
movq 0x10(%r13), %r14
movq %r14, %r15
movq (%r15), %r15
cmpq %r14, %r15
je 0xb51f
movq 0x10(%r15), %rdi
testq %rdi, %rdi
je 0xb507
callq 0x3370
jmp 0xb507
movq %r14, %rdi
callq 0xca12
movq %r14, %rdi
movq %rbx, %rsi
callq 0x32a0
movq (%r13), %r13
jmp 0xb4f7
movl (%rsp), %ecx
leaq 0x4eb5(%rip), %rsi      # 0x103f7
leaq 0x4ece(%rip), %rdx      # 0x10417
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30a0
pushq $0x8
popq %rdi
callq 0x3160
movq %rbx, (%rax)
movq 0xaa83(%rip), %rsi      # 0x15ff0
movq %rax, %rdi
xorl %edx, %edx
callq 0x3480
jmp 0xb640
movl (%rsp), %ecx
leaq 0x4e71(%rip), %rsi      # 0x103f7
leaq 0x4e8a(%rip), %rdx      # 0x10417
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30a0
pushq $0x8
popq %rdi
callq 0x3160
movq %rbx, (%rax)
movq 0xaa3f(%rip), %rsi      # 0x15ff0
movq %rax, %rdi
xorl %edx, %edx
callq 0x3480
jmp 0xb640
movl (%rsp), %ecx
leaq 0x4e2d(%rip), %rsi      # 0x103f7
leaq 0x4e48(%rip), %rdx      # 0x10419
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30a0
pushq $0x8
popq %rdi
callq 0x3160
movq %rbx, (%rax)
movq 0xa9fb(%rip), %rsi      # 0x15ff0
movq %rax, %rdi
xorl %edx, %edx
callq 0x3480
jmp 0xb640
movl (%rsp), %ecx
leaq 0x4dec(%rip), %rsi      # 0x103f7
leaq 0x4e03(%rip), %rdx      # 0x10415
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30a0
pushq $0x8
popq %rdi
callq 0x3160
movq %rbx, (%rax)
movq 0xa9ba(%rip), %rsi      # 0x15ff0
movq %rax, %rdi
xorl %edx, %edx
callq 0x3480
jmp 0xb64c
jmp 0xb64c
jmp 0xb64c
jmp 0xb64c
jmp 0xb64c
jmp 0xb64c
movq %rax, %rdi
callq 0x3120
pushq $0x18
popq %rbx
leaq 0x38(%rsp), %r15
movq (%r15), %r15
leaq 0x38(%rsp), %rax
cmpq %rax, %r15
je 0xb69f
movq 0x10(%r15), %r14
movq %r14, %r12
movq (%r12), %r12
cmpq %r14, %r12
je 0xb68a
movq 0x10(%r12), %rdi
testq %rdi, %rdi
je 0xb670
callq 0x3370
jmp 0xb670
movq %r14, %rdi
callq 0xca12
movq %r14, %rdi
movq %rbx, %rsi
callq 0x32a0
jmp 0xb65c
cmpb $0x0, 0x90(%rsp)
je 0xb6b8
leaq 0x90(%rsp), %rdi
xorl %eax, %eax
callq 0x79bf
leaq 0x4e2a(%rip), %rdi      # 0x104e9
xorl %eax, %eax
callq 0x79bf
callq 0x3470
leaq 0x38(%rsp), %rdi
callq 0xca3c
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0xb6f4
movq %rax, %rbx
callq 0x3470
leaq 0x38(%rsp), %rdi
callq 0xca3c
movq %rbx, %rdi
callq 0x3490
movq %rax, %rdi
callq 0xca07