// File: /workspace/github_c_makefile_star2_O1/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 0x29746f
movl 0x2c(%rbx), %ebp
testl %ebp, %ebp
jne 0x29746b
xorl %ebp, %ebp
cmpq $0x0, 0x120(%rbx)
jne 0x297450
cmpb $0x2, 0x9(%rbx)
je 0x297450
movq (%rbx), %r15
movl 0x1c(%rbx), %r13d
movl $0x200, %edi            # imm = 0x200
callq 0x27c381
movq %rax, %r12
testq %rax, %rax
je 0x2973db
xorl %ebp, %ebp
movl $0x200, %edx            # imm = 0x200
movq %r12, %rdi
xorl %esi, %esi
callq 0x173a0
movl %r13d, (%r12)
movq %r12, 0x40(%rbx)
movq 0x50(%rbx), %rax
cmpq $0x0, (%rax)
jne 0x297430
cmpb $0x4, 0x9(%rbx)
jne 0x2973e9
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movq $0x0, 0x50(%rax)
movabsq $-0xfffffc08, %rcx      # imm = 0xFFFFFFFF000003F8
movq %rcx, 0x8(%rax)
leaq 0x22a755(%rip), %rcx    # 0x4c1b20
movq %rcx, (%rax)
movl $0x0, 0x40(%rax)
movups %xmm0, 0x48(%rax)
jmp 0x297430
movq %r12, 0x40(%rbx)
movl $0x7, %ebp
jmp 0x29746b
movb 0x10(%rbx), %r13b
movl 0x22f288(%rip), %r12d   # 0x4c667c
movq %rbx, %rdi
callq 0x295600
movl %eax, %ebp
testl %eax, %eax
jne 0x297430
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 0x2907f8
movl %eax, %ebp
testl %ebp, %ebp
jne 0x297450
movl $0x0, 0x30(%rbx)
movb $0x0, 0x17(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x60(%rbx)
movq %rbx, %rdi
callq 0x29290f
movl %eax, %ebp
testl %ebp, %ebp
je 0x297467
movq 0x40(%rbx), %rdi
callq 0x294293
movq $0x0, 0x40(%rbx)
jmp 0x29746b
movb $0x3, 0x14(%rbx)
testl %ebp, %ebp
jne 0x2974b7
movq %r14, %rdi
callq 0x294a66
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x29748f
movl 0x30(%r14), %ebp
movl %ebp, %esi
callq 0x290715
testl %eax, %eax
je 0x2974c8
orb $0x4, 0x34(%r14)
cmpl $0x0, 0x80(%rbx)
jle 0x2974a9
movq %r14, %rdi
callq 0x28f9fe
movl %eax, %ebp
jmp 0x2974ab
xorl %ebp, %ebp
movl 0x30(%r14), %eax
cmpl %eax, 0x1c(%rbx)
jae 0x2974b7
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 0x2974da
cmpb $0x4, 0x14(%rbx)
je 0x29748f
orb $0x8, 0x34(%r14)
jmp 0x29748f
movq %r14, %rdi
callq 0x2974ea
movl %eax, %ebp
testl %eax, %eax
jne 0x2974b7
jmp 0x29748f