// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: lhCellWriteOvflPayload
static int lhCellWriteOvflPayload(lhcell *pCell,const void *pKey,sxu32 nKeylen,...)
{
	lhpage *pPage = pCell->pPage;
	lhash_kv_engine *pEngine = pPage->pHash;
	unqlite_page *pOvfl,*pFirst,*pNew;
	const unsigned char *zPtr,*zEnd;
	unsigned char *zRaw,*zRawEnd;
	sxu32 nAvail;
	va_list ap;
	int rc;
	/* Acquire a new overflow page */
	rc = lhAcquirePage(pEngine,&pOvfl);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	/* Acquire a writer lock */
	rc = pEngine->pIo->xWrite(pOvfl);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	pFirst = pOvfl;
	/* Link */
	pCell->iOvfl = pOvfl->iPage;
	/* Update the cell header */
	SyBigEndianPack64(&pPage->pRaw->zData[pCell->iStart + 4/*Hash*/ + 4/*Key*/ + 8/*Data*/ + 2 /*Next cell*/],pCell->iOvfl);
	/* Start the write process */
	zPtr = (const unsigned char *)pKey;
	zEnd = &zPtr[nKeylen];
	SyBigEndianPack64(pOvfl->zData,0); /* Next overflow page on the chain */
	zRaw = &pOvfl->zData[8/* Next ovfl page*/ + 8 /* Data page */ + 2 /* Data offset*/];
	zRawEnd = &pOvfl->zData[pEngine->iPageSize];
	pNew = pOvfl;
	/* Write the key */
	for(;;){
		if( zPtr >= zEnd ){
			break;
		}
		if( zRaw >= zRawEnd ){
			/* Acquire a new page */
			rc = lhAcquirePage(pEngine,&pNew);
			if( rc != UNQLITE_OK ){
				return rc;
			}
			rc = pEngine->pIo->xWrite(pNew);
			if( rc != UNQLITE_OK ){
				return rc;
			}
			/* Link */
			SyBigEndianPack64(pOvfl->zData,pNew->iPage);
			pEngine->pIo->xPageUnref(pOvfl);
			SyBigEndianPack64(pNew->zData,0); /* Next overflow page on the chain */
			pOvfl = pNew;
			zRaw = &pNew->zData[8];
			zRawEnd = &pNew->zData[pEngine->iPageSize];
		}
		nAvail = (sxu32)(zRawEnd-zRaw);
		nKeylen = (sxu32)(zEnd-zPtr);
		if( nKeylen > nAvail ){
			nKeylen = nAvail;
		}
		SyMemcpy((const void *)zPtr,(void *)zRaw,nKeylen);
		/* Synchronize pointers */
		zPtr += nKeylen;
		zRaw += nKeylen;
	}
	rc = UNQLITE_OK;
	va_start(ap,nKeylen);
	pCell->iDataPage = pNew->iPage;
	pCell->iDataOfft = (sxu16)(zRaw-pNew->zData);
	/* Write the data page and its offset */
	SyBigEndianPack64(&pFirst->zData[8/*Next ovfl*/],pCell->iDataPage);
	SyBigEndianPack16(&pFirst->zData[8/*Next ovfl*/+8/*Data page*/],pCell->iDataOfft);
	/* Write data */
	for(;;){
		const void *pData;
		sxu32 nDatalen;
		sxu64 nData;
		pData = va_arg(ap,const void *);
		nData = va_arg(ap,sxu64);
		if( pData == 0 ){
			/* No more chunks */
			break;
		}
		/* Write this chunk */
		zPtr = (const unsigned char *)pData;
		zEnd = &zPtr[nData];
		for(;;){
			if( zPtr >= zEnd ){
				break;
			}
			if( zRaw >= zRawEnd ){
				/* Acquire a new page */
				rc = lhAcquirePage(pEngine,&pNew);
				if( rc != UNQLITE_OK ){
					va_end(ap);
					return rc;
				}
				rc = pEngine->pIo->xWrite(pNew);
				if( rc != UNQLITE_OK ){
					va_end(ap);
					return rc;
				}
				/* Link */
				SyBigEndianPack64(pOvfl->zData,pNew->iPage);
				pEngine->pIo->xPageUnref(pOvfl);
				SyBigEndianPack64(pNew->zData,0); /* Next overflow page on the chain */
				pOvfl = pNew;
				zRaw = &pNew->zData[8];
				zRawEnd = &pNew->zData[pEngine->iPageSize];
			}
			nAvail = (sxu32)(zRawEnd-zRaw);
			nDatalen = (sxu32)(zEnd-zPtr);
			if( nDatalen > nAvail ){
				nDatalen = nAvail;
			}
			SyMemcpy((const void *)zPtr,(void *)zRaw,nDatalen);
			/* Synchronize pointers */
			zPtr += nDatalen;
			zRaw += nDatalen;
		}
	}
	/* Unref the overflow page */
	pEngine->pIo->xPageUnref(pOvfl);
	va_end(ap);
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %edx, %r14d
movq %rsi, %r13
movq %rdi, %r12
movq %rcx, -0x118(%rbp)
movq %r8, -0x110(%rbp)
movq %r9, -0x108(%rbp)
testb %al, %al
je 0x313ce
movaps %xmm0, -0x100(%rbp)
movaps %xmm1, -0xf0(%rbp)
movaps %xmm2, -0xe0(%rbp)
movaps %xmm3, -0xd0(%rbp)
movaps %xmm4, -0xc0(%rbp)
movaps %xmm5, -0xb0(%rbp)
movaps %xmm6, -0xa0(%rbp)
movaps %xmm7, -0x90(%rbp)
movq 0x20(%rdi), %rbx
movq (%rbx), %r15
leaq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x3064e
testl %eax, %eax
jne 0x313f7
movq (%r15), %rax
movq -0x30(%rbp), %rdi
movq %rdi, -0x68(%rbp)
callq *0x28(%rax)
testl %eax, %eax
je 0x31409
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rsi
movq %rsi, 0x18(%r12)
movq 0x8(%rbx), %rax
movq (%rax), %rax
movzwl 0x28(%r12), %ecx
leaq (%rax,%rcx), %rdi
addq $0x12, %rdi
callq 0x2f66d
movl %r14d, %ecx
movq -0x68(%rbp), %rbx
movq (%rbx), %rax
andq $0x0, (%rax)
addq %r13, %rcx
movq (%rbx), %rax
leaq 0x12(%rax), %r14
movq %r15, -0x60(%rbp)
movslq 0x110(%r15), %r15
addq %rax, %r15
leaq -0x38(%rbp), %rax
movq %rbx, (%rax)
movq %rbx, -0x58(%rbp)
movq %r12, -0x78(%rbp)
movq %rcx, -0x70(%rbp)
cmpq %rcx, %r13
jae 0x31514
cmpq %r15, %r14
jb 0x314e0
movq -0x60(%rbp), %r15
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
callq 0x3064e
testl %eax, %eax
jne 0x313f7
movq (%r15), %rax
movq -0x38(%rbp), %r12
movq %r12, %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x313f7
movq -0x58(%rbp), %r14
movq (%r14), %rdi
movq 0x10(%r12), %rsi
callq 0x2f66d
movq (%r15), %rax
movq %r14, %rdi
callq *0x50(%rax)
movq (%r12), %rax
andq $0x0, (%rax)
movq (%r12), %rax
leaq 0x8(%rax), %r14
movslq 0x110(%r15), %r15
addq %rax, %r15
movq %r12, -0x58(%rbp)
movq -0x70(%rbp), %rcx
movl %r15d, %eax
subl %r14d, %eax
movl %ecx, %r12d
subl %r13d, %r12d
cmpl %eax, %r12d
cmovael %eax, %r12d
movq %r13, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x2d3b0
movq -0x70(%rbp), %rcx
addq %r12, %r13
addq %r12, %r14
movq -0x78(%rbp), %r12
jmp 0x31469
movq -0x58(%rbp), %rcx
movq %rcx, -0x30(%rbp)
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rax, -0x50(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x130(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x10(%rcx), %rsi
movq %rsi, 0x30(%r12)
movl (%rcx), %eax
movl %r14d, %ecx
subl %eax, %ecx
movw %cx, 0x38(%r12)
movq (%rbx), %rdi
addq $0x8, %rdi
callq 0x2f66d
movq (%rbx), %rax
movzwl 0x38(%r12), %ecx
rolw $0x8, %cx
movw %cx, 0x10(%rax)
movl -0x50(%rbp), %ecx
cmpq $0x29, %rcx
jae 0x3159c
movq -0x40(%rbp), %rdx
movq %rcx, %rax
addq $0x8, %rax
movl %eax, -0x50(%rbp)
movq (%rdx,%rcx), %r12
cmpl $0x20, %ecx
ja 0x315ab
addq -0x40(%rbp), %rax
addl $0x10, %ecx
movl %ecx, -0x50(%rbp)
jmp 0x315b7
movq -0x48(%rbp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, -0x48(%rbp)
movq (%rax), %r12
movq -0x48(%rbp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, -0x48(%rbp)
testq %r12, %r12
je 0x3165f
movq (%rax), %rbx
addq %r12, %rbx
cmpq %rbx, %r12
jae 0x31570
cmpq %r15, %r14
jb 0x31633
movq -0x60(%rbp), %r15
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
callq 0x3064e
testl %eax, %eax
jne 0x313f7
movq (%r15), %rax
movq -0x38(%rbp), %r14
movq %r14, %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x313f7
movq -0x30(%rbp), %r13
movq (%r13), %rdi
movq 0x10(%r14), %rsi
callq 0x2f66d
movq (%r15), %rax
movq %r13, %rdi
callq *0x50(%rax)
movq (%r14), %rax
andq $0x0, (%rax)
movq %r14, -0x30(%rbp)
movq (%r14), %rax
leaq 0x8(%rax), %r14
movslq 0x110(%r15), %r15
addq %rax, %r15
movl %r15d, %eax
subl %r14d, %eax
movl %ebx, %r13d
subl %r12d, %r13d
cmpl %eax, %r13d
cmovael %eax, %r13d
movq %r12, %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x2d3b0
addq %r13, %r12
addq %r13, %r14
jmp 0x315c6
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rdi
callq *0x50(%rax)
xorl %eax, %eax
jmp 0x313f7