// File: /workspace/github_c_makefile_star2_O1/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
cmpl $0x0, 0x1f0(%rdi)
je 0x3b5ea
xorl %r14d, %r14d
jmp 0x3b628
movq %rdi, %rbx
movq 0x28(%rdi), %rdi
movq (%rbx), %rsi
movq 0x18(%rbx), %rdx
leaq 0x30(%rbx), %r15
movl 0x16c(%rbx), %r8d
movq %r15, %rcx
callq 0x3bd28
testl %eax, %eax
je 0x3b63b
movl %eax, %r14d
movq 0x8(%rbx), %rdi
movq 0x18(%rbx), %rdx
leaq 0x3a3ce(%rip), %rsi     # 0x759ef
xorl %eax, %eax
callq 0x3ac51
movl %r14d, %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movl $0x1, %esi
callq 0x3bdf4
cmpl $-0xe, %eax
je 0x3b673
movl %eax, %r14d
testl %eax, %eax
jne 0x3b628
cmpl $0x1, 0x1f4(%rbx)
jg 0x3b68b
movq %rbx, %rdi
movl $0x1, %esi
callq 0x3be3c
testl %eax, %eax
je 0x3b68b
movl %eax, %r14d
jmp 0x3b628
movq 0x8(%rbx), %rdi
leaq 0x3a419(%rip), %rsi     # 0x75a97
callq 0x31af5
movl $0xfffffff2, %r14d      # imm = 0xFFFFFFF2
jmp 0x3b628
leaq -0x28(%rbp), %rsi
movq $0x0, (%rsi)
movq (%r15), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movl %eax, %r14d
testl %eax, %eax
je 0x3b772
testl %r14d, %r14d
jne 0x3b628
cmpq $0x0, 0x40(%rbx)
je 0x3b6ef
testb $0x1, 0x16d(%rbx)
je 0x3b6ef
movq 0x18(%rbx), %rdi
leaq 0x58(%rbx), %rsi
leaq 0x50(%rbx), %rdx
callq 0x67942
testl %eax, %eax
je 0x3b6ef
movq 0x8(%rbx), %rdi
leaq 0x3a340(%rip), %rsi     # 0x75a23
callq 0x31af5
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 0x3b5e5
movq 0x40(%rbx), %rsi
callq *%rax
movl $0x0, %r14d
testl %eax, %eax
je 0x3b628
movl %eax, %r15d
movq 0x8(%rbx), %rdi
leaq 0x1e0(%rbx), %rdx
leaq 0x3a326(%rip), %rsi     # 0x75a60
xorl %eax, %eax
callq 0x3ac51
cmpl $0x0, 0x1f4(%rbx)
je 0x3b760
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x40(%rax)
movl $0x0, 0x1f4(%rbx)
movl $0x0, 0x1f0(%rbx)
movl %r15d, %r14d
jmp 0x3b628
movq -0x28(%rbp), %rax
movq %rax, 0x50(%rbx)
testq %rax, %rax
jle 0x3b7a2
cmpq $0x1ff, %rax            # imm = 0x1FF
jg 0x3b7d6
movq 0x8(%rbx), %rdi
leaq 0x3a4cc(%rip), %rsi     # 0x75c5e
callq 0x31af5
movl $0xffffffe8, %r14d      # imm = 0xFFFFFFE8
jmp 0x3ba2e
movq (%r15), %rdi
testq %rdi, %rdi
je 0x3b808
movq (%rdi), %rax
movq 0x50(%rax), %rcx
movl $0x200, %r14d           # imm = 0x200
movl $0x200, %eax            # imm = 0x200
testq %rcx, %rcx
je 0x3b7c3
callq *%rcx
movl $0x10000, %ecx          # imm = 0x10000
cmpl %ecx, %eax
cmovll %eax, %ecx
cmpl $0x20, %eax
cmovll %r14d, %ecx
jmp 0x3b80d
movq (%r15), %rdi
movq (%rdi), %rax
leaq -0x230(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
xorl %ecx, %ecx
callq *0x10(%rax)
testl %eax, %eax
je 0x3b88e
movl %eax, %r14d
movq 0x8(%rbx), %rdi
leaq 0x3a474(%rip), %rsi     # 0x75c77
jmp 0x3ba29
movl $0x200, %ecx            # imm = 0x200
movl %ecx, 0x20c(%rbx)
movl 0x5af9f(%rip), %eax     # 0x967b8
leal -0x10001(%rax), %ecx
cmpl $0xffff01ff, %ecx       # imm = 0xFFFF01FF
movl $0x1000, %ecx           # imm = 0x1000
cmovael %eax, %ecx
movl %ecx, 0x208(%rbx)
movq 0x10(%rbx), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, 0x1e0(%rbx)
cmpb $0x0, (%rax)
movq %rax, %rcx
je 0x3ba3f
leaq 0x2(%rax), %rcx
cmpb $0x0, -0x1(%rcx)
je 0x3ba1d
cmpb $0x0, (%rcx)
je 0x3ba3f
cmpb $0x0, 0x1(%rcx)
je 0x3ba3c
leaq 0x4(%rcx), %rdx
cmpb $0x0, 0x2(%rcx)
movq %rdx, %rcx
jne 0x3b858
addq $-0x2, %rdx
movq %rdx, %rcx
jmp 0x3ba3f
leaq 0x3a450(%rip), %rdi     # 0x75ce5
leaq -0x230(%rbp), %rsi
movl $0x7, %edx
callq 0x34ebe
movl $0xffffffe8, %r14d      # imm = 0xFFFFFFE8
leaq 0x3a3ab(%rip), %r15     # 0x75c5e
testl %eax, %eax
jne 0x3b9bc
movl -0x229(%rbp), %eax
bswapl %eax
cmpl $0xdb7c2712, %eax       # imm = 0xDB7C2712
jne 0x3b9bc
movzbl -0x222(%rbp), %eax
movzbl -0x223(%rbp), %edx
movl %edx, %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl -0x224(%rbp), %esi
movl %esi, %edi
shll $0x10, %edi
movzbl -0x225(%rbp), %r8d
movl %r8d, %r9d
shll $0x18, %r9d
orl %edi, %r9d
movl $0x0, 0x1c8(%rbx)
shrl %r8d
addl $0x7bc, %r8d            # imm = 0x7BC
movl %r8d, 0x1bc(%rbx)
shrl $0x15, %r9d
andl $0xf, %r9d
movl %r9d, 0x1b8(%rbx)
andl $0x1f, %esi
movl %esi, 0x1b4(%rbx)
shrl $0x3, %edx
movl %edx, 0x1b0(%rbx)
shrl $0x5, %ecx
andl $0x3f, %ecx
movl %ecx, 0x1ac(%rbx)
addl %eax, %eax
andl $0x3e, %eax
movl %eax, 0x1a8(%rbx)
movzwl -0x21f(%rbp), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movzbl -0x220(%rbp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl -0x221(%rbp), %edx
shll $0x18, %edx
orl %ecx, %edx
movl %edx, 0x20c(%rbx)
movl -0x21d(%rbp), %esi
bswapl %esi
movl %esi, 0x208(%rbx)
cmpl $0x200, %esi            # imm = 0x200
jl 0x3b9bc
leal -0x10001(%rdx), %edi
xorl %eax, %eax
cmpl $0xffff001f, %edi       # imm = 0xFFFF001F
jb 0x3b9be
cmpl $0x10000, %esi          # imm = 0x10000
jg 0x3b9be
addl $0x1ffff, %ecx          # imm = 0x1FFFF
testl %edx, %ecx
je 0x3bafd
xorl %eax, %eax
testb %al, %al
je 0x3ba22
movq -0x28(%rbp), %rcx
movslq 0x208(%rbx), %rsi
movq %rcx, %rax
cqto
idivq %rsi
testq %rax, %rax
movl $0x1, %edx
cmovneq %rax, %rdx
testq %rcx, %rcx
cmovleq %rax, %rdx
movq %rdx, 0x40(%rbx)
movq 0x1e0(%rbx), %rdi
movl 0x1e8(%rbx), %esi
callq 0x3a34f
testq %rax, %rax
je 0x3bad6
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a5f2
movl %eax, %r14d
testl %eax, %eax
sete %r15b
jmp 0x3ba31
decq %rcx
jmp 0x3ba3f
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x31af5
xorl %r15d, %r15d
testb %r15b, %r15b
je 0x3b6aa
jmp 0x3ba4f
incq %rcx
subl %eax, %ecx
movl %ecx, 0x1e8(%rbx)
movq $0x0, 0x40(%rbx)
movq (%rbx), %rdi
movl 0x208(%rbx), %esi
callq 0x343ed
movq %rax, 0x210(%rbx)
testq %rax, %rax
je 0x3babb
movl 0x208(%rbx), %ecx
xorl %r14d, %r14d
testq %rcx, %rcx
je 0x3b6aa
addq %rax, %rcx
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jae 0x3b6aa
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jae 0x3b6aa
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jae 0x3b6aa
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jb 0x3ba7e
jmp 0x3b6aa
movq 0x8(%rbx), %rdi
leaq 0x39f08(%rip), %rsi     # 0x759ce
callq 0x31af5
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x3b6aa
leaq 0x1e0(%rbx), %rdx
movq 0x8(%rbx), %rdi
leaq 0x3a1d7(%rip), %rsi     # 0x75cbf
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x3ac51
movl $0xffffffef, %r14d      # imm = 0xFFFFFFEF
jmp 0x3ba31
leaq -0x217(%rbp), %rsi
movzwl -0x2(%rsi), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
movl $0x1e7, %edx            # imm = 0x1E7
cmpl %edx, %ecx
cmovael %edx, %eax
movq (%rbx), %rdi
movzwl %ax, %r12d
movl %r12d, %edx
callq 0x36268
xorl %r14d, %r14d
testq %rax, %rax
je 0x3bb45
movq %rax, 0x1e0(%rbx)
movl %r12d, 0x1e8(%rbx)
movb $0x1, %al
jmp 0x3b9be
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x3a14c(%rip), %r15     # 0x75c9e
jmp 0x3b9bc