// File: /workspace/github_cpp_makefile_star2_O2/halsafar[P]libtmx-parser/./libs/tinyxml2/tinyxml2.cpp
// Function: tinyxml2::XMLUtil::GetCharacterRef(char const*, char*, int*)
const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
{
    // Presume an entity, and pull it out.
    *length = 0;

    if ( *(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;
            }
        }
        // convert the UCS to UTF-8
        ConvertUTF32ToUTF8( ucs, value, length );
        return p + delta + 1;
    }
    return p+1;
}

// Assembly:
andl $0x0, (%rdx)
leaq 0x1(%rdi), %rax
cmpb $0x23, 0x1(%rdi)
jne 0xb36c
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %r14
movzbl 0x2(%rdi), %ecx
testl %ecx, %ecx
je 0xb364
movq %rdx, %rbx
movq %rsi, %r15
cmpl $0x78, %ecx
jne 0xb300
cmpb $0x0, 0x3(%r14)
je 0xb34e
leaq 0x3(%r14), %rdi
pushq $0x3b
popq %rsi
callq 0x40b0
testq %rax, %rax
je 0xb34e
movq %rax, %rcx
cmpb $0x0, (%rax)
je 0xb34e
movq %rcx, %r12
subq %r14, %r12
decq %rcx
pushq $0x1
popq %rdx
xorl %eax, %eax
xorl %edi, %edi
movzbl (%rcx), %esi
cmpl $0x78, %esi
je 0xb352
leal -0x30(%rsi), %r8d
cmpb $0x9, %r8b
ja 0xb2d6
movzbl %r8b, %esi
jmp 0xb2f2
leal -0x61(%rsi), %r8d
cmpb $0x5, %r8b
ja 0xb2e5
addl $-0x57, %esi
jmp 0xb2f2
leal -0x41(%rsi), %r8d
cmpb $0x5, %r8b
ja 0xb364
addl $-0x37, %esi
imull %edx, %esi
addq %rsi, %rdi
shll $0x4, %edx
decq %rcx
jmp 0xb2ba
leaq 0x2(%r14), %rdi
pushq $0x3b
popq %rsi
callq 0x40b0
testq %rax, %rax
je 0xb34e
movq %rax, %rcx
cmpb $0x0, (%rax)
je 0xb34e
movq %rcx, %r12
subq %r14, %r12
decq %rcx
pushq $0x1
popq %rdx
xorl %eax, %eax
xorl %edi, %edi
movb (%rcx), %sil
cmpb $0x23, %sil
je 0xb352
addb $-0x30, %sil
cmpb $0x9, %sil
ja 0xb364
movzbl %sil, %esi
imull %edx, %esi
addq %rsi, %rdi
imull $0xa, %edx, %edx
decq %rcx
jmp 0xb329
xorl %eax, %eax
jmp 0xb364
movq %r15, %rsi
movq %rbx, %rdx
callq 0xb392
leaq (%r14,%r12), %rax
incq %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop