// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqlitePagerRegisterKvEngine
UNQLITE_PRIVATE int unqlitePagerRegisterKvEngine(Pager *pPager,unqlite_kv_methods *pMethods)
{
	unqlite_db *pStorage = &pPager->pDb->sDB;
	unqlite *pDb = pPager->pDb;
	unqlite_kv_engine *pEngine;
	unqlite_kv_io *pIo;
	sxu32 nByte;
	int rc;
	if( pPager->pEngine ){
		if( pMethods == pPager->pEngine->pIo->pMethods ){
			/* Ticket 1432: Same implementation */
			return UNQLITE_OK;
		}
		/* Release the old KV engine */
		pager_release_kv_engine(pPager);
	}
	/* Allocate a new KV engine instance */
	nByte = (sxu32)pMethods->szKv;
	pEngine = (unqlite_kv_engine *)SyMemBackendAlloc(&pDb->sMem,nByte);
	if( pEngine == 0 ){
		unqliteGenOutofMem(pDb);
		return UNQLITE_NOMEM;
	}
	pIo = (unqlite_kv_io *)SyMemBackendAlloc(&pDb->sMem,sizeof(unqlite_kv_io));
	if( pIo == 0 ){
		SyMemBackendFree(&pDb->sMem,pEngine);
		unqliteGenOutofMem(pDb);
		return UNQLITE_NOMEM;
	}
	/* Zero the structure */
	SyZero(pIo,sizeof(unqlite_io_methods));
	SyZero(pEngine,nByte);
	/* Populate the IO structure */
	pager_kv_io_init(pPager,pMethods,pIo);
	pEngine->pIo = pIo;
	/* Invoke the init callback if avaialble */
	if( pMethods->xInit ){
		rc = pMethods->xInit(pEngine,unqliteGetPageSize());
		if( rc != UNQLITE_OK ){
			unqliteGenErrorFormat(pDb,
				"xInit() method of the underlying KV engine '%z' failed",&pPager->sKv);
			goto fail;
		}
		pEngine->pIo = pIo;
	}
	pPager->pEngine = pEngine;
	/* Allocate a new cursor */
	rc = unqliteInitCursor(pDb,&pStorage->pCursor);
	if( rc != UNQLITE_OK ){
		goto fail;
	}
	return UNQLITE_OK;
fail:
	SyMemBackendFree(&pDb->sMem,pEngine);
	SyMemBackendFree(&pDb->sMem,pIo);
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
addq $0xd8, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x676c3
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx), %rax
jne 0x676ba
movl $0x0, -0x4(%rbp)
jmp 0x6781e
movq -0x10(%rbp), %rdi
callq 0x67ed0
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x5bf70
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x676f9
movq -0x28(%rbp), %rdi
callq 0x67f90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6781e
movq -0x28(%rbp), %rdi
movl $0x88, %esi
callq 0x5bf70
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x67734
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x5d6b0
movq -0x28(%rbp), %rdi
callq 0x67f90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6781e
movq -0x38(%rbp), %rdi
movl $0x58, %esi
callq 0x54280
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x54280
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x67fc0
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x677cd
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
callq 0x680d0
movq -0x50(%rbp), %rdi
movl %eax, %esi
movq -0x48(%rbp), %rax
callq *%rax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x677c2
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x1e0, %rdx            # imm = 0x1E0
leaq 0x5a6b7(%rip), %rsi     # 0xc1e70
movb $0x0, %al
callq 0x68100
jmp 0x677fe
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x10, %rsi
callq 0x59720
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x677f5
jmp 0x677fe
movl $0x0, -0x4(%rbp)
jmp 0x6781e
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x5d6b0
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x5d6b0
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)