// https://syzkaller.appspot.com/bug?id=ff834988a0e05a23199aa0230d9afa4b010c69d2
// 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
#ifndef __NR_pwritev2
#define __NR_pwritev2 328
#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, 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) {
    if (strstr(opts, "errors=panic") || strstr(opts, "errors=remount-ro") == 0)
      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 < 9; 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));
      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[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
                 0xffffffffffffffff};

void execute_call(int call)
{
  intptr_t res = 0;
  switch (call) {
  case 0:
    memcpy((void*)0x20000140, "udf\000", 4);
    memcpy((void*)0x20000a80, "./file0\000", 8);
    memcpy((void*)0x20000180, "noadinicb", 9);
    *(uint8_t*)0x20000189 = 0x2c;
    memcpy((void*)0x2000018a, "utf8", 4);
    *(uint8_t*)0x2000018e = 0x2c;
    memcpy((void*)0x2000018f, "noadinicb", 9);
    *(uint8_t*)0x20000198 = 0x2c;
    memcpy((void*)0x20000199, "volume", 6);
    *(uint8_t*)0x2000019f = 0x3d;
    sprintf((char*)0x200001a0, "%020llu", (long long)0xfffffffffffffffe);
    *(uint8_t*)0x200001b4 = 0x2c;
    memcpy((void*)0x200001b5, "iocharset", 9);
    *(uint8_t*)0x200001be = 0x3d;
    memcpy((void*)0x200001bf, "iso8859-14", 10);
    *(uint8_t*)0x200001c9 = 0x2c;
    *(uint8_t*)0x200001ca = 0;
    memcpy(
        (void*)0x20001540,
        "\x78\x9c\xec\xdb\x5d\x6c\x5b\xe7\x79\x07\xf0\xe7\xe5\x91\x6d\xda\xe9"
        "\x5a\xd9\x4d\xdd\xa4\xcd\x52\x16\x0d\x02\x4f\x69\x33\xf9\x23\xb6\x12"
        "\x6f\x80\x3d\xab\x42\x9b\xaa\x89\x51\x59\xd9\xbc\x8b\xc1\x94\x25\x3b"
        "\x5c\x24\x4a\x95\xe4\xc2\xe9\x86\xcc\xc3\x06\x14\x01\x3a\xc0\x28\xb0"
        "\x5e\xac\xc3\x90\x9b\x5d\x0c\xd8\x85\x77\x31\x0c\xd8\x55\xb6\x8b\x61"
        "\xc0\xb0\xc1\xd8\xc5\x50\xac\x68\xa7\xa5\x6d\x9a\xde\xa9\xd8\x47\xae"
        "\x36\x15\x87\x7c\x29\x51\xb2\x1c\x29\xfe\x92\x1c\xff\x7e\x86\xfd\x27"
        "\x0f\x9f\x43\xbe\x1f\x34\x79\xc8\x97\x27\x00\x00\x00\x00\x00\x00\x00"
        "\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\x88\x5f\xfb\xfc\xc9\xfe\x83\x69\xab"
        "\x5b\x01\x00\xdc\x4b\x2f\x8c\x7c\xa5\xff\xb0\xf7\x7f\x00\x78\xa0\x9c"
        "\xf1\xf9\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb6\xbb\x14"
        "\x45\x7c\xe7\x8f\x86\xe3\xe5\xef\x2f\xa6\x73\xad\xeb\x6d\xd5\xe1\x46"
        "\xf3\xd2\xe5\xd1\xc1\xa1\xf5\x77\xdb\x9d\x22\x45\x25\x8a\x56\x7d\xf9"
        "\xb7\x7a\xf0\xd0\xe1\x23\xcf\x1c\x3d\x36\xd0\xc9\xf7\xde\xff\x4e\x7b"
        "\x34\x5e\x1c\x39\x73\xb2\x76\x6a\x7a\x6a\x66\x76\x62\x6e\x6e\x62\xbc"
        "\x36\xda\x6c\x9c\x9f\x1e\x9f\xd8\xf4\x3d\xdc\xee\xfe\x6b\xf5\xb5\x06"
        "\xa0\x36\xf5\xca\xa5\xf1\x0b\x17\xe6\x6a\x87\x9e\x3e\xbc\xea\xe6\xcb"
        "\xbd\x6f\xef\x7a\x68\x7f\xef\xf1\x63\xcf\x9f\xdd\xd7\xa9\x1d\x1d\x1c"
        "\x1a\x1a\xe9\xaa\xe9\xd9\x71\xcb\x8f\x7e\x83\x9b\x9d\xe1\xb1\x33\x8a"
        "\xf8\x61\xa4\xa8\x7e\xe3\x9d\x54\x8f\x88\x4a\xdc\xfe\x58\x6c\xf0\xdc"
        "\xb9\xdb\x76\xb7\x3a\xd1\xd7\xea\xc4\xe8\xe0\x50\xab\x23\x93\x8d\x7a"
        "\x73\xbe\xbc\x31\x55\x72\x55\x25\xa2\xb7\x6b\xa7\x13\x9d\x31\xba\x07"
        "\x73\xb1\x29\xbf\xfc\xdb\x43\xbf\xbf\xde\xf6\x5a\xc4\x95\xb2\xf9\x65"
        "\x83\xfb\xca\xee\x8d\xcc\xd4\x67\xeb\x63\x93\x13\xb5\xd3\xf5\xd9\xf9"
        "\xc6\x7c\x63\xba\x99\x2a\xed\xd6\x96\xfd\xe9\x8d\x4a\x0c\xa4\x88\x99"
        "\x88\x58\x2c\x6e\xbc\xbb\x1d\x51\xc4\x7f\x44\x8a\x6f\xbe\xbb\x98\xc6"
        "\x22\xa2\xe8\x8c\xc3\x53\xad\x13\x83\x37\x6e\x67\xe5\x7d\xf4\x69\xf8"
        "\x7f\xa6\xff\xe6\x3b\xcd\x4f\x3d\xf1\x3e\x76\xb9\x99\x9e\xb2\x6f\x45"
        "\xc4\xf5\xd8\x46\x73\x76\x1f\xda\x15\x45\xbc\x1e\x29\xbe\x75\xb6\x3f"
        "\xce\xe7\x71\x6d\x0d\xdb\x93\x11\x5f\x2e\xf3\xf1\x88\xaf\x96\xb9\x10"
        "\x71\x35\x5f\x4f\xe5\x13\xe4\xb1\x88\x9f\xad\xf3\x7c\xe2\xfe\xd2\x13"
        "\x45\xfc\x73\xa4\x98\x4e\x8b\x69\xbc\x33\xf7\xad\xd7\x95\xe1\x97\x6a"
        "\x5f\x6c\x5e\x98\xee\xaa\xed\xbc\xae\xdc\xf7\xef\x0f\xf7\xce\xc3\x6f"
        "\x6f\xf3\xd7\xa6\x6a\x14\x31\xd6\x7a\xc5\x5f\x4c\xb7\x7e\xb0\x03\x00"
        "\x00\x00\x00\xc0\xf6\x53\xc4\xdf\x46\x8a\x6b\x53\x07\xd2\x4c\x74\xaf"
        "\x29\x36\x9a\x17\x6b\x67\xea\x63\x93\xed\x6f\x85\x3b\xdf\xfd\xd7\xf2"
        "\x5e\x4b\x4b\x4b\x4b\xbd\xa9\x9d\xb5\x9c\xfd\x39\x4f\xe4\x3c\x9d\xf3"
        "\x5c\xce\x99\x9c\x57\x72\x5e\xcd\xf9\x46\xce\x6b\x39\xdf\xcc\x79\x3d"
        "\xe7\x42\xce\xc5\x9c\x51\xc9\x8f\x9f\xb3\x96\xb3\x3f\xe7\x89\x9c\xa7"
        "\x73\x9e\xcb\x39\x93\xf3\x4a\xce\xab\x39\xdf\xc8\x79\x2d\xe7\x9b\x39"
        "\xaf\xe7\x5c\xc8\xb9\x98\x33\xac\x7b\x01\x00\x00\x00\x00\x00\x00\xb0"
        "\xcd\xec\x8e\x22\xbe\x17\x29\x3e\xf3\xd7\x5f\x6b\x9d\x57\x1c\xad\xf3"
        "\xd2\x3f\x72\x7c\xe0\xc0\x17\x9e\xe8\x3e\x67\xfc\xe3\x1b\xdc\x4f\x59"
        "\xfb\x74\x44\x5c\x8b\xcd\x9d\x93\xbb\x23\x9f\x3a\x9c\x2a\xe5\x9f\x3b"
        "\xdf\x2f\x36\xa7\x1a\x45\xbc\x96\xcf\xff\x5b\xf7\x7c\x73\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\xe0\x81\x51\x89\x22\x3e\x1e\x29\xbe"
        "\xfd\xfa\x62\x8a\x14\x11\xb5\x88\x73\xd1\xce\x85\x62\xab\x5b\x07\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\xdc\x8a\x6a\x2a\xe2\x54\xa4\xf8\xe9\xe7\xab\xad"
        "\xeb\xd7\x23\xe2\x13\x11\xf1\xff\x4b\xe5\x9f\x88\x58\x58\x5a\x63\xab"
        "\x5b\x0c\x00\x00\x00\x00\x00\x00\x00\xdc\x20\x15\xd1\x1f\x29\xf6\x3e"
        "\xba\x98\x7a\x23\xe2\x72\xef\xdb\xbb\x1e\xda\xdf\x7b\xfc\xd8\xf3\x67"
        "\xf7\x15\x51\x44\x2a\x4b\xba\xeb\x5f\x1c\x39\x73\xb2\x76\x6a\x7a\x6a"
        "\x66\x76\x62\x6e\x6e\x62\xbc\x36\xda\x6c\x9c\x9f\x1e\x9f\xd8\xec\xc3"
        "\x55\x87\x1b\xcd\x4b\x97\x47\x07\x87\xee\x4a\x67\x36\xb4\xfb\x2e\xb7"
        "\x7f\x77\xf5\xd4\xf4\xcc\xab\xb3\x8d\x8b\x2f\xcf\xaf\x7b\xfb\x9e\xea"
        "\xc9\xb1\xb9\xf9\xd9\xfa\xf9\xf5\x6f\x8e\xdd\x51\x89\xe8\xef\xde\xd2"
        "\xd7\x6a\xf0\xe8\xe0\x50\xab\xd1\x93\x8d\x7a\xb3\xb5\x6b\xaa\xdc\xa4"
        "\x81\x95\x88\xda\x66\x3b\x03\x00\x00\x00\x00\x00\x00\xc0\x07\xc6\x9e"
        "\x54\xc4\x33\x91\xe2\xe5\xc6\x91\xd4\x59\x37\xee\x69\xaf\xf9\xff\x42"
        "\xfb\x5a\xb1\x5c\xfb\xe7\xbf\xbb\xf2\x5b\x80\xc9\x35\xd9\xd1\xfd\xfb"
        "\x81\xcd\x5c\x4e\x9b\x6d\x68\x5f\x6b\xe1\xbd\x36\x3a\x38\x34\x34\xd2"
        "\xb5\xb9\x67\xc7\x8d\xa5\x65\x9b\x52\x2a\xe2\xaf\x22\xc5\x27\x7f\xe3"
        "\x91\xd6\x7a\x78\x8a\x3d\xeb\xae\x8d\x97\x75\x3b\x23\xc5\xd1\xaf\x1d"
        "\xc9\x75\xbd\x9f\x2c\xeb\x4e\xac\xaa\xaa\xf6\x8d\x0e\x0e\xd5\x5e\x98"
        "\x6e\x7e\xee\xe4\xe4\xe4\xf4\xf9\xfa\x7c\x7d\x6c\x72\xa2\x36\x32\x53"
        "\x3f\xbf\xe9\x1f\x0e\x00\x00\x00\x00\x00\x00\x00\xc0\x5d\xb4\x27\x15"
        "\xf1\x67\x91\xe2\xb7\xfa\xaf\xa7\xce\x79\xe7\x79\xfd\xbf\xa7\x7d\xad"
        "\x6b\xfd\xff\x57\x5a\x4b\xe8\x2d\xd5\xb4\x3a\x97\xb5\xd6\xf6\x3f\xdc"
        "\x5a\xdb\x6f\x5f\xfe\xc8\xf1\x81\xda\xd0\xa7\x6e\xb6\xfd\x6e\xac\xff"
        "\x97\x6d\x4a\xa9\x88\x7f\x8f\x14\x7b\x7f\xe7\x91\xd6\xf9\xf4\x9d\xf5"
        "\xff\xfe\x35\xb5\x65\xdd\x7f\x45\x8a\x7f\xfb\xa7\xc7\x72\x5d\x65\x67"
        "\x59\x77\xb0\xd3\x9d\xf6\x3d\x5e\x68\x4c\x4e\xf4\xa7\x3c\x56\x9f\x7e"
        "\xaa\x53\x1b\xad\xda\x63\xb9\xf6\xa3\x2b\xb5\x07\xcb\xda\x4f\x47\x8a"
        "\xbf\x78\x72\x75\xed\x40\xae\x7d\x78\xa5\xf6\x50\x59\xfb\x87\x91\xe2"
        "\xff\x9e\x59\xbf\xf6\x63\x2b\xb5\x87\xcb\xda\x3f\x88\x14\x5f\x7a\xab"
        "\xd6\xa9\xdd\x53\xd6\x0e\xe7\xda\xfd\x2b\xb5\x4f\x9f\x9f\x9e\x1c\xdf"
        "\x68\x58\xcb\xf9\xff\xfb\x48\x71\xfa\xa7\x5f\x48\x9d\x3e\xdf\x74\xfe"
        "\xbb\x7e\xff\x71\x65\x4d\x2e\xbb\x61\xce\xdf\xfb\xf2\x9d\x9a\xff\xde"
        "\xae\x6d\x57\xf2\xbc\x7e\x2f\xcf\xff\xc1\x0d\xe6\xff\x1f\x22\xc5\x1f"
        "\xff\xe0\xb1\x5c\xd7\x1e\xfb\x43\xf9\xf6\xbd\xad\x7f\x57\xe6\xff\xd7"
        "\x23\xc5\x4f\x7e\x71\x75\xed\xd1\x5c\xbb\x6f\xa5\xf6\xe0\x66\xbb\xb5"
        "\xd5\xca\xf9\xff\x6c\xa4\x38\xfe\xdd\xef\x2e\xf7\x39\xcf\x7f\x1e\xd9"
        "\x95\x19\xea\x9e\xff\x4f\xf4\xac\xce\xe5\x67\xc9\x16\xcd\xff\xde\xae"
        "\x6d\xbd\xb9\x5d\x87\xdf\xe7\x58\x3c\x88\xe6\x5e\xfd\xfa\x2b\xf5\xc9"
        "\xc9\x89\xd9\x5b\xb9\xf0\x9b\x7b\x7f\xf4\xda\x4f\xde\xf9\xbb\x03\xb7"
        "\xb8\xbb\x0b\x2e\xb8\xb0\x5d\x2f\x6c\xf5\x2b\x13\xf7\x42\xf9\xfe\xff"
        "\x2f\x91\xe2\xb9\xe1\x4a\xea\x1c\xc7\xe4\xf7\xff\x0f\xb5\xaf\xad\x1c"
        "\xff\xbd\xfb\xda\xca\xfb\xff\x73\x6b\x72\xd9\x1d\x7b\xff\x5f\x73\x08"
        "\xb5\xc1\xfb\xff\xbe\xae\x6d\xcf\xe5\xa3\x96\x1d\x3d\x11\xd5\xf9\xa9"
        "\x99\x1d\xfb\x23\xaa\x73\xaf\x7e\xfd\x73\x8d\xa9\xfa\xc5\x89\x8b\x13"
        "\xcd\x81\xff\xfd\xd3\x23\xcf\x0e\x1c\x3d\xfa\xec\x8e\x9d\x9d\x63\xbb"
        "\x95\x4b\xef\x6b\xf8\xee\x7b\xe5\xfc\x0f\x47\x8a\x97\x7e\xf0\xaf\xcb"
        "\x9f\x63\x56\x1f\xff\xad\x7f\xfc\xbf\x67\x4d\x2e\xdb\xa2\xe3\xbf\x8f"
        "\x76\xf7\x69\xd5\x71\xcd\xa6\x87\xe2\x81\x54\xce\xff\xd5\x48\xf1\x7b"
        "\x6f\xbd\xb3\xfc\x79\xf3\xbd\x8e\xff\x3b\x9f\xff\x0f\x7c\x66\x75\x2e"
        "\xff\xff\xdb\xa2\xf9\x7f\xb8\x6b\x5b\xeb\x37\xfe\x1f\x8e\x78\xb6\x6b"
        "\xdb\x81\x8f\x45\x9c\xdc\xec\x63\x01\x00\x00\xc0\x07\xcc\x9e\xbc\x4e"
        "\xfe\x27\xbf\xf4\x8f\xcb\xe7\xbc\xaf\xfe\xfc\x1f\x4f\x74\x6a\xbb\xbf"
        "\xff\xb9\x99\xed\x70\xfe\x3f\x00\x00\x00\x00\x00\x3c\xe8\xf6\xa4\x22"
        "\xfe\x32\x52\xfc\x77\xff\x67\x53\xe7\x1c\xb2\xcd\xfc\xfe\x73\x7c\x4d"
        "\x2e\xdb\xa2\xdf\xff\xed\xef\xda\x36\x7e\xbb\xe7\xb5\x6c\xf2\xc2\xa6"
        "\x07\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x60\x1b"
        "\x4a\x51\xc4\xe3\x91\xe2\xe5\xef\x2f\xa6\x85\xa2\xbc\xde\x56\x1d\x6e"
        "\x34\x2f\x5d\x1e\x1d\x1c\x5a\x7f\xb7\xdd\x29\x52\x54\xa2\x68\xd5\x97"
        "\x7f\xab\x07\x0f\x1d\x3e\xf2\xcc\xd1\x63\x03\x9d\x7c\xef\xfd\xef\xb4"
        "\x47\xe3\xc5\x91\x33\x27\x6b\xa7\xa6\xa7\x66\x66\x27\xe6\xe6\x26\xc6"
        "\x6b\xa3\xcd\xc6\xf9\xe9\xf1\x89\x4d\xdf\xc3\xed\xee\xbf\x56\x5f\x6b"
        "\x00\x6a\x53\xaf\x5c\x1a\xbf\x70\x61\xae\x76\xe8\xe9\xc3\xab\x6e\xbe"
        "\xdc\xfb\xf6\xae\x87\xf6\xf7\x1e\x3f\xf6\xfc\xd9\x7d\x9d\xda\xd1\xc1"
        "\xa1\xa1\x91\xae\x9a\x9e\x1d\xb7\xfc\xe8\x37\x48\x37\xd9\xbe\x33\x8a"
        "\xb8\x10\x29\xaa\xdf\x78\x27\xfd\x67\x11\x51\x89\xdb\x1f\x8b\x0d\x9e"
        "\x3b\x77\xdb\xee\x56\x27\xfa\x5a\x9d\x18\x1d\x1c\x6a\x75\x64\xb2\x51"
        "\x6f\xce\x97\x37\xa6\x4a\xae\xaa\x44\xf4\x76\xed\x74\xa2\x33\x46\xf7"
        "\x60\x2e\x6e\x4b\x2d\xe2\x4a\xd9\xfc\xb2\xc1\x7d\x65\xf7\x46\x66\xea"
        "\xb3\xf5\xb1\xc9\x89\xda\xe9\xfa\xec\x7c\x63\xbe\x31\xdd\x4c\x95\x76"
        "\x6b\xcb\xfe\xf4\x46\x25\x06\x52\xc4\x4c\x44\x2c\x16\x37\xde\xdd\x8e"
        "\x28\x62\x2c\x52\x7c\xf3\xdd\xc5\xf4\x56\x11\x51\x74\xc6\xe1\xa9\x17"
        "\x46\xbe\xd2\x7f\x78\xe3\xf6\x54\xee\x42\x1f\x37\xa1\xa7\xec\x5b\x11"
        "\x71\x3d\xee\x83\x39\xdb\xc6\x76\x45\x11\x1f\x8a\x14\xdf\x3a\xdb\x1f"
        "\x3f\x2c\xda\xe3\xda\x1a\xb6\x27\x23\xbe\x5c\xe6\xe3\x11\x5f\x2d\x73"
        "\x21\xe2\x6a\xbe\x9e\xca\x27\xc8\x63\x11\x3f\x5b\xe7\xf9\xc4\xfd\xa5"
        "\x27\x8a\x38\x1d\x29\xa6\xd3\x62\xfa\x51\xd1\x9a\xfb\x2f\xb5\x5f\x57"
        "\x86\x5f\xaa\x7d\xb1\x79\x61\xba\xab\xb6\xf3\xba\x72\xdf\xbf\x3f\xdc"
        "\x4b\xdb\xfc\xb5\xa9\x1a\x45\xfc\xb8\xf5\x8a\xbf\x98\x7e\xec\xff\x33"
        "\x00\x00\x00\x00\xc0\x07\x48\x11\xbf\x1a\x29\xae\x4d\x1d\x48\xad\xf5"
        "\xc1\xe5\x35\xc5\x46\xf3\x62\xed\x4c\x7d\x6c\xb2\xfd\xb5\x7e\xe7\xbb"
        "\xff\x5a\xde\x6b\x69\x69\x69\xa9\x37\xb5\xb3\x96\xb3\x3f\xe7\x89\x9c"
        "\xa7\x73\x9e\xcb\x39\x93\xf3\x4a\xce\xab\x39\xdf\xc8\x79\x2d\xe7\x9b"
        "\x39\xaf\xe7\x5c\xc8\xb9\x98\x33\x2a\xf9\xf1\x73\xd6\x72\xf6\xe7\x3c"
        "\x91\xf3\x74\xce\x73\x39\x67\x72\x5e\xc9\x79\x35\xe7\x1b\x39\xaf\xe5"
        "\x7c\x33\xe7\xf5\x9c\x0b\x39\x17\x73\x86\xef\xc9\x01\x00\x00\x00\x00"
        "\x00\x80\x6d\xa8\x12\x45\x3c\x12\x29\xbe\xfd\xfa\x62\x5a\x2a\xda\x0b"
        "\xbc\xe7\xa2\x9d\x0b\xd6\x39\x3f\xf0\x7e\x1e\x00\x00\xff\xff\xf4\xd9"
        "\x47\x48",
        2637);
    syz_mount_image(0x20000140, 0x20000a80, 0x3004052, 0x20000180, 1, 0xa4d,
                    0x20001540);
    break;
  case 1:
    memcpy((void*)0x20000000, "./file1\000", 8);
    res = syscall(__NR_open, 0x20000000ul, 0x147042ul, 0ul);
    if (res != -1)
      r[0] = res;
    break;
  case 2:
    memcpy((void*)0x200000c0, "./bus\000", 6);
    res = syscall(__NR_open, 0x200000c0ul, 0x14da42ul, 0ul);
    if (res != -1)
      r[1] = res;
    break;
  case 3:
    memcpy((void*)0x20000040, "/proc/self/exe\000", 15);
    res = syscall(__NR_openat, -1, 0x20000040ul, 0ul, 0ul);
    if (res != -1)
      r[2] = res;
    break;
  case 4:
    syscall(__NR_sendfile, r[1], r[2], 0ul, 0x80001d00c0d0ul);
    break;
  case 5:
    *(uint64_t*)0x20000680 = 0x20000200;
    memset((void*)0x20000200, 5, 1);
    *(uint64_t*)0x20000688 = 0x61000;
    syscall(__NR_pwritev2, r[0], 0x20000680ul, 1ul, 0, 0, 0ul);
    break;
  case 6:
    syscall(__NR_ftruncate, r[0], 0x1ful);
    break;
  case 7:
    memcpy((void*)0x20000000, "./file1\000", 8);
    res = syscall(__NR_open, 0x20000000ul, 0x147042ul, 0ul);
    if (res != -1)
      r[3] = res;
    break;
  case 8:
    *(uint64_t*)0x20000680 = 0x20000200;
    memset((void*)0x20000200, 5, 1);
    *(uint64_t*)0x20000688 = 0x61000;
    syscall(__NR_pwritev2, r[3], 0x20000680ul, 1ul, 0, 0, 0ul);
    break;
  }
}
int main(void)
{
  syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
  syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul);
  syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
  use_temporary_dir();
  loop();
  return 0;
}