// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: writeSuperJournal
static int writeSuperJournal(Pager *pPager, const char *zSuper){
  int rc;                          /* Return code */
  int nSuper;                      /* Length of string zSuper */
  i64 iHdrOff;                     /* Offset of header in journal file */
  i64 jrnlSize;                    /* Size of journal file on disk */
  u32 cksum = 0;                   /* Checksum of string zSuper */

  assert( pPager->setSuper==0 );
  assert( !pagerUseWal(pPager) );

  if( !zSuper
   || pPager->journalMode==PAGER_JOURNALMODE_MEMORY
   || !isOpen(pPager->jfd)
  ){
    return SQLITE_OK;
  }
  pPager->setSuper = 1;
  assert( pPager->journalHdr <= pPager->journalOff );

  /* Calculate the length in bytes and the checksum of zSuper */
  for(nSuper=0; zSuper[nSuper]; nSuper++){
    cksum += zSuper[nSuper];
  }

  /* If in full-sync mode, advance to the next disk sector before writing
  ** the super-journal name. This is in case the previous page written to
  ** the journal has already been synced.
  */
  if( pPager->fullSync ){
    pPager->journalOff = journalHdrOffset(pPager);
  }
  iHdrOff = pPager->journalOff;

  /* Write the super-journal data to the end of the journal file. If
  ** an error occurs, return the error code to the caller.
  */
  if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager))))
   || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4)))
   || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper)))
   || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum)))
   || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8,
                                 iHdrOff+4+nSuper+8)))
  ){
    return rc;
  }
  pPager->journalOff += (nSuper+20);

  /* If the pager is in peristent-journal mode, then the physical
  ** journal-file may extend past the end of the super-journal name
  ** and 8 bytes of magic data just written to the file. This is
  ** dangerous because the code to rollback a hot-journal file
  ** will not be able to find the super-journal name to determine
  ** whether or not the journal is hot.
  **
  ** Easiest thing to do in this scenario is to truncate the journal
  ** file to the required size.
  */
  if( SQLITE_OK==(rc = sqlite3OsFileSize(pPager->jfd, &jrnlSize))
   && jrnlSize>pPager->journalOff
  ){
    rc = sqlite3OsTruncate(pPager->jfd, pPager->journalOff);
  }
  return rc;
}

// Assembly:
xorl %eax, %eax
testq %rsi, %rsi
je 0x2977d3
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpb $0x4, 0x9(%rdi)
je 0x2977c5
movq 0x50(%rbx), %rdi
movq (%rdi), %r8
testq %r8, %r8
je 0x2977c5
movq %rsi, %r15
movb $0x1, 0x17(%rbx)
movb (%rsi), %al
testb %al, %al
je 0x2976a8
xorl %r13d, %r13d
xorl %ebp, %ebp
movsbl %al, %eax
addl %eax, %ebp
movb 0x1(%r15,%r13), %al
incq %r13
testb %al, %al
jne 0x297692
movl %r13d, %r14d
jmp 0x2976b0
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpb $0x0, 0xc(%rbx)
je 0x2976dc
movq 0x60(%rbx), %rax
testq %rax, %rax
je 0x2976d6
decq %rax
movl 0xb8(%rbx), %ecx
cqto
idivq %rcx
incq %rax
imulq %rcx, %rax
jmp 0x2976d8
xorl %eax, %eax
movq %rax, 0x60(%rbx)
movq 0x60(%rbx), %r12
movl 0x22f3da(%rip), %eax    # 0x4c6ac0
cltd
idivl 0xbc(%rbx)
incl %eax
bswapl %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r12, %rcx
callq *0x18(%r8)
testl %eax, %eax
jne 0x2977c5
movq 0x50(%rbx), %rdi
addq $0x4, %r12
movq (%rdi), %rax
movq %r15, %rsi
movl %r14d, %edx
movq %r12, %rcx
callq *0x18(%rax)
testl %eax, %eax
jne 0x2977c5
movq 0x50(%rbx), %rdi
addq %r13, %r12
movl %r14d, %eax
bswapl %eax
movq %rsp, %rsi
movl %eax, (%rsi)
movq (%rdi), %rax
movl $0x4, %edx
movq %r12, %rcx
callq *0x18(%rax)
testl %eax, %eax
jne 0x2977c5
movq 0x50(%rbx), %rdi
leaq 0x4(%r12), %rcx
bswapl %ebp
movq %rsp, %rsi
movl %ebp, (%rsi)
movq (%rdi), %rax
movl $0x4, %edx
callq *0x18(%rax)
testl %eax, %eax
jne 0x2977c5
movq 0x50(%rbx), %rdi
addq $0x8, %r12
movq (%rdi), %rax
leaq 0x143ae2(%rip), %rsi    # 0x3db25f
movl $0x8, %edx
movq %r12, %rcx
callq *0x18(%rax)
testl %eax, %eax
jne 0x2977c5
movl %r14d, %eax
movq 0x50(%rbx), %rdi
movq 0x60(%rbx), %rcx
addq %rcx, %rax
addq $0x14, %rax
movq %rax, 0x60(%rbx)
movq (%rdi), %rax
movq %rsp, %rsi
callq *0x30(%rax)
testl %eax, %eax
jne 0x2977c5
movq 0x60(%rbx), %rsi
xorl %eax, %eax
cmpq %rsi, (%rsp)
jle 0x2977c5
movq 0x50(%rbx), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq