// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: querySharedCacheTableLock
static int querySharedCacheTableLock(Btree *p, Pgno iTab, u8 eLock){
  BtShared *pBt = p->pBt;
  BtLock *pIter;

  assert( sqlite3BtreeHoldsMutex(p) );
  assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
  assert( p->db!=0 );
  assert( !(p->db->flags&SQLITE_ReadUncommitted)||eLock==WRITE_LOCK||iTab==1 );
  
  /* If requesting a write-lock, then the Btree must have an open write
  ** transaction on this file. And, obviously, for this to be so there 
  ** must be an open write transaction on the file itself.
  */
  assert( eLock==READ_LOCK || (p==pBt->pWriter && p->inTrans==TRANS_WRITE) );
  assert( eLock==READ_LOCK || pBt->inTransaction==TRANS_WRITE );
  
  /* This routine is a no-op if the shared-cache is not enabled */
  if( !p->sharable ){
    return SQLITE_OK;
  }

  /* If some other connection is holding an exclusive lock, the
  ** requested lock may not be obtained.
  */
  if( pBt->pWriter!=p && (pBt->btsFlags & BTS_EXCLUSIVE)!=0 ){
    sqlite3ConnectionBlocked(p->db, pBt->pWriter->db);
    return SQLITE_LOCKED_SHAREDCACHE;
  }

  for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
    /* The condition (pIter->eLock!=eLock) in the following if(...) 
    ** statement is a simplification of:
    **
    **   (eLock==WRITE_LOCK || pIter->eLock==WRITE_LOCK)
    **
    ** since we know that if eLock==WRITE_LOCK, then no other connection
    ** may hold a WRITE_LOCK on any table in this file (since there can
    ** only be a single writer).
    */
    assert( pIter->eLock==READ_LOCK || pIter->eLock==WRITE_LOCK );
    assert( eLock==READ_LOCK || pIter->pBtree==p || pIter->eLock==READ_LOCK);
    if( pIter->pBtree!=p && pIter->iTable==iTab && pIter->eLock!=eLock ){
      sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
      if( eLock==WRITE_LOCK ){
        assert( p==pBt->pWriter );
        pBt->btsFlags |= BTS_PENDING;
      }
      return SQLITE_LOCKED_SHAREDCACHE;
    }
  }
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movb %al, -0x15(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x11(%rax)
jne 0x291b2
movl $0x0, -0x4(%rbp)
jmp 0x2924d
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rax
cmpq -0x10(%rbp), %rax
je 0x291d9
movq -0x20(%rbp), %rax
movzwl 0x26(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x291d9
movl $0x106, -0x4(%rbp)      # imm = 0x106
jmp 0x2924d
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x29246
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpq -0x10(%rbp), %rax
je 0x29236
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x29236
movq -0x28(%rbp), %rax
movzbl 0xc(%rax), %eax
movzbl -0x15(%rbp), %ecx
cmpl %ecx, %eax
je 0x29236
movzbl -0x15(%rbp), %eax
cmpl $0x2, %eax
jne 0x2922d
movq -0x20(%rbp), %rax
movzwl 0x26(%rax), %ecx
orl $0x40, %ecx
movw %cx, 0x26(%rax)
movl $0x106, -0x4(%rbp)      # imm = 0x106
jmp 0x2924d
jmp 0x29238
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x291e5
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)