// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: lhConsumeCellData
static int lhConsumeCellData(
	lhcell *pCell, /* Target cell */
	int (*xConsumer)(const void *,unsigned int,void *), /* Data consumer callback */
	void *pUserData /* Last argument to xConsumer() */
	)
{
	lhpage *pPage = pCell->pPage;
	const unsigned char *zRaw = pPage->pRaw->zData;
	const unsigned char *zPayload;
	int rc;
	/* Point to the payload area */
	zPayload = &zRaw[pCell->iStart];
	if( pCell->iOvfl == 0 ){
		/* Best scenario, consume the data directly without any overflow page */
		zPayload += L_HASH_CELL_SZ + pCell->nKey;
		rc = xConsumer((const void *)zPayload,(sxu32)pCell->nData,pUserData);
		if( rc != UNQLITE_OK ){
			rc = UNQLITE_ABORT;
		}
	}else{
		lhash_kv_engine *pEngine = pPage->pHash;
		sxu64 nData = pCell->nData;
		unqlite_page *pOvfl;
		int fix_offset = 0;
		sxu32 nByte;
		pgno iOvfl;
		/* Overflow page where data is stored */
		iOvfl = pCell->iDataPage;
		for(;;){
			if( iOvfl == 0 || nData < 1 ){
				/* no more overflow page */
				break;
			}
			/* Point to the overflow page */
			rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,iOvfl,&pOvfl);
			if( rc != UNQLITE_OK ){
				return rc;
			}
			/* Point to the raw content */
			zPayload = pOvfl->zData;
			if( !fix_offset ){
				/* Point to the data */
				zPayload += pCell->iDataOfft;
				nByte = pEngine->iPageSize - pCell->iDataOfft;
				fix_offset = 1;
			}else{
				zPayload += 8;
				/* Total usable bytes in an overflow page */
				nByte = L_HASH_OVERFLOW_SIZE(pEngine->iPageSize);
			}
			/* Consume the data */
			if( nData <= (sxu64)nByte ){
				rc = xConsumer((const void *)zPayload,(unsigned int)nData,pUserData);
				if( rc != UNQLITE_OK ){
					pEngine->pIo->xPageUnref(pOvfl);
					return UNQLITE_ABORT;
				}
				nData = 0;
			}else{
				if( nByte > 0 ){
					rc = xConsumer((const void *)zPayload,nByte,pUserData);
					if( rc != UNQLITE_OK ){
						pEngine->pIo->xPageUnref(pOvfl);
						return UNQLITE_ABORT;
					}
					nData -= nByte;
				}
			}
			/* Next overflow page in the chain */
			SyBigEndianUnpack64(pOvfl->zData,&iOvfl);
			/* Unref the page */
			pEngine->pIo->xPageUnref(pOvfl);
		}
		rc = UNQLITE_OK;
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r8
movq %rdi, %r12
movq 0x20(%rdi), %rax
cmpq $0x0, 0x18(%rdi)
je 0x31c32
movq %rdx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq (%rax), %rbx
movq 0x8(%r12), %r15
movq 0x30(%r12), %rsi
leaq -0x48(%rbp), %rax
movq %rsi, (%rax)
movb $0x1, %r14b
testq %rsi, %rsi
je 0x31c5c
testq %r15, %r15
je 0x31c5c
movq (%rbx), %rax
movq (%rax), %rdi
leaq -0x30(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x31c60
movq -0x30(%rbp), %r13
movq (%r13), %rdi
testb $0x1, %r14b
je 0x31bcb
movzwl 0x38(%r12), %ecx
addq %rcx, %rdi
movl 0x110(%rbx), %eax
subl %ecx, %eax
jmp 0x31bd8
addq $0x8, %rdi
movl 0x110(%rbx), %eax
addl $-0x8, %eax
movl %eax, %esi
movq %r15, %r14
subq %rsi, %r14
jbe 0x31bfb
testq %rsi, %rsi
je 0x31c10
movq -0x38(%rbp), %rdx
callq *-0x40(%rbp)
testl %eax, %eax
jne 0x31c6c
movq -0x30(%rbp), %r13
movq %r14, %r15
jmp 0x31c10
movl %r15d, %esi
movq -0x38(%rbp), %rdx
callq *-0x40(%rbp)
movq -0x30(%rbp), %r13
testl %eax, %eax
jne 0x31c64
xorl %r15d, %r15d
movq (%r13), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2f685
movq (%rbx), %rax
movq %r13, %rdi
callq *0x50(%rax)
xorl %r14d, %r14d
movq -0x48(%rbp), %rsi
jmp 0x31b83
movq 0x8(%rax), %rax
movzwl 0x28(%r12), %ecx
addq (%rax), %rcx
movl 0x4(%r12), %edi
movl 0x8(%r12), %esi
addl $0x1a, %edi
addq %rcx, %rdi
callq *%r8
testl %eax, %eax
pushq $-0xa
popq %rcx
cmovel %eax, %ecx
jmp 0x31c79
xorl %ecx, %ecx
jmp 0x31c79
movl %eax, %ecx
jmp 0x31c79
movq (%rbx), %rax
movq %r13, %rdi
jmp 0x31c73
movq (%rbx), %rax
movq -0x30(%rbp), %rdi
callq *0x50(%rax)
pushq $-0xa
popq %rcx
movl %ecx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq