// File: /workspace/github_cpp_makefile_star2_O3/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 $0x188, %rsp            # imm = 0x188
movl %r9d, 0xc(%rsp)
movq %r8, 0x50(%rsp)
movl %ecx, %ebx
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %r12
leaq 0x20(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
xorl %eax, %eax
movl %eax, 0x8(%rsp)
movl %eax, 0x4(%rsp)
leaq 0x80(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x3160
leaq 0x5b32(%rip), %rdi      # 0x12480
xorl %eax, %eax
callq 0x89f6
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
movl $0x7b, %edi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xc82c
testb %al, %al
movq %rbx, 0x18(%rsp)
movq %r14, 0x40(%rsp)
movq %r15, 0x38(%rsp)
movq %r12, 0x70(%rsp)
je 0xcafd
leaq 0x81398c(%rip), %rbp    # 0x820320
movl $0x18, %edi
callq 0x3270
movq %rax, %r12
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
movb $0x1, %r14b
movl $0x22, %edi
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0x4c(%rsp), %r9
callq 0xc82c
testb %al, %al
je 0xcf30
movslq 0x8(%rsp), %r13
leaq 0x81392f(%rip), %rax    # 0x820314
movl (%rax), %eax
movl 0x4(%rsp), %ecx
cmpl %eax, %r13d
jge 0xceed
movzbl (%rbp,%r13), %edx
cmpl $0xa, %edx
je 0xca0d
cmpl $0x22, %edx
je 0xca1c
testl %edx, %edx
jne 0xca0f
jmp 0xcee5
incl %ecx
incq %r13
cmpl %eax, %r13d
jl 0xc9f4
jmp 0xceda
movl %ecx, 0x4(%rsp)
leal 0x1(%r13), %eax
movl %eax, 0x8(%rsp)
movslq 0x4c(%rsp), %rbx
movq %r13, %rdi
subq %rbx, %rdi
callq 0x3040
movq %rax, %r15
movl %ebx, %eax
notl %eax
addl %r13d, %eax
leaq (%rbx,%rbp), %rsi
incq %rsi
movslq %eax, %r13
movq %r15, %rdi
movq %r13, %rdx
callq 0x31e0
movb $0x0, (%r15,%r13)
movl $0x18, %edi
callq 0x3270
movq %r15, 0x10(%rax)
movq %rax, %rdi
movq %r12, %rsi
callq 0x3070
incq 0x10(%r12)
testb $0x1, %r14b
jne 0xcab0
movl $0x7d, %edi
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xc82c
testb %al, %al
jne 0xcab9
movslq 0x8(%rsp), %rax
cmpb $0x22, (%rbp,%rax)
jne 0xcf77
xorb $0x1, %r14b
jmp 0xc9b3
movl $0x18, %edi
callq 0x3270
movq %r12, 0x10(%rax)
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0x3070
incq 0x30(%rsp)
movl $0x7b, %edi
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xc82c
testb %al, %al
jne 0xc994
movl 0x8(%rsp), %eax
leaq 0x81380c(%rip), %rcx    # 0x820314
cmpl (%rcx), %eax
jne 0xcfbb
movl 0x30(%rsp), %esi
leaq 0x59a0(%rip), %rdi      # 0x124bb
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x89f6
movq 0x20(%rsp), %rcx
leaq 0x20(%rsp), %rax
cmpq %rax, %rcx
je 0xcb9a
movq 0x18(%rsp), %rax
leal 0x1(%rax), %r15d
movq 0x38(%rsp), %rax
leal 0x4(%rax), %r12d
xorl %ebp, %ebp
movq %rcx, 0x10(%rsp)
movq 0x10(%rcx), %r13
movq (%r13), %r14
addl %r15d, %ebp
cmpq %r13, %r14
je 0xcb85
addl %r12d, %ebp
movq 0x10(%r14), %rdi
callq 0x3120
movq %rax, %rbx
movq (%r14), %r14
movq 0x10(%r14), %rdi
callq 0x3120
addl %ebp, %ebx
movq (%r14), %r14
addl %r15d, %ebx
addl %eax, %ebx
movl %ebx, %ebp
jmp 0xcb57
addl %r15d, %ebp
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
leaq 0x20(%rsp), %rax
cmpq %rax, %rcx
jne 0xcb47
addl 0xc(%rsp), %ebp
je 0xcbce
cmpl $0x200000, %ebp         # imm = 0x200000
leaq 0x20(%rsp), %r13
movq 0x18(%rsp), %r14
leaq 0x81375d(%rip), %r12    # 0x820314
jb 0xcc07
leaq 0x5986(%rip), %r8       # 0x12546
movl $0x117, %ecx            # imm = 0x117
leaq 0x595a(%rip), %rsi      # 0x12526
jmp 0xcbf2
leaq 0x5941(%rip), %r8       # 0x12516
movl $0x116, %ecx            # imm = 0x116
leaq 0x5913(%rip), %rsi      # 0x124f4
leaq 0x20(%rsp), %r13
movq 0x18(%rsp), %r14
leaq 0x813722(%rip), %r12    # 0x820314
leaq 0x58d7(%rip), %rdi      # 0x124d0
leaq 0x5904(%rip), %rdx      # 0x12504
xorl %eax, %eax
callq 0x8ce4
movl $0x0, (%r12)
leaq 0x595a(%rip), %rdi      # 0x12570
xorl %eax, %eax
callq 0x89f6
movq 0x20(%rsp), %rax
movl (%r12), %ebx
cmpq %r13, %rax
je 0xce85
movslq %r14d, %rcx
movq %rcx, 0x10(%rsp)
movslq 0x38(%rsp), %r15
movq %rax, 0x58(%rsp)
movq %rax, %r13
movq %r15, 0x68(%rsp)
movslq %ebx, %rbx
leaq 0x8136cd(%rip), %rax    # 0x820320
leaq (%rax,%rbx), %rdi
incq %rdi
movb $0x7b, -0x1(%rdi)
leal 0x1(%rbx), %eax
movl %eax, (%r12)
movq 0x40(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x31e0
leal (%rbx,%r14), %eax
incl %eax
movl %eax, (%r12)
movq %r13, 0x60(%rsp)
movq 0x10(%r13), %rcx
movq (%rcx), %r13
movq %rcx, 0x78(%rsp)
cmpq %rcx, %r13
je 0xcdb4
movslq %eax, %rbx
leaq 0x81367e(%rip), %rbp    # 0x820320
leaq (%rbx,%rbp), %rdi
movq 0x70(%rsp), %rsi
movq %r15, %rdx
callq 0x31e0
movq 0x38(%rsp), %rcx
leal (%rbx,%rcx), %eax
movslq %eax, %r14
leaq (%r14,%rbp), %r15
incq %r15
movb $0x22, %al
movb %al, -0x1(%r15)
leal 0x1(%rbx,%rcx), %eax
movl %eax, (%r12)
movq 0x10(%r13), %r12
movq %r12, %rdi
callq 0x3120
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x31e0
movq 0x10(%r13), %rdi
callq 0x3120
leal (%rax,%r14), %ecx
incl %ecx
movslq %ecx, %rbx
leaq 0x3(%rbp,%rbx), %r15
movw $0x2022, -0x3(%r15)     # imm = 0x2022
leaq 0x2(%rbx), %rcx
leaq 0x8135fe(%rip), %rdx    # 0x820314
movl %ecx, (%rdx)
movq (%r13), %r13
movb $0x22, %cl
movb %cl, -0x1(%r15)
leal 0x4(%rax,%r14), %eax
leaq 0x8135e6(%rip), %rcx    # 0x820314
movl %eax, (%rcx)
movq 0x10(%r13), %r12
movq %r12, %rdi
callq 0x3120
movq %r15, %rdi
movq 0x68(%rsp), %r15
movb $0x22, %bpl
movq %r12, %rsi
leaq 0x8135c3(%rip), %r12    # 0x820314
movq %rax, %rdx
callq 0x31e0
movq 0x10(%r13), %rdi
callq 0x3120
leal (%rax,%rbx), %ecx
addl $0x3, %ecx
movslq %ecx, %r14
leaq 0x8135ae(%rip), %rcx    # 0x820320
leaq 0x1(%rcx,%r14), %rdi
movb %bpl, -0x1(%rdi)
leal 0x4(%rax,%rbx), %eax
movl %eax, (%r12)
movq 0x40(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x31e0
movq 0x18(%rsp), %rax
addl %r14d, %eax
incl %eax
movq 0x18(%rsp), %r14
movl %eax, (%r12)
movq (%r13), %r13
cmpq 0x78(%rsp), %r13
jne 0xcc98
movslq %eax, %rbx
leaq 0x813562(%rip), %rax    # 0x820320
leaq (%rax,%rbx), %rdi
incq %rdi
movb $0x7d, -0x1(%rdi)
leal 0x1(%rbx), %eax
movl %eax, (%r12)
movq 0x40(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x31e0
addl %r14d, %ebx
incl %ebx
movl %ebx, (%r12)
movq 0x60(%rsp), %r13
movq (%r13), %r13
leaq 0x20(%rsp), %rax
cmpq %rax, %r13
jne 0xcc49
movslq %ebx, %rdi
addq 0xa1a7(%rip), %rdi      # 0x16fb0
movl 0xc(%rsp), %ebp
movslq %ebp, %rdx
movq 0x50(%rsp), %rsi
callq 0x31e0
addl %ebp, %ebx
movl %ebx, (%r12)
leaq 0x20(%rsp), %r13
movq 0x58(%rsp), %r12
cmpq %r13, %r12
je 0xcea9
movq 0x10(%r12), %rbx
movq (%rbx), %r14
cmpq %rbx, %r14
je 0xce55
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0xce4a
callq 0x3340
movq (%r14), %r14
cmpq %rbx, %r14
jne 0xce3c
movq (%rbx), %r14
cmpq %rbx, %r14
je 0xce72
movq (%r14), %r15
movl $0x18, %esi
movq %r14, %rdi
callq 0x3280
movq %r15, %r14
cmpq %rbx, %r15
jne 0xce5a
movl $0x18, %esi
movq %rbx, %rdi
callq 0x3280
movq (%r12), %r12
jmp 0xce2a
movslq %ebx, %rbx
leaq 0x813491(%rip), %rdi    # 0x820320
addq %rbx, %rdi
movl 0xc(%rsp), %ebp
movslq %ebp, %rdx
movq 0x50(%rsp), %rsi
callq 0x31e0
addl %ebp, %ebx
movl %ebx, (%r12)
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0xcec8
movq (%rdi), %rbx
movl $0x18, %esi
callq 0x3280
movq %rbx, %rdi
cmpq %r13, %rbx
jne 0xceb3
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, 0x4(%rsp)
movl %r13d, 0x8(%rsp)
jmp 0xceed
movl %ecx, 0x4(%rsp)
movl %eax, 0x8(%rsp)
leaq 0x55a3(%rip), %rsi      # 0x12497
leaq 0x55bc(%rip), %rdx      # 0x124b7
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30a0
movl $0x8, %edi
callq 0x3150
movq %rbx, (%rax)
movq 0xa0c7(%rip), %rsi      # 0x16fe8
movq %rax, %rdi
xorl %edx, %edx
callq 0x3450
jmp 0xcffd
movl 0x4(%rsp), %ecx
leaq 0x555c(%rip), %rsi      # 0x12497
leaq 0x5575(%rip), %rdx      # 0x124b7
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30a0
movl $0x8, %edi
callq 0x3150
movq %rbx, (%rax)
movq 0xa080(%rip), %rsi      # 0x16fe8
movq %rax, %rdi
xorl %edx, %edx
callq 0x3450
jmp 0xcffd
movl 0x4(%rsp), %ecx
leaq 0x5515(%rip), %rsi      # 0x12497
leaq 0x5530(%rip), %rdx      # 0x124b9
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30a0
movl $0x8, %edi
callq 0x3150
movq %rbx, (%rax)
movq 0xa039(%rip), %rsi      # 0x16fe8
movq %rax, %rdi
xorl %edx, %edx
callq 0x3450
jmp 0xcffd
movl 0x4(%rsp), %ecx
leaq 0x54d1(%rip), %rsi      # 0x12497
leaq 0x54e8(%rip), %rdx      # 0x124b5
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x30a0
movl $0x8, %edi
callq 0x3150
movq %rbx, (%rax)
movq 0x9ff5(%rip), %rsi      # 0x16fe8
movq %rax, %rdi
xorl %edx, %edx
callq 0x3450
jmp 0xd009
jmp 0xd009
jmp 0xd009
jmp 0xd009
jmp 0xd009
jmp 0xd009
movq %rax, %rdi
callq 0x3110
movq 0x20(%rsp), %r15
leaq 0x20(%rsp), %r13
cmpq %r13, %r15
je 0xd074
movq 0x10(%r15), %rbx
movq (%rbx), %r14
cmpq %rbx, %r14
je 0xd045
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0xd03a
callq 0x3340
movq (%r14), %r14
cmpq %rbx, %r14
jne 0xd02c
movq (%rbx), %r14
cmpq %rbx, %r14
je 0xd062
movq (%r14), %r12
movl $0x18, %esi
movq %r14, %rdi
callq 0x3280
movq %r12, %r14
cmpq %rbx, %r12
jne 0xd04a
movl $0x18, %esi
movq %rbx, %rdi
callq 0x3280
movq (%r15), %r15
jmp 0xd01b
cmpb $0x0, 0x80(%rsp)
je 0xd08d
leaq 0x80(%rsp), %rdi
xorl %eax, %eax
callq 0x8ce4
leaq 0x54f5(%rip), %rdi      # 0x12589
xorl %eax, %eax
callq 0x8ce4
callq 0x3440
jmp 0xcea9
movq %rax, %rbx
jmp 0xd0b2
movq %rax, %rbx
callq 0x3440
movq 0x20(%rsp), %rdi
leaq 0x20(%rsp), %r15
cmpq %r15, %rdi
je 0xd0d6
movq (%rdi), %r14
movl $0x18, %esi
callq 0x3280
movq %r14, %rdi
cmpq %r15, %r14
jne 0xd0c1
movq %rbx, %rdi
callq 0x3460
movq %rax, %rdi
callq 0xe409