// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, %r8
jl 0x35f07
movq (%rbx), %rax
movq (%rax), %rdi
leaq 0x3d966(%rip), %rsi     # 0x7386b
jmp 0x35f4b
movq %r8, %r14
movl %edx, %r13d
movq %rsi, %r15
movq %rcx, -0x30(%rbp)
movq %rbx, %rdi
callq 0x36309
testq %rax, %rax
je 0x35f69
movq %rax, %r12
movl 0x28(%rax), %r13d
addq %r14, %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, %r13
jl 0x35fc2
movq (%rbx), %rax
movq (%rax), %rdi
leaq 0x3d93a(%rip), %rsi     # 0x73885
callq *0x80(%rax)
movl $0xfffffff9, %r14d      # imm = 0xFFFFFFF9
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movl %r13d, %esi
callq *0xc0(%rbx)
movq %rbx, %rdi
movq %r15, %rsi
movl %r13d, %edx
movq -0x30(%rbp), %rcx
movq %r14, %r8
movl %eax, %r9d
callq 0x36389
testq %rax, %rax
je 0x36004
movq %rbx, %rdi
movq %rax, %rsi
callq 0x36465
movl 0xd0(%rbx), %eax
xorl %r14d, %r14d
cmpl $0x1869f, %eax          # imm = 0x1869F
ja 0x35f57
shll $0x2, %eax
cmpl 0xd4(%rbx), %eax
jb 0x35f57
movq %rbx, %rdi
callq 0x364cb
jmp 0x35f57
movq 0x20(%r12), %rsi
addq $0x8, %rbx
movq %rbx, %rdi
movl %r13d, %edx
callq 0x334b2
testq %rax, %rax
je 0x36004
movq %rax, %rbx
movl 0x28(%r12), %esi
addq %rax, %rsi
movq -0x30(%rbp), %rdi
movl %r14d, %edx
callq 0x34893
movq %rbx, 0x20(%r12)
movl %r13d, 0x28(%r12)
xorl %r14d, %r14d
jmp 0x35f57
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x35f57