// File: rurban[P]dgnlib/cpl_string.cpp
// Function: CSLTokenizeString2
char ** CSLTokenizeString2( const char * pszString,
                            const char * pszDelimiters,
                            int nCSLTFlags )

{
    char        **papszRetList = NULL;
    int         nRetMax = 0, nRetLen = 0;
    char        *pszToken;
    int         nTokenMax, nTokenLen;
    int         bHonourStrings = (nCSLTFlags & CSLT_HONOURSTRINGS);
    int         bAllowEmptyTokens = (nCSLTFlags & CSLT_ALLOWEMPTYTOKENS);

    pszToken = (char *) CPLCalloc(10,1);
    nTokenMax = 10;
    
    while( pszString != NULL && *pszString != '\0' )
    {
        int     bInString = FALSE;

        nTokenLen = 0;
        
        /* Try to find the next delimeter, marking end of token */
        for( ; *pszString != '\0'; pszString++ )
        {

            /* End if this is a delimeter skip it and break. */
            if( !bInString && strchr(pszDelimiters, *pszString) != NULL )
            {
                pszString++;
                break;
            }
            
            /* If this is a quote, and we are honouring constant
               strings, then process the constant strings, with out delim
               but don't copy over the quotes */
            if( bHonourStrings && *pszString == '"' )
            {
                if( nCSLTFlags & CSLT_PRESERVEQUOTES )
                {
                    pszToken[nTokenLen] = *pszString;
                    nTokenLen++;
                }

                if( bInString )
                {
                    bInString = FALSE;
                    continue;
                }
                else
                {
                    bInString = TRUE;
                    continue;
                }
            }

            /* Within string constants we allow for escaped quotes, but
               in processing them we will unescape the quotes */
            if( bInString && pszString[0] == '\\' && pszString[1] == '"' )
            {
                if( nCSLTFlags & CSLT_PRESERVEESCAPES )
                {
                    pszToken[nTokenLen] = *pszString;
                    nTokenLen++;
                }

                pszString++;
            }

            /* Within string constants a \\ sequence reduces to \ */
            else if( bInString 
                     && pszString[0] == '\\' && pszString[1] == '\\' )
            {
                if( nCSLTFlags & CSLT_PRESERVEESCAPES )
                {
                    pszToken[nTokenLen] = *pszString;
                    nTokenLen++;
                }
                pszString++;
            }

            if( nTokenLen >= nTokenMax-3 )
            {
                nTokenMax = nTokenMax * 2 + 10;
                pszToken = (char *) CPLRealloc( pszToken, nTokenMax );
            }

            pszToken[nTokenLen] = *pszString;
            nTokenLen++;
        }

        pszToken[nTokenLen] = '\0';

        /*
         * Add the token.
         */
        if( pszToken[0] != '\0' || bAllowEmptyTokens )
        {
            if( nRetLen >= nRetMax - 1 )
            {
                nRetMax = nRetMax * 2 + 10;
                papszRetList = (char **) 
                    CPLRealloc(papszRetList, sizeof(char*) * nRetMax );
            }

            papszRetList[nRetLen++] = CPLStrdup( pszToken );
            papszRetList[nRetLen] = NULL;
        }
    }

    /*
     * If the last token was empty, then we need to capture
     * it now, as the loop would skip it.
     */
    if( *pszString == '\0' && bAllowEmptyTokens && nRetLen > 0 
        && strchr(pszDelimiters,*(pszString-1)) != NULL )
    {
        if( nRetLen >= nRetMax - 1 )
        {
            nRetMax = nRetMax * 2 + 10;
            papszRetList = (char **) 
                CPLRealloc(papszRetList, sizeof(char*) * nRetMax );
        }

        papszRetList[nRetLen++] = CPLStrdup("");
        papszRetList[nRetLen] = NULL;
    }

    if( papszRetList == NULL )
        papszRetList = (char **) CPLCalloc(sizeof(char *),1);

    CPLFree( pszToken );

    return papszRetList;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x14(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x14(%rbp), %eax
andl $0x2, %eax
movl %eax, -0x40(%rbp)
movl $0xa, %edi
movl $0x1, %esi
callq 0x2fc0
movq %rax, -0x30(%rbp)
movl $0xa, -0x34(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x8(%rbp)
movb %al, -0x45(%rbp)
je 0x7ff1
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
testb $0x1, %al
jne 0x7ffd
jmp 0x8217
movl $0x0, -0x44(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x8195
cmpl $0x0, -0x44(%rbp)
jne 0x8048
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movsbl (%rax), %esi
callq 0x20e0
cmpq $0x0, %rax
je 0x8048
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x8195
cmpl $0x0, -0x3c(%rbp)
je 0x809d
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0x809d
movl -0x14(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x807f
movq -0x8(%rbp), %rax
movb (%rax), %dl
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x8091
movl $0x0, -0x44(%rbp)
jmp 0x8184
movl $0x1, -0x44(%rbp)
jmp 0x8184
cmpl $0x0, -0x44(%rbp)
je 0x80ef
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x80ef
movq -0x8(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x22, %eax
jne 0x80ef
movl -0x14(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x80e1
movq -0x8(%rbp), %rax
movb (%rax), %dl
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x8141
cmpl $0x0, -0x44(%rbp)
je 0x813f
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x813f
movq -0x8(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x5c, %eax
jne 0x813f
movl -0x14(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x8133
movq -0x8(%rbp), %rax
movb (%rax), %dl
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x8141
movl -0x38(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x3, %ecx
cmpl %ecx, %eax
jl 0x816a
movl -0x34(%rbp), %eax
shll %eax
addl $0xa, %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x3120
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movb (%rax), %dl
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x800b
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x81b3
cmpl $0x0, -0x40(%rbp)
je 0x8212
movl -0x28(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x81e0
movl -0x24(%rbp), %eax
shll %eax
addl $0xa, %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
shlq $0x3, %rsi
callq 0x3120
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
callq 0x31e0
movq %rax, %rdx
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x7fd5
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x82ac
cmpl $0x0, -0x40(%rbp)
je 0x82ac
cmpl $0x0, -0x28(%rbp)
jle 0x82ac
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movsbl -0x1(%rax), %esi
callq 0x20e0
cmpq $0x0, %rax
je 0x82ac
movl -0x28(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x8277
movl -0x24(%rbp), %eax
shll %eax
addl $0xa, %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
shlq $0x3, %rsi
callq 0x3120
movq %rax, -0x20(%rbp)
leaq 0x11a06(%rip), %rdi     # 0x19c84
callq 0x31e0
movq %rax, %rdx
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
cmpq $0x0, -0x20(%rbp)
jne 0x82c6
movl $0x8, %edi
movl $0x1, %esi
callq 0x2fc0
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
callq 0xa000
movq -0x20(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)