// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebp
movq %rsi, 0x18(%rsp)
movq %rdi, %r12
movl $0xa, %edi
movl $0x1, %esi
callq 0x2d20
movq %rax, %rdi
testq %r12, %r12
je 0x621f
movb (%r12), %bl
testb %bl, %bl
je 0x61ae
movl $0xa, %r14d
movq $0x0, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
movq $0x0, 0x8(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
testl %r15d, %r15d
jne 0x6071
movsbl %bl, %esi
movq %r13, 0x20(%rsp)
movl %r15d, %r13d
movl %ebp, %r15d
movq %r14, %rbp
movq %rdi, %r14
movq 0x18(%rsp), %rdi
callq 0x20e0
movq %r14, %rdi
movq %rbp, %r14
movl %r15d, %ebp
movl %r13d, %r15d
movq 0x20(%rsp), %r13
testq %rax, %rax
jne 0x6119
testb $0x1, %bpl
je 0x6099
cmpb $0x22, %bl
jne 0x6099
testb $0x4, %bpl
je 0x608c
movslq %r13d, %rax
movb $0x22, (%rdi,%rax)
incl %r13d
xorl %eax, %eax
testl %r15d, %r15d
sete %al
movl %eax, %r15d
jmp 0x6107
cmpb $0x5c, %bl
jne 0x60cd
testl %r15d, %r15d
je 0x60cd
leaq 0x1(%r12), %rbx
movb 0x1(%r12), %al
cmpb $0x22, %al
jne 0x60b9
testb $0x8, %bpl
jne 0x60d2
jmp 0x60dd
testb $0x8, %bpl
sete %cl
cmpb $0x5c, %al
setne %al
cmoveq %rbx, %r12
orb %cl, %al
je 0x60d2
movq %r12, %rbx
jmp 0x60dd
movslq %r13d, %r13
movb $0x5c, (%rdi,%r13)
incl %r13d
leal -0x3(%r14), %eax
cmpl %eax, %r13d
jl 0x60f9
leal 0xa(,%r14,2), %r14d
movslq %r14d, %rsi
callq 0x2dcb
movq %rax, %rdi
movb (%rbx), %al
movslq %r13d, %rcx
movb %al, (%rdi,%rcx)
incl %r13d
movq %rbx, %r12
movb 0x1(%r12), %bl
incq %r12
testb %bl, %bl
jne 0x6034
jmp 0x611c
incq %r12
movslq %r13d, %rax
movb $0x0, (%rdi,%rax)
testb $0x2, %bpl
jne 0x612e
cmpb $0x0, (%rdi)
je 0x61a0
movq %r14, %r15
movq 0x10(%rsp), %rcx
leal -0x1(%rcx), %eax
cmpl %eax, 0x4(%rsp)
jge 0x6146
movq 0x8(%rsp), %r14
jmp 0x6173
movl %ecx, %eax
addl %ecx, %eax
leal 0xa(,%rcx,2), %ecx
movq %rcx, 0x10(%rsp)
cltq
leaq 0x50(,%rax,8), %rsi
movq %rdi, %rbx
movq 0x8(%rsp), %rdi
callq 0x2dcb
movq %rbx, %rdi
movq %rax, %r14
movq %rdi, %rbx
callq 0x2e41
movq %rbx, %rdi
movl 0x4(%rsp), %edx
movslq %edx, %rcx
incl %edx
movl %edx, 0x4(%rsp)
movq %rax, (%r14,%rcx,8)
movq %r14, 0x8(%rsp)
movq $0x0, 0x8(%r14,%rcx,8)
movq %r15, %r14
movb (%r12), %bl
testb %bl, %bl
jne 0x602e
jmp 0x61c8
movq $0x0, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
movq $0x0, 0x10(%rsp)
cmpb $0x0, (%r12)
sete %al
shrb %bpl
cmpl $0x0, 0x4(%rsp)
setg %cl
andb %bpl, %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x6215
movsbl -0x1(%r12), %esi
movq %rdi, %rbx
movq 0x18(%rsp), %rdi
callq 0x20e0
movq %rbx, %rdi
testq %rax, %rax
je 0x6215
movq 0x10(%rsp), %rcx
leal -0x1(%rcx), %eax
cmpl %eax, 0x4(%rsp)
jge 0x6239
movq 0x8(%rsp), %r14
jmp 0x6253
movq 0x8(%rsp), %r14
testq %r14, %r14
jne 0x6273
movq %rdi, %rbx
movl $0x8, %edi
movl $0x1, %esi
callq 0x2d20
movq %rbx, %rdi
movq %rax, %r14
jmp 0x6273
addl %ecx, %ecx
movslq %ecx, %rax
leaq 0x50(,%rax,8), %rsi
movq 0x8(%rsp), %rdi
callq 0x2dcb
movq %rax, %r14
leaq 0x9d92(%rip), %rdi      # 0xffec
callq 0x2e41
movl 0x4(%rsp), %ecx
movq %rax, (%r14,%rcx,8)
movq $0x0, 0x8(%r14,%rcx,8)
movq %rbx, %rdi
callq 0x6edd
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq