// File: /workspace/github_c_makefile_star2_O3/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
movq $0x0, -0x28(%rbp)
movzwl 0x100(%rdi), %eax
movl 0x110(%rdi), %ecx
addl $-0x10, %ecx
cmpl %eax, %ecx
jge 0x38221
movq (%rbx), %rax
movq 0xf8(%rbx), %rsi
movq (%rax), %rdi
leaq -0x30(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x3831e
leaq -0x28(%rbp), %rsi
movq %rbx, %rdi
callq 0x37ddc
testl %eax, %eax
jne 0x3831e
movq $0x0, 0x108(%rbx)
movq -0x28(%rbp), %r12
movq 0x10(%r12), %rax
movq %rax, 0xf8(%rbx)
movl $0x0, 0x104(%rbx)
movw $0xc, 0x100(%rbx)
movq (%rbx), %rax
movq -0x30(%rbp), %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x3831e
movq -0x30(%rbp), %rcx
movq (%rcx), %rax
movq 0x10(%rcx), %rcx
movq 0xd0(%rbx), %rdx
cmpq 0x10(%rdx), %rcx
jne 0x382fc
movq 0x10(%r12), %rcx
bswapq %rcx
movq %rcx, 0x20(%rax)
jmp 0x38311
movq (%rbx), %rax
movq 0xf8(%rbx), %rsi
movq (%rax), %rdi
leaq -0x28(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x3831e
movq -0x28(%rbp), %r12
movq (%rbx), %rax
movq %r12, %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x3831e
movq -0x28(%rbp), %rax
movq (%rax), %rax
movzwl 0x100(%rbx), %ecx
movq %r15, %rdx
bswapq %rdx
movq %rdx, (%rax,%rcx)
movl 0x100(%rbx), %eax
addl $0x8, %eax
movw %ax, 0x100(%rbx)
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movzwl %ax, %eax
movq %r14, %rdx
bswapq %rdx
movq %rdx, (%rcx,%rax)
addw $0x8, 0x100(%rbx)
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x37049
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x3831e
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 0x382dc
movq (%rdi), %rcx
bswapl %eax
movl %eax, 0x28(%rcx)
jmp 0x382f8
movq (%rbx), %rax
callq *0x28(%rax)
testl %eax, %eax
jne 0x3831e
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl 0x104(%rbx), %ecx
bswapl %ecx
movl %ecx, 0x8(%rax)
xorl %eax, %eax
jmp 0x3831e
movq 0x10(%r12), %rcx
bswapq %rcx
movq %rcx, (%rax)
movq (%rbx), %rax
movq -0x30(%rbp), %rdi
callq *0x50(%rax)
movq (%rbx), %rax
movq %r12, %rdi
callq *0x28(%rax)
testl %eax, %eax
je 0x3832b
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rax
movq $0x0, (%rax)
jmp 0x38241