// File: /workspace/github_c_makefile_star2_O3/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 0x39d30
movq (%rax), %rax
cmpq %r13, 0x8(%rax)
je 0x39f2a
movq %r15, %rdi
callq 0x3a2dd
movl 0x8(%r13), %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x33d86
testq %rax, %rax
je 0x39ed8
movq %rax, -0x30(%rbp)
movq %rbx, %rdi
movl $0x88, %esi
callq 0x33d86
testq %rax, %rax
je 0x39ecc
movq %rax, %r12
movq $-0x4, %rax
movl $0x0, 0x4(%r12,%rax)
addq $0x4, %rax
cmpq $0x54, %rax
jb 0x39d6c
testq %r14, %r14
movq -0x30(%rbp), %rdi
je 0x39dbd
movq %rdi, %rax
addq %r14, %rax
movq %rdi, %rcx
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x39dbd
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x39dbd
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jae 0x39dbd
movb $0x0, (%rcx)
incq %rcx
cmpq %rax, %rcx
jb 0x39d91
movq %r15, (%r12)
movq %r13, 0x8(%r12)
leaq 0x664(%rip), %rax       # 0x3a431
movq %rax, 0x10(%r12)
leaq 0x664(%rip), %rax       # 0x3a43d
movq %rax, 0x18(%r12)
leaq 0x667(%rip), %rax       # 0x3a44c
movq %rax, 0x20(%r12)
leaq 0x693(%rip), %rax       # 0x3a484
movq %rax, 0x28(%r12)
leaq 0xb95(%rip), %rax       # 0x3a992
movq %rax, 0x30(%r12)
leaq 0xba1(%rip), %rax       # 0x3a9aa
movq %rax, 0x38(%r12)
leaq 0xbee(%rip), %rax       # 0x3aa03
movq %rax, 0x40(%r12)
leaq 0xbf3(%rip), %rax       # 0x3aa14
movq %rax, 0x48(%r12)
leaq 0xbf7(%rip), %rax       # 0x3aa24
movq %rax, 0x50(%r12)
leaq 0xc82(%rip), %rax       # 0x3aabb
movq %rax, 0x58(%r12)
leaq 0xc82(%rip), %rax       # 0x3aac7
movq %rax, 0x60(%r12)
leaq 0xc82(%rip), %rax       # 0x3aad3
movq %rax, 0x68(%r12)
leaq 0xc83(%rip), %rax       # 0x3aae0
movq %rax, 0x70(%r12)
leaq 0xc84(%rip), %rax       # 0x3aaed
movq %rax, 0x78(%r12)
leaq 0xc85(%rip), %rax       # 0x3aafa
movq %rax, 0x80(%r12)
movq %r12, (%rdi)
movq 0x18(%r13), %rax
testq %rax, %rax
je 0x39ef5
movl 0x5a929(%rip), %ecx     # 0x947b8
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 0x39eef
movl %eax, %r13d
addq $0x1e0, %r15            # imm = 0x1E0
leaq 0x39ae2(%rip), %rsi     # 0x7399f
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3a376
jmp 0x39f12
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x3490d
leaq 0x39af7(%rip), %rsi     # 0x739d6
movq %rbx, %rdi
callq 0x31537
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x39f2d
movq %r12, (%r14)
movq %r14, %rdi
movq %rdi, 0x10(%r15)
leaq 0xe8(%rbx), %rsi
movq %rdi, %r14
movq %rbx, %rdi
callq 0x321b9
movl %eax, %r13d
testl %eax, %eax
je 0x39f2a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3490d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3490d
jmp 0x39f2d
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq