// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: lhash_read_header
static int lhash_read_header(lhash_kv_engine *pEngine,unqlite_page *pHeader)
{
	const unsigned char *zRaw = pHeader->zData;
	lhash_bmap_page *pMap;
	sxu32 nHash;
	int rc;
	pEngine->pHeader = pHeader;
	/* 4 byte magic number */
	SyBigEndianUnpack32(zRaw,&pEngine->nMagic);
	zRaw += 4;
	if( pEngine->nMagic != L_HASH_MAGIC ){
		/* Corrupt implementation */
		return UNQLITE_CORRUPT;
	}
	/* 4 byte hash value to identify a valid hash function */
	SyBigEndianUnpack32(zRaw,&nHash);
	zRaw += 4;
	/* Sanity check */
	if( pEngine->xHash(L_HASH_WORD,sizeof(L_HASH_WORD)-1) != nHash ){
		/* Different hash function */
		pEngine->pIo->xErr(pEngine->pIo->pHandle,"Invalid hash function");
		return UNQLITE_INVALID;
	}
	/* List of free pages */
	SyBigEndianUnpack64(zRaw,&pEngine->nFreeList);
	zRaw += 8;
	/* Current split bucket */
	SyBigEndianUnpack64(zRaw,&pEngine->split_bucket);
	zRaw += 8;
	/* Maximum split bucket */
	SyBigEndianUnpack64(zRaw,&pEngine->max_split_bucket);
	zRaw += 8;
	/* Next generation */
	pEngine->nmax_split_nucket = pEngine->max_split_bucket << 1;
	/* Initialiaze the bucket map */
	pMap = &pEngine->sPageMap;
	/* Fill in the structure */
	pMap->iNum = pHeader->iPage;
	/* Next page in the bucket map */
	SyBigEndianUnpack64(zRaw,&pMap->iNext);
	zRaw += 8;
	/* Total number of records in the bucket map (This page only) */
	SyBigEndianUnpack32(zRaw,&pMap->nRec);
	zRaw += 4;
	pMap->iPtr = (sxu16)(zRaw - pHeader->zData);
	/* Load the map in memory */
	rc = lhMapLoadPage(pEngine,pMap,pHeader->zData);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	/* Load the bucket map chain if any */
	for(;;){
		pgno iNext = pMap->iNext;
		unqlite_page *pPage;
		if( iNext == 0 ){
			/* No more map pages */
			break;
		}
		/* Point to the target page */
		rc = pEngine->pIo->xGet(pEngine->pIo->pHandle,iNext,&pPage);
		if( rc != UNQLITE_OK ){
			return rc;
		}
		/* Fill in the structure */
		pMap->iNum = iNext;
		pMap->iPtr = 0;
		/* Load the map in memory */
		rc = lhMapLoadPage(pEngine,pMap,pPage->zData);
		if( rc != UNQLITE_OK ){
			return rc;
		}
	}
	/* All done */
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xd0(%rax)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x138, %rsi            # imm = 0x138
callq 0x61d60
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0xfa782dcb, 0x138(%rax) # imm = 0xFA782DCB
je 0x619e6
movl $0xffffffe8, -0x4(%rbp) # imm = 0xFFFFFFE8
jmp 0x61be5
movq -0x20(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x61d60
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
leaq 0x6037b(%rip), %rdi     # 0xc1d85
movl $0xa, %esi
callq *0xc0(%rax)
cmpl -0x2c(%rbp), %eax
je 0x61a47
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x80(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
leaq 0x60357(%rip), %rsi     # 0xc1d90
callq *%rax
movl $0xfffffff7, -0x4(%rbp) # imm = 0xFFFFFFF7
jmp 0x61be5
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x118, %rsi            # imm = 0x118
callq 0x61db0
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x120, %rsi            # imm = 0x120
callq 0x61db0
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x128, %rsi            # imm = 0x128
callq 0x61db0
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x128(%rax), %rcx
shlq %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x130(%rax)
movq -0x10(%rbp), %rax
addq $0xf8, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x10, %rsi
callq 0x61db0
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0xc, %rsi
callq 0x61d60
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq (%rax), %rdx
callq 0x61e40
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x61b58
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x61be5
jmp 0x61b5a
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x61b6f
jmp 0x61bde
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
movq -0x38(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq *%rax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x61b9f
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x61be5
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movw $0x0, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rax
movq (%rax), %rdx
callq 0x61e40
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x61bd9
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x61be5
jmp 0x61b5a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop