// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: lhMapWriteRecord
static int lhMapWriteRecord(lhash_kv_engine *pEngine,pgno iLogic,pgno iReal)
{
	lhash_bmap_page *pMap = &pEngine->sPageMap;
	unqlite_page *pPage = 0;
	int rc;
	if( pMap->iPtr > (pEngine->iPageSize - 16) /* 8 byte logical bucket number + 8 byte real bucket number */ ){
		unqlite_page *pOld;
		/* Point to the old page */
		rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,pMap->iNum,&pOld);
		if( rc != UNQLITE_OK ){
			return rc;
		}
		/* Acquire a new page */
		rc = lhAcquirePage(pEngine,&pPage);
		if( rc != UNQLITE_OK ){
			return rc;
		}
		/* Reflect the change  */
		pMap->iNext = 0;
		pMap->iNum = pPage->iPage;
		pMap->nRec = 0;
		pMap->iPtr = 8/* Next page number */+4/* Total records in the map*/;
		/* Link this page */
		rc = pEngine->pIo->xWrite(pOld);
		if( rc != UNQLITE_OK ){
			return rc;
		}
		if( pOld->iPage == pEngine->pHeader->iPage ){
			/* First page (Hash header) */
			SyBigEndianPack64(&pOld->zData[4/*magic*/+4/*hash*/+8/* Free page */+8/*current split bucket*/+8/*Maximum split bucket*/],pPage->iPage);
		}else{
			/* Link the new page */
			SyBigEndianPack64(pOld->zData,pPage->iPage);
			/* Unref */
			pEngine->pIo->xPageUnref(pOld);
		}
		/* Assume the last bucket map page */
		rc = pEngine->pIo->xWrite(pPage);
		if( rc != UNQLITE_OK ){
			return rc;
		}
		SyBigEndianPack64(pPage->zData,0); /* Next bucket map page on the list */
	}
	if( pPage == 0){
		/* Point to the current map page */
		rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,pMap->iNum,&pPage);
		if( rc != UNQLITE_OK ){
			return rc;
		}
	}
	/* Make page writable */
	rc = pEngine->pIo->xWrite(pPage);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	/* Write the data */
	SyBigEndianPack64(&pPage->zData[pMap->iPtr],iLogic);
	pMap->iPtr += 8;
	SyBigEndianPack64(&pPage->zData[pMap->iPtr],iReal);
	pMap->iPtr += 8;
	/* Install the bucket map */
	rc = lhMapInstallBucket(pEngine,iLogic,iReal);
	if( rc == UNQLITE_OK ){
		/* Total number of records */
		pMap->nRec++;
		if( pPage->iPage == pEngine->pHeader->iPage ){
			/* Page one: Always writable */
			SyBigEndianPack32(
				&pPage->zData[4/*magic*/+4/*hash*/+8/* Free page */+8/*current split bucket*/+8/*Maximum split bucket*/+8/*Next map page*/],
				pMap->nRec);
		}else{
			/* Make page writable */
			rc = pEngine->pIo->xWrite(pPage);
			if( rc != UNQLITE_OK ){
				return rc;
			}
			SyBigEndianPack32(&pPage->zData[8],pMap->nRec);
		}
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
andq $0x0, -0x28(%rbp)
movzwl 0x100(%rdi), %eax
movl 0x110(%rdi), %ecx
addl $-0x10, %ecx
cmpl %eax, %ecx
jge 0x30a40
movq (%rbx), %rax
movq 0xf8(%rbx), %rsi
movq (%rax), %rdi
leaq -0x30(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x30b36
leaq -0x28(%rbp), %rsi
movq %rbx, %rdi
callq 0x3064e
testl %eax, %eax
jne 0x30b36
andq $0x0, 0x108(%rbx)
movq -0x28(%rbp), %r12
movq 0x10(%r12), %rax
movq %rax, 0xf8(%rbx)
andl $0x0, 0x104(%rbx)
movw $0xc, 0x100(%rbx)
movq (%rbx), %rax
movq -0x30(%rbp), %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x30b36
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq 0x10(%rax), %rax
movq 0xd0(%rbx), %rcx
cmpq 0x10(%rcx), %rax
jne 0x30b15
addq $0x20, %rdi
movq 0x10(%r12), %rsi
callq 0x2f66d
jmp 0x30b29
movq (%rbx), %rax
movq 0xf8(%rbx), %rsi
movq (%rax), %rdi
leaq -0x28(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x30b36
movq -0x28(%rbp), %r12
movq (%rbx), %rax
movq %r12, %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x30b36
movq -0x28(%rbp), %rax
movzwl 0x100(%rbx), %edi
addq (%rax), %rdi
movq %r15, %rsi
callq 0x2f66d
movl 0x100(%rbx), %eax
addl $0x8, %eax
movw %ax, 0x100(%rbx)
movq -0x28(%rbp), %rcx
movzwl %ax, %edi
addq (%rcx), %rdi
movq %r14, %rsi
callq 0x2f66d
addw $0x8, 0x100(%rbx)
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x2f754
testl %eax, %eax
je 0x30ac8
pushq $-0x1
popq %rax
jmp 0x30b36
movl 0x104(%rbx), %eax
incl %eax
movl %eax, 0x104(%rbx)
movq -0x28(%rbp), %rdi
movq 0x10(%rdi), %rcx
movq 0xd0(%rbx), %rdx
cmpq 0x10(%rdx), %rcx
jne 0x30af5
movq (%rdi), %rcx
bswapl %eax
movl %eax, 0x28(%rcx)
jmp 0x30b11
movq (%rbx), %rax
callq *0x28(%rax)
testl %eax, %eax
jne 0x30b36
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl 0x104(%rbx), %ecx
bswapl %ecx
movl %ecx, 0x8(%rax)
xorl %eax, %eax
jmp 0x30b36
movq 0x10(%r12), %rsi
callq 0x2f66d
movq (%rbx), %rax
movq -0x30(%rbp), %rdi
callq *0x50(%rax)
movq (%rbx), %rax
movq %r12, %rdi
callq *0x28(%rax)
testl %eax, %eax
je 0x30b43
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rax
andq $0x0, (%rax)
jmp 0x30a60