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

#define _GNU_SOURCE

#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.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/futex.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 void use_temporary_dir(void)
{
  char tmpdir_template[] = "./syzkaller.XXXXXX";
  char* tmpdir = mkdtemp(tmpdir_template);
  if (!tmpdir)
    exit(1);
  if (chmod(tmpdir, 0777))
    exit(1);
  if (chdir(tmpdir))
    exit(1);
}

static void thread_start(void* (*fn)(void*), void* arg)
{
  pthread_t th;
  pthread_attr_t attr;
  pthread_attr_init(&attr);
  pthread_attr_setstacksize(&attr, 128 << 10);
  int i = 0;
  for (; i < 100; i++) {
    if (pthread_create(&th, &attr, fn, arg) == 0) {
      pthread_attr_destroy(&attr);
      return;
    }
    if (errno == EAGAIN) {
      usleep(50);
      continue;
    }
    break;
  }
  exit(1);
}

typedef struct {
  int state;
} event_t;

static void event_init(event_t* ev)
{
  ev->state = 0;
}

static void event_reset(event_t* ev)
{
  ev->state = 0;
}

static void event_set(event_t* ev)
{
  if (ev->state)
    exit(1);
  __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
  syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000);
}

static void event_wait(event_t* ev)
{
  while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
    syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
}

static int event_isset(event_t* ev)
{
  return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE);
}

static int event_timedwait(event_t* ev, uint64_t timeout)
{
  uint64_t start = current_time_ms();
  uint64_t now = start;
  for (;;) {
    uint64_t remain = timeout - (now - start);
    struct timespec ts;
    ts.tv_sec = remain / 1000;
    ts.tv_nsec = (remain % 1000) * 1000 * 1000;
    syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
    if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
      return 1;
    now = current_time_ms();
    if (now - start > timeout)
      return 0;
  }
}

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_procfs(volatile long a0, volatile long a1)
{
  char buf[128];
  memset(buf, 0, sizeof(buf));
  if (a0 == 0) {
    snprintf(buf, sizeof(buf), "/proc/self/%s", (char*)a1);
  } else if (a0 == -1) {
    snprintf(buf, sizeof(buf), "/proc/thread-self/%s", (char*)a1);
  } else {
    snprintf(buf, sizeof(buf), "/proc/self/task/%d/%s", (int)a0, (char*)a1);
  }
  int fd = open(buf, O_RDWR);
  if (fd == -1)
    fd = open(buf, O_RDONLY);
  return fd;
}

//% 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;
}

#define FS_IOC_SETFLAGS _IOW('f', 2, long)
static void remove_dir(const char* dir)
{
  int iter = 0;
  DIR* dp = 0;
  const int umount_flags = MNT_FORCE | UMOUNT_NOFOLLOW;

retry:
  while (umount2(dir, umount_flags) == 0) {
  }
  dp = opendir(dir);
  if (dp == NULL) {
    if (errno == EMFILE) {
      exit(1);
    }
    exit(1);
  }
  struct dirent* ep = 0;
  while ((ep = readdir(dp))) {
    if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
      continue;
    char filename[FILENAME_MAX];
    snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
    while (umount2(filename, umount_flags) == 0) {
    }
    struct stat st;
    if (lstat(filename, &st))
      exit(1);
    if (S_ISDIR(st.st_mode)) {
      remove_dir(filename);
      continue;
    }
    int i;
    for (i = 0;; i++) {
      if (unlink(filename) == 0)
        break;
      if (errno == EPERM) {
        int fd = open(filename, O_RDONLY);
        if (fd != -1) {
          long flags = 0;
          if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
          }
          close(fd);
          continue;
        }
      }
      if (errno == EROFS) {
        break;
      }
      if (errno != EBUSY || i > 100)
        exit(1);
      if (umount2(filename, umount_flags))
        exit(1);
    }
  }
  closedir(dp);
  for (int i = 0;; i++) {
    if (rmdir(dir) == 0)
      break;
    if (i < 100) {
      if (errno == EPERM) {
        int fd = open(dir, O_RDONLY);
        if (fd != -1) {
          long flags = 0;
          if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
          }
          close(fd);
          continue;
        }
      }
      if (errno == EROFS) {
        break;
      }
      if (errno == EBUSY) {
        if (umount2(dir, umount_flags))
          exit(1);
        continue;
      }
      if (errno == ENOTEMPTY) {
        if (iter < 100) {
          iter++;
          goto retry;
        }
      }
    }
    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");
  if (symlink("/dev/binderfs", "./binderfs")) {
  }
}

struct thread_t {
  int created, call;
  event_t ready, done;
};

static struct thread_t threads[16];
static void execute_call(int call);
static int running;

static void* thr(void* arg)
{
  struct thread_t* th = (struct thread_t*)arg;
  for (;;) {
    event_wait(&th->ready);
    event_reset(&th->ready);
    execute_call(th->call);
    __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
    event_set(&th->done);
  }
  return 0;
}

static void execute_one(void)
{
  if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
  }
  int i, call, thread;
  for (call = 0; call < 6; call++) {
    for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
         thread++) {
      struct thread_t* th = &threads[thread];
      if (!th->created) {
        th->created = 1;
        event_init(&th->ready);
        event_init(&th->done);
        event_set(&th->done);
        thread_start(thr, th);
      }
      if (!event_isset(&th->done))
        continue;
      event_reset(&th->done);
      th->call = call;
      __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
      event_set(&th->ready);
      event_timedwait(&th->done,
                      50 + (call == 0 ? 4000 : 0) + (call == 5 ? 4000 : 0));
      break;
    }
  }
  for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
    sleep_ms(1);
}

static void execute_one(void);

#define WAIT_FLAGS __WALL

static void loop(void)
{
  int iter = 0;
  for (;; iter++) {
    char cwdbuf[32];
    sprintf(cwdbuf, "./%d", iter);
    if (mkdir(cwdbuf, 0777))
      exit(1);
    reset_loop();
    int pid = fork();
    if (pid < 0)
      exit(1);
    if (pid == 0) {
      if (chdir(cwdbuf))
        exit(1);
      setup_test();
      execute_one();
      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;
    }
    remove_dir(cwdbuf);
  }
}

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

void execute_call(int call)
{
  intptr_t res = 0;
  switch (call) {
  case 0:
    memcpy((void*)0x400000000780, "ext4\000", 5);
    memcpy((void*)0x400000000240, "./file2\000", 8);
    *(uint8_t*)0x4000000000c0 = 0;
    memcpy(
        (void*)0x400000000f80,
        "\x78\x9c\xec\xdd\xcf\x6b\x5c\xd5\x1e\x00\xf0\xef\x9d\xfc\x6a\xd2\xbe"
        "\x97\x3c\x78\xf0\x5e\x5d\x05\x04\x0d\x94\x4e\x4c\x8d\xad\x82\x8b\x8a"
        "\x0b\x11\x2c\x14\x74\x6d\x1b\x26\xd3\x50\x33\xc9\x94\xcc\xa4\x34\x21"
        "\xd0\x16\x11\xdc\x08\x2a\x2e\x04\xdd\x74\xed\x8f\xba\x73\xeb\x8f\xad"
        "\xfe\x17\x2e\xa4\xa5\x6a\x5a\xac\xb8\x90\x91\x3b\x99\x49\x26\xcd\x4c"
        "\x9a\xb4\x99\x99\x60\x3e\x1f\xb8\xb9\xe7\xdc\x73\x6f\xce\xf9\xce\xb9"
        "\x3f\xce\xcc\xbd\xcc\x04\x70\x60\x8d\xa6\x7f\x32\x11\x47\x23\xe2\xfd"
        "\x24\x62\xb8\xb6\x3c\x89\x88\xbe\x6a\xaa\x37\xe2\xf4\xda\x7a\xf7\x57"
        "\x57\x72\xe9\x94\x44\xa5\xf2\xfa\xaf\x49\x75\x9d\x7b\xab\x2b\xb9\x68"
        "\xd8\x26\x75\xb8\x96\xf9\x7f\x44\x7c\xf7\x4e\xc4\xb1\xcc\xd6\x7a\x4b"
        "\x4b\xcb\xb3\x53\x85\x42\x7e\xa1\x96\x1f\x2f\xcf\x5d\x1a\x2f\x2d\x2d"
        "\x1f\xbf\x38\x37\x35\x93\x9f\xc9\xcf\x9f\x9c\x98\x9c\x3c\x71\xea\xb9"
        "\x53\x27\xf7\x2e\xd6\xdf\x7f\x5c\x3e\x72\xfb\x83\x57\x9e\xfe\xf2\xf4"
        "\x9f\x6f\xff\xef\xe6\x7b\xdf\x27\x71\x3a\x8e\xd4\xca\x1a\xe3\xd8\x2b"
        "\xa3\x31\x5a\x7b\x4d\xfa\xd2\x97\x70\x93\x97\xf7\xba\xb2\x2e\x4b\xba"
        "\xdd\x00\x1e\x49\x7a\x68\xf6\xac\x1d\xe5\x71\x34\x86\xa3\xa7\x9a\x6a"
        "\x61\xb0\x93\x2d\x03\x00\xda\xe5\x6a\x44\x54\x00\x80\x03\x26\x71\xfd"
        "\x07\x80\x03\xa6\xfe\x39\xc0\xbd\xd5\x95\x5c\x7d\xea\xee\x27\x12\x9d"
        "\x75\xe7\xa5\x88\x38\xb4\x16\x7f\xfd\xfe\xe6\x5a\x49\x6f\xed\x9e\xdd"
        "\xa1\xea\x7d\xd0\xa1\x7b\xc9\xa6\x3b\x23\x49\x44\x8c\xec\x41\xfd\xa3"
        "\x11\xf1\xe9\xd7\x6f\x7e\x9e\x4e\xd1\xa6\xfb\x90\x00\xcd\x5c\xbb\x1e"
        "\x11\xe7\x47\x46\xb7\x9e\xff\x93\x2d\xcf\x2c\xec\xd6\x33\xdb\x15\x56"
        "\x06\xaa\xb3\xd1\x07\x16\x3b\xff\x41\xe7\x7c\x93\x8e\x7f\x9e\x6f\x36"
        "\xfe\xcb\xac\x8f\x7f\xa2\xc9\xf8\x67\xa0\xc9\xb1\xfb\x28\x1e\x7e\xfc"
        "\x67\x6e\xed\x41\x35\x2d\xa5\xe3\xbf\x17\x1b\x9e\x6d\xbb\xdf\x10\x7f"
        "\xcd\x48\x4f\x2d\xf7\xaf\xea\x98\xaf\x2f\xb9\x70\xb1\x90\x4f\xcf\x6d"
        "\xff\x8e\x88\xb1\xe8\x1b\x48\xf3\x13\xd5\x55\x9b\x3f\x05\x35\x76\xf7"
        "\xaf\xbb\xad\xea\x6f\x1c\xff\xfd\xf6\xe1\x5b\x9f\xa5\xf5\xa7\xf3\x8d"
        "\x35\x32\xb7\x7a\x07\x36\x6f\x33\x3d\x55\x9e\x7a\xdc\xb8\xeb\xee\x5c"
        "\x8f\x78\xa2\xb7\x59\xfc\xc9\x7a\xff\x27\x2d\xc6\xbf\x67\x77\x58\xc7"
        "\xab\x2f\xbc\xfb\x49\xab\xb2\x34\xfe\x34\xde\xfa\xb4\x35\xfe\xf6\xaa"
        "\xdc\x88\x78\xaa\x69\xff\x6f\xf4\x65\xb2\xed\xf3\x89\xe3\xd5\xdd\x61"
        "\xbc\xbe\x53\x34\xf1\xd5\x4f\x1f\x0f\xb5\xaa\x7f\xa3\xff\x07\xaa\xf3"
        "\xb4\xfe\xfa\x7b\x81\x4e\x48\xfb\x7f\x68\xfb\xf8\x47\x92\xc6\xe7\x35"
        "\x4b\xbb\xaf\xe3\x87\x1b\xc3\xdf\xb6\x2a\x6b\xdc\xff\x9b\xc7\xdf\x7c"
        "\xff\xef\x4f\xde\xa8\xa6\xfb\x6b\xcb\xae\x4c\x95\xcb\x0b\x13\x11\xfd"
        "\xc9\x6b\x5b\x97\x9f\xd8\xd8\xb6\x9e\xaf\xaf\x9f\xc6\x3f\xf6\x64\xf3"
        "\xe3\xbf\xd5\xfe\x9f\xa9\x3d\x1b\x7b\x7e\x3d\xb7\xbd\xde\xdb\xbf\x7c"
        "\x51\xfb\x57\x4d\xe3\xaf\xba\xd6\x2a\xfe\xf6\x4a\xe3\x9f\xde\x55\xff"
        "\x6f\x93\xa8\xd4\xb6\x79\xa0\xe8\xe6\xfd\xd9\x9e\x56\xf5\xef\xac\xff"
        "\x27\xab\xa9\xb1\xda\x92\x9d\x9c\xff\x1e\xd2\xd2\xc7\xd8\x9b\x01\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x60\xf7\x32\x11\x71\x24\x92\x4c\x76\x3d\x9d\xc9\x64\xb3\x6b\xbf\xe1"
        "\xfd\xdf\x18\xca\x14\x8a\xa5\xf2\xb1\x0b\xc5\xc5\xf9\xe9\xa8\xfe\x56"
        "\xf6\x48\xf4\x65\xea\x5f\x75\x39\xdc\xf0\x7d\xa8\x13\xb5\xef\xc3\xaf"
        "\xe7\x4f\x3c\x90\x7f\x36\x22\xfe\x13\x11\x1f\x0d\x0c\x56\xf3\xd9\x5c"
        "\xb1\x30\xdd\xed\xe0\x01\x00\x00\x00\x00\x00\x00\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\xe6\xf0\xe6\xdf\xff\xbf\x9a\xce\xb2\xd9\xb5\xb2\x9f\x07"
        "\xba\xdd\x3a\x00\xa0\x6d\x0e\x75\xbb\x01\x00\x40\xc7\xb9\xfe\x03\xc0"
        "\xc1\xb3\xbb\xeb\xff\x60\xdb\xda\x01\x00\x74\xce\xae\xdf\xff\x57\x92"
        "\xf6\x34\x04\x00\xe8\x98\x1d\x5f\xff\xcf\xb7\xb7\x1d\x00\x40\xe7\xb8"
        "\xff\x0f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\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\x9b\x9d\x3d\x73\x26\x9d\x2a\x7f\xac\xae\xe4\xd2\xfc\xf4\xe5"
        "\xa5\xc5\xd9\xe2\xe5\xe3\xd3\xf9\xd2\x6c\x76\x6e\x31\x97\xcd\x15\x17"
        "\x2e\x65\x67\x8a\xc5\x99\x42\x3e\x9b\x2b\xce\xb5\xfc\x47\xd7\xd6\x66"
        "\x85\x62\xf1\xd2\x64\xcc\x2f\x5e\x19\x2f\xe7\x4b\xe5\xf1\xd2\xd2\xf2"
        "\xb9\xb9\xe2\xe2\x7c\xf9\xdc\xc5\xb9\xa9\x99\xfc\xb9\x7c\x5f\xc7\x22"
        "\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\x80\x9d\x2b"
        "\x2d\x2d\xcf\x4e\x15\x0a\xf9\x05\x89\x6d\x13\x83\xfb\xa3\x19\xfb\x26"
        "\xd1\x1b\xfb\xa2\x19\xff\xf8\x44\x7f\xd7\x6a\x6f\x3c\x4b\x0c\x76\xef"
        "\x04\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\xb0\xcf\xfd\x1d\x00\x00\xff\xff\x68\x77"
        "\x25\x42",
        1957);
    syz_mount_image(/*fs=*/0x400000000780, /*dir=*/0x400000000240,
                    /*flags=MS_LAZYTIME|MS_SYNCHRONOUS|MS_NOATIME*/ 0x2000410,
                    /*opts=*/0x4000000000c0, /*chdir=*/0x7f, /*size=*/0x7a5,
                    /*img=*/0x400000000f80);
    break;
  case 1:
    memcpy((void*)0x400000001900, "net/dev\000", 8);
    res = -1;
    res = syz_open_procfs(/*pid=*/0, /*file=*/0x400000001900);
    if (res != -1)
      r[0] = res;
    break;
  case 2:
    memcpy((void*)0x400000002600, "./file1\000", 8);
    res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x400000002600ul,
                  /*flags=O_SYNC|O_DIRECT|O_CREAT|O_RDWR*/ 0x105042,
                  /*mode=S_IWOTH|S_IXGRP|S_IXUSR*/ 0x4a);
    if (res != -1)
      r[1] = res;
    break;
  case 3:
    syscall(__NR_mmap, /*addr=*/0x400000001000ul, /*len=*/0x1000ul,
            /*prot=PROT_WRITE*/ 2ul, /*flags=MAP_FIXED|MAP_SHARED*/ 0x11ul,
            /*fd=*/r[1], /*offset=*/0ul);
    break;
  case 4:
    syscall(__NR_read, /*fd=*/r[0], /*data=*/0x400000001b40ul, /*len=*/8ul);
    break;
  case 5:
    memcpy((void*)0x400000000040, "squashfs\000", 9);
    memcpy((void*)0x400000000240, "./file0\000", 8);
    memcpy(
        (void*)0x400000000b80,
        "\x00\xa3\xd9\xfe\xb8\x6e\x02\xe3\xb0\xbd\x5e\x57\x4a\x82\x2a\xa0\x33"
        "\x06\x08\x29\xd9\xf5\x70\x70\x6d\xaa\xf7\xe6\x43\x85\xf4\xc7\x57\xc8"
        "\xc1\x50\x9c\xbd\x06\x00\x3c\x6d\x03\x00\x00\x00\xff\xdd\xe1\x16\x53"
        "\x4a\x3e\x53\x90\x68\xb6\x79\xd9\x3c\x64\x65\x00\xb7\x1c\x53\x96\x6a"
        "\x78\x8a\x93\xaf\x70\xa9\xe8\x37\x8a\x4d\xff\x15\xe4\xa1\x4b\x5a\x4b"
        "\x6c\x14\xd2\xfe\xff\x8e\xc1\x51\x64\xff\xff\xba\x58\x65\x57\x11\x5a"
        "\xe1\xb2\x47\x0a\x06\xd9\x56\xca\xe4\xea\x3b\x76\xe6\x46\xef\x7b\x00"
        "\xf8\xbc\xba\xd4\x03\x0f\xa2\xf8\x7b\x05\x3a\x2e\xcc\x76\x19\xae\x04"
        "\x7c\xb2\x80\xcd\x39\x13\xe7\xae\x1c\x91\x85\x8f\xde\xe7\x8f\xd1\x98"
        "\x66\x21\x2b\x8a\xed\xf8\x18\xfe\xa0\x39\x93\x2b\x8d\x5f\x45\x4c\xf4"
        "\xfa\x9f\x9c\x1c\x0b\xd1\xc3\xf8\xc0\x2f\x1b\xc7\x02\xd7\x35\x9e\xb8"
        "\xbe\x44\x6f\x88\xb7\x7c\xe9\x2c\x3d\x94\x38\x28\xec\xe9\xee\xf5\x4e"
        "\x10\xc2\xb4\xd6\x6f\xb8\x87\xed\x9e\x56\xe2\xfb\xf9\x82\xea\x34\x43"
        "\xc9\xc3\x0d\x40\xc4\xdd\x06\x76\x82\x18\x7e\x22\x41\x73\xe4\x9a\x3d"
        "\x07\x00\xef\xeb\x8f\xc6\x57\x0c\xe5\xfe\xb7\xd4\xc9\xab\x5c\x4c\xc0"
        "\x9b\xa9\xae\x62\x76\x84\x5f\xf5\x5c\x7f\xda\xab\x25\x77\x6e\xdd\x4d"
        "\x38\xca\xe5\x59\x7e\xf4\xd5\xa2\xbf\x63\x41\x5f\xdf\xe0\x86\x7d\xee"
        "\x33\x9d\xa4\xa4\x9e\x99\xfc\xf9\x77\xe3\xbe\x58\x8f\xb6\xa8\xe4\xee"
        "\x0d\x53\x95\x98\x2f\x37\x4f\x38\x02\xe1\xcf\x12\xc5\x84\x9a\x07\xaf"
        "\x1a\xd1\xe9\xf1\xf5\x27\x25\xea\xb0\x0a\xf2\x83\xcb\xfb\xd1\x8f\xdc"
        "\x8e\x19\x51\xba\x26\x1f\x70\xb3\x78\x11\x17\xb3\xa5\x26\x3e\x36\x71"
        "\xd0\xb9\xe5\xae\xdd\x4e\x92\x61\x65\x4e\x7c\xd5\x21\x36\x00\xa7\x7f"
        "\x55\xf0\xab\x70\x6a\x78\x7a\xc2\x04\xff\xf2\x98\xdc\x72\xbe\x1e\x80"
        "\x38\x9d\x8f\x55\xf4\x2c\x3b\x92\xac\xae\xe0\xdf\x6b\x6b\xea\xaf\xd4"
        "\x3d\x4e\x04\xa3\xf3\x26\xb3\x30\x22\xa2\x47\x4d\x55\x27\xb6\x8b\xa0"
        "\x85\xce\x52\xbf\x89\x4f\x86\xc0\xf0\xf2\xf7\x6c\x1f\xfe\x1e\x7e\xcb"
        "\xf2\xf1\xd7\xf8\xde\x55\x3e\xbd\x38\xa1\xad\x1f\x67\xe4\x3d\xa5\x6f"
        "\x85\x3f\x59\x4b\x16\xbe\x38\x22\xb9\x73\x89\xb2\x48\xdd\x30\x79\xe4"
        "\x1c\xe1\x85\x20\x62\x67\xe9\xf1\x74\xfd\x6b\xa0\x1f\x9c\xc5\x2c\x46"
        "\x56\x08\x00\x00\x48\xd0\xad\x52\x4a\x70\xf1\x68\x8d\x1f\x30\xca\x72"
        "\x99\x63\xf1\x4d\x14\x0b\xf0\x6f\x60\x60\x65\x18\x7f\xef\x9b\x44\xe8"
        "\x84\x69\x9a\x5b\xda\x98\x1b\x07\x00\x00\x00\x00\x00\x00\x00\x9a\x74"
        "\xa8\x43\x88\xdc\x82\xed\x1b\xa2\x9a\xba\x10\x6b\x9f\x6e\x11\xea\x24"
        "\x9e\x48\x70\x49\x4e\xde\x40\xf7\xbc\x48\xdc\x2a\x14\x66\x9c\x1b\x94"
        "\xb3\x22\x09\xf1\x6b\x42\x3a\x92\x74\x74\x0b\x8f\x4e\x64\x1d\x46\xa6"
        "\xf1\x4f\x44\xe2\x6c\x4b\x7d\x54\x22\x32\x2a\x2f\x8d\x96\x75\x32\xb1"
        "\x33\x01\x4d\xa9\xc5\x71\xff\xc2\x66\x4e\x08\x38\x39\x1e\x02\x42\xbc"
        "\xac\xaa\x0c\x00\x35\x8b\xde\xfa\xf2\xbc\x51\xdc\xf4\xa7\x67\x37\x03"
        "\xb8\x9c\xf2\x13\xc3\x32\x5c\x64\x49\x3f\x3e\xd9\x86\x6c\x49\x94\xc1"
        "\x19\x36\x3d\xec\x36\x48\x13\xd2\xa1\xf3\x73\x23\x23\xd6\xfd\xe4\x4b"
        "\x81\x78\xd3\x5f\x93\x62\x00\xa9\x61\x18\x88\x9b\xc3\x4d\x18\x00\x77"
        "\x9c\x82\xb8\x77\xba\x24\xd7\xaa\xde\xc4\xab\xe7\x2a\x3b\x92\x80\xcc"
        "\x12\xd3\xf3\xb6\x0f\xa0\x16\x3f\xc3\xcc\xdc\xe1\x8c\xed\x9a\x8c\xcf"
        "\x33\x12\x20\x55\xf8\x87\x0f\x80\x4f\xb9\x1d\x9f\x91\xba\x8d\xb5\x05"
        "\xd0\x20\xc0\x1f\x53\x2c\x93\x07\x11\x7f\x34\x69\x3d\xd5\x35\xe1\xdf"
        "\x52\xcc\xc9\x4b\xa1\x78\xaa\xf5\x24\x11\x7c\x21\x4f\xa8\x58\xd6\xda"
        "\x2f\x91\xc1\x4a\xb5\xea\x30\x80\x50\x03\x66\x07\x56\x94\xcf\x31\x7c"
        "\xda\xd3\xe6\x1d\x17\xbf\xa4\x49\x01\x24\xe3\x61\x6a\x0d\x58\x1c\xf0"
        "\x5c\xf2\xce\xcc\x0a\x9b\x83\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\xed\x91\x11\xe3\x39\x6f\xea\x12\x3d\x15\xff\x82\x5b\x66"
        "\xe2\x59\x45\xcb\x3f\xd6\xd3\x17\x73\xaf\x06\x34\xa1\x55\xfe\x85\x15"
        "\x9a\x64\x3b\x06\x4f\xba\x11\x35\xff\x23\xd7\x13\x43\x1f\x3c\xf8\x58"
        "\x7d\x87\x78\xf7\xeb\x1a\x02\xd1\x55\xfb\x61\x85\xd1\x05\xd2\x68\x44"
        "\xd1\x11\xc8\x5f\xd6\x32\x1f\xc4\xa9\xa3\x68\xc0\x4c\xd3\xf2\x9a\xb9"
        "\xab\x00\xd3\xef\xd8\x61\x11\xca\x43\x0d\xcf\xbf\x19\x10\xb2\x35\xe6"
        "\x36\xe9\x9b\x61\x51\x63\x98\x9a\x37\x79\xe5\x20\xb5\x9d\x2e\x7d\xb3"
        "\x09\xa3\x71\x0d\x5b\x11\xae\x9c\x21\xad\x7e\x4c\x7d\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x34\xaa\xfb\x04\x79\xe8\xea\x1a\xb8\xbf"
        "\xd9\x7c\x21\x86\xa3\xa7\x84\xce\x99\x6d\x63\xc4\x2c\x31\xe3\xa2\x11"
        "\xc2\x84\xf7\xc0\x18\x74\x29\xd7\xf0\x17\x48\xd6\xf0\x25\x19\x92\x1b"
        "\x9d\x81\xa5\x10\xde\x2f\xf2\xf2\x1e\x74\x23\x32\x80\x36\xd4\x5a\xdf"
        "\x7d\xf5\x7a\x05\x72\xa6\xdf\xba\x1e\x0e\x7d\xbe\xd9\xae\xeb\xb7\xcd"
        "\x80\x6f\x36\x85\x45\x9b\xe4\x6d\xc6\x9d\x31\x4f\xd3\xea\x63\x3b\x15"
        "\x39\xf4\x66\xc8\xd3\x2a\x2e\x93\x92\xd1\x62\x06\x56\x95\x89\x00\xff"
        "\xbf\x0c\x3f\x51\x39\xc0\x35\x80\xf8\x35\x16\xf0\x2c\x1a\xdb\xb6\xe1"
        "\x60\x40\xf2\x73\x45\x6e\x98\x27\x41\xfe\x40\xb3\xf6\xa3\x0b\xc9\x23"
        "\x7f\x9d\xa1\x35\x72\xc2\x09\x96\x8b\x40\xdd\x6b\xf4\xfb\xb0\x56\xd3"
        "\x03\x69\x8c\x74\xcd\xbd\x4c\x38\xc5\x4e\x94\x5e\x8e\x93\xff\x94\x6a"
        "\xa2\xa1\xfc\x94\x06\x46\xfc\x7d\xbc\xb3\x45\x52\x21\xcf\x61\x92\xc9"
        "\x86\xeb\x7a\x08\x7a\xf4\x5e\x68\x86\x8f\x84\x95\x00\x42\xc9\x8f\xa2"
        "\x50\x5d\xbb\x1a\x86\xd4\x27\x0d\xb2\xe4\xd7\xd5\xfb\xa2\x0c\xb0\x43"
        "\x3e\x0a\x40\xcb\xe5\xf0\xb9\xbb\x00\x37\xf3\x84\x88\x67\x13\x6c\xf2"
        "\x26\x1d\x09\x3a\xdd\xe2\x62\x79\x9a\xc8\x67\x01\x01\x02\x65\xee\x1b"
        "\xa9\xcb\xa2\x90\x52\x73\x52\x56\x5b\x05\x16\xa0\xbd\xf7\xc3\xdb\xa1"
        "\x36\xfe\x02\xfc\x11\x31\xff\xbe\x3e\x2d\xed\x41\xdd\x48\x82\x00\x04"
        "\x97\x54\xa5\x7f\xdc\x1a\xa2\xc7\x56\xb5\x8c\xd7\x03\x23\x05\x9d\x6d"
        "\x2f\x06\x55\x4d\x80\x39\x10\x12\x63\xe8\x8e\x13\xa7\x0d\x15\x7f\xe3"
        "\x7e\xc7\x8d\x89\x11\xfd\xa3\x60\xf4\x45\xcd\xd6\xba\x18\x09\x8a\xc9"
        "\x38\xb7\x1d\x84\xfe\x99\x91\x62\x0d\x81\xe1\x09\x88\x59\x5c\x89\x53"
        "\x75\x37\x8e\x5f\x15\xf1\x2f\x2c\xa6\x3e\x45\xd9\xbf\xe5\x74\x45\x1a"
        "\x60\x23\x5a\xa5\x5d\x88\x82\x58\xec\x38\xbc\xca\xff\x6e\xa7\xdc\xfd"
        "\x46\x78\xbd\xe8\x6e\xe9\x1b\x01\xbd\x98\xfb\x1f\x68\x7f\xaa\x35\x78"
        "\x6d\x33\xa5\x2c\xc2\xee\x7c\xe1\x26\x04\xbe\xa5\x38\xe7\x18\x40\x37"
        "\x04\xca\xe6\xcc\x2e\x85\x60\xf4\x5b\x41\x61\xa8\x98\xdd\x7a\xb7\x41"
        "\xba\xbf\x6f\x65\x3b\x66\xb1\xb4\x96\x9d\xb9\xc6\x98\x23\xbf\xe9\xc6"
        "\xf9\xfb\xe8\x70\xc5\xe0\x0f\xcb\x34\x6a\x8a\x2f\xc8\xdf\x37\x25\x3c"
        "\x02\x66\xbc\x33\xe1\xa8\x11\xa9\xa3\x37\x9a\x2a\xdf\x24\x2c\x54\x57",
        1479);
    memcpy(
        (void*)0x400000000980,
        "\x78\x9c\xca\x28\x2e\x2c\x66\x67\x60\x60\xf8\xfb\xb1\x26\x99\x41\x80"
        "\x01\x0c\x18\x19\x78\x18\x2e\x30\x30\x32\xb0\x30\x30\x30\xa8\x33\x42"
        "\xc4\x18\x98\x20\xd4\x7a\x28\xff\x05\x94\x9e\x09\x95\xb6\x81\xf2\x9b"
        "\xa1\xf4\x42\x28\x5d\xf1\xbf\x7e\xdd\x9a\x53\x7e\x67\x4e\x7a\xea\x6a"
        "\x2d\x93\x65\x66\x68\xf5\xd4\x96\xaf\xb8\xa5\x0d\x17\x93\x4b\xed\x31"
        "\x72\x93\x5c\xcc\x23\xc1\xcc\x10\x9a\x7a\x64\x51\x71\x65\x55\x76\x62"
        "\x4e\x4e\x6a\x51\xf1\x42\x86\x8a\x5b\xc9\x49\x15\xa7\x4f\x30\xb0\x5c"
        "\xb7\xbf\xa6\xd2\x2c\xc1\xe9\xf0\x47\x9e\xc3\x21\x49\xd3\x41\x87\xe9"
        "\x88\x8f\x47\xd6\x8c\xc6\x12\xce\x49\x52\x9a\x62\x6c\x6c\x99\x0a\x67"
        "\xcf\x7c\x90\x5f\xc7\xa6\x71\x84\xe1\xd1\x0a\xe6\x8d\x75\x9e\x79\x8d"
        "\x75\x85\xa9\x53\xf3\xd2\xf2\x92\xaa\xb2\xaa\xb2\xe6\x4d\x9c\xb8\x71"
        "\x66\x63\x67\x63\xe3\xca\x89\x75\x51\x69\x7e\xab\x18\x5b\x52\x5c\x36"
        "\x35\x75\x32\x32\x39\x6c\x51\x13\xd8\xcc\x6c\xa8\x3e\xc9\x46\x7b\xc2"
        "\xbb\xf6\x55\x0f\x93\x1c\x58\x7b\x3c\xfc\x9a\x4f\x19\x2b\xbd\x4e\x65"
        "\xbe\x64\xbc\xb0\x48\xea\xd4\x8a\xaa\x99\x13\xbe\x28\xcd\x66\x34\xfc"
        "\xce\x70\x87\xa7\x6c\x85\x84\x86\x86\x93\xc4\x15\x09\x8b\x7f\xbc\x0c"
        "\xec\x0c\xb6\x0d\xae\x20\x27\xa6\x34\x30\xa4\x29\x84\x31\x26\xa9\xb1"
        "\x89\xb5\x6d\x39\x33\x27\x84\x99\x9f\xcd\x6d\x81\x42\x4b\xf2\x09\xa6"
        "\xd0\xa3\x1c\x4b\x67\x4a\x58\x1c\x10\xaa\x3a\xf9\xd3\x52\xf3\xad\x43"
        "\xa2\xdb\x8c\x6d\x4f\x1d\xd8\xce\xf0\x1c\x3e\xce\xb3\xa6\xa0\x4f\xd0"
        "\xe8\xb8\x04\x83\xd3\x42\xc1\xff\x32\x20\x63\x12\x1a\x1a\xca\x34\xd6"
        "\x32\x2d\xb5\x5d\xf0\xa5\x48\xe3\xaf\x84\xd7\x6a\x63\xa7\x0c\x06\x77"
        "\x7b\xa6\x65\xb0\x00\x65\x69\x00\x91\x2b\xa1\x3c\x59\xb0\x9e\x84\xe4"
        "\x15\x1e\x3a\x9a\x9a\x46\x29\xc9\x09\x0d\x9b\x24\x12\x92\xdc\x0a\x38"
        "\x18\x18\xb6\xee\xe1\xe4\x60\x68\x60\x60\x60\x66\x80\x01\x15\x06\x06"
        "\x86\xed\x8c\xb0\xb8\x85\x80\x6b\x8c\x0c\xa3\x60\x14\x8c\x82\x51\x30"
        "\x0a\x46\xc1\x28\x18\x05\xa3\x60\x14\x8c\x82\x51\x30\x0a\x46\x10\x00"
        "\x04\x00\x00\xff\xff\x68\x89\x97\x62",
        468);
    syz_mount_image(/*fs=*/0x400000000040, /*dir=*/0x400000000240,
                    /*flags=MS_NODIRATIME|MS_NODEV*/ 0x804,
                    /*opts=*/0x400000000b80, /*chdir=*/1, /*size=*/0x1d4,
                    /*img=*/0x400000000980);
    break;
  }
}
int main(void)
{
  syscall(__NR_mmap, /*addr=*/0x3ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x400000000000ul, /*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=*/0x400001000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1,
          /*offset=*/0ul);
  const char* reason;
  (void)reason;
  for (procid = 0; procid < 5; procid++) {
    if (fork() == 0) {
      use_temporary_dir();
      loop();
    }
  }
  sleep(1000000);
  return 0;
}