// File: /workspace/github_c_makefile_star2_O1/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, -0x88(%rbp)
movq %rdx, -0x68(%rbp)
movq %rsi, -0x98(%rbp)
movq %rdi, %r15
movq 0x10(%rbp), %r12
xorl %r14d, %r14d
movq %r14, -0x40(%rbp)
movq %r14, (%r12)
movl $0x0, -0x34(%rbp)
movl %r9d, -0x4c(%rbp)
testl %r9d, %r9d
setne %bl
movq 0x18(%rdi), %rdi
testq %rdi, %rdi
je 0x13eb5
callq *0x7f4f3(%rip)          # 0x933a8
movl $0x28, %esi
movq %r15, %rdi
callq 0x144ee
movq %rax, %r13
testq %rax, %rax
je 0x143a0
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r13)
movups %xmm0, (%r13)
movq $0x0, 0x20(%r13)
movl $0x290, %esi            # imm = 0x290
movq %r15, %rdi
callq 0x144ee
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x1439d
movl -0x34(%rbp), %eax
movb %bl, %al
movl %eax, -0x34(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x4c(%rbp)
setne %al
movl %eax, %ecx
xorl $0x3, %ecx
movl %ecx, -0x74(%rbp)
orl $0x2, %eax
movq %rax, -0x80(%rbp)
leaq 0x6b540(%rip), %rbx     # 0x7f464
leaq 0x691ee(%rip), %r12     # 0x7d119
xorl %eax, %eax
movl $0x0, -0x38(%rbp)
movq %r15, -0x70(%rbp)
movq %r13, -0x60(%rbp)
movl %eax, -0x78(%rbp)
movl $0x290, %edx            # imm = 0x290
movq -0x30(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xa210
movq %r15, (%r14)
movq -0x40(%rbp), %rsi
movq %r15, %rdi
callq 0xb6df
movq $0x0, -0x40(%rbp)
movq %r15, %rdi
callq 0xb3a2
movq %r14, %rdi
xorl %esi, %esi
movq -0x68(%rbp), %rdx
movq -0x98(%rbp), %rcx
callq 0x14590
testq %rax, %rax
je 0x13fa7
testb $0x10, 0x46(%rax)
je 0x13fa9
movq -0x30(%rbp), %rdi
leaq 0x69111(%rip), %rsi     # 0x7d0ad
movq -0x68(%rbp), %rdx
xorl %eax, %eax
callq 0x14804
xorl %eax, %eax
testq %rax, %rax
je 0x13fca
testb $0x20, 0x46(%rax)
je 0x13fcc
movq -0x30(%rbp), %rdi
leaq 0x6910c(%rip), %rsi     # 0x7d0cb
movq -0x68(%rbp), %rdx
xorl %eax, %eax
callq 0x14804
xorl %eax, %eax
testq %rax, %rax
je 0x13fee
cmpq $0x0, 0x18(%rax)
je 0x13ff0
movq -0x30(%rbp), %rdi
leaq 0x6910c(%rip), %rsi     # 0x7d0ef
movq -0x68(%rbp), %rdx
xorl %eax, %eax
callq 0x14804
xorl %eax, %eax
testq %rax, %rax
je 0x143aa
movswl 0x3e(%rax), %ecx
testl %ecx, %ecx
movq %rax, -0x48(%rbp)
jle 0x1403d
movq 0x8(%rax), %r15
movl %ecx, -0x58(%rbp)
movl %ecx, %r14d
xorl %r13d, %r13d
movq (%r15), %rdi
movq -0x88(%rbp), %rsi
callq 0xa3f0
testl %eax, %eax
je 0x14042
incq %r13
addq $0x30, %r15
cmpq %r13, %r14
jne 0x14012
movl -0x58(%rbp), %ecx
movl %ecx, %r13d
movq -0x70(%rbp), %r15
jmp 0x14049
xorl %r13d, %r13d
jmp 0x14049
movq -0x70(%rbp), %r15
movl -0x58(%rbp), %ecx
cmpl %ecx, %r13d
je 0x143d5
cmpl $0x0, -0x4c(%rbp)
je 0x140e5
testb $0x8, 0x2e(%r15)
jne 0x14138
xorl %r14d, %r14d
movq -0x48(%rbp), %rsi
movq 0x10(%rsi), %rax
testq %rax, %rax
je 0x140a6
movzwl 0x5e(%rax), %ecx
testq %rcx, %rcx
je 0x140a0
movq 0x8(%rax), %rdx
xorl %esi, %esi
movswl (%rdx,%rsi,2), %edi
cmpl %edi, %r13d
cmoveq %rbx, %r14
cmpl $-0x2, %edi
cmoveq %rbx, %r14
incq %rsi
cmpq %rsi, %rcx
jne 0x14086
movq 0x28(%rax), %rax
jmp 0x14072
testq %r14, %r14
je 0x140dc
movq %r15, %rdi
xorl %esi, %esi
callq 0xb6df
movq %r15, %rdi
leaq 0x69066(%rip), %rsi     # 0x7d125
movq %r14, %rdx
xorl %eax, %eax
callq 0x148c2
movq %rax, -0x40(%rbp)
movq %r15, %rdi
callq 0xb3fa
movl $0x1, -0x38(%rbp)
testq %r14, %r14
jne 0x144db
movq -0x30(%rbp), %rdi
callq 0x14939
movq %rax, %r14
movq -0x60(%rbp), %rax
movq %r14, 0x18(%rax)
testq %r14, %r14
je 0x1432b
movq -0x48(%rbp), %rax
movq 0x68(%rax), %rax
testq %rax, %rax
je 0x14173
movl 0x28(%r15), %ecx
testl %ecx, %ecx
jle 0x1417b
movq 0x20(%r15), %rdx
addq $0x18, %rdx
xorl %r15d, %r15d
cmpq %rax, (%rdx)
je 0x1417e
incq %r15
addq $0x20, %rdx
cmpq %r15, %rcx
jne 0x14122
movl %ecx, %r15d
jmp 0x1417e
movq -0x48(%rbp), %rsi
movq 0x20(%rsi), %rax
xorl %r14d, %r14d
testq %rax, %rax
je 0x1406e
movslq 0x28(%rax), %rcx
testq %rcx, %rcx
jle 0x1416d
shlq $0x4, %rcx
xorl %edx, %edx
cmpl %r13d, 0x40(%rax,%rdx)
cmoveq %r12, %r14
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x1415b
movq 0x8(%rax), %rax
jmp 0x14143
movl $0xfff0bdc0, %r15d      # imm = 0xFFF0BDC0
jmp 0x1417e
xorl %r15d, %r15d
movl (%rax), %r8d
movslq 0x4(%rax), %rax
movq %rax, -0x58(%rbp)
movq %r14, %rdi
movl $0x3, %esi
movl %r15d, %edx
movl -0x34(%rbp), %ecx
callq 0x3fa9e
movq %r14, %rdi
movl %eax, %esi
movq -0x58(%rbp), %rdx
movl $0xfffffff2, %ecx       # imm = 0xFFFFFFF2
callq 0x14ab9
movq (%r14), %rax
cmpb $0x0, 0x51(%rax)
leaq 0x8132b(%rip), %rax     # 0x954e8
jne 0x141d3
movslq 0x3c(%r14), %rax
movq 0x8(%r14), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rax
addq $-0x18, %rax
movb $0x1, 0x3(%rax)
movq %r14, %rdi
movl $0xa, %esi
leaq 0x6622a(%rip), %rdx     # 0x7a410
callq 0x149e4
movl $0x1, %eax
movl %r15d, %ecx
shll %cl, %eax
orl %eax, 0x94(%r14)
cmpl $0x1, %r15d
je 0x14222
movq (%r14), %rcx
movq 0x20(%rcx), %rcx
movslq %r15d, %rdx
shlq $0x5, %rdx
movq 0x8(%rcx,%rdx), %rcx
cmpb $0x0, 0x11(%rcx)
je 0x14222
orl %eax, 0x98(%r14)
movq (%r14), %rax
movb 0x51(%rax), %al
leaq 0x812b9(%rip), %rdx     # 0x954e8
movq %rdx, %rcx
testb %al, %al
movq -0x48(%rbp), %rsi
jne 0x14242
movq 0x8(%r14), %rcx
addq $0x18, %rcx
movl %r15d, 0x4(%rcx)
movl 0x38(%rsi), %ecx
testb %al, %al
je 0x14258
movl %ecx, 0x8129d(%rip)     # 0x954f0
movq %rdx, %rax
jmp 0x14263
movq 0x8(%r14), %rax
movl %ecx, 0x20(%rax)
addq $0x18, %rax
movl -0x34(%rbp), %ecx
movl %ecx, 0xc(%rax)
movq (%rsi), %rdx
movq %r14, %rdi
movl $0x1, %esi
xorl %ecx, %ecx
callq 0x14ab9
movq %r14, %rdi
movl -0x74(%rbp), %esi
callq 0x14be2
movq -0x48(%rbp), %rdi
movl 0x38(%rdi), %eax
movq (%r14), %rcx
cmpb $0x0, 0x51(%rcx)
je 0x142a9
movl %eax, 0x81254(%rip)     # 0x954f0
leaq 0x81245(%rip), %rcx     # 0x954e8
movq -0x80(%rbp), %rsi
jmp 0x142bc
movq 0x8(%r14), %rcx
movq -0x80(%rbp), %rsi
leaq (%rsi,%rsi,2), %rdx
leaq (%rcx,%rdx,8), %rcx
movl %eax, 0x8(%rcx)
movl %r15d, 0xc(%rcx)
movswq 0x3e(%rdi), %rdx
incq %rdx
movq %rdi, %r15
movq %r14, %rdi
movl $0xfffffff2, %ecx       # imm = 0xFFFFFFF2
callq 0x14ab9
movswl 0x3e(%r15), %eax
movq (%r14), %rcx
cmpb $0x0, 0x51(%rcx)
leaq 0x811fd(%rip), %rcx     # 0x954e8
jne 0x142f9
movq 0x8(%r14), %rcx
movl $0x90, %edx
addq %rdx, %rcx
movl %eax, 0x8(%rcx)
movq -0x70(%rbp), %r15
cmpb $0x0, 0x51(%r15)
jne 0x1432b
movq -0x30(%rbp), %rsi
movl $0x1, 0x1e4(%rsi)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x50(%rsi)
movq %r14, %rdi
callq 0x14c2a
movq -0x60(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, (%rax)
movl %r13d, 0xc(%rax)
movq %rax, %r13
movq %r15, 0x20(%rax)
movq %r15, %rdi
callq 0xb3fa
cmpb $0x0, 0x51(%r15)
jne 0x1440f
movq 0x18(%r13), %rdi
movl $0x1, %esi
movq -0x90(%rbp), %r14
movq %r14, %rdx
callq 0xa050
movq %r13, %rdi
movq %r14, %rsi
leaq -0x40(%rbp), %rdx
callq 0x14fd2
movl %eax, %r14d
movl -0x78(%rbp), %eax
cmpl $0x30, %eax
ja 0x14415
incl %eax
movl $0x11, -0x38(%rbp)
cmpl $0x11, %r14d
je 0x13f3c
jmp 0x14415
xorl %r14d, %r14d
movq $0x0, -0x30(%rbp)
jmp 0x14419
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x143ff
movq %r15, %rdi
xorl %esi, %esi
callq 0xb6df
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, -0x40(%rbp)
movq $0x0, 0x8(%rcx)
jmp 0x143ff
movq %r15, %rdi
xorl %esi, %esi
callq 0xb6df
leaq 0x68d1e(%rip), %rsi     # 0x7d104
movq %r15, %rdi
movq -0x88(%rbp), %rdx
xorl %eax, %eax
callq 0x148c2
movq %rax, -0x40(%rbp)
movq -0x60(%rbp), %r13
movq %r15, %rdi
callq 0xb3fa
movl $0x1, %r14d
jmp 0x14415
movl -0x38(%rbp), %eax
movl %eax, %r14d
movq 0x10(%rbp), %r12
testl %r14d, %r14d
jne 0x14429
cmpb $0x0, 0x51(%r15)
je 0x144d2
testq %r13, %r13
je 0x1443c
movq 0x18(%r13), %rdi
testq %rdi, %rdi
je 0x1443c
callq 0x113bc
movq %r15, %rdi
movq %r13, %rsi
callq 0xb6df
movq %r15, %rbx
movq -0x40(%rbp), %r15
testq %r15, %r15
leaq 0x68f2b(%rip), %rdx     # 0x7d383
cmoveq %r15, %rdx
movq %rbx, %rdi
movl %r14d, %esi
movq %r15, %rcx
xorl %eax, %eax
callq 0xef6c
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb6df
movq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x1513e
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb6df
cmpl $0xc0a, %r14d           # imm = 0xC0A
je 0x144a3
cmpb $0x0, 0x51(%rbx)
jne 0x144a3
andl 0x48(%rbx), %r14d
jmp 0x144b1
movq %rbx, %rdi
callq 0x28aa8
movl $0x7, %r14d
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x144c0
callq *0x7eef8(%rip)          # 0x933b8
movl %r14d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, (%r12)
jmp 0x14447
movl -0x38(%rbp), %eax
movl %eax, %r14d
movq 0x10(%rbp), %r12
movq -0x60(%rbp), %r13
jmp 0x14419