// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rdi
callq *%rax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x6293d
movl -0x58(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62acf
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %eax
addl $0x1a, %eax
movl %eax, %eax
movl %eax, %esi
addq -0x30(%rbp), %rsi
leaq -0x52(%rbp), %rdx
callq 0x63d40
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x629bf
movq -0x10(%rbp), %rdi
movl $0x1a, %esi
leaq -0x52(%rbp), %rdx
callq 0x63d40
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x629b8
cmpl $0x0, 0x10(%rbp)
jne 0x6298e
movl $0xffffffb7, -0x4(%rbp) # imm = 0xFFFFFFB7
jmp 0x62acf
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movl -0x34(%rbp), %r9d
callq 0x64000
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62acf
movl $0x1, -0x44(%rbp)
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x64080
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x62a04
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq 0x80(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
leaq 0x5f3b0(%rip), %rsi     # 0xc1da6
callq *%rax
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x62acf
movw -0x52(%rbp), %cx
movq -0x50(%rbp), %rax
movw %cx, 0x28(%rax)
movl -0x1c(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x34(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x40000, -0x1c(%rbp)   # imm = 0x40000
jae 0x62a4c
movq -0x50(%rbp), %rdi
addq $0x40, %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x5d9d0
movq -0x50(%rbp), %rdi
callq 0x64100
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x62a66
movl -0x58(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62acf
cmpl $0x0, -0x44(%rbp)
je 0x62aa7
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
movb $0x0, %al
callq 0x643c0
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
je 0x62aa5
movq -0x50(%rbp), %rdi
callq 0x64990
movl -0x58(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62acf
jmp 0x62abf
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x64ad0
movq -0x50(%rbp), %rdi
callq 0x64b70
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)