// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: pager_extract_header
static int pager_extract_header(Pager *pPager,const unsigned char *zRaw,sxu32 nByte)
{
	const unsigned char *zEnd = &zRaw[nByte];
	sxu32 nDos,iMagic;
	sxu16 nLen;
	char *zKv;
	/* Database signature */
	if( SyMemcmp(UNQLITE_DB_SIG,zRaw,sizeof(UNQLITE_DB_SIG)-1) != 0 ){
		/* Corrupt database */
		return UNQLITE_CORRUPT;
	}
	zRaw += sizeof(UNQLITE_DB_SIG)-1;
	/* Database magic number */
	SyBigEndianUnpack32(zRaw,&iMagic);
	zRaw += 4; /* 4 byte magic number */
	if( iMagic != UNQLITE_DB_MAGIC ){
		/* Corrupt database */
		return UNQLITE_CORRUPT;
	}
	/* Database creation time */
	SyBigEndianUnpack32(zRaw,&nDos);
	zRaw += 4; /* 4 byte DOS time format */
	SyDosTimeFormat(nDos,&pPager->tmCreate);
	/* Sector size */
	SyBigEndianUnpack32(zRaw,(sxu32 *)&pPager->iSectorSize);
	zRaw += 4; /* 4 byte sector size */
	/* Page size */
	SyBigEndianUnpack32(zRaw,(sxu32 *)&pPager->iPageSize);
	zRaw += 4; /* 4 byte page size */
	/* Check that the values read from the page-size and sector-size fields
    ** are within range. To be 'in range', both values need to be a power
    ** of two greater than or equal to 512 or 32, and not greater than their 
    ** respective compile time maximum limits.
    */
    if( pPager->iPageSize<UNQLITE_MIN_PAGE_SIZE || pPager->iSectorSize<32
     || pPager->iPageSize>UNQLITE_MAX_PAGE_SIZE || pPager->iSectorSize>MAX_SECTOR_SIZE
     || ((pPager->iPageSize<-1)&pPager->iPageSize)!=0    || ((pPager->iSectorSize-1)&pPager->iSectorSize)!=0 
    ){
      return UNQLITE_CORRUPT;
	}
	/* Key value storage engine */
	SyBigEndianUnpack16(zRaw,&nLen); /* 2 byte storage engine length */
	zRaw += 2;
	if( nLen > (sxu16)(zEnd - zRaw) ){
		nLen = (sxu16)(zEnd - zRaw);
	}
	zKv = (char *)SyMemBackendDup(pPager->pAllocator,(const char *)zRaw,nLen);
	if( zKv == 0 ){
		return UNQLITE_NOMEM;
	}
	SyStringInitFromBuf(&pPager->sKv,zKv,nLen);
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rsi
leaq 0x582c2(%rip), %rdi     # 0xc21be
movl $0x7, %edx
callq 0x5d3c0
cmpl $0x0, %eax
je 0x69f17
movl $0xffffffe8, -0x4(%rbp) # imm = 0xFFFFFFE8
jmp 0x6a0ce
movq -0x18(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x61d60
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
cmpl $0xdb7c2712, -0x30(%rbp) # imm = 0xDB7C2712
je 0x69f51
movl $0xffffffe8, -0x4(%rbp) # imm = 0xFFFFFFE8
jmp 0x6a0ce
movq -0x18(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x61d60
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movl -0x2c(%rbp), %edi
movq -0x10(%rbp), %rsi
addq $0x1a8, %rsi            # imm = 0x1A8
callq 0x6a130
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x20c, %rsi            # imm = 0x20C
callq 0x61d60
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x208, %rsi            # imm = 0x208
callq 0x61d60
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x200, 0x208(%rax)     # imm = 0x200
jl 0x6a038
movq -0x10(%rbp), %rax
cmpl $0x20, 0x20c(%rax)
jl 0x6a038
movq -0x10(%rbp), %rax
cmpl $0x10000, 0x208(%rax)   # imm = 0x10000
jg 0x6a038
movq -0x10(%rbp), %rax
cmpl $0x10000, 0x20c(%rax)   # imm = 0x10000
jg 0x6a038
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x208(%rax)
setl %al
andb $0x1, %al
movzbl %al, %eax
movq -0x10(%rbp), %rcx
andl 0x208(%rcx), %eax
cmpl $0x0, %eax
jne 0x6a038
movq -0x10(%rbp), %rax
movl 0x20c(%rax), %eax
subl $0x1, %eax
movq -0x10(%rbp), %rcx
andl 0x20c(%rcx), %eax
cmpl $0x0, %eax
je 0x6a044
movl $0xffffffe8, -0x4(%rbp) # imm = 0xFFFFFFE8
jmp 0x6a0ce
movq -0x18(%rbp), %rdi
leaq -0x32(%rbp), %rsi
callq 0x64c70
movq -0x18(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x18(%rbp)
movzwl -0x32(%rbp), %eax
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rdx
subq %rdx, %rcx
movzwl %cx, %ecx
cmpl %ecx, %eax
jle 0x6a082
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movw %ax, -0x32(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movzwl -0x32(%rbp), %edx
callq 0x5f650
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x6a0aa
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6a0ce
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x1e0(%rax)
movzwl -0x32(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1e8(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)