// File: /workspace/github_cpp_makefile_star2_O1/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 0xcc4e
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movzbl 0x2(%rdi), %ecx
testl %ecx, %ecx
je 0xcc46
movq %rdx, %r14
movq %rsi, %r15
cmpl $0x78, %ecx
jne 0xcbf7
cmpb $0x0, 0x3(%rbx)
je 0xcc44
leaq 0x3(%rbx), %rdi
movl $0x3b, %esi
callq 0x40c0
testq %rax, %rax
je 0xcc25
cmpb $0x0, (%rax)
je 0xcc25
movq %rax, %r12
subq %rbx, %r12
movb -0x1(%rax), %sil
movb $0x1, %cl
cmpb $0x78, %sil
je 0xcc21
addq $-0x2, %rax
movl $0x1, %edx
xorl %edi, %edi
leal -0x30(%rsi), %r8d
cmpb $0x9, %r8b
ja 0xcbbc
movzbl %r8b, %esi
jmp 0xcbe0
leal -0x61(%rsi), %r8d
cmpb $0x5, %r8b
ja 0xcbcf
movzbl %sil, %esi
addl $-0x57, %esi
jmp 0xcbe0
leal -0x41(%rsi), %r8d
cmpb $0x5, %r8b
ja 0xcc2a
movzbl %sil, %esi
addl $-0x37, %esi
imull %edx, %esi
addq %rsi, %rdi
shll $0x4, %edx
movb (%rax), %sil
decq %rax
cmpb $0x78, %sil
jne 0xcbac
jmp 0xcc2c
leaq 0x2(%rbx), %rdi
movl $0x3b, %esi
callq 0x40c0
testq %rax, %rax
je 0xcc25
cmpb $0x0, (%rax)
je 0xcc25
movq %rax, %r12
subq %rbx, %r12
movb -0x1(%rax), %sil
cmpb $0x23, %sil
jne 0xcc4f
movb $0x1, %cl
xorl %edi, %edi
jmp 0xcc2c
xorl %edi, %edi
xorl %r12d, %r12d
xorl %ecx, %ecx
testb %cl, %cl
je 0xcc44
movq %r15, %rsi
movq %r14, %rdx
callq 0xcca8
leaq (%rbx,%r12), %rax
incq %rax
jmp 0xcc46
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
addq $-0x2, %rax
movl $0x1, %edx
xorl %edi, %edi
addb $-0x30, %sil
cmpb $0xa, %sil
setb %cl
jae 0xcc2c
movzbl %sil, %esi
imull %edx, %esi
addq %rsi, %rdi
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movb (%rax), %sil
decq %rax
cmpb $0x23, %sil
jne 0xcc5a
jmp 0xcc2c