// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, %r8
movq %rdi, %r15
movq 0x20(%rdi), %rax
cmpq $0x0, 0x18(%rdi)
je 0x395e9
movq %rdx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq 0x8(%r15), %r13
movq 0x30(%r15), %rbx
testq %rbx, %rbx
sete %cl
testq %r13, %r13
sete %dl
xorl %r12d, %r12d
orb %cl, %dl
jne 0x3962e
movq (%rax), %r14
movb $0x1, %r12b
movq (%r14), %rax
movq (%rax), %rdi
movq %rbx, %rsi
leaq -0x30(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x39614
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
testb $0x1, %r12b
je 0x3957b
movzwl 0x38(%r15), %edx
addq %rdx, %rax
movl 0x110(%r14), %ecx
subl %edx, %ecx
jmp 0x39589
addq $0x8, %rax
movl 0x110(%r14), %ecx
addl $-0x8, %ecx
movl %ecx, %esi
movq %r13, %rbx
subq %rsi, %rbx
jbe 0x395af
testq %rsi, %rsi
je 0x395c7
movq %rax, %rdi
movq -0x38(%rbp), %rdx
callq *-0x40(%rbp)
testl %eax, %eax
jne 0x3961e
movq -0x30(%rbp), %rdi
movq %rbx, %r13
jmp 0x395c7
movq %rax, %rdi
movl %r13d, %esi
movq -0x38(%rbp), %rdx
callq *-0x40(%rbp)
movq -0x30(%rbp), %rdi
testl %eax, %eax
jne 0x39619
xorl %r13d, %r13d
movq (%rdi), %rax
movq (%rax), %rbx
bswapq %rbx
movq (%r14), %rax
callq *0x50(%rax)
xorl %r12d, %r12d
testq %rbx, %rbx
je 0x3962e
testq %r13, %r13
jne 0x39543
jmp 0x3962e
movq 0x8(%rax), %rax
movzwl 0x28(%r15), %ecx
addq (%rax), %rcx
movl 0x4(%r15), %edi
movl 0x8(%r15), %esi
addl $0x1a, %edi
addq %rcx, %rdi
callq *%r8
testl %eax, %eax
movl $0xfffffff6, %r12d      # imm = 0xFFFFFFF6
cmovel %eax, %r12d
jmp 0x3962e
movl %eax, %r12d
jmp 0x3962e
movq (%r14), %rax
jmp 0x39625
movq (%r14), %rax
movq -0x30(%rbp), %rdi
callq *0x50(%rax)
movl $0xfffffff6, %r12d      # imm = 0xFFFFFFF6
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq