// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqlite_kv_delete
int unqlite_kv_delete(unqlite *pDb,const void *pKey,int nKeyLen)
{
	unqlite_kv_methods *pMethods;
	unqlite_kv_engine *pEngine;
	unqlite_kv_cursor *pCur;
	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);
	 pMethods = pEngine->pIo->pMethods;
	 pCur = pDb->sDB.pCursor;
	 if( pMethods->xDelete == 0 ){
		 /* Storage engine does not implement such method */
		 unqliteGenError(pDb,"xDelete() 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{
			 /* Seek to the record position */
			 rc = pMethods->xSeek(pCur,pKey,nKeyLen,UNQLITE_CURSOR_MATCH_EXACT);
		 }
		 if( rc == UNQLITE_OK ){
			 /* Exact match found, delete the entry */
			 rc = pMethods->xDelete(pCur);
		 }
	 }
#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, %r12d      # imm = 0xFFFFFFE8
testq %rdi, %rdi
je 0x31fde
movq %rdi, %rbx
cmpl $0xdb7c2712, 0x120(%rdi) # imm = 0xDB7C2712
jne 0x31fde
movl %edx, %r15d
movq %rsi, %r14
movq 0xf8(%rbx), %rdi
testq %rdi, %rdi
je 0x31ee3
movq 0x62898(%rip), %rax     # 0x94778
callq *0x20(%rax)
cmpl $0x2, 0x6289e(%rip)     # 0x94788
jb 0x31f02
movl $0xfffffff6, %r12d      # imm = 0xFFFFFFF6
cmpl $0xdb7c2712, 0x120(%rbx) # imm = 0xDB7C2712
jne 0x31fde
movq 0xd8(%rbx), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %r13
cmpq $0x0, 0x80(%r13)
je 0x31f5b
testl %r15d, %r15d
jns 0x31f7d
cmpb $0x0, (%r14)
movq %r14, %r15
je 0x31f7a
leaq 0x2(%r14), %r15
cmpb $0x0, -0x1(%r15)
je 0x31f72
cmpb $0x0, (%r15)
je 0x31f7a
cmpb $0x0, 0x1(%r15)
je 0x31f77
leaq 0x4(%r15), %rax
cmpb $0x0, 0x2(%r15)
movq %rax, %r15
jne 0x31f30
addq $-0x2, %rax
movq %rax, %r15
jmp 0x31f7a
leaq 0x41848(%rip), %rsi     # 0x737aa
movq %rbx, %rdi
callq 0x31537
movl $0xffffffef, %r12d      # imm = 0xFFFFFFEF
jmp 0x31fc8
decq %r15
jmp 0x31f7a
incq %r15
subl %r14d, %r15d
testl %r15d, %r15d
je 0x31fb3
movq 0xe8(%rbx), %rdi
movq %rdi, -0x30(%rbp)
movq %r14, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq *0x50(%r13)
movl %eax, %r12d
testl %eax, %eax
jne 0x31fc8
movq -0x30(%rbp), %rdi
callq *0x80(%r13)
movl %eax, %r12d
jmp 0x31fc8
leaq 0x417a4(%rip), %rsi     # 0x7375e
movq %rbx, %rdi
callq 0x31537
movl $0xfffffffd, %r12d      # imm = 0xFFFFFFFD
movq 0xf8(%rbx), %rdi
testq %rdi, %rdi
je 0x31fde
movq 0x6279d(%rip), %rax     # 0x94778
callq *0x30(%rax)
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq