// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %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, 0x10(%rsp)
movl 0x30(%rdi), %r12d
leal -0x1(%r12), %edx
movl %eax, %r14d
negl %r14d
andl %edx, %r14d
cmpl %ecx, %r12d
jbe 0x2368ca
subl %r14d, %r12d
jmp 0x2368da
leal (%r14,%rax), %edx
movl %ecx, %r12d
subl %r14d, %r12d
cmpl %ecx, %edx
cmovbel %eax, %r12d
incl %r14d
movl $0x0, 0x4(%rsp)
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpl %r12d, %r15d
jge 0x2369ae
testl %ebp, %ebp
jne 0x2369ae
leal (%r14,%r15), %r13d
movq 0x10(%rsp), %rax
cmpl 0x30(%rax), %r13d
je 0x23694b
movq 0x40(%rbx), %rdi
movl %r13d, %esi
callq 0x234550
testl %eax, %eax
je 0x23694b
movq %rbx, %rdi
movl %r13d, %esi
callq 0x232e4f
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
testq %rax, %rax
je 0x2369a6
movzwl 0x34(%rax), %ecx
testb $0x8, %cl
movl 0x4(%rsp), %ecx
pushq $0x1
popq %rdx
cmovnel %edx, %ecx
movl %ecx, 0x4(%rsp)
movq %rax, %rdi
jmp 0x2369a1
movl 0x20411f(%rip), %eax    # 0x43aa70
cltd
idivl 0xbc(%rbx)
incl %eax
xorl %ebp, %ebp
cmpl %eax, %r13d
je 0x2369a6
movq %rbx, %rdi
movl %r13d, %esi
leaq 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq *0x108(%rbx)
testl %eax, %eax
je 0x23697c
movl %eax, %ebp
jmp 0x2369a6
movq 0x8(%rsp), %rdi
callq 0x2369ff
movl %eax, %ebp
movq 0x8(%rsp), %rdi
movzwl 0x34(%rdi), %eax
testb $0x8, %al
movl 0x4(%rsp), %eax
pushq $0x1
popq %rcx
cmovnel %ecx, %eax
movl %eax, 0x4(%rsp)
callq 0x23445c
incl %r15d
jmp 0x2368ea
testl %ebp, %ebp
jne 0x2369ea
cmpl $0x0, 0x4(%rsp)
je 0x2369ea
xorl %r15d, %r15d
testl %r12d, %r12d
cmovgl %r12d, %r15d
subl $0x1, %r15d
jb 0x2369ea
movq %rbx, %rdi
movl %r14d, %esi
callq 0x232e4f
testq %rax, %rax
je 0x2369e5
orb $0x8, 0x34(%rax)
movq %rax, %rdi
callq 0x23445c
incl %r14d
jmp 0x2369c3
andb $-0x5, 0x18(%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq