// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movzwl 0x28(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x65ee1
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1a, %ecx
movq -0x38(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl %ecx, %esi
movq -0x20(%rbp), %rdx
callq *%rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x65edc
movl $0xfffffff6, -0x3c(%rbp) # imm = 0xFFFFFFF6
jmp 0x6607d
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x65f19
cmpq $0x1, -0x50(%rbp)
jae 0x65f1e
jmp 0x66076
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
movq -0x68(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq *%rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x65f51
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x66083
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x5c(%rbp)
jne 0x65f98
movq -0x10(%rbp), %rax
movzwl 0x38(%rax), %ecx
movq -0x38(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movl 0x110(%rax), %eax
movq -0x10(%rbp), %rcx
movzwl 0x38(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x60(%rbp)
movl $0x1, -0x5c(%rbp)
jmp 0x65fb4
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movl 0x110(%rax), %eax
subl $0x8, %eax
movl %eax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movl -0x60(%rbp), %ecx
cmpq %rcx, %rax
ja 0x66004
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rcx
movl %ecx, %esi
movq -0x20(%rbp), %rdx
callq *%rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x65ffa
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x50(%rax), %rax
movq -0x58(%rbp), %rdi
callq *%rax
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x66083
movq $0x0, -0x50(%rbp)
jmp 0x66050
cmpl $0x0, -0x60(%rbp)
jbe 0x6604e
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rdi
movl -0x60(%rbp), %esi
movq -0x20(%rbp), %rdx
callq *%rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x6603e
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x50(%rax), %rax
movq -0x58(%rbp), %rdi
callq *%rax
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x66083
movl -0x60(%rbp), %eax
movl %eax, %ecx
movq -0x50(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x50(%rbp)
jmp 0x66050
movq -0x58(%rbp), %rax
movq (%rax), %rdi
leaq -0x68(%rbp), %rsi
callq 0x61db0
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x50(%rax), %rax
movq -0x58(%rbp), %rdi
callq *%rax
jmp 0x65f0b
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)