// File: /workspace/github_c_makefile_star2_O1/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 %rbx
pushq %rax
movq %rdi, %rbx
callq 0x3b5ca
testl %eax, %eax
je 0x32d17
movl %eax, %r14d
jmp 0x32d42
xorl %r14d, %r14d
cmpl $0x1, 0x1f0(%rbx)
jg 0x32d42
cmpl $0x0, 0x200(%rbx)
je 0x32d50
movq 0x8(%rbx), %rdi
leaq 0x46fa9(%rip), %rsi     # 0x79ce0
callq 0x31af5
movl $0xffffffb5, %r14d      # imm = 0xFFFFFFB5
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movl $0x2, %esi
callq 0x3bdf4
cmpl $-0xe, %eax
je 0x32df5
movl %eax, %r14d
testl %eax, %eax
jne 0x32d42
movq (%rbx), %r15
movq %r15, %rdi
movl $0x20, %esi
callq 0x343ed
testq %rax, %rax
je 0x32e1b
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movl $0x40, 0xc(%rax)
movq %r15, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x343ed
testq %rax, %rax
je 0x32e10
movl 0xc(%r14), %edx
shll $0x3, %edx
testl %edx, %edx
je 0x32dec
movq %rax, %rcx
addq %rdx, %rcx
movq %rax, %rdx
movb $0x0, (%rdx)
incq %rdx
cmpq %rcx, %rdx
jae 0x32dec
movb $0x0, (%rdx)
incq %rdx
cmpq %rcx, %rdx
jae 0x32dec
movb $0x0, (%rdx)
incq %rdx
cmpq %rcx, %rdx
jae 0x32dec
movb $0x0, (%rdx)
incq %rdx
cmpq %rcx, %rdx
jb 0x32dc0
movq %rax, 0x10(%r14)
movq %r15, (%r14)
jmp 0x32e1e
movq 0x8(%rbx), %rdi
leaq 0x46ef3(%rip), %rsi     # 0x79cf3
callq 0x31af5
movl $0xfffffff2, %r14d      # imm = 0xFFFFFFF2
jmp 0x32d42
movq %r15, %rdi
movq %r14, %rsi
callq 0x3503f
xorl %r14d, %r14d
movq %r14, 0x198(%rbx)
testq %r14, %r14
je 0x32e76
movl $0x2, 0x1f0(%rbx)
movq 0x40(%rbx), %rax
movq %rax, 0x48(%rbx)
movq $0x0, 0x170(%rbx)
movl $0x0, 0x60(%rbx)
xorl %r14d, %r14d
testq %rax, %rax
jne 0x32d42
movq %rbx, %rdi
callq 0x67bce
movl %eax, %r15d
testl %eax, %eax
jne 0x32e8c
movq $0x1, 0x40(%rbx)
jmp 0x32d42
movq 0x8(%rbx), %rdi
leaq 0x42b4d(%rip), %rsi     # 0x759ce
callq 0x31af5
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x1f4(%rbx)
je 0x32eae
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x40(%rax)
movl $0x1, 0x1f4(%rbx)
movl %r15d, %r14d
jmp 0x32d42