// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: MemHashAppend
static int MemHashAppend(
	  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 * MEM_HASH_FILL_FACTOR >= pEngine->nBucket && pEngine->nRecord < 100000 ){
			/* Rehash the table */
			MemHashGrowTable(pEngine);
		}
	}else{
		unqlite_int64 nNew = pRecord->nDataLen + nDataLen;
		void *pOld = (void *)pRecord->pData;
		sxu32 nData;
		char *zNew;
		/* Append data to the existing record */
		if( nNew > SXU32_HIGH ){
			/* Overflow */
			pEngine->pIo->xErr(pEngine->pIo->pHandle,"Append operation will cause data overflow");	
			return UNQLITE_LIMIT;
		}
		nData = (sxu32)nNew;
		/* Allocate bigger chunk */
		zNew = (char *)SyMemBackendRealloc(&pEngine->sAlloc,pOld,nData);
		if( zNew == 0 ){
			return UNQLITE_NOMEM;
		}
		/* Reflect the change */
		SyMemcpy(pData,&zNew[pRecord->nDataLen],(sxu32)nDataLen);
		pRecord->pData = (const void *)zNew;
		pRecord->nDataLen = nData;
	}
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %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 0x5fc7e
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x80(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
leaq 0x620cc(%rip), %rsi     # 0xc1d3c
callq *%rax
movl $0xfffffff9, -0x4(%rbp) # imm = 0xFFFFFFF9
jmp 0x5fe0c
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x60450
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x5fd53
movq -0x38(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movq 0xc0(%rax), %rax
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq *%rax
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
movl -0x74(%rbp), %edx
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %r8
movl %eax, %r9d
callq 0x60520
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x5fd0f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5fe0c
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x60650
movq -0x38(%rbp), %rax
movl 0xd0(%rax), %eax
shll $0x2, %eax
movq -0x38(%rbp), %rcx
cmpl 0xd4(%rcx), %eax
jb 0x5fd4e
movq -0x38(%rbp), %rax
cmpl $0x186a0, 0xd0(%rax)    # imm = 0x186A0
jae 0x5fd4e
movq -0x38(%rbp), %rdi
callq 0x60770
jmp 0x5fe05
movq -0x40(%rbp), %rax
movl 0x28(%rax), %eax
addq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x50(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x48(%rbp)
jle 0x5fda3
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x80(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
leaq 0x61fbe(%rip), %rsi     # 0xc1d56
callq *%rax
movl $0xfffffff9, -0x4(%rbp) # imm = 0xFFFFFFF9
jmp 0x5fe0c
movq -0x48(%rbp), %rax
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rdi
addq $0x8, %rdi
movq -0x50(%rbp), %rsi
movl -0x54(%rbp), %edx
callq 0x5abc0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x5fdd2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5fe0c
movq -0x28(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x40(%rbp), %rax
movl 0x28(%rax), %eax
addq %rax, %rsi
movq -0x30(%rbp), %rax
movl %eax, %edx
callq 0x5d570
movq -0x60(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x54(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x28(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)