// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %r14
callq 0x3acaa
testl %eax, %eax
je 0x326e0
movl %eax, %ebx
jmp 0x3270b
xorl %ebx, %ebx
cmpl $0x1, 0x1f0(%r14)
jg 0x3270b
cmpl $0x0, 0x200(%r14)
je 0x32716
movq 0x8(%r14), %rdi
leaq 0x455ea(%rip), %rsi     # 0x77ceb
callq 0x31537
movl $0xffffffb5, %ebx       # imm = 0xFFFFFFB5
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movl $0x2, %esi
callq 0x3b475
cmpl $-0xe, %eax
je 0x3280c
testl %eax, %eax
jne 0x326dc
movq (%r14), %r15
movq %r15, %rdi
movl $0x20, %esi
callq 0x33d86
testq %rax, %rax
je 0x32831
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movl $0x40, 0xc(%rax)
movq %r15, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x33d86
testq %rax, %rax
je 0x32826
movl 0xc(%r12), %edx
shll $0x3, %edx
testl %edx, %edx
je 0x327b4
movq %rax, %rcx
addq %rdx, %rcx
movq %rax, %rdx
movb $0x0, (%rdx)
incq %rdx
cmpq %rcx, %rdx
jae 0x327b4
movb $0x0, (%rdx)
incq %rdx
cmpq %rcx, %rdx
jae 0x327b4
movb $0x0, (%rdx)
incq %rdx
cmpq %rcx, %rdx
jae 0x327b4
movb $0x0, (%rdx)
incq %rdx
cmpq %rcx, %rdx
jb 0x32788
movq %rax, 0x10(%r12)
movq %r15, (%r12)
movq %r12, 0x198(%r14)
movl $0x2, 0x1f0(%r14)
movq 0x40(%r14), %rax
movq %rax, 0x48(%r14)
movq $0x0, 0x170(%r14)
movl $0x0, 0x60(%r14)
testq %rax, %rax
jne 0x3270b
movq %r14, %rdi
callq 0x6600a
testl %eax, %eax
jne 0x3284c
movq $0x1, 0x40(%r14)
jmp 0x3270b
movq 0x8(%r14), %rdi
leaq 0x454e7(%rip), %rsi     # 0x77cfe
callq 0x31537
movl $0xfffffff2, %ebx       # imm = 0xFFFFFFF2
jmp 0x3270b
movq %r15, %rdi
movq %r12, %rsi
callq 0x3490d
movq $0x0, 0x198(%r14)
movq 0x8(%r14), %rdi
leaq 0x4118f(%rip), %rsi     # 0x739d6
callq 0x31537
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x0, 0x1f4(%r14)
je 0x3270b
movq 0x30(%r14), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x40(%rax)
movl $0x1, 0x1f4(%r14)
jmp 0x3270b