// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: pager_read_journal_header
static int pager_read_journal_header(
  Pager *pPager,               /* Pager object */
  sxu32 *pNRec,                /* OUT: Value read from the nRec field */
  pgno  *pDbSize               /* OUT: Value of original database size field */
)
{
	sxu32 iPageSize,iSectorSize;
	unsigned char zMagic[8];
	sxi64 iHdrOfft;
	sxi64 iSize;
	int rc;
	/* Offset to start reading from */
	iHdrOfft = 0;
	/* Get the size of the journal */
	rc = unqliteOsFileSize(pPager->pjfd,&iSize);
	if( rc != UNQLITE_OK ){
		return UNQLITE_DONE;
	}
	/* If the journal file is too small, return UNQLITE_DONE. */
	if( 32 /* Minimum sector size */> iSize ){
		return UNQLITE_DONE;
	}
	/* Make sure we are dealing with a valid journal */
	rc = unqliteOsRead(pPager->pjfd,zMagic,sizeof(zMagic),iHdrOfft);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	if( SyMemcmp(zMagic,aJournalMagic,sizeof(zMagic)) != 0 ){
		return UNQLITE_DONE;
	}
	iHdrOfft += sizeof(zMagic);
	 /* Read the first three 32-bit fields of the journal header: The nRec
      ** field, the checksum-initializer and the database size at the start
      ** of the transaction. Return an error code if anything goes wrong.
      */
	rc = ReadInt32(pPager->pjfd,pNRec,iHdrOfft);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	iHdrOfft += 4;
	rc = ReadInt32(pPager->pjfd,&pPager->cksumInit,iHdrOfft);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	iHdrOfft += 4;
	rc = ReadInt64(pPager->pjfd,pDbSize,iHdrOfft);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	iHdrOfft += 8;
	/* Read the page-size and sector-size journal header fields. */
	rc = ReadInt32(pPager->pjfd,&iSectorSize,iHdrOfft);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	iHdrOfft += 4;
	rc = ReadInt32(pPager->pjfd,&iPageSize,iHdrOfft);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	/* 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( iPageSize < UNQLITE_MIN_PAGE_SIZE || iSectorSize<32
     || iPageSize > UNQLITE_MAX_PAGE_SIZE || iSectorSize>MAX_SECTOR_SIZE
     || ((iPageSize-1)&iPageSize)!=0    || ((iSectorSize-1)&iSectorSize)!=0 
    ){
      /* If the either the page-size or sector-size in the journal-header is 
      ** invalid, then the process that wrote the journal-header must have 
      ** crashed before the header was synced. In this case stop reading 
      ** the journal file here.
      */
      return UNQLITE_DONE;
    }
    /* Update the assumed sector-size to match the value used by 
    ** the process that created this journal. If this journal was
    ** created by a process other than this one, then this routine
    ** is being called from within pager_playback(). The local value
    ** of Pager.sectorSize is restored at the end of that routine.
    */
    pPager->iSectorSize = iSectorSize;
	pPager->iPageSize = iPageSize;
	/* Ready to rollback */
	pPager->iJournalOfft = JOURNAL_HDR_SZ(pPager);
	/* All done */
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x698b0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x69922
movl $0xffffffe4, -0x4(%rbp) # imm = 0xFFFFFFE4
jmp 0x69b17
movl $0x20, %eax
cmpq -0x40(%rbp), %rax
jle 0x69939
movl $0xffffffe4, -0x4(%rbp) # imm = 0xFFFFFFE4
jmp 0x69b17
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
leaq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rcx
movl $0x8, %edx
callq 0x69cd0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x69967
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x69b17
leaq -0x30(%rbp), %rdi
leaq 0x57864(%rip), %rsi     # 0xc11d6
movl $0x8, %edx
callq 0x5d3c0
cmpl $0x0, %eax
je 0x6998d
movl $0xffffffe4, -0x4(%rbp) # imm = 0xFFFFFFE4
jmp 0x69b17
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x69d10
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x699c2
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x69b17
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x168, %rsi            # imm = 0x168
movq -0x38(%rbp), %rdx
callq 0x69d10
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x699fe
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x69b17
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x69d70
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x69a33
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x69b17
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x38(%rbp), %rdx
leaq -0x28(%rbp), %rsi
callq 0x69d10
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x69a68
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x69b17
movq -0x38(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x38(%rbp), %rdx
leaq -0x24(%rbp), %rsi
callq 0x69d10
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x69a9a
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x69b17
cmpl $0x200, -0x24(%rbp)     # imm = 0x200
jb 0x69ad7
cmpl $0x20, -0x28(%rbp)
jb 0x69ad7
cmpl $0x10000, -0x24(%rbp)   # imm = 0x10000
ja 0x69ad7
cmpl $0x10000, -0x28(%rbp)   # imm = 0x10000
ja 0x69ad7
movl -0x24(%rbp), %eax
subl $0x1, %eax
andl -0x24(%rbp), %eax
cmpl $0x0, %eax
jne 0x69ad7
movl -0x28(%rbp), %eax
subl $0x1, %eax
andl -0x28(%rbp), %eax
cmpl $0x0, %eax
je 0x69ae0
movl $0xffffffe4, -0x4(%rbp) # imm = 0xFFFFFFE4
jmp 0x69b17
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20c(%rax)
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x208(%rax)
movq -0x10(%rbp), %rax
movslq 0x20c(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x170(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq