// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3CreateView
SQLITE_PRIVATE void sqlite3CreateView(
  Parse *pParse,     /* The parsing context */
  Token *pBegin,     /* The CREATE token that begins the statement */
  Token *pName1,     /* The token that holds the name of the view */
  Token *pName2,     /* The token that holds the name of the view */
  Select *pSelect,   /* A SELECT statement that will become the new view */
  int isTemp,        /* TRUE for a TEMPORARY view */
  int noErr          /* Suppress error messages if VIEW already exists */
){
  Table *p;
  int n;
  const char *z;
  Token sEnd;
  DbFixer sFix;
  Token *pName = 0;
  int iDb;
  sqlite3 *db = pParse->db;

  if( pParse->nVar>0 ){
    sqlite3ErrorMsg(pParse, "parameters are not allowed in views");
    sqlite3SelectDelete(db, pSelect);
    return;
  }
  sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
  p = pParse->pNewTable;
  if( p==0 || pParse->nErr ){
    sqlite3SelectDelete(db, pSelect);
    return;
  }
  sqlite3TwoPartName(pParse, pName1, pName2, &pName);
  iDb = sqlite3SchemaToIndex(db, p->pSchema);
  if( sqlite3FixInit(&sFix, pParse, iDb, "view", pName)
    && sqlite3FixSelect(&sFix, pSelect)
  ){
    sqlite3SelectDelete(db, pSelect);
    return;
  }

  /* Make a copy of the entire SELECT statement that defines the view.
  ** This will force all the Expr.token.z values to be dynamically
  ** allocated rather than point to the input string - which means that
  ** they will persist after the current sqlite3_exec() call returns.
  */
  p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
  sqlite3SelectDelete(db, pSelect);
  if( db->mallocFailed ){
    return;
  }
  if( !db->init.busy ){
    sqlite3ViewGetColumnNames(pParse, p);
  }

  /* Locate the end of the CREATE VIEW statement.  Make sEnd point to
  ** the end.
  */
  sEnd = pParse->sLastToken;
  if( ALWAYS(sEnd.z[0]!=0) && sEnd.z[0]!=';' ){
    sEnd.z += sEnd.n;
  }
  sEnd.n = 0;
  n = (int)(sEnd.z - pBegin->z);
  z = pBegin->z;
  while( ALWAYS(n>0) && sqlite3Isspace(z[n-1]) ){ n--; }
  sEnd.z = &z[n-1];
  sEnd.n = 1;

  /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
  sqlite3EndTable(pParse, 0, &sEnd, 0);
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r15
movq %rdi, %rbx
movl 0x10(%rbp), %eax
movq $0x0, -0x48(%rbp)
movq (%rdi), %r12
cmpl $0x0, 0x1f8(%rdi)
jle 0x3b859
leaq 0x40085(%rip), %rsi     # 0x7b8bb
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11724
movq %r12, %rdi
movq %r15, %rsi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x340e4
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, -0x50(%rbp)
movl %eax, (%rsp)
movq %rbx, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movl %r9d, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x393b1
movq 0x238(%rbx), %rax
testq %rax, %rax
je 0x3b840
cmpl $0x0, 0x50(%rbx)
jne 0x3b840
leaq -0x48(%rbp), %rcx
movq %rbx, %rdi
movq %rax, -0x30(%rbp)
movq %r13, %rsi
movq %r14, %rdx
callq 0x45ec1
movq -0x30(%rbp), %rax
movq 0x68(%rax), %rcx
testq %rcx, %rcx
je 0x3b8de
movl 0x28(%r12), %edx
testl %edx, %edx
jle 0x3b8e5
movq 0x20(%r12), %rsi
addq $0x18, %rsi
xorl %eax, %eax
cmpq %rcx, (%rsi)
je 0x3b8e7
incq %rax
addq $0x20, %rsi
cmpq %rax, %rdx
jne 0x3b8c9
movl %edx, %eax
jmp 0x3b8e7
movl $0xfff0bdc0, %eax       # imm = 0xFFF0BDC0
jmp 0x3b8e7
xorl %eax, %eax
testl %eax, %eax
sets %cl
cmpl $0x1, %eax
sete %dl
orb %cl, %dl
jne 0x3b93e
movq -0x48(%rbp), %rcx
movq (%rbx), %rdx
leaq -0x78(%rbp), %rdi
movq %rbx, (%rdi)
movq 0x20(%rdx), %rdx
movl %eax, %eax
shlq $0x5, %rax
movq (%rdx,%rax), %rsi
movq %rsi, 0x10(%rdi)
movq 0x18(%rdx,%rax), %rax
movq %rax, 0x8(%rdi)
leaq 0x413d2(%rip), %rax     # 0x7ccf8
movq %rax, 0x18(%rdi)
movq %rcx, 0x20(%rdi)
movq %r15, %rsi
callq 0x4c0a3
testl %eax, %eax
jne 0x3b840
movq %r12, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x4841f
movq -0x30(%rbp), %rcx
movq %rax, 0x18(%rcx)
movq %r12, %rdi
movq %r15, %rsi
callq 0x340e4
cmpb $0x0, 0x50(%r12)
jne 0x3ba03
cmpb $0x0, 0x99(%r12)
jne 0x3b984
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x4a326
movups 0x260(%rbx), %xmm0
movaps %xmm0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movzbl (%rax), %ecx
testl %ecx, %ecx
je 0x3b9a9
cmpl $0x3b, %ecx
je 0x3b9a9
movl -0x38(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x40(%rbp), %ecx
movq -0x50(%rbp), %rax
movq (%rax), %rax
subl %eax, %ecx
testl %ecx, %ecx
jle 0x3b9e0
leaq 0x3a599(%rip), %rdx     # 0x75f60
movl %ecx, %esi
movzbl -0x1(%rax,%rsi), %esi
testb $0x1, (%rsi,%rdx)
je 0x3b9e0
leal -0x1(%rcx), %esi
cmpl $0x1, %ecx
movl %esi, %ecx
jg 0x3b9c7
xorl %ecx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
decq %rax
leaq -0x40(%rbp), %rdx
movq %rax, (%rdx)
movl $0x1, 0x8(%rdx)
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x39877
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq