// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rsi
addq $0x8, %rsi
leaq -0x50(%rbp), %rdi
callq 0x58bb0
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x65bb4
jmp 0x65cad
movq -0x28(%rbp), %rax
movl (%rax), %eax
andq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x65ca0
movl $0x0, -0x5c(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x65c03
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x65cd0
movl %eax, -0x5c(%rbp)
jmp 0x65c8f
leaq -0x50(%rbp), %rdi
callq 0x65e00
movq -0x28(%rbp), %rax
cmpl $0x1, 0x50(%rax)
jae 0x65c3d
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rdx
addq $0x40, %rdx
leaq -0xca79(%rip), %rsi     # 0x591b0
xorl %ecx, %ecx
callq 0x655d0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x65c3b
jmp 0x65cb4
jmp 0x65c3d
movq -0x28(%rbp), %rdi
leaq -0xca98(%rip), %rsi     # 0x591b0
leaq -0x50(%rbp), %rdx
callq 0x65e50
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x65c5c
jmp 0x65cb4
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rsi
movq -0x28(%rbp), %rax
movl 0x50(%rax), %edx
movq -0x48(%rbp), %rcx
movl -0x40(%rbp), %eax
movl %eax, %r8d
movq -0x28(%rbp), %rax
movl (%rax), %r9d
movl $0x1, (%rsp)
callq 0x628e0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x65c97
jmp 0x65cb4
movq -0x28(%rbp), %rdi
callq 0x66090
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x65ba8
movl $0x0, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x58c00
movl -0x5c(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)