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

#define _GNU_SOURCE

#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.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/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

#include <linux/loop.h>

#ifndef __NR_ioctl
#define __NR_ioctl 29
#endif
#ifndef __NR_memfd_create
#define __NR_memfd_create 279
#endif
#ifndef __NR_mmap
#define __NR_mmap 222
#endif
#ifndef __NR_openat
#define __NR_openat 56
#endif
#ifndef __NR_write
#define __NR_write 64
#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;
}

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 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 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();
      exit(0);
    }
    int status = 0;
    uint64_t start = current_time_ms();
    for (;;) {
      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
        break;
      sleep_ms(1);
      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;
  memcpy((void*)0x200000c0, "/dev/input/event#\000", 18);
  res = -1;
  res = syz_open_dev(/*dev=*/0x200000c0, /*id=*/0x40, /*flags=*/0);
  if (res != -1)
    r[0] = res;
  *(uint16_t*)0x20000300 = 0x50;
  *(uint16_t*)0x20000302 = -1;
  *(uint16_t*)0x20000304 = 6;
  *(uint16_t*)0x20000306 = 0;
  *(uint16_t*)0x20000308 = 0;
  *(uint16_t*)0x2000030a = 0;
  *(uint16_t*)0x2000030c = 0;
  *(uint16_t*)0x20000310 = 0;
  *(uint16_t*)0x20000312 = 0;
  *(uint16_t*)0x20000314 = 0;
  *(uint16_t*)0x20000316 = 0;
  *(uint16_t*)0x20000318 = 0;
  *(uint16_t*)0x2000031a = 0;
  *(uint16_t*)0x2000031c = 0;
  *(uint16_t*)0x2000031e = 0;
  *(uint16_t*)0x20000320 = 0;
  *(uint16_t*)0x20000322 = 0;
  *(uint16_t*)0x20000324 = 0;
  *(uint16_t*)0x20000326 = 0;
  syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x40304580, /*arg=*/0x20000300ul);
  memcpy((void*)0x20000040, "/dev/uinput\000", 12);
  res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x20000040ul,
                /*flags=O_RDWR_NONBLOCK*/ 0x802ul, /*mode=*/0ul);
  if (res != -1)
    r[1] = res;
  syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x4004556b, /*arg=*/0x51ul);
  memcpy((void*)0x20000800,
         "syz1\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000\000\000\000\000",
         80);
  *(uint16_t*)0x20000850 = 0;
  *(uint16_t*)0x20000852 = 0;
  *(uint16_t*)0x20000854 = 0;
  *(uint16_t*)0x20000856 = 0;
  *(uint32_t*)0x20000858 = 0x35;
  *(uint32_t*)0x2000085c = 0;
  *(uint32_t*)0x20000860 = 0;
  *(uint32_t*)0x20000864 = 0;
  *(uint32_t*)0x20000868 = 0;
  *(uint32_t*)0x2000086c = 0;
  *(uint32_t*)0x20000870 = 0;
  *(uint32_t*)0x20000874 = 0;
  *(uint32_t*)0x20000878 = 0;
  *(uint32_t*)0x2000087c = 0;
  *(uint32_t*)0x20000880 = 0;
  *(uint32_t*)0x20000884 = 0;
  *(uint32_t*)0x20000888 = 0;
  *(uint32_t*)0x2000088c = 0;
  *(uint32_t*)0x20000890 = 0;
  *(uint32_t*)0x20000894 = 0;
  *(uint32_t*)0x20000898 = 0;
  *(uint32_t*)0x2000089c = 0;
  *(uint32_t*)0x200008a0 = 0;
  *(uint32_t*)0x200008a4 = 0;
  *(uint32_t*)0x200008a8 = 0;
  *(uint32_t*)0x200008ac = 0;
  *(uint32_t*)0x200008b0 = 0;
  *(uint32_t*)0x200008b4 = 0;
  *(uint32_t*)0x200008b8 = 0;
  *(uint32_t*)0x200008bc = 0;
  *(uint32_t*)0x200008c0 = 0;
  *(uint32_t*)0x200008c4 = 0;
  *(uint32_t*)0x200008c8 = 0;
  *(uint32_t*)0x200008cc = 0;
  *(uint32_t*)0x200008d0 = 0;
  *(uint32_t*)0x200008d4 = 0;
  *(uint32_t*)0x200008d8 = 0;
  *(uint32_t*)0x200008dc = 0;
  *(uint32_t*)0x200008e0 = 1;
  *(uint32_t*)0x200008e4 = 0;
  *(uint32_t*)0x200008e8 = 0;
  *(uint32_t*)0x200008ec = 0;
  *(uint32_t*)0x200008f0 = 0;
  *(uint32_t*)0x200008f4 = 0;
  *(uint32_t*)0x200008f8 = 3;
  *(uint32_t*)0x200008fc = 0;
  *(uint32_t*)0x20000900 = 0;
  *(uint32_t*)0x20000904 = 0;
  *(uint32_t*)0x20000908 = 0;
  *(uint32_t*)0x2000090c = 0;
  *(uint32_t*)0x20000910 = 0;
  *(uint32_t*)0x20000914 = 0;
  *(uint32_t*)0x20000918 = 0;
  *(uint32_t*)0x2000091c = -1;
  *(uint32_t*)0x20000920 = 0;
  *(uint32_t*)0x20000924 = 0;
  *(uint32_t*)0x20000928 = 0;
  *(uint32_t*)0x2000092c = 0;
  *(uint32_t*)0x20000930 = 0;
  *(uint32_t*)0x20000934 = 0x6d37;
  *(uint32_t*)0x20000938 = 0;
  *(uint32_t*)0x2000093c = 0;
  *(uint32_t*)0x20000940 = 0;
  *(uint32_t*)0x20000944 = 0;
  *(uint32_t*)0x20000948 = 0;
  *(uint32_t*)0x2000094c = 0;
  *(uint32_t*)0x20000950 = 0;
  *(uint32_t*)0x20000954 = 0;
  *(uint32_t*)0x20000958 = 0;
  *(uint32_t*)0x2000095c = 0;
  *(uint32_t*)0x20000960 = 0;
  *(uint32_t*)0x20000964 = 0;
  *(uint32_t*)0x20000968 = 0;
  *(uint32_t*)0x2000096c = 0xfff;
  *(uint32_t*)0x20000970 = 0;
  *(uint32_t*)0x20000974 = 0;
  *(uint32_t*)0x20000978 = 0;
  *(uint32_t*)0x2000097c = 0;
  *(uint32_t*)0x20000980 = 0;
  *(uint32_t*)0x20000984 = 0;
  *(uint32_t*)0x20000988 = 0;
  *(uint32_t*)0x2000098c = 0;
  *(uint32_t*)0x20000990 = 0;
  *(uint32_t*)0x20000994 = 0;
  *(uint32_t*)0x20000998 = 0;
  *(uint32_t*)0x2000099c = 0;
  *(uint32_t*)0x200009a0 = 0;
  *(uint32_t*)0x200009a4 = 0;
  *(uint32_t*)0x200009a8 = 4;
  *(uint32_t*)0x200009ac = 0;
  *(uint32_t*)0x200009b0 = 0;
  *(uint32_t*)0x200009b4 = 0x800;
  *(uint32_t*)0x200009b8 = 0;
  *(uint32_t*)0x200009bc = -1;
  *(uint32_t*)0x200009c0 = 0;
  *(uint32_t*)0x200009c4 = 0;
  *(uint32_t*)0x200009c8 = 0;
  *(uint32_t*)0x200009cc = 0;
  *(uint32_t*)0x200009d0 = 0;
  *(uint32_t*)0x200009d4 = 0;
  *(uint32_t*)0x200009d8 = 0;
  *(uint32_t*)0x200009dc = 0;
  *(uint32_t*)0x200009e0 = 0;
  *(uint32_t*)0x200009e4 = 0;
  *(uint32_t*)0x200009e8 = 0;
  *(uint32_t*)0x200009ec = 0;
  *(uint32_t*)0x200009f0 = 0;
  *(uint32_t*)0x200009f4 = 0xfffffffe;
  *(uint32_t*)0x200009f8 = 0;
  *(uint32_t*)0x200009fc = 0;
  *(uint32_t*)0x20000a00 = 0;
  *(uint32_t*)0x20000a04 = 0;
  *(uint32_t*)0x20000a08 = 0;
  *(uint32_t*)0x20000a0c = 0;
  *(uint32_t*)0x20000a10 = 0;
  *(uint32_t*)0x20000a14 = 0;
  *(uint32_t*)0x20000a18 = 0;
  *(uint32_t*)0x20000a1c = 0;
  *(uint32_t*)0x20000a20 = 0;
  *(uint32_t*)0x20000a24 = 0;
  *(uint32_t*)0x20000a28 = 0;
  *(uint32_t*)0x20000a2c = 0;
  *(uint32_t*)0x20000a30 = 0;
  *(uint32_t*)0x20000a34 = 0;
  *(uint32_t*)0x20000a38 = 0;
  *(uint32_t*)0x20000a3c = 0;
  *(uint32_t*)0x20000a40 = 0;
  *(uint32_t*)0x20000a44 = 0;
  *(uint32_t*)0x20000a48 = 0;
  *(uint32_t*)0x20000a4c = 0;
  *(uint32_t*)0x20000a50 = 4;
  *(uint32_t*)0x20000a54 = 0;
  *(uint32_t*)0x20000a58 = 0;
  *(uint32_t*)0x20000a5c = 0;
  *(uint32_t*)0x20000a60 = 0;
  *(uint32_t*)0x20000a64 = 0;
  *(uint32_t*)0x20000a68 = 0;
  *(uint32_t*)0x20000a6c = 0;
  *(uint32_t*)0x20000a70 = 0;
  *(uint32_t*)0x20000a74 = 0;
  *(uint32_t*)0x20000a78 = 0;
  *(uint32_t*)0x20000a7c = 0;
  *(uint32_t*)0x20000a80 = 0;
  *(uint32_t*)0x20000a84 = 0;
  *(uint32_t*)0x20000a88 = 0;
  *(uint32_t*)0x20000a8c = 0x200000;
  *(uint32_t*)0x20000a90 = 0;
  *(uint32_t*)0x20000a94 = 0;
  *(uint32_t*)0x20000a98 = 0;
  *(uint32_t*)0x20000a9c = 0;
  *(uint32_t*)0x20000aa0 = 0;
  *(uint32_t*)0x20000aa4 = 7;
  *(uint32_t*)0x20000aa8 = 0;
  *(uint32_t*)0x20000aac = 0xfffffffd;
  *(uint32_t*)0x20000ab0 = 0;
  *(uint32_t*)0x20000ab4 = 0;
  *(uint32_t*)0x20000ab8 = 0;
  *(uint32_t*)0x20000abc = 0x20;
  *(uint32_t*)0x20000ac0 = 0;
  *(uint32_t*)0x20000ac4 = -1;
  *(uint32_t*)0x20000ac8 = 0;
  *(uint32_t*)0x20000acc = 0;
  *(uint32_t*)0x20000ad0 = 0x100;
  *(uint32_t*)0x20000ad4 = 0;
  *(uint32_t*)0x20000ad8 = 0;
  *(uint32_t*)0x20000adc = 0;
  *(uint32_t*)0x20000ae0 = 0;
  *(uint32_t*)0x20000ae4 = 0;
  *(uint32_t*)0x20000ae8 = 0;
  *(uint32_t*)0x20000aec = 0;
  *(uint32_t*)0x20000af0 = 0;
  *(uint32_t*)0x20000af4 = 0;
  *(uint32_t*)0x20000af8 = 0;
  *(uint32_t*)0x20000afc = 0xfffffffd;
  *(uint32_t*)0x20000b00 = 0;
  *(uint32_t*)0x20000b04 = 0;
  *(uint32_t*)0x20000b08 = 0x2000;
  *(uint32_t*)0x20000b0c = 0;
  *(uint32_t*)0x20000b10 = 0;
  *(uint32_t*)0x20000b14 = 0;
  *(uint32_t*)0x20000b18 = 0;
  *(uint32_t*)0x20000b1c = 0;
  *(uint32_t*)0x20000b20 = 0;
  *(uint32_t*)0x20000b24 = 0;
  *(uint32_t*)0x20000b28 = 0;
  *(uint32_t*)0x20000b2c = 0;
  *(uint32_t*)0x20000b30 = 0;
  *(uint32_t*)0x20000b34 = 1;
  *(uint32_t*)0x20000b38 = 0;
  *(uint32_t*)0x20000b3c = 0;
  *(uint32_t*)0x20000b40 = 0;
  *(uint32_t*)0x20000b44 = 0;
  *(uint32_t*)0x20000b48 = 0;
  *(uint32_t*)0x20000b4c = 0;
  *(uint32_t*)0x20000b50 = 0;
  *(uint32_t*)0x20000b54 = 0;
  *(uint32_t*)0x20000b58 = 0;
  *(uint32_t*)0x20000b5c = 0;
  *(uint32_t*)0x20000b60 = 0;
  *(uint32_t*)0x20000b64 = 0;
  *(uint32_t*)0x20000b68 = 0;
  *(uint32_t*)0x20000b6c = 0;
  *(uint32_t*)0x20000b70 = 0;
  *(uint32_t*)0x20000b74 = 0;
  *(uint32_t*)0x20000b78 = 0;
  *(uint32_t*)0x20000b7c = 0;
  *(uint32_t*)0x20000b80 = 0;
  *(uint32_t*)0x20000b84 = 0;
  *(uint32_t*)0x20000b88 = 0xfffffffe;
  *(uint32_t*)0x20000b8c = 0;
  *(uint32_t*)0x20000b90 = 0;
  *(uint32_t*)0x20000b94 = 5;
  *(uint32_t*)0x20000b98 = 7;
  *(uint32_t*)0x20000b9c = 0;
  *(uint32_t*)0x20000ba0 = 0;
  *(uint32_t*)0x20000ba4 = 0;
  *(uint32_t*)0x20000ba8 = 0;
  *(uint32_t*)0x20000bac = 7;
  *(uint32_t*)0x20000bb0 = 0;
  *(uint32_t*)0x20000bb4 = 0;
  *(uint32_t*)0x20000bb8 = 0;
  *(uint32_t*)0x20000bbc = 0;
  *(uint32_t*)0x20000bc0 = 0;
  *(uint32_t*)0x20000bc4 = 0;
  *(uint32_t*)0x20000bc8 = 0;
  *(uint32_t*)0x20000bcc = 0;
  *(uint32_t*)0x20000bd0 = 0;
  *(uint32_t*)0x20000bd4 = 0;
  *(uint32_t*)0x20000bd8 = 0xfffffffc;
  *(uint32_t*)0x20000bdc = 0;
  *(uint32_t*)0x20000be0 = 3;
  *(uint32_t*)0x20000be4 = 0;
  *(uint32_t*)0x20000be8 = 0;
  *(uint32_t*)0x20000bec = 0;
  *(uint32_t*)0x20000bf0 = 0;
  *(uint32_t*)0x20000bf4 = 0;
  *(uint32_t*)0x20000bf8 = 0;
  *(uint32_t*)0x20000bfc = 0;
  *(uint32_t*)0x20000c00 = 0;
  *(uint32_t*)0x20000c04 = 0;
  *(uint32_t*)0x20000c08 = 0;
  *(uint32_t*)0x20000c0c = 0;
  *(uint32_t*)0x20000c10 = 0;
  *(uint32_t*)0x20000c14 = 0;
  *(uint32_t*)0x20000c18 = 0;
  *(uint32_t*)0x20000c1c = 2;
  *(uint32_t*)0x20000c20 = 0;
  *(uint32_t*)0x20000c24 = 0;
  *(uint32_t*)0x20000c28 = 0;
  *(uint32_t*)0x20000c2c = 0;
  *(uint32_t*)0x20000c30 = 0;
  *(uint32_t*)0x20000c34 = 0;
  *(uint32_t*)0x20000c38 = 0;
  *(uint32_t*)0x20000c3c = 0;
  *(uint32_t*)0x20000c40 = 0;
  *(uint32_t*)0x20000c44 = 0;
  *(uint32_t*)0x20000c48 = 0;
  *(uint32_t*)0x20000c4c = 0;
  *(uint32_t*)0x20000c50 = 0;
  *(uint32_t*)0x20000c54 = 0;
  *(uint32_t*)0x20000c58 = 0;
  syscall(__NR_write, /*fd=*/r[1], /*data=*/0x20000800ul, /*len=*/0x45cul);
  syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x5501, 0);
  memcpy((void*)0x20000180, "ext4\000", 5);
  memcpy((void*)0x200000c0, "./file0\000", 8);
  *(uint8_t*)0x20000500 = 0;
  memcpy(
      (void*)0x200077c0,
      "\x78\x9c\xec\xdc\xcd\x6f\x14\xe5\x1f\x00\xf0\xef\x4c\x5b\xde\xa1\xfd\xf1"
      "\x43\x14\x04\xad\xa2\x91\xf8\xd2\xd2\x82\xca\xc1\x8b\x46\x13\x0f\x9a\x98"
      "\xe8\x01\x8f\xb5\x2d\x88\x2c\xd4\xd0\x9a\x08\x69\xb4\x1a\x83\x47\x43\xe2"
      "\xdd\x78\x34\xf1\x2f\xf0\xe6\xc5\xa8\x07\x63\xe2\x55\x13\x8f\x86\x84\x68"
      "\x63\x42\xf5\x54\x33\x6f\xb0\x5d\x76\x4b\x29\xdb\xae\x76\x3f\x9f\x64\xd9"
      "\xe7\x99\x79\x66\x9f\xe7\xbb\x33\xcf\xec\x33\xf3\x30\x0d\xa0\x6b\x0d\x66"
      "\xff\x24\x11\x3b\x22\xe2\xe7\x88\xe8\x2f\xb2\x4b\x0b\x0c\x16\x6f\x0b\xf3"
      "\xb3\xe3\x7f\xcd\xcf\x8e\x27\xb1\xb8\xf8\xea\xef\x49\x5e\xee\xda\xfc\xec"
      "\x78\x55\xb4\xda\x6e\x7b\x99\x39\x9c\x46\xa4\x1f\x25\x65\x25\x4b\x4d\x5f"
      "\xb8\x78\x66\xac\x56\x9b\x3c\x5f\xe6\x87\x67\xce\xbe\x3d\x3c\x7d\xe1\xe2"
      "\x13\xa7\xcf\x8e\x9d\x9a\x3c\x35\x79\x6e\xf4\xf8\xf1\x63\x47\x47\x9e\x7e"
      "\x6a\xf4\xc9\xb6\xc4\x99\xc5\x75\x6d\xff\x7b\x53\x07\xf6\xbd\xf8\xfa\xe5"
      "\x97\xc7\x4f\x5c\x7e\xe3\xbb\x2f\xb3\xf6\xee\x3d\x58\xac\xaf\x8f\xa3\x5d"
      "\x06\xb3\xc0\xff\x58\xcc\x35\xae\x7b\xb8\xdd\x95\x75\xd8\xce\xba\x74\xd2"
      "\xdb\xc1\x86\x70\x5b\x7a\x22\x22\xdb\x5d\x7d\x79\xff\xef\x8f\x9e\xb8\xb1"
      "\xf3\xfa\xe3\x85\x0f\x3b\xda\x38\x60\x4d\x65\xbf\x4d\x9b\x5b\xaf\x9e\x5b"
      "\x04\x36\xb0\x24\x3a\xdd\x02\xa0\x33\xaa\x1f\xfa\xec\xfa\xb7\x7a\xad\xd3"
      "\xd0\xe3\x5f\xe1\xea\xb3\x11\x9b\xca\xf4\xc2\xfc\xec\xf8\xc2\xf5\xf8\x7b"
      "\x23\x2d\x97\xf7\xad\x61\xfd\x83\x11\x71\x62\xee\xef\xcf\xb2\x57\xac\xd1"
      "\x7d\x08\x00\x80\x7a\xf9\xd8\xe6\xf1\x66\xe3\xbf\x34\xf6\xe6\xef\xc5\xac"
      "\xce\xae\x72\x0e\x65\x20\x22\xfe\x17\x11\xbb\x23\xe2\xff\x11\xb1\x27\x22"
      "\xee\x8a\xc8\xcb\xde\x1d\x11\xf7\x14\x1b\x2f\xf6\xaf\xb0\xfe\xc6\xa9\xa1"
      "\x9b\xc7\x3f\xe9\x95\xa6\x6d\x6e\x93\x6c\xfc\xf7\x4c\xdd\xd8\x6f\xa1\x2e"
      "\xfe\xf2\x6d\xa0\xa7\xcc\xed\xcc\xe3\xef\x4b\x4e\x9e\xae\x4d\x1e\x29\xbf"
      "\x93\xc3\xd1\xb7\x39\xcb\x8f\x2c\x53\xc7\xd7\xcf\xff\xf4\x49\xab\x75\xf5"
      "\xe3\xbf\xec\x95\xd5\x5f\x8d\x05\xcb\x06\x5c\xe9\x6d\xb8\x41\x37\x31\x36"
      "\x33\xd6\xae\x2f\xe1\xea\x07\x11\xfb\x7b\x9b\xc5\x9f\x5c\x9f\x09\xc8\x8e"
      "\x80\x7d\x11\xb1\xff\xf6\x3e\x7a\x57\x95\x38\xfd\xe8\x17\x07\x5a\x15\xba"
      "\x75\xfc\xcb\x68\xc3\x3c\xd3\xe2\xe7\x11\x8f\x14\xfb\x7f\x2e\x1a\xe2\xaf"
      "\x24\xcb\xcf\x4f\x0e\x6f\x89\xda\xe4\x91\xe1\xea\xa8\xb8\xd9\xf7\x3f\x5e"
      "\x7a\xa5\x55\xfd\x77\x14\x7f\x1b\x64\xfb\x7f\xdb\xd2\xe3\xbf\xa1\x44\xff"
      "\x9f\x49\x31\x5f\xdb\x17\xb5\xda\xe4\xf9\xe9\xdb\xaf\xe3\xd2\x2f\x1f\xb7"
      "\xbc\xa6\x59\xed\xf1\xbf\x29\x79\x2d\x9f\xb3\xfe\xe1\xcd\x62\xd9\xbb\x63"
      "\x33\x33\xe7\x47\x22\x36\x25\x2f\xe5\xf9\xea\x9a\x2e\x5f\x3e\x7a\x63\xdb"
      "\x2a\x5f\x95\xcf\xe2\x3f\x7c\xa8\x79\xff\xdf\x5d\x6e\x93\xc5\x7f\x6f\x44"
      "\x64\x07\xf1\xc1\x88\xb8\x2f\x22\xee\x2f\xdb\xfe\x40\x44\x3c\x18\x11\x87"
      "\x96\x89\xff\xdb\xe7\x1e\x7a\x6b\x99\xf8\x93\x48\xa2\xa3\xfb\x7f\xa2\xe9"
      "\xf9\xef\xfa\xf1\x3f\x90\xd4\xcf\xd7\xaf\x22\xd1\x73\xe6\x9b\xaf\x92\x16"
      "\xf5\xaf\x6c\xff\x1f\x8b\xb9\xfc\x5c\x5b\xc8\xcf\x7f\xb7\xb0\xd2\x06\xde"
      "\xe1\xd7\x07\x00\x00\x00\xff\x09\x69\x44\xec\x88\x24\x1d\x2a\xd2\x83\x3b"
      "\x22\x4d\x87\x86\x8a\xff\xc3\xbf\x27\xb6\xa5\xb5\xa9\xe9\x99\xc7\x4e\x4e"
      "\xbd\x73\x6e\xa2\x78\x46\x60\x20\xfa\xd2\xea\x4e\x57\x7f\xdd\xfd\xd0\x91"
      "\x64\xae\xfc\xc4\x22\x3f\x5a\xde\x2b\xae\xd6\x1f\x2d\xef\x1b\x7f\xda\xb3"
      "\x35\xcf\x0f\x8d\x4f\xd5\x26\x3a\x1c\x3b\x74\xbb\xed\x4b\xfb\x7f\x54\xfd"
      "\x3f\xf3\x5b\x4f\xa7\x5b\x07\xac\x39\xcf\x6b\x41\xf7\x6a\xec\xff\x69\x87"
      "\xda\x01\xac\xbf\x95\xfc\xfe\xbb\x16\x80\x8d\xa9\x49\xff\xdf\xda\x89\x76"
      "\x00\xeb\xcf\xf5\x3f\x74\xaf\x66\xfd\xff\xfd\x86\xbc\xf1\x3f\x6c\x4c\x37"
      "\xf7\xff\x5f\x9b\xfc\xc9\x3a\x60\x23\x32\xfe\x87\xee\xa5\xff\x43\xf7\xd2"
      "\xff\xa1\x2b\xdd\xc9\x73\xfd\xab\x4f\x54\x0f\x0b\xac\xfe\x73\xb6\xac\xf8"
      "\x09\x7f\x89\xf6\x25\xb6\xc6\x8d\x25\x91\x76\xbe\x3d\x12\x6b\x97\xe8\xf4"
      "\x99\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa0\x3d\xfe\x09\x00"
      "\x00\xff\xff\x68\x54\xea\x81",
      1141);
  syz_mount_image(
      /*fs=*/0x20000180, /*dir=*/0x200000c0,
      /*flags=MS_I_VERSION|MS_SYNCHRONOUS|MS_NODEV|MS_NOATIME|0x300*/ 0x800714,
      /*opts=*/0x20000500, /*chdir=*/-1, /*size=*/0x475, /*img=*/0x200077c0);
}
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);
  for (procid = 0; procid < 5; procid++) {
    if (fork() == 0) {
      loop();
    }
  }
  sleep(1000000);
  return 0;
}