#define _USE_LARGEFILE
#define _FILE_OFFSET_BITS 64

#include <stdlib.h>
#include <stdint.h>

#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv)
{
  int f;
  uint64_t buf[4096/8], ofs, size;

  f = open(argv[1], O_RDWR | O_CREAT|O_TRUNC, 0666);
  if (f == -1) exit(1);

  ofs = atoll(argv[2]) << 20;
  size = atoll(argv[3]) << 20;

  if (lseek(f, ofs, SEEK_SET) != ofs) exit(2);

  for (; ofs<size; ofs+=8) {
	buf[(ofs&4095)/8] = ofs;
	if ((ofs&4095)/8==4095/8) write(f, buf, 4096);
  }
  if (size&4095) write(f, buf, size&4095);
  close(f);
}

