// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0xf8, %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rax
movzwl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movl 0x110(%rcx), %ecx
subl $0x10, %ecx
cmpl %ecx, %eax
jle 0x62c60
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
movq -0x28(%rbp), %rcx
movq (%rcx), %rsi
leaq -0x40(%rbp), %rdx
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x62b5d
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62db2
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x625b0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x62b7e
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62db2
movq -0x28(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x28(%rbp), %rax
movw $0xc, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rdi
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x62bd3
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62db2
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0xd0(%rcx), %rcx
cmpq 0x10(%rcx), %rax
jne 0x62c06
movq -0x40(%rbp), %rax
movq (%rax), %rdi
addq $0x20, %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x61c60
jmp 0x62c2b
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x61c60
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x50(%rax), %rax
movq -0x40(%rbp), %rdi
callq *%rax
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rdi
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x62c50
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62db2
movq -0x30(%rbp), %rax
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x61c60
cmpq $0x0, -0x30(%rbp)
jne 0x62c9f
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
movq -0x28(%rbp), %rcx
movq (%rcx), %rsi
leaq -0x30(%rbp), %rdx
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x62c9d
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62db2
jmp 0x62c9f
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rdi
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x62cc4
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62db2
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movzwl 0x8(%rax), %eax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x61c60
movq -0x28(%rbp), %rax
movzwl 0x8(%rax), %ecx
addl $0x8, %ecx
movw %cx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movzwl 0x8(%rax), %eax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x61c60
movq -0x28(%rbp), %rax
movzwl 0x8(%rax), %ecx
addl $0x8, %ecx
movw %cx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x61f80
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x62dac
movq -0x28(%rbp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0xd0(%rcx), %rcx
cmpq 0x10(%rcx), %rax
jne 0x62d71
movq -0x30(%rbp), %rax
movq (%rax), %rdi
addq $0x28, %rdi
movq -0x28(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x61bf0
jmp 0x62daa
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rdi
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x62d93
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x62db2
movq -0x30(%rbp), %rax
movq (%rax), %rdi
addq $0x8, %rdi
movq -0x28(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x61bf0
jmp 0x62dac
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)