// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: pagerWriteLargeSector
static SQLITE_NOINLINE int pagerWriteLargeSector(PgHdr *pPg){
  int rc = SQLITE_OK;          /* Return code */
  Pgno nPageCount;             /* Total number of pages in database file */
  Pgno pg1;                    /* First page of the sector pPg is located on. */
  int nPage = 0;               /* Number of pages starting at pg1 to journal */
  int ii;                      /* Loop counter */
  int needSync = 0;            /* True if any page has PGHDR_NEED_SYNC */
  Pager *pPager = pPg->pPager; /* The pager that owns pPg */
  Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);

  /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
  ** a journal header to be written between the pages journaled by
  ** this function.
  */
  assert( !MEMDB );
  assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)==0 );
  pPager->doNotSpill |= SPILLFLAG_NOSYNC;

  /* This trick assumes that both the page-size and sector-size are
  ** an integer power of 2. It sets variable pg1 to the identifier
  ** of the first page of the sector pPg is located on.
  */
  pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;

  nPageCount = pPager->dbSize;
  if( pPg->pgno>nPageCount ){
    nPage = (pPg->pgno - pg1)+1;
  }else if( (pg1+nPagePerSector-1)>nPageCount ){
    nPage = nPageCount+1-pg1;
  }else{
    nPage = nPagePerSector;
  }
  assert(nPage>0);
  assert(pg1<=pPg->pgno);
  assert((pg1+nPage)>pPg->pgno);

  for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){
    Pgno pg = pg1+ii;
    PgHdr *pPage;
    if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){
      if( pg!=PAGER_MJ_PGNO(pPager) ){
        rc = sqlite3PagerGet(pPager, pg, &pPage, 0);
        if( rc==SQLITE_OK ){
          rc = pager_write(pPage);
          if( pPage->flags&PGHDR_NEED_SYNC ){
            needSync = 1;
          }
          sqlite3PagerUnrefNotNull(pPage);
        }
      }
    }else if( (pPage = sqlite3PagerLookup(pPager, pg))!=0 ){
      if( pPage->flags&PGHDR_NEED_SYNC ){
        needSync = 1;
      }
      sqlite3PagerUnrefNotNull(pPage);
    }
  }

  /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
  ** starting at pg1, then it needs to be set for all of them. Because
  ** writing to any of these nPage pages may damage the others, the
  ** journal file must contain sync()ed copies of all of them
  ** before any of them can be written out to the database file.
  */
  if( rc==SQLITE_OK && needSync ){
    assert( !MEMDB );
    for(ii=0; ii<nPage; ii++){
      PgHdr *pPage = sqlite3PagerLookup(pPager, pg1+ii);
      if( pPage ){
        pPage->flags |= PGHDR_NEED_SYNC;
        sqlite3PagerUnrefNotNull(pPage);
      }
    }
  }

  assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
  pPager->doNotSpill &= ~SPILLFLAG_NOSYNC;
  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x28(%rdi), %rbx
movl 0x1c(%rbx), %ecx
movl 0xb8(%rbx), %eax
xorl %edx, %edx
divl 0xbc(%rbx)
orb $0x4, 0x18(%rbx)
movq %rdi, 0x20(%rsp)
movl 0x30(%rdi), %r12d
leal -0x1(%r12), %edx
movl %eax, %esi
negl %esi
andl %edx, %esi
cmpl %ecx, %r12d
jbe 0x28d506
subl %esi, %r12d
jmp 0x28d515
leal (%rsi,%rax), %edx
movl %ecx, %r12d
subl %esi, %r12d
cmpl %ecx, %edx
cmovbel %eax, %r12d
testl %r12d, %r12d
jle 0x28d637
leal 0x1(%rsi), %ebp
movl $0x0, 0xc(%rsp)
movl $0x1, %r14d
movq %rsi, 0x10(%rsp)
leal (%rsi,%r14), %r13d
movq 0x20(%rsp), %rax
cmpl 0x30(%rax), %r13d
je 0x28d591
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x28d591
movl %r13d, %esi
callq 0x286b64
movq 0x10(%rsp), %rsi
testl %eax, %eax
je 0x28d591
movq %rbx, %rdi
movl %r13d, %esi
callq 0x289239
movq %rax, 0x18(%rsp)
xorl %r15d, %r15d
testq %rax, %rax
je 0x28d5ec
movzwl 0x34(%rax), %ecx
testb $0x8, %cl
movl 0xc(%rsp), %ecx
movl $0x1, %edx
cmovnel %edx, %ecx
movl %ecx, 0xc(%rsp)
movq %rax, %rdi
jmp 0x28d5e7
movl 0x22e529(%rip), %eax    # 0x4bbac0
cltd
idivl 0xbc(%rbx)
incl %eax
xorl %r15d, %r15d
cmpl %eax, %r13d
je 0x28d5f1
movq %rbx, %rdi
movl %r13d, %esi
leaq 0x18(%rsp), %rdx
xorl %ecx, %ecx
callq *0x108(%rbx)
testl %eax, %eax
jne 0x28d63c
movq 0x18(%rsp), %rdi
callq 0x28d655
movl %eax, %r15d
movq 0x18(%rsp), %rdi
movzwl 0x34(%rdi), %eax
testb $0x8, %al
movl 0xc(%rsp), %eax
movl $0x1, %ecx
cmovnel %ecx, %eax
movl %eax, 0xc(%rsp)
callq 0x28ab87
movq 0x10(%rsp), %rsi
cmpl %r12d, %r14d
jge 0x28d602
incl %r14d
testl %r15d, %r15d
je 0x28d534
testl %r15d, %r15d
jne 0x28d63f
cmpl $0x0, 0xc(%rsp)
je 0x28d63f
testl %r12d, %r12d
jle 0x28d63f
movq %rbx, %rdi
movl %ebp, %esi
callq 0x289239
testq %rax, %rax
je 0x28d62e
orb $0x8, 0x34(%rax)
movq %rax, %rdi
callq 0x28ab87
incl %ebp
decl %r12d
jne 0x28d613
jmp 0x28d63f
xorl %r15d, %r15d
jmp 0x28d63f
movl %eax, %r15d
andb $-0x5, 0x18(%rbx)
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq