// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3VtabFinishParse
SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
  Table *pTab = pParse->pNewTable;  /* The table being constructed */
  sqlite3 *db = pParse->db;         /* The database connection */

  if( pTab==0 ) return;
  addArgumentToVtab(pParse);
  pParse->sArg.z = 0;
  if( pTab->nModuleArg<1 ) return;
  
  /* If the CREATE VIRTUAL TABLE statement is being entered for the
  ** first time (in other words if the virtual table is actually being
  ** created now instead of just being read out of sqlite_master) then
  ** do additional initialization work and store the statement text
  ** in the sqlite_master table.
  */
  if( !db->init.busy ){
    char *zStmt;
    char *zWhere;
    int iDb;
    Vdbe *v;

    /* Compute the complete text of the CREATE VIRTUAL TABLE statement */
    if( pEnd ){
      pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
    }
    zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);

    /* A slot for the record has already been allocated in the 
    ** SQLITE_MASTER table.  We just need to update that slot with all
    ** the information we've collected.  
    **
    ** The VM register number pParse->regRowid holds the rowid of an
    ** entry in the sqlite_master table tht was created for this vtab
    ** by sqlite3StartTable().
    */
    iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
    sqlite3NestedParse(pParse,
      "UPDATE %Q.%s "
         "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
       "WHERE rowid=#%d",
      db->aDb[iDb].zName, SCHEMA_TABLE(iDb),
      pTab->zName,
      pTab->zName,
      zStmt,
      pParse->regRowid
    );
    sqlite3DbFree(db, zStmt);
    v = sqlite3GetVdbe(pParse);
    sqlite3ChangeCookie(pParse, iDb);

    sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
    zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
    sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
    sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0, 
                         pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
  }

  /* If we are rereading the sqlite_master table create the in-memory
  ** record of the table. The xConnect() method is not called until
  ** the first time the virtual table is used in an SQL statement. This
  ** allows a schema that contains virtual tables to be loaded before
  ** the required virtual table implementations are registered.  */
  else {
    Table *pOld;
    Schema *pSchema = pTab->pSchema;
    const char *zName = pTab->zName;
    int nName = sqlite3Strlen30(zName);
    assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
    pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab);
    if( pOld ){
      db->mallocFailed = 1;
      assert( pTab==pOld );  /* Malloc must have failed inside HashInsert() */
      return;
    }
    pParse->pNewTable = 0;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x238(%rdi), %rbx
testq %rbx, %rbx
je 0x41ee5
movq %rsi, %r12
movq %rdi, %r15
movq (%rdi), %r14
callq 0x57e34
andq $0x0, 0x270(%r15)
cmpl $0x0, 0x4c(%rbx)
jle 0x41ee5
cmpb $0x0, 0x99(%r14)
je 0x41dcc
movq (%rbx), %r12
movq 0x68(%rbx), %r13
movq %r12, %rdi
callq 0x8f8e
addq $0x8, %r13
movq %r13, %rdi
movq %r12, %rsi
movl %eax, %edx
movq %rbx, %rcx
callq 0x2f1a7
testq %rax, %rax
je 0x41edd
movb $0x1, 0x50(%r14)
jmp 0x41ee5
testq %r12, %r12
je 0x41de8
movl (%r12), %eax
subl 0x250(%r15), %eax
addl 0x8(%r12), %eax
movl %eax, 0x258(%r15)
leaq 0x250(%r15), %rdx
leaq 0x2cf3a(%rip), %rsi     # 0x6ed30
movq %r14, %rdi
xorl %eax, %eax
callq 0x10594
movq %rax, %r13
movq 0x68(%rbx), %rsi
movq %r14, %rdi
callq 0x1064e
movq 0x20(%r14), %rcx
movslq %eax, %r12
movq %r12, %rax
shlq $0x5, %rax
movq (%rcx,%rax), %rdx
cmpl $0x1, %r12d
leaq 0x2a10d(%rip), %rax     # 0x6bf39
leaq 0x2a119(%rip), %rcx     # 0x6bf4c
cmoveq %rax, %rcx
movq (%rbx), %r8
movl 0x1a0(%r15), %r10d
leaq 0x2cf00(%rip), %rsi     # 0x6ed48
movq %r15, %rdi
movq %r8, %r9
xorl %eax, %eax
pushq %r10
pushq %r13
callq 0x4268c
popq %rax
popq %rcx
movq %r14, %rdi
movq %r13, %rsi
callq 0x968b
movq %r15, %rdi
callq 0x41ef4
movq %rax, %r13
movq %r15, %rdi
movl %r12d, %esi
callq 0x427b7
movq %r13, %rdi
movl $0x84, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x41f42
movq (%rbx), %rdx
leaq 0x2cf09(%rip), %rsi     # 0x6eda0
movq %r14, %rdi
xorl %eax, %eax
callq 0x10594
movq %r13, %rdi
movl %r12d, %esi
movq %rax, %rdx
callq 0x42823
movq (%rbx), %rbx
movq %rbx, %rdi
callq 0x8f8e
incl %eax
subq $0x8, %rsp
movq %r13, %rdi
movl $0x87, %esi
movl %r12d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
pushq %rax
callq 0x41fd2
popq %rcx
popq %rdx
jmp 0x41ee5
andq $0x0, 0x238(%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq