// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x210, %rsp            # imm = 0x210
xorl %r14d, %r14d
cmpl $0x0, 0x1f0(%rdi)
jne 0x330d2
movq %rdi, %rbx
movq 0x28(%rdi), %rdi
movq (%rbx), %rsi
movq 0x18(%rbx), %rdx
leaq 0x30(%rbx), %r12
movl 0x16c(%rbx), %r8d
movq %r12, %rcx
callq 0x33642
testl %eax, %eax
je 0x330e5
movl %eax, %r15d
movq 0x8(%rbx), %rdi
movq 0x18(%rbx), %rdx
leaq 0x3090f(%rip), %rsi     # 0x639d7
xorl %eax, %eax
callq 0x32836
movl %r15d, %r14d
movl %r14d, %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x336d2
cmpl $-0xe, %eax
je 0x33116
testl %eax, %eax
jne 0x33111
cmpl $0x1, 0x1f4(%rbx)
jg 0x3312c
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x3371a
testl %eax, %eax
je 0x3312c
movl %eax, %r14d
jmp 0x330d2
movq 0x8(%rbx), %rdi
leaq 0x3095e(%rip), %rsi     # 0x63a7f
callq 0x2a542
pushq $-0xe
popq %r14
jmp 0x330d2
leaq -0x28(%rbp), %rsi
andq $0x0, (%rsi)
movq (%r12), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
testl %eax, %eax
je 0x33147
movl %eax, %r15d
jmp 0x330cf
movq -0x28(%rbp), %rax
movq %rax, 0x50(%rbx)
testq %rax, %rax
jle 0x33179
cmpq $0x1ff, %rax            # imm = 0x1FF
ja 0x332bf
movq 0x8(%rbx), %rdi
leaq 0x30adb(%rip), %rsi     # 0x63c46
callq 0x2a542
pushq $-0x18
popq %r15
jmp 0x330cf
movq (%r12), %rdi
movl $0x200, %eax            # imm = 0x200
testq %rdi, %rdi
je 0x331aa
movq (%rdi), %rcx
movq 0x50(%rcx), %rcx
testq %rcx, %rcx
je 0x331aa
callq *%rcx
movl $0x10000, %ecx          # imm = 0x10000
cmpl %ecx, %eax
cmovbl %eax, %ecx
cmpl $0x20, %eax
movl $0x200, %eax            # imm = 0x200
cmovgel %ecx, %eax
movl %eax, 0x20c(%rbx)
movl 0x54622(%rip), %eax     # 0x877d8
leal -0x10001(%rax), %ecx
cmpl $0xffff01ff, %ecx       # imm = 0xFFFF01FF
movl $0x1000, %r15d          # imm = 0x1000
cmovael %eax, %r15d
movl %r15d, 0x208(%rbx)
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq %rdi, 0x1e0(%rbx)
callq 0x28e24
movl %eax, 0x1e8(%rbx)
andq $0x0, 0x40(%rbx)
movq (%rbx), %rdi
movl %r15d, %esi
callq 0x2ca19
movq %rax, 0x210(%rbx)
testq %rax, %rax
je 0x332ee
movl 0x208(%rbx), %esi
movq %rax, %rdi
callq 0x27aea
cmpq $0x0, 0x40(%rbx)
je 0x3325d
testb $0x1, 0x16d(%rbx)
je 0x3325d
leaq 0x50(%rbx), %rdx
movq 0x18(%rbx), %rdi
leaq 0x58(%rbx), %rsi
callq 0x5734a
testl %eax, %eax
je 0x3325d
movq 0x8(%rbx), %rdi
leaq 0x307ba(%rip), %rsi     # 0x63a0b
callq 0x2a542
andb $-0x2, 0x16d(%rbx)
movl $0x1, 0x1f0(%rbx)
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
movq 0x30(%rax), %rax
testq %rax, %rax
je 0x330d2
movq 0x40(%rbx), %rsi
callq *%rax
testl %eax, %eax
je 0x330d2
movl %eax, %r15d
movq 0x8(%rbx), %rdi
leaq 0x1e0(%rbx), %rdx
leaq 0x307a6(%rip), %rsi     # 0x63a48
xorl %eax, %eax
callq 0x32836
movq %rbx, %rdi
xorl %esi, %esi
callq 0x33bcd
andl $0x0, 0x1f0(%rbx)
jmp 0x330cf
movq (%r12), %rdi
movq (%rdi), %rax
leaq -0x230(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
xorl %ecx, %ecx
callq *0x10(%rax)
testl %eax, %eax
je 0x33300
movl %eax, %r15d
movq 0x8(%rbx), %rdi
leaq 0x30976(%rip), %rsi     # 0x63c5f
jmp 0x333b4
pushq $-0x1
popq %r15
movq 0x8(%rbx), %rdi
callq 0x32825
jmp 0x330cf
leaq 0x309c6(%rip), %rdi     # 0x63ccd
leaq -0x230(%rbp), %rsi
pushq $0x7
popq %rdx
callq 0x2d30e
leaq 0x30929(%rip), %r12     # 0x63c46
pushq $-0x18
popq %r15
testl %eax, %eax
jne 0x333ad
movl -0x229(%rbp), %eax
bswapl %eax
cmpl $0xdb7c2712, %eax       # imm = 0xDB7C2712
jne 0x333ad
movl -0x225(%rbp), %edi
bswapl %edi
leaq 0x1a8(%rbx), %rsi
callq 0x33d2b
movzwl -0x21f(%rbp), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
movzbl -0x220(%rbp), %eax
shll $0x10, %eax
orl %ecx, %eax
movzbl -0x221(%rbp), %ecx
shll $0x18, %ecx
orl %eax, %ecx
movl %ecx, 0x20c(%rbx)
movl -0x21d(%rbp), %edx
bswapl %edx
movl %edx, 0x208(%rbx)
cmpl $0x200, %edx            # imm = 0x200
jl 0x333ad
leal -0x10001(%rcx), %esi
cmpl $0xffff001f, %esi       # imm = 0xFFFF001F
jb 0x333ad
cmpl $0x10000, %edx          # imm = 0x10000
ja 0x333ad
addl $0x1ffff, %eax          # imm = 0x1FFFF
testl %ecx, %eax
je 0x333be
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x2a542
jmp 0x330cf
leaq -0x217(%rbp), %rsi
movzwl -0x2(%rsi), %eax
rolw $0x8, %ax
cmpw $0x1e7, %ax             # imm = 0x1E7
movl $0x1e7, %ecx            # imm = 0x1E7
cmovbl %eax, %ecx
movq (%rbx), %rdi
movzwl %cx, %r15d
movl %r15d, %edx
callq 0x2e418
testq %rax, %rax
je 0x33452
movq %rax, %rdi
movq %rax, 0x1e0(%rbx)
movl %r15d, 0x1e8(%rbx)
movq -0x28(%rbp), %rcx
movslq 0x208(%rbx), %rsi
movq %rcx, %rax
cqto
idivq %rsi
testq %rax, %rax
pushq $0x1
popq %rdx
cmovneq %rax, %rdx
testq %rcx, %rcx
cmovleq %rax, %rdx
movq %rdx, 0x40(%rbx)
movl %r15d, %esi
callq 0x32082
testq %rax, %rax
je 0x33462
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3223e
testl %eax, %eax
jne 0x33142
movl 0x208(%rbx), %r15d
jmp 0x331f8
leaq 0x3082d(%rip), %r12     # 0x63c86
pushq $-0x1
popq %r15
jmp 0x333ad
movq 0x8(%rbx), %rdi
addq $0x1e0, %rbx            # imm = 0x1E0
leaq 0x30833(%rip), %rsi     # 0x63ca7
movq %rbx, %rdx
xorl %eax, %eax
callq 0x32836
pushq $-0x11
jmp 0x33172