// File: /workspace/github_c_makefile_star2_O1/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 0x36617
movq (%rbx), %rax
movq (%rax), %rdi
leaq 0x3f25c(%rip), %rsi     # 0x75863
callq *0x80(%rax)
movl $0xfffffff9, %eax       # imm = 0xFFFFFFF9
jmp 0x3670f
movq %r8, %r14
movl %edx, %r13d
movq %rsi, %r15
movq %rcx, -0x30(%rbp)
movq %rbx, %rdi
callq 0x36a20
testq %rax, %rax
je 0x36667
movq %rax, %r12
movl 0x28(%rax), %r13d
addq %r14, %r13
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, %r13
jl 0x366bd
movq (%rbx), %rax
movq (%rax), %rdi
leaq 0x3f226(%rip), %rsi     # 0x7587d
callq *0x80(%rax)
movl $0xfffffff9, %eax       # imm = 0xFFFFFFF9
jmp 0x36707
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 0x36aa0
testq %rax, %rax
je 0x366fb
movq %rbx, %rdi
movq %rax, %rsi
callq 0x36b7c
movl 0xd0(%rbx), %eax
cmpl $0x1869f, %eax          # imm = 0x1869F
ja 0x3670d
shll $0x2, %eax
cmpl 0xd4(%rbx), %eax
jb 0x3670d
movq %rbx, %rdi
callq 0x36be6
jmp 0x3670d
movq 0x20(%r12), %rsi
addq $0x8, %rbx
movq %rbx, %rdi
movl %r13d, %edx
callq 0x33b0f
testq %rax, %rax
je 0x36702
movq %rax, %rbx
movl 0x28(%r12), %esi
addq %rax, %rsi
movq -0x30(%rbp), %rdi
movl %r14d, %edx
callq 0x34fc5
movq %rbx, 0x20(%r12)
movl %r13d, 0x28(%r12)
movb $0x1, %cl
jmp 0x36709
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3670f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
testb %cl, %cl
je 0x3670f
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq