// https://syzkaller.appspot.com/bug?id=6414c846646a1d8631515cdd08ff46f03f4788b2
// 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 __thread int clone_ongoing;
static __thread int skip_segv;
static __thread jmp_buf segv_env;

static void segv_handler(int sig, siginfo_t* info, void* ctx)
{
  if (__atomic_load_n(&clone_ongoing, __ATOMIC_RELAXED) != 0) {
    exit(sig);
  }
  uintptr_t addr = (uintptr_t)info->si_addr;
  const uintptr_t prog_start = 1 << 20;
  const uintptr_t prog_end = 100 << 20;
  int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0;
  int valid = addr < prog_start || addr > prog_end;
  if (skip && valid) {
    _longjmp(segv_env, 1);
  }
  exit(sig);
}

static void install_segv_handler(void)
{
  struct sigaction sa;
  memset(&sa, 0, sizeof(sa));
  sa.sa_handler = SIG_IGN;
  syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
  syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
  memset(&sa, 0, sizeof(sa));
  sa.sa_sigaction = segv_handler;
  sa.sa_flags = SA_NODEFER | SA_SIGINFO;
  sigaction(SIGSEGV, &sa, NULL);
  sigaction(SIGBUS, &sa, NULL);
}

#define NONFAILING(...)                                                        \
  ({                                                                           \
    int ok = 1;                                                                \
    __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST);                       \
    if (_setjmp(segv_env) == 0) {                                              \
      __VA_ARGS__;                                                             \
    } else                                                                     \
      ok = 0;                                                                  \
    __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST);                       \
    ok;                                                                        \
  })

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 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) {
    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;
}

static void kill_and_wait(int pid, int* status)
{
  kill(-pid, SIGKILL);
  kill(pid, SIGKILL);
  for (int i = 0; i < 100; i++) {
    if (waitpid(-1, status, WNOHANG | __WALL) == pid)
      return;
    usleep(1000);
  }
  DIR* dir = opendir("/sys/fs/fuse/connections");
  if (dir) {
    for (;;) {
      struct dirent* ent = readdir(dir);
      if (!ent)
        break;
      if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
        continue;
      char abort[300];
      snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
               ent->d_name);
      int fd = open(abort, O_WRONLY);
      if (fd == -1) {
        continue;
      }
      if (write(fd, abort, 1) < 0) {
      }
      close(fd);
    }
    closedir(dir);
  } else {
  }
  while (waitpid(-1, status, __WALL) != pid) {
  }
}

static void reset_loop()
{
  char buf[64];
  snprintf(buf, sizeof(buf), "/dev/loop%llu", procid);
  int loopfd = open(buf, O_RDWR);
  if (loopfd != -1) {
    ioctl(loopfd, LOOP_CLR_FD, 0);
    close(loopfd);
  }
}

static void setup_test()
{
  prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  setpgrp();
  write_file("/proc/self/oom_score_adj", "1000");
}

static void setup_sysctl()
{
  char mypid[32];
  snprintf(mypid, sizeof(mypid), "%d", getpid());
  struct {
    const char* name;
    const char* data;
  } files[] = {
      {"/sys/kernel/debug/x86/nmi_longest_ns", "10000000000"},
      {"/proc/sys/kernel/hung_task_check_interval_secs", "20"},
      {"/proc/sys/net/core/bpf_jit_kallsyms", "1"},
      {"/proc/sys/net/core/bpf_jit_harden", "0"},
      {"/proc/sys/kernel/kptr_restrict", "0"},
      {"/proc/sys/kernel/softlockup_all_cpu_backtrace", "1"},
      {"/proc/sys/fs/mount-max", "100"},
      {"/proc/sys/vm/oom_dump_tasks", "0"},
      {"/proc/sys/debug/exception-trace", "0"},
      {"/proc/sys/kernel/printk", "7 4 1 3"},
      {"/proc/sys/kernel/keys/gc_delay", "1"},
      {"/proc/sys/vm/oom_kill_allocating_task", "1"},
      {"/proc/sys/kernel/ctrl-alt-del", "0"},
      {"/proc/sys/kernel/cad_pid", mypid},
  };
  for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) {
    if (!write_file(files[i].name, files[i].data))
      printf("write to %s failed: %s\n", files[i].name, strerror(errno));
  }
}

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);
      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++) {
    reset_loop();
    int pid = fork();
    if (pid < 0)
      exit(1);
    if (pid == 0) {
      setup_test();
      execute_one();
      exit(0);
    }
    int status = 0;
    uint64_t start = current_time_ms();
    for (;;) {
      if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
        break;
      sleep_ms(1);
      if (current_time_ms() - start < 5000)
        continue;
      kill_and_wait(pid, &status);
      break;
    }
  }
}

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

void execute_call(int call)
{
  intptr_t res = 0;
  switch (call) {
  case 0:
    NONFAILING(memcpy((void*)0x20000040, "ext4\000", 5));
    NONFAILING(memcpy((void*)0x200007c0, "./file0\000", 8));
    NONFAILING(memcpy(
        (void*)0x20000fc0,
        "\x78\x9c\xec\xdd\xcf\x6b\x5c\xd5\x1e\x00\xf0\xef\x9d\x64\x9a\xbe\xb4"
        "\xef\x25\x0f\x1e\x3c\xeb\x2a\x20\x68\xa0\x74\x62\x6a\x6c\x15\x5c\x44"
        "\x5c\x88\x60\xa1\xa0\x6b\xdb\x30\x99\x86\x9a\x49\xa6\x64\x26\xa5\x09"
        "\x41\x5b\x44\xe8\x46\x50\x71\x21\xe8\xa6\x6b\x7f\xb4\x3b\xb7\xfe\xd8"
        "\xea\x7f\xe1\x42\x5a\xaa\xa6\xc5\x8a\x0b\x89\xdc\xc9\x4c\x33\x6d\x66"
        "\x92\x49\x9a\x64\xa2\xf3\xf9\xc0\x6d\xcf\xb9\x73\xee\x9c\xf3\xbd\xe7"
        "\xfe\x38\x99\x73\x99\x09\xa0\x6b\x0d\xa5\xff\x64\x22\x8e\x44\xc4\xfb"
        "\x49\xc4\x40\x6d\x7d\x12\x11\xd9\x6a\xaa\x37\x62\x7c\xb5\xdc\xbd\xe5"
        "\xa5\x7c\xba\x24\xb1\xb2\xf2\xda\x2f\x49\xb5\xcc\xdd\xe5\xa5\x7c\x34"
        "\x6c\x93\x3a\x54\xcb\x3c\x16\x11\xdf\xbe\x1b\x71\x34\xb3\xbe\xde\xf2"
        "\xc2\xe2\xf4\x44\xb1\x58\x98\xab\xe5\x47\x2a\x33\x17\x46\xca\x0b\x8b"
        "\xc7\xce\xcf\x4c\x4c\x15\xa6\x0a\xb3\x27\x46\xc7\xc6\x8e\x9f\x7c\xf6"
        "\xe4\x89\x9d\x8b\xf5\xb7\x1f\x16\x0f\xdf\xfa\xe0\xe5\xa7\xbe\x1c\xff"
        "\xe3\x9d\xff\x5f\x7f\xef\xbb\x24\xc6\xe3\x70\xed\xb5\xc6\x38\x76\xca"
        "\x50\x0c\xd5\xf6\x49\x36\xdd\x85\x0f\x78\x69\xa7\x2b\xeb\xb0\xa4\xd3"
        "\x0d\x60\x5b\xd2\x53\xb3\x67\xf5\x2c\x8f\x23\x31\x10\x3d\xd5\x14\x00"
        "\xf0\x4f\xf6\x76\x44\xac\x6c\x55\x76\xeb\x9b\x00\x00\xfb\x49\xe2\x66"
        "\x0e\x00\x5d\xa6\xfe\x39\xc0\xdd\xe5\xa5\x7c\x7d\xe9\xec\x27\x12\x7b"
        "\xeb\xf6\x8b\x11\x71\x70\x35\xfe\xfa\xfc\xe6\xea\x6c\x48\x6f\x6d\xce"
        "\xee\x60\x75\x1e\xb4\xff\x6e\xf2\xc0\xcc\x48\x12\x11\x83\x3b\x50\xff"
        "\x50\x44\x7c\xfa\xd5\x1b\x9f\xa7\x4b\xec\xd2\x3c\x24\x40\x33\x97\xaf"
        "\x44\xc4\xd9\xc1\xa1\xf5\xd7\xff\x64\xdd\x33\x0b\x5b\xf5\x74\x1b\x65"
        "\x86\x1e\xca\xbb\xfe\xc1\xde\xf9\x3a\x1d\xff\x3c\xd7\x6c\xfc\x97\xb9"
        "\x3f\xfe\x89\x26\xe3\x9f\xbe\x26\xe7\xee\x76\x6c\x7e\xfe\x67\x6e\xee"
        "\x40\x35\x2d\xa5\xe3\xbf\x17\x1a\x9e\x6d\xbb\xd7\x10\x7f\xcd\x60\x4f"
        "\x2d\xf7\xef\xea\x98\x2f\x9b\x9c\x3b\x5f\x2c\xa4\xd7\xb6\xff\x44\xc4"
        "\x70\x64\xfb\xd2\xfc\xe8\x06\x75\x0c\xdf\xf9\xf3\x4e\xab\xd7\x1a\xc7"
        "\x7f\xbf\x7e\xf8\xe6\x67\x69\xfd\xe9\xff\x6b\x25\x32\x37\x7b\xfb\x1e"
        "\xdc\x66\x72\xa2\x32\xf1\x28\x31\x37\xba\x7d\x25\xe2\xf1\xde\x66\xf1"
        "\x27\xf7\xfb\x3f\x69\x31\xfe\x3d\xdd\x66\x1d\xaf\x3c\x7f\xf5\x93\x56"
        "\xaf\xa5\xf1\xa7\xf1\xd6\x97\xf5\xf1\xef\xae\x95\x6b\x11\x4f\x36\xed"
        "\xff\xb5\x27\xda\x92\x0d\x9f\x4f\x1c\xa9\x1e\x0e\x23\xf5\x83\xa2\x89"
        "\x1b\x3f\x7e\xdc\xdf\xaa\xfe\xc6\xfe\x4f\x97\xb4\xfe\xfa\xdf\x02\x8d"
        "\xb2\x3b\x12\xed\x7a\x69\xff\xf7\x6f\x1c\xff\x60\xb2\xf6\xbc\xe6\xd5"
        "\xb9\x72\xbb\xef\xfc\xd6\x8d\x7a\xea\xfb\x6b\x03\xdf\xb4\x2a\xb5\x79"
        "\xfc\xcd\x8f\xff\x03\xc9\xeb\xd5\xf4\x81\xda\xba\x4b\x13\x95\xca\xdc"
        "\x68\xc4\x81\xe4\xd5\xf5\xeb\x8f\xaf\x6d\x5b\xcf\xd7\xcb\xa7\xf1\x0f"
        "\x3f\xd1\xfc\xfc\xdf\xe8\xf8\x4f\xfb\xe3\x6c\x9b\x7b\xa2\xf7\xd6\xcf"
        "\x5f\x6c\x3f\xfe\xdd\x95\xc6\x3f\xd9\x7e\xff\x17\xe6\xb6\x91\xb8\x7e"
        "\x6f\xba\xa7\x55\xfd\xed\xf5\xff\x58\x35\x35\x5c\x5b\xd3\xce\xf5\xaf"
        "\xdd\x06\x3e\xca\xbe\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x80\x76\x65\x22\xe2\x70\x24\x99\xdc\xfd"
        "\x74\x26\x93\xcb\xad\xfe\x86\xf7\xff\xa2\x3f\x53\x2c\x95\x2b\x47\xcf"
        "\x95\xe6\x67\x27\xa3\xfa\x5b\xd9\x83\x91\xcd\xd4\xbf\xea\x72\xa0\xe1"
        "\xfb\x50\x47\x6b\xdf\x87\x5f\xcf\x1f\x7f\x28\xff\x4c\x44\xfc\x37\x22"
        "\x3e\xea\xfb\x57\x35\x9f\xcb\x97\x8a\x93\x9d\x0e\x1e\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x6a\x0e\xb5\xf8\xfd\xff\xd4"
        "\x4f\x7d\x9d\x6e\x1d\x00\xb0\x6b\x0e\x76\xba\x01\x00\xc0\x9e\x73\xff"
        "\x07\x80\xee\xe3\xfe\x0f\x00\xdd\xc7\xfd\x1f\x00\xba\x8f\xfb\x3f\x00"
        "\x74\x1f\xf7\x7f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x76\xd9\xe9\x53\xa7\xd2\x65\xe5\xf7\xe5\xa5\x7c\x9a"
        "\x9f\xbc\xb8\x30\x3f\x5d\xba\x78\x6c\xb2\x50\x9e\xce\xcd\xcc\xe7\x73"
        "\xf9\xd2\xdc\x85\xdc\x54\xa9\x34\x55\x2c\xe4\xf2\xa5\x99\xcd\xde\xaf"
        "\x58\x2a\x5d\x18\x8b\xd9\xf9\x4b\x23\x95\x42\xb9\x32\x52\x5e\x58\x3c"
        "\x33\x53\x9a\x9f\xad\x9c\x39\x3f\x33\x31\x55\x38\x53\xc8\xee\x49\x54"
        "\x00\x00\x00\x00\x00\x00\x00\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\x35\xe5"
        "\x85\xc5\xe9\x89\x62\xb1\x30\xb7\x9f\x12\xb5\xb6\x5d\xde\x2f\xed\xe9"
        "\xde\x44\xc4\xe6\x65\xc6\xf7\x47\x53\xf7\x7d\x22\x89\x88\x7d\xd0\x8c"
        "\x76\x13\x1d\xbe\x30\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\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfc\x4d\xfc\x15\x00\x00"
        "\xff\xff\x64\x70\x23\xe8",
        1927));
    NONFAILING(syz_mount_image(0x20000040, 0x200007c0, 0, 0x20000800, 0x24,
                               0x787, 0x20000fc0));
    break;
  case 1:
    NONFAILING(memcpy((void*)0x20000040, "./bus\000", 6));
    res = syscall(__NR_creat, 0x20000040ul, 0ul);
    if (res != -1)
      r[0] = res;
    break;
  case 2:
    NONFAILING(memcpy((void*)0x20001100, "/dev/zero\000", 10));
    res = syscall(__NR_openat, 0xffffffffffffff9cul, 0x20001100ul, 0ul, 0ul);
    if (res != -1)
      r[1] = res;
    break;
  case 3:
    NONFAILING(memcpy((void*)0x20000000, "./file0\000", 8));
    NONFAILING(memcpy((void*)0x20000080, "9p\000", 3));
    NONFAILING(memcpy((void*)0x200000c0, "trans=fd,", 9));
    NONFAILING(memcpy((void*)0x200000c9, "rfdno", 5));
    NONFAILING(*(uint8_t*)0x200000ce = 0x3d);
    NONFAILING(sprintf((char*)0x200000cf, "0x%016llx", (long long)r[1]));
    NONFAILING(*(uint8_t*)0x200000e1 = 0x2c);
    NONFAILING(memcpy((void*)0x200000e2, "wfdno", 5));
    NONFAILING(*(uint8_t*)0x200000e7 = 0x3d);
    NONFAILING(sprintf((char*)0x200000e8, "0x%016llx", (long long)r[0]));
    NONFAILING(*(uint8_t*)0x200000fa = 0x2c);
    NONFAILING(memcpy((void*)0x200000fb, "nodevmap", 8));
    NONFAILING(*(uint8_t*)0x20000103 = 0x2c);
    NONFAILING(memcpy((void*)0x20000104, "fscache", 7));
    NONFAILING(*(uint8_t*)0x2000010b = 0x2c);
    NONFAILING(memcpy((void*)0x2000010c, "version=9p2000.L", 16));
    NONFAILING(*(uint8_t*)0x2000011c = 0x2c);
    NONFAILING(memcpy((void*)0x2000011d, "afid", 4));
    NONFAILING(*(uint8_t*)0x20000121 = 0x3d);
    NONFAILING(sprintf((char*)0x20000122, "0x%016llx", (long long)0x100));
    NONFAILING(*(uint8_t*)0x20000134 = 0x2c);
    NONFAILING(memcpy((void*)0x20000135, "afid", 4));
    NONFAILING(*(uint8_t*)0x20000139 = 0x3d);
    NONFAILING(sprintf((char*)0x2000013a, "0x%016llx", (long long)0x6f2a80c8));
    NONFAILING(*(uint8_t*)0x2000014c = 0x2c);
    NONFAILING(memcpy((void*)0x2000014d, "aname", 5));
    NONFAILING(*(uint8_t*)0x20000152 = 0x3d);
    NONFAILING(memcpy((void*)0x20000153, "ext4\000", 5));
    NONFAILING(*(uint8_t*)0x20000158 = 0x2c);
    NONFAILING(memcpy((void*)0x20000159, "mmap", 4));
    NONFAILING(*(uint8_t*)0x2000015d = 0x2c);
    NONFAILING(memcpy((void*)0x2000015e, "dont_measure", 12));
    NONFAILING(*(uint8_t*)0x2000016a = 0x2c);
    NONFAILING(memcpy((void*)0x2000016b, "audit", 5));
    NONFAILING(*(uint8_t*)0x20000170 = 0x2c);
    NONFAILING(*(uint8_t*)0x20000171 = 0);
    syscall(__NR_mount, 0ul, 0x20000000ul, 0x20000080ul, 0x2004012ul,
            0x200000c0ul);
    break;
  case 4:
    NONFAILING(memcpy((void*)0x20000380, "/dev/loop", 9));
    NONFAILING(*(uint8_t*)0x20000389 = 0x30);
    NONFAILING(*(uint8_t*)0x2000038a = 0);
    NONFAILING(memcpy((void*)0x200003c0, "./bus\000", 6));
    syscall(__NR_mount, 0x20000380ul, 0x200003c0ul, 0ul, 0x1000ul, 0ul);
    break;
  case 5:
    NONFAILING(memcpy((void*)0x20004400, "./bus\000", 6));
    res = syscall(__NR_openat, 0xffffff9c, 0x20004400ul, 0x1c1002ul, 0ul);
    if (res != -1)
      r[2] = res;
    break;
  case 6:
    NONFAILING(memcpy(
        (void*)0x20001780,
        "\xdd\xc8\xe4\xec\xc3\x37\x3a\x4d\x97\x06\xd8\xc2\x43\x38\xe9\x3e\x9e"
        "\xdf\x88\x45\xe4\x54\xf3\x20\xc2\x70\xeb\x5c\x88\xfc\x75\xee\xbe\xb8"
        "\xa2\x54\x40\x91\x8f\xc4\x65\x13\x23\x29\xd7\x2b\x11\x62\xd5\x58\x3d"
        "\x59\x03\x19\x37\x54\x14\xe6\x90\x0e\x9b\x30\x4d\x16\x7d\x7a\x7b\xc9"
        "\x3c\x12\x21\x40\x24\x48\xf0\x3c\xfc\xf8\xdf\x96\xb7\x71\x7e\x00\xb6"
        "\x44\x8c\x5c\xf3\xf7\xac\xd4\xcf\xf2\xdf\xc5\x27\xe9\x14\xaa\x04\xf6"
        "\xa9\x07\x94\xf3\x31\xed\x57\xa0\x31\x54\xaa\xf8\xd0\x02\x70\xfb\x66"
        "\x32\xe7\x06\x52\x9b\xe3\xf7\x4c\x20\x5e\x9a\xbf\x12\xe4\x35\xaa\xc3"
        "\xfe\x28\x3d\xb5\xc0\x2a\xf2\x63\x3c\x03\x18\x73\xe5\xa6\xd7\x5e\x6c"
        "\xc0\x99\x28\x4c\x2d\x38\x5b\x5d\xea\xfe\xbd\xf1\x9a\xe2\x84\x48\xe1"
        "\x45\x1e\xe9\x10\x80\x29\x27\x93\xae\x62\x93\x0d\xcd\x47\x80\x59\x29"
        "\x92\x9c\xca\x7d\x24\x39\x0b\x37\xb6\x20\x87\x05\x3c\x9a\x99\xa4\x84"
        "\xf0\xa2\x98\x90\x71\xf3\x84\xba\x72\xfc\xb5\xf3\x53\x6b\x09\x96\x4e"
        "\x0c\xad\x59\x95\x89\x1d\xb8\xb8\x71\x24\xe8\xd5\x68\x2e\x03\xdd\x6b"
        "\x1a\xbc\x92\x24\x0c\x8b\x11\xbe\x16\x95\x8a\x20\xec\xb6\xfa\xa6\xe0"
        "\xd3\x6b\xf4\xfb\xe1\x90\x44\xc7\xcf\x4f\x55\xae\xfa\x65\xf1\x33\xbc"
        "\xc9\xad\xc8\xc0\x64\x12\x1c\x87\x92\x6a\xd3\x21\xbf\x01\xb9\x2e\xe7"
        "\x48\xe2\x18\x63\x63\xc4\xeb\xa3\xe1\x6b\x10\x12\x5f\xf3\x3d\xe5\x8b"
        "\x4d\xa7\x0a\x79\xcb\x16\x8a\x16\xac\xe1\xfd\x8e\x89\xaf\x91\xed\x71"
        "\xe5\x1a\xa8\xdf\x4a\x38\x55\xa8\x7a\xe8\x43\xd8\x43\x1d\xd3\xf4\x92"
        "\x49\x6d\x40\x5c\x26\xc9\xd0\x40\xf9\xbe\xa8\xd9\x07\x46\xc4\x2e\x02"
        "\x87\x20\xcf\xef\xe0\xe9\x18\xc0\xeb\x46\xf7\x22\x26\xd1\xfe\xa6\xb6"
        "\x79\x07\x41\x4d\x89\x78\x95\x2f\x28\x65\xce\x93\x27\xa0\x36\x2b\xcc"
        "\xc7\xb5\xc8\x13\xc1\x74\x30\x6a\x13\x7c\xb7\xe5\xa4\x73\x7c\x06\xf6"
        "\xb9\xfc\xc6\x3d\xd9\x78\xa1\x6e\x06\xb2\x51\x3c\x21\xe1\xe4\xc1\x3b"
        "\x8c\xf4\x08\x1a\xda\xfb\x77\x90\x2e\xc0\xf9\xcc\x30\x5b\x0c\x0e\x65"
        "\x33\x1b\x98\x4c\x0b\x08\xd2\x42\x3f\x36\x64\x78\x12\x00\xf2\x3a\xb6"
        "\xbd\x76\x81\x8b\x10\x02\xce\xf2\xdf\xe4\xfa\x4d\x5a\xd8\x7d\x37\x42"
        "\xb7\xc6\x06\x47\x2c\x74\xaf\x4c\xbc\xa4\x7e\x78\xe3\xce\xb9\x57\x19"
        "\x5f\xc7\x36\xf1\x45\x5b\x40\x30\x0c\x21\x4d\x1f\xaa\x3b\x8b\x76\x60"
        "\xed\x59\x69\xe3\x25\x2d\x0c\x34\x5c\x9d\x25\xb3\x14\x4c\xba\xd5\x37"
        "\x04\x6f\xe0\xdd\xdf\xc0\x85\x47\x57\x9c\xca\x76\x9e\x86\x85\x45\xce"
        "\xfd\xc9\x92\x60\xee\x39\x12\xfa\x65\xfe\x2e\x0f\xc0\x78\xe3\x12\xd6"
        "\x52\xbe\x83\xa2\x49\x22\x95\xc2\xe5\x55\x44\xe0\x6f\xfc\xd2\xe9\xb1"
        "\x8f\x22\xb3\x7c\xaf\x6f\xf9\x84\xc5\xa5\xda\x4f\x21\xb6\x0c\x02\xc0"
        "\xb8\xca\x84\xba\xd7\x62\xfe\x8c\x14\x78\xe3\xfd\x46\xb9\x8f\x8c\xa9"
        "\x83\xf6\xa8\xe3\x40\xdb\x3d\x72\x15\x36\xd9\x05\xb0\xb5\x17\x1d\x99"
        "\x70\xae\x56\x37\x4c\x8b\x4e\x6b\x0f\xa1\x89\x16\x5f\x7f\xd5\x18\xde"
        "\x0b\x8e\xed\xd1\x5b\x24\xa9\xe2\x45\xa5\xe0\x49\x5d\x63\xb2\x57\x6c"
        "\xf0\x10\xa5\x05\x0f\xb9\x54\xc7\x22\x85\xfa\xb8\x9c\x93\xff\xd9\xf9"
        "\xee\x65\xd0\x95\x30\xb8\x3e\xc8\x57\x1a\x5c\x56\x33\xca\xe9\x79\xb5"
        "\x6d\x7a\x4b\xa9\x4c\x2e\xa5\x6f\x61\x30\x31\xf4\x32\x62\x42\x13\x60"
        "\x01\x16\x13\xe5\x6c\x6a\xa3\x91\x54\x23\x6c\x0e\x3b\x11\x29\x30\xf0"
        "\x76\xe7\x69\xe5\xc7\x13\x1a\x42\xd8\x85\xbc\x58\xb9\x1b\x72\xa5\x84"
        "\x6f\xf0\x21\x63\x32\x2b\x31\xa0\xe6\x9e\x28\xc7\x5a\x29\xed\xa3\x67"
        "\x9a\x89\xee\xc9\xa0\xa7\xef\x4e\xfe\x53\xa2\xa7\x48\x3d\xd7\x56\xf4"
        "\x85\x26\x64\xa0\x9a\x45\xb4\x12\x71\xf7\x36\xc9\x37\x04\xee\x52\x65"
        "\xa9\xf8\xf4\x9b\x4f\xdc\x75\x79\x9a\xc3\xa5\x61\xc5\xab\x34\xde\xda"
        "\x58\x1a\x81\x4b\xd1\x12\x22\xe7\x62\x94\x01\x0b\x7b\xdb\x35\x75\x36"
        "\xe2\xde\xcf\x42\xb9\xdf\xad\xb6\xae\x9c\x50\xea\xc0\x42\x67\xc7\xe4"
        "\x93\x20\x67\x7b\x4c\xfe\xc4\xa7\x7e\x2a\x96\x0e\x0c\xeb\x63\xd4\xc3"
        "\x25\xcb\xe7\x0c\x4c\x41\x36\x20\x4b\x16\x32\x12\xe4\x8e\x9b\xa8\xef"
        "\x0d\x48\xe2\x4b\xc4\xab\xeb\x4f\xd2\x08\x74\xbf\x91\xfd\x5c\x21\x97"
        "\x64\x87\x39\x6d\xe3\x2d\x89\xdc\xf5\xbe\x32\x76\x87\x45\x9a\x7d\xf7"
        "\x28\x43\xe4\x87\x4c\x44\x68\x81\x26\x63\x79\xd4\xdc\xa7\xd1\xf2\xb4"
        "\x92\xba\xe1\xe5\xfe\xce\x62\x2d\xce\x69\x49\x29\xba\x23\xb4\xce\xc8"
        "\xda\xd8\x7e\x91\x80\x76\xb0\x51\x8b\x35\x23\x5e\x41\x24\xee\x12\xdb"
        "\x2c\xad\x78\x8a\x5c\x09\x50\xcb\x41\x5f\xd7\xe7\x6d\x39\xa4\x8f\x9c"
        "\xd9\x96\x45\x3b\x4b\x3a\xfe\xca\x31\x8a\x4f\x38\xd6\xf1\xda\x3c\xf1"
        "\x65\xa7\x52\x7c\x61\x7f\xf9\xbf\xb5\x54\x8b\xb3\x11\xb5\xe1\xb0\x7e"
        "\xfc\x10\x5e\x27\x16\x84\x67\x60\x64\x54\x4e\x31\x07\x7d\x62\x11\x19"
        "\x1c\x8a\x99\x74\x1f\xa9\x0a\x61\x07\xda\x64\xd6\x23\x61\xfc\x57\x68"
        "\xa3\xd7\xfe\xbe\xc7\x13\x63\x32\xed\x87\xae\x86\x7a\x63\x67\x78\xea"
        "\xd3\x7f\x49\x29\xd0\x52\x17\xfb\xe7\x18\x8c\xb1\x7c\x0b\x4e\x07\x67"
        "\x3d\xef\x50\x8b\x06\xb6\x1c\xeb\x1b\x6b\x42\x11\x26\xbb\x92\x23\x0f"
        "\xdc\x63\x07\xfe\x58\xf1\x3a\x12\x01\x69\xb7\x72\xd1\x79\x0f\x0a\x63"
        "\x36\xb1\xd8\x1a\xab\x4b\xed\x11\x9f\x54\xc4\x18\x71\xb1\xd9\xf4\x39"
        "\xff\xce\x12\x7c\xcc\x40\xb3\x83\xab\x12\x3e\xa8\x17\xb8\xd4\xa6\xd0"
        "\x5c\x00\x0f\xae\x21\xfc\x96\x29\x1f\x42\x48\x49\xf3\xbb\xac\xc7\xb5"
        "\x1b\x4a\x12\x4f\x81\xff\x6b\xba\xfa\x49\x1f\xc3\x28\x0e\xf8\xd8\xc8"
        "\xa8\xe3\x05\xaa\xf8\x16\x2c\x66\x22\xc7\xa9\x2c\x27\x93\x8a\x37\x33"
        "\x66\x39\x8d\xa6\x2c\x8b\xca\x17\x90\x46\xf6\x5e\xe2\xcb\xa9\xe6\x5e"
        "\xf5\xf3\xad\xb0\xcb\x98\x0e\xa4\x17\x4a\x93\xc7\x5a\x7c\x60\x06\xa2"
        "\x53\xbc\xae\xef\x7a\x26\x5f\x67\x7a\x18\x88\x2c\xe6\x1f\xb0\x4b\x17"
        "\x78\xb6\xf2\xfc\x27\x75\xeb\xc1\x82\x79\x8b\xe1\x2b\x84\x5c\x2e\xe4"
        "\xe2\xbb\x28\xe6\x96\xdf\x4c\xab\xb9\x6e\x75\x02\x5c\x37\x95\x53\xb4"
        "\x2e\x85\xa1\x77\x86\x76\xe0\x37\x3a\xd9\xb5\x42\x72\xda\x9a\x1c\x6c"
        "\x45\x16\xd1\xce\x9a\xdb\x53\xac\x08\x81\x7a\x4d\xbb\x8e\xa6\x82\xec"
        "\x1d\xc2\x08\xf1\x77\xbb\x8f\xcb\x9f\xe9\xbd\xc7\x43\x0d\xf9\xd9\x3c"
        "\x93\x22\x63\x6f\x17\x6b\x41\x76\x82\xba\xc3\x59\x3c\xa2\xe3\xeb\xc5"
        "\xbd\x7f\x57\x09\xad\x15\xae\x36\x80\xa7\x4e\xdc\x17\x18\xe5\x2f\xa3"
        "\xc0\x53\xb6\xf5\x31\xdb\xc7\x63\x82\x72\x0d\x30\x05\xae\x47\x95\xc8"
        "\x90\x07\x36\xfe\x7e\x4c\xe6\x32\xc6\xb2\xc6\xbb\x4f\x3b\xe8\xde\xe3"
        "\x8b\x64\x77\x0a\x70\x4d\x90\x90\xf8\x24\xac\x02\x4e\x78\x7e\x80\xdb"
        "\xaf\x37\x58\x2a\x2f\x6c\xce\xa9\x4c\x07\xa5\xdc\x4b\xff\x36\x88\xfc"
        "\x2b\x52\x2d\xf0\x1f\xc3\xb8\x4a\x68\xb0\xf8\xbb\x13\x13\xce\x3b\x40"
        "\x90\x8c\x76\x25\x11\x73\x63\x2b\x2b\xca\x46\xd3\xc3\x35\xa0\x75\x9a"
        "\x07\x29\x5f\x58\x8d\x38\xd8\x0c\x4d\xb1\x91\x0d\x90\xf5\xb0\x38\x82"
        "\x07\xe5\x00\xf5\x93\x16\x5d\xba\x8f\x67\x1d\x9c\x3b\x1a\x0d\x5e\x63"
        "\xc4\xea\x21\x36\x29\xe8\x0a\x8d\xf0\x56\x0d\x47\x5e\x5c\xa7\xf5\xe6"
        "\x94\x6f\xdf\x36\xe0\xae\xc2\x2f\x29\x03\x9f\xef\x5b\x00\x60\x03\xff"
        "\xd6\x96\x4d\xe2\xc8\x7c\xde\x1b\x0d\xe6\x3d\xde\x4c\x86\xf2\xb8\x07"
        "\x83\xf7\x5f\x79\xf6\x17\xf7\x57\xe7\x8c\x64\xea\x65\xb0\x1b\xbe\x0b"
        "\x7e\x21\x42\x7e\x47\x25\x38\x5d\xfd\xd4\xc3\xda\x25\xa2\xfc\xe0\x26"
        "\x7b\xba\x9b\x9f\x37\xb3\x06\xca\xc9\x6a\x1b\x48\x17\x7c\xe4\xea\xb3"
        "\x79\x84\x87\x0a\xc1\x94\xcd\xc1\x70\x42\x6f\x18\xe4\xef\xb4\x99\xcc"
        "\x75\x3b\x7b\x68\x67\xd5\x2b\x32\x9e\xd2\x2a\x19\x3d\x7b\x6c\x34\x61"
        "\xab\x3e\xb5\xc7\x0e\x4e\x65\x60\xd7\xa1\x1c\x18\x91\x0d\x88\xab\x6b"
        "\xec\xf2\x03\x8e\x67\x22\x23\xe5\xf0\x8e\xc5\x29\xed\x3c\xc2\x97\x65"
        "\x5d\xee\xcc\xef\xf5\x44\xe7\xda\xb9\xc9\x77\xc4\xfd\x35\x91\x0a\x31"
        "\x57\xbb\x86\x5f\x91\x6d\x5c\x1e\x34\x52\xbd\xc2\xc8\x67\x6b\x79\x99"
        "\x23\xe6\xe4\x51\xff\xfb\x27\xc0\x48\xc0\xa2\x33\xce\xc5\xeb\xe8\xe6"
        "\x8c\x7d\x9e\x16\x7a\xd5\x8c\xd4\xdc\x05\xbe\x7f\xd3\x91\x48\x1c\x42"
        "\xdb\xbb\xac\x0a\x6a\xcc\xe0\xef\xc4\x21\x57\x62\x69\x91\x04\x5e\x59"
        "\x7e\x9e\x0e\x1f\x38\xdb\x60\x51\x75\x3c\x2e\xd3\xb7\x86\x2c\x5d\xdf"
        "\x62\x2f\xa5\x1c\x80\x49\x88\x32\x9b\xe9\x2f\xd6\xef\x42\x62\x51\xee"
        "\xfd\xc1\xd6\x01\xfe\x89\xda\xe9\xc3\xb3\x3b\xd2\x56\x95\x8d\x06\x2f"
        "\x8b\xa0\xad\xde\x29\xbe\xda\xc0\xe7\xb6\xcd\x9b\xd4\x3f\x33\xa3\x84"
        "\xa0\x92\x9b\x77\xc4\x89\xdf\x52\xd3\x48\x92\x07\x3d\x21\x5f\x0b\x39"
        "\x31\xde\x88\xbc\x97\xcf\x51\x1e\x7c\xad\x1f\xda\x52\xdb\x95\xf8\x07"
        "\x9c\x67\x7b\x1e\x18\xc2\x95\x31\x4e\x25\x98\xff\x2a\xd2\xa4\xcb\x81"
        "\x92\xc6\x30\x41\x78\x37\x96\x29\xf8\x06\x95\x24\x46\x6a\x90\x2b\x1f"
        "\x43\x56\x73\xb6\x41\x1c\x17\x9e\x0c\x38\xef\x96\x5f\x54\x4c\x3a\xcf"
        "\x3c\xfe\xea\xbe\x49\x89\x9b\x21\xef\x08\x36\x54\x16\x7a\x23\x27\x7c"
        "\xbe\xa3\x78\x24\xea\x66\xf2\xea\x67\x02\xbd\x0f\xa0\x31\xaf\xd1\x9f"
        "\x65\x4f\xa9\xb8\x9d\x23\x7c\x9c\xb4\x3c\x81\x7c\x8d\x9a\xb8\x46\x05"
        "\xf2\x06\x07\xdf\x4a\x73\x36\x1a\x82\x60\x82\x1b\x1d\x60\xaa\x75\xea"
        "\x49\x66\xc4\x0d\x2b\x2d\x07\x90\x56\x6a\xc4\xd5\xfc\xe9\x67\x33\x72"
        "\xaf\x65\xc9\x40\x91\xdb\x10\xc5\xe4\xa2\x0b\x38\x08\x53\x8c\xa9\x6b"
        "\x4b\xa5\x2e\x17\xce\x2f\x68\x43\xa2\x32\x12\xa0\xe9\x2f\x8e\xc6\x4c"
        "\x47\x5a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
        2057));
    syscall(__NR_write, r[2], 0x20001780ul, 0x809ul);
    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);
  setup_sysctl();
  install_segv_handler();
  loop();
  return 0;
}