// File: rurban[P]dgnlib/cpl_error.cpp
// Function: CPLDebug
void CPLDebug( const char * pszCategory, const char * pszFormat, ... )

{
    CPLErrorContext *psCtx = CPLGetErrorContext();
    char        *pszMessage;
    va_list     args;
    const char  *pszDebug = CPLGetConfigOption("CPL_DEBUG",NULL);

#define ERROR_MAX 25000

/* -------------------------------------------------------------------- */
/*      Does this message pass our current criteria?                    */
/* -------------------------------------------------------------------- */
    if( pszDebug == NULL )
        return;

    if( !EQUAL(pszDebug,"ON") && !EQUAL(pszDebug,"") )
    {
        int            i, nLen = strlen(pszCategory);

        for( i = 0; pszDebug[i] != '\0'; i++ )
        {
            if( EQUALN(pszCategory,pszDebug+i,nLen) )
                break;
        }

        if( pszDebug[i] == '\0' )
            return;
    }

/* -------------------------------------------------------------------- */
/*    Allocate a block for the error.                                   */
/* -------------------------------------------------------------------- */
    pszMessage = (char *) VSIMalloc( ERROR_MAX );
    if( pszMessage == NULL )
        return;
        
/* -------------------------------------------------------------------- */
/*      Dal -- always log a timestamp as the first part of the line     */
/*      to ensure one is looking at what one should be looking at!      */
/* -------------------------------------------------------------------- */

    pszMessage[0] = '\0';
#ifdef TIMESTAMP_DEBUG
    if( CPLGetConfigOption( "CPL_TIMESTAMP", NULL ) != NULL )
    {
        strcpy( pszMessage, VSICTime( VSITime(NULL) ) );
        
        // On windows anyway, ctime puts a \n at the end, but I'm not 
        // convinced this is standard behaviour, so we'll get rid of it
        // carefully

        if (pszMessage[strlen(pszMessage) -1 ] == '\n')
        {
            pszMessage[strlen(pszMessage) - 1] = 0; // blow it out
        }
        strcat( pszMessage, ": " );
    }
#endif

/* -------------------------------------------------------------------- */
/*      Add the category.                                               */
/* -------------------------------------------------------------------- */
    strcat( pszMessage, pszCategory );
    strcat( pszMessage, ": " );
    
/* -------------------------------------------------------------------- */
/*      Format the application provided portion of the debug message.   */
/* -------------------------------------------------------------------- */
    va_start(args, pszFormat);
#if defined(HAVE_VSNPRINTF)
    vsnprintf(pszMessage+strlen(pszMessage), ERROR_MAX - strlen(pszMessage), 
              pszFormat, args);
#else
    vsprintf(pszMessage+strlen(pszMessage), pszFormat, args);
#endif
    va_end(args);

/* -------------------------------------------------------------------- */
/*      Invoke the current error handler.                               */
/* -------------------------------------------------------------------- */
    if( psCtx->psHandlerStack != NULL )
    {
        psCtx->psHandlerStack->pfnHandler( CE_Debug, CPLE_None, pszMessage );
    }
    else
    {
        CPLMutexHolderD( &hErrorMutex );
        if( pfnErrorHandler != NULL )
            pfnErrorHandler( CE_Debug, CPLE_None, pszMessage );
    }

    VSIFree( pszMessage );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
testb %al, %al
je 0x5a47
movaps %xmm0, -0x100(%rbp)
movaps %xmm1, -0xf0(%rbp)
movaps %xmm2, -0xe0(%rbp)
movaps %xmm3, -0xd0(%rbp)
movaps %xmm4, -0xc0(%rbp)
movaps %xmm5, -0xb0(%rbp)
movaps %xmm6, -0xa0(%rbp)
movaps %xmm7, -0x90(%rbp)
movq %r9, -0x108(%rbp)
movq %r8, -0x110(%rbp)
movq %rcx, -0x118(%rbp)
movq %rdx, -0x120(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x5990
movq %rax, -0x18(%rbp)
leaq 0x13ad3(%rip), %rdi     # 0x1954e
xorl %eax, %eax
movl %eax, %esi
callq 0x40b0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x5a94
jmp 0x5d14
movq -0x48(%rbp), %rdi
leaq 0x13f01(%rip), %rsi     # 0x199a0
callq 0x2300
cmpl $0x0, %eax
je 0x5b26
movq -0x48(%rbp), %rdi
leaq 0x141d0(%rip), %rsi     # 0x19c84
callq 0x2300
cmpl $0x0, %eax
je 0x5b26
movq -0x8(%rbp), %rdi
callq 0x2120
movl %eax, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x5b0e
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movslq -0x4c(%rbp), %rax
addq %rax, %rsi
movslq -0x50(%rbp), %rdx
callq 0x23c0
cmpl $0x0, %eax
jne 0x5b01
jmp 0x5b0e
jmp 0x5b03
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x5ad1
movq -0x48(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x5b24
jmp 0x5d14
jmp 0x5b26
movl $0x61a8, %edi           # imm = 0x61A8
callq 0x9fb0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x5b40
jmp 0x5d14
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
leaq 0x13a0a(%rip), %rdi     # 0x19558
xorl %eax, %eax
movl %eax, %esi
callq 0x40b0
cmpq $0x0, %rax
je 0x5bed
movq -0x20(%rbp), %rax
movq %rax, -0x140(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0xa080
movq %rax, %rdi
callq 0xa0c0
movq -0x140(%rbp), %rdi
movq %rax, %rsi
callq 0x22c0
movq -0x20(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2120
movq %rax, %rcx
movq -0x138(%rbp), %rax
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x5bdd
movq -0x20(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2120
movq %rax, %rcx
movq -0x148(%rbp), %rax
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
movq -0x20(%rbp), %rdi
leaq 0x1397e(%rip), %rsi     # 0x19566
callq 0x2500
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x2500
movq -0x20(%rbp), %rdi
leaq 0x13961(%rip), %rsi     # 0x19566
callq 0x2500
leaq -0x40(%rbp), %rax
leaq -0x130(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2120
movq %rax, %rcx
movq -0x158(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x150(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2120
movq -0x150(%rbp), %rdi
movl $0x61a8, %esi           # imm = 0x61A8
subq %rax, %rsi
movq -0x10(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x21a0
leaq -0x40(%rbp), %rax
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x5ca5
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rdx
movl $0x1, %edi
xorl %esi, %esi
callq *%rax
jmp 0x5d0b
leaq -0x68(%rbp), %rdi
leaq 0x199b0(%rip), %rsi     # 0x1f660
movsd 0x13568(%rip), %xmm0    # 0x19220
leaq 0x13881(%rip), %rdx     # 0x19540
movl $0x15e, %ecx            # imm = 0x15E
callq 0x6370
cmpq $0x0, 0x195ff(%rip)     # 0x1f2d0
je 0x5d02
movq 0x195f6(%rip), %rax     # 0x1f2d0
movq -0x20(%rbp), %rdx
movl $0x1, %edi
xorl %esi, %esi
callq *%rax
jmp 0x5ce9
jmp 0x5d02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x6390
jmp 0x5d1d
leaq -0x68(%rbp), %rdi
callq 0x6390
movq -0x20(%rbp), %rdi
callq 0xa000
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x24f0
nopw %cs:(%rax,%rax)