// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movl %edx, %ebp
movq %rsi, 0x28(%rsp)
movq %rdi, %r12
pushq $0xa
popq %rdi
pushq $0x1
popq %rsi
callq 0x2c6c
movq %rax, %rdi
pushq $0xa
popq %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movl $0x0, 0x4(%rsp)
movq $0x0, 0x8(%rsp)
movl 0x4(%rsp), %r15d
testq %r12, %r12
je 0x5dad
movb (%r12), %r14b
testb %r14b, %r14b
je 0x5dad
movq %r15, 0x30(%rsp)
xorl %r13d, %r13d
xorl %esi, %esi
movq 0x10(%rsp), %r15
movslq %r13d, %rbx
testb %r14b, %r14b
je 0x5d26
testl %esi, %esi
jne 0x5c84
movl %r13d, 0x24(%rsp)
movq %r12, %r13
movl %esi, %r12d
movsbl %r14b, %esi
movq %r15, 0x10(%rsp)
movl %ebp, %r15d
movq %rdi, %rbp
movq 0x28(%rsp), %rdi
callq 0x20e0
movl %r12d, %esi
movq %r13, %r12
movl 0x24(%rsp), %r13d
movq %rbp, %rdi
movl %r15d, %ebp
movq 0x10(%rsp), %r15
testq %rax, %rax
jne 0x5d2d
testb $0x1, %bpl
je 0x5caa
cmpb $0x22, %r14b
jne 0x5caa
testb $0x4, %bpl
je 0x5c9f
movb $0x22, (%rdi,%rbx)
incl %ebx
movl %ebx, %r13d
xorl %eax, %eax
testl %esi, %esi
sete %al
movl %eax, %esi
jmp 0x5d19
cmpb $0x5c, %r14b
jne 0x5cec
testl %esi, %esi
je 0x5cec
leaq 0x1(%r12), %rax
movb 0x1(%r12), %cl
cmpb $0x22, %cl
jne 0x5ccb
testb $0x8, %bpl
jne 0x5ce0
jmp 0x5ce9
testb $0x8, %bpl
sete %dl
cmpb $0x5c, %cl
setne %cl
cmoveq %rax, %r12
orb %dl, %cl
jne 0x5cec
movb $0x5c, (%rdi,%rbx)
incl %ebx
movl %ebx, %r13d
movq %rax, %r12
leal -0x3(%r15), %eax
cmpl %eax, %r13d
jl 0x5d0c
leal 0xa(,%r15,2), %r15d
movl %esi, %ebx
movslq %r15d, %rsi
callq 0x2d0a
movl %ebx, %esi
movq %rax, %rdi
movb (%r12), %al
movslq %r13d, %rcx
movb %al, (%rdi,%rcx)
incl %r13d
movb 0x1(%r12), %r14b
incq %r12
jmp 0x5c31
movq %r15, 0x10(%rsp)
jmp 0x5d30
incq %r12
movb $0x0, (%rdi,%rbx)
testb $0x2, %bpl
jne 0x5d43
cmpb $0x0, (%rdi)
je 0x5c07
movq 0x18(%rsp), %rcx
leal -0x1(%rcx), %eax
cmpl %eax, 0x4(%rsp)
jge 0x5d58
movq 0x8(%rsp), %r14
jmp 0x5d85
movl %ecx, %eax
addl %ecx, %eax
leal 0xa(,%rcx,2), %ecx
movq %rcx, 0x18(%rsp)
cltq
leaq 0x50(,%rax,8), %rsi
movq %rdi, %rbx
movq 0x8(%rsp), %rdi
callq 0x2d0a
movq %rbx, %rdi
movq %rax, %r14
movq %rdi, %rbx
callq 0x2d77
movq %rbx, %rdi
incl 0x4(%rsp)
movq 0x30(%rsp), %rcx
movq %rax, (%r14,%rcx,8)
movq %r14, 0x8(%rsp)
andq $0x0, 0x8(%r14,%rcx,8)
jmp 0x5c07
testb $0x2, %bpl
sete %al
cmpl $0x0, 0x4(%rsp)
sete %cl
orb %al, %cl
jne 0x5e21
movsbl -0x1(%r12), %esi
movq %rdi, %rbx
movq 0x28(%rsp), %rdi
callq 0x20e0
movq %rbx, %rdi
testq %rax, %rax
je 0x5e21
movq 0x18(%rsp), %rcx
leal -0x1(%rcx), %eax
cmpl %eax, 0x4(%rsp)
movq 0x8(%rsp), %r14
jl 0x5e06
addl %ecx, %ecx
movslq %ecx, %rax
leaq 0x50(,%rax,8), %rsi
movq %r14, %rdi
callq 0x2d0a
movq %rax, %r14
leaq 0x91df(%rip), %rdi      # 0xefec
callq 0x2d77
movq %rax, (%r14,%r15,8)
andq $0x0, 0x8(%r14,%r15,8)
movq %rbx, %rdi
jmp 0x5e3f
movq 0x8(%rsp), %r14
testq %r14, %r14
jne 0x5e3f
movq %rdi, %rbx
pushq $0x8
popq %rdi
pushq $0x1
popq %rsi
callq 0x2c6c
movq %rbx, %rdi
movq %rax, %r14
callq 0x6a49
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq