// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: btreeCreateTable
static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){
  BtShared *pBt = p->pBt;
  MemPage *pRoot;
  Pgno pgnoRoot;
  int rc;
  int ptfFlags;          /* Page-type flage for the root page of new table */

  assert( sqlite3BtreeHoldsMutex(p) );
  assert( pBt->inTransaction==TRANS_WRITE );
  assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );

#ifdef SQLITE_OMIT_AUTOVACUUM
  rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
  if( rc ){
    return rc;
  }
#else
  if( pBt->autoVacuum ){
    Pgno pgnoMove;      /* Move a page here to make room for the root-page */
    MemPage *pPageMove; /* The page to move to. */

    /* Creating a new table may probably require moving an existing database
    ** to make room for the new tables root page. In case this page turns
    ** out to be an overflow page, delete all overflow page-map caches
    ** held by open cursors.
    */
    invalidateAllOverflowCache(pBt);

    /* Read the value of meta[3] from the database to determine where the
    ** root page of the new table should go. meta[3] is the largest root-page
    ** created so far, so the new root-page is (meta[3]+1).
    */
    sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
    pgnoRoot++;

    /* The new root-page may not be allocated on a pointer-map page, or the
    ** PENDING_BYTE page.
    */
    while( pgnoRoot==PTRMAP_PAGENO(pBt, pgnoRoot) ||
        pgnoRoot==PENDING_BYTE_PAGE(pBt) ){
      pgnoRoot++;
    }
    assert( pgnoRoot>=3 );

    /* Allocate a page. The page that currently resides at pgnoRoot will
    ** be moved to the allocated page (unless the allocated page happens
    ** to reside at pgnoRoot).
    */
    rc = allocateBtreePage(pBt, &pPageMove, &pgnoMove, pgnoRoot, BTALLOC_EXACT);
    if( rc!=SQLITE_OK ){
      return rc;
    }

    if( pgnoMove!=pgnoRoot ){
      /* pgnoRoot is the page that will be used for the root-page of
      ** the new table (assuming an error did not occur). But we were
      ** allocated pgnoMove. If required (i.e. if it was not allocated
      ** by extending the file), the current page at position pgnoMove
      ** is already journaled.
      */
      u8 eType = 0;
      Pgno iPtrPage = 0;

      /* Save the positions of any open cursors. This is required in
      ** case they are holding a reference to an xFetch reference
      ** corresponding to page pgnoRoot.  */
      rc = saveAllCursors(pBt, 0, 0);
      releasePage(pPageMove);
      if( rc!=SQLITE_OK ){
        return rc;
      }

      /* Move the page currently at pgnoRoot to pgnoMove. */
      rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
      if( rc!=SQLITE_OK ){
        return rc;
      }
      rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
      if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){
        rc = SQLITE_CORRUPT_BKPT;
      }
      if( rc!=SQLITE_OK ){
        releasePage(pRoot);
        return rc;
      }
      assert( eType!=PTRMAP_ROOTPAGE );
      assert( eType!=PTRMAP_FREEPAGE );
      rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove, 0);
      releasePage(pRoot);

      /* Obtain the page at pgnoRoot */
      if( rc!=SQLITE_OK ){
        return rc;
      }
      rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
      if( rc!=SQLITE_OK ){
        return rc;
      }
      rc = sqlite3PagerWrite(pRoot->pDbPage);
      if( rc!=SQLITE_OK ){
        releasePage(pRoot);
        return rc;
      }
    }else{
      pRoot = pPageMove;
    } 

    /* Update the pointer-map and meta-data with the new root-page number. */
    ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
    if( rc ){
      releasePage(pRoot);
      return rc;
    }

    /* When the new root page was allocated, page 1 was made writable in
    ** order either to increase the database filesize, or to decrement the
    ** freelist count.  Hence, the sqlite3BtreeUpdateMeta() call cannot fail.
    */
    assert( sqlite3PagerIswriteable(pBt->pPage1->pDbPage) );
    rc = sqlite3BtreeUpdateMeta(p, 4, pgnoRoot);
    if( NEVER(rc) ){
      releasePage(pRoot);
      return rc;
    }

  }else{
    rc = allocateBtreePage(pBt, &pRoot, &pgnoRoot, 1, 0);
    if( rc ) return rc;
  }
#endif
  assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
  if( createTabFlags & BTREE_INTKEY ){
    ptfFlags = PTF_INTKEY | PTF_LEAFDATA | PTF_LEAF;
  }else{
    ptfFlags = PTF_ZERODATA | PTF_LEAF;
  }
  zeroPage(pRoot, ptfFlags);
  sqlite3PagerUnref(pRoot->pDbPage);
  assert( (pBt->openFlags & BTREE_SINGLE)==0 || pgnoRoot==2 );
  *piTable = (int)pgnoRoot;
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x41303
movq -0x28(%rbp), %rdi
callq 0x2b910
movq -0x10(%rbp), %rdi
movl $0x4, %esi
leaq -0x34(%rbp), %rdx
callq 0xe510
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x2b950
movl -0x58(%rbp), %ecx
movl %eax, %edx
movb $0x1, %al
cmpl %edx, %ecx
movb %al, -0x51(%rbp)
je 0x41116
movl -0x34(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl 0x8f7d3(%rip), %eax     # 0xd08d0
movq -0x28(%rbp), %rcx
xorl %edx, %edx
divl 0x30(%rcx)
movl %eax, %ecx
movl -0x5c(%rbp), %eax
addl $0x1, %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x4111f
jmp 0x4112a
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x410d1
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %ecx
leaq -0x48(%rbp), %rsi
leaq -0x40(%rbp), %rdx
movl $0x1, %r8d
callq 0x2cef0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x41158
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41373
movl -0x40(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x4129d
movb $0x0, -0x49(%rbp)
movl $0x0, -0x50(%rbp)
movq -0x28(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2bad0
movl %eax, -0x38(%rbp)
movq -0x48(%rbp), %rdi
callq 0x29fd0
cmpl $0x0, -0x38(%rbp)
je 0x4119b
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41373
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x30(%rbp), %rdx
xorl %ecx, %ecx
callq 0x29ed0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x411c1
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41373
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x49(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x2cdf0
movl %eax, -0x38(%rbp)
movzbl -0x49(%rbp), %eax
cmpl $0x1, %eax
je 0x411ea
movzbl -0x49(%rbp), %eax
cmpl $0x2, %eax
jne 0x411f7
movl $0xde2d, %edi           # imm = 0xDE2D
callq 0x24410
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x41211
movq -0x30(%rbp), %rdi
callq 0x29fd0
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41373
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movb -0x49(%rbp), %al
movl -0x50(%rbp), %ecx
movl -0x40(%rbp), %r8d
xorl %r9d, %r9d
movzbl %al, %edx
callq 0x2d7d0
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x29fd0
cmpl $0x0, -0x38(%rbp)
je 0x4124b
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41373
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x30(%rbp), %rdx
xorl %ecx, %ecx
callq 0x29ed0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x41271
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41373
movq -0x30(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0xef80
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x4129b
movq -0x30(%rbp), %rdi
callq 0x29fd0
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41373
jmp 0x412a5
movq -0x48(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %esi
movl $0x1, %edx
xorl %ecx, %ecx
leaq -0x38(%rbp), %r8
callq 0x2dd40
cmpl $0x0, -0x38(%rbp)
je 0x412d6
movq -0x30(%rbp), %rdi
callq 0x29fd0
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41373
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %edx
movl $0x4, %esi
callq 0xed20
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x41301
movq -0x30(%rbp), %rdi
callq 0x29fd0
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41373
jmp 0x4132f
movq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x34(%rbp), %rdx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x2cef0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x4132d
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41373
jmp 0x4132f
movl -0x1c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x41343
movl $0xd, -0x3c(%rbp)
jmp 0x4134a
movl $0xa, -0x3c(%rbp)
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x2a920
movq -0x30(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0xec30
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)