// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
pushq $-0x18
popq %r13
testq %rdi, %rdi
je 0x2ab68
movq %rdi, %rbx
cmpl $0xdb7c2712, 0x120(%rdi) # imm = 0xDB7C2712
jne 0x2ab68
movq %rcx, %r15
movl %edx, %r14d
movq %rsi, %r12
movq 0xf8(%rbx), %rdi
testq %rdi, %rdi
je 0x2aa73
movq %r8, %r13
movq 0x5cd2b(%rip), %rax     # 0x87798
callq *0x20(%rax)
movq %r13, %r8
cmpl $0x2, 0x5cd2e(%rip)     # 0x877a8
jb 0x2aa8c
cmpl $0xdb7c2712, 0x120(%rbx) # imm = 0xDB7C2712
jne 0x2ab64
movq %r8, -0x30(%rbp)
movq 0xd8(%rbx), %rax
movq 0xe8(%rbx), %rdx
movq 0x10(%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %r13
testl %r14d, %r14d
jns 0x2aabf
movq %rdx, %r14
movq %r12, %rdi
callq 0x28e24
movq %r14, %rdx
movl %eax, %r14d
testl %r14d, %r14d
je 0x2ab39
pushq $0x1
popq %rcx
movq %rdx, %rdi
movq %rdx, -0x38(%rbp)
movq %r12, %rsi
movl %r14d, %edx
callq *0x50(%r13)
movq %r13, %rcx
movl %eax, %r13d
testl %eax, %eax
jne 0x2ab4c
movq -0x38(%rbp), %rdi
testq %r15, %r15
je 0x2ab7a
movq -0x30(%rbp), %r12
movl (%r12), %eax
leaq -0x58(%rbp), %r14
movq %r15, 0x8(%r14)
movl %eax, 0x14(%r14)
andl $0x0, 0x10(%r14)
andq $0x0, (%r14)
movl $0x3, 0x18(%r14)
leaq 0x6e(%rip), %rsi        # 0x2ab89
movq %r14, %rdx
callq *0xa0(%rcx)
movl %eax, %r13d
movl 0x10(%r14), %eax
movq %rax, (%r12)
movq %r14, %rdi
callq 0x2a72f
jmp 0x2ab4c
leaq 0x38bfe(%rip), %rsi     # 0x6373e
movq %rbx, %rdi
callq 0x2a542
pushq $-0x3
popq %r13
movq 0xf8(%rbx), %rdi
testq %rdi, %rdi
je 0x2ab68
movq 0x5cc39(%rip), %rax     # 0x87798
callq *0x30(%rax)
jmp 0x2ab68
pushq $-0xa
popq %r13
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x30(%rbp), %rsi
callq *0x98(%rcx)
movl %eax, %r13d
jmp 0x2ab4c