// File: /workspace/github_cpp_makefile_star2_O1/rurban[P]dgnlib/cpl_string.cpp
// Function: CSLRemoveStrings
char **CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete,
                        int nNumToRemove, char ***ppapszRetStrings)
{
    int     i, nSrcLines, nDstLines;
    char    **ppszSrc, **ppszDst;

    nSrcLines = CSLCount(papszStrList);
    nDstLines = nSrcLines - nNumToRemove;

    if (nNumToRemove < 1 || nSrcLines == 0)
        return papszStrList;    /* Nothing to do!*/

    /* If operation will result in an empty StringList then don't waste
     * time here!
     */
    if (nDstLines < 1)
    {
        CSLDestroy(papszStrList);
        return NULL;
    }

    
    /* Remove lines from the source StringList...
     * Either free() each line or store them to a new StringList depending on
     * the caller's choice.
     */
    ppszDst = papszStrList + nFirstLineToDelete;

    if (ppapszRetStrings == NULL)
    {
        /* free() all the strings that will be removed.
         */
        for (i=0; i < nNumToRemove; i++)
        {
            CPLFree(*ppszDst);
            *ppszDst = NULL;
        }
    }
    else
    {
        /* Store the strings to remove in a new StringList
         */
        *ppapszRetStrings = (char **)CPLCalloc(nNumToRemove+1, sizeof(char*));

        for (i=0; i < nNumToRemove; i++)
        {
            (*ppapszRetStrings)[i] = *ppszDst;
            *ppszDst = NULL;
            ppszDst++;
        }
    }


    /* Shift down all the lines that follow the lines to remove.
     */
    if (nFirstLineToDelete == -1 || nFirstLineToDelete > nSrcLines)
        nFirstLineToDelete = nDstLines;

    ppszSrc = papszStrList + nFirstLineToDelete + nNumToRemove;
    ppszDst = papszStrList + nFirstLineToDelete;

    for ( ; *ppszSrc != NULL; ppszSrc++, ppszDst++)
    {
        *ppszDst = *ppszSrc;
    }
    /* Move the NULL pointer at the end of the StringList     */
    *ppszDst = *ppszSrc; 

    /* At this point, we could realloc() papszStrList to a smaller size, but
     * since this array will likely grow again in further operations on the
     * StringList we'll leave it as it is.
     */

    return papszStrList;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movl %edx, %r15d
movq %rdi, %rbx
xorl %r12d, %r12d
testq %rdi, %rdi
je 0x5f79
cmpq $0x0, (%rbx)
je 0x5f79
xorl %r12d, %r12d
cmpq $0x0, 0x8(%rbx,%r12,8)
leaq 0x1(%r12), %r12
jne 0x5f6c
testl %r15d, %r15d
setle %al
testl %r12d, %r12d
sete %cl
orb %al, %cl
jne 0x6044
movl %r12d, %eax
subl %r15d, %eax
testl %eax, %eax
jle 0x5fe4
movl %eax, (%rsp)
movl %esi, 0x4(%rsp)
movslq %esi, %rax
leaq (%rbx,%rax,8), %rbp
movl %r15d, %r13d
testq %r14, %r14
je 0x5ff0
leal 0x1(%r15), %edi
movl $0x8, %esi
callq 0x2d54
movq %rax, (%r14)
testl %r15d, %r15d
jle 0x600b
xorl %eax, %eax
movq (%rbp,%rax,8), %rcx
movq (%r14), %rdx
movq %rcx, (%rdx,%rax,8)
movq $0x0, (%rbp,%rax,8)
incq %rax
cmpq %rax, %r13
jne 0x5fc5
jmp 0x600b
movq %rbx, %rdi
callq 0x596e
xorl %ebx, %ebx
jmp 0x6044
testl %r15d, %r15d
jle 0x600b
movq (%rbp), %rdi
callq 0x701d
movq $0x0, (%rbp)
decl %r15d
jne 0x5ff5
movl 0x4(%rsp), %ecx
cmpl %ecx, %r12d
movl %ecx, %eax
movl (%rsp), %edx
cmovll %edx, %eax
cmpl $-0x1, %ecx
cmovel %edx, %eax
cltq
leaq (%rbx,%rax,8), %rax
movq (%rax,%r13,8), %rcx
testq %rcx, %rcx
je 0x603d
movq %rcx, (%rax)
movq 0x8(%rax,%r13,8), %rcx
addq $0x8, %rax
jmp 0x602a
movq $0x0, (%rax)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq