// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: lhStoreCell
static int lhStoreCell(
	lhpage *pPage, /* Target page */
	const void *pKey,sxu32 nKeyLen, /* Payload: Key */
	const void *pData,unqlite_int64 nDataLen, /* Payload: Data */
	sxu32 nHash, /* Hash of the key */
	int auto_append /* Auto append a slave page if full */
	)
{
	lhash_kv_engine *pEngine = pPage->pHash;
	int iNeedOvfl = 0; /* Need overflow page for this cell and its payload*/
	lhcell *pCell;
	sxu16 nOfft;
	int rc;
	/* Acquire a writer lock on this page first */
	rc = pEngine->pIo->xWrite(pPage->pRaw);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	/* Check for a free block  */
	rc = lhAllocateSpace(pPage,L_HASH_CELL_SZ+nKeyLen+nDataLen,&nOfft);
	if( rc != UNQLITE_OK ){
		/* Check for a free block to hold a single cell only (without payload) */
		rc = lhAllocateSpace(pPage,L_HASH_CELL_SZ,&nOfft);
		if( rc != UNQLITE_OK ){
			if( !auto_append ){
				/* A split must be done */
				return UNQLITE_FULL;
			}else{
				/* Store this record in a slave page */
				rc = lhSlaveStore(pPage,pKey,nKeyLen,pData,nDataLen,nHash);
				return rc;
			}
		}
		iNeedOvfl = 1;
	}
	/* Allocate a new cell instance */
	pCell = lhNewCell(pEngine,pPage);
	if( pCell == 0 ){
		pEngine->pIo->xErr(pEngine->pIo->pHandle,"KV store is running out of memory");
		return UNQLITE_NOMEM;
	}
	/* Fill-in the structure */
	pCell->iStart = nOfft;
	pCell->nKey = nKeyLen;
	pCell->nData = (sxu64)nDataLen;
	pCell->nHash = nHash;
	if( nKeyLen < 262144 /* 256 KB */ ){
		/* Keep the key in-memory for fast lookup */
		SyBlobAppend(&pCell->sKey,pKey,nKeyLen);
	}
	/* Link the cell */
	rc = lhInstallCell(pCell);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	/* Write the payload */
	if( iNeedOvfl ){
		rc = lhCellWriteOvflPayload(pCell,pKey,nKeyLen,pData,nDataLen,(const void *)0);
		if( rc != UNQLITE_OK ){
			lhCellDiscard(pCell);
			return rc;
		}
	}else{
		lhCellWriteLocalPayload(pCell,pKey,nKeyLen,pData,nDataLen);
	}
	/* Finally, Write the cell header */
	lhCellWriteHeader(pCell);
	/* All done */
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, -0x30(%rbp)
movq %r8, -0x50(%rbp)
movq %rcx, -0x48(%rbp)
movl %edx, %r13d
movq %rsi, %r15
movq %rdi, %r14
movq (%rdi), %r12
movq (%r12), %rax
movq 0x8(%rdi), %rdi
callq *0x28(%rax)
movl %eax, %ebx
testl %eax, %eax
jne 0x30943
movq %r15, -0x38(%rbp)
movq %r13, -0x40(%rbp)
leal 0x1a(%r13), %esi
movq -0x50(%rbp), %rbx
addq %rbx, %rsi
leaq -0x2a(%rbp), %rdx
movq %r14, %rdi
callq 0x30e98
movl %eax, %r13d
testl %eax, %eax
je 0x3089c
pushq $0x1a
popq %rsi
leaq -0x2a(%rbp), %rdx
movq %r14, %rdi
callq 0x30e98
testl %eax, %eax
je 0x3089c
cmpl $0x0, 0x10(%rbp)
je 0x30940
movq -0x40(%rbp), %r15
movl %r15d, %esi
movq %rbx, %r12
addq %rbx, %rsi
leaq -0x58(%rbp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x31802
movl %eax, %ebx
testl %eax, %eax
jne 0x30943
movq -0x58(%rbp), %rdi
movl $0x1, (%rsp)
movq -0x38(%rbp), %rsi
movl %r15d, %edx
movq -0x48(%rbp), %rcx
movq %r12, %r8
movl -0x30(%rbp), %r9d
callq 0x307cd
movl %eax, %ebx
jmp 0x30943
movq %r12, %rdi
movq %r14, %rsi
callq 0x31189
testq %rax, %rax
je 0x30928
movq %rax, %r14
movzwl -0x2a(%rbp), %eax
movw %ax, 0x28(%r14)
movq -0x40(%rbp), %r15
movl %r15d, 0x4(%r14)
movq %rbx, %r12
movq %rbx, 0x8(%r14)
movl -0x30(%rbp), %eax
movl %eax, (%r14)
cmpl $0x3ffff, %r15d         # imm = 0x3FFFF
movq -0x48(%rbp), %rbx
ja 0x308ed
movq %r14, %rdi
addq $0x40, %rdi
movq -0x38(%rbp), %rsi
movl %r15d, %edx
callq 0x2e250
movq %r14, %rdi
callq 0x311e2
testl %eax, %eax
jne 0x3093c
movq %r14, %rdi
testl %r13d, %r13d
je 0x30954
movq -0x38(%rbp), %rsi
movl %r15d, %edx
movq %rbx, %rcx
movq %r12, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x31360
testl %eax, %eax
je 0x30966
movl %eax, %ebx
movq %r14, %rdi
callq 0x31674
jmp 0x30943
movq (%r12), %rax
movq (%rax), %rdi
leaq 0x32f7f(%rip), %rsi     # 0x638b5
callq *0x80(%rax)
pushq $-0x1
jmp 0x30942
pushq $-0x49
popq %rbx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %rsi
movl %r15d, %edx
movq %rbx, %rcx
movq %r12, %r8
callq 0x31712
movq %r14, %rdi
callq 0x31771
xorl %ebx, %ebx
jmp 0x30943