// File: /workspace/github_c_makefile_star2_O3/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 0x31525
movq %rdi, %rbx
cmpl $0xdb7c2712, 0x120(%rdi) # imm = 0xDB7C2712
jne 0x31525
movq %rcx, %r15
movl %edx, %r13d
movq %rsi, %r12
movq 0xf8(%rbx), %rdi
testq %rdi, %rdi
je 0x31449
movq 0x63338(%rip), %rax     # 0x94778
movq %r8, %r14
callq *0x20(%rax)
movq %r14, %r8
cmpl $0x2, 0x63338(%rip)     # 0x94788
jb 0x31468
movl $0xfffffff6, %r14d      # imm = 0xFFFFFFF6
cmpl $0xdb7c2712, 0x120(%rbx) # imm = 0xDB7C2712
jne 0x31525
movq 0xd8(%rbx), %rax
movq 0x10(%rax), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
movq 0x38(%rax), %rax
testq %rax, %rax
je 0x314c3
testl %r13d, %r13d
jns 0x314e5
cmpb $0x0, (%r12)
movq %r12, %r13
je 0x314e2
leaq 0x2(%r12), %r13
cmpb $0x0, -0x1(%r13)
je 0x314da
cmpb $0x0, (%r13)
je 0x314e2
cmpb $0x0, 0x1(%r13)
je 0x314df
leaq 0x4(%r13), %rcx
cmpb $0x0, 0x2(%r13)
movq %rcx, %r13
jne 0x31497
addq $-0x2, %rcx
movq %rcx, %r13
jmp 0x314e2
leaq 0x42251(%rip), %rsi     # 0x7371b
movq %rbx, %rdi
callq 0x31537
movl $0xffffffef, %r14d      # imm = 0xFFFFFFEF
jmp 0x3150f
decq %r13
jmp 0x314e2
incq %r13
subl %r12d, %r13d
testl %r13d, %r13d
je 0x314fa
movq %r12, %rsi
movl %r13d, %edx
movq %r15, %rcx
callq *%rax
movl %eax, %r14d
jmp 0x3150f
leaq 0x4225d(%rip), %rsi     # 0x7375e
movq %rbx, %rdi
callq 0x31537
movl $0xfffffffd, %r14d      # imm = 0xFFFFFFFD
movq 0xf8(%rbx), %rdi
testq %rdi, %rdi
je 0x31525
movq 0x63256(%rip), %rax     # 0x94778
callq *0x30(%rax)
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq