// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: unqlitePagerBegin
UNQLITE_PRIVATE int unqlitePagerBegin(Pager *pPager)
{
	int rc;
	/* Obtain a shared lock on the database first */
	rc = pager_shared_lock(pPager);
	if( rc != UNQLITE_OK ){
		return rc;
	}
	if( pPager->iState >= PAGER_WRITER_LOCKED ){
		return UNQLITE_OK;
	}
	if( pPager->is_rdonly ){
		unqliteGenError(pPager->pDb,"Read-only database");
		/* Read only database */
		return UNQLITE_READ_ONLY;
	}
	/* Obtain a reserved lock on the database */
	rc = pager_wait_on_lock(pPager,RESERVED_LOCK);
	if( rc == UNQLITE_OK ){
		/* Create the bitvec */
		pPager->pVec = unqliteBitvecCreate(pPager->pAllocator,pPager->dbSize);
		if( pPager->pVec == 0 ){
			unqliteGenOutofMem(pPager->pDb);
			rc = UNQLITE_NOMEM;
			goto fail;
		}
		/* Change to the WRITER_LOCK state */
		pPager->iState = PAGER_WRITER_LOCKED;
		pPager->dbOrigSize = pPager->dbSize;
		pPager->iJournalOfft = 0;
		pPager->nRec = 0;
		if( pPager->dbSize < 1 ){
			/* Write the  database header */
			rc = pager_create_header(pPager);
			if( rc != UNQLITE_OK ){
				goto fail;
			}
			pPager->dbSize = 1;
		}
	}else if( rc == UNQLITE_BUSY ){
		unqliteGenError(pPager->pDb,"Another process or thread have a reserved lock on this database");
	}
	return rc;
fail:
	/* Downgrade to shared lock */
	pager_unlock_db(pPager,SHARED_LOCK);
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x686b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x59f09
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5a050
movq -0x10(%rbp), %rax
cmpl $0x2, 0x1f0(%rax)
jl 0x59f22
movl $0x0, -0x4(%rbp)
jmp 0x5a050
movq -0x10(%rbp), %rax
cmpl $0x0, 0x200(%rax)
je 0x59f4f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6c286(%rip), %rsi     # 0xc61c4
callq 0x58950
movl $0xffffffb5, -0x4(%rbp) # imm = 0xFFFFFFB5
jmp 0x5a050
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x68eb0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x5a018
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0xadf60
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x198(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x198(%rax)
jne 0x59fb3
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x67f90
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x5a03c
movq -0x10(%rbp), %rax
movl $0x2, 0x1f0(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x170(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x60(%rax)
movq -0x10(%rbp), %rax
cmpq $0x1, 0x40(%rax)
jae 0x5a016
movq -0x10(%rbp), %rdi
callq 0xae030
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x5a00a
jmp 0x5a03c
movq -0x10(%rbp), %rax
movq $0x1, 0x40(%rax)
jmp 0x5a034
cmpl $-0xe, -0x14(%rbp)
jne 0x5a032
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6c1aa(%rip), %rsi     # 0xc61d7
callq 0x58950
jmp 0x5a034
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5a050
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x693c0
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)