// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: unixWrite
static int unixWrite(
  sqlite3_file *id, 
  const void *pBuf, 
  int amt,
  sqlite3_int64 offset 
){
  unixFile *pFile = (unixFile*)id;
  int wrote = 0;
  assert( id );
  assert( amt>0 );

  /* If this is a database file (not a journal, master-journal or temp
  ** file), the bytes in the locking range should never be read or written. */
#if 0
  assert( pFile->pUnused==0
       || offset>=PENDING_BYTE+512
       || offset+amt<=PENDING_BYTE 
  );
#endif

#ifdef SQLITE_DEBUG
  /* If we are doing a normal write to a database file (as opposed to
  ** doing a hot-journal rollback or a write to some file other than a
  ** normal database file) then record the fact that the database
  ** has changed.  If the transaction counter is modified, record that
  ** fact too.
  */
  if( pFile->inNormalWrite ){
    pFile->dbUpdate = 1;  /* The database has been modified */
    if( offset<=24 && offset+amt>=27 ){
      int rc;
      char oldCntr[4];
      SimulateIOErrorBenign(1);
      rc = seekAndRead(pFile, 24, oldCntr, 4);
      SimulateIOErrorBenign(0);
      if( rc!=4 || memcmp(oldCntr, &((char*)pBuf)[24-offset], 4)!=0 ){
        pFile->transCntrChng = 1;  /* The transaction counter has changed */
      }
    }
  }
#endif

#if SQLITE_MAX_MMAP_SIZE>0
  /* Deal with as much of this write request as possible by transfering
  ** data from the memory mapping using memcpy().  */
  if( offset<pFile->mmapSize ){
    if( offset+amt <= pFile->mmapSize ){
      memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
      return SQLITE_OK;
    }else{
      int nCopy = pFile->mmapSize - offset;
      memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
      pBuf = &((u8 *)pBuf)[nCopy];
      amt -= nCopy;
      offset += nCopy;
    }
  }
#endif

  while( amt>0 && (wrote = seekAndWrite(pFile, offset, pBuf, amt))>0 ){
    amt -= wrote;
    offset += wrote;
    pBuf = &((char*)pBuf)[wrote];
  }
  SimulateIOError(( wrote=(-1), amt=1 ));
  SimulateDiskfullError(( wrote=0, amt=1 ));

  if( amt>0 ){
    if( wrote<0 && pFile->lastErrno!=ENOSPC ){
      /* lastErrno set by seekAndWrite */
      return SQLITE_IOERR_WRITE;
    }else{
      pFile->lastErrno = 0; /* not a system error */
      return SQLITE_FULL;
    }
  }

  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, -0x30(%rbp)
movq 0x50(%rdi), %rcx
movq %rcx, %rax
subq %r14, %rax
jle 0x17802
movslq %r12d, %rdx
leaq (%rdx,%r14), %rsi
cmpq %rcx, %rsi
jle 0x1787b
movq -0x30(%rbp), %rcx
movq 0x68(%rcx), %rdi
addq %r14, %rdi
movslq %eax, %r13
movq %r15, %rsi
movq %r13, %rdx
callq 0x82f0
addq %r13, %r15
subl %r13d, %r12d
addq %r13, %r14
xorl %ecx, %ecx
testl %r12d, %r12d
setg %bl
jle 0x17850
movq -0x30(%rbp), %rax
leaq 0x20(%rax), %r13
movl 0x18(%rax), %edi
movq %r14, %rsi
movq %r15, %rdx
movl %r12d, %ecx
movq %r13, %r8
callq 0x18f86
testl %eax, %eax
jle 0x17849
movl %r12d, %ecx
subl %eax, %ecx
testl %ecx, %ecx
setg %bl
subl %eax, %r12d
jle 0x17849
movl %eax, %eax
addq %rax, %r14
addq %rax, %r15
movq -0x30(%rbp), %rax
jmp 0x17814
shrl $0x1f, %eax
xorl %ecx, %ecx
jmp 0x17852
xorl %eax, %eax
testb %bl, %bl
je 0x17890
testb %al, %al
je 0x17869
movl $0x30a, %ecx            # imm = 0x30A
movq -0x30(%rbp), %rax
cmpl $0x1c, 0x20(%rax)
jne 0x17890
movq -0x30(%rbp), %rax
movl $0x0, 0x20(%rax)
movl $0xd, %ecx
jmp 0x17890
movq -0x30(%rbp), %rax
addq 0x68(%rax), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x82f0
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq