// File: /workspace/github_c_makefile_star2_O1/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 0x45902
movq %rsi, %r12
movq %rdi, %r15
movq (%rdi), %r14
callq 0x635df
movq $0x0, 0x270(%r15)
cmpl $0x0, 0x4c(%rbx)
jle 0x45902
cmpb $0x0, 0x99(%r14)
je 0x45871
movq (%rbx), %rsi
movq 0x68(%rbx), %rdi
testq %rsi, %rsi
je 0x458dd
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rsi, %rax
incl %edx
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x4585e
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
jmp 0x458df
testq %r12, %r12
je 0x4588d
movl (%r12), %eax
subl 0x250(%r15), %eax
addl 0x8(%r12), %eax
movl %eax, 0x258(%r15)
leaq 0x250(%r15), %rdx
leaq 0x37475(%rip), %rsi     # 0x7cd10
xorl %r12d, %r12d
movq %r14, %rdi
xorl %eax, %eax
callq 0x117e2
movq %rax, %r13
movq 0x68(%rbx), %rax
testq %rax, %rax
je 0x45911
movl 0x28(%r14), %ecx
testl %ecx, %ecx
jle 0x45917
movq 0x20(%r14), %rdx
addq $0x18, %rdx
xorl %r12d, %r12d
cmpq %rax, (%rdx)
je 0x45917
incq %r12
addq $0x20, %rdx
cmpq %r12, %rcx
jne 0x458c7
movl %ecx, %r12d
jmp 0x45917
xorl %edx, %edx
addq $0x8, %rdi
movq %rbx, %rcx
callq 0x33cea
testq %rax, %rax
je 0x458f7
movb $0x1, 0x50(%r14)
jmp 0x45902
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
movq 0x20(%r14), %rax
movslq %r12d, %rsi
movq %rsi, -0x30(%rbp)
movq %rsi, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rdx
cmpl $0x1, %esi
leaq 0x345e2(%rip), %rax     # 0x79f19
leaq 0x345ee(%rip), %rcx     # 0x79f2c
cmoveq %rax, %rcx
movq (%rbx), %r8
movl 0x1a0(%r15), %r10d
leaq 0x373d5(%rip), %rsi     # 0x7cd28
movq %r15, %rdi
movq %r8, %r9
xorl %eax, %eax
pushq %r10
pushq %r13
callq 0x465b3
addq $0x10, %rsp
movq %r14, %rdi
movq %r13, %rsi
callq 0x9c3a
movq %r15, %rdi
callq 0x45b57
movq %rax, %r13
movq %r15, %rdi
movq -0x30(%rbp), %r15
movl %r15d, %esi
callq 0x466e1
movq %r13, %rdi
movl $0x84, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movq (%rbx), %rdx
leaq 0x373d5(%rip), %rsi     # 0x7cd80
movq %r14, %rdi
xorl %eax, %eax
callq 0x117e2
movq %r13, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x4679b
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x459ec
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %rbx, %rax
incl %r14d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x459d4
andl $0x3fffffff, %r14d      # imm = 0x3FFFFFFF
incl %r14d
jmp 0x459f2
movl $0x1, %r14d
movq %r13, %rdi
movl $0x87, %esi
movl %r12d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
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 0x11975