// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movl %edx, %ebx
movq %rsi, %r12
movq %rdi, %r15
callq 0x2120
leaq 0x1(%rax), %rdi
callq 0x2cb3
movq %rax, %r14
movb $0x0, (%rax)
cmpl $0x1, %ebx
je 0x6722
cmpl $0x2, %ebx
je 0x664a
xorl %ebp, %ebp
xorl %eax, %eax
cmpl $0x3, %ebx
jne 0x6606
movslq %eax, %rdx
movzbl (%r15,%rdx), %ecx
cmpl $0x27, %ecx
je 0x65ec
testl %ecx, %ecx
jne 0x65fb
jmp 0x67f6
cmpb $0x27, 0x1(%r15,%rdx)
jne 0x65fb
incq %rdx
movb $0x27, %cl
movl %edx, %eax
movb %cl, (%r14,%rbp)
incq %rbp
incl %eax
jmp 0x65d6
movslq %eax, %rdx
movzbl (%r15,%rdx), %ecx
cmpl $0x5c, %ecx
je 0x661c
testl %ecx, %ecx
jne 0x6638
jmp 0x67f6
movzbl 0x1(%r15,%rdx), %ecx
incq %rdx
movl %edx, %eax
cmpl $0x30, %ecx
je 0x6643
cmpl $0x6e, %ecx
jne 0x6638
movb $0xa, (%r14,%rbp)
jmp 0x663c
movb %cl, (%r14,%rbp)
incq %rbp
incl %eax
jmp 0x6606
movb $0x0, (%r14,%rbp)
jmp 0x663c
movq %r12, 0x10(%rsp)
leaq 0x80c4(%rip), %r13      # 0xe71a
xorl %ebp, %ebp
xorl %ecx, %ecx
movslq %ecx, %r12
movzbl (%r15,%r12), %edx
cmpl $0x25, %edx
je 0x6677
movb $0x20, %bl
cmpl $0x2b, %edx
je 0x66b3
testl %edx, %edx
jne 0x66b1
jmp 0x6718
movb 0x1(%r15,%r12), %bl
testb %bl, %bl
je 0x66b1
movb 0x2(%r15,%r12), %al
testb %al, %al
je 0x66b1
addq $0x2, %r12
leal -0x41(%rbx), %ecx
cmpb $0x5, %cl
jbe 0x669d
leal -0x61(%rbx), %ecx
cmpb $0x5, %cl
ja 0x66cc
shlb $0x4, %bl
addb $-0x70, %bl
leal -0x41(%rax), %ecx
cmpb $0x5, %cl
ja 0x66be
addb %bl, %al
addb $-0x37, %al
jmp 0x66e5
movl %edx, %ebx
movb %bl, (%r14,%rbp)
incq %rbp
incl %ecx
jmp 0x665a
leal -0x61(%rax), %ecx
cmpb $0x5, %cl
ja 0x66d9
addb %bl, %al
addb $-0x57, %al
jmp 0x66e5
leal -0x30(%rbx), %ecx
cmpb $0x9, %cl
ja 0x66ec
shlb $0x4, %bl
jmp 0x66a3
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x6705
addb %bl, %al
addb $-0x30, %al
movl %eax, %ebx
movl %r12d, %ecx
jmp 0x66b3
xorl %ebx, %ebx
leaq 0x7cb1(%rip), %rdi      # 0xe3a6
movq %r13, %rsi
xorl %eax, %eax
callq 0x45a8
movb (%r15,%r12), %al
jmp 0x66a3
leaq 0x7c9a(%rip), %rdi      # 0xe3a6
movq %r13, %rsi
xorl %eax, %eax
callq 0x45a8
jmp 0x66e7
movq 0x10(%rsp), %r12
jmp 0x67f6
movq %r14, 0x8(%rsp)
movq %r12, 0x10(%rsp)
xorl %ebp, %ebp
pushq $0x4
popq %r14
xorl %r12d, %r12d
movslq %r12d, %rbx
movb (%r15,%rbx), %r13b
testb %r13b, %r13b
je 0x67ec
addq %r15, %rbx
movq %rbx, %rdi
leaq 0x7fb1(%rip), %rsi      # 0xe703
movq %r14, %rdx
callq 0x23b0
testl %eax, %eax
je 0x67ab
movq %rbx, %rdi
leaq 0x7fa0(%rip), %rsi      # 0xe708
movq %r14, %rdx
callq 0x23b0
testl %eax, %eax
je 0x67ba
movq %rbx, %rdi
leaq 0x7f8f(%rip), %rsi      # 0xe70d
pushq $0x5
popq %rdx
callq 0x23b0
testl %eax, %eax
movq 0x8(%rsp), %r14
je 0x67c9
movq %rbx, %rdi
leaq 0x7f7a(%rip), %rsi      # 0xe713
pushq $0x6
popq %rdx
callq 0x23b0
testl %eax, %eax
je 0x67d4
movb %r13b, (%r14,%rbp)
jmp 0x67dd
movq 0x8(%rsp), %rax
movb $0x3c, (%rax,%rbp)
addl $0x3, %r12d
jmp 0x67e1
movq 0x8(%rsp), %rax
movb $0x3e, (%rax,%rbp)
addl $0x3, %r12d
jmp 0x67dd
movb $0x26, (%r14,%rbp)
addl $0x4, %r12d
jmp 0x67dd
movb $0x22, (%r14,%rbp)
addl $0x5, %r12d
pushq $0x4
popq %r14
incq %rbp
incl %r12d
jmp 0x6735
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r14
movl %ebp, %eax
movb $0x0, (%r14,%rax)
testq %r12, %r12
je 0x6806
movl %ebp, (%r12)
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq