// https://syzkaller.appspot.com/bug?id=18c0c49921bc69a249c353bf7d52dfda9bd8dfdc
// autogenerated by syzkaller (https://github.com/google/syzkaller)

#define _GNU_SOURCE

#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

#include <linux/capability.h>
#include <linux/loop.h>

#ifndef __NR_memfd_create
#define __NR_memfd_create 319
#endif

static unsigned long long procid;

static void sleep_ms(uint64_t ms)
{
  usleep(ms * 1000);
}

static uint64_t current_time_ms(void)
{
  struct timespec ts;
  if (clock_gettime(CLOCK_MONOTONIC, &ts))
    exit(1);
  return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}

static bool write_file(const char* file, const char* what, ...)
{
  char buf[1024];
  va_list args;
  va_start(args, what);
  vsnprintf(buf, sizeof(buf), what, args);
  va_end(args);
  buf[sizeof(buf) - 1] = 0;
  int len = strlen(buf);
  int fd = open(file, O_WRONLY | O_CLOEXEC);
  if (fd == -1)
    return false;
  if (write(fd, buf, len) != len) {
    int err = errno;
    close(fd);
    errno = err;
    return false;
  }
  close(fd);
  return true;
}

#define MAX_FDS 30

static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
{
  if (a0 == 0xc || a0 == 0xb) {
    char buf[128];
    sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1,
            (uint8_t)a2);
    return open(buf, O_RDWR, 0);
  } else {
    char buf[1024];
    char* hash;
    strncpy(buf, (char*)a0, sizeof(buf) - 1);
    buf[sizeof(buf) - 1] = 0;
    while ((hash = strchr(buf, '#'))) {
      *hash = '0' + (char)(a1 % 10);
      a1 /= 10;
    }
    return open(buf, a2, 0);
  }
}

//% This code is derived from puff.{c,h}, found in the zlib development. The
//% original files come with the following copyright notice:

//% Copyright (C) 2002-2013 Mark Adler, all rights reserved
//% version 2.3, 21 Jan 2013
//% This software is provided 'as-is', without any express or implied
//% warranty.  In no event will the author be held liable for any damages
//% arising from the use of this software.
//% Permission is granted to anyone to use this software for any purpose,
//% including commercial applications, and to alter it and redistribute it
//% freely, subject to the following restrictions:
//% 1. The origin of this software must not be misrepresented; you must not
//%    claim that you wrote the original software. If you use this software
//%    in a product, an acknowledgment in the product documentation would be
//%    appreciated but is not required.
//% 2. Altered source versions must be plainly marked as such, and must not be
//%    misrepresented as being the original software.
//% 3. This notice may not be removed or altered from any source distribution.
//% Mark Adler    madler@alumni.caltech.edu

//% BEGIN CODE DERIVED FROM puff.{c,h}

#define MAXBITS 15
#define MAXLCODES 286
#define MAXDCODES 30
#define MAXCODES (MAXLCODES + MAXDCODES)
#define FIXLCODES 288

struct puff_state {
  unsigned char* out;
  unsigned long outlen;
  unsigned long outcnt;
  const unsigned char* in;
  unsigned long inlen;
  unsigned long incnt;
  int bitbuf;
  int bitcnt;
  jmp_buf env;
};
static int puff_bits(struct puff_state* s, int need)
{
  long val = s->bitbuf;
  while (s->bitcnt < need) {
    if (s->incnt == s->inlen)
      longjmp(s->env, 1);
    val |= (long)(s->in[s->incnt++]) << s->bitcnt;
    s->bitcnt += 8;
  }
  s->bitbuf = (int)(val >> need);
  s->bitcnt -= need;
  return (int)(val & ((1L << need) - 1));
}
static int puff_stored(struct puff_state* s)
{
  s->bitbuf = 0;
  s->bitcnt = 0;
  if (s->incnt + 4 > s->inlen)
    return 2;
  unsigned len = s->in[s->incnt++];
  len |= s->in[s->incnt++] << 8;
  if (s->in[s->incnt++] != (~len & 0xff) ||
      s->in[s->incnt++] != ((~len >> 8) & 0xff))
    return -2;
  if (s->incnt + len > s->inlen)
    return 2;
  if (s->outcnt + len > s->outlen)
    return 1;
  for (; len--; s->outcnt++, s->incnt++) {
    if (s->in[s->incnt])
      s->out[s->outcnt] = s->in[s->incnt];
  }
  return 0;
}
struct puff_huffman {
  short* count;
  short* symbol;
};
static int puff_decode(struct puff_state* s, const struct puff_huffman* h)
{
  int first = 0;
  int index = 0;
  int bitbuf = s->bitbuf;
  int left = s->bitcnt;
  int code = first = index = 0;
  int len = 1;
  short* next = h->count + 1;
  while (1) {
    while (left--) {
      code |= bitbuf & 1;
      bitbuf >>= 1;
      int count = *next++;
      if (code - count < first) {
        s->bitbuf = bitbuf;
        s->bitcnt = (s->bitcnt - len) & 7;
        return h->symbol[index + (code - first)];
      }
      index += count;
      first += count;
      first <<= 1;
      code <<= 1;
      len++;
    }
    left = (MAXBITS + 1) - len;
    if (left == 0)
      break;
    if (s->incnt == s->inlen)
      longjmp(s->env, 1);
    bitbuf = s->in[s->incnt++];
    if (left > 8)
      left = 8;
  }
  return -10;
}
static int puff_construct(struct puff_huffman* h, const short* length, int n)
{
  int len;
  for (len = 0; len <= MAXBITS; len++)
    h->count[len] = 0;
  int symbol;
  for (symbol = 0; symbol < n; symbol++)
    (h->count[length[symbol]])++;
  if (h->count[0] == n)
    return 0;
  int left = 1;
  for (len = 1; len <= MAXBITS; len++) {
    left <<= 1;
    left -= h->count[len];
    if (left < 0)
      return left;
  }
  short offs[MAXBITS + 1];
  offs[1] = 0;
  for (len = 1; len < MAXBITS; len++)
    offs[len + 1] = offs[len] + h->count[len];
  for (symbol = 0; symbol < n; symbol++)
    if (length[symbol] != 0)
      h->symbol[offs[length[symbol]]++] = symbol;
  return left;
}
static int puff_codes(struct puff_state* s, const struct puff_huffman* lencode,
                      const struct puff_huffman* distcode)
{
  static const short lens[29] = {3,  4,  5,  6,   7,   8,   9,   10,  11, 13,
                                 15, 17, 19, 23,  27,  31,  35,  43,  51, 59,
                                 67, 83, 99, 115, 131, 163, 195, 227, 258};
  static const short lext[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2,
                                 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
  static const short dists[30] = {
      1,    2,    3,    4,    5,    7,    9,    13,    17,    25,
      33,   49,   65,   97,   129,  193,  257,  385,   513,   769,
      1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577};
  static const short dext[30] = {0, 0, 0,  0,  1,  1,  2,  2,  3,  3,
                                 4, 4, 5,  5,  6,  6,  7,  7,  8,  8,
                                 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
  int symbol;
  do {
    symbol = puff_decode(s, lencode);
    if (symbol < 0)
      return symbol;
    if (symbol < 256) {
      if (s->outcnt == s->outlen)
        return 1;
      if (symbol)
        s->out[s->outcnt] = symbol;
      s->outcnt++;
    } else if (symbol > 256) {
      symbol -= 257;
      if (symbol >= 29)
        return -10;
      int len = lens[symbol] + puff_bits(s, lext[symbol]);
      symbol = puff_decode(s, distcode);
      if (symbol < 0)
        return symbol;
      unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]);
      if (dist > s->outcnt)
        return -11;
      if (s->outcnt + len > s->outlen)
        return 1;
      while (len--) {
        if (dist <= s->outcnt && s->out[s->outcnt - dist])
          s->out[s->outcnt] = s->out[s->outcnt - dist];
        s->outcnt++;
      }
    }
  } while (symbol != 256);
  return 0;
}
static int puff_fixed(struct puff_state* s)
{
  static int virgin = 1;
  static short lencnt[MAXBITS + 1], lensym[FIXLCODES];
  static short distcnt[MAXBITS + 1], distsym[MAXDCODES];
  static struct puff_huffman lencode, distcode;
  if (virgin) {
    lencode.count = lencnt;
    lencode.symbol = lensym;
    distcode.count = distcnt;
    distcode.symbol = distsym;
    short lengths[FIXLCODES];
    int symbol;
    for (symbol = 0; symbol < 144; symbol++)
      lengths[symbol] = 8;
    for (; symbol < 256; symbol++)
      lengths[symbol] = 9;
    for (; symbol < 280; symbol++)
      lengths[symbol] = 7;
    for (; symbol < FIXLCODES; symbol++)
      lengths[symbol] = 8;
    puff_construct(&lencode, lengths, FIXLCODES);
    for (symbol = 0; symbol < MAXDCODES; symbol++)
      lengths[symbol] = 5;
    puff_construct(&distcode, lengths, MAXDCODES);
    virgin = 0;
  }
  return puff_codes(s, &lencode, &distcode);
}
static int puff_dynamic(struct puff_state* s)
{
  static const short order[19] = {16, 17, 18, 0, 8,  7, 9,  6, 10, 5,
                                  11, 4,  12, 3, 13, 2, 14, 1, 15};
  int nlen = puff_bits(s, 5) + 257;
  int ndist = puff_bits(s, 5) + 1;
  int ncode = puff_bits(s, 4) + 4;
  if (nlen > MAXLCODES || ndist > MAXDCODES)
    return -3;
  short lengths[MAXCODES];
  int index;
  for (index = 0; index < ncode; index++)
    lengths[order[index]] = puff_bits(s, 3);
  for (; index < 19; index++)
    lengths[order[index]] = 0;
  short lencnt[MAXBITS + 1], lensym[MAXLCODES];
  struct puff_huffman lencode = {lencnt, lensym};
  int err = puff_construct(&lencode, lengths, 19);
  if (err != 0)
    return -4;
  index = 0;
  while (index < nlen + ndist) {
    int symbol;
    int len;
    symbol = puff_decode(s, &lencode);
    if (symbol < 0)
      return symbol;
    if (symbol < 16)
      lengths[index++] = symbol;
    else {
      len = 0;
      if (symbol == 16) {
        if (index == 0)
          return -5;
        len = lengths[index - 1];
        symbol = 3 + puff_bits(s, 2);
      } else if (symbol == 17)
        symbol = 3 + puff_bits(s, 3);
      else
        symbol = 11 + puff_bits(s, 7);
      if (index + symbol > nlen + ndist)
        return -6;
      while (symbol--)
        lengths[index++] = len;
    }
  }
  if (lengths[256] == 0)
    return -9;
  err = puff_construct(&lencode, lengths, nlen);
  if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1]))
    return -7;
  short distcnt[MAXBITS + 1], distsym[MAXDCODES];
  struct puff_huffman distcode = {distcnt, distsym};
  err = puff_construct(&distcode, lengths + nlen, ndist);
  if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1]))
    return -8;
  return puff_codes(s, &lencode, &distcode);
}
static int puff(unsigned char* dest, unsigned long* destlen,
                const unsigned char* source, unsigned long sourcelen)
{
  struct puff_state s = {
      .out = dest,
      .outlen = *destlen,
      .outcnt = 0,
      .in = source,
      .inlen = sourcelen,
      .incnt = 0,
      .bitbuf = 0,
      .bitcnt = 0,
  };
  int err;
  if (setjmp(s.env) != 0)
    err = 2;
  else {
    int last;
    do {
      last = puff_bits(&s, 1);
      int type = puff_bits(&s, 2);
      err = type == 0 ? puff_stored(&s)
                      : (type == 1 ? puff_fixed(&s)
                                   : (type == 2 ? puff_dynamic(&s) : -1));
      if (err != 0)
        break;
    } while (!last);
  }
  *destlen = s.outcnt;
  return err;
}

//% END CODE DERIVED FROM puff.{c,h}

#define ZLIB_HEADER_WIDTH 2

static int puff_zlib_to_file(const unsigned char* source,
                             unsigned long sourcelen, int dest_fd)
{
  if (sourcelen < ZLIB_HEADER_WIDTH)
    return 0;
  source += ZLIB_HEADER_WIDTH;
  sourcelen -= ZLIB_HEADER_WIDTH;
  const unsigned long max_destlen = 132 << 20;
  void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ,
                   MAP_PRIVATE | MAP_ANON, -1, 0);
  if (ret == MAP_FAILED)
    return -1;
  unsigned char* dest = (unsigned char*)ret;
  unsigned long destlen = max_destlen;
  int err = puff(dest, &destlen, source, sourcelen);
  if (err) {
    munmap(dest, max_destlen);
    errno = -err;
    return -1;
  }
  if (write(dest_fd, dest, destlen) != (ssize_t)destlen) {
    munmap(dest, max_destlen);
    return -1;
  }
  return munmap(dest, max_destlen);
}

static int setup_loop_device(unsigned char* data, unsigned long size,
                             const char* loopname, int* loopfd_p)
{
  int err = 0, loopfd = -1;
  int memfd = syscall(__NR_memfd_create, "syzkaller", 0);
  if (memfd == -1) {
    err = errno;
    goto error;
  }
  if (puff_zlib_to_file(data, size, memfd)) {
    err = errno;
    goto error_close_memfd;
  }
  loopfd = open(loopname, O_RDWR);
  if (loopfd == -1) {
    err = errno;
    goto error_close_memfd;
  }
  if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
    if (errno != EBUSY) {
      err = errno;
      goto error_close_loop;
    }
    ioctl(loopfd, LOOP_CLR_FD, 0);
    usleep(1000);
    if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
      err = errno;
      goto error_close_loop;
    }
  }
  close(memfd);
  *loopfd_p = loopfd;
  return 0;

error_close_loop:
  close(loopfd);
error_close_memfd:
  close(memfd);
error:
  errno = err;
  return -1;
}

static void reset_loop_device(const char* loopname)
{
  int loopfd = open(loopname, O_RDWR);
  if (loopfd == -1) {
    return;
  }
  if (ioctl(loopfd, LOOP_CLR_FD, 0)) {
  }
  close(loopfd);
}

static long syz_mount_image(volatile long fsarg, volatile long dir,
                            volatile long flags, volatile long optsarg,
                            volatile long change_dir,
                            volatile unsigned long size, volatile long image)
{
  unsigned char* data = (unsigned char*)image;
  int res = -1, err = 0, need_loop_device = !!size;
  char* mount_opts = (char*)optsarg;
  char* target = (char*)dir;
  char* fs = (char*)fsarg;
  char* source = NULL;
  char loopname[64];
  if (need_loop_device) {
    int loopfd;
    memset(loopname, 0, sizeof(loopname));
    snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
    if (setup_loop_device(data, size, loopname, &loopfd) == -1)
      return -1;
    close(loopfd);
    source = loopname;
  }
  mkdir(target, 0777);
  char opts[256];
  memset(opts, 0, sizeof(opts));
  if (strlen(mount_opts) > (sizeof(opts) - 32)) {
  }
  strncpy(opts, mount_opts, sizeof(opts) - 32);
  if (strcmp(fs, "iso9660") == 0) {
    flags |= MS_RDONLY;
  } else if (strncmp(fs, "ext", 3) == 0) {
    bool has_remount_ro = false;
    char* remount_ro_start = strstr(opts, "errors=remount-ro");
    if (remount_ro_start != NULL) {
      char after = *(remount_ro_start + strlen("errors=remount-ro"));
      char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1);
      has_remount_ro = ((before == '\0' || before == ',') &&
                        (after == '\0' || after == ','));
    }
    if (strstr(opts, "errors=panic") || !has_remount_ro)
      strcat(opts, ",errors=continue");
  } else if (strcmp(fs, "xfs") == 0) {
    strcat(opts, ",nouuid");
  }
  res = mount(source, target, fs, flags, opts);
  if (res == -1) {
    err = errno;
    goto error_clear_loop;
  }
  res = open(target, O_RDONLY | O_DIRECTORY);
  if (res == -1) {
    err = errno;
    goto error_clear_loop;
  }
  if (change_dir) {
    res = chdir(target);
    if (res == -1) {
      err = errno;
    }
  }

error_clear_loop:
  if (need_loop_device)
    reset_loop_device(loopname);
  errno = err;
  return res;
}

static void sandbox_common_mount_tmpfs(void)
{
  write_file("/proc/sys/fs/mount-max", "100000");
  if (mkdir("./syz-tmp", 0777))
    exit(1);
  if (mount("", "./syz-tmp", "tmpfs", 0, NULL))
    exit(1);
  if (mkdir("./syz-tmp/newroot", 0777))
    exit(1);
  if (mkdir("./syz-tmp/newroot/dev", 0700))
    exit(1);
  unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE;
  if (mount("/dev", "./syz-tmp/newroot/dev", NULL, bind_mount_flags, NULL))
    exit(1);
  if (mkdir("./syz-tmp/newroot/proc", 0700))
    exit(1);
  if (mount("syz-proc", "./syz-tmp/newroot/proc", "proc", 0, NULL))
    exit(1);
  if (mkdir("./syz-tmp/newroot/selinux", 0700))
    exit(1);
  const char* selinux_path = "./syz-tmp/newroot/selinux";
  if (mount("/selinux", selinux_path, NULL, bind_mount_flags, NULL)) {
    if (errno != ENOENT)
      exit(1);
    if (mount("/sys/fs/selinux", selinux_path, NULL, bind_mount_flags, NULL) &&
        errno != ENOENT)
      exit(1);
  }
  if (mkdir("./syz-tmp/newroot/sys", 0700))
    exit(1);
  if (mount("/sys", "./syz-tmp/newroot/sys", 0, bind_mount_flags, NULL))
    exit(1);
  if (mkdir("./syz-tmp/pivot", 0777))
    exit(1);
  if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) {
    if (chdir("./syz-tmp"))
      exit(1);
  } else {
    if (chdir("/"))
      exit(1);
    if (umount2("./pivot", MNT_DETACH))
      exit(1);
  }
  if (chroot("./newroot"))
    exit(1);
  if (chdir("/"))
    exit(1);
}

static void setup_common()
{
  if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
  }
}

static void setup_binderfs()
{
  if (mkdir("/dev/binderfs", 0777)) {
  }
  if (mount("binder", "/dev/binderfs", "binder", 0, NULL)) {
  }
  if (symlink("/dev/binderfs", "./binderfs")) {
  }
}

static void loop();

static void sandbox_common()
{
  prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  setsid();
  struct rlimit rlim;
  rlim.rlim_cur = rlim.rlim_max = (200 << 20);
  setrlimit(RLIMIT_AS, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 32 << 20;
  setrlimit(RLIMIT_MEMLOCK, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 136 << 20;
  setrlimit(RLIMIT_FSIZE, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 1 << 20;
  setrlimit(RLIMIT_STACK, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 128 << 20;
  setrlimit(RLIMIT_CORE, &rlim);
  rlim.rlim_cur = rlim.rlim_max = 256;
  setrlimit(RLIMIT_NOFILE, &rlim);
  if (unshare(CLONE_NEWNS)) {
  }
  if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
  }
  if (unshare(CLONE_NEWIPC)) {
  }
  if (unshare(0x02000000)) {
  }
  if (unshare(CLONE_NEWUTS)) {
  }
  if (unshare(CLONE_SYSVSEM)) {
  }
  typedef struct {
    const char* name;
    const char* value;
  } sysctl_t;
  static const sysctl_t sysctls[] = {
      {"/proc/sys/kernel/shmmax", "16777216"},
      {"/proc/sys/kernel/shmall", "536870912"},
      {"/proc/sys/kernel/shmmni", "1024"},
      {"/proc/sys/kernel/msgmax", "8192"},
      {"/proc/sys/kernel/msgmni", "1024"},
      {"/proc/sys/kernel/msgmnb", "1024"},
      {"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
  };
  unsigned i;
  for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
    write_file(sysctls[i].name, sysctls[i].value);
}

static int wait_for_loop(int pid)
{
  if (pid < 0)
    exit(1);
  int status = 0;
  while (waitpid(-1, &status, __WALL) != pid) {
  }
  return WEXITSTATUS(status);
}

static void drop_caps(void)
{
  struct __user_cap_header_struct cap_hdr = {};
  struct __user_cap_data_struct cap_data[2] = {};
  cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
  cap_hdr.pid = getpid();
  if (syscall(SYS_capget, &cap_hdr, &cap_data))
    exit(1);
  const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
  cap_data[0].effective &= ~drop;
  cap_data[0].permitted &= ~drop;
  cap_data[0].inheritable &= ~drop;
  if (syscall(SYS_capset, &cap_hdr, &cap_data))
    exit(1);
}

static int do_sandbox_none(void)
{
  if (unshare(CLONE_NEWPID)) {
  }
  int pid = fork();
  if (pid != 0)
    return wait_for_loop(pid);
  setup_common();
  sandbox_common();
  drop_caps();
  if (unshare(CLONE_NEWNET)) {
  }
  write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535");
  sandbox_common_mount_tmpfs();
  setup_binderfs();
  loop();
  exit(1);
}

static void kill_and_wait(int pid, int* status)
{
  kill(-pid, SIGKILL);
  kill(pid, SIGKILL);
  for (int i = 0; i < 100; i++) {
    if (waitpid(-1, status, WNOHANG | __WALL) == pid)
      return;
    usleep(1000);
  }
  DIR* dir = opendir("/sys/fs/fuse/connections");
  if (dir) {
    for (;;) {
      struct dirent* ent = readdir(dir);
      if (!ent)
        break;
      if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
        continue;
      char abort[300];
      snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
               ent->d_name);
      int fd = open(abort, O_WRONLY);
      if (fd == -1) {
        continue;
      }
      if (write(fd, abort, 1) < 0) {
      }
      close(fd);
    }
    closedir(dir);
  } else {
  }
  while (waitpid(-1, status, __WALL) != pid) {
  }
}

static void reset_loop()
{
  char buf[64];
  snprintf(buf, sizeof(buf), "/dev/loop%llu", procid);
  int loopfd = open(buf, O_RDWR);
  if (loopfd != -1) {
    ioctl(loopfd, LOOP_CLR_FD, 0);
    close(loopfd);
  }
}

static void setup_test()
{
  prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  setpgrp();
  write_file("/proc/self/oom_score_adj", "1000");
}

static void close_fds()
{
  for (int fd = 3; fd < MAX_FDS; fd++)
    close(fd);
}

static void execute_one(void);

#define WAIT_FLAGS __WALL

static void loop(void)
{
  int iter = 0;
  for (;; iter++) {
    reset_loop();
    int pid = fork();
    if (pid < 0)
      exit(1);
    if (pid == 0) {
      setup_test();
      execute_one();
      close_fds();
      exit(0);
    }
    int status = 0;
    uint64_t start = current_time_ms();
    for (;;) {
      sleep_ms(10);
      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
        break;
      if (current_time_ms() - start < 5000)
        continue;
      kill_and_wait(pid, &status);
      break;
    }
  }
}

uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff};

void execute_one(void)
{
  intptr_t res = 0;
  if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  }
  memcpy((void*)0x20000080, "udf\000", 4);
  memcpy((void*)0x20000180, "./file1\000", 8);
  memcpy((void*)0x20000740,
         "lastblock=00000000000000000000,umask=00000000000000000000002,dmode="
         "00000000000000000077777,novrs,shortad,shortad,undelete,iocharset="
         "cp437,shortad,umask=00000000000000000000006,dmode="
         "00000000000000000000011,fileset=00000000000000000011,uid=",
         239);
  sprintf((char*)0x2000082f, "%020llu", (long long)-1);
  memcpy((void*)0x20000843, ",session=0000\000000000000000005,\000", 31);
  memcpy(
      (void*)0x20001080,
      "\x78\x9c\xec\xdd\x4f\x6c\x1c\xd7\x7d\x07\xf0\xdf\x1b\x2d\xc5\x95\xdc\x56"
      "\x4c\xec\x28\x4e\x1a\xb7\x9b\xa6\x48\x65\xc5\x72\xf5\x2f\xa6\x62\x15\xee"
      "\xaa\xa6\xd9\x06\x90\x65\x21\x14\x73\x0b\xc0\x95\x48\xa9\x0b\x53\x24\x41"
      "\x52\x8d\x6c\xa4\x05\xd3\x4b\x0f\x3d\x04\x28\x8a\x1e\x72\x22\xd0\x1a\x05"
      "\x52\x34\x30\x9a\x22\xe8\x91\x69\x5d\x20\xb9\xf8\x50\xe4\xd4\x13\xd1\xc2"
      "\x46\x50\xf4\xc0\x16\x01\x72\x0a\x18\xcc\xec\x5b\x71\x49\x91\x36\x23\x92"
      "\x12\x69\x7d\x3e\x36\xf5\xdd\x9d\x7d\x6f\xe6\xbd\x79\xeb\x19\x59\xd0\x9b"
      "\x17\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\xc4\x1f\xbc"
      "\x72\xe9\xf4\x99\xf4\xa8\x5b\x01\x00\x3c\x4c\x57\x46\xbe\x72\xfa\xac\xfb"
      "\x3f\x00\x3c\x56\xae\xf9\xff\x7f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\xd8\xef\x52\x14\xf1\x64\xa4\x98\xb9\xb2\x92\xc6\xaa\xf7\x1d\xf5\xcb"
      "\xed\xbe\x3b\x77\x47\x87\x86\x37\xaf\x76\x24\x55\x35\x0f\x55\xe5\xcb\x9f"
      "\xfa\x99\xb3\xe7\xce\x7f\xf1\x85\xc1\x0b\xdd\xbc\xdc\x9e\xfa\x80\xfa\xbb"
      "\xed\xd3\xf1\xda\xc8\xb5\x4b\x8d\x97\xa7\x6f\xcf\xcc\x4e\xcc\xcd\x4d\x8c"
      "\x37\x46\xa7\xda\x37\xa6\xc7\x27\xb6\xbd\x87\x9d\xd6\xdf\xe8\x64\x75\x02"
      "\x1a\xb7\x5f\xbf\x33\x7e\xf3\xe6\x5c\xe3\xec\xf3\xe7\xd6\x7d\x7c\x77\xe0"
      "\xfd\xfe\x27\x8e\x0f\x5c\x1c\x7c\xf6\xd4\x33\xdd\xb2\xa3\x43\xc3\xc3\x23"
      "\x6b\x45\xea\xbd\xe5\x6b\x0f\xdc\x90\x8e\xad\x66\x78\x1c\x8e\x22\x4e\x45"
      "\x8a\xe7\xbe\xfb\x93\xd4\x8a\x88\x22\x76\x7e\x2e\xea\x0f\x77\xec\x37\x3a"
      "\x52\x75\xe2\x64\xd5\x89\xd1\xa1\xe1\xaa\x23\x93\xed\xd6\xd4\x7c\xf9\xe1"
      "\xd5\xee\x89\x28\x22\x1a\x3d\x95\x9a\xdd\x73\xb4\xf9\x58\x44\xad\xef\xa1"
      "\xf6\x61\x6b\xcd\x88\x85\xb2\xf9\x65\x83\x4f\x96\xdd\x1b\x99\x69\xcd\xb6"
      "\xae\x4f\x4e\x34\xae\xb6\x66\xe7\xdb\xf3\xed\xe9\xa9\xab\xa9\xd3\xda\xb2"
      "\x3f\x8d\x28\xe2\x42\x8a\x58\x8c\x88\xe5\xfe\xfb\x77\xd7\x17\x45\xd4\x22"
      "\xc5\xb7\x8f\xad\xa4\xeb\x11\x71\xa8\x7b\x1e\xbe\x50\x4d\x0c\xde\xba\x1d"
      "\xc5\x1e\xf6\x71\x1b\xca\x76\x36\xfa\x22\x16\x8b\x03\x30\x66\xfb\x58\x7f"
      "\x14\xf1\x6a\xa4\xf8\xe9\x3b\x27\xe2\x46\xbe\xce\x54\xd7\x9a\xcf\x47\xbc"
      "\x5a\xe6\xf7\x23\xde\x2a\xf3\xa5\x88\x54\x7e\x31\xce\x47\xbc\xb7\xc9\xf7"
      "\x88\x83\xa9\x16\x45\xfc\x65\x39\xfe\x17\x57\xd2\x78\x75\x3d\xe8\x5e\x57"
      "\x2e\x7f\xb5\xf1\xe5\xa9\x9b\xd3\x3d\x65\xbb\xd7\x95\x5f\xf2\xfe\x70\xdf"
      "\x95\xe2\x11\xdd\x1f\x8e\x6c\xc8\x87\x63\x9f\x5f\x9b\xea\x51\x44\xab\xba"
      "\xe2\xaf\xa4\x07\xff\xcd\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\xbb\xed\x48\x14\xf1\xa9\x48\xf1\xca\x7f\xfc\x49\x35\xaf\x38\xaa"
      "\x79\xe9\xc7\x2e\x0e\xfe\xe1\xc0\xaf\xf6\xce\x19\x7f\xfa\x43\xf6\x53\x96"
      "\x7d\x3e\x22\x16\x8a\xed\xcd\xc9\x3d\x9c\x27\x06\x5e\x4d\x57\x53\x7a\xc4"
      "\x73\x89\x1f\x67\xf5\x28\xe2\x4f\xf3\xfc\xbf\x6f\x3e\xea\xc6\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3c\xd6\x8a\xf8\x71\xa4"
      "\x78\xf1\xdd\x13\x69\x31\x7a\xd7\x14\x6f\x4f\xdd\x6a\x5c\x6b\x5d\x9f\xec"
      "\xac\x0a\xdb\x5d\xfb\xb7\xbb\x66\xfa\xea\xea\xea\x6a\x23\x75\xb2\x99\x73"
      "\x2c\xe7\x42\xce\xc5\x9c\x4b\x39\x97\x73\x46\x91\xeb\xe7\x6c\xe6\x1c\xcb"
      "\xb9\x90\x73\x31\xe7\x52\xce\xe5\x9c\x71\x28\xd7\xcf\xd9\xcc\x39\x96\x73"
      "\x21\xe7\x62\xce\xa5\x9c\xcb\x39\xa3\x96\xeb\xe7\x6c\xe6\x1c\xcb\xb9\x90"
      "\x73\x31\x2f\xba\xbf\x94\xdf\x2f\xe7\x8c\x7d\xb2\x76\x2f\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\xc0\x47\x49\x11\x45\xfc\x3c\x52\x7c\xeb\xeb\x2b"
      "\x29\x52\x44\x34\x23\xc6\xa2\x93\x4b\xfd\x8f\xba\x75\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\xa9\x3f\x15"
      "\xf1\xbd\x48\xd1\xf8\xa3\xe6\xbd\x6d\xb5\x88\x48\xd5\xbf\x1d\x27\xca\x5f"
      "\xce\x47\xf3\x70\x99\x1f\x8f\xe6\x60\x99\x2f\x45\xf3\x52\xce\x56\x95\xb5"
      "\xe6\x37\x1f\x41\xfb\xd9\x99\xbe\x54\xc4\x8f\x22\x45\x7f\xfd\xed\x7b\x03"
      "\x9e\xc7\xbf\xaf\xf3\xee\xde\xd7\x20\xde\xfa\xc6\xda\xbb\x4f\xd7\x3a\x79"
      "\xa8\xfb\xe1\xc0\xfb\xfd\x4f\x1c\x3f\x76\x71\x70\xf8\x37\x9e\xde\xea\x75"
      "\xda\xac\x01\x27\x2f\xb7\xa7\xee\xdc\x6d\x8c\x0e\x0d\x0f\x8f\xf4\x6c\xae"
      "\xe5\xa3\x7f\xbc\x67\xdb\x40\x3e\x6e\xb1\x3b\x5d\x27\x22\xe6\xde\x78\xf3"
      "\xf5\xd6\xe4\xe4\xc4\xec\x83\xbf\x28\xbf\x02\x3b\xa8\x7e\x80\x5e\xa4\xda"
      "\xe3\xd2\xd3\x83\xfd\xe2\x37\x77\x6b\x87\x51\xdb\x0f\xdd\x79\x34\x2f\x1e"
      "\xf5\x95\x89\x87\xa1\xbc\xff\xbf\x17\x29\x7e\xf7\xdd\xff\xec\xde\xf0\x3b"
      "\xf7\xff\x7a\xfc\x4a\xe7\xdd\xbd\x3b\x7c\xfc\xec\xcf\xd6\xee\xff\x2f\x6e"
      "\xdc\xd1\x36\xef\xff\xb5\x8d\xf5\xf2\xfd\xbf\xbc\xa7\x6f\x76\xff\x7f\xb2"
      "\x67\xdb\x8b\xf9\x77\x23\x7d\xb5\x88\xfa\xfc\xed\x99\xbe\xe3\x11\xf5\xb9"
      "\x37\xde\x3c\xd5\xbe\xdd\xba\x35\x71\x6b\x62\xea\xfc\xe9\xd3\x5f\x1a\x1c"
      "\xfc\xd2\xb9\xd3\x7d\x87\x23\xea\x37\xdb\x93\x13\x3d\xaf\x76\xe5\x74\x01"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3c\x3c\xa9\x88\xdf\x8f"
      "\x14\xad\x1f\xad\xa4\x46\x44\xdc\xad\xe6\x6b\x0d\x5c\x1c\x7c\xf6\xd4\x33"
      "\x87\xe2\x50\x35\xdf\x6a\xdd\xbc\xed\xd7\x46\xae\x5d\x6a\xbc\x3c\x7d\x7b"
      "\x66\x76\x62\x6e\x6e\x62\xbc\x31\x3a\xd5\xbe\x31\x3d\x3e\xb1\xdd\xc3\xd5"
      "\xab\xe9\x5e\xa3\x43\xc3\x7b\xd2\x99\x0f\x75\x64\x8f\xdb\x7f\xa4\xfe\xf2"
      "\xf4\xcc\x1b\xb3\xed\x5b\x7f\x3c\xbf\xe9\xe7\x47\xeb\x97\xae\xcf\xcd\xcf"
      "\xb6\x6e\x6c\xfe\x71\x1c\x89\x22\xa2\xd9\xbb\xe5\x64\xd5\xe0\xd1\xa1\xe1"
      "\xaa\xd1\x93\xed\xd6\x54\x55\xf5\xea\xa6\x93\xe9\x7f\x79\x7d\xa9\x88\xff"
      "\x8a\x14\x37\xce\x37\xd2\x67\xf3\xb6\x3c\xff\x7f\xe3\x0c\xff\x75\xf3\xff"
      "\x17\x36\xee\x68\x8f\xe6\xff\x7f\xac\x67\x5b\x79\xcc\x94\x8a\xf8\x59\xa4"
      "\xf8\x9d\xbf\x7a\x3a\x3e\x5b\xb5\xf3\x68\xdc\x77\xce\x72\xb9\xbf\x8b\x14"
      "\x27\x2f\x7c\x26\x97\x8b\xc3\x65\xb9\x6e\x1b\x3a\xcf\x15\xe8\xcc\x0c\x2c"
      "\xcb\xfe\x5f\xa4\xf8\xa7\x9f\xaf\x2f\xdb\x9d\x0f\xf9\xe4\x5a\xd9\x33\xdb"
      "\x3e\xb1\x07\x44\x39\xfe\xc7\x22\xc5\xf7\xfe\xe2\x3b\xf1\x5b\x79\xdb\xfa"
      "\xe7\x3f\x6c\x3e\xfe\x47\x37\xee\x68\x8f\xc6\xff\xa9\x9e\x6d\x47\xd7\x3d"
      "\xaf\x60\xc7\x5d\x27\x8f\xff\xa9\x48\xf1\xd2\x93\x6f\xc7\xe7\xf2\xb6\x0f"
      "\x7a\xfe\x47\xf7\xd9\x1b\x27\x72\xe1\x7b\xcf\xe7\xd8\xa3\xf1\xff\x44\xcf"
      "\xb6\x81\x7c\xdc\xdf\xde\x9d\xae\x03\x00\x00\x00\x00\x00\x00\x00\x00\x1c"
      "\x68\x7d\xa9\x88\xbf\x8f\x14\x3f\x18\xae\xa5\x17\xf2\xb6\xed\xfc\xfd\xbf"
      "\xf1\x8d\x3b\xda\xa3\xbf\xff\xf5\xc9\x9e\x6d\xe3\xbb\xb3\x5e\xd1\x87\xbe"
      "\xd8\xf1\x49\x05\x00\x00\x00\x80\x7d\xa2\x2f\x15\xf1\xe3\x48\x71\x6b\xfe"
      "\xed\x7b\x73\xa8\xd7\xcf\xff\xee\x99\xff\xf9\x7b\x6b\xf3\x3f\x87\xd2\x86"
      "\x4f\xab\x3f\xe7\xfb\xb5\xea\xb9\x01\xbb\xf9\xe7\x7f\xbd\x06\xf2\x71\xc7"
      "\x76\xde\x6d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\xd8\x57\x52\x2a\xe2\x85\xbc\x9e\xfa\x58\x35\x9f\x7f\x7c\xcb\xf5\xd4\x97"
      "\x22\xc5\x2b\xff\xf3\x5c\x2e\x97\x8e\x97\xe5\xba\xeb\xc0\x0f\x54\xbf\xd6"
      "\xaf\x4c\x4f\x9d\xba\x34\x39\x39\x7d\xa3\x35\xdf\xba\x3e\x39\xd1\x18\x99"
      "\x69\xdd\x98\x28\xeb\x3e\x15\x29\x56\xfe\xf6\x33\xb9\x6e\x51\xad\xaf\xde"
      "\x5d\x6f\xbe\xb3\xc6\xfb\xda\x5a\xec\xb3\x91\x62\xf8\x1f\xba\x65\x3b\x6b"
      "\xb1\x77\xd7\x26\x7f\x6a\xad\xec\x99\xb2\xec\xc7\x22\xc5\x7f\xff\xe3\xfa"
      "\xb2\x9f\xcb\xe5\x3e\xb1\x56\xf6\x6c\x59\xf6\x6f\x22\xc5\xd7\xfe\xe5\xfe"
      "\xb2\xa5\xe3\x6b\x65\xcf\x95\x65\xbf\x13\x29\x7e\xf8\xb5\x46\xb7\xec\xd1"
      "\xb2\x6c\xf7\xf9\xa8\x9f\x5c\x2b\xfb\xfc\x8d\xe9\x62\x8f\x46\x06\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xc7\x49\x5f\x2a\xe2"
      "\xcf\x23\xc5\xff\xde\x5e\xbc\x37\x97\x3f\xaf\xff\xdf\xd7\xf3\xb6\xf2\xd6"
      "\x37\x7a\xd6\xfb\xdf\xe0\x6e\xb5\xce\xff\x40\xb5\xfe\xff\x56\xaf\x1f\x64"
      "\xfd\xff\xea\xb9\x02\x0b\x5b\x1d\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x3e\x9a\x52\x14\xf1\x66\xa4\x98\xb9\xb2"
      "\x92\x96\xfa\xcb\xf7\x1d\xf5\xcb\xed\xa9\x3b\x77\x47\x87\x86\x37\xaf\x76"
      "\x24\x55\x35\x0f\x55\xe5\xcb\x9f\xfa\x99\xb3\xe7\xce\x7f\xf1\x85\xc1\x0b"
      "\xdd\xfc\xe0\xfa\xbb\xed\x53\xf1\xda\xc8\xb5\x4b\x8d\x97\xa7\x6f\xcf\xcc"
      "\x4e\xcc\xcd\x4d\x8c\x37\x46\xa7\xda\x37\xa6\xc7\x27\xb6\xbd\x87\x9d\xd6"
      "\xdf\xe8\x64\x75\x02\x1a\xb7\x5f\xbf\x33\x7e\xf3\xe6\x5c\xe3\xec\xf3\xe7"
      "\xd6\x7d\x7c\x77\xe0\xfd\xfe\x27\x8e\x0f\x5c\x1c\x7c\xf6\xd4\x33\xdd\xb2"
      "\xa3\x43\xc3\xc3\x23\x3d\x65\x6a\x7d\x0f\x7c\xf4\xfb\xa4\x2d\xb6\x1f\x8e"
      "\x22\xfe\x3a\x52\x3c\xf7\xdd\x9f\xa4\x1f\xf4\x47\x14\xb1\xf3\x73\xf1\x21"
      "\xdf\x9d\xbd\x76\xa4\xea\xc4\xc9\xaa\x13\xa3\x43\xc3\x55\x47\x26\xdb\xad"
      "\xa9\xf9\xf2\xc3\xab\xdd\x13\x51\x44\x34\x7a\x2a\x35\xbb\xe7\xe8\x21\x8c"
      "\xc5\x8e\x34\x23\x16\xca\xe6\x97\x0d\x3e\x59\x76\x6f\x64\xa6\x35\xdb\xba"
      "\x3e\x39\xd1\xb8\xda\x9a\x9d\x6f\xcf\xb7\xa7\xa7\xae\xa6\x4e\x6b\xcb\xfe"
      "\x34\xa2\x88\x0b\x29\x62\x31\x22\x96\xfb\xef\xdf\x5d\x5f\x14\xf1\x7a\xa4"
      "\xf8\xf6\xb1\x95\xf4\xaf\xfd\x11\x87\xba\xe7\xe1\x0b\x57\x46\xbe\x72\xfa"
      "\xec\xd6\xed\x28\xf6\xb0\x8f\xdb\x50\xb6\xb3\xd1\x17\xb1\x58\x1c\x80\x31"
      "\xdb\xc7\xfa\xa3\x88\x7f\x8e\x14\x3f\x7d\xe7\x44\xfc\x5b\x7f\x44\x2d\x3a"
      "\x3f\xf1\xf9\x88\x57\xcb\xfc\x7e\xc4\x5b\xd1\x19\xef\x54\x7e\x31\xce\x47"
      "\xbc\xb7\xc9\xf7\x88\x83\xa9\x16\x45\xfc\x7f\x39\xfe\x17\x57\xd2\x3b\xfd"
      "\xe5\xf5\xa0\x7b\x5d\xb9\xfc\xd5\xc6\x97\xa7\x6e\x4e\xf7\x94\xed\x5e\x57"
      "\x0e\xfc\xfd\xe1\x61\xda\xe7\xd7\xa6\x7a\x14\xf1\xc3\xea\x8a\xbf\x92\xfe"
      "\xdd\x7f\xd7\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfb\x48"
      "\x11\xbf\x1e\x29\x5e\x7c\xf7\x44\xaa\xe6\x07\xdf\x9b\x53\xdc\x9e\xba\xd5"
      "\xb8\xd6\xba\x3e\xd9\x99\xd6\xd7\x9d\xfb\xd7\x9d\x33\xbd\xba\xba\xba\xda"
      "\x48\x9d\x6c\xe6\x1c\xcb\xb9\x90\x73\x31\xe7\x52\xce\xe5\x9c\x51\xe4\xfa"
      "\x39\x9b\x65\xd6\x57\x57\xc7\xf2\xfb\x85\x9c\x8b\x39\x97\x72\x2e\xe7\x8c"
      "\x43\xb9\x7e\xce\x66\xce\xb1\x9c\x0b\x39\x17\x73\x2e\xe5\x5c\xce\x19\xb5"
      "\x5c\x3f\x67\x33\xe7\x58\xce\x85\x9c\x8b\x39\x97\x72\x2e\xe7\x8c\x7d\x32"
      "\x77\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x68"
      "\x29\xaa\x7f\x52\x7c\xeb\xeb\x2b\x69\xb5\xbf\xb3\xbe\xf4\x58\x74\x72\xc9"
      "\x7a\xa0\x1f\x79\xbf\x08\x00\x00\xff\xff\x5a\x93\xf4\x76",
      3128);
  syz_mount_image(/*fs=*/0x20000080, /*dir=*/0x20000180,
                  /*flags=MS_REC*/ 0x4000, /*opts=*/0x20000740, /*chdir=*/0x12,
                  /*size=*/0xc38, /*img=*/0x20001080);
  *(uint64_t*)0x20000100 = -1;
  *(uint64_t*)0x20000108 = -1;
  syscall(__NR_setrlimit, /*res=RLIMIT_FSIZE*/ 1ul, /*rlim=*/0x20000100ul);
  memcpy((void*)0x20000040, "./file1\000", 8);
  res = syscall(__NR_open, /*file=*/0x20000040ul,
                /*flags=O_RDWR|0x100000*/ 0x100002ul, /*mode=*/0ul);
  if (res != -1)
    r[0] = res;
  memset((void*)0x20000140, 157, 1);
  syscall(__NR_pwrite64, /*fd=*/r[0], /*buf=*/0x20000140ul, /*count=*/1ul,
          /*pos=*/0x10000000005ul);
  memcpy((void*)0x20000640, "/dev/loop#\000", 11);
  res = -1;
  res = syz_open_dev(/*dev=*/0x20000640, /*id=*/0,
                     /*flags=O_NOFOLLOW|FASYNC|O_APPEND*/ 0x22400);
  if (res != -1)
    r[1] = res;
  *(uint32_t*)0x200000c0 = 0;
  *(uint16_t*)0x200000c8 = 0;
  *(uint64_t*)0x200000d0 = 0;
  *(uint16_t*)0x200000d8 = 0;
  *(uint32_t*)0x200000e0 = 3;
  *(uint32_t*)0x200000e4 = 5;
  *(uint32_t*)0x200000e8 = 0x100a;
  *(uint32_t*)0x200000ec = 8;
  memcpy((void*)0x200000f0,
         "\x9e\x95\x9f\x16\xb6\x78\x7b\x08\xaa\x26\xe6\x6c\x40\x56\xa5\x16\x95"
         "\x28\x48\x54\xc3\x82\xec\x6b\xcf\xee\xf4\xfb\x0e\xfc\xc1\xd8\xa6\x07"
         "\x8e\xd9\x8e\x20\x3f\xd5\xf0\x64\x39\x02\xdd\x8f\x6f\xac\x27\x4d\xe9"
         "\xd9\x40\xbb\xa5\xe5\x1e\x92\xbb\xd4\xce\x85\x45\x0d",
         64);
  memcpy((void*)0x20000130,
         "\xf6\x25\x71\x70\x00\x00\x36\xc8\x00\xde\xf9\x60\x06\xe0\x8d\x34\x00"
         "\x00\x00\x00\x6f\x1c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         32);
  *(uint64_t*)0x20000150 = 4;
  *(uint64_t*)0x20000158 = 7;
  *(uint32_t*)0x20000160 = 0;
  syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x4c02, /*arg=*/0x200000c0ul);
}
int main(void)
{
  syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul,
          /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  const char* reason;
  (void)reason;
  do_sandbox_none();
  return 0;
}