// File: /workspace/github_c_makefile_star2_O0/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
subq $0x2060, %rsp           # imm = 0x2060
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x2038(%rbp)
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jb 0xaad95
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x65e00
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x30(%rcx), %eax
cmpl $0x0, %eax
jbe 0xaadf0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x2038(%rbp), %rsi
callq 0xaafd0
movl %eax, -0x203c(%rbp)
cmpl $0x0, -0x203c(%rbp)
jne 0xaadee
movq -0x2038(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
addl 0x30(%rax), %ecx
movl %ecx, 0x30(%rax)
movq -0x2038(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xaafbe
jmp 0xaadf0
jmp 0xaadf2
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x2058(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x2050(%rbp)
leaq -0x2030(%rbp), %rax
movq %rax, -0x2048(%rbp)
cmpq $0x0, -0x20(%rbp)
jle 0xaae3c
cmpq $0x2000, -0x20(%rbp)    # imm = 0x2000
jae 0xaae3c
movq -0x20(%rbp), %rax
movq %rax, -0x2060(%rbp)
jmp 0xaae4a
movl $0x2000, %eax           # imm = 0x2000
movq %rax, -0x2060(%rbp)
jmp 0xaae4a
movq -0x2058(%rbp), %rax
movq -0x2048(%rbp), %rsi
movq -0x2050(%rbp), %rdi
movq -0x2060(%rbp), %rdx
callq *%rax
movq %rax, -0x2038(%rbp)
cmpq $0x1, -0x2038(%rbp)
jge 0xaae7e
jmp 0xaaf58
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
leaq -0x2030(%rbp), %rsi
movq -0x2038(%rbp), %rax
movl %eax, %edx
callq 0x5d9d0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x2038(%rbp), %rsi
callq 0xaafd0
movl %eax, -0x203c(%rbp)
cmpl $0x0, -0x203c(%rbp)
jne 0xaaee1
movq -0x2038(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
addl 0x30(%rax), %ecx
movl %ecx, 0x30(%rax)
movq -0x2038(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xaafbe
cmpq $0x0, -0x20(%rbp)
jle 0xaaf53
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x30(%rcx), %eax
movl %eax, %eax
cmpq -0x20(%rbp), %rax
jl 0xaaf53
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x30(%rcx), %eax
movl %eax, %eax
movq %rax, -0x2038(%rbp)
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x65e00
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x2038(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xaafbe
jmp 0xaadf2
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x30(%rcx), %eax
cmpl $0x0, %eax
jbe 0xaafb3
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x30(%rcx), %eax
movl %eax, %eax
movq %rax, -0x2038(%rbp)
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
callq 0x65e00
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x2038(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x2060, %rsp           # imm = 0x2060
popq %rbp
retq
nopl (%rax,%rax)