// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/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;

  /* An in-memory journal file should only ever be appended to. Random
  ** access writes are not required by sqlite.
  */
  assert( iOfst==p->endpoint.iOffset );
  UNUSED_PARAMETER(iOfst);

  while( nWrite>0 ){
    FileChunk *pChunk = p->endpoint.pChunk;
    int iChunkOffset = (int)(p->endpoint.iOffset%JOURNAL_CHUNKSIZE);
    int iSpace = MIN(nWrite, JOURNAL_CHUNKSIZE - iChunkOffset);

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

    memcpy(&p->endpoint.pChunk->zChunk[iChunkOffset], zWrite, iSpace);
    zWrite += iSpace;
    nWrite -= iSpace;
    p->endpoint.iOffset += iSpace;
  }

  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %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)
cmpl $0x0, -0x34(%rbp)
jle 0x21fa1
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl $0x3f8, %ecx            # imm = 0x3F8
cqto
idivq %rcx
movl %edx, %eax
movl %eax, -0x4c(%rbp)
movl -0x34(%rbp), %eax
movl $0x3f8, %ecx            # imm = 0x3F8
subl -0x4c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x21ee1
movl -0x34(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0x21eec
movl $0x3f8, %eax            # imm = 0x3F8
subl -0x4c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x21f50
movl $0x400, %edi            # imm = 0x400
callq 0xa380
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x21f19
movl $0xc0a, -0x4(%rbp)      # imm = 0xC0A
jmp 0x21fa8
movq -0x58(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, -0x48(%rbp)
je 0x21f38
movq -0x58(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
jmp 0x21f44
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x8, %rdi
movslq -0x4c(%rbp), %rax
addq %rax, %rdi
movq -0x40(%rbp), %rsi
movslq -0x50(%rbp), %rdx
callq 0x82f0
movl -0x50(%rbp), %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x50(%rbp), %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
movslq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
jmp 0x21e9d
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)