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

#define _GNU_SOURCE

#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.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/mount.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

#include <linux/loop.h>
#include <linux/usb/ch9.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 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;
}

#define MAX_FDS 30

#define USB_MAX_IFACE_NUM 4
#define USB_MAX_EP_NUM 32
#define USB_MAX_FDS 6

struct usb_endpoint_index {
  struct usb_endpoint_descriptor desc;
  int handle;
};

struct usb_iface_index {
  struct usb_interface_descriptor* iface;
  uint8_t bInterfaceNumber;
  uint8_t bAlternateSetting;
  uint8_t bInterfaceClass;
  struct usb_endpoint_index eps[USB_MAX_EP_NUM];
  int eps_num;
};

struct usb_device_index {
  struct usb_device_descriptor* dev;
  struct usb_config_descriptor* config;
  uint8_t bDeviceClass;
  uint8_t bMaxPower;
  int config_length;
  struct usb_iface_index ifaces[USB_MAX_IFACE_NUM];
  int ifaces_num;
  int iface_cur;
};

struct usb_info {
  int fd;
  struct usb_device_index index;
};

static struct usb_info usb_devices[USB_MAX_FDS];
static int usb_devices_num;

static bool parse_usb_descriptor(const char* buffer, size_t length,
                                 struct usb_device_index* index)
{
  if (length < sizeof(*index->dev) + sizeof(*index->config))
    return false;
  memset(index, 0, sizeof(*index));
  index->dev = (struct usb_device_descriptor*)buffer;
  index->config = (struct usb_config_descriptor*)(buffer + sizeof(*index->dev));
  index->bDeviceClass = index->dev->bDeviceClass;
  index->bMaxPower = index->config->bMaxPower;
  index->config_length = length - sizeof(*index->dev);
  index->iface_cur = -1;
  size_t offset = 0;
  while (true) {
    if (offset + 1 >= length)
      break;
    uint8_t desc_length = buffer[offset];
    uint8_t desc_type = buffer[offset + 1];
    if (desc_length <= 2)
      break;
    if (offset + desc_length > length)
      break;
    if (desc_type == USB_DT_INTERFACE &&
        index->ifaces_num < USB_MAX_IFACE_NUM) {
      struct usb_interface_descriptor* iface =
          (struct usb_interface_descriptor*)(buffer + offset);
      index->ifaces[index->ifaces_num].iface = iface;
      index->ifaces[index->ifaces_num].bInterfaceNumber =
          iface->bInterfaceNumber;
      index->ifaces[index->ifaces_num].bAlternateSetting =
          iface->bAlternateSetting;
      index->ifaces[index->ifaces_num].bInterfaceClass = iface->bInterfaceClass;
      index->ifaces_num++;
    }
    if (desc_type == USB_DT_ENDPOINT && index->ifaces_num > 0) {
      struct usb_iface_index* iface = &index->ifaces[index->ifaces_num - 1];
      if (iface->eps_num < USB_MAX_EP_NUM) {
        memcpy(&iface->eps[iface->eps_num].desc, buffer + offset,
               sizeof(iface->eps[iface->eps_num].desc));
        iface->eps_num++;
      }
    }
    offset += desc_length;
  }
  return true;
}

static struct usb_device_index* add_usb_index(int fd, const char* dev,
                                              size_t dev_len)
{
  int i = __atomic_fetch_add(&usb_devices_num, 1, __ATOMIC_RELAXED);
  if (i >= USB_MAX_FDS)
    return NULL;
  if (!parse_usb_descriptor(dev, dev_len, &usb_devices[i].index))
    return NULL;
  __atomic_store_n(&usb_devices[i].fd, fd, __ATOMIC_RELEASE);
  return &usb_devices[i].index;
}

static struct usb_device_index* lookup_usb_index(int fd)
{
  for (int i = 0; i < USB_MAX_FDS; i++) {
    if (__atomic_load_n(&usb_devices[i].fd, __ATOMIC_ACQUIRE) == fd)
      return &usb_devices[i].index;
  }
  return NULL;
}

struct vusb_connect_string_descriptor {
  uint32_t len;
  char* str;
} __attribute__((packed));

struct vusb_connect_descriptors {
  uint32_t qual_len;
  char* qual;
  uint32_t bos_len;
  char* bos;
  uint32_t strs_len;
  struct vusb_connect_string_descriptor strs[0];
} __attribute__((packed));

static const char default_string[] = {8, USB_DT_STRING, 's', 0, 'y', 0, 'z', 0};

static const char default_lang_id[] = {4, USB_DT_STRING, 0x09, 0x04};

static bool
lookup_connect_response_in(int fd, const struct vusb_connect_descriptors* descs,
                           const struct usb_ctrlrequest* ctrl,
                           struct usb_qualifier_descriptor* qual,
                           char** response_data, uint32_t* response_length)
{
  struct usb_device_index* index = lookup_usb_index(fd);
  uint8_t str_idx;
  if (!index)
    return false;
  switch (ctrl->bRequestType & USB_TYPE_MASK) {
  case USB_TYPE_STANDARD:
    switch (ctrl->bRequest) {
    case USB_REQ_GET_DESCRIPTOR:
      switch (ctrl->wValue >> 8) {
      case USB_DT_DEVICE:
        *response_data = (char*)index->dev;
        *response_length = sizeof(*index->dev);
        return true;
      case USB_DT_CONFIG:
        *response_data = (char*)index->config;
        *response_length = index->config_length;
        return true;
      case USB_DT_STRING:
        str_idx = (uint8_t)ctrl->wValue;
        if (descs && str_idx < descs->strs_len) {
          *response_data = descs->strs[str_idx].str;
          *response_length = descs->strs[str_idx].len;
          return true;
        }
        if (str_idx == 0) {
          *response_data = (char*)&default_lang_id[0];
          *response_length = default_lang_id[0];
          return true;
        }
        *response_data = (char*)&default_string[0];
        *response_length = default_string[0];
        return true;
      case USB_DT_BOS:
        *response_data = descs->bos;
        *response_length = descs->bos_len;
        return true;
      case USB_DT_DEVICE_QUALIFIER:
        if (!descs->qual) {
          qual->bLength = sizeof(*qual);
          qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER;
          qual->bcdUSB = index->dev->bcdUSB;
          qual->bDeviceClass = index->dev->bDeviceClass;
          qual->bDeviceSubClass = index->dev->bDeviceSubClass;
          qual->bDeviceProtocol = index->dev->bDeviceProtocol;
          qual->bMaxPacketSize0 = index->dev->bMaxPacketSize0;
          qual->bNumConfigurations = index->dev->bNumConfigurations;
          qual->bRESERVED = 0;
          *response_data = (char*)qual;
          *response_length = sizeof(*qual);
          return true;
        }
        *response_data = descs->qual;
        *response_length = descs->qual_len;
        return true;
      default:
        break;
      }
      break;
    default:
      break;
    }
    break;
  default:
    break;
  }
  return false;
}

typedef bool (*lookup_connect_out_response_t)(
    int fd, const struct vusb_connect_descriptors* descs,
    const struct usb_ctrlrequest* ctrl, bool* done);

static bool lookup_connect_response_out_generic(
    int fd, const struct vusb_connect_descriptors* descs,
    const struct usb_ctrlrequest* ctrl, bool* done)
{
  switch (ctrl->bRequestType & USB_TYPE_MASK) {
  case USB_TYPE_STANDARD:
    switch (ctrl->bRequest) {
    case USB_REQ_SET_CONFIGURATION:
      *done = true;
      return true;
    default:
      break;
    }
    break;
  }
  return false;
}

#define UDC_NAME_LENGTH_MAX 128

struct usb_raw_init {
  __u8 driver_name[UDC_NAME_LENGTH_MAX];
  __u8 device_name[UDC_NAME_LENGTH_MAX];
  __u8 speed;
};

enum usb_raw_event_type {
  USB_RAW_EVENT_INVALID = 0,
  USB_RAW_EVENT_CONNECT = 1,
  USB_RAW_EVENT_CONTROL = 2,
};

struct usb_raw_event {
  __u32 type;
  __u32 length;
  __u8 data[0];
};

struct usb_raw_ep_io {
  __u16 ep;
  __u16 flags;
  __u32 length;
  __u8 data[0];
};

#define USB_RAW_EPS_NUM_MAX 30
#define USB_RAW_EP_NAME_MAX 16
#define USB_RAW_EP_ADDR_ANY 0xff

struct usb_raw_ep_caps {
  __u32 type_control : 1;
  __u32 type_iso : 1;
  __u32 type_bulk : 1;
  __u32 type_int : 1;
  __u32 dir_in : 1;
  __u32 dir_out : 1;
};

struct usb_raw_ep_limits {
  __u16 maxpacket_limit;
  __u16 max_streams;
  __u32 reserved;
};

struct usb_raw_ep_info {
  __u8 name[USB_RAW_EP_NAME_MAX];
  __u32 addr;
  struct usb_raw_ep_caps caps;
  struct usb_raw_ep_limits limits;
};

struct usb_raw_eps_info {
  struct usb_raw_ep_info eps[USB_RAW_EPS_NUM_MAX];
};

#define USB_RAW_IOCTL_INIT _IOW('U', 0, struct usb_raw_init)
#define USB_RAW_IOCTL_RUN _IO('U', 1)
#define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event)
#define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor)
#define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32)
#define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP_READ _IOWR('U', 8, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_CONFIGURE _IO('U', 9)
#define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32)
#define USB_RAW_IOCTL_EPS_INFO _IOR('U', 11, struct usb_raw_eps_info)
#define USB_RAW_IOCTL_EP0_STALL _IO('U', 12)
#define USB_RAW_IOCTL_EP_SET_HALT _IOW('U', 13, __u32)
#define USB_RAW_IOCTL_EP_CLEAR_HALT _IOW('U', 14, __u32)
#define USB_RAW_IOCTL_EP_SET_WEDGE _IOW('U', 15, __u32)

static int usb_raw_open()
{
  return open("/dev/raw-gadget", O_RDWR);
}

static int usb_raw_init(int fd, uint32_t speed, const char* driver,
                        const char* device)
{
  struct usb_raw_init arg;
  strncpy((char*)&arg.driver_name[0], driver, sizeof(arg.driver_name));
  strncpy((char*)&arg.device_name[0], device, sizeof(arg.device_name));
  arg.speed = speed;
  return ioctl(fd, USB_RAW_IOCTL_INIT, &arg);
}

static int usb_raw_run(int fd)
{
  return ioctl(fd, USB_RAW_IOCTL_RUN, 0);
}

static int usb_raw_event_fetch(int fd, struct usb_raw_event* event)
{
  return ioctl(fd, USB_RAW_IOCTL_EVENT_FETCH, event);
}

static int usb_raw_ep0_write(int fd, struct usb_raw_ep_io* io)
{
  return ioctl(fd, USB_RAW_IOCTL_EP0_WRITE, io);
}

static int usb_raw_ep0_read(int fd, struct usb_raw_ep_io* io)
{
  return ioctl(fd, USB_RAW_IOCTL_EP0_READ, io);
}

static int usb_raw_ep_enable(int fd, struct usb_endpoint_descriptor* desc)
{
  return ioctl(fd, USB_RAW_IOCTL_EP_ENABLE, desc);
}

static int usb_raw_ep_disable(int fd, int ep)
{
  return ioctl(fd, USB_RAW_IOCTL_EP_DISABLE, ep);
}

static int usb_raw_configure(int fd)
{
  return ioctl(fd, USB_RAW_IOCTL_CONFIGURE, 0);
}

static int usb_raw_vbus_draw(int fd, uint32_t power)
{
  return ioctl(fd, USB_RAW_IOCTL_VBUS_DRAW, power);
}

static int usb_raw_ep0_stall(int fd)
{
  return ioctl(fd, USB_RAW_IOCTL_EP0_STALL, 0);
}

static void set_interface(int fd, int n)
{
  struct usb_device_index* index = lookup_usb_index(fd);
  if (!index)
    return;
  if (index->iface_cur >= 0 && index->iface_cur < index->ifaces_num) {
    for (int ep = 0; ep < index->ifaces[index->iface_cur].eps_num; ep++) {
      int rv = usb_raw_ep_disable(
          fd, index->ifaces[index->iface_cur].eps[ep].handle);
      if (rv < 0) {
      } else {
      }
    }
  }
  if (n >= 0 && n < index->ifaces_num) {
    for (int ep = 0; ep < index->ifaces[n].eps_num; ep++) {
      int rv = usb_raw_ep_enable(fd, &index->ifaces[n].eps[ep].desc);
      if (rv < 0) {
      } else {
        index->ifaces[n].eps[ep].handle = rv;
      }
    }
    index->iface_cur = n;
  }
}

static int configure_device(int fd)
{
  struct usb_device_index* index = lookup_usb_index(fd);
  if (!index)
    return -1;
  int rv = usb_raw_vbus_draw(fd, index->bMaxPower);
  if (rv < 0) {
    return rv;
  }
  rv = usb_raw_configure(fd);
  if (rv < 0) {
    return rv;
  }
  set_interface(fd, 0);
  return 0;
}

#define USB_MAX_PACKET_SIZE 4096

struct usb_raw_control_event {
  struct usb_raw_event inner;
  struct usb_ctrlrequest ctrl;
  char data[USB_MAX_PACKET_SIZE];
};

struct usb_raw_ep_io_data {
  struct usb_raw_ep_io inner;
  char data[USB_MAX_PACKET_SIZE];
};

static volatile long
syz_usb_connect_impl(uint64_t speed, uint64_t dev_len, const char* dev,
                     const struct vusb_connect_descriptors* descs,
                     lookup_connect_out_response_t lookup_connect_response_out)
{
  if (!dev) {
    return -1;
  }
  int fd = usb_raw_open();
  if (fd < 0) {
    return fd;
  }
  if (fd >= MAX_FDS) {
    close(fd);
    return -1;
  }
  struct usb_device_index* index = add_usb_index(fd, dev, dev_len);
  if (!index) {
    return -1;
  }
  char device[32];
  sprintf(&device[0], "dummy_udc.%llu", procid);
  int rv = usb_raw_init(fd, speed, "dummy_udc", &device[0]);
  if (rv < 0) {
    return rv;
  }
  rv = usb_raw_run(fd);
  if (rv < 0) {
    return rv;
  }
  bool done = false;
  while (!done) {
    struct usb_raw_control_event event;
    event.inner.type = 0;
    event.inner.length = sizeof(event.ctrl);
    rv = usb_raw_event_fetch(fd, (struct usb_raw_event*)&event);
    if (rv < 0) {
      return rv;
    }
    if (event.inner.type != USB_RAW_EVENT_CONTROL)
      continue;
    char* response_data = NULL;
    uint32_t response_length = 0;
    struct usb_qualifier_descriptor qual;
    if (event.ctrl.bRequestType & USB_DIR_IN) {
      if (!lookup_connect_response_in(fd, descs, &event.ctrl, &qual,
                                      &response_data, &response_length)) {
        usb_raw_ep0_stall(fd);
        continue;
      }
    } else {
      if (!lookup_connect_response_out(fd, descs, &event.ctrl, &done)) {
        usb_raw_ep0_stall(fd);
        continue;
      }
      response_data = NULL;
      response_length = event.ctrl.wLength;
    }
    if ((event.ctrl.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD &&
        event.ctrl.bRequest == USB_REQ_SET_CONFIGURATION) {
      rv = configure_device(fd);
      if (rv < 0) {
        return rv;
      }
    }
    struct usb_raw_ep_io_data response;
    response.inner.ep = 0;
    response.inner.flags = 0;
    if (response_length > sizeof(response.data))
      response_length = 0;
    if (event.ctrl.wLength < response_length)
      response_length = event.ctrl.wLength;
    response.inner.length = response_length;
    if (response_data)
      memcpy(&response.data[0], response_data, response_length);
    else
      memset(&response.data[0], 0, response_length);
    if (event.ctrl.bRequestType & USB_DIR_IN) {
      rv = usb_raw_ep0_write(fd, (struct usb_raw_ep_io*)&response);
    } else {
      rv = usb_raw_ep0_read(fd, (struct usb_raw_ep_io*)&response);
    }
    if (rv < 0) {
      return rv;
    }
  }
  sleep_ms(200);
  return fd;
}

static volatile long syz_usb_connect(volatile long a0, volatile long a1,
                                     volatile long a2, volatile long a3)
{
  uint64_t speed = a0;
  uint64_t dev_len = a1;
  const char* dev = (const char*)a2;
  const struct vusb_connect_descriptors* descs =
      (const struct vusb_connect_descriptors*)a3;
  return syz_usb_connect_impl(speed, dev_len, dev, descs,
                              &lookup_connect_response_out_generic);
}

struct fs_image_segment {
  void* data;
  uintptr_t size;
  uintptr_t offset;
};
static int setup_loop_device(long unsigned size, long unsigned nsegs,
                             struct fs_image_segment* segs,
                             const char* loopname, int* memfd_p, int* loopfd_p)
{
  int err = 0, loopfd = -1;
  int memfd = syscall(__NR_memfd_create, "syzkaller", 0);
  if (memfd == -1) {
    err = errno;
    goto error;
  }
  if (ftruncate(memfd, size)) {
    err = errno;
    goto error_close_memfd;
  }
  for (size_t i = 0; i < nsegs; i++) {
    if (pwrite(memfd, segs[i].data, segs[i].size, segs[i].offset) < 0) {
    }
  }
  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;
    }
  }
  *memfd_p = 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 unsigned long size,
                            volatile unsigned long nsegs,
                            volatile long segments, volatile long flags,
                            volatile long optsarg, volatile long change_dir)
{
  struct fs_image_segment* segs = (struct fs_image_segment*)segments;
  int res = -1, err = 0, loopfd = -1, memfd = -1, need_loop_device = !!segs;
  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(size, nsegs, segs, loopname, &memfd, &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);
    close(memfd);
  }
  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")) {
  }
}

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

void execute_one(void)
{
  intptr_t res = 0;
  memcpy((void*)0x20000000, "f2fs\000", 5);
  memcpy((void*)0x20000100, "./file0\000", 8);
  *(uint64_t*)0x20000200 = 0x20010720;
  memset((void*)0x20010720, 0, 2);
  *(uint64_t*)0x20000208 = 2;
  *(uint64_t*)0x20000210 = 1;
  *(uint64_t*)0x20000218 = 0x20010f40;
  memcpy((void*)0x20010f40,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\xb0\xda"
         "\x17\x3e\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x0b\x00\x00"
         "\x00\x00\x00\x00\x00\x0d\x00\x00\x00\x10\x00\x00\x00\x12\x00\x00\x00"
         "\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x03\x00"
         "\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         115);
  *(uint64_t*)0x20000220 = 0x73;
  *(uint64_t*)0x20000228 = 3;
  *(uint64_t*)0x20000230 = 0x20010420;
  memcpy(
      (void*)0x20010420,
      "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
      "\000\000\000\000\000\000\000\000\000\000%"
      "\000\000\000mp\000\000\000\000\000\000wm\000\000\000\000\000\000og\000",
      51);
  *(uint64_t*)0x20000238 = 0x33;
  *(uint64_t*)0x20000240 = 0x76;
  *(uint64_t*)0x20000248 = 0x20010e40;
  memcpy((void*)0x20010e40,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00"
         "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x01\x00\x08"
         "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00",
         64);
  *(uint64_t*)0x20000250 = 0x40;
  *(uint64_t*)0x20000258 = 0xa9;
  *(uint64_t*)0x20000260 = 0x20010000;
  memcpy((void*)0x20010000,
         "\x10\x20\xf5\xf2\x01\x00\x0e\x00\x09\x00\x00\x00\x03\x00\x00\x00\x10"
         "\x00\x00\x00\x09\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x1f\x00\x00"
         "\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00"
         "\x18\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x06\x00\x00\x00"
         "\x0a\x00\x00\x00\x0e\x00\x00\x00\x10\x00\x00\x03\x00\x00\x00\x01\x00"
         "\x00\x00\x02\x00\x00\x00\x22\x55\x7c\x7f\x4c\x46\x48\x34\xa1\x8d\xa3"
         "\xb1\x91\x54\xb9\x55\x00\x00\x00\x00",
         128);
  *(uint64_t*)0x20000268 = 0x80;
  *(uint64_t*)0x20000270 = 0x400;
  *(uint64_t*)0x20000278 = 0x20010080;
  memcpy(
      (void*)0x20010080,
      "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
      "\000\000\000\000\000\000\000\000\000\000%"
      "\000\000\000mp\000\000\000\000\000\000wm\000\000\000\000\000\000og\000"
      "\000\000\000\000\000jp\000\000\000\000\000\000avi\000\000\000\000\000m4v"
      "\000\000\000\000\000m4p\000\000\000\000\000mkv\000\000\000\000\000mov"
      "\000\000\000\000\000webm\000\000\000\000wav\000\000\000\000\000m4a\000"
      "\000\000\000\0003gp\000\000\000\000\000opus\000\000\000\000flac\000\000"
      "\000\000gif\000\000\000\000\000png\000\000\000\000\000svg\000\000\000"
      "\000\000webp\000\000\000\000jar\000\000\000\000\000deb\000\000\000\000"
      "\000iso\000\000\000\000\000gz\000\000\000\000\000\000xz\000\000\000\000"
      "\000\000zst\000\000\000\000\000pdf\000\000\000\000\000pyc\000\000\000"
      "\000\000ttc\000\000\000\000\000ttf\000\000\000\000\000exe\000\000\000"
      "\000\000apk\000\000\000\000\000cnt\000\000\000\000\000exo\000\000\000"
      "\000\000odex\000\000\000\000vdex\000\000\000\000so\000\000\000\000\000"
      "\000cold\000\000\000\000db\000\000\000\000\000\000\000\000\000\000\000"
      "\000\000\000\000\000\000\000\000\000\000\000",
      352);
  *(uint64_t*)0x20000280 = 0x160;
  *(uint64_t*)0x20000288 = 0x860;
  *(uint64_t*)0x20000290 = 0x200101e0;
  memcpy((void*)0x200101e0,
         "\000\000\000\000Linux version 5.17.11-1rodete2-amd64 "
         "(glinux-team@google.com) (gcc-11 (Debian 11.2.0-20) 11.2.0, GNU ld "
         "(GNU Binutils for Debian) 2.38) #1 SMP PREEMPT Debian "
         "5.17.11-1rodete2 (2022-06-09)\000",
         192);
  *(uint64_t*)0x20000298 = 0xc0;
  *(uint64_t*)0x200002a0 = 0xa80;
  *(uint64_t*)0x200002a8 = 0x20000b00;
  memcpy(
      (void*)0x20000b00,
      "\x00\x00\x00\x00\x4c\x69\x6e\x75\x78\x20\x76\x65\x72\x73\x69\x6f\x6e\x20"
      "\x35\x2e\x31\x37\x2e\x31\x31\x2d\x31\x72\x6f\x64\x65\x74\x95\x7f\x2d\x61"
      "\x6d\x64\x36\x34\x20\x28\x67\x6c\x69\x6e\x75\x78\x2d\x74\x65\x61\x6d\x40"
      "\x67\x6f\x6f\x67\x6c\x65\x2e\x63\x6f\x6d\x29\x20\x28\x67\x63\x63\x2d\x31"
      "\x31\x20\x28\x44\x65\x62\x69\x61\x6e\x20\x31\x31\x2e\x32\x2e\x30\x2d\x32"
      "\x30\x29\x20\x31\x31\x2e\x32\x2e\x30\x2c\x20\x47\x4e\x55\x20\x6c\x64\x20"
      "\x28\x47\x4e\x55\x20\x42\x69\x6e\x75\x74\x69\x6c\x73\x20\x66\x6f\x72\x20"
      "\x44\x65\x62\x69\x61\x6e\x29\x20\x32\x2e\x33\x38\x29\x20\x23\x31\x20\x53"
      "\x4d\x50\x20\x50\x52\x45\x45\x4d\x50\x54\x20\x44\x65\x62\x69\x61\x6e\x20"
      "\x35\x2e\x31\x37\x2e\x31\x31\x2d\x31\x72\x6f\x64\x65\x74\x65\x32\x20\x28"
      "\x32\x30\x32\x32\x2d\x30\x36\x2d\x30\x39\x29\x00",
      192);
  *(uint64_t*)0x200002b0 = 0xc0;
  *(uint64_t*)0x200002b8 = 0xb80;
  *(uint64_t*)0x200002c0 = 0x20000c00;
  memcpy((void*)0x20000c00,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5c\xbe"
         "\xd2\xb6\xf0\xe7\xa5\x8a\x8a\xd0\xdd\xc3\x2e\xe9\xda\x62\xa6\x15\xdb"
         "\xf0\x43\x7d\x4d\xec\x34\xaf\xb1\xb0\x85\x2b\x1a\x76\xd3\xcd\xca\xa5"
         "\x75\x3c\x32\xed\xd9\x57\xaa\x75\x68\x80\x0e\xed\x7a\x79\x7c\x50\x87"
         "\xc1\x77\x75\x4c\xfa\xff\x5d\xdb\x3b\xa6\xdd\x08\x4d\x52\x3b\x7a\xa7"
         "\xf1\x59\xab\xf6\xae\xe3\x8a\x48\xb6\xa1\x5a\x4d\x49\xc5\xc8\x35\x73"
         "\x90\x89\xa0\x9e\xeb\x95\x38\x2e\xe0\xd5\x5a\xdf\x96\x60\x99\x24\x32"
         "\x51\xee\xee\x84\xcf\x0a\x1b\xd3\xe5\xf6\x48\x2d\x25\x97\x89\xee\xa5"
         "\x60\x2b\xf6\x1b\x38\xa7\x31\x25\x0a\xf0\x92\x1c\x3c\x0d\x58\x5a\xf9"
         "\xfb\x9e\x1c\xea\xd8\xc4\x26\x14\xeb\x70\x0c\xda\x4f\xeb\xba\x20\xfe"
         "\x27\xe5\x5b\xb9\xd1\x31\xc9\x34\x4f\xcd\x22\x25\xd1\xd9\xe4\x0d\x58"
         "\x87\x5f\x4b\x7b\xad\x28\x26\x02\x1f\xfe\x4e\x68\x67\xb8\xe1\xc4",
         203);
  *(uint64_t*)0x200002c8 = 0xcb;
  *(uint64_t*)0x200002d0 = 0xc80;
  *(uint64_t*)0x200002d8 = 0x20010380;
  memcpy((void*)0x20010380,
         "\x00\x00\x00\x00\x00\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",
         32);
  *(uint64_t*)0x200002e0 = 0x20;
  *(uint64_t*)0x200002e8 = 0xec0;
  *(uint64_t*)0x200002f0 = 0x200103a0;
  memcpy((void*)0x200103a0,
         "\x10\x20\xf5\xf2\x01\x00\x0e\x00\x09\x00\x00\x00\x03\x00\x00\x00\x0c"
         "\x00\x00\x00\x09\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x1f\x00\x00"
         "\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00"
         "\x18\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x06\x00\x00\x00"
         "\x0a\x00\x00\x00\x0e\x00\x00\x00\x10\x00\x00\x03\x00\x00\x00\x01\x00"
         "\x00\x00\x02\x00\x00\x00\x22\x55\x7c\x7f\x4c\x46\x48\x34\xa1\x8d\xa3"
         "\xb1\x91\x54\xb9\x55\x00\x00\x00\x00",
         128);
  *(uint64_t*)0x200002f8 = 0x80;
  *(uint64_t*)0x20000300 = 0x1400;
  *(uint64_t*)0x20000308 = 0x20010580;
  memcpy((void*)0x20010580,
         "\000\000\000\000Linux version 5.17.11-1rodete2-amd64 "
         "(glinux-team@google.com) (gcc-11 (Debian 11.2.0-20) 11.2.0, GNU ld "
         "(GNU Binutils for Debian) 2.38) #1 SMP PREEMPT Debian "
         "5.17.11-1rodete2 (2022-06-09)\000",
         192);
  *(uint64_t*)0x20000310 = 0xc0;
  *(uint64_t*)0x20000318 = 0x1a80;
  *(uint64_t*)0x20000320 = 0x20000d00;
  memcpy(
      (void*)0x20000d00,
      "\x00\x00\x00\x00\x4c\x69\x6e\x75\x78\x20\x76\x65\x72\x73\x69\x6f\x6e\x20"
      "\x35\x2e\x31\x37\x2e\x31\x31\x2d\x31\x72\x6f\x64\x65\x74\x65\x32\x2d\x61"
      "\x6d\x64\x36\x34\x20\x28\x67\x6c\x69\x6e\x10\x78\x2d\x74\x65\x61\x6d\x40"
      "\x67\x6f\x6f\x67\x6c\x65\x2e\x63\x6f\x6d\x29\x20\x28\x67\x63\x63\x2d\x31"
      "\x31\x20\x28\x44\x65\x62\x69\x61\x6e\x20\x31\x31\x2e\x32\x2e\x30\x2d\x32"
      "\x30\x29\x20\x31\x31\x2e\x32\x2e\x30\x2c\x20\x47\x4e\x55\x20\x6c\x64\x20"
      "\xd3\x90\xc9\x67\x54\xac\xe8\x27\x75\x74\x69\x6c\x73\x20\x66\x6f\x72\x20"
      "\x44\x65\x62\x69\x20\x32\x2e\x33\x38\x29\x20\x23\x31\x20\x53\x4d\x50\x20"
      "\x50\x52\x45\x45\x4d\x50\x54\x20\x44\x65\x62\x69\x61\x6e\x20\x35\x2e\x31"
      "\x37\x2e\x31\x31\x2d\x31\x72\x6f\x64\x65\x74\x65\x32\x20\x28\x32\x30\x32"
      "\x32\x2d\x30\x36\x2d\x30\x39\x29\x00\x00\x00\x00\x0a\x3b\x62\x5e\x77\x7e"
      "\x27\xb5\x66\xff\x4b\x45\xd5\x0b\x55\x54\xb9\x30\xb4\x25\xe1\x1d\xf9\x29"
      "\x96\x5f\x22\xd5\xdc\x5d\x47\x87\x56\xac\x06\x9a\x06\xd0\x66\x10\x5b\x96"
      "\x5d\x14\x60\x99\x79\xc8\x73\xc1\x3e\x5c\x5d\xb6\x37\xdd\xd1\x90\x37\xe5"
      "\xef\x0a\x11\x57",
      256);
  *(uint64_t*)0x20000328 = 0x100;
  *(uint64_t*)0x20000330 = 0x1b80;
  *(uint64_t*)0x20000338 = 0x20010700;
  memcpy((void*)0x20010700,
         "\000\000\000\000\b\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
         32);
  *(uint64_t*)0x20000340 = 0x20;
  *(uint64_t*)0x20000348 = 0x1c80;
  *(uint64_t*)0x20000350 = 0x20010740;
  memcpy(
      (void*)0x20010740,
      "\xb1\xda\x17\x3e\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x0b\x00"
      "\x00\x00\x00\x00\x00\x00\x0d\x00\x00\x00\x10\x00\x00\x00\x12\x00\x00\x00"
      "\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\xff\xff\xff\xff\xff\xff"
      "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x03\x00\x06\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x0b\x00"
      "\x00\x00\x05\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
      "\xff\xff\xff\xff\xff\xff\xff\xff\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\xc5\x01\x00\x00\x06\x00\x00\x00\x01\x00\x00\x00"
      "\x07\x00\x00\x00\x07\x00\x00\x00\x0a\x00\x00\x00\x40\x00\x00\x00\x40\x00"
      "\x00\x00\xfc\x0f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
      192);
  *(uint64_t*)0x20000358 = 0xc0;
  *(uint64_t*)0x20000360 = 0x200000;
  *(uint64_t*)0x20000368 = 0x20010800;
  memcpy((void*)0x20010800,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x38\x2c\x77\xa2\x00\x00"
         "\x03\x00\x00\x00\x00\x03\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         64);
  *(uint64_t*)0x20000370 = 0x40;
  *(uint64_t*)0x20000378 = 0x200fe0;
  *(uint64_t*)0x20000380 = 0x20010840;
  memcpy(
      (void*)0x20010840,
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x02\x0c\x60"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01"
      "\x00\x00\x00\x05\x10\xec\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00"
      "\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x14\x00",
      192);
  *(uint64_t*)0x20000388 = 0xc0;
  *(uint64_t*)0x20000390 = 0x2011e0;
  *(uint64_t*)0x20000398 = 0x20010900;
  memcpy((void*)0x20010900,
         "\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x04\x00\x78\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00"
         "\x05\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00",
         96);
  *(uint64_t*)0x200003a0 = 0x60;
  *(uint64_t*)0x200003a8 = 0x2012e0;
  *(uint64_t*)0x200003b0 = 0x20010960;
  memcpy((void*)0x20010960,
         "\x00\x00\x00\x0b\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         32);
  *(uint64_t*)0x200003b8 = 0x20;
  *(uint64_t*)0x200003c0 = 0x201380;
  *(uint64_t*)0x200003c8 = 0x20010980;
  memcpy((void*)0x20010980,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00"
         "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x01\x00\x08"
         "\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00",
         64);
  *(uint64_t*)0x200003d0 = 0x40;
  *(uint64_t*)0x200003d8 = 0x2013e0;
  *(uint64_t*)0x200003e0 = 0x200109c0;
  memcpy((void*)0x200109c0,
         "\x03\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x04\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         32);
  *(uint64_t*)0x200003e8 = 0x20;
  *(uint64_t*)0x200003f0 = 0x202000;
  *(uint64_t*)0x200003f8 = 0x20000900;
  memcpy((void*)0x20000900,
         "\x00\x00\x8c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         32);
  *(uint64_t*)0x20000400 = 0x20;
  *(uint64_t*)0x20000408 = 0x202e00;
  *(uint64_t*)0x20000410 = 0x20010a00;
  memcpy((void*)0x20010a00,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x05\x00"
         "\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00"
         "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x08"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         96);
  *(uint64_t*)0x20000418 = 0x60;
  *(uint64_t*)0x20000420 = 0x202fe0;
  *(uint64_t*)0x20000428 = 0x20010a80;
  memcpy(
      (void*)0x20010a80,
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\xb1\xda\x17\x3e"
      "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x0b\x00\x00\x00\x00\x00"
      "\x00\x00\x0d\x00\x00\x00\x10\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00"
      "\x01\x00\x00\x00\x02\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
      "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x03\x00\x06\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x0b\x00\x00\x00\x05\x00"
      "\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
      "\xff\xff\xff\xff\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\xc5\x01\x00\x00\x06\x00\x00\x00\x01\x00\x00\x00\x07\x00\x00\x00"
      "\x07\x00\x00\x00\x0a\x00\x00\x00\x40\x00\x00\x00\x40\x00\x00\x00\xfc\x0f"
      "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00",
      224);
  *(uint64_t*)0x20000430 = 0xe0;
  *(uint64_t*)0x20000438 = 0x204fe0;
  *(uint64_t*)0x20000440 = 0x20010b60;
  memcpy((void*)0x20010b60,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x38\x2c\x77\xa2",
         32);
  *(uint64_t*)0x20000448 = 0x20;
  *(uint64_t*)0x20000450 = 0x205fe0;
  *(uint64_t*)0x20000458 = 0x20010b80;
  memcpy((void*)0x20010b80,
         "\xb1\xda\x17\x3e\x38\x2c\x77\xa2\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         32);
  *(uint64_t*)0x20000460 = 0x20;
  *(uint64_t*)0x20000468 = 0x3ff000;
  *(uint64_t*)0x20000470 = 0x20010ba0;
  memcpy((void*)0x20010ba0,
         "\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         96);
  *(uint64_t*)0x20000478 = 0x60;
  *(uint64_t*)0x20000480 = 0x3ff040;
  *(uint64_t*)0x20000488 = 0x20010c00;
  memcpy(
      (void*)0x20010c00,
      "\xb0\xda\x17\x3e\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x0b\x00"
      "\x00\x00\x00\x00\x00\x00\x0d\x00\x00\x00\x10\x00\x00\x00\x12\x00\x00\x00"
      "\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\xff\xff\xff\xff\xff\xff"
      "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x03\x00\x06\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x0b\x00"
      "\x00\x00\x05\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
      "\xff\xff\xff\xff\xff\xff\xff\xff\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\xc5\x00\x00\x00\x06\x00\x00\x00\x01\x00\x00\x00"
      "\x07\x00\x00\x00\x07\x00\x00\x00\x0a\x00\x00\x00\x40\x00\x00\x00\x40\x00"
      "\x00\x00\xfc\x0f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
      192);
  *(uint64_t*)0x20000490 = 0xc0;
  *(uint64_t*)0x20000498 = 0x400000;
  *(uint64_t*)0x200004a0 = 0x20010cc0;
  memcpy((void*)0x20010cc0,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5e\x2e\xcb\x6b\x00\x00"
         "\x03\x00\x00\x00\x00\x03\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         64);
  *(uint64_t*)0x200004a8 = 0x40;
  *(uint64_t*)0x200004b0 = 0x400fe0;
  *(uint64_t*)0x200004b8 = 0x20010d00;
  memcpy(
      (void*)0x20010d00,
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x02\x0c\x60"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01"
      "\x00\x00\x00\xd1\xcd\xed\x7b\xeb\xe3\xa0\xa0\xeb\x8e\x0e\x05\x10\xec\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00",
      192);
  *(uint64_t*)0x200004c0 = 0xc0;
  *(uint64_t*)0x200004c8 = 0x4011e0;
  *(uint64_t*)0x200004d0 = 0x20010dc0;
  memcpy((void*)0x20010dc0,
         "\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x05\x12\x00\x00"
         "\x00\x08\x00\x00\x00\x00\x00",
         92);
  *(uint64_t*)0x200004d8 = 0x5c;
  *(uint64_t*)0x200004e0 = 0x4012e0;
  *(uint64_t*)0x200004e8 = 0x20010e20;
  memcpy((void*)0x20010e20,
         "\x00\x00\x00\x09\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaf\xf1\x3b\xf6\xbd",
         31);
  *(uint64_t*)0x200004f0 = 0x1f;
  *(uint64_t*)0x200004f8 = 0x40137e;
  *(uint64_t*)0x20000500 = 0x20010e80;
  memcpy((void*)0x20010e80,
         "\x03\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x06\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xf7\x00\x00\x00",
         32);
  *(uint64_t*)0x20000508 = 0x20;
  *(uint64_t*)0x20000510 = 0x402000;
  *(uint64_t*)0x20000518 = 0x20010ea0;
  memcpy((void*)0x20010ea0,
         "\000\000p\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
         32);
  *(uint64_t*)0x20000520 = 0x20;
  *(uint64_t*)0x20000528 = 0x402e00;
  *(uint64_t*)0x20000530 = 0x20010ec0;
  memcpy((void*)0x20010ec0,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x05\x00"
         "\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00"
         "\x00\x00\x08\x00\x00\x00\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x08"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         96);
  *(uint64_t*)0x20000538 = 0x60;
  *(uint64_t*)0x20000540 = 0x402fe0;
  *(uint64_t*)0x20000548 = 0x20010f20;
  memcpy((void*)0x20010f20,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00",
         32);
  *(uint64_t*)0x20000550 = 0x20;
  *(uint64_t*)0x20000558 = 0x403fe0;
  *(uint64_t*)0x20000560 = 0x20011020;
  memcpy((void*)0x20011020,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5e\x2e\xcb\x6b",
         32);
  *(uint64_t*)0x20000568 = 0x20;
  *(uint64_t*)0x20000570 = 0x405fe0;
  *(uint64_t*)0x20000578 = 0x20000140;
  memcpy((void*)0x20000140,
         "\xb0\xda\x8e\xf3\x5e\x2e\xcb\x6b\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa5\xd9"
         "\x9c\x0d\x43\xae\xe3\x15\xbf\x34\xb1\x4d\xb1\x1d\x58\x8c\xc6\xbc\x7b",
         51);
  *(uint64_t*)0x20000580 = 0x33;
  *(uint64_t*)0x20000588 = 0x5ff000;
  *(uint64_t*)0x20000590 = 0x20011060;
  memcpy((void*)0x20011060,
         "\x00\x00\x00\x00\x00\x00\x00\x00\xfe\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
         "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         96);
  *(uint64_t*)0x20000598 = 0x60;
  *(uint64_t*)0x200005a0 = 0x5ff040;
  *(uint64_t*)0x200005a8 = 0x20000180;
  memcpy((void*)0x20000180,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00"
         "\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x00\x03\x00\x00\x00\x01\x10"
         "\x00\x00\x00\x04\x00\x00\x00\x02\x10\x00\x00\x00\x05\x00\x00\x00\x00"
         "\x12\x00\x00\x00\x06\x00\x00\x00\x01\x12\x00\x00\x00\x07\x00\x00\x00"
         "\x02\x12\x00\x00\x00\x08\x00\x00\x00\x05\x12\x00\x00\x00\x09\x00\x00"
         "\x00\x04\x12\x00\x00\x00\x00\x00\x00\x00\x00",
         96);
  *(uint64_t*)0x200005b0 = 0x60;
  *(uint64_t*)0x200005b8 = 0xa00000;
  *(uint64_t*)0x200005c0 = 0x20000ec0;
  memcpy((void*)0x20000ec0,
         "\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00"
         "\x00\x00\x02\x00\x00\x00\x00\x04\x00\x00\x00\x02\x10\x00\x00\x00\x05"
         "\x00\x00\x00\x00\x12\x00\x00\x00\x06\x00\x00\x00\x01\x12\x00\x00\x00"
         "\x07\x00\x00\x00\x02\x12\x00\x00\x00\x08\x00\x00\x00\x03\x12\x00\x00"
         "\x00\x09\x00\x00\x00\x04\x12\x00\x00\x00\x00\x00\x00\x00\x00\x75\x83"
         "\x99\xeb\xe5\xe2\x0e\xa4\x2d\x2f\xa5\xbf\x12\xac\x2d\xf5\x7a\xed\x00"
         "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         114);
  *(uint64_t*)0x200005c8 = 0x72;
  *(uint64_t*)0x200005d0 = 0xbffffc;
  *(uint64_t*)0x200005d8 = 0x20011180;
  memcpy((void*)0x20011180,
         "\xed\x41\x00\x20\x80\x76\x10\x00\x53\x5f\x01\x00\x03\x00\x00\x00\x00"
         "\x10\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x5e\x1f"
         "\x1f\x63\x00\x00\x00\x00\x65\x1f\x1f\x63\x00\x00\x00\x00\x65\x1f\x1f"
         "\x63\x00\x00\x00\x00\x00\x00\x00\x00\xc9\x67\x5f\x30\xc9\x67\x5f\x30"
         "\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         96);
  *(uint64_t*)0x200005e0 = 0x60;
  *(uint64_t*)0x200005e8 = 0x1001000;
  *(uint64_t*)0x200005f0 = 0x200111e0;
  memcpy((void*)0x200111e0,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x01\x16\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         32);
  *(uint64_t*)0x200005f8 = 0x20;
  *(uint64_t*)0x20000600 = 0x1001160;
  *(uint64_t*)0x20000608 = 0x20011200;
  memcpy(
      (void*)0x20011200,
      "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00\x00\x00"
      "\x00\x00\xad\xda\x17\x3e\x00\x00\x00\x00\x02\x10\x00\x00\xed\x41\x00\x25"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7c\x0d\x00\x00\x00\x00\x00\x00"
      "\x01\x00\x00\x00\x00\x00\x00\x00\x58\x1f\x1f\x63\x00\x00\x00\x00\x65\x1f"
      "\x1f\x63\x00\x00\x00\x00\x65\x1f\x1f\x63\x00\x00\x00\x00\xc9\x67\x5f\x30"
      "\xc9\x67\x5f\x30\xc9\x67\x5f\x30\xc7\x6f\x1e\x44\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x10\x00\x00\x03\x00\x00\x00\x05\x00\x00\x00\x66\x69\x6c\x65"
      "\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
      160);
  *(uint64_t*)0x20000610 = 0xa0;
  *(uint64_t*)0x20000618 = 0x1001fe0;
  *(uint64_t*)0x20000620 = 0x20011320;
  memcpy(
      (void*)0x20011320,
      "\000\000\000\000\000\000\000\000\000\000\000\000."
      "\000\000\000\000\000\000\000.."
      "\000\000\000\000\000\000file0\000\000\000file1\000\000\000\000\000\000"
      "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
      64);
  *(uint64_t*)0x20000628 = 0x40;
  *(uint64_t*)0x20000630 = 0x1002960;
  *(uint64_t*)0x20000638 = 0x20000080;
  memcpy((void*)0x20000080,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x03\x10\x00\x00\x21\xc8\x89\x93\x32\x92\xea\xb8"
         "\x85\x06\xc2\xbf\x4b\x21\x9e\x41\x58\x6b\x2e\xe7\xe0\xc3\xb5\xdc\x95"
         "\x0e\x5f\xe5\x1e\xd5\xd1\x7f\xe4\x53\x2c\xc4\xdd\xa6\x33\x13\x3c\xc8"
         "\x32\x5e\x59\x6a\xaa\xe7\xbf\x82\x40\xbd\xeb\xa0\xbe\x9e\x65\xd4\x3d"
         "\x3b\x16\x13\x9a\x6e\x1e\x74\x81\x36\x4c\xab\x10\x0c\x31\xc3\x8d\xb2"
         "\x49\x2e\xb6\xb5\x71\x9c\xeb\x4d",
         110);
  *(uint64_t*)0x20000640 = 0x6e;
  *(uint64_t*)0x20000648 = 0x1002fe0;
  *(uint64_t*)0x20000650 = 0x20011380;
  memcpy((void*)0x20011380,
         "\xed\x81\x00\x2b\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x1a"
         "\x04\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x65\x1f"
         "\x1f\x63\x00\x00\x00\x00\x65\x1f\x1f\x63\x00\x00\x00\x00\x65\x1f\x1f"
         "\x63\x00\x00\x00\x00\xc9\x67\x5f\x30\xc9\x67\x5f\x30\xc9\x67\x5f\x30"
         "\x5e\xe7\x8c\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04"
         "\x00\x00\x00\x05\x00\x00\x00\x66\x69\x6c\x65\x30\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         128);
  *(uint64_t*)0x20000658 = 0x80;
  *(uint64_t*)0x20000660 = 0x1200000;
  *(uint64_t*)0x20000668 = 0x20011400;
  memcpy((void*)0x20011400,
         "\000\000\000\000\000\000\000\000$"
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000syzkallersyzkallersyzkallersyzkallersyzkallersyzk"
         "allersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallers"
         "yzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkall"
         "ersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzk"
         "allersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallers"
         "yzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkall"
         "ersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzk"
         "allersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallers"
         "yzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkall"
         "ersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzk"
         "allersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallers"
         "yzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkall"
         "ersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzk"
         "allersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallers"
         "yzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkallersyzkall"
         "ersyzkallersyzkallersyzkallersyzkal\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
         1120);
  *(uint64_t*)0x20000670 = 0x460;
  *(uint64_t*)0x20000678 = 0x1200160;
  *(uint64_t*)0x20000680 = 0x20011860;
  memcpy(
      (void*)0x20011860,
      "\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x05\x00\x00\x00\x01\x00"
      "\x00\x00\xad\xda\x17\x3e\x00\x00\x00\x00\x01\x12\x00\x00\xff\xa1\x00\x2b"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x27\x00\x00\x00\x00\x00"
      "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x65\x1f\x1f\x63\x00\x00\x00\x00"
      "\x65\x1f\x1f\x63\x00\x00\x00\x00\x65\x1f\x1f\x63\x00\x00\x00\x00\xc9\x67"
      "\x5f\x30\xc9\x67\x5f\x30\xc9\x67\x5f\x30\xf1\x68\x9d\x18\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x66\x69"
      "\x6c\x65\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
      160);
  *(uint64_t*)0x20000688 = 0xa0;
  *(uint64_t*)0x20000690 = 0x1200fe0;
  *(uint64_t*)0x20000698 = 0x20011900;
  memcpy((void*)0x20011900,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x24\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\xdf\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2f\x74\x6d"
         "\x70\x2f\x73\x79\x7a\x2d\x69\x6d\x61\x67\x65\x67\x65\x6e\x32\x39\x34"
         "\x31\x39\x36\x31\x37\x34\x39\x2f\x66\x69\x6c\x65\x30\x2f\x66\x69\x6c"
         "\x65\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         96);
  *(uint64_t*)0x200006a0 = 0x60;
  *(uint64_t*)0x200006a8 = 0x1201163;
  *(uint64_t*)0x200006b0 = 0x20000a00;
  memcpy((void*)0x20000a00,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x24\x04\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\xe2\xeb\x3c\x83\xab\x01\xfd\x04\x00\x00\x00\x00\x00\x04"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x73\x79\x7a\x6b\x61"
         "\x6c\x6c\x65\x72\x73\x00\x00\x00\x00\x00\x00\x87\x29\x5c\xa6\x1d\x57"
         "\x99\xae\x89\x1d\x70\x65\x70\xa2\x14\xc4\xf1\xd3\x6b\x61\x63\x5f\xf5"
         "\xb6\x89\x48\x3b\xd4\xaa\x47\x22\x11\x94\x2c\x5a\xcb\x66\xaf\xa0\x67"
         "\xdc\x10\x0e\x10\x3f\x3d\xc0\xa8\xeb\x6d\xf1\x9c\xc9\x4a\xbd",
         117);
  *(uint64_t*)0x200006b8 = 0x75;
  *(uint64_t*)0x200006c0 = 0x1202160;
  *(uint64_t*)0x200006c8 = 0x20011a40;
  memcpy((void*)0x20011a40,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x20\xf5\xf2\x01"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x01\x06\x06\x00\x78\x61\x74\x74\x72\x31\x78\x61\x74\x74\x72"
         "\x31\x01\x06\x06\x00\x78\x61\x74\x74\x72\x32\x78\x61\x74\x74\x72\x32"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         96);
  *(uint64_t*)0x200006d0 = 0x60;
  *(uint64_t*)0x200006d8 = 0x1202f00;
  *(uint64_t*)0x200006e0 = 0x20011aa0;
  memcpy((void*)0x20011aa0,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x07\x00\x00\x00\x01"
         "\x00\x00\x00\xad\xda\x17\x3e\x00\xc0\x2d\x01\x00\x00\x00\x00",
         32);
  *(uint64_t*)0x200006e8 = 0x20;
  *(uint64_t*)0x200006f0 = 0x1202fe0;
  *(uint64_t*)0x200006f8 = 0x20011ac0;
  memcpy((void*)0x20011ac0,
         "\xed\x81\x01\x2b\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x64"
         "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x65\x1f"
         "\x1f\x63\x00\x00\x00\x00\x65\x1f\x1f\x63\x00\x00\x00\x00\x65\x1f\x1f"
         "\x63\x00\x00\x00\x00\xc9\x67\x5f\x30\xc9\x67\x5f\x30\xc9\x67\x5f\x30"
         "\x55\x9f\x02\xd3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03"
         "\x00\x00\x00\x09\x00\x00\x00\x66\x69\x6c\x65\x2e\x63\x6f\x6c\x64\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         128);
  *(uint64_t*)0x20000700 = 0x80;
  *(uint64_t*)0x20000708 = 0x1203ffc;
  *(uint64_t*)0x20000710 = 0x20011b40;
  memcpy((void*)0x20011b40,
         "\000\000\000\000\000\000\000\000$"
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000syzkallersyzkallersyzkallersyzkallersyzkallersyzk"
         "allersyzkallersyzkallersyzkallersyzkallersyzkallers\000\000\000\000"
         "\000\000\000\000\000\000\000\000",
         160);
  *(uint64_t*)0x20000718 = 0xa0;
  *(uint64_t*)0x20000720 = 0x1204160;
  *(uint64_t*)0x20000728 = 0x20011be0;
  memcpy(
      (void*)0x20011be0,
      "\x00\x00\x00\x00\x00\x00\x00\x00\x09\x00\x00\x00\x09\x00\x00\x00\x01\x00"
      "\x00\x00\xad\xda\x17\x3e\x00\x00\x00\x00\x05\x12\x00\x00\xed\x81\x02\x21"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x28\x23\x00\x00\x00\x00"
      "\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x65\x1f\x1f\x63\x00\x00\x00\x00"
      "\x65\x1f\x1f\x63\x00\x00\x00\x00\x65\x1f\x1f\x63\x00\x00\x00\x00\xc9\x67"
      "\x5f\x30\xc9\x67\x5f\x30\xc9\x67\x5f\x30\xb4\x1f\xa9\x09\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x05\x00\x00\x00\x66\x69"
      "\x6c\x65\x33\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
      "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
      160);
  *(uint64_t*)0x20000730 = 0xa0;
  *(uint64_t*)0x20000738 = 0x1204fe0;
  *(uint64_t*)0x20000740 = 0x20011c80;
  memcpy((void*)0x20011c80,
         "\x02\x16\x00\x00\x03\x00\x00\x00\x24\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x16\x00\x00\x03\x16\x00"
         "\x00\x04\x16\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         64);
  *(uint64_t*)0x20000748 = 0x40;
  *(uint64_t*)0x20000750 = 0x1205161;
  *(uint64_t*)0x20000758 = 0x20011cc0;
  memcpy((void*)0x20011cc0,
         "\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00\x00\x01"
         "\x00\x00\x00\xae\xda\x17\x3e\xb7\xc3\x3c\x19\x06\x12\x00\x00",
         32);
  *(uint64_t*)0x20000760 = 0x20;
  *(uint64_t*)0x20000768 = 0x1205fe0;
  *(uint64_t*)0x20000770 = 0x20011ce0;
  memcpy((void*)0x20011ce0,
         "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x03\x00\x00\x00\x01\x00\x02\x00\x00\x00\x00\x03\x00\x00\x00\x02\x00"
         "\x02\x4a\x81\x13\xed\x04\x00\x00\x00\x05\x00\x02\x8d\xce\xce\x45\x07"
         "\x00\x00\x00\x05\x00\x01\xba\xee\xd0\x6f\x08\x00\x00\x00\x05\x00\x01"
         "\x53\xbf\xc5\x50\x08\x00\x00\x00\x05\x00\x01\x12\x00\x52\x23\x09\x00"
         "\x00\x00\x09\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00",
         128);
  *(uint64_t*)0x20000778 = 0x80;
  *(uint64_t*)0x20000780 = 0x1601000;
  *(uint64_t*)0x20000788 = 0x20011d60;
  memcpy((void*)0x20011d60,
         "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000."
         "\000\000\000\000\000\000\000.."
         "\000\000\000\000\000\000file0\000\000\000file1\000\000\000file2\000"
         "\000\000file3\000\000\000file."
         "cold\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
         "\000\000\000\000\000\000\000",
         96);
  *(uint64_t*)0x20000790 = 0x60;
  *(uint64_t*)0x20000798 = 0x1601940;
  memcpy((void*)0x200007c0,
         "\x00\x00\x00\x00\x00\x00\xfb\xff\xff\xff\x3e\x10\xe2\xd7\x42\x8f\x7f"
         "\xf9\x9d\x98\xcd\x1c\xdc\x1e\x2f\xa5\x04\x07\xdb\xc9\x57\x39\xe0\x26"
         "\xb9\x51\x76\xc1\xba\x73\x2b\xec\xc3\xdd\xdf\xc7\x8d\x40\x42\xfb\x51"
         "\xbc\x0f\xa9\x60\x7e\xc5\xcb\xef\x34\x56\xef\x2a\xda\x10\xe3\x46\x03"
         "\xb0\xc1\x15\xab\x20\xb4\xfa\x4b\xd6\xfd\x04\x18\xb2\x58\xdf\xf7\xe7"
         "\x60\xd0\x71\xcb\x59\x0b\xc8\x38\xaa\xeb\x1d\x95\x53\x88\x1c\xf5\xe0"
         "\xd6\x03\xce\xc2\x94\x0e\x27\xdd\xf9\x3e\x7e\x2a\x9e\x39\xe4\xb0\x6b"
         "\xa0\xbc\x7b\x36\x5a\x4e\x0e\x5a\xa5\x7a\xcb\xe0\x90\xe4\xbc\x03\x18"
         "\xbf\x1c\xba\x37\x24\x28\x2c\x64\xac\xc3\x10\x60\xd2\xe7\x6b\xa7\xfc"
         "\xa4\xd4\x98\x96\xb8\x79\xec\x30\x07\x72\x8c\x7a",
         165);
  syz_mount_image(0x20000000, 0x20000100, 0x4000000, 0x3c, 0x20000200, 0,
                  0x200007c0, 1);
  *(uint8_t*)0x20000040 = 0x12;
  *(uint8_t*)0x20000041 = 1;
  *(uint16_t*)0x20000042 = 0;
  *(uint8_t*)0x20000044 = 0x4b;
  *(uint8_t*)0x20000045 = 0xfe;
  *(uint8_t*)0x20000046 = 0xe9;
  *(uint8_t*)0x20000047 = 8;
  *(uint16_t*)0x20000048 = 0xfe6;
  *(uint16_t*)0x2000004a = 0x9800;
  *(uint16_t*)0x2000004c = 0x195d;
  *(uint8_t*)0x2000004e = 0;
  *(uint8_t*)0x2000004f = 0;
  *(uint8_t*)0x20000050 = 0;
  *(uint8_t*)0x20000051 = 1;
  *(uint8_t*)0x20000052 = 9;
  *(uint8_t*)0x20000053 = 2;
  *(uint16_t*)0x20000054 = 0x12;
  *(uint8_t*)0x20000056 = 1;
  *(uint8_t*)0x20000057 = 0;
  *(uint8_t*)0x20000058 = 0;
  *(uint8_t*)0x20000059 = 0;
  *(uint8_t*)0x2000005a = 0;
  *(uint8_t*)0x2000005b = 9;
  *(uint8_t*)0x2000005c = 4;
  *(uint8_t*)0x2000005d = 0;
  *(uint8_t*)0x2000005e = 0;
  *(uint8_t*)0x2000005f = 0;
  *(uint8_t*)0x20000060 = 0x2c;
  *(uint8_t*)0x20000061 = 0xeb;
  *(uint8_t*)0x20000062 = 0x14;
  *(uint8_t*)0x20000063 = 0;
  syz_usb_connect(0, 0x24, 0x20000040, 0);
  memcpy((void*)0x20002000, "./bus\000", 6);
  res = syscall(__NR_open, 0x20002000ul, 0x143142ul, 0ul);
  if (res != -1)
    r[0] = res;
  memcpy((void*)0x20002000, "./bus\000", 6);
  res = syscall(__NR_open, 0x20002000ul, 0x143042ul, 0ul);
  if (res != -1)
    r[1] = res;
  syscall(__NR_ftruncate, r[1], 0x2007ffbul);
  syscall(__NR_sendfile, r[0], r[1], 0ul, 0x1000000201005ul);
}
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;
}