// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: StreamReadLine
static jx9_int64 StreamReadLine(io_private *pDev, const char **pzData, jx9_int64 nMaxLen)
{
	const jx9_io_stream *pStream = pDev->pStream;
	char zBuf[8192];
	jx9_int64 n;
	sxi32 rc;
	n = 0;
	if( pDev->nOfft >= SyBlobLength(&pDev->sBuffer) ){
		/* Reset the working buffer so that we avoid excessive memory allocation */
		SyBlobReset(&pDev->sBuffer);
		pDev->nOfft = 0;
	}
	if( SyBlobLength(&pDev->sBuffer) - pDev->nOfft > 0 ){
		/* Check if there is a line */
		rc = GetLine(pDev, &n, pzData);
		if( rc == SXRET_OK ){
			/* Got line, update the cursor  */
			pDev->nOfft += (sxu32)n;
			return n;
		}
	}
	/* Perform the read operation until a new line is extracted or length
	 * limit is reached.
	 */
	for(;;){
		n = pStream->xRead(pDev->pHandle, zBuf, (nMaxLen > 0 && nMaxLen < sizeof(zBuf)) ? nMaxLen : sizeof(zBuf));
		if( n < 1 ){
			/* EOF or IO error */
			break;
		}
		/* Append the data just read */
		SyBlobAppend(&pDev->sBuffer, zBuf, (sxu32)n);
		/* Try to extract a line */
		rc = GetLine(pDev, &n, pzData);
		if( rc == SXRET_OK ){
			/* Got one, return immediately */
			pDev->nOfft += (sxu32)n;
			return n;
		}
		if( nMaxLen > 0 && (SyBlobLength(&pDev->sBuffer) - pDev->nOfft >= nMaxLen) ){
			/* Read limit reached, return the available data */
			*pzData = (const char *)SyBlobDataAt(&pDev->sBuffer, pDev->nOfft);
			n = SyBlobLength(&pDev->sBuffer) - pDev->nOfft;
			/* Reset the working buffer */
			SyBlobReset(&pDev->sBuffer);
			pDev->nOfft = 0;
			return n;
		}
	}
	if( SyBlobLength(&pDev->sBuffer) - pDev->nOfft > 0 ){
		/* Read limit reached, return the available data */
		*pzData = (const char *)SyBlobDataAt(&pDev->sBuffer, pDev->nOfft);
		n = SyBlobLength(&pDev->sBuffer) - pDev->nOfft;
		/* Reset the working buffer */
		SyBlobReset(&pDev->sBuffer);
		pDev->nOfft = 0;
	}
	return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2018, %rsp           # imm = 0x2018
movq %rdx, %r15
movq %rdi, %rbx
movq (%rdi), %rax
movq %rax, -0x38(%rbp)
movl 0x20(%rdi), %eax
movl 0x30(%rdi), %ecx
cmpl %ecx, %eax
jbe 0x64b28
movq 0x18(%rbx), %rdx
addq %rcx, %rdx
subl %ecx, %eax
addq %rdx, %rax
xorl %r8d, %r8d
cmpb $0xa, (%rdx,%r8)
je 0x64bf5
leaq (%rdx,%r8), %rdi
incq %rdi
incq %r8
cmpq %rax, %rdi
jb 0x64b0c
jmp 0x64b52
movl $0x0, 0x20(%rbx)
movl 0x28(%rbx), %eax
testb $0x4, %al
je 0x64b4b
movq $0x0, 0x18(%rbx)
movl $0x0, 0x24(%rbx)
andl $-0x5, %eax
movl %eax, 0x28(%rbx)
movl $0x0, 0x30(%rbx)
movq %rsi, -0x30(%rbp)
leaq 0x10(%rbx), %r12
leaq -0x1(%r15), %rax
cmpq $0x1fff, %rax           # imm = 0x1FFF
movl $0x2000, %r13d          # imm = 0x2000
cmovbq %r15, %r13
leaq -0x2040(%rbp), %r14
movq 0x8(%rbx), %rdi
movq %r14, %rsi
movq %r13, %rdx
movq -0x38(%rbp), %rax
callq *0x30(%rax)
testq %rax, %rax
jle 0x64c16
movq %r12, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x359ad
movl 0x20(%rbx), %eax
movl 0x30(%rbx), %edx
movq %rdx, %rcx
addq 0x18(%rbx), %rcx
subl %edx, %eax
je 0x64bc8
leaq (%rcx,%rax), %rdi
xorl %esi, %esi
cmpb $0xa, (%rcx,%rsi)
je 0x64be3
leaq (%rcx,%rsi), %r8
incq %r8
incq %rsi
cmpq %rdi, %r8
jb 0x64bb3
testq %r15, %r15
setle %dl
cmpq %r15, %rax
setl %sil
orb %dl, %sil
jne 0x64b75
movq -0x30(%rbp), %rdx
movq %rcx, (%rdx)
jmp 0x64c32
leaq 0x1(%rsi), %rax
movq -0x30(%rbp), %rdi
movq %rcx, (%rdi)
leal (%rdx,%rsi), %ecx
incl %ecx
jmp 0x64c01
leaq 0x1(%r8), %rax
movq %rdx, (%rsi)
addl %r8d, %ecx
incl %ecx
movl %ecx, 0x30(%rbx)
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x20(%rbx), %ecx
movl 0x30(%rbx), %edx
cmpl %edx, %ecx
je 0x64c04
movq %rdx, %rax
addq 0x18(%rbx), %rax
movq -0x30(%rbp), %rsi
movq %rax, (%rsi)
movl %ecx, %eax
subl %edx, %eax
movl $0x0, 0x20(%rbx)
movl 0x28(%rbx), %edx
xorl %ecx, %ecx
testb $0x4, %dl
je 0x64c01
movq $0x0, 0x18(%rbx)
movl $0x0, 0x24(%rbx)
andl $-0x5, %edx
movl %edx, 0x28(%rbx)
jmp 0x64c01