// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl 0xb8(%rax), %eax
movq -0x28(%rbp), %rcx
xorl %edx, %edx
divl 0xbc(%rcx)
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x18(%rax), %ecx
orl $0x4, %ecx
movb %cl, 0x18(%rax)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
subl $0x1, %eax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
cmpl -0x10(%rbp), %eax
jbe 0x3e7e77
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
subl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3e7e9b
movl -0x14(%rbp), %eax
addl -0x2c(%rbp), %eax
subl $0x1, %eax
cmpl -0x10(%rbp), %eax
jbe 0x3e7e93
movl -0x10(%rbp), %eax
addl $0x1, %eax
subl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x3e7e99
movl -0x2c(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x3e7e9b
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x18(%rbp), %ecx
movb %al, -0x41(%rbp)
jge 0x3e7eb9
cmpl $0x0, -0xc(%rbp)
sete %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x3e7ec5
jmp 0x3e7fa5
movl -0x14(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x30(%rcx), %eax
je 0x3e7eef
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rdi
movl -0x30(%rbp), %esi
callq 0x3e3460
cmpl $0x0, %eax
jne 0x3e7f5d
movl -0x30(%rbp), %eax
movl %eax, -0x48(%rbp)
movl 0x257db5(%rip), %eax    # 0x63fcb0
movq -0x28(%rbp), %rcx
cltd
idivl 0xbc(%rcx)
movl %eax, %ecx
movl -0x48(%rbp), %eax
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x3e7f5b
movq -0x28(%rbp), %rdi
movl -0x30(%rbp), %esi
leaq -0x38(%rbp), %rdx
xorl %ecx, %ecx
callq 0x3c6020
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x3e7f59
movq -0x38(%rbp), %rdi
callq 0x3e8020
movl %eax, -0xc(%rbp)
movq -0x38(%rbp), %rax
movzwl 0x34(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x3e7f50
movl $0x1, -0x20(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3e3030
jmp 0x3e7f5b
jmp 0x3e7f95
movq -0x28(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x3e0f70
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x3e7f93
movq -0x38(%rbp), %rax
movzwl 0x34(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x3e7f8a
movl $0x1, -0x20(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3e3030
jmp 0x3e7f95
jmp 0x3e7f97
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3e7ea2
cmpl $0x0, -0xc(%rbp)
jne 0x3e8001
cmpl $0x0, -0x20(%rbp)
je 0x3e8001
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3e7fff
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %esi
addl -0x1c(%rbp), %esi
callq 0x3e0f70
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x3e7ff2
movq -0x40(%rbp), %rax
movzwl 0x34(%rax), %ecx
orl $0x8, %ecx
movw %cx, 0x34(%rax)
movq -0x40(%rbp), %rdi
callq 0x3e3030
jmp 0x3e7ff4
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3e7fb8
jmp 0x3e8001
movq -0x28(%rbp), %rax
movzbl 0x18(%rax), %ecx
andl $-0x5, %ecx
movb %cl, 0x18(%rax)
movl -0xc(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)