// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: lhPageSplit
static int lhPageSplit(
	lhpage *pOld,      /* Page to be split */
	lhpage *pNew,      /* New page */
	pgno split_bucket, /* Current split bucket */
	pgno high_mask     /* High mask (Max split bucket - 1) */
	)
{
	lhcell *pCell,*pNext;
	SyBlob sWorker;
	pgno iBucket;
	int rc; 
	SyBlobInit(&sWorker,&pOld->pHash->sAllocator);
	/* Perform the split */
	pCell = pOld->pList;
	for( ;; ){
		if( pCell == 0 ){
			/* No more cells */
			break;
		}
		/* Obtain the new logical bucket */
		iBucket = pCell->nHash & high_mask;
		pNext =  pCell->pNext;
		if( iBucket != split_bucket){
			rc = UNQLITE_OK;
			if( pCell->iOvfl ){
				/* Transfer the cell only */
				rc = lhTransferCell(pCell,pNew);
			}else{
				/* Transfer the cell and its payload */
				SyBlobReset(&sWorker);
				if( SyBlobLength(&pCell->sKey) < 1 ){
					/* Consume the key */
					rc = lhConsumeCellkey(pCell,unqliteDataConsumer,&pCell->sKey,0);
					if( rc != UNQLITE_OK ){
						goto fail;
					}
				}
				/* Consume the data (Very small data < 65k) */
				rc = lhConsumeCellData(pCell,unqliteDataConsumer,&sWorker);
				if( rc != UNQLITE_OK ){
					goto fail;
				}
				/* Perform the transfer */
				rc = lhStoreCell(
					pNew,
					SyBlobData(&pCell->sKey),(int)SyBlobLength(&pCell->sKey),
					SyBlobData(&sWorker),SyBlobLength(&sWorker),
					pCell->nHash,
					1
					);
			}
			if( rc != UNQLITE_OK ){
				goto fail;
			}
			/* Discard the cell from the old page */
			lhUnlinkCell(pCell);
		}
		/* Point to the next cell */
		pCell = pNext;
	}
	/* All done */
	rc = UNQLITE_OK;
fail:
	SyBlobRelease(&sWorker);
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
addq $0x8, %rdi
xorps %xmm0, %xmm0
movups %xmm0, -0x48(%rbp)
movq %rdi, -0x50(%rbp)
movl $0x0, -0x38(%rbp)
testq %rsi, %rsi
je 0x394bd
movq %r8, %rbx
movq %rdx, %r15
movq %rsi, %r12
movq %rcx, -0x68(%rbp)
movq %r8, -0x60(%rbp)
movl (%r12), %eax
andl %ebx, %eax
movq 0x60(%r12), %r14
cmpq %rcx, %rax
je 0x394ac
cmpq $0x0, 0x18(%r12)
je 0x39417
movq %r15, -0x58(%rbp)
movl $0x1a, %esi
movq %r15, %rdi
leaq -0x2a(%rbp), %rdx
callq 0x38687
movq %r15, %rsi
testl %eax, %eax
je 0x3938c
movq (%r15), %rdi
movq 0x40(%r15), %rsi
movl $0x1a, %edx
leaq -0x2a(%rbp), %rcx
leaq -0x58(%rbp), %r8
callq 0x38fc0
movl %eax, %r13d
testl %eax, %eax
jne 0x3940e
movq -0x58(%rbp), %rsi
movq (%rsi), %rdi
callq 0x38981
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x3940e
movq %rax, %rbx
movzwl -0x2a(%rbp), %eax
movw %ax, 0x28(%rbx)
movq 0x8(%r12), %rax
movq %rax, 0x8(%rbx)
movl 0x4(%r12), %eax
movl %eax, 0x4(%rbx)
movq 0x18(%r12), %rax
movq %rax, 0x18(%rbx)
movzwl 0x38(%r12), %eax
movw %ax, 0x38(%rbx)
movq 0x30(%r12), %rax
movq %rax, 0x30(%rbx)
movl (%r12), %eax
movl %eax, (%rbx)
movl 0x50(%r12), %edx
testl %edx, %edx
je 0x393f7
movq %rbx, %rdi
addq $0x40, %rdi
movq 0x48(%r12), %rsi
callq 0x359ad
movq %rbx, %rdi
callq 0x389d8
testl %eax, %eax
jne 0x3940e
movq %rbx, %rdi
callq 0x38f5b
xorl %r13d, %r13d
movq -0x60(%rbp), %rbx
jmp 0x3949b
movl $0x0, -0x40(%rbp)
movl -0x38(%rbp), %eax
testb $0x4, %al
je 0x3943a
movq $0x0, -0x48(%rbp)
movl $0x0, -0x3c(%rbp)
andl $-0x5, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, 0x50(%r12)
jne 0x3945c
leaq 0x40(%r12), %rdx
movq %r12, %rdi
leaq -0x772a(%rip), %rsi     # 0x31d27
xorl %ecx, %ecx
callq 0x39132
testl %eax, %eax
jne 0x394c2
movq %r12, %rdi
leaq -0x773f(%rip), %rsi     # 0x31d27
leaq -0x50(%rbp), %rdx
callq 0x394f0
testl %eax, %eax
jne 0x394c2
movq 0x48(%r12), %rsi
movl 0x50(%r12), %edx
movq -0x48(%rbp), %rcx
movl -0x40(%rbp), %r8d
movl (%r12), %r9d
movl $0x1, (%rsp)
movq %r15, %rdi
callq 0x37f67
movl %eax, %r13d
testl %r13d, %r13d
jne 0x394c5
movq %r12, %rdi
callq 0x39640
movq -0x68(%rbp), %rcx
movq %r14, %r12
testq %r14, %r14
jne 0x39328
xorl %r13d, %r13d
jmp 0x394c5
xorl %r13d, %r13d
jmp 0x394de
movl %eax, %r13d
testb $0x6, -0x38(%rbp)
jne 0x394de
cmpl $0x0, -0x3c(%rbp)
je 0x394de
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x3490d
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq