// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: CollectionLoadHeader
static int CollectionLoadHeader(unqlite_col *pCol)
{
	SyBlob *pHeader = &pCol->sHeader;
	unsigned char *zRaw,*zEnd;
	sxu16 nMagic;
	sxu32 iDos;
	int rc;
	SyBlobReset(pHeader);
	/* Read the binary header */
	rc = unqlite_kv_cursor_data_callback(pCol->pCursor,unqliteDataConsumer,pHeader);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	/* Perform a sanity check */
	if( SyBlobLength(pHeader) < (2 /* magic */ + 8 /* record_id */ + 8 /* total_records */+ 4 /* DOS creation time*/) ){
		return UNQLITE_CORRUPT;
	}
	zRaw = (unsigned char *)SyBlobData(pHeader);
	zEnd = &zRaw[SyBlobLength(pHeader)];
	/* Extract the magic number */
	SyBigEndianUnpack16(zRaw,&nMagic);
	if( nMagic != UNQLITE_COLLECTION_MAGIC ){
		return UNQLITE_CORRUPT;
	}
	zRaw += 2; /* sizeof(sxu16) */
	/* Extract the record ID */
	SyBigEndianUnpack64(zRaw,(sxu64 *)&pCol->nLastid);
	zRaw += 8; /* sizeof(sxu64) */
	/* Total records in the collection */
	SyBigEndianUnpack64(zRaw,(sxu64 *)&pCol->nTotRec);
	/* Extract the collection creation date (DOS) */
	zRaw += 8; /* sizeof(sxu64) */
	SyBigEndianUnpack32(zRaw,&iDos);
	SyDosTimeFormat(iDos,&pCol->sCreation);
	zRaw += 4;
	/* Check for a collection schema */
	pCol->nSchemaOfft = (sxu32)(zRaw - (unsigned char *)SyBlobData(pHeader));
	if( zRaw < zEnd ){
		/* Decode the FastJson value */
		FastJsonDecode((const void *)zRaw,(sxu32)(zEnd-zRaw),&pCol->sSchema,0,0);
	}
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x88, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x65e00
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movq -0x18(%rbp), %rdx
leaq -0x14be9(%rip), %rsi    # 0x591b0
callq 0x59d10
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x6ddb2
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6ded0
movq -0x18(%rbp), %rax
cmpl $0x16, 0x10(%rax)
jae 0x6ddc8
movl $0xffffffe8, -0x4(%rbp) # imm = 0xFFFFFFE8
jmp 0x6ded0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x2a(%rbp), %rsi
callq 0x64c70
movzwl -0x2a(%rbp), %eax
cmpl $0x611e, %eax           # imm = 0x611E
je 0x6de0a
movl $0xffffffe8, -0x4(%rbp) # imm = 0xFFFFFFE8
jmp 0x6ded0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0xa8, %rsi
callq 0x61db0
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0xb8, %rsi
callq 0x61db0
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x61d60
movl -0x30(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0xe0, %rsi
callq 0x6a130
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x6dec9
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, %esi
movq -0x10(%rbp), %rdx
addq $0x20, %rdx
xorl %eax, %eax
movl %eax, %ecx
xorl %r8d, %r8d
callq 0x6ec70
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)