// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r13
movq %rdi, %r15
movq 0x8(%rdi), %rbx
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x32274
movq (%rax), %rax
cmpq %r13, 0x8(%rax)
je 0x32421
movq %r15, %rdi
callq 0x327b7
movl 0x8(%r13), %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2ca19
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x323de
movq %rbx, %rdi
movl $0x88, %esi
callq 0x2ca19
testq %rax, %rax
je 0x323d2
movq %rax, %r12
pushq $0x58
popq %rsi
movq %rax, %rdi
callq 0x27aea
movq -0x30(%rbp), %rdi
movl %r14d, %esi
movq %rdi, %r14
callq 0x27aea
movq %r15, (%r12)
movq %r13, 0x8(%r12)
leaq 0x5fb(%rip), %rax       # 0x328ce
movq %rax, 0x10(%r12)
leaq 0x5fb(%rip), %rax       # 0x328da
movq %rax, 0x18(%r12)
leaq 0x5fe(%rip), %rax       # 0x328e9
movq %rax, 0x20(%r12)
leaq 0x62a(%rip), %rax       # 0x32921
movq %rax, 0x28(%r12)
leaq 0xadc(%rip), %rax       # 0x32ddf
movq %rax, 0x30(%r12)
leaq 0xae8(%rip), %rax       # 0x32df7
movq %rax, 0x38(%r12)
leaq 0xb31(%rip), %rax       # 0x32e4c
movq %rax, 0x40(%r12)
leaq 0xb36(%rip), %rax       # 0x32e5d
movq %rax, 0x48(%r12)
leaq 0xb3a(%rip), %rax       # 0x32e6d
movq %rax, 0x50(%r12)
leaq 0xbc2(%rip), %rax       # 0x32f01
movq %rax, 0x58(%r12)
leaq 0xbc2(%rip), %rax       # 0x32f0d
movq %rax, 0x60(%r12)
leaq 0xbc2(%rip), %rax       # 0x32f19
movq %rax, 0x68(%r12)
leaq 0xbc3(%rip), %rax       # 0x32f26
movq %rax, 0x70(%r12)
leaq 0xbc4(%rip), %rax       # 0x32f33
movq %rax, 0x78(%r12)
leaq 0xbc5(%rip), %rax       # 0x32f40
movq %rax, 0x80(%r12)
movq %r12, (%r14)
movq 0x18(%r13), %rax
testq %rax, %rax
je 0x323ef
movl 0x55443(%rip), %ecx     # 0x877d8
leal -0x10001(%rcx), %edx
cmpl $0xffff01ff, %edx       # imm = 0xFFFF01FF
movl $0x1000, %esi           # imm = 0x1000
cmovael %ecx, %esi
movq %r14, %rdi
callq *%rax
testl %eax, %eax
je 0x323ec
movl %eax, %r13d
addq $0x1e0, %r15            # imm = 0x1E0
leaq 0x315bc(%rip), %rsi     # 0x6397f
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x32836
jmp 0x32409
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x2d420
movq %rbx, %rdi
callq 0x32825
pushq $-0x1
popq %r13
jmp 0x32424
movq %r12, (%r14)
movq %r14, 0x10(%r15)
leaq 0xe8(%rbx), %rsi
movq %rbx, %rdi
callq 0x2af93
movl %eax, %r13d
testl %eax, %eax
je 0x32421
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2d420
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2d420
jmp 0x32424
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq