// File: /workspace/github_c_makefile_star2_O3/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 $0x118, %rsp            # imm = 0x118
movl %edx, %ebx
movq %rsi, %r13
movq %rdi, %r12
movq %rcx, -0x128(%rbp)
movq %r8, -0x120(%rbp)
movq %r9, -0x118(%rbp)
testb %al, %al
je 0x38c01
movaps %xmm0, -0x110(%rbp)
movaps %xmm1, -0x100(%rbp)
movaps %xmm2, -0xf0(%rbp)
movaps %xmm3, -0xe0(%rbp)
movaps %xmm4, -0xd0(%rbp)
movaps %xmm5, -0xc0(%rbp)
movaps %xmm6, -0xb0(%rbp)
movaps %xmm7, -0xa0(%rbp)
movq 0x20(%rdi), %r14
movq (%r14), %r15
leaq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x37ddc
testl %eax, %eax
jne 0x38eab
movl %ebx, -0x50(%rbp)
movq (%r15), %rax
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x38eab
movq 0x10(%rbx), %rax
movq %rax, 0x18(%r12)
movq 0x8(%r14), %rcx
movq (%rcx), %rcx
movq %r12, -0x80(%rbp)
movzwl 0x28(%r12), %edx
bswapq %rax
movq %rax, 0x12(%rcx,%rdx)
movq (%rbx), %rax
movq $0x0, (%rax)
movq (%rbx), %rax
leaq 0x12(%rax), %r14
movq %r15, -0x40(%rbp)
movslq 0x110(%r15), %r15
addq %rax, %r15
movq %rbx, -0x38(%rbp)
movl -0x50(%rbp), %eax
testl %eax, %eax
movq %rbx, -0x78(%rbp)
je 0x38d47
movl %eax, %eax
addq %r13, %rax
movq %rax, -0x88(%rbp)
movq %rbx, -0x48(%rbp)
cmpq %r15, %r14
jae 0x38ca3
movq -0x48(%rbp), %r12
jmp 0x38d09
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
callq 0x37ddc
testl %eax, %eax
jne 0x38eab
movq (%rbx), %rax
movq -0x38(%rbp), %r12
movq %r12, %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x38eab
movq -0x48(%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), %rax
leaq 0x8(%rax), %r14
movslq 0x110(%rbx), %r15
addq %rax, %r15
movq %r12, -0x48(%rbp)
movq %r15, -0x50(%rbp)
movl %r15d, %eax
subl %r14d, %eax
movq -0x88(%rbp), %r15
movl %r15d, %ebx
subl %r13d, %ebx
cmpl %eax, %ebx
cmovael %eax, %ebx
movq %r13, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x34893
addq %rbx, %r13
addq %rbx, %r14
cmpq %r15, %r13
movq -0x50(%rbp), %r15
jb 0x38c98
jmp 0x38d4a
movq %rbx, %r12
movq %r12, -0x30(%rbp)
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rax, -0x70(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x140(%rbp), %rax
movq %rax, -0x60(%rbp)
movq 0x10(%r12), %rax
movq -0x80(%rbp), %rsi
movq %rax, 0x30(%rsi)
movl (%r12), %ecx
movl %r14d, %edx
subl %ecx, %edx
movw %dx, 0x38(%rsi)
bswapq %rax
movq -0x78(%rbp), %rdx
movq (%rdx), %rcx
movq %rax, 0x8(%rcx)
movq (%rdx), %rax
movzwl 0x38(%rsi), %ecx
rolw $0x8, %cx
movw %cx, 0x10(%rax)
movq -0x60(%rbp), %rax
movl -0x70(%rbp), %ecx
movq -0x68(%rbp), %rdx
cmpl $0x29, %ecx
jae 0x38dd4
movl %ecx, %edi
leal 0x8(%rcx), %esi
movl %esi, -0x70(%rbp)
movq (%rax,%rdi), %r12
cmpl $0x20, %ecx
ja 0x38de4
movl %esi, %esi
addq %rax, %rsi
addl $0x10, %ecx
movl %ecx, -0x70(%rbp)
jmp 0x38df1
leaq 0x8(%rdx), %rsi
movq %rsi, -0x68(%rbp)
movq (%rdx), %r12
movq %rsi, %rdx
jmp 0x38de6
movl %esi, %ecx
movq %rdx, %rsi
addq $0x8, %rdx
movq %rdx, -0x68(%rbp)
testq %r12, %r12
je 0x38e9b
movq (%rsi), %r13
testq %r13, %r13
jle 0x38db1
addq %r12, %r13
cmpq %r15, %r14
jb 0x38e69
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
callq 0x37ddc
testl %eax, %eax
jne 0x38eab
movq (%rbx), %rax
movq -0x38(%rbp), %r14
movq %r14, %rdi
callq *0x28(%rax)
testl %eax, %eax
jne 0x38eab
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), %r15
addq %rax, %r15
movl %r15d, %eax
subl %r14d, %eax
movl %r13d, %ebx
subl %r12d, %ebx
cmpl %eax, %ebx
cmovael %eax, %ebx
movq %r12, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x34893
addq %rbx, %r12
addq %rbx, %r14
cmpq %r13, %r12
jb 0x38e05
jmp 0x38da6
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rdi
callq *0x50(%rax)
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq