// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3WalOpen
SQLITE_PRIVATE int sqlite3WalOpen(
  sqlite3_vfs *pVfs,              /* vfs module to open wal and wal-index */
  sqlite3_file *pDbFd,            /* The open database file */
  const char *zWalName,           /* Name of the WAL file */
  int bNoShm,                     /* True to run in heap-memory mode */
  i64 mxWalSize,                  /* Truncate WAL to this size on reset */
  Wal **ppWal                     /* OUT: Allocated Wal handle */
){
  int rc;                         /* Return Code */
  Wal *pRet;                      /* Object to allocate and return */
  int flags;                      /* Flags passed to OsOpen() */

  assert( zWalName && zWalName[0] );
  assert( pDbFd );

  /* In the amalgamation, the os_unix.c and os_win.c source files come before
  ** this source file.  Verify that the #defines of the locking byte offsets
  ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
  ** For that matter, if the lock offset ever changes from its initial design
  ** value of 120, we need to know that so there is an assert() to check it.
  */
  assert( 120==WALINDEX_LOCK_OFFSET );
  assert( 136==WALINDEX_HDR_SIZE );
#ifdef WIN_SHM_BASE
  assert( WIN_SHM_BASE==WALINDEX_LOCK_OFFSET );
#endif
#ifdef UNIX_SHM_BASE
  assert( UNIX_SHM_BASE==WALINDEX_LOCK_OFFSET );
#endif


  /* Allocate an instance of struct Wal to return. */
  *ppWal = 0;
  pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile);
  if( !pRet ){
    return SQLITE_NOMEM_BKPT;
  }

  pRet->pVfs = pVfs;
  pRet->pWalFd = (sqlite3_file *)&pRet[1];
  pRet->pDbFd = pDbFd;
  pRet->readLock = -1;
  pRet->mxWalSize = mxWalSize;
  pRet->zWalName = zWalName;
  pRet->syncHeader = 1;
  pRet->padToSectorBoundary = 1;
  pRet->exclusiveMode = (bNoShm ? WAL_HEAPMEMORY_MODE: WAL_NORMAL_MODE);

  /* Open file handle on the write-ahead log file. */
  flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
  rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
  if( rc==SQLITE_OK && flags&SQLITE_OPEN_READONLY ){
    pRet->readOnly = WAL_RDONLY;
  }

  if( rc!=SQLITE_OK ){
    walIndexClose(pRet, 0);
    sqlite3OsClose(pRet->pWalFd);
    sqlite3_free(pRet);
  }else{
    int iDC = sqlite3OsDeviceCharacteristics(pDbFd);
    if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
    if( iDC & SQLITE_IOCAP_POWERSAFE_OVERWRITE ){
      pRet->padToSectorBoundary = 0;
    }
    *ppWal = pRet;
    WALTRACE(("WAL%d: opened\n", pRet));
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movslq 0x4(%rax), %rdi
addq $0x90, %rdi
callq 0x3c51d0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x3e77d5
movl $0x7, -0x4(%rbp)
jmp 0x3e78fc
movq -0x10(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
addq $0x90, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rax
movw $0xffff, 0x3c(%rax)     # imm = 0xFFFF
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x48(%rbp), %rax
movb $0x1, 0x44(%rax)
movq -0x48(%rbp), %rax
movb $0x1, 0x45(%rax)
movl -0x24(%rbp), %edx
xorl %eax, %eax
movl $0x2, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, 0x3f(%rax)
movl $0x80006, -0x4c(%rbp)   # imm = 0x80006
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdx
movl -0x4c(%rbp), %ecx
leaq -0x4c(%rbp), %r8
callq 0x3dbb90
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x3e788c
movl -0x4c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3e788c
movq -0x48(%rbp), %rax
movb $0x1, 0x42(%rax)
cmpl $0x0, -0x3c(%rbp)
je 0x3e78b5
movq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x3df940
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3dbe40
movq -0x48(%rbp), %rdi
callq 0x3c0800
jmp 0x3e78f6
movq -0x18(%rbp), %rdi
callq 0x3dbbe0
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x3e78d6
movq -0x48(%rbp), %rax
movb $0x0, 0x44(%rax)
movl -0x50(%rbp), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x3e78eb
movq -0x48(%rbp), %rax
movb $0x0, 0x45(%rax)
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)