// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: pager_write
static int pager_write(PgHdr *pPg){
  Pager *pPager = pPg->pPager;
  int rc = SQLITE_OK;

  /* This routine is not called unless a write-transaction has already
  ** been started. The journal file may or may not be open at this point.
  ** It is never called in the ERROR state.
  */
  assert( pPager->eState==PAGER_WRITER_LOCKED
       || pPager->eState==PAGER_WRITER_CACHEMOD
       || pPager->eState==PAGER_WRITER_DBMOD
  );
  assert( assert_pager_state(pPager) );
  assert( pPager->errCode==0 );
  assert( pPager->readOnly==0 );
  CHECK_PAGE(pPg);

  /* The journal file needs to be opened. Higher level routines have already
  ** obtained the necessary locks to begin the write-transaction, but the
  ** rollback journal might not yet be open. Open it now if this is the case.
  **
  ** This is done before calling sqlite3PcacheMakeDirty() on the page.
  ** Otherwise, if it were done after calling sqlite3PcacheMakeDirty(), then
  ** an error might occur and the pager would end up in WRITER_LOCKED state
  ** with pages marked as dirty in the cache.
  */
  if( pPager->eState==PAGER_WRITER_LOCKED ){
    rc = pager_open_journal(pPager);
    if( rc!=SQLITE_OK ) return rc;
  }
  assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
  assert( assert_pager_state(pPager) );

  /* Mark the page that is about to be modified as dirty. */
  sqlite3PcacheMakeDirty(pPg);

  /* If a rollback journal is in use, them make sure the page that is about
  ** to change is in the rollback journal, or if the page is a new page off
  ** then end of the file, make sure it is marked as PGHDR_NEED_SYNC.
  */
  assert( (pPager->pInJournal!=0) == isOpen(pPager->jfd) );
  if( pPager->pInJournal!=0
   && sqlite3BitvecTestNotNull(pPager->pInJournal, pPg->pgno)==0
  ){
    assert( pagerUseWal(pPager)==0 );
    if( pPg->pgno<=pPager->dbOrigSize ){
      rc = pagerAddPageToRollbackJournal(pPg);
      if( rc!=SQLITE_OK ){
        return rc;
      }
    }else{
      if( pPager->eState!=PAGER_WRITER_DBMOD ){
        pPg->flags |= PGHDR_NEED_SYNC;
      }
      PAGERTRACE(("APPEND %d page %d needSync=%d\n",
              PAGERID(pPager), pPg->pgno,
             ((pPg->flags&PGHDR_NEED_SYNC)?1:0)));
    }
  }

  /* The PGHDR_DIRTY bit is set above when the page was added to the dirty-list
  ** and before writing the page into the rollback journal.  Wait until now,
  ** after the page has been successfully journalled, before setting the
  ** PGHDR_WRITEABLE bit that indicates that the page can be safely modified.
  */
  pPg->flags |= PGHDR_WRITEABLE;

  /* If the statement journal is open and the page is not in it,
  ** then write the page into the statement journal.
  */
  if( pPager->nSavepoint>0 ){
    rc = subjournalPageIfRequired(pPg);
  }

  /* Update the database size and return. */
  if( pPager->dbSize<pPg->pgno ){
    pPager->dbSize = pPg->pgno;
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x2, %eax
jne 0x3e806b
movq -0x18(%rbp), %rdi
callq 0x3e8140
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x3e8069
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3e8130
jmp 0x3e806b
movq -0x10(%rbp), %rdi
callq 0x3e3500
movq -0x18(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x3e80e4
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %esi
callq 0x3dc8d0
cmpl $0x0, %eax
jne 0x3e80e4
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20(%rcx), %eax
ja 0x3e80c4
movq -0x10(%rbp), %rdi
callq 0x3e82f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x3e80c2
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3e8130
jmp 0x3e80e2
movq -0x18(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x4, %eax
je 0x3e80e0
movq -0x10(%rbp), %rax
movzwl 0x34(%rax), %ecx
orl $0x8, %ecx
movw %cx, 0x34(%rax)
jmp 0x3e80e2
jmp 0x3e80e4
movq -0x10(%rbp), %rax
movzwl 0x34(%rax), %ecx
orl $0x4, %ecx
movw %cx, 0x34(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x80(%rax)
jle 0x3e810c
movq -0x10(%rbp), %rdi
callq 0x3dc0b0
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jae 0x3e812a
movq -0x10(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)