// https://syzkaller.appspot.com/bug?id=da0d8a51e89e8a43bbe9f97163f12296725c796c
// 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;
}

//% 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 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, loopfd = -1, 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) {
    memset(loopname, 0, sizeof(loopname));
    snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
    if (setup_loop_device(data, size, loopname, &loopfd) == -1)
      return -1;
    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) {
    ioctl(loopfd, LOOP_CLR_FD, 0);
    close(loopfd);
  }
  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;
retry:
  while (umount2(dir, MNT_DETACH | UMOUNT_NOFOLLOW) == 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, MNT_DETACH | UMOUNT_NOFOLLOW) == 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, MNT_DETACH | UMOUNT_NOFOLLOW))
        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, MNT_DETACH | UMOUNT_NOFOLLOW))
          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)
{
  int i, call, thread;
  for (call = 0; call < 7; 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);
      if (call == 3)
        break;
      event_timedwait(&th->done, 50 + (call == 0 ? 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 (;;) {
      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;
    }
    remove_dir(cwdbuf);
  }
}

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

void execute_call(int call)
{
  intptr_t res = 0;
  switch (call) {
  case 0:
    memcpy((void*)0x20000c00, "udf\000", 4);
    memcpy((void*)0x20000000, "./file0\000", 8);
    memcpy(
        (void*)0x200003c0,
        "\x00\xfc\x26\x47\x80\xb8\x4b\x20\xb3\x69\x41\xcf\x58\x30\x3e\x48\x0e"
        "\x33\xde\xf8\xd2\x2b\xec\xbe\x07\x9d\x71\xd2\xe2\x20\x4e\x08\xd1\x00"
        "\x00\x00\x00\xea\xff\xff\xff\x00\x00\x00\x00\x87\x59\x34\xcd\x5a\x00"
        "\x1c\xaa\x86\x47\x9b\xda\x7b\x66\xa3\x3c\xeb\xf9\x62\x22\x77\x95\x84"
        "\xe7\x21\x79\xf7\x98\xd6\xcc\xbf\xf5\xa2\xe7\x82\xc7\x36\x0d\x82\x3a"
        "\xe1\xf3\x8c\xa3\xb4\x11\xce\x64\x76\x8e\x09\xdf\x7f\x74\xaf\x3b\xc7"
        "\x32\x3d\x9d\x17\xc5\x4e\x87\x2a\x7e\x04\x4d\x8b\x8d\x26\x8d\x32\xc1"
        "\x9e\xfd\xf7\x2c\xcb\x0e\xef\x93\x97\xad\x4f\xde\x92\x46\x7c\x81\x50"
        "\x5c\x52\x2c\x7d\x48\xe1\x48\xbf\x89\x6f\x77\xc7\xbf\x10\xde\x76\xd6"
        "\xfb\x99\x05\x00\x00\x00\x00\x00\x00\x00\x06\x51\xe3\x84\x59\xf2\xc0"
        "\x1d\x16\x23\x06\x6e\xe1\x40\x89\xe5\x84\x41\xda\x54\x35\x4e\xcb\x3a"
        "\xf9\x47\x76\x2b\x1a\x7c\xb1\x1c\xfe\x7e\x9f\xa5\xfd\x00\x00\x00\x00"
        "\xef\xd7\xdd\x65\xf8\xea\xbc\x7c\xcd\x73\x8c\x68\xa2\x9c\xcf\x33\xf6"
        "\x50\x62\x1e\x58\x7f\x18\x42\xf9\xeb\xb0\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x23\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf3\x47\x09\xb0\x75\xaf\xa0\x3f"
        "\xd0\x98\x23\x15\x32\x8c\x5e\xc6\x79\x2e\xd0\x19\x1a\xd3\x6c\x20\xab"
        "\xbe\xdc\x0b\x17\x71\x7f\xe2\x9b\xae\x9a\xd9\x0f\x1f\xf7\xe1\xd2\xb7"
        "\x6d\x88\x52\x8d\x16\x7f\x87\xb3\xbb\x77\x9a\x07\x8f\xf5",
        320);
    memcpy(
        (void*)0x200018c0,
        "\x78\x9c\xec\xdd\x4f\x6c\x1c\xd7\x79\x00\xf0\xef\x0d\x49\x93\x92\x8b"
        "\x64\xeb\x58\xb2\x93\x1a\xc1\xda\x05\x1c\x55\x69\x54\x92\x8a\x2d\x1b"
        "\x0c\x50\xab\x66\x89\xa6\x51\x6c\xd6\x14\x93\xb6\xee\xc1\x2b\x71\xa5"
        "\x6e\x45\x2d\x17\x24\xe5\xc8\x46\x9b\xb8\x27\x1f\x5a\xa0\x6c\x0a\xf4"
        "\xd2\x14\x28\x50\xa4\x30\x7a\x08\xd8\x43\x0e\xed\x29\x05\x0a\xf4\x4a"
        "\x14\xb9\x15\x05\xd4\x34\x75\x5d\x14\x05\xf6\x10\x23\x97\xc2\x2c\x66"
        "\xf6\x2d\xb9\xa2\x68\x8b\x30\x45\x51\xb2\x7f\x3f\x40\xfc\x66\x67\xbe"
        "\x37\xfb\xfe\xac\x67\x66\xe7\xed\xc0\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\x00\x44\xfc\xca\xaf\x9e\x1d\x9f\x48\x87\x5d"
        "\x0b\x00\xe0\x6e\x7a\x61\xee\xa5\xf1\x49\xe7\x7f\x00\xf8\x58\x39\xef"
        "\xfb\x3f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xdc\xeb\x52\x14"
        "\xf1\x4e\xa4\xf8\xc6\x63\xdd\xf4\x4a\xf5\xba\x67\xec\x5c\xab\x7d\xed"
        "\xfa\xfc\xf4\xcc\xee\xc5\x8e\xa4\xaa\xe4\x50\x95\x5f\xfe\x1b\x9b\x98"
        "\x3c\xfd\xc5\xa7\x9e\x3e\xf3\x4c\x3f\x7e\x70\xf9\x3b\xed\xd3\xf1\xe2"
        "\xdc\xf9\xb3\xf5\xe7\x97\xae\x76\x96\x9b\x2b\x2b\xcd\x85\xfa\x7c\xbb"
        "\x75\x71\x69\xa1\xb9\xe7\x3d\xec\xb7\xfc\x4e\x27\xab\x0e\xa8\x5f\xbd"
        "\x72\x6d\xe1\xd2\xa5\x95\xfa\xe4\xa9\xd3\x37\x6d\xbe\x5e\x7b\x7b\xf4"
        "\xc1\xe3\xb5\xa9\x33\x13\x2f\x1f\xeb\xe7\xce\x4f\xcf\xcc\xcc\x0d\xe4"
        "\x0c\x8f\x7c\xe8\x77\xbf\xc5\xfb\x3d\xe1\xf1\x40\x14\x71\x29\x52\x5c"
        "\x79\xeb\x9d\xd4\x88\x88\x22\xf6\xdf\x17\xb7\xf9\xec\x1c\xb4\x23\x55"
        "\x23\x4e\x56\x8d\x98\x9f\x9e\xa9\x1a\xb2\xd8\x6a\xb4\x57\xcb\x8d\xb3"
        "\xfd\x8e\x28\x22\x6a\x03\x85\x9e\xeb\xf7\xd1\x5d\x18\x8b\x7d\xa9\x47"
        "\xbc\x51\x56\xbf\xac\xf0\xc9\xb2\x79\x73\x9d\xc6\x72\xe3\xc2\x62\xb3"
        "\x3e\xdb\x58\x5e\x6d\xad\xb6\x96\xda\xb3\xa9\x57\xdb\x54\xa5\x17\xf1"
        "\x4c\x8a\xe8\x44\x44\x77\xf4\xd6\xdd\x8d\x44\x11\xdf\x8c\x14\x6f\x7e"
        "\xa7\x9b\x2e\x44\xc4\x50\xbf\x1f\x3e\x5f\x3d\x18\x7c\xfb\xfa\x14\x07"
        "\xd0\xc6\x3d\x18\x8e\x88\xda\x48\xc4\x46\x71\x1f\x8c\xd9\x3d\x6c\x34"
        "\x8a\xf8\x5e\xa4\xf8\xf6\xb7\xc6\xe3\x62\xee\xd7\xaa\xdb\x9e\x8c\xf8"
        "\x6a\x19\x8f\x47\x5c\x2b\xe3\x8d\x88\xb5\x32\x7e\x36\x22\x95\x1f\x90"
        "\x87\x23\xde\xdd\xe5\xf3\xc4\xfd\x65\x38\x8a\xf8\xa3\x48\xf1\x93\xa9"
        "\x6e\x5a\xe8\x8f\x7d\x75\x5c\x39\xf7\xb5\xfa\x97\xdb\x97\x96\x06\x72"
        "\xfb\xc7\x95\xfb\xfe\xfc\x70\x37\xdd\xe3\xc7\xa6\xb1\x28\xa2\x51\x1d"
        "\xf1\xbb\xe9\xc3\x5f\xec\x00\x00\x00\x00\x00\x70\xef\x29\xe2\x4f\x23"
        "\xc5\xe3\x3f\x3c\x91\x3a\x31\x38\xa7\xd8\x6a\x5f\xae\x9f\x6f\x5c\x58"
        "\xec\xdd\x15\xee\xdf\xfb\xaf\xe7\x52\x9b\x9b\x9b\x9b\xb5\xd4\x8b\xe3"
        "\x39\xce\xe6\xd8\xc9\x71\x2d\xc7\xf5\x1c\x37\x72\xec\xe6\x58\x2b\x72"
        "\xf9\x1c\x67\x73\xec\xe4\xb8\x96\xe3\x7a\x8e\x1b\x39\x76\x73\xac\x0d"
        "\xe5\xf2\x39\xce\xe6\xd8\xc9\x71\x2d\xc7\xf5\x1c\x37\x72\xec\xe6\x58"
        "\x1b\xce\xe5\x73\x9c\x1d\xae\x9a\xf6\x46\x27\xbf\x5e\xcb\x71\x3d\xc7"
        "\x8d\x1c\xbb\xc3\x87\x36\x58\x00\x00\x00\x00\x00\x00\x00\xb0\xab\x23"
        "\x51\xc4\xd7\x23\xc5\x93\xbf\xf4\x6a\xf5\x5c\x71\x54\xcf\xa5\x7f\x72"
        "\xea\xcc\x4b\xa7\x7e\x7d\xf0\x99\xf1\x47\x6f\xb3\x9f\x32\xf7\x54\x44"
        "\xac\x17\x7b\x7b\x26\xf7\x81\xfc\xe8\xf0\x6c\x9a\x4d\xe9\x90\x9e\x21"
        "\xa6\xf7\xfc\xdf\x1f\xe4\xe7\xff\xfe\xf0\xb0\x2b\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\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x1c\xaa\x22\x8a\x78\x22\x52\xbc\xfa\xfd"
        "\x6e\x8a\x14\x11\xf5\x88\x57\xa2\x17\x6f\x8c\x1e\x76\xed\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\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\x3b\x61\x2c\x15\xf1\x6e\xa4\xf8\xf3\xaf\x8c\x55\xaf\x37"
        "\x8a\x88\xdf\x8e\x88\xf7\x36\xdf\xdb\x8c\x88\x1b\xef\x6d\xde\x69\x87"
        "\xdd\x62\x00\x00\x00\x00\x00\x00\x00\xf8\x08\x4a\x45\xbc\x16\x29\x9e"
        "\x78\xa9\x9b\x6a\x11\x71\xbd\xf6\xf6\xe8\x83\xc7\x6b\x53\x67\x26\x5e"
        "\x3e\x36\x14\x43\x91\xca\x94\xc1\xfc\x17\xe7\xce\x9f\xad\x3f\xbf\x74"
        "\xb5\xb3\xdc\x5c\x59\x69\x2e\xd4\xe7\xdb\xad\x8b\x4b\x0b\xcd\xbd\xbe"
        "\xdd\xd8\xb9\x56\xfb\xda\xf5\xf9\xe9\x99\x03\x69\xcc\x6d\x1d\x39\xe0"
        "\xfa\x1f\x19\x7b\x7e\xa9\xf3\xda\x72\xeb\xf2\xef\xae\xee\xba\xfd\xe8"
        "\xd8\xd9\x0b\x2b\xab\xcb\x8d\x8b\xbb\x6f\x8e\x23\x51\x44\xd4\x07\xd7"
        "\x9c\xac\x2a\x3c\x3f\x3d\x53\x55\x7a\xb1\xd5\x68\x57\x45\x67\xd3\x5e"
        "\x6b\x0c\x00\x00\x00\x00\x00\x00\xc0\xc7\xc1\x48\x2a\xe2\xbd\x48\xf1"
        "\xe6\xdf\xbc\xb5\x35\xef\x3c\xdc\x9b\xf3\x1f\xde\x99\xfb\xdd\x2f\x45"
        "\x14\x79\x79\x3a\xcf\x3f\x6f\x4d\x43\x57\xbf\x1b\xf8\x44\xf5\xbb\x81"
        "\xde\xf2\x27\xa7\xce\xfc\xc6\xe4\x67\x06\x97\x77\x9d\xb2\x3e\x59\x4d"
        "\xa8\xd7\xe7\xa7\x67\x66\xe6\x06\x56\x0f\x8f\xdc\x9a\x3a\x96\xdf\x77"
        "\x7c\x7f\x4d\x66\x40\x39\xfe\xab\x91\xe2\x8f\xff\xb2\x9e\x1e\xcf\xeb"
        "\x6e\x1e\xff\xa1\xad\xdc\xef\xfe\xfe\xf6\x78\xbf\xb1\x73\x47\xef\x33"
        "\xe6\xfb\x1d\xff\x9f\x1d\x58\x57\xbe\x67\x4a\x45\xfc\x5d\xa4\xf8\xb9"
        "\xdf\x7c\x34\x1e\xaf\xea\x79\x34\x6e\xf9\xcd\x44\xce\xfb\x4a\xa4\xf8"
        "\xad\xf5\xc7\x72\x5e\x3c\x50\xe6\x3d\x91\xb7\x3f\x54\xfd\x1d\xbb\xd4"
        "\x5a\x6c\x8e\x97\xb9\xd7\x23\xc5\x3f\x5e\xbb\x39\xf7\xc9\x9c\xfb\xa9"
        "\xed\xdc\x89\x3d\x77\xec\x7d\xa2\x1c\xff\x27\x22\xc5\xff\xfc\xce\xfa"
        "\x56\xdf\xe4\xf1\xcf\x23\xb0\x3d\x6a\x83\xe3\xff\x99\x9d\x9f\x8e\x03"
        "\x1a\xff\x87\x06\xd6\xd5\xf2\xfb\xfe\xfc\x9d\x69\x3a\x11\xb1\xf2\xda"
        "\xeb\x57\x1a\x8b\x8b\xcd\x65\x0b\x16\x2c\x58\xd8\x5a\x38\xec\x23\x13"
        "\x77\x43\x79\xfe\xff\x7a\xa4\xf8\x87\x3f\xfb\xd7\xad\xeb\x9d\x7c\xfe"
        "\xff\x99\xde\xab\xed\xeb\xbf\x9f\x7e\x73\xfb\xfc\x3f\xb5\x73\x47\x07"
        "\x74\xfe\xff\xd4\xc0\xba\xa9\x7c\x35\x32\x32\x1c\x31\xb6\x7a\xb5\x33"
        "\xf2\x48\xc4\xd8\xca\x6b\xaf\x7f\xa1\x75\xb5\x71\xb9\x79\xb9\xd9\x3e"
        "\x7d\xe6\xd9\xa7\x27\xc7\x9f\x9d\x18\x3f\x3d\xf2\x40\xff\xe2\x6e\x7b"
        "\x69\xe7\x3b\xdf\xf2\xfd\xe6\xe3\xa8\x1c\xff\xdf\x8b\x14\xdf\xfb\xd1"
        "\xdf\xc6\xe7\xf2\xba\x9b\xaf\xff\x76\xbf\xfe\x3f\xba\x73\x47\x07\x34"
        "\xfe\x0f\x0f\xac\x3b\x7a\xd3\xf5\xca\xbe\x9b\x4e\x1e\xff\xff\x8b\x14"
        "\xff\x3c\xfd\x83\x38\x91\xd7\x7d\xd0\xf5\x7f\xff\xfb\xff\x89\x7c\x11"
        "\xbe\x75\x7d\x7e\x40\xe3\x7f\x6c\x60\x5d\xf5\x1d\xef\x13\x11\xbf\x30"
        "\xb0\xee\xc4\xb1\x88\x8f\xdc\x97\x32\x00\x00\x00\xb8\xc3\x52\x2a\xe2"
        "\x07\x79\x3e\x75\xfc\x36\xf3\xa9\xff\x14\x29\x5e\xff\xef\x5f\xcc\x79"
        "\xe9\x78\x99\xf7\x5c\xde\x5e\xab\xfe\x8e\xbd\xb0\xd4\xfe\xc2\xd9\xc5"
        "\xc5\xa5\x8b\x8d\xd5\xc6\x85\xc5\x66\x7d\xae\xd3\xb8\xd8\x2c\xcb\xfe"
        "\x38\x52\x74\xff\xfa\xb1\x5c\xb6\xa8\xe6\x57\xfb\xf3\xcd\xbd\x39\xde"
        "\xed\xb9\xd8\x7f\x89\x14\xcf\xfe\x5a\x3f\xb7\x37\x17\xdb\xbf\x37\xf5"
        "\xf0\x76\xee\x44\x99\x7b\x2a\x52\xfc\xc9\x0b\x37\xe7\xf6\xef\x63\x1c"
        "\xdb\xce\x9d\x2c\x73\xff\x2d\x52\x4c\xbc\xbc\x7b\xee\xf1\xed\xdc\xd3"
        "\x65\xee\x7f\x45\x8a\x9f\xfe\x45\xbd\x9f\x7b\xb4\xcc\xfd\x52\xce\x7d"
        "\x64\x3b\xf7\xd4\xc5\xa5\xc5\x85\x03\x18\x16\x00\x00\x00\x00\x00\xd8"
        "\x97\x91\x54\xc4\xd3\x91\xe2\xef\x4f\x0f\xa7\xfe\xfd\xed\xbd\xfc\xfe"
        "\xf3\x96\x9b\xde\x07\xf4\xfb\xbf\x47\x06\xd6\x2d\xdc\xa5\xe7\x55\xf6"
        "\xdd\xa9\x00\x70\x8f\x2b\xcf\xff\x27\xca\xb3\xfa\x2f\xff\xd5\xd6\x5c"
        "\xfe\xcd\xe7\xff\xed\xe7\x64\x06\xcf\xff\x3b\x0d\xfe\x7f\x03\xde\x6f"
        "\xf9\xc3\x9c\xff\x6b\x77\xa6\x99\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x3b\x29\x8a\x58\x8a\x14"
        "\xdf\x78\xac\x9b\x6e\x8c\x96\xaf\x7b\xc6\xce\xb5\xda\xd7\xae\xcf\x4f"
        "\xcf\xec\x5e\xec\x48\xaa\x4a\x0e\x55\xf9\xe5\xbf\xb1\x89\xc9\xd3\x5f"
        "\x7c\xea\xe9\x33\xcf\xf4\xe3\x07\x97\xbf\xd3\x3e\x1d\x2f\xce\x9d\x3f"
        "\x5b\x7f\x7e\xe9\x6a\x67\xb9\xb9\xb2\xd2\x5c\xa8\xcf\xb7\x5b\x17\x97"
        "\x16\x9a\x7b\xde\xc3\x7e\xcb\xef\x74\xb2\xea\x80\xfa\xd5\x2b\xd7\x16"
        "\x2e\x5d\x5a\xa9\x4f\x9e\x3a\x7d\xd3\xe6\xeb\xb5\xb7\x47\x1f\x3c\x5e"
        "\x9b\x3a\x33\xf1\xf2\xb1\x7e\xee\xfc\xf4\xcc\xcc\xdc\x40\xce\xf0\xc8"
        "\x87\x7e\xf7\x5b\xa4\xf7\x59\xff\x40\x14\xf1\xbf\x91\xe2\xca\x5b\xef"
        "\xa4\x7f\x1f\x8d\x28\x62\xff\x7d\x71\x9b\xcf\xce\x41\x3b\x52\x35\xe2"
        "\x64\xd5\x88\xf9\xe9\x99\xaa\x21\x8b\xad\x46\x7b\xb5\xdc\x38\xdb\xef"
        "\x88\x22\xa2\x36\x50\xe8\xb9\x7e\x1f\xdd\x85\xb1\xd8\x97\x7a\xc4\x1b"
        "\x65\xf5\xcb\x0a\x9f\x2c\x9b\x37\xd7\x69\x2c\x37\x2e\x2c\x36\xeb\xb3"
        "\x8d\xe5\xd5\xd6\x6a\x6b\xa9\x3d\x9b\x7a\xb5\x4d\x55\x7a\x11\xcf\xa4"
        "\x88\x4e\x44\x74\x47\x6f\xdd\xdd\x48\x14\x31\x12\x29\xde\xfc\x4e\x37"
        "\xfd\x68\x34\x62\xa8\xdf\x0f\x9f\x7f\x61\xee\xa5\xf1\xc9\xdb\xd7\xa7"
        "\x38\x80\x36\xee\xc1\x70\x44\xd4\x46\x22\x36\x8a\xfb\x60\xcc\xee\x61"
        "\xa3\x51\xc4\x53\x91\xe2\xdb\xdf\x1a\x8f\xff\x18\xed\xf5\x6b\xd5\x6d"
        "\x4f\x46\x7c\xb5\x8c\xc7\x23\xae\x95\xf1\x46\xc4\x5a\x19\x3f\x1b\x91"
        "\xca\x0f\xc8\xc3\x11\xef\xee\xf2\x79\xe2\xfe\x32\x1c\x45\x3c\x14\x29"
        "\x7e\x32\xd5\x4d\x3f\x1e\xcd\x63\x5f\x1d\x57\xce\x7d\xad\xfe\xe5\xf6"
        "\xa5\xa5\x81\xdc\xfe\x71\xe5\xbe\x3f\x3f\xdc\x4d\xf7\xf8\xb1\x69\x2c"
        "\x8a\x78\xa7\x3a\xe2\x77\xd3\x7f\xfa\xef\x19\x00\x00\x00\x00\xe0\x23"
        "\xa4\x88\x47\x23\xc5\xe3\x3f\x3c\x91\xaa\xf9\xc1\xad\x39\xc5\x56\xfb"
        "\x72\xfd\x7c\xe3\xc2\x62\xef\xb6\x7e\xff\xde\x7f\x3d\x97\xda\xdc\xdc"
        "\xdc\xac\xa5\x5e\x1c\xcf\x71\x36\xc7\x4e\x8e\x6b\x39\xae\xe7\xb8\x91"
        "\x63\x37\xc7\x5a\x91\xcb\xe7\x38\x9b\x63\x27\xc7\xb5\x1c\xd7\x73\xdc"
        "\xc8\xb1\x9b\x63\x6d\x28\x97\xcf\x71\x36\xc7\x4e\x8e\x6b\x39\xae\xe7"
        "\xb8\x91\x63\x37\xc7\xda\x70\x2e\x9f\xe3\x6c\x8e\x9d\x1c\xd7\x72\x5c"
        "\xcf\x71\x23\xc7\xee\xf0\x61\x8e\x17\x00\x00\x00\x00\x00\x00\xc0\xee"
        "\x8a\x28\xe2\x73\x91\xe2\xd5\xef\x77\xd3\xe6\x68\x6f\x82\xf7\x95\xe8"
        "\xc5\x1b\x9e\x07\xfa\xc8\xfb\xff\x00\x00\x00\xff\xff\xc6\x00\x58\x02",
        3060);
    syz_mount_image(/*fs=*/0x20000c00, /*dir=*/0x20000000, /*flags=*/0x14,
                    /*opts=*/0x200003c0, /*chdir=*/1, /*size=*/0xbf4,
                    /*img=*/0x200018c0);
    break;
  case 1:
    memcpy((void*)0x20000180, "./bus\000", 6);
    res = syscall(__NR_open, /*file=*/0x20000180ul, /*flags=*/0x14937eul,
                  /*mode=*/0ul);
    if (res != -1)
      r[0] = res;
    break;
  case 2:
    memcpy((void*)0x20000180, "./bus\000", 6);
    res = syscall(__NR_open, /*file=*/0x20000180ul, /*flags=*/0x14d27eul,
                  /*mode=*/0ul);
    if (res != -1)
      r[1] = res;
    break;
  case 3:
    syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x600000ul,
            /*prot=*/0x27ffffful, /*flags=*/0x4002011ul, /*fd=*/r[1],
            /*offset=*/0ul);
    break;
  case 4:
    memcpy((void*)0x20000080, "./bus\000", 6);
    res = syscall(__NR_open, /*file=*/0x20000080ul, /*flags=*/0x14113eul,
                  /*mode=*/0ul);
    if (res != -1)
      r[2] = res;
    break;
  case 5:
    syscall(__NR_write, /*fd=*/r[2], /*data=*/0x20000000ul,
            /*len=*/0x208e24bul);
    break;
  case 6:
    syscall(__NR_ftruncate, /*fd=*/r[0], /*len=*/2ul);
    break;
  }
}
int main(void)
{
  syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=*/7ul,
          /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul);
  syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
          /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul);
  use_temporary_dir();
  loop();
  return 0;
}