// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
testq %rdi, %rdi
je 0x3183
movq %rdi, %r14
xorl %r15d, %r15d
pushq $0x1
popq %r13
xorl %r12d, %r12d
xorl %ebp, %ebp
leal 0x29(%r12), %edi
callq 0x2fd4
movq %rax, %rbx
leal 0x1(%rbp), %eax
cmpl %eax, %r15d
jne 0x30ec
movslq %ebp, %rax
movb (%rsp,%rax), %al
movb %al, (%rsp)
leaq 0x1(%rsp), %rdi
movq %r13, %rsi
pushq $0x27
popq %rdx
movq %r14, %rcx
callq 0x695f
movq %rax, %r15
testl %r15d, %r15d
je 0x3194
incl %r15d
jmp 0x3109
movq %rsp, %rdi
movq %r13, %rsi
pushq $0x28
popq %rdx
movq %r14, %rcx
callq 0x695f
movq %rax, %r15
testl %r15d, %r15d
je 0x318f
movslq %r15d, %rax
decq %rax
movslq %r12d, %r12
xorl %ecx, %ecx
cmpl %eax, %ecx
jge 0x3132
movzbl (%rsp,%rcx), %edx
cmpl $0xa, %edx
je 0x3136
cmpl $0xd, %edx
je 0x3144
movb %dl, (%rbx,%r12)
incq %r12
incq %rcx
jmp 0x3114
movl %ecx, %ebp
jmp 0x3151
cmpb $0xd, 0x1(%rsp,%rcx)
jne 0x314b
movl %ecx, %ebp
addl $0x2, %ebp
jmp 0x3151
cmpb $0xa, 0x1(%rsp,%rcx)
je 0x313d
movq %rcx, %rbp
incq %rbp
cmpl %eax, %ecx
jl 0x319a
cmpl $0x27, %r15d
jg 0x30aa
cmpl %eax, %ebp
jne 0x30aa
movzbl (%rsp,%rax), %eax
cmpl $0xd, %eax
je 0x31ba
cmpl $0xa, %eax
je 0x31ba
movb %al, (%rbx,%r12)
leal 0x1(%r12), %eax
movl %eax, %r12d
jmp 0x31ba
pushq $-0x1
popq %rdi
callq 0x2fd4
xorl %ebx, %ebx
jmp 0x31c1
xorl %r15d, %r15d
jmp 0x319a
pushq $0x1
popq %rax
movl %eax, %r15d
subl %ebp, %r15d
jle 0x31ba
movq %r14, %rdi
callq 0x6947
movslq %r15d, %rcx
subq %rcx, %rax
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x693f
movslq %r12d, %rax
movb $0x0, (%rbx,%rax)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq