// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x23, %eax
jne 0x1a125
movq -0x10(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x1a125
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x78, %eax
jne 0x1a034
movq -0x10(%rbp), %rax
cmpb $0x0, 0x3(%rax)
jne 0x19efc
movq $0x0, -0x8(%rbp)
jmp 0x1a131
movq -0x10(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl $0x3b, %esi
callq 0x40d0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x19f2a
movq -0x40(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x19f37
movq $0x0, -0x8(%rbp)
jmp 0x1a131
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x78, %eax
je 0x1a02f
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jl 0x19f96
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jg 0x19f96
movl -0x34(%rbp), %eax
movq -0x40(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x30, %ecx
imull %ecx, %eax
movl %eax, %eax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x1a015
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x61, %eax
jl 0x19fcd
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x66, %eax
jg 0x19fcd
movl -0x34(%rbp), %eax
movq -0x40(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x61, %ecx
addl $0xa, %ecx
imull %ecx, %eax
movl %eax, %eax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x1a013
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x41, %eax
jl 0x1a004
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x46, %eax
jg 0x1a004
movl -0x34(%rbp), %eax
movq -0x40(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x41, %ecx
addl $0xa, %ecx
imull %ecx, %eax
movl %eax, %eax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x1a011
movq $0x0, -0x8(%rbp)
jmp 0x1a131
jmp 0x1a013
jmp 0x1a015
movl -0x34(%rbp), %eax
shll $0x4, %eax
movl %eax, -0x34(%rbp)
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x19f52
jmp 0x1a102
movq -0x10(%rbp), %rax
cmpb $0x0, 0x2(%rax)
jne 0x1a04b
movq $0x0, -0x8(%rbp)
jmp 0x1a131
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl $0x3b, %esi
callq 0x40d0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x1a079
movq -0x48(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x1a086
movq $0x0, -0x8(%rbp)
jmp 0x1a131
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0x1a100
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jl 0x1a0e1
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jg 0x1a0e1
movl -0x34(%rbp), %eax
movq -0x48(%rbp), %rcx
movsbl (%rcx), %ecx
subl $0x30, %ecx
imull %ecx, %eax
movl %eax, %eax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x1a0eb
movq $0x0, -0x8(%rbp)
jmp 0x1a131
imull $0xa, -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x1a0a1
jmp 0x1a102
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x1a1a0
movq -0x10(%rbp), %rax
addq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x1a131
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)