// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x33073
testl %eax, %eax
je 0x2b44d
movl %eax, %r14d
jmp 0x2b476
xorl %r14d, %r14d
cmpl $0x1, 0x1f0(%rbx)
jg 0x2b476
cmpl $0x0, 0x200(%rbx)
je 0x2b488
movq 0x8(%rbx), %rdi
leaq 0x3c85e(%rip), %rsi     # 0x67ccb
callq 0x2a542
pushq $-0x4b
popq %r14
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x336d2
cmpl $-0xe, %eax
je 0x2b621
testl %eax, %eax
jne 0x2b448
movq (%rbx), %r15
pushq $0x20
popq %rsi
movq %r15, %rdi
callq 0x2ca19
testq %rax, %rax
je 0x2b643
movq %rax, %r12
pushq $0x20
popq %rsi
movq %rax, %rdi
callq 0x27aea
movl $0x40, 0xc(%r12)
movq %r15, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x2ca19
testq %rax, %rax
je 0x2b638
movq %rax, %r13
movl 0xc(%r12), %esi
shll $0x3, %esi
movq %rax, %rdi
callq 0x27aea
movq %r13, 0x10(%r12)
movq %r15, (%r12)
movq %r12, 0x198(%rbx)
movl $0x2, 0x1f0(%rbx)
movq 0x40(%rbx), %rax
movq %rax, 0x48(%rbx)
andq $0x0, 0x170(%rbx)
andl $0x0, 0x60(%rbx)
testq %rax, %rax
jne 0x2b476
movq %rbx, %rdi
xorl %esi, %esi
callq 0x334c4
testq %rax, %rax
je 0x2b654
movq %rax, %r14
movq %rax, 0x1a0(%rbx)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x33528
movq %rbx, %rdi
movq %r14, %rsi
callq 0x340da
movq 0x10(%rbx), %r13
movq 0x1a0(%rbx), %rax
movq (%rax), %r14
leaq 0x38757(%rip), %rdi     # 0x63ccd
pushq $0x7
popq %rdx
movq %r14, %rsi
callq 0x2d3b0
movl $0x12277cdb, 0x7(%r14)  # imm = 0x12277CDB
leaq 0x1a8(%rbx), %r15
pushq $0x38
popq %rsi
movq %r15, %rdi
callq 0x27aea
movq 0x28(%rbx), %rdi
movq 0x48(%rdi), %rax
testq %rax, %rax
je 0x2b5ad
movq %r15, %rsi
callq *%rax
leaq -0x2c(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x359b7
movl (%r12), %eax
bswapl %eax
movl %eax, 0xb(%r14)
movl 0x20c(%rbx), %eax
bswapl %eax
movl %eax, 0xf(%r14)
movl 0x208(%rbx), %eax
bswapl %eax
movl %eax, 0x13(%r14)
movq (%r13), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
callq 0x28e24
movzwl %ax, %edx
rolw $0x8, %ax
movw %ax, 0x17(%r14)
addq $0x19, %r14
movq (%r13), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq %r14, %rsi
callq 0x2d3b0
movq $0x1, 0x40(%rbx)
xorl %r14d, %r14d
jmp 0x2b476
movq 0x8(%rbx), %rdi
leaq 0x3c6b2(%rip), %rsi     # 0x67cde
callq 0x2a542
pushq $-0xe
jmp 0x2b474
movq %r15, %rdi
movq %r12, %rsi
callq 0x2d420
andq $0x0, 0x198(%rbx)
movq 0x8(%rbx), %rdi
callq 0x32825
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x33bcd
pushq $-0x1
jmp 0x2b474