// File: /workspace/github_cpp_makefile_star2_O3/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 0x2d6b
movq %rax, %r14
movb $0x0, (%rax)
cmpl $0x1, %ebp
je 0x6b7a
cmpl $0x2, %ebp
je 0x6a9f
cmpl $0x3, %ebp
jne 0x6c61
xorl %ebp, %ebp
xorl %eax, %eax
movslq %eax, %rdx
movzbl (%rbx,%rdx), %ecx
cmpl $0x27, %ecx
je 0x6a86
testl %ecx, %ecx
jne 0x6a94
jmp 0x6c40
cmpb $0x27, 0x1(%rbx,%rdx)
jne 0x6a94
incq %rdx
movb $0x27, %cl
movl %edx, %eax
movb %cl, (%r14,%rbp)
incq %rbp
incl %eax
jmp 0x6a71
movq %r15, (%rsp)
leaq 0x8c70(%rip), %r13      # 0xf71a
xorl %ebp, %ebp
xorl %ecx, %ecx
movslq %ecx, %r12
movzbl (%rbx,%r12), %edx
cmpl $0x25, %edx
je 0x6acc
movb $0x20, %r15b
cmpl $0x2b, %edx
je 0x6b0f
testl %edx, %edx
jne 0x6b0c
jmp 0x6c3c
movb 0x1(%rbx,%r12), %r15b
testb %r15b, %r15b
je 0x6b0c
movb 0x2(%rbx,%r12), %al
testb %al, %al
je 0x6b0c
addq $0x2, %r12
leal -0x41(%r15), %ecx
cmpb $0x5, %cl
jbe 0x6af5
leal -0x61(%r15), %ecx
cmpb $0x5, %cl
ja 0x6b29
shlb $0x4, %r15b
addb $-0x70, %r15b
leal -0x41(%rax), %ecx
cmpb $0x5, %cl
ja 0x6b1a
addb %r15b, %al
addb $-0x37, %al
jmp 0x6b45
movl %edx, %r15d
movb %r15b, (%r14,%rbp)
incq %rbp
incl %ecx
jmp 0x6aae
leal -0x61(%rax), %ecx
cmpb $0x5, %cl
ja 0x6b38
addb %r15b, %al
addb $-0x57, %al
jmp 0x6b45
leal -0x30(%r15), %ecx
cmpb $0x9, %cl
ja 0x6b4d
shlb $0x4, %r15b
jmp 0x6afd
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x6b67
addb %r15b, %al
addb $-0x30, %al
movl %eax, %r15d
movl %r12d, %ecx
jmp 0x6b0f
xorl %r15d, %r15d
leaq 0x884f(%rip), %rdi      # 0xf3a6
movq %r13, %rsi
xorl %eax, %eax
callq 0x4844
movb (%rbx,%r12), %al
jmp 0x6afd
leaq 0x8838(%rip), %rdi      # 0xf3a6
movq %r13, %rsi
xorl %eax, %eax
callq 0x4844
jmp 0x6b48
movb (%rbx), %r12b
testb %r12b, %r12b
je 0x6ca4
movq %r15, (%rsp)
xorl %ebp, %ebp
movq %rbx, %r15
xorl %r13d, %r13d
movl $0x4, %edx
movq %r15, %rdi
leaq 0x8b62(%rip), %rsi      # 0xf703
callq 0x23b0
testl %eax, %eax
je 0x6bf8
movl $0x4, %edx
movq %r15, %rdi
leaq 0x8b4f(%rip), %rsi      # 0xf708
callq 0x23b0
testl %eax, %eax
je 0x6bff
movl $0x5, %edx
movq %r15, %rdi
leaq 0x8b3c(%rip), %rsi      # 0xf70d
callq 0x23b0
testl %eax, %eax
je 0x6c26
movl $0x6, %edx
movq %r15, %rdi
leaq 0x8b2a(%rip), %rsi      # 0xf713
callq 0x23b0
testl %eax, %eax
je 0x6c31
movb %r12b, (%r14,%rbp)
jmp 0x6c08
movb $0x3c, (%r14,%rbp)
jmp 0x6c04
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 0x6b92
jmp 0x6c3c
movb $0x26, (%r14,%rbp)
addl $0x4, %r13d
jmp 0x6c08
movb $0x22, (%r14,%rbp)
addl $0x5, %r13d
jmp 0x6c08
movq (%rsp), %r15
movl %ebp, %eax
movb $0x0, (%r14,%rax)
testq %r15, %r15
je 0x6c4f
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 0x6c77
testl %ecx, %ecx
jne 0x6c92
jmp 0x6c40
movzbl 0x1(%rbx,%rdx), %ecx
incq %rdx
movl %edx, %eax
cmpl $0x30, %ecx
je 0x6c9d
cmpl $0x6e, %ecx
jne 0x6c92
movb $0xa, (%r14,%rbp)
jmp 0x6c96
movb %cl, (%r14,%rbp)
incq %rbp
incl %eax
jmp 0x6c65
movb $0x0, (%r14,%rbp)
jmp 0x6c96
xorl %ebp, %ebp
jmp 0x6c40