// File: /workspace/github_cpp_makefile_star2_O1/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 0x32e4
movq %rdi, %rbx
xorl %r15d, %r15d
movq %rsp, %r13
xorl %ebp, %ebp
xorl %r12d, %r12d
leal 0x29(%rbp), %edi
callq 0x30d3
movq %rax, %r14
leal 0x1(%r12), %eax
cmpl %eax, %r15d
jne 0x3209
movslq %r12d, %rax
movb (%rsp,%rax), %al
movb %al, (%rsp)
movl $0x1, %esi
movl $0x27, %edx
leaq 0x1(%rsp), %rdi
movq %rbx, %rcx
callq 0x6f33
movq %rax, %r15
testl %r15d, %r15d
je 0x32f8
incl %r15d
jmp 0x322a
movl $0x1, %esi
movl $0x28, %edx
movq %r13, %rdi
movq %rbx, %rcx
callq 0x6f33
movq %rax, %r15
testl %r15d, %r15d
je 0x32f3
leal -0x1(%r15), %eax
cmpl $0x2, %r15d
jl 0x329a
xorl %ecx, %ecx
xorl %r12d, %r12d
movslq %r12d, %rsi
movzbl (%rsp,%rsi), %edx
cmpl $0xa, %edx
je 0x325c
cmpl $0xd, %edx
jne 0x327e
cmpb $0xa, 0x1(%rsi,%r13)
je 0x3264
cmpl $0xd, %edx
je 0x3274
cmpl $0xa, %edx
jne 0x327e
cmpb $0xd, 0x1(%rsi,%r13)
jne 0x326a
addl $0x2, %r12d
jmp 0x3277
cmpl $0xd, %edx
je 0x3274
cmpl $0xa, %edx
jne 0x327e
incl %r12d
movl $0x1, %ecx
jmp 0x328a
incl %r12d
movslq %ebp, %rsi
incl %ebp
movb %dl, (%r14,%rsi)
testl %ecx, %ecx
sete %dl
cmpl %eax, %r12d
jge 0x329f
testl %ecx, %ecx
je 0x3239
jmp 0x329f
movb $0x1, %dl
xorl %r12d, %r12d
testb %dl, %dl
je 0x32d8
cmpl %eax, %r12d
setne %cl
cmpl $0x28, %r15d
setge %dl
movb $0x1, %al
orb %cl, %dl
jne 0x32da
movslq %r12d, %rax
movzbl (%rsp,%rax), %eax
cmpl $0xd, %eax
je 0x32c7
cmpl $0xa, %eax
jne 0x32cc
incl %r12d
jmp 0x32d8
incl %r12d
movslq %ebp, %rcx
incl %ebp
movb %al, (%r14,%rcx)
xorl %eax, %eax
testb %al, %al
jne 0x31c3
jmp 0x32fe
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x30d3
xorl %r14d, %r14d
jmp 0x3326
xorl %r15d, %r15d
jmp 0x32fe
movl $0x1, %r15d
subl %r12d, %r15d
jle 0x331e
movq %rbx, %rdi
callq 0x6f1b
movslq %r15d, %rcx
subq %rcx, %rax
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x6f13
movslq %ebp, %rax
movb $0x0, (%r14,%rax)
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq