// File: /workspace/github_c_makefile_star2_O2/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: sqlite3_blob_open
SQLITE_STDCALL sqlite3_blob_open(
  sqlite3* db,            /* The database connection */
  const char *zDb,        /* The attached database containing the blob */
  const char *zTable,     /* The table containing the blob */
  const char *zColumn,    /* The column containing the blob */
  sqlite_int64 iRow,      /* The row containing the glob */
  int flags,              /* True -> read/write access, false -> read-only */
  sqlite3_blob **ppBlob   /* Handle for accessing the blob returned here */
){
  int nAttempt = 0;
  int iCol;               /* Index of zColumn in row-record */

  /* This VDBE program seeks a btree cursor to the identified 
  ** db/table/row entry. The reason for using a vdbe program instead
  ** of writing code to use the b-tree layer directly is that the
  ** vdbe program will take advantage of the various transaction,
  ** locking and error handling infrastructure built into the vdbe.
  **
  ** After seeking the cursor, the vdbe executes an OP_ResultRow.
  ** Code external to the Vdbe then "borrows" the b-tree cursor and
  ** uses it to implement the blob_read(), blob_write() and 
  ** blob_bytes() functions.
  **
  ** The sqlite3_blob_close() function finalizes the vdbe program,
  ** which closes the b-tree cursor and (possibly) commits the 
  ** transaction.
  */
  static const int iLn = VDBE_OFFSET_LINENO(4);
  static const VdbeOpList openBlob[] = {
    /* {OP_Transaction, 0, 0, 0},  // 0: Inserted separately */
    {OP_TableLock, 0, 0, 0},       /* 1: Acquire a read or write lock */
    /* One of the following two instructions is replaced by an OP_Noop. */
    {OP_OpenRead, 0, 0, 0},        /* 2: Open cursor 0 for reading */
    {OP_OpenWrite, 0, 0, 0},       /* 3: Open cursor 0 for read/write */
    {OP_Variable, 1, 1, 1},        /* 4: Push the rowid to the stack */
    {OP_NotExists, 0, 10, 1},      /* 5: Seek the cursor */
    {OP_Column, 0, 0, 1},          /* 6  */
    {OP_ResultRow, 1, 0, 0},       /* 7  */
    {OP_Goto, 0, 4, 0},            /* 8  */
    {OP_Close, 0, 0, 0},           /* 9  */
    {OP_Halt, 0, 0, 0},            /* 10 */
  };

  int rc = SQLITE_OK;
  char *zErr = 0;
  Table *pTab;
  Parse *pParse = 0;
  Incrblob *pBlob = 0;

#ifdef SQLITE_ENABLE_API_ARMOR
  if( ppBlob==0 ){
    return SQLITE_MISUSE_BKPT;
  }
#endif
  *ppBlob = 0;
#ifdef SQLITE_ENABLE_API_ARMOR
  if( !sqlite3SafetyCheckOk(db) || zTable==0 ){
    return SQLITE_MISUSE_BKPT;
  }
#endif
  flags = !!flags;                /* flags = (flags ? 1 : 0); */

  sqlite3_mutex_enter(db->mutex);

  pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
  if( !pBlob ) goto blob_open_out;
  pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
  if( !pParse ) goto blob_open_out;

  do {
    memset(pParse, 0, sizeof(Parse));
    pParse->db = db;
    sqlite3DbFree(db, zErr);
    zErr = 0;

    sqlite3BtreeEnterAll(db);
    pTab = sqlite3LocateTable(pParse, 0, zTable, zDb);
    if( pTab && IsVirtual(pTab) ){
      pTab = 0;
      sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
    }
    if( pTab && !HasRowid(pTab) ){
      pTab = 0;
      sqlite3ErrorMsg(pParse, "cannot open table without rowid: %s", zTable);
    }
#ifndef SQLITE_OMIT_VIEW
    if( pTab && pTab->pSelect ){
      pTab = 0;
      sqlite3ErrorMsg(pParse, "cannot open view: %s", zTable);
    }
#endif
    if( !pTab ){
      if( pParse->zErrMsg ){
        sqlite3DbFree(db, zErr);
        zErr = pParse->zErrMsg;
        pParse->zErrMsg = 0;
      }
      rc = SQLITE_ERROR;
      sqlite3BtreeLeaveAll(db);
      goto blob_open_out;
    }

    /* Now search pTab for the exact column. */
    for(iCol=0; iCol<pTab->nCol; iCol++) {
      if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
        break;
      }
    }
    if( iCol==pTab->nCol ){
      sqlite3DbFree(db, zErr);
      zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
      rc = SQLITE_ERROR;
      sqlite3BtreeLeaveAll(db);
      goto blob_open_out;
    }

    /* If the value is being opened for writing, check that the
    ** column is not indexed, and that it is not part of a foreign key. 
    ** It is against the rules to open a column to which either of these
    ** descriptions applies for writing.  */
    if( flags ){
      const char *zFault = 0;
      Index *pIdx;
#ifndef SQLITE_OMIT_FOREIGN_KEY
      if( db->flags&SQLITE_ForeignKeys ){
        /* Check that the column is not part of an FK child key definition. It
        ** is not necessary to check if it is part of a parent key, as parent
        ** key columns must be indexed. The check below will pick up this 
        ** case.  */
        FKey *pFKey;
        for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
          int j;
          for(j=0; j<pFKey->nCol; j++){
            if( pFKey->aCol[j].iFrom==iCol ){
              zFault = "foreign key";
            }
          }
        }
      }
#endif
      for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
        int j;
        for(j=0; j<pIdx->nKeyCol; j++){
          /* FIXME: Be smarter about indexes that use expressions */
          if( pIdx->aiColumn[j]==iCol || pIdx->aiColumn[j]==XN_EXPR ){
            zFault = "indexed";
          }
        }
      }
      if( zFault ){
        sqlite3DbFree(db, zErr);
        zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
        rc = SQLITE_ERROR;
        sqlite3BtreeLeaveAll(db);
        goto blob_open_out;
      }
    }

    pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse);
    assert( pBlob->pStmt || db->mallocFailed );
    if( pBlob->pStmt ){
      Vdbe *v = (Vdbe *)pBlob->pStmt;
      int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);


      sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags, 
                           pTab->pSchema->schema_cookie,
                           pTab->pSchema->iGeneration);
      sqlite3VdbeChangeP5(v, 1);     
      sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);

      /* Make sure a mutex is held on the table to be accessed */
      sqlite3VdbeUsesBtree(v, iDb); 

      /* Configure the OP_TableLock instruction */
#ifdef SQLITE_OMIT_SHARED_CACHE
      sqlite3VdbeChangeToNoop(v, 1);
#else
      sqlite3VdbeChangeP1(v, 1, iDb);
      sqlite3VdbeChangeP2(v, 1, pTab->tnum);
      sqlite3VdbeChangeP3(v, 1, flags);
      sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
#endif

      /* Remove either the OP_OpenWrite or OpenRead. Set the P2 
      ** parameter of the other to pTab->tnum.  */
      sqlite3VdbeChangeToNoop(v, 3 - flags);
      sqlite3VdbeChangeP2(v, 2 + flags, pTab->tnum);
      sqlite3VdbeChangeP3(v, 2 + flags, iDb);

      /* Configure the number of columns. Configure the cursor to
      ** think that the table has one more column than it really
      ** does. An OP_Column to retrieve this imaginary column will
      ** always return an SQL NULL. This is useful because it means
      ** we can invoke OP_Column to fill in the vdbe cursors type 
      ** and offset cache without causing any IO.
      */
      sqlite3VdbeChangeP4(v, 2+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
      sqlite3VdbeChangeP2(v, 6, pTab->nCol);
      if( !db->mallocFailed ){
        pParse->nVar = 1;
        pParse->nMem = 1;
        pParse->nTab = 1;
        sqlite3VdbeMakeReady(v, pParse);
      }
    }
   
    pBlob->flags = flags;
    pBlob->iCol = iCol;
    pBlob->db = db;
    sqlite3BtreeLeaveAll(db);
    if( db->mallocFailed ){
      goto blob_open_out;
    }
    sqlite3_bind_int64(pBlob->pStmt, 1, iRow);
    rc = blobSeekToRow(pBlob, iRow, &zErr);
  } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA );

blob_open_out:
  if( rc==SQLITE_OK && db->mallocFailed==0 ){
    *ppBlob = (sqlite3_blob *)pBlob;
  }else{
    if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
    sqlite3DbFree(db, pBlob);
  }
  sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
  sqlite3DbFree(db, zErr);
  sqlite3ParserReset(pParse);
  sqlite3StackFree(db, pParse);
  rc = sqlite3ApiExit(db, rc);
  sqlite3_mutex_leave(db->mutex);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, -0x90(%rbp)
movq %rcx, -0x80(%rbp)
movq %rdx, -0x78(%rbp)
movq %rsi, -0x98(%rbp)
movq %rdi, %r14
movq 0x10(%rbp), %r12
andq $0x0, -0x48(%rbp)
andq $0x0, (%r12)
movl $0x0, -0x30(%rbp)
movl %r9d, -0x4c(%rbp)
testl %r9d, %r9d
setne %bl
movq 0x18(%rdi), %rdi
testq %rdi, %rdi
je 0x12d8e
callq *0x7071a(%rip)          # 0x834a8
pushq $0x28
popq %rsi
movq %r14, %rdi
callq 0x12153
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x1316b
movl $0x290, %esi            # imm = 0x290
movq %r14, %rdi
callq 0x132c5
testq %rax, %rax
je 0x1316b
movq %rax, %rdx
movl -0x30(%rbp), %eax
movb %bl, %al
movl %eax, -0x30(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x4c(%rbp)
setne %al
movl %eax, %ecx
xorl $0x3, %ecx
movl %ecx, -0x5c(%rbp)
orl $0x2, %eax
movl %eax, -0x60(%rbp)
movq %rdx, -0x40(%rbp)
addq $0x8, %rdx
movq %rdx, -0x88(%rbp)
leaq 0x5b670(%rip), %r12     # 0x6e464
leaq 0x5931e(%rip), %r13     # 0x6c119
movl $0x0, -0x50(%rbp)
xorl %eax, %eax
movq %r14, -0x70(%rbp)
movl %eax, %ebx
movl $0x288, %edx            # imm = 0x288
movq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0xa270
movq -0x40(%rbp), %r15
movq %r14, (%r15)
movq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0xb856
andq $0x0, -0x48(%rbp)
movq %r14, %rdi
callq 0xb551
movq %r15, %rdi
xorl %esi, %esi
movq -0x78(%rbp), %rdx
movq -0x98(%rbp), %rcx
callq 0x1335c
testq %rax, %rax
je 0x131ba
movb 0x46(%rax), %cl
testb $0x10, %cl
jne 0x13193
testb $0x20, %cl
jne 0x1319c
cmpq $0x0, 0x18(%rax)
jne 0x131a5
movl %ebx, -0x64(%rbp)
movswl 0x3e(%rax), %ecx
testl %ecx, %ecx
movl $0x0, %ebx
movl %ecx, -0x2c(%rbp)
cmovgl %ecx, %ebx
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x12ed2
movq %rax, %r13
movq 0x8(%rax), %rax
movq (%rax,%r14), %rdi
movq -0x80(%rbp), %rsi
callq 0xa4f0
testl %eax, %eax
je 0x12ec5
incq %r15
addq $0x30, %r14
movq %r13, %rax
leaq 0x59256(%rip), %r13     # 0x6c119
jmp 0x12e95
movl %r15d, %ebx
movq %r13, %rax
leaq 0x59247(%rip), %r13     # 0x6c119
cmpl -0x2c(%rbp), %ebx
movq -0x70(%rbp), %r14
je 0x13278
cmpl $0x0, -0x4c(%rbp)
je 0x12f36
testb $0x8, 0x2e(%r14)
jne 0x12fdc
xorl %r15d, %r15d
movq %rax, %rdi
addq $0x10, %rdi
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x12f2d
movzwl 0x5e(%rdi), %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x12f27
movq 0x8(%rdi), %rsi
movswl (%rsi,%rdx,2), %esi
cmpl %esi, %ebx
cmoveq %r12, %r15
cmpl $-0x2, %esi
cmoveq %r12, %r15
incq %rdx
jmp 0x12f08
addq $0x28, %rdi
jmp 0x12efa
testq %r15, %r15
jne 0x13292
movq %rax, %r13
movq -0x40(%rbp), %rdi
callq 0x136af
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
testq %rcx, %rcx
je 0x130f0
movq %r13, -0x58(%rbp)
movq 0x68(%r13), %r15
movq %rcx, %r13
movq %r14, %rdi
movq %r15, %rsi
callq 0x136fb
movl (%r15), %r8d
movl 0x4(%r15), %r9d
movq %r13, %rdi
pushq $0x3
popq %rsi
movl %eax, %edx
movl %eax, %r15d
movl -0x30(%rbp), %ecx
callq 0x1373a
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x13770
movq %r13, %rdi
pushq $0xa
popq %rsi
leaq 0x56472(%rip), %rdx     # 0x69410
callq 0x1378a
movq %r13, %rdi
movl %r15d, -0x2c(%rbp)
movl %r15d, %esi
callq 0x13824
movq (%r13), %rax
cmpb $0x0, 0x51(%rax)
je 0x1301b
movl -0x2c(%rbp), %eax
movl %eax, 0x72627(%rip)     # 0x855ec
movq -0x58(%rbp), %r14
movl 0x38(%r14), %eax
movl %eax, 0x7261d(%rip)     # 0x855f0
leaq 0x7260e(%rip), %rax     # 0x855e8
jmp 0x13034
leaq 0x20(%rax), %rsi
xorl %r15d, %r15d
movq (%rsi), %rsi
testq %rsi, %rsi
je 0x12ef3
movl 0x28(%rsi), %ecx
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
shlq $0x4, %rcx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x13015
cmpl %ebx, 0x40(%rsi,%rdx)
cmoveq %r13, %r15
addq $0x10, %rdx
jmp 0x13002
addq $0x8, %rsi
jmp 0x12fe3
movq 0x8(%r13), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, 0x1c(%rax)
movq -0x58(%rbp), %r14
movl 0x38(%r14), %ecx
movl %ecx, 0x20(%rax)
addq $0x18, %rax
movl -0x30(%rbp), %ecx
movl %ecx, 0xc(%rax)
movq (%r14), %rdx
movq %r13, %rdi
pushq $0x1
popq %rsi
xorl %ecx, %ecx
callq 0x1385d
movq %r13, %rdi
movl -0x5c(%rbp), %esi
callq 0x1396b
movl 0x38(%r14), %eax
movl %eax, -0x58(%rbp)
movq %r13, %rdi
movl -0x60(%rbp), %r15d
movl %r15d, %esi
callq 0x386ca
movl -0x58(%rbp), %ecx
movl %ecx, 0x8(%rax)
movq %r13, %rdi
movl %r15d, %esi
callq 0x386ca
movl -0x2c(%rbp), %ecx
movl %ecx, 0xc(%rax)
movswq 0x3e(%r14), %rdx
incq %rdx
movq %r13, %rdi
movl %r15d, %esi
pushq $-0xe
popq %rcx
callq 0x1385d
movswl 0x3e(%r14), %eax
movq (%r13), %rcx
cmpb $0x0, 0x51(%rcx)
leaq 0x7253c(%rip), %rcx     # 0x855e8
movq -0x40(%rbp), %r15
jne 0x130be
movq 0x8(%r13), %rcx
movl $0x90, %edx
addq %rdx, %rcx
movl %eax, 0x8(%rcx)
movq -0x70(%rbp), %r14
cmpb $0x0, 0x51(%r14)
jne 0x130f0
movl $0x1, 0x1e4(%r15)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x50(%r15)
movq %r13, %rdi
movq %r15, %rsi
callq 0x139b0
movq -0x38(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, (%rax)
movl %ebx, 0xc(%rax)
movq %r14, 0x20(%rax)
movq %r14, %rdi
callq 0xb594
cmpb $0x0, 0x51(%r14)
movl -0x64(%rbp), %r15d
leaq 0x59001(%rip), %r13     # 0x6c119
jne 0x13160
movq -0x38(%rbp), %rbx
movq 0x18(%rbx), %rdi
pushq $0x1
popq %rsi
movq -0x90(%rbp), %r15
movq %r15, %rdx
callq 0xa050
movq %rbx, %rdi
movq %r15, %rsi
leaq -0x48(%rbp), %rdx
callq 0x13cee
movl %eax, %r15d
movl -0x50(%rbp), %eax
cmpl $0x30, %eax
ja 0x13160
incl %eax
movl %eax, -0x50(%rbp)
pushq $0x11
popq %rax
cmpl $0x11, %r15d
je 0x12e08
testl %r15d, %r15d
movq 0x10(%rbp), %r12
jne 0x131e4
jmp 0x13173
movq $0x0, -0x40(%rbp)
cmpb $0x0, 0x51(%r14)
je 0x13186
xorl %r15d, %r15d
cmpq $0x0, -0x38(%rbp)
jne 0x131e4
jmp 0x131f6
movq -0x38(%rbp), %rax
movq %rax, (%r12)
xorl %r15d, %r15d
jmp 0x13202
leaq 0x58f13(%rip), %rsi     # 0x6c0ad
jmp 0x131ac
leaq 0x58f28(%rip), %rsi     # 0x6c0cb
jmp 0x131ac
leaq 0x58f43(%rip), %rsi     # 0x6c0ef
movq %r15, %rdi
movq -0x78(%rbp), %rdx
xorl %eax, %eax
callq 0x1357a
cmpq $0x0, 0x8(%r15)
je 0x131d8
movq %r14, %rdi
xorl %esi, %esi
callq 0xb856
movq 0x8(%r15), %rax
movq %rax, -0x48(%rbp)
andq $0x0, 0x8(%r15)
movq %r14, %rdi
callq 0xb594
pushq $0x1
popq %r15
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x131f6
callq 0x10895
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0xb856
movq -0x48(%rbp), %rbx
testq %rbx, %rbx
leaq 0x59173(%rip), %rdx     # 0x6c383
cmoveq %rbx, %rdx
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0xe89d
movq %r14, %rdi
movq %rbx, %rsi
callq 0xb856
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x13e42
movq %r14, %rdi
movq %rbx, %rsi
callq 0xb856
movq %r14, %rdi
movl %r15d, %esi
callq 0x108ce
movq %r14, %rcx
movl %eax, %r14d
movq 0x18(%rcx), %rdi
testq %rdi, %rdi
je 0x13266
callq *0x70252(%rip)          # 0x834b8
movl %r14d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
xorl %esi, %esi
callq 0xb856
leaq 0x58e7b(%rip), %rsi     # 0x6c104
movq %r14, %rdi
movq -0x80(%rbp), %rdx
jmp 0x132a9
movq %r14, %rdi
xorl %esi, %esi
callq 0xb856
leaq 0x58e82(%rip), %rsi     # 0x6c125
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x13638
movq %rax, -0x48(%rbp)
movq %r14, %rdi
callq 0xb594
pushq $0x1
popq %r15
jmp 0x1317d