// File: /workspace/github_cpp_makefile_star2_O1/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 0x2d54
movq %rax, %rdi
testq %r12, %r12
je 0x62b5
cmpb $0x0, (%r12)
je 0x62b5
movl $0xa, %r14d
movq $0x0, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
movq $0x0, 0x8(%rsp)
movb (%r12), %bl
testb %bl, %bl
je 0x621c
xorl %r15d, %r15d
xorl %r13d, %r13d
testl %r15d, %r15d
jne 0x6169
movsbl %bl, %esi
movq %r12, 0x20(%rsp)
movq %r13, %r12
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 %r12, %r13
movq 0x20(%rsp), %r12
testq %rax, %rax
jne 0x6221
testb $0x1, %bpl
je 0x6190
cmpb $0x22, %bl
jne 0x6190
testb $0x4, %bpl
je 0x6183
movslq %r13d, %rax
movb %bl, (%rdi,%rax)
incl %r13d
xorl %eax, %eax
testl %r15d, %r15d
sete %al
movl %eax, %r15d
jmp 0x620a
testl %r15d, %r15d
je 0x61e1
cmpb $0x5c, %bl
jne 0x61e1
cmpb $0x22, 0x1(%r12)
jne 0x61ad
incq %r12
testb $0x8, %bpl
jne 0x61d7
jmp 0x61e1
cmpb $0x5c, %bl
jne 0x61e1
testb $0x8, %bpl
sete %cl
cmpb $0x5c, 0x1(%r12)
movq %r12, %rax
leaq 0x1(%r12), %r12
setne %dl
cmoveq %r12, %rax
orb %cl, %dl
je 0x61d7
movq %rax, %r12
jmp 0x61e1
movslq %r13d, %r13
movb %bl, (%rdi,%r13)
incl %r13d
leal -0x3(%r14), %eax
cmpl %eax, %r13d
jl 0x61fd
leal 0xa(,%r14,2), %r14d
movslq %r14d, %rsi
callq 0x2df9
movq %rax, %rdi
movb (%r12), %al
movslq %r13d, %rcx
movb %al, (%rdi,%rcx)
incl %r13d
movb 0x1(%r12), %bl
incq %r12
testb %bl, %bl
jne 0x6126
jmp 0x6224
xorl %r13d, %r13d
jmp 0x6224
incq %r12
movslq %r13d, %rax
movb $0x0, (%rdi,%rax)
testb $0x2, %bpl
jne 0x6236
cmpb $0x0, (%rdi)
je 0x62a8
movq %r14, %r15
movq 0x10(%rsp), %rcx
leal -0x1(%rcx), %eax
cmpl %eax, 0x4(%rsp)
jge 0x624e
movq 0x8(%rsp), %r14
jmp 0x627b
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 0x2df9
movq %rbx, %rdi
movq %rax, %r14
movq %rdi, %rbx
callq 0x2e6c
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
cmpb $0x0, (%r12)
jne 0x6114
jmp 0x62cf
movq $0x0, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
movq $0x0, 0x8(%rsp)
cmpb $0x0, (%r12)
sete %al
shrb %bpl
cmpl $0x0, 0x4(%rsp)
setg %cl
andb %bpl, %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x6354
movq %rdi, %rbx
movsbl -0x1(%r12), %esi
movq 0x18(%rsp), %rdi
callq 0x20e0
testq %rax, %rax
je 0x6351
movq 0x10(%rsp), %rcx
leal -0x1(%rcx), %eax
cmpl %eax, 0x4(%rsp)
movq 0x8(%rsp), %r14
jl 0x632f
addl %ecx, %ecx
movslq %ecx, %rax
leaq 0x50(,%rax,8), %rsi
movq %r14, %rdi
callq 0x2df9
movq %rax, %r14
leaq 0xac7e(%rip), %rdi      # 0x10fb4
callq 0x2e6c
movl 0x4(%rsp), %ecx
movq %rax, (%r14,%rcx,8)
movq $0x0, 0x8(%r14,%rcx,8)
movq %rbx, %rdi
jmp 0x6359
movq %rbx, %rdi
movq 0x8(%rsp), %r14
testq %r14, %r14
jne 0x6376
movq %rdi, %rbx
movl $0x8, %edi
movl $0x1, %esi
callq 0x2d54
movq %rbx, %rdi
movq %rax, %r14
callq 0x701d
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq