// File: /workspace/github_c_makefile_star2_O1/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 0x2971cc
subl %r14d, %r12d
jmp 0x2971dc
leal (%r14,%rax), %edx
movl %ecx, %r12d
subl %r14d, %r12d
cmpl %ecx, %edx
cmovbel %eax, %r12d
testl %r12d, %r12d
jle 0x2972c8
movl $0x0, 0x4(%rsp)
movl $0x1, %r15d
leal (%r14,%r15), %r13d
movq 0x10(%rsp), %rax
cmpl 0x30(%rax), %r13d
je 0x29724a
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
je 0x29724a
movl %r13d, %esi
callq 0x290715
testl %eax, %eax
je 0x29724a
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2930a5
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
testq %rax, %rax
je 0x2972a7
movzwl 0x34(%rax), %ecx
testb $0x8, %cl
movl 0x4(%rsp), %ecx
movl $0x1, %edx
cmovnel %edx, %ecx
movl %ecx, 0x4(%rsp)
movq %rax, %rdi
jmp 0x2972a2
movl 0x22f870(%rip), %eax    # 0x4c6ac0
cltd
idivl 0xbc(%rbx)
incl %eax
xorl %ebp, %ebp
cmpl %eax, %r13d
je 0x2972a7
movq %rbx, %rdi
movl %r13d, %esi
leaq 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq *0x108(%rbx)
testl %eax, %eax
je 0x29727b
movl %eax, %ebp
jmp 0x2972a7
movq 0x8(%rsp), %rdi
callq 0x297311
movl %eax, %ebp
movq 0x8(%rsp), %rdi
movzwl 0x34(%rdi), %eax
testb $0x8, %al
movl 0x4(%rsp), %eax
movl $0x1, %ecx
cmovnel %ecx, %eax
movl %eax, 0x4(%rsp)
callq 0x2949b7
cmpl %r12d, %r15d
jge 0x2972b7
incl %r15d
testl %ebp, %ebp
je 0x2971f3
testl %ebp, %ebp
sete %cl
cmpl $0x0, 0x4(%rsp)
setne %al
andb %cl, %al
jmp 0x2972cc
xorl %ebp, %ebp
xorl %eax, %eax
testb %al, %al
je 0x2972fc
testl %r12d, %r12d
jle 0x2972fc
incl %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2930a5
testq %rax, %rax
je 0x2972f4
orb $0x8, 0x34(%rax)
movq %rax, %rdi
callq 0x2949b7
incl %r14d
decl %r12d
jne 0x2972d8
andb $-0x5, 0x18(%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq