// File: /workspace/github_cpp_makefile_star2_O3/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:
movl $0x0, (%rdx)
leaq 0x1(%rdi), %rax
cmpb $0x23, 0x1(%rdi)
jne 0xcc75
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movzbl 0x2(%rdi), %ecx
testl %ecx, %ecx
je 0xcc6d
movq %rdx, %r14
movq %rsi, %r15
cmpl $0x78, %ecx
jne 0xcbf6
cmpb $0x0, 0x3(%rbx)
je 0xcc25
leaq 0x3(%rbx), %rdi
movl $0x3b, %esi
callq 0x40c0
testq %rax, %rax
je 0xcc25
movq %rax, %rcx
cmpb $0x0, (%rax)
je 0xcc25
movq %rcx, %r12
subq %rbx, %r12
movb -0x1(%rcx), %sil
cmpb $0x78, %sil
je 0xcc21
addq $-0x2, %rcx
movl $0x1, %edx
xorl %eax, %eax
xorl %edi, %edi
leal -0x30(%rsi), %r8d
cmpb $0x9, %r8b
ja 0xcbb7
movzbl %r8b, %esi
jmp 0xcbdf
leal -0x61(%rsi), %r8d
cmpb $0x5, %r8b
ja 0xcbca
movzbl %sil, %esi
addl $-0x57, %esi
jmp 0xcbdf
leal -0x41(%rsi), %r8d
cmpb $0x5, %r8b
ja 0xcc6d
movzbl %sil, %esi
addl $-0x37, %esi
imull %edx, %esi
addq %rsi, %rdi
shll $0x4, %edx
movb (%rcx), %sil
decq %rcx
cmpb $0x78, %sil
jne 0xcba7
jmp 0xcc5b
leaq 0x2(%rbx), %rdi
movl $0x3b, %esi
callq 0x40c0
testq %rax, %rax
je 0xcc25
movq %rax, %rcx
cmpb $0x0, (%rax)
je 0xcc25
movq %rcx, %r12
subq %rbx, %r12
movb -0x1(%rcx), %sil
cmpb $0x23, %sil
jne 0xcc29
xorl %edi, %edi
jmp 0xcc5b
xorl %eax, %eax
jmp 0xcc6d
addq $-0x2, %rcx
movl $0x1, %edx
xorl %eax, %eax
xorl %edi, %edi
addb $-0x30, %sil
cmpb $0x9, %sil
ja 0xcc6d
movzbl %sil, %esi
imull %edx, %esi
addq %rsi, %rdi
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movb (%rcx), %sil
decq %rcx
cmpb $0x23, %sil
jne 0xcc36
movq %r15, %rsi
movq %r14, %rdx
callq 0xcc9a
leaq (%rbx,%r12), %rax
incq %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq