// File: /workspace/github_c_makefile_star2_O3/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 0x28d688
movl 0x2c(%rbx), %ebp
testl %ebp, %ebp
jne 0x28d6d0
cmpq $0x0, 0x120(%rbx)
jne 0x28d684
cmpb $0x2, 0x9(%rbx)
jne 0x28d703
movb $0x3, 0x14(%rbx)
movq %r14, %rdi
callq 0x28ac36
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x28d6a8
movl 0x30(%r14), %ebp
movl %ebp, %esi
callq 0x286b64
testl %eax, %eax
je 0x28d6e1
orb $0x4, 0x34(%r14)
cmpl $0x0, 0x80(%rbx)
jle 0x28d6c2
movq %r14, %rdi
callq 0x285e77
movl %eax, %ebp
jmp 0x28d6c4
xorl %ebp, %ebp
movl 0x30(%r14), %eax
cmpl %eax, 0x1c(%rbx)
jae 0x28d6d0
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 0x28d6f3
cmpb $0x4, 0x14(%rbx)
je 0x28d6a8
orb $0x8, 0x34(%r14)
jmp 0x28d6a8
movq %r14, %rdi
callq 0x28d868
movl %eax, %ebp
testl %eax, %eax
jne 0x28d6d0
jmp 0x28d6a8
movq (%rbx), %r15
movl 0x1c(%rbx), %ebp
movl $0x200, %edi            # imm = 0x200
callq 0x272ae6
testq %rax, %rax
je 0x28d782
movq %rax, %r12
movq %rax, %rdi
addq $0x4, %rdi
movl $0x1fc, %edx            # imm = 0x1FC
xorl %esi, %esi
callq 0x173a0
movl %ebp, (%r12)
movq %r12, 0x40(%rbx)
movq 0x50(%rbx), %rax
cmpq $0x0, (%rax)
jne 0x28d81a
cmpb $0x4, 0x9(%rbx)
jne 0x28d794
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movq $0x0, 0x40(%rax)
movabsq $-0xfffffc08, %rcx      # imm = 0xFFFFFFFF000003F8
movq %rcx, 0x8(%rax)
leaq 0x22939a(%rip), %rcx    # 0x4b6b10
movq %rcx, (%rax)
movups %xmm0, 0x48(%rax)
jmp 0x28d81a
movq $0x0, 0x40(%rbx)
movl $0x7, %ebp
jmp 0x28d6d0
cmpb $0x0, 0x10(%rbx)
je 0x28d7a9
movl $0x100e, %r12d          # imm = 0x100E
movl 0x22ded5(%rip), %r13d   # 0x4bb67c
jmp 0x28d7b2
xorl %r13d, %r13d
movl $0x806, %r12d           # imm = 0x806
movq %rbx, %rdi
callq 0x28b7ad
movl %eax, %ebp
testl %eax, %eax
je 0x28d7c6
testl %ebp, %ebp
jne 0x28d83e
jmp 0x28d81a
movq 0x50(%rbx), %rdx
movq 0xd8(%rbx), %rsi
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rdx)
movups %xmm0, 0x30(%rdx)
movups %xmm0, 0x20(%rdx)
movups %xmm0, 0x10(%rdx)
movups %xmm0, (%rdx)
movq $0x0, 0x50(%rdx)
testl %r13d, %r13d
je 0x28d854
movl $0x3f8, %eax            # imm = 0x3F8
cmovgl %r13d, %eax
movl %eax, 0x8(%rdx)
leaq 0x229309(%rip), %rax    # 0x4b6b10
movq %rax, (%rdx)
movl %r13d, 0xc(%rdx)
movl %r12d, 0x40(%rdx)
movq %rsi, 0x50(%rdx)
movq %r15, 0x48(%rdx)
movl $0x0, 0x30(%rbx)
movb $0x0, 0x17(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x60(%rbx)
movq %rbx, %rdi
callq 0x288ae8
movl %eax, %ebp
testl %eax, %eax
je 0x28d684
movq 0x40(%rbx), %rdi
callq 0x28a41d
movq $0x0, 0x40(%rbx)
jmp 0x28d6d0
movq %r15, %rdi
movl %r12d, %ecx
xorl %r8d, %r8d
callq *0x28(%r15)
movl %eax, %ebp
jmp 0x28d7c0