// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/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.
  */
#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;
  }

  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(pRet->pWalFd);
    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), %rax
addq $0x88, %rax
movl %eax, %edi
callq 0xd860
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x2a736
movl $0x7, -0x4(%rbp)
jmp 0x2a85e
movq -0x10(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
addq $0x88, %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, 0x78(%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 0x20df0
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x2a7ea
movl -0x4c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2a7ea
movq -0x48(%rbp), %rax
movb $0x1, 0x42(%rax)
cmpl $0x0, -0x3c(%rbp)
je 0x2a813
movq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x25950
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x20ea0
movq -0x48(%rbp), %rdi
callq 0xa420
jmp 0x2a858
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x210d0
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x2a838
movq -0x48(%rbp), %rax
movb $0x0, 0x44(%rax)
movl -0x50(%rbp), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x2a84d
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 (%rax,%rax)