// File: smallmuou[P]tinyhtml/tinyxmlparser.cpp
// Function: TiXmlBase::GetEntity(char const*, char*, int*, TiXmlEncoding)
const char* TiXmlBase::GetEntity( const char* p, char* value, int* length, TiXmlEncoding encoding )
{
	// Presume an entity, and pull it out.
    TIXML_STRING ent;
	int i;
	*length = 0;

	if ( *(p+1) && *(p+1) == '#' && *(p+2) )
	{
		unsigned long ucs = 0;
		ptrdiff_t delta = 0;
		unsigned mult = 1;

		if ( *(p+2) == 'x' )
		{
			// Hexadecimal.
			if ( !*(p+3) ) return 0;

			const char* q = p+3;
			q = strchr( q, ';' );

			if ( !q || !*q ) return 0;

			delta = q-p;
			--q;

			while ( *q != 'x' )
			{
				if ( *q >= '0' && *q <= '9' )
					ucs += mult * (*q - '0');
				else if ( *q >= 'a' && *q <= 'f' )
					ucs += mult * (*q - 'a' + 10);
				else if ( *q >= 'A' && *q <= 'F' )
					ucs += mult * (*q - 'A' + 10 );
				else 
					return 0;
				mult *= 16;
				--q;
			}
		}
		else
		{
			// Decimal.
			if ( !*(p+2) ) return 0;

			const char* q = p+2;
			q = strchr( q, ';' );

			if ( !q || !*q ) return 0;

			delta = q-p;
			--q;

			while ( *q != '#' )
			{
				if ( *q >= '0' && *q <= '9' )
					ucs += mult * (*q - '0');
				else 
					return 0;
				mult *= 10;
				--q;
			}
		}
		if ( encoding == TIXML_ENCODING_UTF8 )
		{
			// convert the UCS to UTF-8
			ConvertUTF32ToUTF8( ucs, value, length );
		}
		else
		{
			*value = (char)ucs;
			*length = 1;
		}
		return p + delta + 1;
	}

	// Now try to match it.
	for( i=0; i<NUM_ENTITY; ++i )
	{
		if ( strncmp( entity[i].str, p, entity[i].strLength ) == 0 )
		{
			assert( strlen( entity[i].str ) == entity[i].strLength );
			*value = entity[i].chr;
			*length = 1;
			return ( p + entity[i].strLength );
		}
	}

	// So it wasn't an entity, its unrecognized, or something like that.
	*value = *p;	// Don't put back the last one, since we return it!
	//*length = 1;	// Leave unrecognized entities - this doesn't really work.
					// Just writes strange XML.
	return p+1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x78a0
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x1(%rax)
je 0x9407
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x23, %eax
jne 0x9407
movq -0x10(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x9407
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x1, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x78, %eax
jne 0x92d6
movq -0x10(%rbp), %rax
cmpb $0x0, 0x3(%rax)
jne 0x918d
movq $0x0, -0x8(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x9528
movq -0x10(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movl $0x3b, %esi
callq 0x3080
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x91bb
movq -0x58(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x91cf
movq $0x0, -0x8(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x9528
movq -0x58(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x78, %eax
je 0x92d1
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jl 0x9231
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jg 0x9231
movl -0x4c(%rbp), %eax
movq -0x58(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x30, %ecx
imull %ecx, %eax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x92b7
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x61, %eax
jl 0x9268
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x66, %eax
jg 0x9268
movl -0x4c(%rbp), %eax
movq -0x58(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x61, %ecx
addl $0xa, %ecx
imull %ecx, %eax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x92b5
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x41, %eax
jl 0x929f
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x46, %eax
jg 0x929f
movl -0x4c(%rbp), %eax
movq -0x58(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x41, %ecx
addl $0xa, %ecx
imull %ecx, %eax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x92b3
movq $0x0, -0x8(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x9528
jmp 0x92b5
jmp 0x92b7
movl -0x4c(%rbp), %eax
shll $0x4, %eax
movl %eax, -0x4c(%rbp)
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x91ea
jmp 0x93bc
movq -0x10(%rbp), %rax
cmpb $0x0, 0x2(%rax)
jne 0x92f4
movq $0x0, -0x8(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x9528
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movl $0x3b, %esi
callq 0x3080
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x9322
movq -0x60(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x9336
movq $0x0, -0x8(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x9528
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x60(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0x93ba
movq -0x60(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jl 0x9391
movq -0x60(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jg 0x9391
movl -0x4c(%rbp), %eax
movq -0x60(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x30, %ecx
imull %ecx, %eax
movl %eax, %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x93a5
movq $0x0, -0x8(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x9528
imull $0xa, -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x60(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x9351
jmp 0x93bc
cmpl $0x1, -0x24(%rbp)
jne 0x93d5
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x8850
jmp 0x93eb
movq -0x40(%rbp), %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movq -0x10(%rbp), %rax
addq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x9528
movl $0x0, -0x34(%rbp)
cmpl $0x5, -0x34(%rbp)
jge 0x9509
movslq -0x34(%rbp), %rcx
leaq 0xad4d(%rip), %rax      # 0x14170
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movslq -0x34(%rbp), %rcx
leaq 0xad34(%rip), %rax      # 0x14170
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %edx
callq 0x30b0
cmpl $0x0, %eax
jne 0x94f9
movslq -0x34(%rbp), %rcx
leaq 0xad0f(%rip), %rax      # 0x14170
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x30a0
movslq -0x34(%rbp), %rdx
leaq 0xacf5(%rip), %rcx      # 0x14170
shlq $0x4, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jne 0x948c
jmp 0x94ab
leaq 0x5687(%rip), %rdi      # 0xeb1a
leaq 0x55b9(%rip), %rsi      # 0xea53
movl $0x207, %edx            # imm = 0x207
leaq 0x56a3(%rip), %rcx      # 0xeb49
callq 0x30e0
movslq -0x34(%rbp), %rcx
leaq 0xacba(%rip), %rax      # 0x14170
shlq $0x4, %rcx
addq %rcx, %rax
movb 0xc(%rax), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rdx
leaq 0xac91(%rip), %rcx      # 0x14170
shlq $0x4, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x50(%rbp)
jmp 0x9528
jmp 0x94fb
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x940e
movq -0x10(%rbp), %rax
movb (%rax), %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x50(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x78c0
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)