// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x28(%rdi), %rbx
cmpb $0x2, 0x14(%rbx)
jne 0x236a32
movl 0x2c(%rbx), %ebp
testl %ebp, %ebp
jne 0x236a7a
cmpq $0x0, 0x120(%rbx)
jne 0x236a2e
cmpb $0x2, 0x9(%rbx)
jne 0x236aad
movb $0x3, 0x14(%rbx)
movq %r14, %rdi
callq 0x234591
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x236a52
movl 0x30(%r14), %ebp
movl %ebp, %esi
callq 0x230beb
testl %eax, %eax
je 0x236a8b
orb $0x4, 0x34(%r14)
cmpl $0x0, 0x80(%rbx)
jle 0x236a6c
movq %r14, %rdi
callq 0x2300e4
movl %eax, %ebp
jmp 0x236a6e
xorl %ebp, %ebp
movl 0x30(%r14), %eax
cmpl %eax, 0x1c(%rbx)
jae 0x236a7a
movl %eax, 0x1c(%rbx)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl 0x20(%rbx), %ebp
jbe 0x236a9d
cmpb $0x4, 0x14(%rbx)
je 0x236a52
orb $0x8, 0x34(%r14)
jmp 0x236a52
movq %r14, %rdi
callq 0x236b8e
movl %eax, %ebp
testl %eax, %eax
jne 0x236a7a
jmp 0x236a52
movq (%rbx), %r15
movl 0x1c(%rbx), %edi
callq 0x231168
movq %rax, 0x40(%rbx)
testq %rax, %rax
je 0x236b07
movq 0x50(%rbx), %rax
cmpq $0x0, (%rax)
jne 0x236b5a
cmpb $0x4, 0x9(%rbx)
jne 0x236b0f
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
andq $0x0, 0x40(%rax)
movabsq $-0xfffffc08, %rcx      # imm = 0xFFFFFFFF000003F8
movq %rcx, 0x8(%rax)
leaq 0x1ff002(%rip), %rcx    # 0x435b00
movq %rcx, (%rax)
movups %xmm0, 0x48(%rax)
jmp 0x236b5a
pushq $0x7
popq %rbp
jmp 0x236a7a
movb 0x10(%rbx), %r13b
movl 0x203b12(%rip), %r12d   # 0x43a62c
movq %rbx, %rdi
callq 0x235091
movl %eax, %ebp
testl %eax, %eax
jne 0x236b56
xorl %eax, %eax
testb %r13b, %r13b
cmovel %eax, %r12d
movl $0x806, %eax            # imm = 0x806
movl $0x100e, %ecx           # imm = 0x100E
cmovel %eax, %ecx
movq 0x50(%rbx), %rdx
movq 0xd8(%rbx), %rsi
movq %r15, %rdi
movl %r12d, %r8d
callq 0x230cca
movl %eax, %ebp
testl %ebp, %ebp
jne 0x236b7b
andl $0x0, 0x30(%rbx)
movb $0x0, 0x17(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x60(%rbx)
movq %rbx, %rdi
callq 0x2327b0
movl %eax, %ebp
testl %eax, %eax
je 0x236a2e
movq 0x40(%rbx), %rdi
callq 0x233e95
andq $0x0, 0x40(%rbx)
jmp 0x236a7a