// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/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++;
    DisableLookaside;
  }
  sParse.disableVtab = (prepFlags & SQLITE_PREPARE_NO_VTAB)!=0;

  /* 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.
  */
  if( !db->noSharedCache ){
    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( pzTail ){
    *pzTail = sParse.zTail;
  }

  if( db->init.busy==0 ){
    sqlite3VdbeSetSql(sParse.pVdbe, zSql, (int)(sParse.zTail-zSql), prepFlags);
  }
  if( db->mallocFailed ){
    sParse.rc = SQLITE_NOMEM_BKPT;
  }
  rc = sParse.rc;
  if( rc!=SQLITE_OK ){
    if( sParse.pVdbe ) 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 $0x210, %rsp            # imm = 0x210
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 -0x1e0(%rbp), %rdi
xorl %esi, %esi
movl $0xd4, %edx
callq 0x19360
leaq -0x1e0(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
xorl %esi, %esi
movl $0xa0, %edx
callq 0x19360
movq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl -0x18(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x40b635
movb -0x1bc(%rbp), %al
addb $0x1, %al
movb %al, -0x1bc(%rbp)
movq -0x8(%rbp), %rax
movl 0x170(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x170(%rax)
movq -0x8(%rbp), %rax
movw $0x0, 0x174(%rax)
movl -0x18(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movb %al, -0x1bb(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x69(%rax)
jne 0x40b700
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x40b6fe
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x1e8(%rbp)
cmpq $0x0, -0x1e8(%rbp)
je 0x40b6ee
movq -0x1e8(%rbp), %rdi
callq 0x40ba90
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x40b6ec
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x1f0(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x1f0(%rbp), %rcx
leaq 0x1a04e7(%rip), %rdx    # 0x5abbc7
movb $0x0, %al
callq 0x3c50b0
jmp 0x40b946
jmp 0x40b6ee
jmp 0x40b6f0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x40b661
jmp 0x40b700
movq -0x8(%rbp), %rdi
callq 0x40bad0
movq -0x8(%rbp), %rax
movq %rax, -0x1e0(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x40b804
cmpl $0x0, -0x14(%rbp)
je 0x40b73e
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x40b804
movq -0x8(%rbp), %rax
movl 0x80(%rax), %eax
movl %eax, -0x1fc(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x1fc(%rbp), %eax
jle 0x40b786
movq -0x8(%rbp), %rdi
movl $0x12, %esi
leaq 0x1a047c(%rip), %rdx    # 0x5abbe5
movb $0x0, %al
callq 0x3c50b0
movq -0x8(%rbp), %rdi
movl $0x12, %esi
callq 0x3c7380
movl %eax, -0x34(%rbp)
jmp 0x40b946
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x40bb40
movq %rax, -0x1f8(%rbp)
cmpq $0x0, -0x1f8(%rbp)
je 0x40b7f0
movq -0x1f8(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x3cea20
movq -0x10(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq -0x1f8(%rbp), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x1f8(%rbp), %rsi
callq 0x3c00a0
jmp 0x40b802
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
jmp 0x40b818
movq -0x10(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x3cea20
cmpl $0x65, -0x1c8(%rbp)
jne 0x40b82b
movl $0x0, -0x1c8(%rbp)
cmpb $0x0, -0x1c3(%rbp)
je 0x40b840
leaq -0x1e0(%rbp), %rdi
callq 0x40bbb0
cmpq $0x0, 0x10(%rbp)
je 0x40b855
movq -0xa0(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movzbl 0xb5(%rax), %eax
cmpl $0x0, %eax
jne 0x40b88b
movq -0x1d0(%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 0x40bcc0
movq -0x8(%rbp), %rax
cmpb $0x0, 0x61(%rax)
je 0x40b89f
movl $0x7, -0x1c8(%rbp)
movl -0x1c8(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x40b8c6
cmpq $0x0, -0x1d0(%rbp)
je 0x40b8c4
movq -0x1d0(%rbp), %rdi
callq 0x3c7330
jmp 0x40b8d4
movq -0x1d0(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x30(%rbp)
je 0x40b903
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x30(%rbp), %rcx
leaq 0x190734(%rip), %rdx    # 0x59c021
movb $0x0, %al
callq 0x3c50b0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x3c00a0
jmp 0x40b90f
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x3c5210
jmp 0x40b911
cmpq $0x0, -0x58(%rbp)
je 0x40b944
movq -0x58(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x208(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x208(%rbp), %rsi
callq 0x3c00a0
jmp 0x40b911
jmp 0x40b946
leaq -0x1e0(%rbp), %rdi
callq 0x3cc3b0
movl -0x34(%rbp), %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
nop