// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq $0x0, -0x20(%rbp)
movzwl 0x100(%rdi), %eax
movl 0x110(%rdi), %ecx
addl $-0x10, %ecx
cmpl %eax, %ecx
jge 0x38a57
movq (%rbx), %rax
movq 0xf8(%rbx), %rsi
movq (%rax), %rdi
leaq -0x28(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x38a4d
leaq -0x20(%rbp), %rsi
movq %rbx, %rdi
callq 0x38609
testl %eax, %eax
jne 0x38a4d
movq $0x0, 0x108(%rbx)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, 0xf8(%rbx)
movl $0x0, 0x104(%rbx)
movw $0xc, 0x100(%rbx)
movq (%rbx), %rax
movq -0x28(%rbp), %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x38a4d
movq -0x28(%rbp), %rcx
movq (%rcx), %rax
movq 0x10(%rcx), %rcx
movq 0xd0(%rbx), %rdx
cmpq 0x10(%rdx), %rcx
jne 0x38a23
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
bswapq %rcx
movq %rcx, 0x20(%rax)
jmp 0x38a3b
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
bswapq %rcx
movq %rcx, (%rax)
movq (%rbx), %rax
movq -0x28(%rbp), %rdi
callq *0x50(%rax)
movq (%rbx), %rax
movq -0x20(%rbp), %rdi
callq *0x28(%rax)
testl %eax, %eax
je 0x38b71
xorl %ecx, %ecx
testb %cl, %cl
je 0x38b66
cmpq $0x0, -0x20(%rbp)
je 0x38b14
movq (%rbx), %rax
movq -0x20(%rbp), %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x38b66
movq -0x20(%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 -0x20(%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 0x377a1
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x38b66
movl 0x104(%rbx), %eax
incl %eax
movl %eax, 0x104(%rbx)
movq -0x20(%rbp), %rdi
movq 0x10(%rdi), %rcx
movq 0xd0(%rbx), %rdx
cmpq 0x10(%rdx), %rcx
jne 0x38b31
movq (%rdi), %rdx
leaq 0x28(%rdx), %rcx
movl %eax, %esi
rolw $0x8, %si
movw %si, 0x2a(%rdx)
movl %eax, %esi
shrl $0x10, %esi
movb %sil, 0x29(%rdx)
jmp 0x38b5f
movq (%rbx), %rax
movq 0xf8(%rbx), %rsi
movq (%rax), %rdi
leaq -0x20(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x38b66
jmp 0x38a62
movq (%rbx), %rax
callq *0x28(%rax)
testl %eax, %eax
jne 0x38b66
movq -0x20(%rbp), %rax
movq (%rax), %rdx
leaq 0x8(%rdx), %rcx
movl 0x104(%rbx), %eax
movl %eax, %esi
rolw $0x8, %si
movw %si, 0xa(%rdx)
movl %eax, %esi
shrl $0x10, %esi
movb %sil, 0x9(%rdx)
shrl $0x18, %eax
movb %al, (%rcx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq $0x0, (%rax)
movb $0x1, %cl
jmp 0x38a4f