// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
movl $0x0, (%rdx)
cmpb $0x23, 0x1(%rdi)
jne 0x6f22
movl %ecx, %ebp
movzbl 0x2(%rbx), %eax
cmpl $0x78, %eax
je 0x6fa7
testl %eax, %eax
jne 0x7035
movq %r14, 0x10(%rsp)
leaq 0x1(%rbx), %rax
movq %rax, 0x8(%rsp)
movl $0xc, %r15d
leaq 0x9243(%rip), %r14      # 0x10180
movq -0xc(%r15,%r14), %rbp
movl -0x4(%r15,%r14), %r13d
movq %rbp, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x30b0
testl %eax, %eax
je 0x6f73
addq $0x10, %r15
cmpq $0x5c, %r15
jne 0x6f3d
movb (%rbx), %al
movb %al, (%r12)
movq 0x8(%rsp), %r8
jmp 0x70b6
movq %rbp, %rdi
callq 0x30a0
cmpq %r13, %rax
jne 0x70c8
movb (%r15,%r14), %al
movb %al, (%r12)
movq 0x10(%rsp), %rax
movl $0x1, (%rax)
movl -0x4(%r15,%r14), %eax
addq %rax, %rbx
movq %rbx, %r8
jmp 0x70b6
cmpb $0x0, 0x3(%rbx)
je 0x705f
leaq 0x3(%rbx), %rdi
movl $0x3b, %esi
callq 0x3080
testq %rax, %rax
je 0x705f
cmpb $0x0, (%rax)
je 0x705f
movq %rax, %r13
subq %rbx, %r13
movb -0x1(%rax), %dl
cmpb $0x78, %dl
je 0x705b
addq $-0x2, %rax
movl $0x1, %ecx
xorl %r8d, %r8d
xorl %edi, %edi
leal -0x30(%rdx), %esi
cmpb $0x9, %sil
ja 0x6ffc
movzbl %sil, %edx
jmp 0x7020
leal -0x61(%rdx), %esi
cmpb $0x5, %sil
ja 0x700d
movzbl %dl, %edx
addl $-0x57, %edx
jmp 0x7020
leal -0x41(%rdx), %esi
cmpb $0x5, %sil
ja 0x70b6
movzbl %dl, %edx
addl $-0x37, %edx
imull %ecx, %edx
addq %rdx, %rdi
shll $0x4, %ecx
movb (%rax), %dl
decq %rax
cmpb $0x78, %dl
jne 0x6fed
jmp 0x7092
leaq 0x2(%rbx), %rdi
movl $0x3b, %esi
callq 0x3080
testq %rax, %rax
je 0x705f
cmpb $0x0, (%rax)
je 0x705f
movq %rax, %r13
subq %rbx, %r13
movb -0x1(%rax), %dl
cmpb $0x23, %dl
jne 0x7064
xorl %edi, %edi
jmp 0x7092
xorl %r8d, %r8d
jmp 0x70b6
addq $-0x2, %rax
movl $0x1, %ecx
xorl %r8d, %r8d
xorl %edi, %edi
addb $-0x30, %dl
cmpb $0x9, %dl
ja 0x70b6
movzbl %dl, %edx
imull %ecx, %edx
addq %rdx, %rdi
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
movb (%rax), %dl
decq %rax
cmpb $0x23, %dl
jne 0x7072
cmpl $0x1, %ebp
jne 0x70a4
movq %r12, %rsi
movq %r14, %rdx
callq 0x6acc
jmp 0x70af
movb %dil, (%r12)
movl $0x1, (%r14)
leaq (%rbx,%r13), %r8
incq %r8
movq %r8, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3624(%rip), %rdi      # 0xa6f3
leaq 0x355c(%rip), %rsi      # 0xa632
leaq 0x3645(%rip), %rcx      # 0xa722
movl $0x207, %edx            # imm = 0x207
callq 0x30e0
nop