// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqlite_kv_fetch
int unqlite_kv_fetch(unqlite *pDb,const void *pKey,int nKeyLen,void *pBuf,unqlite_int64 *pBufLen)
{
	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( 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 ){
		 if( pBuf == 0 ){
			 /* Data length only */
			 rc = pMethods->xDataLength(pCur,pBufLen);
		 }else{
			 SyBlob sBlob;
			 /* Initialize the data consumer */
			 SyBlobInitFromBuf(&sBlob,pBuf,(sxu32)*pBufLen);
			 /* Consume the data */
			 rc = pMethods->xData(pCur,unqliteDataConsumer,&sBlob);
			 /* Data length */
			 *pBufLen = (unqlite_int64)SyBlobLength(&sBlob);
			 /* Cleanup */
			 SyBlobRelease(&sBlob);
		 }
	 }
#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
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x58fe2
movq -0x10(%rbp), %rax
cmpl $0xdb7c2712, 0x120(%rax) # imm = 0xDB7C2712
je 0x58fee
movl $0xffffffe8, -0x4(%rbp) # imm = 0xFFFFFFE8
jmp 0x59151
movq -0x10(%rbp), %rax
cmpq $0x0, 0xf8(%rax)
je 0x59014
movq 0x95875(%rip), %rax     # 0xee878
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0xf8(%rcx), %rdi
callq *%rax
cmpl $0x1, 0x9586d(%rip)     # 0xee888
jbe 0x59039
movq -0x10(%rbp), %rax
cmpl $0xdb7c2712, 0x120(%rax) # imm = 0xDB7C2712
je 0x59039
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x59151
movq -0x10(%rbp), %rdi
callq 0x58930
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x59076
movq -0x18(%rbp), %rdi
callq 0x55d10
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x59095
movq -0x10(%rbp), %rdi
leaq 0x68b97(%rip), %rsi     # 0xc1c1e
callq 0x58950
movl $0xfffffffd, -0x4c(%rbp) # imm = 0xFFFFFFFD
jmp 0x590b2
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl $0x1, %ecx
callq *%rax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x59125
cmpq $0x0, -0x28(%rbp)
jne 0x590d9
movq -0x38(%rbp), %rax
movq 0x98(%rax), %rax
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq *%rax
movl %eax, -0x4c(%rbp)
jmp 0x59123
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
leaq -0x70(%rbp), %rdi
callq 0x59160
movq -0x38(%rbp), %rax
movq 0xa0(%rax), %rax
movq -0x48(%rbp), %rdi
leaq 0xab(%rip), %rsi        # 0x591b0
leaq -0x70(%rbp), %rdx
callq *%rax
movl %eax, -0x4c(%rbp)
movl -0x60(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
leaq -0x70(%rbp), %rdi
callq 0x58c00
jmp 0x59125
movq -0x10(%rbp), %rax
cmpq $0x0, 0xf8(%rax)
je 0x5914b
movq 0x9573e(%rip), %rax     # 0xee878
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0xf8(%rcx), %rdi
callq *%rax
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)