// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: MemHashReplace
static int MemHashReplace(
	  unqlite_kv_engine *pKv,
	  const void *pKey,int nKeyLen,
	  const void *pData,unqlite_int64 nDataLen
	  )
{
	mem_hash_kv_engine *pEngine = (mem_hash_kv_engine *)pKv;
	mem_hash_record *pRecord;
	if( nDataLen > SXU32_HIGH ){
		/* Database limit */
		pEngine->pIo->xErr(pEngine->pIo->pHandle,"Record size limit reached");
		return UNQLITE_LIMIT;
	}
	/* Fetch the record first */
	pRecord = MemHashGetEntry(pEngine,pKey,nKeyLen);
	if( pRecord == 0 ){
		/* Allocate a new record */
		pRecord = MemHashNewRecord(pEngine,
			pKey,nKeyLen,
			pData,nDataLen,
			pEngine->xHash(pKey,nKeyLen)
			);
		if( pRecord == 0 ){
			return UNQLITE_NOMEM;
		}
		/* Link the entry */
		MemHashLinkRecord(pEngine,pRecord);
		if( (pEngine->nRecord >= pEngine->nBucket * MEM_HASH_FILL_FACTOR) && pEngine->nRecord < 100000 ){
			/* Rehash the table */
			MemHashGrowTable(pEngine);
		}
	}else{
		sxu32 nData = (sxu32)nDataLen;
		void *pNew;
		/* Replace an existing record */
		if( nData == pRecord->nDataLen ){
			/* No need to free the old chunk */
			pNew = (void *)pRecord->pData;
		}else{
			pNew = SyMemBackendAlloc(&pEngine->sAlloc,nData);
			if( pNew == 0 ){
				return UNQLITE_NOMEM;
			}
			/* Release the old data */
			SyMemBackendFree(&pEngine->sAlloc,(void *)pRecord->pData);
		}
		/* Reflect the change */
		pRecord->nDataLen = nData;
		SyMemcpy(pData,pNew,nData);
		pRecord->pData = pNew;
	}
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x30(%rbp)
jle 0x5faae
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x80(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
leaq 0x6229c(%rip), %rsi     # 0xc1d3c
callq *%rax
movl $0xfffffff9, -0x4(%rbp) # imm = 0xFFFFFFF9
jmp 0x5fc06
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x60450
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x5fb7f
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq 0xc0(%rax), %rax
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq *%rax
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl -0x64(%rbp), %edx
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %r8
movl %eax, %r9d
callq 0x60520
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x5fb39
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5fc06
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x60650
movq -0x38(%rbp), %rax
movl 0xd0(%rax), %eax
movq -0x38(%rbp), %rcx
movl 0xd4(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jb 0x5fb7a
movq -0x38(%rbp), %rax
cmpl $0x186a0, 0xd0(%rax)    # imm = 0x186A0
jae 0x5fb7a
movq -0x38(%rbp), %rdi
callq 0x60770
jmp 0x5fbff
movq -0x30(%rbp), %rax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jne 0x5fba0
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x5fbd9
movq -0x38(%rbp), %rdi
addq $0x8, %rdi
movl -0x44(%rbp), %esi
callq 0x5bf70
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x5fbc4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5fc06
movq -0x38(%rbp), %rdi
addq $0x8, %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x5d6b0
movl -0x44(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x28(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0x44(%rbp), %edx
callq 0x5d570
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)