// File: /workspace/github_cpp_makefile_star2_O3/rurban[P]dgnlib/cpl_conv.cpp
// Function: CPLUnlinkTree
int CPLUnlinkTree( const char *pszPath )

{
/* -------------------------------------------------------------------- */
/*      First, ensure there isn't any such file yet.                    */
/* -------------------------------------------------------------------- */
    VSIStatBuf sStatBuf;

    if( VSIStat( pszPath, &sStatBuf ) != 0 )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "It seems no file system object called '%s' exists.",
                  pszPath );

        return errno;
    }

/* -------------------------------------------------------------------- */
/*      If it's a simple file, just delete it.                          */
/* -------------------------------------------------------------------- */
    if( VSI_ISREG( sStatBuf.st_mode ) )
    {
        if( VSIUnlink( pszPath ) != 0 )
        {
            CPLError( CE_Failure, CPLE_AppDefined, 
                      "Failed to unlink %s.\n%s", 
                      pszPath, VSIStrerror( errno ) );
            return errno;
        }
        else
            return 0;
    }

/* -------------------------------------------------------------------- */
/*      If it is a directory recurse then unlink the directory.         */
/* -------------------------------------------------------------------- */
    else if( VSI_ISDIR( sStatBuf.st_mode ) )
    {
        char **papszItems = CPLReadDir( pszPath );
        int  i;

        for( i = 0; papszItems != NULL && papszItems[i] != NULL; i++ )
        {
            char *pszSubPath;
            int nErr;

            if( EQUAL(papszItems[i],".") || EQUAL(papszItems[i],"..") )
                continue;

            pszSubPath = CPLStrdup(
                CPLFormFilename( pszPath, papszItems[i], NULL ) );

            nErr = CPLUnlinkTree( pszSubPath );
            CPLFree( pszSubPath );

            if( nErr != 0 )
            {
                CSLDestroy( papszItems );
                return nErr;
            }
        }
        
        CSLDestroy( papszItems );

        if( VSIRmdir( pszPath ) != 0 )
        {
            CPLError( CE_Failure, CPLE_AppDefined, 
                      "Failed to unlink %s.\n%s", 
                      pszPath, VSIStrerror( errno ) );
            return errno;
        }
        else
            return 0;
    }

/* -------------------------------------------------------------------- */
/*      otherwise report an error.                                      */
/* -------------------------------------------------------------------- */
    else
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "Failed to unlink %s.\nUnrecognised filesystem object.",
                  pszPath );
        return 1000;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %rsi
callq 0x6eec
testl %eax, %eax
je 0x4407
leaq 0xb0a6(%rip), %rdx      # 0xf47e
movl $0x3, %edi
movl $0x1, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x460c
callq 0x2040
movl (%rax), %ebp
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xf000, %eax           # imm = 0xF000
andl 0x20(%rsp), %eax
cmpl $0x4000, %eax           # imm = 0x4000
je 0x442f
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x44ff
movq %rbx, %rdi
callq 0x6db5
jmp 0x44c6
movq %rbx, %rdi
callq 0x45a8
movq %rax, %r12
testq %rax, %rax
je 0x44b6
movq (%r12), %r13
testq %r13, %r13
je 0x44b6
movq %r12, %r14
addq $0x8, %r14
leaq 0xc9da(%rip), %r15      # 0x10e30
movq %r13, %rdi
movq %r15, %rsi
callq 0x22e0
testl %eax, %eax
je 0x44aa
movq %r13, %rdi
leaq 0xb05a(%rip), %rsi      # 0xf4c9
callq 0x22e0
testl %eax, %eax
je 0x44aa
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x53ff
movq %rax, %rdi
callq 0x2e41
movq %rax, %r13
movq %rax, %rdi
callq 0x43af
movl %eax, %ebp
movq %r13, %rdi
callq 0x6edd
testl %ebp, %ebp
jne 0x452b
movq (%r14), %r13
addq $0x8, %r14
testq %r13, %r13
jne 0x4456
movq %r12, %rdi
callq 0x58b2
movq %rbx, %rdi
callq 0x6dbf
testl %eax, %eax
je 0x4524
callq 0x2040
movq %rax, %r14
movl (%rax), %edi
callq 0x6f6f
leaq 0xafd1(%rip), %rdx      # 0xf4b1
movl $0x3, %edi
movl $0x1, %esi
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x460c
movl (%r14), %ebp
jmp 0x43f3
leaq 0xafc6(%rip), %rdx      # 0xf4cc
movl $0x3, %edi
movl $0x1, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x460c
movl $0x3e8, %ebp            # imm = 0x3E8
jmp 0x43f3
xorl %ebp, %ebp
jmp 0x43f3
movq %r12, %rdi
callq 0x58b2
jmp 0x43f3