// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqlite_kv_store
int unqlite_kv_store(unqlite *pDb,const void *pKey,int nKeyLen,const void *pData,unqlite_int64 nDataLen)
{
	unqlite_kv_engine *pEngine;
	int rc;
	if( UNQLITE_DB_MISUSE(pDb) ){
		return UNQLITE_CORRUPT;
	}
#if defined(UNQLITE_ENABLE_THREADS)
	 /* Acquire DB mutex */
	 SyMutexEnter(sUnqlMPGlobal.pMutexMethods, pDb->pMutex); /* NO-OP if sUnqlMPGlobal.nThreadingLevel != UNQLITE_THREAD_LEVEL_MULTI */
	 if( sUnqlMPGlobal.nThreadingLevel > UNQLITE_THREAD_LEVEL_SINGLE && 
		 UNQLITE_THRD_DB_RELEASE(pDb) ){
			 return UNQLITE_ABORT; /* Another thread have released this instance */
	 }
#endif
	 /* Point to the underlying storage engine */
	 pEngine = unqlitePagerGetKvEngine(pDb);
	 if( pEngine->pIo->pMethods->xReplace == 0 ){
		 /* Storage engine does not implement such method */
		 unqliteGenError(pDb,"xReplace() method not implemented in the underlying storage engine");
		 rc = UNQLITE_NOTIMPLEMENTED;
	 }else{
		 if( nKeyLen < 0 ){
			 /* Assume a null terminated string and compute it's length */
			 nKeyLen = SyStrlen((const char *)pKey);
		 }
		 if( !nKeyLen ){
			 unqliteGenError(pDb,"Empty key");
			 rc = UNQLITE_EMPTY;
		 }else{
			 /* Perform the requested operation */
			 rc = pEngine->pIo->pMethods->xReplace(pEngine,pKey,nKeyLen,pData,nDataLen);
		 }
	 }
#if defined(UNQLITE_ENABLE_THREADS)
	 /* Leave DB mutex */
	 SyMutexLeave(sUnqlMPGlobal.pMutexMethods,pDb->pMutex); /* NO-OP if sUnqlMPGlobal.nThreadingLevel != UNQLITE_THREAD_LEVEL_MULTI */
#endif
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0xffffffe8, %r14d      # imm = 0xFFFFFFE8
testq %rdi, %rdi
je 0x31ae3
movq %rdi, %rbx
cmpl $0xdb7c2712, 0x120(%rdi) # imm = 0xDB7C2712
jne 0x31ae3
movq %rcx, %r15
movl %edx, %r13d
movq %rsi, %r12
movq 0xf8(%rbx), %rdi
testq %rdi, %rdi
je 0x31a07
movq 0x64d7a(%rip), %rax     # 0x96778
movq %r8, %r14
callq *0x20(%rax)
movq %r14, %r8
cmpl $0x2, 0x64d7a(%rip)     # 0x96788
jb 0x31a26
movl $0xfffffff6, %r14d      # imm = 0xFFFFFFF6
cmpl $0xdb7c2712, 0x120(%rbx) # imm = 0xDB7C2712
jne 0x31ae3
movq 0xd8(%rbx), %rax
movq 0x10(%rax), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
movq 0x38(%rax), %rax
testq %rax, %rax
je 0x31a81
testl %r13d, %r13d
jns 0x31aa3
cmpb $0x0, (%r12)
movq %r12, %r13
je 0x31aa0
leaq 0x2(%r12), %r13
cmpb $0x0, -0x1(%r13)
je 0x31a98
cmpb $0x0, (%r13)
je 0x31aa0
cmpb $0x0, 0x1(%r13)
je 0x31a9d
leaq 0x4(%r13), %rcx
cmpb $0x0, 0x2(%r13)
movq %rcx, %r13
jne 0x31a55
addq $-0x2, %rcx
movq %rcx, %r13
jmp 0x31aa0
leaq 0x43c8b(%rip), %rsi     # 0x75713
movq %rbx, %rdi
callq 0x31af5
movl $0xffffffef, %r14d      # imm = 0xFFFFFFEF
jmp 0x31acd
decq %r13
jmp 0x31aa0
incq %r13
subl %r12d, %r13d
testl %r13d, %r13d
je 0x31ab8
movq %r12, %rsi
movl %r13d, %edx
movq %r15, %rcx
callq *%rax
movl %eax, %r14d
jmp 0x31acd
leaq 0x43c97(%rip), %rsi     # 0x75756
movq %rbx, %rdi
callq 0x31af5
movl $0xfffffffd, %r14d      # imm = 0xFFFFFFFD
movq 0xf8(%rbx), %rdi
testq %rdi, %rdi
je 0x31ae3
movq 0x64c98(%rip), %rax     # 0x96778
callq *0x30(%rax)
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq