// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3PagerBegin
SQLITE_PRIVATE int sqlite3PagerBegin(Pager *pPager, int exFlag, int subjInMemory){
  int rc = SQLITE_OK;

  if( pPager->errCode ) return pPager->errCode;
  assert( pPager->eState>=PAGER_READER && pPager->eState<PAGER_ERROR );
  pPager->subjInMemory = (u8)subjInMemory;

  if( ALWAYS(pPager->eState==PAGER_READER) ){
    assert( pPager->pInJournal==0 );

    if( pagerUseWal(pPager) ){
      /* If the pager is configured to use locking_mode=exclusive, and an
      ** exclusive lock on the database is not already held, obtain it now.
      */
      if( pPager->exclusiveMode && sqlite3WalExclusiveMode(pPager->pWal, -1) ){
        rc = pagerLockDb(pPager, EXCLUSIVE_LOCK);
        if( rc!=SQLITE_OK ){
          return rc;
        }
        sqlite3WalExclusiveMode(pPager->pWal, 1);
      }

      /* Grab the write lock on the log file. If successful, upgrade to
      ** PAGER_RESERVED state. Otherwise, return an error code to the caller.
      ** The busy-handler is not invoked if another connection already
      ** holds the write-lock. If possible, the upper layer will call it.
      */
      rc = sqlite3WalBeginWriteTransaction(pPager->pWal);
    }else{
      /* Obtain a RESERVED lock on the database file. If the exFlag parameter
      ** is true, then immediately upgrade this to an EXCLUSIVE lock. The
      ** busy-handler callback can be used when upgrading to the EXCLUSIVE
      ** lock, but not when obtaining the RESERVED lock.
      */
      rc = pagerLockDb(pPager, RESERVED_LOCK);
      if( rc==SQLITE_OK && exFlag ){
        rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
      }
    }

    if( rc==SQLITE_OK ){
      /* Change to WRITER_LOCKED state.
      **
      ** WAL mode sets Pager.eState to PAGER_WRITER_LOCKED or CACHEMOD
      ** when it has an open transaction, but never to DBMOD or FINISHED.
      ** This is because in those states the code to roll back savepoint 
      ** transactions may copy data from the sub-journal into the database 
      ** file as well as into the page cache. Which would be incorrect in 
      ** WAL mode.
      */
      pPager->eState = PAGER_WRITER_LOCKED;
      pPager->dbHintSize = pPager->dbSize;
      pPager->dbFileSize = pPager->dbSize;
      pPager->dbOrigSize = pPager->dbSize;
      pPager->journalOff = 0;
    }

    assert( rc==SQLITE_OK || pPager->eState==PAGER_READER );
    assert( rc!=SQLITE_OK || pPager->eState==PAGER_WRITER_LOCKED );
    assert( assert_pager_state(pPager) );
  }

  PAGERTRACE(("TRANSACTION %d\n", PAGERID(pPager)));
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x29682
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x2979c
movl -0x18(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x18(%rax)
movq -0x10(%rbp), %rax
movzbl 0x13(%rax), %eax
cmpl $0x1, %eax
jne 0x29796
movq -0x10(%rbp), %rdi
callq 0x211a0
cmpl $0x0, %eax
je 0x29720
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
je 0x2970b
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x29060
cmpl $0x0, %eax
je 0x2970b
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x247e0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x296f6
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2979c
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movl $0x1, %esi
callq 0x29060
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
callq 0x2a870
movl %eax, -0x1c(%rbp)
jmp 0x29750
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x247e0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x2974e
cmpl $0x0, -0x14(%rbp)
je 0x2974e
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x24780
movl %eax, -0x1c(%rbp)
jmp 0x29750
cmpl $0x0, -0x1c(%rbp)
jne 0x29794
movq -0x10(%rbp), %rax
movb $0x2, 0x13(%rax)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x29796
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)