// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: lhConsumeCellkey
static int lhConsumeCellkey(
	lhcell *pCell, /* Target cell */
	int (*xConsumer)(const void *,unsigned int,void *), /* Consumer callback */
	void *pUserData, /* Last argument to xConsumer() */
	int offt_only
	)
{
	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 key directly without any overflow page */
		zPayload += L_HASH_CELL_SZ;
		rc = xConsumer((const void *)zPayload,pCell->nKey,pUserData);
		if( rc != UNQLITE_OK ){
			rc = UNQLITE_ABORT;
		}
	}else{
		lhash_kv_engine *pEngine = pPage->pHash;
		sxu32 nByte,nData = pCell->nKey;
		unqlite_page *pOvfl;
		int data_offset = 0;
		pgno iOvfl;
		/* Overflow page */
		iOvfl = pCell->iOvfl;
		/* Total usable bytes in an overflow page */
		nByte = L_HASH_OVERFLOW_SIZE(pEngine->iPageSize);
		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;
			}
			zPayload = &pOvfl->zData[8];
			/* Point to the raw content */
			if( !data_offset ){
				/* Get the data page and offset */
				SyBigEndianUnpack64(zPayload,&pCell->iDataPage);
				zPayload += 8;
				SyBigEndianUnpack16(zPayload,&pCell->iDataOfft);
				zPayload += 2;
				if( offt_only ){
					/* Key too large, grab the data offset and return */
					pEngine->pIo->xPageUnref(pOvfl);
					return UNQLITE_OK;
				}
				data_offset = 1;
			}
			/* Consume the key */
			if( nData <= nByte ){
				rc = xConsumer((const void *)zPayload,nData,pUserData);
				if( rc != UNQLITE_OK ){
					pEngine->pIo->xPageUnref(pOvfl);
					return UNQLITE_ABORT;
				}
				nData = 0;
			}else{
				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)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movzwl 0x28(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x65656
movq -0x40(%rbp), %rax
addq $0x1a, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %esi
movq -0x20(%rbp), %rdx
callq *%rax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x65651
movl $0xfffffff6, -0x44(%rbp) # imm = 0xFFFFFFF6
jmp 0x657fd
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x64(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rax
movl 0x110(%rax), %eax
subl $0x8, %eax
movl %eax, -0x54(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x6569b
cmpl $0x1, -0x58(%rbp)
jae 0x656a0
jmp 0x657f6
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
movq -0x70(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq *%rax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x656d3
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x65803
movq -0x60(%rbp), %rax
movq (%rax), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x64(%rbp)
jne 0x6574c
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
callq 0x61db0
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x38, %rsi
callq 0x64c70
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x65745
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq 0x50(%rax), %rax
movq -0x60(%rbp), %rdi
callq *%rax
movl $0x0, -0x4(%rbp)
jmp 0x65803
movl $0x1, -0x64(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
ja 0x65791
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rdi
movl -0x58(%rbp), %esi
movq -0x20(%rbp), %rdx
callq *%rax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x65788
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq 0x50(%rax), %rax
movq -0x60(%rbp), %rdi
callq *%rax
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x65803
movl $0x0, -0x58(%rbp)
jmp 0x657d0
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rdi
movl -0x54(%rbp), %esi
movq -0x20(%rbp), %rdx
callq *%rax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x657c5
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq 0x50(%rax), %rax
movq -0x60(%rbp), %rdi
callq *%rax
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x65803
movl -0x54(%rbp), %ecx
movl -0x58(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x58(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rdi
leaq -0x70(%rbp), %rsi
callq 0x61db0
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq 0x50(%rax), %rax
movq -0x60(%rbp), %rdi
callq *%rax
jmp 0x6568e
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)