// File: rurban[P]dgnlib/cpl_path.cpp
// Function: CPLExtractRelativePath
const char *CPLExtractRelativePath( const char *pszBaseDir, 
                                    const char *pszTarget,
                                    int *pbGotRelative )

{
    int nBasePathLen;

/* -------------------------------------------------------------------- */
/*      If we don't have a basedir, then we can't relativize the path.  */
/* -------------------------------------------------------------------- */
    if( pszBaseDir == NULL )
    {
        if( pbGotRelative != NULL )
            *pbGotRelative = FALSE;

        return pszTarget;
    }

    nBasePathLen = strlen(pszBaseDir);

/* -------------------------------------------------------------------- */
/*      One simple case is where neither file has a path.  We return    */
/*      the original target filename and it is relative.                */
/* -------------------------------------------------------------------- */
    const char *pszTargetPath = CPLGetPath(pszTarget);

    if( (nBasePathLen == 0 || EQUAL(pszBaseDir,"."))
        && (strlen(pszTargetPath) == 0 || EQUAL(pszTargetPath,".")) )
    {
        if( pbGotRelative != NULL )
            *pbGotRelative = TRUE;

        return pszTarget;
    }

/* -------------------------------------------------------------------- */
/*      By this point, if we don't have a base path, we can't have a    */
/*      meaningful common prefix.                                       */
/* -------------------------------------------------------------------- */
    if( nBasePathLen == 0 )
    {
        if( pbGotRelative != NULL )
            *pbGotRelative = FALSE;

        return pszTarget;
    }

/* -------------------------------------------------------------------- */
/*      If we don't have a common path prefix, then we can't get a      */
/*      relative path.                                                  */
/* -------------------------------------------------------------------- */
    if( !EQUALN(pszBaseDir,pszTarget,nBasePathLen) 
        || (pszTarget[nBasePathLen] != '\\' 
            && pszTarget[nBasePathLen] != '/') )
    {
        if( pbGotRelative != NULL )
            *pbGotRelative = FALSE;

        return pszTarget;
    }

/* -------------------------------------------------------------------- */
/*      We have a relative path.  Strip it off to get a string to       */
/*      return.                                                         */
/* -------------------------------------------------------------------- */
    if( pbGotRelative != NULL )
        *pbGotRelative = TRUE;

    return pszTarget + nBasePathLen + 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x71b9
cmpq $0x0, -0x20(%rbp)
je 0x71ac
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x72c7
movq -0x10(%rbp), %rdi
callq 0x2120
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rdi
callq 0x67b0
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x71ed
movq -0x10(%rbp), %rdi
leaq 0x1380d(%rip), %rsi     # 0x1a9f0
callq 0x2300
cmpl $0x0, %eax
jne 0x722f
movq -0x30(%rbp), %rdi
callq 0x2120
cmpq $0x0, %rax
je 0x7211
movq -0x30(%rbp), %rdi
leaq 0x137e9(%rip), %rsi     # 0x1a9f0
callq 0x2300
cmpl $0x0, %eax
jne 0x722f
cmpq $0x0, -0x20(%rbp)
je 0x7222
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x72c7
cmpl $0x0, -0x24(%rbp)
jne 0x7250
cmpq $0x0, -0x20(%rbp)
je 0x7246
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x72c7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x24(%rbp), %rdx
callq 0x23c0
cmpl $0x0, %eax
jne 0x7288
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5c, %eax
je 0x72a3
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
je 0x72a3
cmpq $0x0, -0x20(%rbp)
je 0x7299
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x72c7
cmpq $0x0, -0x20(%rbp)
je 0x72b4
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
addq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)