// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: pager_commit_phase1
static int pager_commit_phase1(Pager *pPager)
{
	int get_excl = 0;
	Page *pDirty;
	int rc;
	/* If no database changes have been made, return early. */
	if( pPager->iState < PAGER_WRITER_CACHEMOD ){
		return UNQLITE_OK;
	}
	if( pPager->is_mem ){
		/* An in-memory database */
		return UNQLITE_OK;
	}
	if( pPager->is_rdonly ){
		/* Read-Only DB */
		unqliteGenError(pPager->pDb,"Read-Only database");
		return UNQLITE_READ_ONLY;
	}
	/* Finalize the journal file */
	rc = unqliteFinalizeJournal(pPager,&get_excl,1);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	/* Get the dirty pages */
	pDirty = pager_get_dirty_pages(pPager);
	if( get_excl ){
		/* Wait one last time for the exclusive lock */
		rc = pager_wait_on_lock(pPager,EXCLUSIVE_LOCK);
		if( rc != UNQLITE_OK ){
			unqliteGenError(pPager->pDb,"Cannot obtain an Exclusive lock on the target database");
			return rc;
		}
	}
	if( pPager->iFlags & PAGER_CTRL_DIRTY_COMMIT ){
		/* Synce the database first if a dirty commit have been applied */
		unqliteOsSync(pPager->pfd,UNQLITE_SYNC_NORMAL);
	}
	/* Write the dirty pages */
	rc = pager_write_dirty_pages(pPager,pDirty);
	if( rc != UNQLITE_OK ){
		/* Rollback your DB */
		pPager->iFlags |= PAGER_CTRL_COMMIT_ERR;
		pPager->pFirstDirty = pDirty;
		unqliteGenError(pPager->pDb,"IO error while writing dirty pages, rollback your database");
		return rc;
	}
	/* If the file on disk is not the same size as the database image,
     * then use unqliteOsTruncate to grow or shrink the file here.
     */
	if( pPager->dbSize != pPager->dbOrigSize ){
		unqliteOsTruncate(pPager->pfd,pPager->iPageSize * pPager->dbSize);
	}
	/* Sync the database file */
	unqliteOsSync(pPager->pfd,UNQLITE_SYNC_FULL);
	/* Remove stale flags */
	pPager->iJournalOfft = 0;
	pPager->nRec = 0;
	return UNQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x3, 0x1f0(%rax)
jge 0xae25c
movl $0x0, -0x4(%rbp)
jmp 0xae3f1
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1fc(%rax)
je 0xae275
movl $0x0, -0x4(%rbp)
jmp 0xae3f1
movq -0x10(%rbp), %rax
cmpl $0x0, 0x200(%rax)
je 0xae2a2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x17f86(%rip), %rsi     # 0xc6217
callq 0x58950
movl $0xffffffb5, -0x4(%rbp) # imm = 0xFFFFFFB5
jmp 0xae3f1
movq -0x10(%rbp), %rdi
leaq -0x14(%rbp), %rsi
movl $0x1, %edx
callq 0x6a8d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xae2c8
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xae3f1
movq -0x10(%rbp), %rdi
callq 0xae4d0
movq %rax, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0xae313
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x68eb0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xae311
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x17f29(%rip), %rsi     # 0xc622a
callq 0x58950
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xae3f1
jmp 0xae313
movq -0x10(%rbp), %rax
movl 0x1f8(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xae337
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movl $0x2, %esi
callq 0x695e0
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xae690
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xae38b
movq -0x10(%rbp), %rax
movl 0x1f8(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x1f8(%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x218(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x17ee3(%rip), %rsi     # 0xc6261
callq 0x58950
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xae3f1
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
je 0xae3be
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x208(%rax), %rsi
movq -0x10(%rbp), %rax
imulq 0x40(%rax), %rsi
callq 0x69b20
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movl $0x3, %esi
callq 0x695e0
movq -0x10(%rbp), %rax
movq $0x0, 0x170(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x60(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)