// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rsi, %r13
movq 0x18(%rdi), %r14
movq 0x20(%rdi), %rax
testq %r14, %r14
je 0x39242
movl 0x4(%rdi), %r12d
xorl %ebx, %ebx
testl %r12d, %r12d
je 0x39295
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movl 0x110(%rax), %eax
addl $-0x8, %eax
movl %eax, -0x40(%rbp)
movq %rdi, -0x58(%rbp)
leaq 0x30(%rdi), %rax
movq %rax, -0x50(%rbp)
movb $0x1, %bl
movq %r15, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rdi
movq %r14, %rsi
leaq -0x38(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x3926d
movq %r13, %r15
movq -0x38(%rbp), %r14
movq (%r14), %r13
leaq 0x8(%r13), %rdi
testb $0x1, %bl
je 0x391eb
movq -0x50(%rbp), %rsi
callq 0x36f8d
movzwl 0x10(%r13), %eax
rolw $0x8, %ax
movq -0x58(%rbp), %rcx
movw %ax, 0x38(%rcx)
cmpl $0x0, -0x3c(%rbp)
jne 0x39286
addq $0x12, %r13
movq %r13, %rdi
movl %r12d, %ebx
movl -0x40(%rbp), %esi
subl %esi, %ebx
movq %r15, %r13
jbe 0x39208
movq -0x48(%rbp), %rdx
callq *%r13
testl %eax, %eax
jne 0x39271
movl %ebx, %r12d
jmp 0x39219
movl %r12d, %esi
movq -0x48(%rbp), %rdx
callq *%r13
xorl %r12d, %r12d
testl %eax, %eax
jne 0x39271
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq (%rax), %r14
bswapq %r14
movq -0x30(%rbp), %rax
movq (%rax), %rax
callq *0x50(%rax)
xorl %ebx, %ebx
testq %r14, %r14
je 0x39295
testl %r12d, %r12d
jne 0x39191
jmp 0x39295
movq 0x8(%rax), %rax
movq (%rax), %rax
movzwl 0x28(%rdi), %ecx
movq %rdi, %rdx
leaq (%rax,%rcx), %rdi
addq $0x1a, %rdi
movl 0x4(%rdx), %esi
movq %r15, %rdx
callq *%r13
testl %eax, %eax
movl $0xfffffff6, %ebx       # imm = 0xFFFFFFF6
cmovel %eax, %ebx
jmp 0x39295
movl %eax, %ebx
jmp 0x39295
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *0x50(%rax)
movl $0xfffffff6, %ebx       # imm = 0xFFFFFFF6
jmp 0x39295
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %r14, %rdi
callq *0x50(%rax)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq