// File: /workspace/github_cpp_makefile_star2_O1/rurban[P]dgnlib/cpl_string.cpp
// Function: CPLUnescapeString
char *CPLUnescapeString( const char *pszInput, int *pnLength, int nScheme )

{
    char *pszOutput;
    int iOut=0, iIn;

    pszOutput = (char *) CPLMalloc(strlen(pszInput)+1);
    pszOutput[0] = '\0';

    if( nScheme == CPLES_XML )
    {
        for( iIn = 0; pszInput[iIn] != '\0'; iIn++ )
        {
            if( EQUALN(pszInput+iIn,"&lt;",4) )
            {
                pszOutput[iOut++] = '<';
                iIn += 3;
            }
            else if( EQUALN(pszInput+iIn,"&gt;",4) )
            {
                pszOutput[iOut++] = '>';
                iIn += 3;
            }
            else if( EQUALN(pszInput+iIn,"&amp;",5) )
            {
                pszOutput[iOut++] = '&';
                iIn += 4;
            }
            else if( EQUALN(pszInput+iIn,"&quot;",6) )
            {
                pszOutput[iOut++] = '"';
                iIn += 5;
            }
            else
            {
                pszOutput[iOut++] = pszInput[iIn];
            }
        }
    }
    else if( nScheme == CPLES_URL )
    {
        for( iIn = 0; pszInput[iIn] != '\0'; iIn++ )
        {
            if( pszInput[iIn] == '%' 
                && pszInput[iIn+1] != '\0' 
                && pszInput[iIn+2] != '\0' )
            {
                int nHexChar = 0;

                if( pszInput[iIn+1] >= 'A' && pszInput[iIn+1] <= 'F' )
                    nHexChar += 16 * (pszInput[iIn+1] - 'A' + 10);
                else if( pszInput[iIn+1] >= 'a' && pszInput[iIn+1] <= 'f' )
                    nHexChar += 16 * (pszInput[iIn+1] - 'a' + 10);
                else if( pszInput[iIn+1] >= '0' && pszInput[iIn+1] <= '9' )
                    nHexChar += 16 * (pszInput[iIn+1] - '0');
                else
                    CPLDebug( "CPL", 
                              "Error unescaping CPLES_URL text, percent not "
                              "followed by two hex digits." );
                    
                if( pszInput[iIn+2] >= 'A' && pszInput[iIn+2] <= 'F' )
                    nHexChar += pszInput[iIn+2] - 'A' + 10;
                else if( pszInput[iIn+2] >= 'a' && pszInput[iIn+2] <= 'f' )
                    nHexChar += pszInput[iIn+2] - 'a' + 10;
                else if( pszInput[iIn+2] >= '0' && pszInput[iIn+2] <= '9' )
                    nHexChar += pszInput[iIn+2] - '0';
                else
                    CPLDebug( "CPL", 
                              "Error unescaping CPLES_URL text, percent not "
                              "followed by two hex digits." );

                pszOutput[iOut++] = (char) nHexChar;
                iIn += 2;
            }
            else if( pszInput[iIn] == '+' )
            {
                pszOutput[iOut++] = ' ';
            }   
            else
            {
                pszOutput[iOut++] = pszInput[iIn];
            }
        }
    }
    else if( nScheme == CPLES_SQL )
    {
        for( iIn = 0; pszInput[iIn] != '\0'; iIn++ )
        {
            if( pszInput[iIn] == '\'' && pszInput[iIn+1] == '\'' )
            {
                iIn++;
                pszOutput[iOut++] = pszInput[iIn];
            }
            else
            {
                pszOutput[iOut++] = pszInput[iIn];
            }
        }
    }
    else /* if( nScheme == CPLES_BackslashQuoteable ) */
    {
        for( iIn = 0; pszInput[iIn] != '\0'; iIn++ )
        {
            if( pszInput[iIn] == '\\' )
            {
                iIn++;
                if( pszInput[iIn] == 'n' )
                    pszOutput[iOut++] = '\n';
                else if( pszInput[iIn] == '0' )
                    pszOutput[iOut++] = '\0';
                else 
                    pszOutput[iOut++] = pszInput[iIn];
            }
            else
            {
                pszOutput[iOut++] = pszInput[iIn];
            }
        }
    }

    pszOutput[iOut] = '\0';

    if( pnLength != NULL )
        *pnLength = iOut;

    return pszOutput;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
callq 0x2120
leaq 0x1(%rax), %rdi
callq 0x2d9b
movq %rax, %r14
movb $0x0, (%rax)
cmpl $0x1, %ebp
je 0x6cb7
cmpl $0x2, %ebp
je 0x6bb7
cmpl $0x3, %ebp
jne 0x6d9e
xorl %ebp, %ebp
xorl %eax, %eax
movslq %eax, %rsi
movzbl (%rbx,%rsi), %edx
cmpl $0x27, %edx
je 0x6b9a
testl %edx, %edx
jne 0x6baa
jmp 0x6d7d
movb 0x1(%rbx,%rsi), %cl
cmpb $0x27, %cl
jne 0x6baa
incq %rsi
movl %esi, %eax
jmp 0x6bac
movl %edx, %ecx
movb %cl, (%r14,%rbp)
incq %rbp
incl %eax
jmp 0x6b85
movq %r15, (%rsp)
leaq 0x9b3c(%rip), %r13      # 0x106fe
xorl %ebp, %ebp
xorl %eax, %eax
movslq %eax, %r15
movzbl (%rbx,%r15), %r12d
cmpl $0x25, %r12d
je 0x6be8
cmpl $0x2b, %r12d
je 0x6c16
testl %r12d, %r12d
jne 0x6ca9
jmp 0x6d79
movzbl 0x1(%rbx,%r15), %ecx
testl %ecx, %ecx
je 0x6c0c
cmpb $0x0, 0x2(%rbx,%r15)
je 0x6c0c
leal -0x41(%rcx), %eax
cmpb $0x5, %al
ja 0x6c1e
shll $0x4, %ecx
addl $0xfffffc90, %ecx       # imm = 0xFFFFFC90
jmp 0x6c2e
cmpb $0x2b, %r12b
jne 0x6ca9
movb $0x20, %r12b
jmp 0x6ca9
leal -0x61(%rcx), %eax
cmpb $0x5, %al
ja 0x6c5c
shll $0x4, %ecx
addl $0xfffffa90, %ecx       # imm = 0xFFFFFA90
movl %ecx, %r12d
addq $0x2, %r15
movzbl (%rbx,%r15), %eax
leal -0x41(%rax), %ecx
cmpb $0x5, %cl
ja 0x6c4b
addl %eax, %r12d
addl $-0x37, %r12d
jmp 0x6ca6
leal -0x61(%rax), %ecx
cmpb $0x5, %cl
ja 0x6c6d
addl %eax, %r12d
addl $-0x57, %r12d
jmp 0x6ca6
movl %ecx, %eax
addb $-0x30, %al
cmpb $0x9, %al
ja 0x6c7f
shlb $0x4, %cl
movzbl %cl, %r12d
jmp 0x6c31
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x6c95
addb $-0x30, %al
movzbl %al, %eax
addl %eax, %r12d
jmp 0x6ca6
xorl %r12d, %r12d
leaq 0x96fd(%rip), %rdi      # 0x10386
movq %r13, %rsi
xorl %eax, %eax
callq 0x48d9
jmp 0x6c31
leaq 0x96ea(%rip), %rdi      # 0x10386
movq %r13, %rsi
xorl %eax, %eax
callq 0x48d9
movl %r15d, %eax
movb %r12b, (%r14,%rbp)
incq %rbp
incl %eax
jmp 0x6bc6
movb (%rbx), %r12b
testb %r12b, %r12b
je 0x6de1
movq %r15, (%rsp)
xorl %ebp, %ebp
movq %rbx, %r15
xorl %r13d, %r13d
movl $0x4, %edx
movq %r15, %rdi
leaq 0x9a09(%rip), %rsi      # 0x106e7
callq 0x23c0
testl %eax, %eax
je 0x6d35
movl $0x4, %edx
movq %r15, %rdi
leaq 0x99f6(%rip), %rsi      # 0x106ec
callq 0x23c0
testl %eax, %eax
je 0x6d3c
movl $0x5, %edx
movq %r15, %rdi
leaq 0x99e3(%rip), %rsi      # 0x106f1
callq 0x23c0
testl %eax, %eax
je 0x6d63
movl $0x6, %edx
movq %r15, %rdi
leaq 0x99d1(%rip), %rsi      # 0x106f7
callq 0x23c0
testl %eax, %eax
je 0x6d6e
movb %r12b, (%r14,%rbp)
jmp 0x6d45
movb $0x3c, (%r14,%rbp)
jmp 0x6d41
movb $0x3e, (%r14,%rbp)
addl $0x3, %r13d
incq %rbp
movslq %r13d, %r13
leaq (%rbx,%r13), %r15
incq %r15
incq %r13
movb (%r15), %r12b
testb %r12b, %r12b
jne 0x6ccf
jmp 0x6d79
movb $0x26, (%r14,%rbp)
addl $0x4, %r13d
jmp 0x6d45
movb $0x22, (%r14,%rbp)
addl $0x5, %r13d
jmp 0x6d45
movq (%rsp), %r15
movl %ebp, %eax
movb $0x0, (%r14,%rax)
testq %r15, %r15
je 0x6d8c
movl %ebp, (%r15)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
xorl %eax, %eax
movslq %eax, %rdx
movzbl (%rbx,%rdx), %ecx
cmpl $0x5c, %ecx
je 0x6db4
testl %ecx, %ecx
jne 0x6dcf
jmp 0x6d7d
movzbl 0x1(%rbx,%rdx), %ecx
incq %rdx
movl %edx, %eax
cmpl $0x30, %ecx
je 0x6dda
cmpl $0x6e, %ecx
jne 0x6dcf
movb $0xa, (%r14,%rbp)
jmp 0x6dd3
movb %cl, (%r14,%rbp)
incq %rbp
incl %eax
jmp 0x6da2
movb $0x0, (%r14,%rbp)
jmp 0x6dd3
xorl %ebp, %ebp
jmp 0x6d7d