// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %r9, 0x28(%rsp)
movq %r8, %r14
movl %ecx, %ebp
movl %edx, %r13d
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
movq $0x0, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
xorl %r12d, %r12d
movl $0xd4, %edx
xorl %esi, %esi
callq 0x173a0
leaq 0x138(%rsp), %r15
movl $0xa0, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x173a0
movq %r14, 0x30(%r15)
testb $0x1, %bpl
je 0x2af2f4
incb 0x54(%rsp)
incl 0x170(%rbx)
movw $0x0, 0x174(%rbx)
movl %ebp, 0x1c(%rsp)
movl %ebp, %eax
shrb $0x2, %al
andb $0x1, %al
movb %al, 0x55(%rsp)
cmpb $0x0, 0x69(%rbx)
je 0x2af386
movq %rbx, %rdi
callq 0x2af7a6
movq %rbx, 0x30(%rsp)
testl %r13d, %r13d
js 0x2af36d
movl %r13d, %r14d
je 0x2af32d
movq 0x8(%rsp), %rax
cmpb $0x0, -0x1(%rax,%r14)
je 0x2af36d
cmpl %r13d, 0x80(%rbx)
jge 0x2af410
leaq 0x130b64(%rip), %rdx    # 0x3dfea5
movq %rbx, %rdi
movl $0x12, %esi
xorl %eax, %eax
callq 0x27fc17
cmpb $0x0, 0x61(%rbx)
je 0x2af437
movq %rbx, %rdi
callq 0x299b1a
movl $0x7, %r12d
jmp 0x2af43f
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rsi
callq 0x2874c0
jmp 0x2af4be
cmpl $0x0, 0x28(%rbx)
jle 0x2af309
leaq 0x130af0(%rip), %r14    # 0x3dfe87
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x20(%rbx), %rax
movq 0x8(%rax,%r15), %rdi
movl $0x0, %eax
testq %rdi, %rdi
je 0x2af3f7
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq %rax, 0x8(%rcx)
movl $0x1, %esi
movl $0x1, %edx
callq 0x296571
testl %eax, %eax
je 0x2af3f2
movl %eax, %r12d
movq 0x20(%rbx), %rax
movq (%rax,%r15), %rcx
movq %rbx, %rdi
movl %r12d, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0x27fc17
movl $0x5, %eax
jmp 0x2af3f7
xorl %eax, %eax
xorl %r12d, %r12d
testl %eax, %eax
jne 0x2af429
incq %rbp
movslq 0x28(%rbx), %rax
addq $0x20, %r15
cmpq %rax, %rbp
jl 0x2af39f
jmp 0x2af309
cmpq $0x0, 0x8(%rsp)
je 0x2af446
leaq 0x1(%r14), %rsi
movq %rbx, %rdi
callq 0x28c518
movq %rax, %r13
jmp 0x2af449
cmpl $0x5, %eax
je 0x2af6e2
jmp 0x2af6ec
movl 0x54(%rbx), %r12d
andl $0x12, %r12d
movl $0x5, %eax
jmp 0x2af4ac
xorl %r13d, %r13d
testq %r13, %r13
je 0x2af49d
movq %r13, %rdi
movq 0x8(%rsp), %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x17660
movb $0x0, (%r13,%r14)
leaq 0x30(%rsp), %r14
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x2874c0
movq 0x140(%r14), %rax
subq %r13, %rax
addq %r15, %rax
movq %rax, 0x140(%r14)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x28c3e7
jmp 0x2af4aa
addq 0x8(%rsp), %r14
movq %r14, 0x170(%rsp)
xorl %eax, %eax
testl %eax, %eax
je 0x2af4be
cmpl $0x5, %eax
je 0x2af6e2
jmp 0x2af6ec
movq %rbx, 0x20(%rsp)
cmpl $0x65, 0x48(%rsp)
jne 0x2af4d2
movl $0x0, 0x48(%rsp)
cmpb $0x0, 0x4d(%rsp)
je 0x2af5ad
movq 0x30(%rsp), %r12
cmpl $0x0, 0x28(%r12)
jle 0x2af5ad
xorl %ebp, %ebp
xorl %r13d, %r13d
movq 0x20(%r12), %rax
movq 0x8(%rax,%rbp), %r14
testq %r14, %r14
je 0x2af554
movb 0x10(%r14), %bl
testb %bl, %bl
je 0x2af573
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rax, 0x8(%rcx)
movq 0x18(%rcx), %rax
movq 0x50(%rax), %rax
movl 0x28(%rax), %eax
bswapl %eax
movq 0x20(%r12), %rcx
movq 0x18(%rcx,%rbp), %rcx
cmpl (%rcx), %eax
je 0x2af543
movq %r12, %rdi
movl %r13d, %esi
callq 0x2a4bc6
movl $0x11, 0x48(%rsp)
xorl %r15d, %r15d
testb %bl, %bl
jne 0x2af55a
movq %r14, %rdi
callq 0x2aec70
jmp 0x2af55a
movl $0x4, %r15d
testb $0x3, %r15b
jne 0x2af5ad
incq %r13
movslq 0x28(%r12), %rax
addq $0x20, %rbp
cmpq %rax, %r13
jl 0x2af4f3
jmp 0x2af5ad
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x28036f
testl %eax, %eax
je 0x2af50a
movl $0x1, %r15d
cmpl $0xc0a, %eax            # imm = 0xC0A
je 0x2af595
cmpl $0x7, %eax
jne 0x2af55a
movq %r12, %rdi
movl %eax, 0x18(%rsp)
callq 0x2824bb
cmpl $0x0, 0x18(%rsp)
jne 0x2af55a
jmp 0x2af50a
movq 0x210(%rsp), %rcx
testq %rcx, %rcx
je 0x2af5c5
movq 0x170(%rsp), %rax
movq %rax, (%rcx)
movq 0x20(%rsp), %rax
cmpb $0x0, 0xb5(%rax)
movl 0x1c(%rsp), %ecx
jne 0x2af642
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0x2af642
movq 0x170(%rsp), %rax
subq 0x8(%rsp), %rax
movb %cl, 0xc4(%rbx)
testb %cl, %cl
js 0x2af602
movl $0x0, 0x114(%rbx)
movslq %eax, %r14
cmpq $0x0, 0x8(%rsp)
je 0x2af61e
movq (%rbx), %rdi
leaq 0x1(%r14), %rsi
callq 0x28c518
movq %rax, %r12
jmp 0x2af621
xorl %r12d, %r12d
testq %r12, %r12
je 0x2af63b
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x17660
movb $0x0, (%r12,%r14)
movq %r12, 0xf0(%rbx)
movq 0x20(%rsp), %rbx
cmpb $0x0, 0x61(%rbx)
je 0x2af655
movl $0x7, 0x48(%rsp)
movl 0x48(%rsp), %r12d
movq 0x40(%rsp), %rdi
testl %r12d, %r12d
je 0x2af670
testq %rdi, %rdi
je 0x2af678
callq 0x281916
jmp 0x2af678
movq 0x28(%rsp), %rax
movq %rdi, (%rax)
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x2af6a1
leaq 0x122b48(%rip), %rdx    # 0x3d21d1
movq %rbx, %rdi
movl %r12d, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x27fc17
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x2af6d0
movl %r12d, 0x50(%rbx)
testl %r12d, %r12d
jne 0x2af6b4
cmpq $0x0, 0x160(%rbx)
je 0x2af6d5
movq %rbx, %rdi
movl %r12d, %esi
callq 0x28e696
jmp 0x2af6d5
movq 0x8(%rsi), %rax
movq %rax, 0x1b8(%rsp)
movq %rbx, %rdi
callq 0x28c3e7
movq 0x1b8(%rsp), %rsi
testq %rsi, %rsi
jne 0x2af6c1
leaq 0x30(%rsp), %rdi
callq 0x285775
movl %r12d, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq