// File: rurban[P]dgnlib/cpl_conv.cpp
// Function: CPLReadLineL
const char *CPLReadLineL( FILE * fp )

{
/* -------------------------------------------------------------------- */
/*      Cleanup case.                                                   */
/* -------------------------------------------------------------------- */
    if( fp == NULL )
    {
        CPLReadLineBuffer( -1 );
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Loop reading chunks of the line till we get to the end of       */
/*      the line.                                                       */
/* -------------------------------------------------------------------- */
    char *pszRLBuffer;
    const int nChunkSize = 40;
    char szChunk[nChunkSize];
    int nChunkBytesRead = 0;
    int nBufLength = 0;
    int nChunkBytesConsumed = 0;

    while( TRUE )
    {
/* -------------------------------------------------------------------- */
/*      Read a chunk from the input file.                               */
/* -------------------------------------------------------------------- */
        pszRLBuffer = CPLReadLineBuffer( nBufLength + nChunkSize + 1 );

        if( nChunkBytesRead == nChunkBytesConsumed + 1 )
        {
            // case where one character is left over from last read.
            szChunk[0] = szChunk[nChunkBytesConsumed];
            nChunkBytesRead = VSIFReadL( szChunk+1, 1, nChunkSize-1, fp ) + 1;
            if( nChunkBytesRead == 1 )
                break;
        }
        else
        {
            // fresh read.
            nChunkBytesRead = VSIFReadL( szChunk, 1, nChunkSize, fp );
            if( nChunkBytesRead == 0 )
                break;
        }
        
/* -------------------------------------------------------------------- */
/*      copy over characters watching for end-of-line.                  */
/* -------------------------------------------------------------------- */
        int bBreak = FALSE;
        nChunkBytesConsumed = 0;
        while( nChunkBytesConsumed < nChunkBytesRead-1 && !bBreak )
        {
            if( (szChunk[nChunkBytesConsumed] == 13
                 && szChunk[nChunkBytesConsumed+1] == 10)
                || (szChunk[nChunkBytesConsumed] == 10
                    && szChunk[nChunkBytesConsumed+1] == 13) )
            {
                nChunkBytesConsumed += 2;
                bBreak = TRUE;
            }
            else if( szChunk[nChunkBytesConsumed] == 10
                     || szChunk[nChunkBytesConsumed] == 13 )
            {
                nChunkBytesConsumed += 1;
                bBreak = TRUE;
            }
            else
                pszRLBuffer[nBufLength++] = szChunk[nChunkBytesConsumed++];
        }

        if( bBreak )
            break;

/* -------------------------------------------------------------------- */
/*      If there is a remaining character and it is not a newline       */
/*      consume it.  If it is a newline, but we are clearly at the      */
/*      end of the file then consume it.                                */
/* -------------------------------------------------------------------- */
        if( nChunkBytesConsumed == nChunkBytesRead-1 
            && nChunkBytesRead < nChunkSize )
        {
            if( szChunk[nChunkBytesConsumed] == 10
                || szChunk[nChunkBytesConsumed] == 13 )
            {
                nChunkBytesConsumed++;
                break;
            }

            pszRLBuffer[nBufLength++] = szChunk[nChunkBytesConsumed++];
            break;
        }
    }

/* -------------------------------------------------------------------- */
/*      If we have left over bytes after breaking out, seek back to     */
/*      ensure they remain to be read next time.                        */
/* -------------------------------------------------------------------- */
    if( nChunkBytesConsumed < nChunkBytesRead )
    {
        int nBytesToPush = nChunkBytesRead - nChunkBytesConsumed;
        
        VSIFSeekL( fp, VSIFTellL( fp ) - nBytesToPush, SEEK_SET );
    }

    pszRLBuffer[nBufLength] = '\0';

    return( pszRLBuffer );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x36ba
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3580
movq $0x0, -0x8(%rbp)
jmp 0x38f5
movl $0x28, -0x1c(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x58(%rbp), %edi
addl $0x28, %edi
addl $0x1, %edi
callq 0x3580
movq %rax, -0x18(%rbp)
movl -0x54(%rbp), %eax
movl -0x5c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x372f
movslq -0x5c(%rbp), %rax
movb -0x50(%rbp,%rax), %al
movb %al, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
addq $0x1, %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %esi
movl $0x27, %edx
callq 0x9be0
addq $0x1, %rax
movl %eax, -0x54(%rbp)
cmpl $0x1, -0x54(%rbp)
jne 0x372d
jmp 0x38aa
jmp 0x3756
leaq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %esi
movl $0x28, %edx
callq 0x9be0
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jne 0x3754
jmp 0x38aa
jmp 0x3756
movl $0x0, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %ecx
movl -0x54(%rbp), %edx
subl $0x1, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x65(%rbp)
jge 0x3782
cmpl $0x0, -0x60(%rbp)
setne %al
xorb $-0x1, %al
movb %al, -0x65(%rbp)
movb -0x65(%rbp), %al
testb $0x1, %al
jne 0x378e
jmp 0x383b
movslq -0x5c(%rbp), %rax
movsbl -0x50(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0x37ae
movl -0x5c(%rbp), %eax
addl $0x1, %eax
cltq
movsbl -0x50(%rbp,%rax), %eax
cmpl $0xa, %eax
je 0x37ce
movslq -0x5c(%rbp), %rax
movsbl -0x50(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x37e0
movl -0x5c(%rbp), %eax
addl $0x1, %eax
cltq
movsbl -0x50(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0x37e0
movl -0x5c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x5c(%rbp)
movl $0x1, -0x60(%rbp)
jmp 0x3836
movslq -0x5c(%rbp), %rax
movsbl -0x50(%rbp,%rax), %eax
cmpl $0xa, %eax
je 0x37fc
movslq -0x5c(%rbp), %rax
movsbl -0x50(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0x380e
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movl $0x1, -0x60(%rbp)
jmp 0x3834
movl -0x5c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x5c(%rbp)
cltq
movb -0x50(%rbp,%rax), %dl
movq -0x18(%rbp), %rax
movl -0x58(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x58(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x3836
jmp 0x3764
cmpl $0x0, -0x60(%rbp)
je 0x3843
jmp 0x38aa
movl -0x5c(%rbp), %eax
movl -0x54(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x38a5
cmpl $0x28, -0x54(%rbp)
jge 0x38a5
movslq -0x5c(%rbp), %rax
movsbl -0x50(%rbp,%rax), %eax
cmpl $0xa, %eax
je 0x3872
movslq -0x5c(%rbp), %rax
movsbl -0x50(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0x387d
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x38aa
movl -0x5c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x5c(%rbp)
cltq
movb -0x50(%rbp,%rax), %dl
movq -0x18(%rbp), %rax
movl -0x58(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x58(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x38aa
jmp 0x36d6
movl -0x5c(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0x38e1
movl -0x54(%rbp), %eax
subl -0x5c(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
callq 0x9b70
movq -0x70(%rbp), %rdi
movq %rax, %rsi
movslq -0x64(%rbp), %rax
subq %rax, %rsi
xorl %edx, %edx
callq 0x9b40
movq -0x18(%rbp), %rax
movslq -0x58(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nop