// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqliteOpenJournal
static int unqliteOpenJournal(Pager *pPager)
{
	unsigned char *zHeader;
	int rc = UNQLITE_OK;
	if( pPager->is_mem || pPager->no_jrnl ){
		/* Journaling is omitted for this database */
		goto finish;
	}
	if( pPager->iState >= PAGER_WRITER_CACHEMOD ){
		/* Already opened */
		return UNQLITE_OK;
	}
	/* Delete any previously journal with the same name */
	unqliteOsDelete(pPager->pVfs,pPager->zJournal,1);
	/* Open the journal file */
	rc = unqliteOsOpen(pPager->pVfs,pPager->pAllocator,pPager->zJournal,
		&pPager->pjfd,UNQLITE_OPEN_CREATE|UNQLITE_OPEN_READWRITE);
	if( rc != UNQLITE_OK ){
		unqliteGenErrorFormat(pPager->pDb,"IO error while opening journal file: %s",pPager->zJournal);
		return rc;
	}
	/* Write the journal header */
	zHeader = (unsigned char *)SyMemBackendAlloc(pPager->pAllocator,(sxu32)pPager->iSectorSize);
	if( zHeader == 0 ){
		rc = UNQLITE_NOMEM;
		goto fail;
	}
	pager_write_journal_header(pPager,zHeader);
	/* Perform the disk write */
	rc = unqliteOsWrite(pPager->pjfd,zHeader,pPager->iSectorSize,0);
	/* Offset to start writing from */
	pPager->iJournalOfft = pPager->iSectorSize;
	/* All done, journal will be synced later */
	SyMemBackendFree(pPager->pAllocator,zHeader);
finish:
	if( rc == UNQLITE_OK ){
		pPager->iState = PAGER_WRITER_CACHEMOD;
		return UNQLITE_OK;
	}
fail:
	/* Unlink the journal file if something goes wrong */
	unqliteOsCloseFree(pPager->pAllocator,pPager->pjfd);
	unqliteOsDelete(pPager->pVfs,pPager->zJournal,0);
	pPager->pjfd = 0;
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1fc(%rax)
jne 0x6a33d
movq -0x10(%rbp), %rax
cmpl $0x0, 0x204(%rax)
je 0x6a342
jmp 0x6a451
movq -0x10(%rbp), %rax
cmpl $0x3, 0x1f0(%rax)
jl 0x6a35b
movl $0x0, -0x4(%rbp)
jmp 0x6a4ad
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movl $0x1, %edx
callq 0x69810
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x10(%rbp), %rcx
addq $0x38, %rcx
movl $0x6, %r8d
callq 0x68de0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x6a3d1
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0x57e21(%rip), %rsi     # 0xc21e0
movb $0x0, %al
callq 0x68100
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6a4ad
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x20c(%rax), %esi
callq 0x5bf70
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x6a3fb
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x6a470
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6a800
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movslq 0x20c(%rax), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x69e30
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movslq 0x20c(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x170(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x5d6b0
cmpl $0x0, -0x1c(%rbp)
jne 0x6a46e
movq -0x10(%rbp), %rax
movl $0x3, 0x1f0(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x6a4ad
jmp 0x6a470
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x697c0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
xorl %edx, %edx
callq 0x69810
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)