// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: memjrnlWrite
static int memjrnlWrite(
  sqlite3_file *pJfd,    /* The journal file into which to write */
  const void *zBuf,      /* Take data to be written from here */
  int iAmt,              /* Number of bytes to write */
  sqlite_int64 iOfst     /* Begin writing at this offset into the file */
){
  MemJournal *p = (MemJournal *)pJfd;
  int nWrite = iAmt;
  u8 *zWrite = (u8 *)zBuf;

  /* If the file should be created now, create it and write the new data
  ** into the file on disk. */
  if( p->nSpill>0 && (iAmt+iOfst)>p->nSpill ){
    int rc = memjrnlCreateFile(p);
    if( rc==SQLITE_OK ){
      rc = sqlite3OsWrite(pJfd, zBuf, iAmt, iOfst);
    }
    return rc;
  }

  /* If the contents of this write should be stored in memory */
  else{
    /* An in-memory journal file should only ever be appended to. Random
    ** access writes are not required. The only exception to this is when
    ** the in-memory journal is being used by a connection using the
    ** atomic-write optimization. In this case the first 28 bytes of the
    ** journal file may be written as part of committing the transaction. */
    assert( iOfst==p->endpoint.iOffset || iOfst==0 );
#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
    if( iOfst==0 && p->pFirst ){
      assert( p->nChunkSize>iAmt );
      memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt);
    }else
#else
    assert( iOfst>0 || p->pFirst==0 );
#endif
    {
      while( nWrite>0 ){
        FileChunk *pChunk = p->endpoint.pChunk;
        int iChunkOffset = (int)(p->endpoint.iOffset%p->nChunkSize);
        int iSpace = MIN(nWrite, p->nChunkSize - iChunkOffset);

        if( iChunkOffset==0 ){
          /* New chunk is required to extend the file. */
          FileChunk *pNew = sqlite3_malloc(fileChunkSize(p->nChunkSize));
          if( !pNew ){
            return SQLITE_IOERR_NOMEM_BKPT;
          }
          pNew->pNext = 0;
          if( pChunk ){
            assert( p->pFirst );
            pChunk->pNext = pNew;
          }else{
            assert( !p->pFirst );
            p->pFirst = pNew;
          }
          p->endpoint.pChunk = pNew;
        }

        memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace);
        zWrite += iSpace;
        nWrite -= iSpace;
        p->endpoint.iOffset += iSpace;
      }
      p->nSize = iAmt + iOfst;
    }
  }

  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jle 0x3dce90
movslq -0x1c(%rbp), %rax
addq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq 0xc(%rcx), %rcx
cmpq %rcx, %rax
jle 0x3dce90
movq -0x30(%rbp), %rdi
callq 0x3dd0d0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x3dce85
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x3c6930
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3dcfc2
jmp 0x3dce92
cmpl $0x0, -0x34(%rbp)
jle 0x3dcfaa
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
movslq 0x8(%rcx), %rcx
cqto
idivq %rcx
movl %edx, %eax
movl %eax, -0x54(%rbp)
movl -0x34(%rbp), %eax
movq -0x30(%rbp), %rcx
movl 0x8(%rcx), %ecx
subl -0x54(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3dcedb
movl -0x34(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x3dcee8
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
subl -0x54(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x54(%rbp)
jne 0x3dcf59
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x8, %eax
cltq
addq $0x10, %rax
movl %eax, %edi
callq 0x3c0710
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x3dcf22
movl $0xc0a, -0x4(%rbp)      # imm = 0xC0A
jmp 0x3dcfc2
movq -0x60(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, -0x50(%rbp)
je 0x3dcf41
movq -0x60(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
jmp 0x3dcf4d
movq -0x60(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x60(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdi
addq $0x8, %rdi
movslq -0x54(%rbp), %rax
addq %rax, %rdi
movq -0x40(%rbp), %rsi
movslq -0x58(%rbp), %rdx
callq 0x19610
movl -0x58(%rbp), %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x58(%rbp), %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movslq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
jmp 0x3dce92
movslq -0x1c(%rbp), %rax
addq -0x28(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)