// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, -0x3c(%rbp)
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rdx
movq 0x18(%rdi), %rsi
movq 0x20(%rdi), %rax
testq %rsi, %rsi
je 0x31a84
movq (%rax), %rax
movl 0x4(%rdx), %ebx
leaq -0x50(%rbp), %rcx
movq %rsi, (%rcx)
movq %rax, -0x30(%rbp)
movl 0x110(%rax), %eax
addl $-0x8, %eax
movl %eax, -0x40(%rbp)
movq %rdx, -0x60(%rbp)
leaq 0x30(%rdx), %rax
movq %rax, -0x58(%rbp)
movb $0x1, %r12b
movq %r13, -0x48(%rbp)
xorl %ecx, %ecx
testq %rsi, %rsi
je 0x31ad0
testl %ebx, %ebx
je 0x31ad0
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x31aaa
movq %r15, %r13
movq -0x38(%rbp), %r14
movq (%r14), %r15
leaq 0x8(%r15), %rdi
testb $0x1, %r12b
je 0x31a31
movq -0x58(%rbp), %rsi
callq 0x2f685
movzwl 0x10(%r15), %eax
rolw $0x8, %ax
movq -0x60(%rbp), %rcx
movw %ax, 0x38(%rcx)
cmpl $0x0, -0x3c(%rbp)
jne 0x31ac1
addq $0x12, %r15
movq %r15, %rdi
movl %ebx, %r14d
movl -0x40(%rbp), %esi
subl %esi, %r14d
movq %r13, %r15
jbe 0x31a48
movq -0x48(%rbp), %rdx
callq *%r15
jmp 0x31a54
movl %ebx, %esi
movq -0x48(%rbp), %rdx
callq *%r15
xorl %r14d, %r14d
testl %eax, %eax
jne 0x31aae
movq -0x38(%rbp), %rbx
movq (%rbx), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2f685
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rbx, %rdi
callq *0x50(%rax)
xorl %r12d, %r12d
movq -0x50(%rbp), %rsi
movl %r14d, %ebx
jmp 0x319c6
movq 0x8(%rax), %rax
movq (%rax), %rax
movzwl 0x28(%rdx), %ecx
leaq (%rax,%rcx), %rdi
addq $0x1a, %rdi
movl 0x4(%rdx), %esi
movq %r13, %rdx
callq *%r15
testl %eax, %eax
pushq $-0xa
popq %rcx
cmovel %eax, %ecx
jmp 0x31ad0
movl %eax, %ecx
jmp 0x31ad0
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *0x50(%rax)
pushq $-0xa
popq %rcx
jmp 0x31ad0
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %r14, %rdi
callq *0x50(%rax)
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq