// File: /workspace/github_c_makefile_star2_O1/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 0x3a628
movq (%rax), %rax
cmpq %r13, 0x8(%rax)
je 0x3a822
movq %r15, %rdi
callq 0x3abb8
movl 0x8(%r13), %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x343ed
testq %rax, %rax
je 0x3a7d0
movq %rax, -0x30(%rbp)
movq %rbx, %rdi
movl $0x88, %esi
callq 0x343ed
testq %rax, %rax
je 0x3a7c4
movq %rax, %r12
movq $-0x4, %rax
movl $0x0, 0x4(%r12,%rax)
addq $0x4, %rax
cmpq $0x54, %rax
jb 0x3a664
testq %r14, %r14
movq -0x30(%rbp), %rdi
je 0x3a6b5
movq %rdi, %rax
addq %r14, %rax
movq %rdi, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3a6b5
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3a6b5
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x3a6b5
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x3a689
movq %r15, (%r12)
movq %r13, 0x8(%r12)
leaq 0x647(%rip), %rax       # 0x3ad0c
movq %rax, 0x10(%r12)
leaq 0x647(%rip), %rax       # 0x3ad18
movq %rax, 0x18(%r12)
leaq 0x64a(%rip), %rax       # 0x3ad27
movq %rax, 0x20(%r12)
leaq 0x676(%rip), %rax       # 0x3ad5f
movq %rax, 0x28(%r12)
leaq 0xbb5(%rip), %rax       # 0x3b2aa
movq %rax, 0x30(%r12)
leaq 0xbc1(%rip), %rax       # 0x3b2c2
movq %rax, 0x38(%r12)
leaq 0xc0a(%rip), %rax       # 0x3b317
movq %rax, 0x40(%r12)
leaq 0xc0f(%rip), %rax       # 0x3b328
movq %rax, 0x48(%r12)
leaq 0xc13(%rip), %rax       # 0x3b338
movq %rax, 0x50(%r12)
leaq 0xc9e(%rip), %rax       # 0x3b3cf
movq %rax, 0x58(%r12)
leaq 0xc9e(%rip), %rax       # 0x3b3db
movq %rax, 0x60(%r12)
leaq 0xc9e(%rip), %rax       # 0x3b3e7
movq %rax, 0x68(%r12)
leaq 0xc9f(%rip), %rax       # 0x3b3f4
movq %rax, 0x70(%r12)
leaq 0xca0(%rip), %rax       # 0x3b401
movq %rax, 0x78(%r12)
leaq 0xca1(%rip), %rax       # 0x3b40e
movq %rax, 0x80(%r12)
movq %r12, (%rdi)
movq 0x18(%r13), %rax
testq %rax, %rax
je 0x3a7ed
movl 0x5c031(%rip), %ecx     # 0x967b8
leal -0x10001(%rcx), %edx
cmpl $0xffff01ff, %edx       # imm = 0xFFFF01FF
movl $0x1000, %esi           # imm = 0x1000
cmovael %ecx, %esi
movq %rdi, %r14
callq *%rax
testl %eax, %eax
je 0x3a7e7
movl %eax, %r13d
addq $0x1e0, %r15            # imm = 0x1E0
leaq 0x3b1e2(%rip), %rsi     # 0x75997
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3ac51
jmp 0x3a80a
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x3503f
leaq 0x3b1f7(%rip), %rsi     # 0x759ce
movq %rbx, %rdi
callq 0x31af5
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x3a825
movq %r12, (%r14)
movq %r14, %rdi
movq %rdi, 0x10(%r15)
leaq 0xe8(%rbx), %rsi
movq %rdi, %r14
movq %rbx, %rdi
callq 0x327a8
movl %eax, %r13d
testl %eax, %eax
je 0x3a822
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3503f
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3503f
jmp 0x3a825
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq