// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3_initialize
SQLITE_API int sqlite3_initialize(void){
  MUTEX_LOGIC( sqlite3_mutex *pMaster; )       /* The main static mutex */
  int rc;                                      /* Result code */
#ifdef SQLITE_EXTRA_INIT
  int bRunExtraInit = 0;                       /* Extra initialization needed */
#endif

#ifdef SQLITE_OMIT_WSD
  rc = sqlite3_wsd_init(4096, 24);
  if( rc!=SQLITE_OK ){
    return rc;
  }
#endif

  /* If SQLite is already completely initialized, then this call
  ** to sqlite3_initialize() should be a no-op.  But the initialization
  ** must be complete.  So isInit must not be set until the very end
  ** of this routine.
  */
  if( sqlite3GlobalConfig.isInit ) return SQLITE_OK;

#ifdef SQLITE_ENABLE_SQLLOG
  {
    extern void sqlite3_init_sqllog(void);
    sqlite3_init_sqllog();
  }
#endif

  /* Make sure the mutex subsystem is initialized.  If unable to 
  ** initialize the mutex subsystem, return early with the error.
  ** If the system is so sick that we are unable to allocate a mutex,
  ** there is not much SQLite is going to be able to do.
  **
  ** The mutex subsystem must take care of serializing its own
  ** initialization.
  */
  rc = sqlite3MutexInit();
  if( rc ) return rc;

  /* Initialize the malloc() system and the recursive pInitMutex mutex.
  ** This operation is protected by the STATIC_MASTER mutex.  Note that
  ** MutexAlloc() is called for a static mutex prior to initializing the
  ** malloc subsystem - this implies that the allocation of a static
  ** mutex must not require support from the malloc subsystem.
  */
  MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
  sqlite3_mutex_enter(pMaster);
  sqlite3GlobalConfig.isMutexInit = 1;
  if( !sqlite3GlobalConfig.isMallocInit ){
    rc = sqlite3MallocInit();
  }
  if( rc==SQLITE_OK ){
    sqlite3GlobalConfig.isMallocInit = 1;
    if( !sqlite3GlobalConfig.pInitMutex ){
      sqlite3GlobalConfig.pInitMutex =
           sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
      if( sqlite3GlobalConfig.bCoreMutex && !sqlite3GlobalConfig.pInitMutex ){
        rc = SQLITE_NOMEM;
      }
    }
  }
  if( rc==SQLITE_OK ){
    sqlite3GlobalConfig.nRefInitMutex++;
  }
  sqlite3_mutex_leave(pMaster);

  /* If rc is not SQLITE_OK at this point, then either the malloc
  ** subsystem could not be initialized or the system failed to allocate
  ** the pInitMutex mutex. Return an error in either case.  */
  if( rc!=SQLITE_OK ){
    return rc;
  }

  /* Do the rest of the initialization under the recursive mutex so
  ** that we will be able to handle recursive calls into
  ** sqlite3_initialize().  The recursive calls normally come through
  ** sqlite3_os_init() when it invokes sqlite3_vfs_register(), but other
  ** recursive calls might also be possible.
  **
  ** IMPLEMENTATION-OF: R-00140-37445 SQLite automatically serializes calls
  ** to the xInit method, so the xInit method need not be threadsafe.
  **
  ** The following mutex is what serializes access to the appdef pcache xInit
  ** methods.  The sqlite3_pcache_methods.xInit() all is embedded in the
  ** call to sqlite3PcacheInitialize().
  */
  sqlite3_mutex_enter(sqlite3GlobalConfig.pInitMutex);
  if( sqlite3GlobalConfig.isInit==0 && sqlite3GlobalConfig.inProgress==0 ){
    FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
    sqlite3GlobalConfig.inProgress = 1;
    memset(pHash, 0, sizeof(sqlite3GlobalFunctions));
    sqlite3RegisterGlobalFunctions();
    if( sqlite3GlobalConfig.isPCacheInit==0 ){
      rc = sqlite3PcacheInitialize();
    }
    if( rc==SQLITE_OK ){
      sqlite3GlobalConfig.isPCacheInit = 1;
      rc = sqlite3OsInit();
    }
    if( rc==SQLITE_OK ){
      sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, 
          sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
      sqlite3GlobalConfig.isInit = 1;
#ifdef SQLITE_EXTRA_INIT
      bRunExtraInit = 1;
#endif
    }
    sqlite3GlobalConfig.inProgress = 0;
  }
  sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);

  /* Go back under the static mutex and clean up the recursive
  ** mutex to prevent a resource leak.
  */
  sqlite3_mutex_enter(pMaster);
  sqlite3GlobalConfig.nRefInitMutex--;
  if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
    assert( sqlite3GlobalConfig.nRefInitMutex==0 );
    sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex);
    sqlite3GlobalConfig.pInitMutex = 0;
  }
  sqlite3_mutex_leave(pMaster);

  /* The following is just a sanity check to make sure SQLite has
  ** been compiled correctly.  It is important to run this code, but
  ** we don't want to run it too often and soak up CPU cycles for no
  ** reason.  So we run it once during initialization.
  */
#ifndef NDEBUG
#ifndef SQLITE_OMIT_FLOATING_POINT
  /* This section of code's only "output" is via assert() statements. */
  if ( rc==SQLITE_OK ){
    u64 x = (((u64)1)<<63)-1;
    double y;
    assert(sizeof(x)==8);
    assert(sizeof(x)==sizeof(y));
    memcpy(&y, &x, 8);
    assert( sqlite3IsNaN(y) );
  }
#endif
#endif

  /* Do extra initialization steps requested by the SQLITE_EXTRA_INIT
  ** compile-time option.
  */
#ifdef SQLITE_EXTRA_INIT
  if( bRunExtraInit ){
    int SQLITE_EXTRA_INIT(const char*);
    rc = SQLITE_EXTRA_INIT(0);
  }
#endif

  return rc;
}

// Assembly:
xorl %eax, %eax
cmpl $0x0, 0x7de17(%rip)     # 0x87560
je 0x974c
retq
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl $0x1, 0x7de08(%rip)     # 0x87568
cmpl $0x0, 0x7de05(%rip)     # 0x8756c
je 0x9905
movl $0x1, 0x7ddf5(%rip)     # 0x8756c
cmpq $0x0, 0x7ddf9(%rip)     # 0x87578
jne 0x978c
movq $0x8, 0x7ddec(%rip) # 0x87578
movl 0x7ddee(%rip), %ecx     # 0x87580
incl %ecx
movl %ecx, 0x7dde6(%rip)     # 0x87580
movl 0x7ddc4(%rip), %edx     # 0x87564
xorl %eax, %eax
orl 0x7ddb8(%rip), %edx     # 0x87560
jne 0x9a57
movl $0x1, 0x7ddac(%rip)     # 0x87564
leaq 0x7f6d9(%rip), %rbx     # 0x88e98
xorl %r14d, %r14d
movl $0xb8, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x81e0
leaq 0x7e2e8(%rip), %r15     # 0x87ac0
cmpq $0xee8, %r14            # imm = 0xEE8
je 0x97f3
leaq (%r15,%r14), %rsi
movq %rbx, %rdi
callq 0x59527
addq $0x48, %r14
jmp 0x97d8
xorl %r14d, %r14d
leaq 0x7f1b3(%rip), %r15     # 0x889b0
leaq 0x7f694(%rip), %rbx     # 0x88e98
cmpq $0x240, %r14            # imm = 0x240
je 0x981f
leaq (%r15,%r14), %rsi
movq %rbx, %rdi
callq 0x59527
addq $0x48, %r14
jmp 0x9804
xorl %r14d, %r14d
leaq 0x7f3c7(%rip), %r15     # 0x88bf0
leaq 0x7f668(%rip), %rbx     # 0x88e98
cmpq $0xd8, %r14
je 0x984b
leaq (%r15,%r14), %rsi
movq %rbx, %rdi
callq 0x59527
addq $0x48, %r14
jmp 0x9830
cmpl $0x0, 0x7dd1e(%rip)     # 0x87570
je 0x9a08
movl $0x1, 0x7dd0e(%rip)     # 0x87570
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x9c1c
testq %rax, %rax
je 0x9a47
movq %rax, %rdi
callq 0x9c7b
callq 0xb1f7
cmpl $0x0, 0x7f70f(%rip)     # 0x88f98
je 0x9a39
movq 0x7dcb2(%rip), %rsi     # 0x87548
movl 0x7dcb8(%rip), %ecx     # 0x87554
movslq 0x7dcad(%rip), %rdi     # 0x87550
andq $-0x8, %rdi
movl %edi, 0x7f6ef(%rip)     # 0x88f9c
movl %ecx, 0x7f715(%rip)     # 0x88fc8
movl %ecx, 0x7f6e7(%rip)     # 0x88fa0
cmpl $0x5a, %ecx
jg 0x98cc
pushq $0xa
popq %r8
movl %ecx, %eax
cltd
idivl %r8d
movl %eax, %ebx
incl %ebx
movl %ebx, 0x7f6d2(%rip)     # 0x88fa4
movq %rsi, 0x7f6cf(%rip)     # 0x88fa8
andq $0x0, 0x7f6df(%rip)     # 0x88fc0
andl $0x0, 0x7f6e4(%rip)     # 0x88fcc
xorl %eax, %eax
subl $0x1, %ecx
jb 0x9a32
movq %rax, (%rsi)
movq %rsi, 0x7f6c3(%rip)     # 0x88fc0
movq %rsi, %rax
addq %rdi, %rsi
jmp 0x98ea
cmpq $0x0, 0x7db13(%rip)     # 0x87420
jne 0x9914
callq 0x1308f
xorps %xmm0, %xmm0
movups %xmm0, 0x7f43a(%rip)    # 0x88d58
andq $0x0, 0x7f442(%rip)     # 0x88d68
movups %xmm0, 0x7f41b(%rip)    # 0x88d48
movups %xmm0, 0x7f404(%rip)    # 0x88d38
cmpl $0x0, 0x7dac9(%rip)     # 0x87404
je 0x9948
movq $0x8, 0x7f3f0(%rip) # 0x88d38
movq 0x7dbe9(%rip), %rax     # 0x87538
testq %rax, %rax
setne %sil
movl 0x7dbe4(%rip), %edx     # 0x87540
cmpl $0x64, %edx
setge %dil
movl 0x7dbdb(%rip), %ecx     # 0x87544
testl %ecx, %ecx
setg %r8b
andb %dil, %r8b
andb %sil, %r8b
cmpb $0x1, %r8b
jne 0x99a9
movl %edx, %edx
andl $0x7ffffff8, %edx       # imm = 0x7FFFFFF8
movl %edx, 0x7dbb7(%rip)     # 0x87540
movq %rax, 0x7f3d0(%rip)     # 0x88d60
movl %ecx, 0x7f3d2(%rip)     # 0x88d68
decl %ecx
subl $0x1, %ecx
jb 0x99ba
leaq (%rax,%rdx), %rsi
movq %rsi, (%rax)
movq %rsi, %rax
jmp 0x9998
andq $0x0, 0x7f3a7(%rip)     # 0x88d58
movups %xmm0, 0x7db80(%rip)    # 0x87538
jmp 0x99c9
andq $0x0, (%rax)
addq $0x8, %rax
movq %rax, 0x7f38f(%rip)     # 0x88d58
cmpq $0x0, 0x7db77(%rip)     # 0x87548
je 0x99e8
cmpl $0x200, 0x7db73(%rip)   # imm = 0x200
jl 0x99e8
cmpl $0x0, 0x7db6e(%rip)     # 0x87554
jg 0x99f2
xorps %xmm0, %xmm0
movups %xmm0, 0x7db56(%rip)    # 0x87548
movq 0x7da5f(%rip), %rdi     # 0x87458
callq *0x7da49(%rip)          # 0x87448
testl %eax, %eax
jne 0x9a6d
jmp 0x976d
movq 0x7daa9(%rip), %rax     # 0x874b8
testq %rax, %rax
jne 0x9a20
callq 0x130a7
movq 0x7da98(%rip), %rax     # 0x874b8
movq 0x7da89(%rip), %rdi     # 0x874b0
callq *%rax
testl %eax, %eax
jne 0x9a4a
jmp 0x9858
movq %rsi, 0x7f577(%rip)     # 0x88fb0
movl $0x1, 0x7db1d(%rip)     # 0x87560
xorl %eax, %eax
jmp 0x9a4a
pushq $0x7
popq %rax
andl $0x0, 0x7db13(%rip)     # 0x87564
movl 0x7db29(%rip), %ecx     # 0x87580
leal -0x1(%rcx), %edx
movl %edx, 0x7db20(%rip)     # 0x87580
cmpl $0x1, %ecx
jg 0x9a6d
andq $0x0, 0x7db0b(%rip)     # 0x87578
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq