// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: pager_shared_lock
static int pager_shared_lock(Pager *pPager)
{
	int rc = UNQLITE_OK;
	if( pPager->iState == PAGER_OPEN ){
		unqlite_kv_methods *pMethods;
		/* Open the target database */
		rc = unqliteOsOpen(pPager->pVfs,pPager->pAllocator,pPager->zFilename,&pPager->pfd,pPager->iOpenFlags);
		if( rc != UNQLITE_OK ){
			unqliteGenErrorFormat(pPager->pDb,
				"IO error while opening the target database file: %s",pPager->zFilename
				);
			return rc;
		}
		/* Try to obtain a shared lock */
		rc = pager_wait_on_lock(pPager,SHARED_LOCK);
		if( rc == UNQLITE_OK ){
			if( pPager->iLock <= SHARED_LOCK ){
				/* Rollback any hot journal */
				rc = pager_journal_rollback(pPager,1);
				if( rc != UNQLITE_OK ){
					return rc;
				}
			}
			/* Read the database header */
			rc = pager_read_db_header(pPager);
			if( rc != UNQLITE_OK ){
				return rc;
			}
			if(pPager->dbSize > 0 ){
				if( pPager->iOpenFlags & UNQLITE_OPEN_MMAP ){
					const jx9_vfs *pVfs = jx9ExportBuiltinVfs();
					/* Obtain a read-only memory view of the whole file */
					if( pVfs && pVfs->xMmap ){
						int vr;
						vr = pVfs->xMmap(pPager->zFilename,&pPager->pMmap,&pPager->dbByteSize);
						if( vr != JX9_OK ){
							/* Generate a warning */
							unqliteGenError(pPager->pDb,"Cannot obtain a read-only memory view of the target database");
							pPager->iOpenFlags &= ~UNQLITE_OPEN_MMAP;
						}
					}else{
						/* Generate a warning */
						unqliteGenError(pPager->pDb,"Cannot obtain a read-only memory view of the target database");
						pPager->iOpenFlags &= ~UNQLITE_OPEN_MMAP;
					}
				}
			}
			/* Update the pager state */
			pPager->iState = PAGER_READER;
			/* Invoke the xOpen methods if available */
			pMethods = pPager->pEngine->pIo->pMethods;
			if( pMethods->xOpen ){
				rc = pMethods->xOpen(pPager->pEngine,pPager->dbSize);
				if( rc != UNQLITE_OK ){
					unqliteGenErrorFormat(pPager->pDb,
						"xOpen() method of the underlying KV engine '%z' failed",
						&pPager->sKv
						);
					pager_unlock_db(pPager,NO_LOCK);
					pPager->iState = PAGER_OPEN;
					return rc;
				}
			}
		}else if( rc == UNQLITE_BUSY ){
			unqliteGenError(pPager->pDb,"Another process or thread have a reserved or exclusive lock on this database");
		}		
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1f0(%rax)
jne 0x6891e
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x10(%rbp), %rcx
addq $0x30, %rcx
movq -0x10(%rbp), %rax
movl 0x16c(%rax), %r8d
callq 0x68de0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x68735
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x597a5(%rip), %rsi     # 0xc1ec8
movb $0x0, %al
callq 0x68100
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x68924
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x68eb0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x68900
movq -0x10(%rbp), %rax
cmpl $0x1, 0x1f4(%rax)
jg 0x68781
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x68f20
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x6877f
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x68924
jmp 0x68781
movq -0x10(%rbp), %rdi
callq 0x690b0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x6879e
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x68924
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jbe 0x6886b
movq -0x10(%rbp), %rax
movl 0x16c(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x68869
callq 0x5a4c0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6883d
movq -0x28(%rbp), %rax
cmpq $0x0, 0x108(%rax)
je 0x6883d
movq -0x28(%rbp), %rax
movq 0x108(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rdi
movq -0x10(%rbp), %rsi
addq $0x58, %rsi
movq -0x10(%rbp), %rdx
addq $0x50, %rdx
callq *%rax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x6883b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x596dc(%rip), %rsi     # 0xc1efc
callq 0x58950
movq -0x10(%rbp), %rax
movl 0x16c(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
movl %ecx, 0x16c(%rax)
jmp 0x68867
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x596b0(%rip), %rsi     # 0xc1efc
callq 0x58950
movq -0x10(%rbp), %rax
movl 0x16c(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
movl %ecx, 0x16c(%rax)
jmp 0x68869
jmp 0x6886b
movq -0x10(%rbp), %rax
movl $0x1, 0x1f0(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x688fe
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rdi
movq -0x10(%rbp), %rcx
movq 0x40(%rcx), %rsi
callq *%rax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x688fc
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x1e0, %rdx            # imm = 0x1E0
leaq 0x59665(%rip), %rsi     # 0xc1f39
movb $0x0, %al
callq 0x68100
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x693c0
movq -0x10(%rbp), %rax
movl $0x0, 0x1f0(%rax)
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x68924
jmp 0x688fe
jmp 0x6891c
cmpl $-0xe, -0x14(%rbp)
jne 0x6891a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x5965b(%rip), %rsi     # 0xc1f70
callq 0x58950
jmp 0x6891c
jmp 0x6891e
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)