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

#define _GNU_SOURCE

#include <endian.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>

static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
{
  if (a0 == 0xc || a0 == 0xb) {
    char buf[128];
    sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1,
            (uint8_t)a2);
    return open(buf, O_RDWR, 0);
  } else {
    char buf[1024];
    char* hash;
    strncpy(buf, (char*)a0, sizeof(buf) - 1);
    buf[sizeof(buf) - 1] = 0;
    while ((hash = strchr(buf, '#'))) {
      *hash = '0' + (char)(a1 % 10);
      a1 /= 10;
    }
    return open(buf, a2, 0);
  }
}

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

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);
  intptr_t res = 0;
  memcpy((void*)0x20000040, "/dev/loop#\000", 11);
  res = -1;
  res = syz_open_dev(0x20000040, 0, 0x10d082);
  if (res != -1)
    r[0] = res;
  memcpy((void*)0x20000000, "/proc/self/exe\000", 15);
  res = syscall(__NR_openat, 0xffffff9c, 0x20000000ul, 0ul, 0ul);
  if (res != -1)
    r[1] = res;
  syscall(__NR_ioctl, r[0], 0x4c00, r[1]);
  syscall(__NR_mmap, 0x20000000ul, 0x600000ul, 2ul, 0x11ul, r[0], 0ul);
  *(uint32_t*)0x20000280 = 0;
  *(uint16_t*)0x20000288 = 0;
  *(uint64_t*)0x20000290 = 0;
  *(uint16_t*)0x20000298 = 0;
  *(uint32_t*)0x200002a0 = 9;
  *(uint32_t*)0x200002a4 = 0;
  *(uint32_t*)0x200002a8 = 0;
  *(uint32_t*)0x200002ac = 0;
  memcpy((void*)0x200002b0,
         "\x3d\x0e\x6b\x6c\xee\xa9\xca\x56\x2b\xeb\x8e\x94\x26\x3b\x80\xe4\xd9"
         "\x74\x05\xc2\x69\x9b\xbc\x5c\xa9\x93\x60\x92\x1e\x84\x7e\x00\xc5\x8f"
         "\x96\xec\xa5\xb9\x9e\xbf\x76\x10\xb2\x14\xf9\x84\x25\xea\xc0\x42\xe8"
         "\x23\x00\xbd\x1e\x75\x7f\x5a\x8c\x0a\xd6\x57\x5f\xfa",
         64);
  memcpy((void*)0x200002f0,
         "\x5f\x2c\x2f\x90\x8f\x37\xe2\x4a\x65\x38\x3a\x0a\x41\xcb\xf8\x8b\x31"
         "\x8c\xc1\x30\xcd\xb1\x8e\xee\xf7\x7d\x7e\xd4\x28\x44\x3a\x4a",
         32);
  *(uint64_t*)0x20000310 = 0;
  *(uint64_t*)0x20000318 = 0;
  *(uint32_t*)0x20000320 = 0;
  syscall(__NR_ioctl, r[0], 0x4c02, 0x20000280ul);
  return 0;
}