// https://syzkaller.appspot.com/bug?id=73a4263f057243fb32c83d1f55ba7d69a58286f6
// 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

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[1] = {0xffffffffffffffff};

void execute_one(void)
{
  intptr_t res = 0;
  memcpy((void*)0x200001c0, "/dev/loop#\000", 11);
  res = -1;
  res = syz_open_dev(/*dev=*/0x200001c0, /*id=*/0, /*flags=*/0);
  if (res != -1)
    r[0] = res;
  syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x4c09, /*arg=*/0x800ul);
  memcpy((void*)0x200000c0, "hfsplus\000", 8);
  memcpy((void*)0x20000840,
         "\023\023w\305\3745\324\024T\325\324\035)\255\032`)"
         "Y\201F\346\276\026nA\255\r\275@T\003<\2373\273\332\202$"
         "\242\363\327r\347cnH\263<\277p\203r\350\361\271\223>"
         "\305\022wC\276\"\006 \236\360-\371\313\362\366\350\200\3238/\000",
         78);
  memcpy((void*)0x20000100, "part", 4);
  *(uint8_t*)0x20000104 = 0x3d;
  sprintf((char*)0x20000105, "0x%016llx", (long long)4);
  *(uint8_t*)0x20000117 = 0x2c;
  memcpy((void*)0x20000118, "umask", 5);
  *(uint8_t*)0x2000011d = 0x3d;
  sprintf((char*)0x2000011e, "%023llo", (long long)0xbf6);
  *(uint8_t*)0x20000135 = 0x2c;
  memcpy((void*)0x20000136, "nls", 3);
  *(uint8_t*)0x20000139 = 0x3d;
  memcpy((void*)0x2000013a, "cp737", 5);
  *(uint8_t*)0x2000013f = 0x2c;
  memcpy((void*)0x20000140, "umask", 5);
  *(uint8_t*)0x20000145 = 0x3d;
  sprintf((char*)0x20000146, "%023llo", (long long)0xad9b);
  *(uint8_t*)0x2000015d = 0x2c;
  *(uint8_t*)0x2000015e = 0;
  memcpy(
      (void*)0x200009c0,
      "\x78\x9c\xec\xdd\x4f\x6c\x1c\x57\x1d\x07\xf0\xef\x6c\x36\x6b\x6f\x90\x52"
      "\xb7\x4d\xd3\x80\x90\x62\x35\x52\x05\x8d\x48\xec\xac\x4a\x82\x84\xd4\x80"
      "\x10\xca\x21\x42\x11\x5c\x7a\xb5\x12\xa7\xb1\xb2\x49\x2b\xc7\x45\x69\x85"
      "\xc8\x06\x28\x48\x9c\x38\xa1\x1e\x38\x14\xa1\x70\xe8\x09\x21\x84\x54\x4e"
      "\x88\x72\x46\x42\xe2\xc2\x29\xf7\x48\xdc\x38\xe4\x00\x18\xcd\xec\xec\x7a"
      "\x6d\x6f\x1c\x3b\x7f\xbc\x6e\xfb\xf9\x48\xb3\xf3\x66\xdf\xbc\xf7\x7e\xf3"
      "\xcb\xfc\xd9\x99\x8d\xb5\x01\x3e\xb3\xce\xbd\x9e\xfd\xbd\x14\x39\x77\xfc"
      "\xfc\xcd\x72\xf9\xee\x9d\x4e\xf7\xee\x9d\xce\xb5\x41\x39\xc9\x54\x92\x46"
      "\xd2\xec\xcf\x52\xb4\x93\xe2\xe3\xe4\x6c\xfa\x53\x3e\x5f\xbe\x59\x77\x57"
      "\x3c\x68\x9c\x57\xef\x7d\x54\x34\xdf\xff\xb0\xd3\x5f\x6a\xd6\x53\xb5\x7e"
      "\x63\xab\x76\x9b\x8c\x5d\xb3\x97\x4c\x0f\x17\xf6\x25\x99\xed\x17\xff\xb3"
      "\xed\x6e\x37\xf5\x57\x4d\x55\x3f\x17\xd7\xfa\x7b\x44\xc5\x30\xee\x32\x61"
      "\xc7\x06\x89\x83\x49\x5b\xdd\xa4\xb7\x56\xd9\x78\x68\xf3\xed\x1f\xb7\xc0"
      "\x9e\x75\xab\x7f\xdd\xdc\x64\x26\x39\x90\xfe\xd5\xb5\xfc\x1c\x90\xfa\xec"
      "\xf0\xf0\x33\xc3\xe4\x6d\x79\x6e\xea\xed\x5e\x1c\x00\x00\x00\xf0\xb4\xac"
      "\xbb\x97\x2f\xc6\xdc\xec\x3e\x73\x3f\xf7\x73\x33\x07\x77\x31\x26\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\xf8\xc4\x2b\xfa\xbf\x19\x58\xd4\x53\x63\x50"
      "\x9e\x4d\x31\xf8\xfd\xff\xd6\xc8\x6f\xea\xb7\x26\x1c\xee\x63\x7a\xef\x72"
      "\x35\xfb\xee\x33\x93\x0e\x04\x00\x00\x00\x00\x00\x00\x00\x1e\xcb\xd1\xfb"
      "\xb9\x9f\x9b\x39\x38\x58\x5e\x2d\xaa\xef\xfc\x5f\xaa\x16\x0e\x55\xaf\x9f"
      "\xcb\xdb\xb9\x91\xc5\x2c\xe7\x44\x6e\x66\x21\x2b\x59\xc9\x72\xe6\x93\xcc"
      "\x8c\x74\xd4\xba\xb9\xb0\xb2\xb2\x3c\xbf\xb9\xe5\x2f\x53\xb6\x5c\x5d\x5d"
      "\xbd\x55\xb7\x3c\x35\xb6\xe5\xa9\xf5\x71\xf5\x36\x06\x3a\xee\x7f\x1a\x6c"
      "\x5a\x09\x00\x00\x00\x00\x00\x00\x00\x3e\xb3\x7e\x94\x73\x6b\xdf\xff\x03"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\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\x5e\x50\x24\xfb\xfa\xb3\x6a"
      "\x3a\x34\x28\xcf\xa4\xd1\x4c\x32\x9d\xa4\x55\xcc\x0e\x57\x6f\x4d\x34\xd8"
      "\x27\xe0\xcf\x93\x0e\x00\x00\x00\x00\x9e\xbe\x76\x3d\x3f\x58\xfc\xaf\x5f"
      "\x58\x2d\xaa\x7b\xfe\xc3\xd5\x7d\xff\x74\xde\xce\xf5\xac\x64\x29\x2b\xe9"
      "\x66\x31\x97\xaa\x67\x01\xfd\xbb\xfe\xc6\xdf\x7b\x9d\xee\xdd\x3b\x9d\x6b"
      "\xe5\xb4\xb9\xe3\x6f\xfc\x6b\x47\x71\x54\x3d\xa6\xff\xec\x61\xfc\xc8\x73"
      "\xd5\x1a\x2f\x0c\x5b\x9c\xcb\xb7\xf3\xbd\x1c\xcf\x6c\x2e\x64\x39\x4b\xf9"
      "\x7e\x16\xb2\x92\xc5\xcc\xe6\x5b\x55\x69\x21\x45\x66\xea\xa7\x17\x33\x77"
      "\xef\xb4\x33\x88\x75\x73\xbc\x67\xd7\x2d\x5d\x18\x29\x4f\x97\x2f\x47\x47"
      "\xde\x28\xe3\x3b\x52\x45\xd2\xce\xe5\x2c\x55\xb1\x9d\xc8\xc5\xd6\x20\xf4"
      "\x46\xbd\xde\x91\x91\xd1\xfe\xd8\x4a\x36\x8c\x78\xbb\xcc\x4e\xf1\x5a\x6d"
      "\x9b\x39\xba\x54\xcf\xcb\x2d\xfa\x45\x3d\xdf\x1b\x66\xaa\x2d\xdf\x3f\xcc"
      "\xc8\x5c\x9d\xfb\x32\x1b\xcf\x8e\xe6\x7d\x73\xee\x77\xb8\x9f\x6c\x1c\x69"
      "\x3e\x8d\xe1\x33\xa8\x43\x6b\xa3\x94\x8b\x1b\x47\x7a\xa4\x9c\x1f\xa8\xe7"
      "\x65\xae\x7f\xfa\x74\x73\xbe\xc3\x47\x69\xeb\x33\xd1\xfb\x79\xb9\x34\xd8"
      "\xfb\x0e\x6f\x9d\xf3\xe4\xcb\xff\xf8\xcb\x85\x2b\x8d\xeb\x57\xaf\x5c\xbe"
      "\x71\x7c\xef\xec\x46\x8f\x68\xe3\x3e\xd1\x19\xc9\xc4\x8b\xdb\xca\x44\xb7"
      "\xcc\x44\xef\x31\x32\x31\xfd\x38\xf1\x3f\x39\xad\x3a\x1b\xfd\xb3\xe8\xce"
      "\xce\x96\x2f\x55\x6d\x0f\x66\x29\xdf\xc9\x9b\xb9\x94\xc5\x9c\xce\x5c\xe6"
      "\x73\x26\x73\xf9\x5a\x4e\xa5\x93\x53\x23\x79\x7d\x61\xeb\xbc\x56\xc7\x5a"
      "\x63\x67\xc7\xda\xb1\x2f\xd5\x85\xf2\x9a\xf4\xb3\x91\x6b\xd3\xae\x99\x7a"
      "\x50\x45\x99\xd7\x67\x47\xf2\x3a\x7a\xa6\x9b\xa9\xea\x46\xdf\x59\xcb\xd2"
      "\x73\xdb\xc8\x52\xd1\xca\xf8\x2c\xfd\x73\x6c\x28\xcd\x2f\xd4\x85\x72\x8c"
      "\x1f\x8f\x5c\x71\x26\x6f\x63\x26\xe6\x47\x32\xf1\xfc\xd6\x99\xf8\xf5\x7f"
      "\x57\x93\xdc\xe8\x5e\xbf\xba\x7c\x65\xe1\xad\x6d\x8e\xf7\x72\x3d\x2f\x0f"
      "\xdb\xf7\xd6\x9f\x9b\x7f\xf3\x44\x36\x68\xe7\xea\xcd\x2d\xf7\x97\xe7\xca"
      "\x7f\xac\xf4\x2f\x1b\xa3\x7b\x47\x59\xf7\xfc\xa0\x6e\x43\xbe\x5a\xf5\x37"
      "\x2e\xcd\xba\xb3\x75\x75\xad\x54\xc7\x73\xbf\xee\x61\x47\x6a\xd9\xd3\xe1"
      "\xdb\xe3\x7a\xea\xd7\xbd\x38\x76\x94\x4e\x55\x77\x64\xa4\x6e\xdd\xa7\x9c"
      "\xbc\x99\xee\xf0\x53\x08\x00\x7b\xd8\x81\x57\x0e\xb4\xda\xf7\xda\x7f\x6b"
      "\x7f\xd0\xfe\x49\xfb\x4a\xfb\xfc\xf4\x37\xa7\xce\x4c\x7d\xb1\x95\xfd\x7f"
      "\x6d\xfe\x69\xdf\xef\x1a\xbf\x6d\x7c\xbd\x78\x25\x1f\xe4\x87\x39\x38\xe9"
      "\x48\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\xe0\xd3\xe0\xc6\x3b\xef\x5e\x5d\xe8\x76\x17\x97"
      "\xf7\x60\x21\x8d\x27\xdc\xe1\xed\xb1\x55\x83\x54\xf4\xdf\x69\x3d\xf1\xcd"
      "\x39\xba\x27\x92\xb9\x4b\x85\xa9\xad\xf6\xa8\xdf\x27\xd9\xa2\x79\x6b\x12"
      "\x31\xb7\x93\xec\x89\xd4\xa5\xb9\x0b\x63\x4d\x65\x4c\xd5\xf9\xe1\x3b\xed"
      "\xa4\x31\x8c\x27\xc9\xd5\x3d\xf2\x03\x77\xc0\xd3\x70\x72\xe5\xda\x5b\x27"
      "\x6f\xbc\xf3\xee\x57\x96\xae\x2d\xbc\xb1\xf8\xc6\xe2\xf5\x53\x67\x4e\xbf"
      "\x76\xba\xf3\xd5\xf9\x5b\x27\x2f\x2f\x75\x17\xe7\xfa\xaf\x93\x8e\x12\x78"
      "\x1a\xd6\x3e\x06\x4c\x3a\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x60\xbb"
      "\x76\xe3\xcf\x1b\xc6\x0c\x5b\xf4\x26\xb0\xad\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\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\x27\xd3\xb9"
      "\xd7\xb3\xbf\x97\x22\xf3\x73\x27\xe6\xca\xe5\xbb\x77\x3a\xdd\x72\x1a\x94"
      "\xd7\xd6\x6c\x26\x69\x24\x29\x7e\x90\x14\x1f\x27\x67\xd3\x9f\x32\x33\xd2"
      "\x5d\xf1\xa0\x71\x5e\xbd\xf7\xd1\xaf\x5e\x7e\xff\xc3\xce\x5a\x5f\xcd\xc1"
      "\xfa\x8d\x0d\xed\xfe\xf0\xef\xd5\xd5\x1d\x6e\x45\xaf\x9e\x32\x9b\x64\x5f"
      "\x3d\x7f\xb8\xa9\x6d\xf5\x77\x71\xa4\xbf\xde\x0e\x03\xeb\x2b\x86\x5b\x58"
      "\x26\xec\xd8\x20\x71\x30\x69\xff\x0f\x00\x00\xff\xff\xc2\x59\x08\x15",
      1709);
  syz_mount_image(/*fs=*/0x200000c0, /*dir=*/0x20000840,
                  /*flags=MS_POSIXACL|MS_STRICTATIME|MS_NODEV*/ 0x1010004,
                  /*opts=*/0x20000100, /*chdir=*/6, /*size=*/0x6ad,
                  /*img=*/0x200009c0);
}
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;
}