// File: /workspace/github_c_makefile_star2_O3/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 0x3ad09
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 0x3b3a9
testl %eax, %eax
je 0x3ad1c
movl %eax, %r15d
movq 0x8(%rbx), %rdi
movq 0x18(%rbx), %rdx
leaq 0x38cf8(%rip), %rsi     # 0x739f7
xorl %eax, %eax
callq 0x3a376
movl %r15d, %r14d
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 0x3b475
cmpl $-0xe, %eax
je 0x3ad51
testl %eax, %eax
jne 0x3ad4c
cmpl $0x1, 0x1f4(%rbx)
jg 0x3ad69
movq %rbx, %rdi
movl $0x1, %esi
callq 0x3b4bd
testl %eax, %eax
je 0x3ad69
movl %eax, %r14d
jmp 0x3ad09
movq 0x8(%rbx), %rdi
leaq 0x38d43(%rip), %rsi     # 0x73a9f
callq 0x31537
movl $0xfffffff2, %r14d      # imm = 0xFFFFFFF2
jmp 0x3ad09
leaq -0x28(%rbp), %rsi
movq $0x0, (%rsi)
movq (%r12), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
testl %eax, %eax
je 0x3ad8a
movl %eax, %r15d
jmp 0x3ad06
movq -0x28(%rbp), %rax
movq %rax, 0x50(%rbx)
testq %rax, %rax
jle 0x3adbe
cmpq $0x1ff, %rax            # imm = 0x1FF
ja 0x3ae70
movq 0x8(%rbx), %rdi
leaq 0x38eb8(%rip), %rsi     # 0x73c66
callq 0x31537
movl $0xffffffe8, %r15d      # imm = 0xFFFFFFE8
jmp 0x3ad06
movq (%r12), %rdi
movl $0x200, %eax            # imm = 0x200
testq %rdi, %rdi
je 0x3adef
movq (%rdi), %rcx
movq 0x50(%rcx), %rcx
testq %rcx, %rcx
je 0x3adef
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 0x599bd(%rip), %eax     # 0x947b8
leal -0x10001(%rax), %ecx
cmpl $0xffff01ff, %ecx       # imm = 0xFFFF01FF
movl $0x1000, %esi           # imm = 0x1000
cmovael %eax, %esi
movl %esi, 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 0x3afe2
leaq 0x2(%rax), %rcx
cmpb $0x0, -0x1(%rcx)
je 0x3afda
cmpb $0x0, (%rcx)
je 0x3afe2
cmpb $0x0, 0x1(%rcx)
je 0x3afdf
leaq 0x4(%rcx), %rdx
cmpb $0x0, 0x2(%rcx)
movq %rdx, %rcx
jne 0x3ae3a
addq $-0x2, %rdx
movq %rdx, %rcx
jmp 0x3afe2
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 0x3ae9f
movl %eax, %r15d
movq 0x8(%rbx), %rdi
leaq 0x38de5(%rip), %rsi     # 0x73c7f
jmp 0x3afd0
leaq 0x38e47(%rip), %rdi     # 0x73ced
leaq -0x230(%rbp), %rsi
movl $0x7, %edx
callq 0x347f1
leaq 0x38da8(%rip), %rsi     # 0x73c66
movl $0xffffffe8, %r15d      # imm = 0xFFFFFFE8
testl %eax, %eax
jne 0x3afcc
movl -0x229(%rbp), %eax
bswapl %eax
cmpl $0xdb7c2712, %eax       # imm = 0xDB7C2712
jne 0x3afcc
movzbl -0x222(%rbp), %eax
movzbl -0x223(%rbp), %edx
movl %edx, %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl -0x224(%rbp), %edi
movl %edi, %r8d
shll $0x10, %r8d
movzbl -0x225(%rbp), %r9d
movl %r9d, %r10d
shll $0x18, %r10d
orl %r8d, %r10d
movl $0x0, 0x1c8(%rbx)
shrl %r9d
addl $0x7bc, %r9d            # imm = 0x7BC
movl %r9d, 0x1bc(%rbx)
shrl $0x15, %r10d
andl $0xf, %r10d
movl %r10d, 0x1b8(%rbx)
andl $0x1f, %edi
movl %edi, 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, %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 0x3afcc
leal -0x10001(%rcx), %edi
cmpl $0xffff001f, %edi       # imm = 0xFFFF001F
jb 0x3afcc
cmpl $0x10000, %edx          # imm = 0x10000
ja 0x3afcc
addl $0x1ffff, %eax          # imm = 0x1FFFF
testl %ecx, %eax
je 0x3b115
movq 0x8(%rbx), %rdi
callq 0x31537
jmp 0x3ad06
decq %rcx
jmp 0x3afe2
incq %rcx
subl %eax, %ecx
movl %ecx, 0x1e8(%rbx)
movq $0x0, 0x40(%rbx)
movq (%rbx), %rdi
callq 0x33d86
movq %rax, 0x210(%rbx)
testq %rax, %rax
je 0x3b0fa
movl 0x208(%rbx), %ecx
testq %rcx, %rcx
je 0x3b044
addq %rax, %rcx
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jae 0x3b044
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jae 0x3b044
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jae 0x3b044
movb $0x0, (%rax)
incq %rax
cmpq %rcx, %rax
jb 0x3b018
cmpq $0x0, 0x40(%rbx)
je 0x3b080
testb $0x1, 0x16d(%rbx)
je 0x3b080
leaq 0x50(%rbx), %rdx
movq 0x18(%rbx), %rdi
leaq 0x58(%rbx), %rsi
callq 0x65d7e
testl %eax, %eax
je 0x3b080
movq 0x8(%rbx), %rdi
leaq 0x389b7(%rip), %rsi     # 0x73a2b
callq 0x31537
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 0x3ad09
movq 0x40(%rbx), %rsi
callq *%rax
testl %eax, %eax
je 0x3ad09
movl %eax, %r15d
movq 0x8(%rbx), %rdi
leaq 0x1e0(%rbx), %rdx
leaq 0x389a3(%rip), %rsi     # 0x73a68
xorl %eax, %eax
callq 0x3a376
cmpl $0x0, 0x1f4(%rbx)
je 0x3b0eb
movq 0x30(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x40(%rax)
movl $0x0, 0x1f4(%rbx)
movl $0x0, 0x1f0(%rbx)
jmp 0x3ad06
movq 0x8(%rbx), %rdi
leaq 0x388d1(%rip), %rsi     # 0x739d6
callq 0x31537
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x3ad06
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, %r15d
movl %r15d, %edx
callq 0x35b66
testq %rax, %rax
je 0x3b1ab
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
movl $0x1, %edx
cmovneq %rax, %rdx
testq %rcx, %rcx
cmovleq %rax, %rdx
movq %rdx, 0x40(%rbx)
movl %r15d, %esi
callq 0x39a5b
testq %rax, %rax
je 0x3b1bd
movq %rbx, %rdi
movq %rax, %rsi
callq 0x39cfa
testl %eax, %eax
jne 0x3ad82
movl 0x208(%rbx), %esi
jmp 0x3aff2
leaq 0x38af4(%rip), %rsi     # 0x73ca6
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x3afcc
movq 0x8(%rbx), %rdi
addq $0x1e0, %rbx            # imm = 0x1E0
leaq 0x38af8(%rip), %rsi     # 0x73cc7
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3a376
movl $0xffffffef, %r15d      # imm = 0xFFFFFFEF
jmp 0x3ad06