// File: /workspace/github_c_makefile_star2_O1/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
movq %rsi, -0x38(%rbp)
movq (%rdi), %rax
addq $0x8, %rax
xorps %xmm0, %xmm0
movups %xmm0, -0x50(%rbp)
movq %rax, -0x58(%rbp)
movl $0x0, -0x40(%rbp)
movq 0x28(%rdi), %r12
testq %r12, %r12
je 0x39de6
movq %rcx, %rbx
movq %rdx, %r15
movq %rdx, -0x68(%rbp)
movl (%r12), %eax
andl %ebx, %eax
movq 0x60(%r12), %r14
cmpq %r15, %rax
je 0x39dda
cmpq $0x0, 0x18(%r12)
je 0x39d40
movq %rbx, %r15
movq -0x38(%rbp), %rdi
movq %rdi, -0x60(%rbp)
movl $0x1a, %esi
leaq -0x2a(%rbp), %rdx
callq 0x38f12
testl %eax, %eax
je 0x39cae
movl $0x1a, %esi
movq -0x38(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
leaq -0x60(%rbp), %rcx
callq 0x398df
movl %eax, %r13d
testl %eax, %eax
jne 0x39d34
movq -0x60(%rbp), %rsi
movq (%rsi), %rdi
callq 0x3921c
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x39d34
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 0x39d1d
movq %rbx, %rdi
addq $0x40, %rdi
movq 0x48(%r12), %rsi
callq 0x360ae
movq %rbx, %rdi
callq 0x39277
testl %eax, %eax
jne 0x39d34
movq %rbx, %rdi
callq 0x3987a
xorl %r13d, %r13d
movq %r15, %rbx
movq -0x68(%rbp), %r15
jmp 0x39dcd
movl $0x0, -0x48(%rbp)
movl -0x40(%rbp), %eax
testb $0x4, %al
je 0x39d63
movq $0x0, -0x50(%rbp)
movl $0x0, -0x44(%rbp)
andl $-0x5, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, 0x50(%r12)
jne 0x39d89
leaq 0x40(%r12), %rdx
movq %r12, %rdi
leaq -0x7a68(%rip), %rsi     # 0x32312
xorl %ecx, %ecx
callq 0x39a56
testl %eax, %eax
jne 0x39e25
movq %r12, %rdi
leaq -0x7a81(%rip), %rsi     # 0x32312
leaq -0x58(%rbp), %rdx
callq 0x39e2a
testl %eax, %eax
jne 0x39e25
movq 0x48(%r12), %rsi
movl 0x50(%r12), %edx
movq -0x50(%rbp), %rcx
movl -0x48(%rbp), %r8d
movl (%r12), %r9d
movl $0x1, (%rsp)
movq -0x38(%rbp), %rdi
callq 0x38799
movl %eax, %r13d
testl %r13d, %r13d
jne 0x39de9
movq %r12, %rdi
callq 0x39f6b
movq %r14, %r12
testq %r14, %r14
jne 0x39c50
xorl %r13d, %r13d
leaq -0x50(%rbp), %rbx
testb $0x6, 0x10(%rbx)
jne 0x39e06
cmpl $0x0, -0x44(%rbp)
je 0x39e06
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x3503f
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movl $0x0, 0x10(%rbx)
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r13d
jmp 0x39de9