// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: writeMasterJournal
static int writeMasterJournal(Pager *pPager, const char *zMaster){
  int rc;                          /* Return code */
  int nMaster;                     /* Length of string zMaster */
  i64 iHdrOff;                     /* Offset of header in journal file */
  i64 jrnlSize;                    /* Size of journal file on disk */
  u32 cksum = 0;                   /* Checksum of string zMaster */

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

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

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

  /* If in full-sync mode, advance to the next disk sector before writing
  ** the master 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 master 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, zMaster, nMaster, iHdrOff+4)))
   || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nMaster, nMaster)))
   || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nMaster+4, cksum)))
   || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8, iHdrOff+4+nMaster+8)))
  ){
    return rc;
  }
  pPager->journalOff += (nMaster+20);

  /* If the pager is in peristent-journal mode, then the physical 
  ** journal-file may extend past the end of the master-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 master-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:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x34(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x2b2a8
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x4, %eax
je 0x2b2a8
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x2, %eax
jne 0x2b2b4
movl $0x0, -0x4(%rbp)
jmp 0x2b46d
movq -0x10(%rbp), %rax
movb $0x1, 0x16(%rax)
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x2b2ee
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2b2c3
movq -0x10(%rbp), %rax
cmpb $0x0, 0xc(%rax)
je 0x2b30c
movq -0x10(%rbp), %rdi
callq 0x244b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x28(%rbp), %rsi
movl 0xa55a6(%rip), %eax     # 0xd08d0
movq -0x10(%rbp), %rcx
cltd
idivl 0xbc(%rcx)
movl %eax, %edx
addl $0x1, %edx
callq 0x21b50
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x2b408
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x20(%rbp), %edx
movq -0x28(%rbp), %rcx
addq $0x4, %rcx
callq 0xf430
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x2b408
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x4, %rsi
movslq -0x20(%rbp), %rax
addq %rax, %rsi
movl -0x20(%rbp), %edx
callq 0x21b50
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x2b408
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x4, %rsi
movslq -0x20(%rbp), %rax
addq %rax, %rsi
addq $0x4, %rsi
movl -0x34(%rbp), %edx
callq 0x21b50
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x2b408
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x28(%rbp), %rcx
addq $0x4, %rcx
movslq -0x20(%rbp), %rax
addq %rax, %rcx
addq $0x8, %rcx
leaq 0x7fad1(%rip), %rsi     # 0xaaec4
movl $0x8, %edx
callq 0xf430
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
je 0x2b410
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2b46d
movl -0x20(%rbp), %eax
addl $0x14, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
addq 0x60(%rax), %rcx
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x23e00
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x2b467
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x60(%rcx), %rax
jle 0x2b467
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rsi
callq 0x241d0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)