// File: /workspace/github_c_makefile_star2_O0/ukontainer[P]sqlite-bench/sqlite3.c
// Function: sqlite3Prepare
static int sqlite3Prepare(
  sqlite3 *db,              /* Database handle. */
  const char *zSql,         /* UTF-8 encoded SQL statement. */
  int nBytes,               /* Length of zSql in bytes. */
  u32 prepFlags,            /* Zero or more SQLITE_PREPARE_* flags */
  Vdbe *pReprepare,         /* VM being reprepared */
  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
  const char **pzTail       /* OUT: End of parsed string */
){
  char *zErrMsg = 0;        /* Error message */
  int rc = SQLITE_OK;       /* Result code */
  int i;                    /* Loop counter */
  Parse sParse;             /* Parsing context */

  memset(&sParse, 0, PARSE_HDR_SZ);
  memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
  sParse.pReprepare = pReprepare;
  assert( ppStmt && *ppStmt==0 );
  /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */
  assert( sqlite3_mutex_held(db->mutex) );

  /* For a long-term use prepared statement avoid the use of
  ** lookaside memory.
  */
  if( prepFlags & SQLITE_PREPARE_PERSISTENT ){
    sParse.disableLookaside++;
    db->lookaside.bDisable++;
  }

  /* Check to verify that it is possible to get a read lock on all
  ** database schemas.  The inability to get a read lock indicates that
  ** some other database connection is holding a write-lock, which in
  ** turn means that the other connection has made uncommitted changes
  ** to the schema.
  **
  ** Were we to proceed and prepare the statement against the uncommitted
  ** schema changes and if those schema changes are subsequently rolled
  ** back and different changes are made in their place, then when this
  ** prepared statement goes to run the schema cookie would fail to detect
  ** the schema change.  Disaster would follow.
  **
  ** This thread is currently holding mutexes on all Btrees (because
  ** of the sqlite3BtreeEnterAll() in sqlite3LockAndPrepare()) so it
  ** is not possible for another thread to start a new schema change
  ** while this routine is running.  Hence, we do not need to hold 
  ** locks on the schema, we just need to make sure nobody else is 
  ** holding them.
  **
  ** Note that setting READ_UNCOMMITTED overrides most lock detection,
  ** but it does *not* override schema lock detection, so this all still
  ** works even if READ_UNCOMMITTED is set.
  */
  for(i=0; i<db->nDb; i++) {
    Btree *pBt = db->aDb[i].pBt;
    if( pBt ){
      assert( sqlite3BtreeHoldsMutex(pBt) );
      rc = sqlite3BtreeSchemaLocked(pBt);
      if( rc ){
        const char *zDb = db->aDb[i].zDbSName;
        sqlite3ErrorWithMsg(db, rc, "database schema is locked: %s", zDb);
        testcase( db->flags & SQLITE_ReadUncommit );
        goto end_prepare;
      }
    }
  }

  sqlite3VtabUnlockList(db);

  sParse.db = db;
  if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
    char *zSqlCopy;
    int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
    testcase( nBytes==mxLen );
    testcase( nBytes==mxLen+1 );
    if( nBytes>mxLen ){
      sqlite3ErrorWithMsg(db, SQLITE_TOOBIG, "statement too long");
      rc = sqlite3ApiExit(db, SQLITE_TOOBIG);
      goto end_prepare;
    }
    zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes);
    if( zSqlCopy ){
      sqlite3RunParser(&sParse, zSqlCopy, &zErrMsg);
      sParse.zTail = &zSql[sParse.zTail-zSqlCopy];
      sqlite3DbFree(db, zSqlCopy);
    }else{
      sParse.zTail = &zSql[nBytes];
    }
  }else{
    sqlite3RunParser(&sParse, zSql, &zErrMsg);
  }
  assert( 0==sParse.nQueryLoop );

  if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
  if( sParse.checkSchema ){
    schemaIsValid(&sParse);
  }
  if( db->mallocFailed ){
    sParse.rc = SQLITE_NOMEM_BKPT;
  }
  if( pzTail ){
    *pzTail = sParse.zTail;
  }
  rc = sParse.rc;

#ifndef SQLITE_OMIT_EXPLAIN
  if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
    static const char * const azColName[] = {
       "addr", "opcode", "p1", "p2", "p3", "p4", "p5", "comment",
       "id", "parent", "notused", "detail"
    };
    int iFirst, mx;
    if( sParse.explain==2 ){
      sqlite3VdbeSetNumCols(sParse.pVdbe, 4);
      iFirst = 8;
      mx = 12;
    }else{
      sqlite3VdbeSetNumCols(sParse.pVdbe, 8);
      iFirst = 0;
      mx = 8;
    }
    for(i=iFirst; i<mx; i++){
      sqlite3VdbeSetColName(sParse.pVdbe, i-iFirst, COLNAME_NAME,
                            azColName[i], SQLITE_STATIC);
    }
  }
#endif

  if( db->init.busy==0 ){
    sqlite3VdbeSetSql(sParse.pVdbe, zSql, (int)(sParse.zTail-zSql), prepFlags);
  }
  if( sParse.pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){
    sqlite3VdbeFinalize(sParse.pVdbe);
    assert(!(*ppStmt));
  }else{
    *ppStmt = (sqlite3_stmt*)sParse.pVdbe;
  }

  if( zErrMsg ){
    sqlite3ErrorWithMsg(db, rc, "%s", zErrMsg);
    sqlite3DbFree(db, zErrMsg);
  }else{
    sqlite3Error(db, rc);
  }

  /* Delete any TriggerPrg structures allocated while parsing this statement. */
  while( sParse.pTriggerPrg ){
    TriggerPrg *pT = sParse.pTriggerPrg;
    sParse.pTriggerPrg = pT->pNext;
    sqlite3DbFree(db, pT);
  }

end_prepare:

  sqlite3ParserReset(&sParse);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
leaq -0x1d0(%rbp), %rdi
xorl %esi, %esi
movl $0xc4, %edx
callq 0x4010b0
leaq -0x1d0(%rbp), %rdi
addq $0xf8, %rdi
xorl %esi, %esi
movl $0xa0, %edx
callq 0x4010b0
movq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl -0x18(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x455738
movb -0x1ac(%rbp), %al
addb $0x1, %al
movb %al, -0x1ac(%rbp)
movq -0x8(%rbp), %rax
movl 0x160(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x160(%rax)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x4557dc
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x1d8(%rbp)
cmpq $0x0, -0x1d8(%rbp)
je 0x4557cc
movq -0x1d8(%rbp), %rdi
callq 0x455b20
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x4557ca
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x1e0(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x1e0(%rbp), %rcx
leaq 0x12a50f(%rip), %rdx    # 0x57fccd
movb $0x0, %al
callq 0x40a910
jmp 0x455afb
jmp 0x4557cc
jmp 0x4557ce
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x45573f
movq -0x8(%rbp), %rdi
callq 0x454d70
movq -0x8(%rbp), %rax
movq %rax, -0x1d0(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x4558e0
cmpl $0x0, -0x14(%rbp)
je 0x45581a
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x4558e0
movq -0x8(%rbp), %rax
movl 0x80(%rax), %eax
movl %eax, -0x1ec(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x1ec(%rbp), %eax
jle 0x455862
movq -0x8(%rbp), %rdi
movl $0x12, %esi
leaq 0x12a4a6(%rip), %rdx    # 0x57fceb
movb $0x0, %al
callq 0x40a910
movq -0x8(%rbp), %rdi
movl $0x12, %esi
callq 0x40cd50
movl %eax, -0x34(%rbp)
jmp 0x455afb
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x453ae0
movq %rax, -0x1e8(%rbp)
cmpq $0x0, -0x1e8(%rbp)
je 0x4558cc
movq -0x1e8(%rbp), %rsi
leaq -0x1d0(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x4143a0
movq -0x10(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq -0x1e8(%rbp), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x1e8(%rbp), %rsi
callq 0x4058a0
jmp 0x4558de
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
jmp 0x4558f4
movq -0x10(%rbp), %rsi
leaq -0x1d0(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x4143a0
cmpl $0x65, -0x1b8(%rbp)
jne 0x455907
movl $0x0, -0x1b8(%rbp)
cmpb $0x0, -0x1b3(%rbp)
je 0x45591c
leaq -0x1d0(%rbp), %rdi
callq 0x455b60
movq -0x8(%rbp), %rax
cmpb $0x0, 0x61(%rax)
je 0x455930
movl $0x7, -0x1b8(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x455945
movq -0xa0(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl -0x1b8(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x455a1a
cmpq $0x0, -0x1c0(%rbp)
je 0x455a1a
movzbl -0xc5(%rbp), %eax
cmpl $0x0, %eax
je 0x455a1a
movzbl -0xc5(%rbp), %eax
cmpl $0x2, %eax
jne 0x4559a9
movq -0x1c0(%rbp), %rdi
movl $0x4, %esi
callq 0x455c70
movl $0x8, -0x1f0(%rbp)
movl $0xc, -0x1f4(%rbp)
jmp 0x4559ce
movq -0x1c0(%rbp), %rdi
movl $0x8, %esi
callq 0x455c70
movl $0x0, -0x1f0(%rbp)
movl $0x8, -0x1f4(%rbp)
movl -0x1f0(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x1f4(%rbp), %eax
jge 0x455a18
movq -0x1c0(%rbp), %rdi
movl -0x38(%rbp), %esi
subl -0x1f0(%rbp), %esi
movslq -0x38(%rbp), %rcx
leaq 0x1769c3(%rip), %rax    # 0x5cc3c0
movq (%rax,%rcx,8), %rcx
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %r8d
callq 0x455d40
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4559d7
jmp 0x455a1a
movq -0x8(%rbp), %rax
movzbl 0xb5(%rax), %eax
cmpl $0x0, %eax
jne 0x455a50
movq -0x1c0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0xa0(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movl %eax, %edx
movl -0x18(%rbp), %eax
movzbl %al, %ecx
callq 0x455dd0
cmpq $0x0, -0x1c0(%rbp)
je 0x455a7b
cmpl $0x0, -0x34(%rbp)
jne 0x455a6d
movq -0x8(%rbp), %rax
movzbl 0x61(%rax), %eax
cmpl $0x0, %eax
je 0x455a7b
movq -0x1c0(%rbp), %rdi
callq 0x40cd00
jmp 0x455a89
movq -0x1c0(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x455ab8
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x30(%rbp), %rcx
leaq 0x121941(%rip), %rdx    # 0x5773e3
movb $0x0, %al
callq 0x40a910
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x4058a0
jmp 0x455ac4
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x40aa70
jmp 0x455ac6
cmpq $0x0, -0x58(%rbp)
je 0x455af9
movq -0x58(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x200(%rbp), %rsi
callq 0x4058a0
jmp 0x455ac6
jmp 0x455afb
leaq -0x1d0(%rbp), %rdi
callq 0x411cf0
movl -0x34(%rbp), %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
nopw %cs:(%rax,%rax)