// File: /workspace/github_c_makefile_star2_O3/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 0x45c93
movq %rsi, %r12
movq %rdi, %r15
movq (%rdi), %r14
callq 0x63478
movq $0x0, 0x270(%r15)
cmpl $0x0, 0x4c(%rbx)
jle 0x45c93
cmpb $0x0, 0x99(%r14)
je 0x45be0
movq (%rbx), %rsi
movq 0x68(%rbx), %rdi
testq %rsi, %rsi
je 0x45c6e
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rsi, %rax
incl %edx
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x45bca
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
jmp 0x45c70
testq %r12, %r12
je 0x45bfc
movl (%r12), %eax
subl 0x250(%r15), %eax
addl 0x8(%r12), %eax
movl %eax, 0x258(%r15)
leaq 0x250(%r15), %rdx
leaq 0x37106(%rip), %rsi     # 0x7cd10
xorl %r12d, %r12d
movq %r14, %rdi
xorl %eax, %eax
callq 0x11900
movq %rax, %r13
movq 0x68(%rbx), %rcx
testq %rcx, %rcx
je 0x45ca2
movl 0x28(%r14), %edx
testl %edx, %edx
jle 0x45ca8
movq 0x20(%r14), %rax
leaq 0x18(%rax), %rsi
xorl %r12d, %r12d
cmpq %rcx, (%rsi)
je 0x45c4a
incq %r12
addq $0x20, %rsi
cmpq %r12, %rdx
jne 0x45c36
movl %edx, %r12d
movslq %r12d, %rcx
movq %rcx, %rdx
shlq $0x5, %rdx
addq %rdx, %rax
cmpl $0x1, %ecx
leaq 0x342b8(%rip), %rdx     # 0x79f19
leaq 0x342c4(%rip), %rcx     # 0x79f2c
cmoveq %rdx, %rcx
jmp 0x45cba
xorl %edx, %edx
addq $0x8, %rdi
movq %rbx, %rcx
callq 0x34400
testq %rax, %rax
je 0x45c88
movb $0x1, 0x50(%r14)
jmp 0x45c93
movq $0x0, 0x238(%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xfff0bdc0, %r12d      # imm = 0xFFF0BDC0
movslq %r12d, %rax
shlq $0x5, %rax
addq 0x20(%r14), %rax
leaq 0x34272(%rip), %rcx     # 0x79f2c
movq (%rax), %rdx
movq (%rbx), %r8
movl 0x1a0(%r15), %r10d
leaq 0x3705a(%rip), %rsi     # 0x7cd28
movq %r15, %rdi
movq %r8, %r9
xorl %eax, %eax
pushq %r10
pushq %r13
callq 0x468e4
addq $0x10, %rsp
movq %r14, %rdi
movq %r13, %rsi
callq 0x9ca4
movq %r15, %rdi
callq 0x45ece
movq %rax, %r13
movq %r15, %rdi
movl %r12d, %esi
callq 0x46a12
movq %r13, %rdi
movl $0x84, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq (%rbx), %rdx
leaq 0x3705e(%rip), %rsi     # 0x7cd80
movq %r14, %rdi
xorl %eax, %eax
callq 0x11900
movq %r13, %rdi
movl %r12d, %esi
movq %rax, %rdx
callq 0x46acc
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x45d63
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %rbx, %rax
incl %r14d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x45d4b
andl $0x3fffffff, %r14d      # imm = 0x3FFFFFFF
incl %r14d
jmp 0x45d69
movl $0x1, %r14d
movq %r13, %rdi
movl $0x87, %esi
movl %r12d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq %r13, %rdi
movl %eax, %esi
movq %rbx, %rdx
movl %r14d, %ecx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11a9f