// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3_initialize
SQLITE_API int sqlite3_initialize(void){
  MUTEX_LOGIC( sqlite3_mutex *pMainMtx; )      /* 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 the following assert() fails on some obscure processor/compiler
  ** combination, the work-around is to set the correct pointer
  ** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */
  assert( SQLITE_PTRSIZE==sizeof(char*) );

  /* 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 ){
    sqlite3MemoryBarrier();
    return SQLITE_OK;
  }

  /* 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_MAIN 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( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
  sqlite3_mutex_enter(pMainMtx);
  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_BKPT;
      }
    }
  }
  if( rc==SQLITE_OK ){
    sqlite3GlobalConfig.nRefInitMutex++;
  }
  sqlite3_mutex_leave(pMainMtx);

  /* 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 ){
    sqlite3GlobalConfig.inProgress = 1;
#ifdef SQLITE_ENABLE_SQLLOG
    {
      extern void sqlite3_init_sqllog(void);
      sqlite3_init_sqllog();
    }
#endif
    memset(&sqlite3BuiltinFunctions, 0, sizeof(sqlite3BuiltinFunctions));
    sqlite3RegisterBuiltinFunctions();
    if( sqlite3GlobalConfig.isPCacheInit==0 ){
      rc = sqlite3PcacheInitialize();
    }
    if( rc==SQLITE_OK ){
      sqlite3GlobalConfig.isPCacheInit = 1;
      rc = sqlite3OsInit();
    }
#ifdef SQLITE_ENABLE_DESERIALIZE
    if( rc==SQLITE_OK ){
      rc = sqlite3MemdbInit();
    }
#endif
    if( rc==SQLITE_OK ){
      sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
          sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
      sqlite3MemoryBarrier();
      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(pMainMtx);
  sqlite3GlobalConfig.nRefInitMutex--;
  if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
    assert( sqlite3GlobalConfig.nRefInitMutex==0 );
    sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex);
    sqlite3GlobalConfig.pInitMutex = 0;
  }
  sqlite3_mutex_leave(pMainMtx);

  /* 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:
pushq %r14
pushq %rbx
pushq %rax
xorl %ebx, %ebx
cmpl $0x0, 0x249200(%rip)    # 0x4bb7b4
je 0x2725c0
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movl $0x1, 0x2491f2(%rip)    # 0x4bb7bc
cmpl $0x0, 0x2491ef(%rip)    # 0x4bb7c0
je 0x272778
movl $0x1, 0x2491df(%rip)    # 0x4bb7c0
cmpq $0x0, 0x2491e7(%rip)    # 0x4bb7d0
jne 0x2725f6
movq $0x8, 0x2491da(%rip) # 0x4bb7d0
movl 0x2491cc(%rip), %eax    # 0x4bb7c8
incl %eax
movl %eax, 0x2491c4(%rip)    # 0x4bb7c8
movl 0x2491ae(%rip), %ecx    # 0x4bb7b8
xorl %ebx, %ebx
orl 0x2491a2(%rip), %ecx    # 0x4bb7b4
jne 0x2728d1
movl $0x1, 0x249196(%rip)    # 0x4bb7b8
leaq 0x24c6bf(%rip), %rdi    # 0x4bece8
movl $0xb8, %edx
xorl %esi, %esi
callq 0x173a0
leaq 0x24a944(%rip), %rdi    # 0x4bcf80
movl $0x3, %esi
callq 0x2ec016
leaq 0x24aa13(%rip), %rdi    # 0x4bd060
movl $0xf, %esi
callq 0x2ec016
leaq 0x24ae42(%rip), %rdi    # 0x4bd4a0
movl $0x8, %esi
callq 0x2ec016
leaq 0x249751(%rip), %rdi    # 0x4bbdc0
movl $0x3f, %esi
callq 0x2ec016
cmpl $0x0, 0x249144(%rip)    # 0x4bb7c4
je 0x272816
movl $0x1, 0x249134(%rip)    # 0x4bb7c4
callq 0x2725a7
movl $0x7, %ebx
testl %eax, %eax
jne 0x2728c1
movl $0xa, %edi
callq 0x272ae6
testq %rax, %rax
je 0x2728c1
movq %rax, %r14
cmpl $0x0, 0x248fa1(%rip)    # 0x4bb660
je 0x2726da
movq %r14, %rdi
callq *0x248fce(%rip)         # 0x4bb698
cltq
subq %rax, 0x24c425(%rip)    # 0x4beaf8
decq 0x24c466(%rip)          # 0x4beb40
movq %r14, %rdi
callq *0x248fa5(%rip)         # 0x4bb688
xorl %ebx, %ebx
leaq 0x249134(%rip), %r14    # 0x4bb820
leaq (%r14,%rbx), %rdi
xorl %esi, %esi
testq %rbx, %rbx
sete %sil
callq 0x2728f3
addq $0xa8, %rbx
cmpq $0x2a0, %rbx            # imm = 0x2A0
jne 0x2726ec
cmpl $0x0, 0x24c6eb(%rip)    # 0x4bee00
je 0x2728b5
movq 0x249076(%rip), %rax    # 0x4bb798
movl 0x249078(%rip), %edx    # 0x4bb7a0
xorl %ecx, %ecx
testq %rax, %rax
je 0x272735
movl 0x24906f(%rip), %ecx    # 0x4bb7a4
andl $-0x8, %edx
testl %ecx, %ecx
cmovel %ecx, %edx
movl %edx, 0x24c6c9(%rip)    # 0x4bee0c
movl %ecx, 0x24c6ef(%rip)    # 0x4bee38
movl %ecx, 0x24c6c1(%rip)    # 0x4bee10
cmpl $0x5b, %ecx
jl 0x272850
movl $0xa, 0x24c6b2(%rip)    # 0x4bee14
movq %rax, 0x24c6af(%rip)    # 0x4bee18
movl $0x0, 0x24c6c9(%rip)    # 0x4bee3c
jmp 0x27288f
cmpq $0x0, 0x248f00(%rip)    # 0x4bb680
jne 0x272795
leaq 0x2459a7(%rip), %rsi    # 0x4b8130
movl $0x4, %edi
xorl %eax, %eax
callq 0x27e871
xorps %xmm0, %xmm0
movups %xmm0, 0x24c409(%rip)   # 0x4beba8
movq $0x0, 0x24c40e(%rip) # 0x4bebb8
movq $0x8, 0x24c3eb(%rip) # 0x4beba0
cmpq $0x0, 0x248fdb(%rip)    # 0x4bb798
je 0x2727d4
cmpl $0x200, 0x248fd7(%rip)  # imm = 0x200
jl 0x2727d4
cmpl $0x0, 0x248fd2(%rip)    # 0x4bb7a4
jg 0x2727e9
movq $0x0, 0x248fb9(%rip) # 0x4bb798
movl $0x0, 0x248fb7(%rip)    # 0x4bb7a0
movq 0x248ec8(%rip), %rdi    # 0x4bb6b8
callq *0x248eb2(%rip)         # 0x4bb6a8
testl %eax, %eax
je 0x2725d7
movl %eax, %ebx
xorps %xmm0, %xmm0
movups %xmm0, 0x24c3a6(%rip)   # 0x4bebb0
movups %xmm0, 0x24c38f(%rip)   # 0x4beba0
jmp 0x2725b6
movq 0x248efb(%rip), %rax    # 0x4bb718
testq %rax, %rax
jne 0x27283c
leaq 0x245947(%rip), %rsi    # 0x4b8170
movl $0x12, %edi
xorl %eax, %eax
callq 0x27e871
movq 0x248edc(%rip), %rax    # 0x4bb718
movq 0x248ecd(%rip), %rdi    # 0x4bb710
callq *%rax
movl %eax, %ebx
testl %eax, %eax
jne 0x2728c1
jmp 0x272686
movslq %ecx, %rsi
imulq $0x66666667, %rsi, %rsi # imm = 0x66666667
movq %rsi, %rdi
shrq $0x3f, %rdi
sarq $0x22, %rsi
addl %edi, %esi
incl %esi
movl %esi, 0x24c5a5(%rip)    # 0x4bee14
movq %rax, 0x24c5a2(%rip)    # 0x4bee18
movq $0x0, 0x24c5af(%rip) # 0x4bee30
movl $0x0, 0x24c5b1(%rip)    # 0x4bee3c
testl %ecx, %ecx
je 0x2728ae
movslq %edx, %rdx
xorl %esi, %esi
movq %rsi, (%rax)
movq %rax, %rsi
addq %rdx, %rax
decl %ecx
jne 0x272894
movq %rax, %rcx
subq %rdx, %rcx
movq %rcx, 0x24c582(%rip)    # 0x4bee30
movq %rax, 0x24c56b(%rip)    # 0x4bee20
movl $0x1, 0x248ef5(%rip)    # 0x4bb7b4
xorl %ebx, %ebx
movl $0x0, 0x248eed(%rip)    # 0x4bb7b8
movl 0x248ef7(%rip), %eax    # 0x4bb7c8
leal -0x1(%rax), %ecx
movl %ecx, 0x248eee(%rip)    # 0x4bb7c8
cmpl $0x1, %eax
jg 0x2725b6
movq $0x0, 0x248ee2(%rip) # 0x4bb7d0
jmp 0x2725b6