// File: /workspace/github_c_makefile_star2_O1/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, %r13d
movq %rsi, %r12
movq %rdi, %r14
movq %rcx, -0x118(%rbp)
movq %r8, -0x110(%rbp)
movq %r9, -0x108(%rbp)
testb %al, %al
je 0x394a1
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 0x38609
testl %eax, %eax
jne 0x394cd
movl %r13d, -0x38(%rbp)
movq (%r15), %rax
movq -0x30(%rbp), %r13
movq %r13, %rdi
callq *0x28(%rax)
testl %eax, %eax
je 0x394df
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%r13), %rax
movq %rax, 0x18(%r14)
movq 0x8(%rbx), %rcx
movq (%rcx), %rcx
movq %r14, -0x78(%rbp)
movzwl 0x28(%r14), %edx
bswapq %rax
movq %rax, 0x12(%rcx,%rdx)
movq (%r13), %rax
movq $0x0, (%rax)
movq (%r13), %rax
leaq 0x12(%rax), %r14
movq %r15, -0x70(%rbp)
movslq 0x110(%r15), %rbx
addq %rax, %rbx
movq %r13, -0x40(%rbp)
movl -0x38(%rbp), %eax
testl %eax, %eax
movq %r13, %r15
je 0x395de
movl %eax, %eax
addq %r12, %rax
movq %rax, -0x38(%rbp)
movq %r15, -0x68(%rbp)
movq -0x38(%rbp), %r13
cmpq %rbx, %r14
jb 0x395ab
movq -0x70(%rbp), %rbx
movq %rbx, %rdi
leaq -0x40(%rbp), %rsi
callq 0x38609
testl %eax, %eax
jne 0x394cd
movq (%rbx), %rax
movq -0x40(%rbp), %r14
movq %r14, %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x394cd
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%r14), %rcx
bswapq %rcx
movq %rcx, (%rax)
movq (%rbx), %rax
callq *0x50(%rax)
movq (%r14), %rax
movq $0x0, (%rax)
movq %r14, -0x30(%rbp)
movq (%r14), %rax
leaq 0x8(%rax), %r14
movslq 0x110(%rbx), %rbx
addq %rax, %rbx
movl %ebx, %eax
subl %r14d, %eax
movl %r13d, %r15d
subl %r12d, %r15d
cmpl %eax, %r15d
cmovael %eax, %r15d
movq %r12, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x34fc5
addq %r15, %r12
addq %r15, %r14
movq -0x68(%rbp), %r15
cmpq %r13, %r12
jb 0x39543
leaq -0x130(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rax, -0x60(%rbp)
leaq -0x40(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rcx
movq -0x78(%rbp), %rsi
movq %rcx, 0x30(%rsi)
movl (%rax), %eax
movl %r14d, %edx
subl %eax, %edx
movw %dx, 0x38(%rsi)
movq (%r15), %rax
bswapq %rcx
movq %rcx, 0x8(%rax)
movq (%r15), %rax
movzwl 0x38(%rsi), %ecx
rolw $0x8, %cx
movw %cx, 0x10(%rax)
movl -0x60(%rbp), %ecx
cmpq $0x28, %rcx
ja 0x3964e
movq %rcx, %rdx
addq -0x50(%rbp), %rdx
addl $0x8, %ecx
movl %ecx, -0x60(%rbp)
jmp 0x3965a
movq -0x58(%rbp), %rdx
leaq 0x8(%rdx), %rcx
movq %rcx, -0x58(%rbp)
movq (%rdx), %r13
movl -0x60(%rbp), %ecx
cmpq $0x28, %rcx
ja 0x39675
movq %rcx, %rdx
addq -0x50(%rbp), %rdx
addl $0x8, %ecx
movl %ecx, -0x60(%rbp)
jmp 0x39681
movq -0x58(%rbp), %rdx
leaq 0x8(%rdx), %rcx
movq %rcx, -0x58(%rbp)
testq %r13, %r13
je 0x3973f
movq (%rdx), %r15
xorl %ecx, %ecx
testq %r15, %r15
jle 0x3974f
movl %eax, -0x38(%rbp)
addq %r13, %r15
cmpq %rbx, %r14
jb 0x39709
movq %rbx, -0x68(%rbp)
movq -0x70(%rbp), %rbx
movq %rbx, %rdi
leaq -0x40(%rbp), %rsi
callq 0x38609
testl %eax, %eax
jne 0x39746
movq (%rbx), %rax
movq -0x40(%rbp), %r12
movq %r12, %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x39746
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%r12), %rcx
bswapq %rcx
movq %rcx, (%rax)
movq (%rbx), %rax
callq *0x50(%rax)
movq (%r12), %rax
movq $0x0, (%rax)
movq %r12, -0x30(%rbp)
movq (%r12), %rax
leaq 0x8(%rax), %r14
movslq 0x110(%rbx), %rbx
addq %rax, %rbx
movl %ebx, %eax
subl %r14d, %eax
movl %r15d, %r12d
subl %r13d, %r12d
cmpl %eax, %r12d
cmovael %eax, %r12d
movq %r13, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x34fc5
addq %r12, %r13
addq %r12, %r14
cmpq %r15, %r13
jb 0x3969e
movl -0x38(%rbp), %eax
xorl %ecx, %ecx
jmp 0x3974f
movl $0x4, %ecx
jmp 0x3974f
movl $0x1, %ecx
movq -0x68(%rbp), %rbx
testl %ecx, %ecx
je 0x39636
cmpl $0x4, %ecx
jne 0x394cd
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rdi
callq *0x50(%rax)
xorl %eax, %eax
jmp 0x394cd