// https://syzkaller.appspot.com/bug?id=f3910842f03bd71d807dc52968523ba9cf813bbb
// 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[1] = {0xffffffffffffffff};

int main(void)
{
  syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
  intptr_t res = 0;
  memcpy((void*)0x20000000, "/dev/swradio#\000", 14);
  res = syz_open_dev(0x20000000, 0, 2);
  if (res != -1)
    r[0] = res;
  *(uint32_t*)0x20001440 = 0;
  *(uint32_t*)0x20001444 = 9;
  *(uint32_t*)0x20001448 = 1;
  *(uint32_t*)0x20001450 = 0xb;
  *(uint32_t*)0x20001458 = 0;
  *(uint32_t*)0x2000145c = 0xffff;
  *(uint32_t*)0x20001460 = 0;
  *(uint32_t*)0x20001464 = 0;
  *(uint32_t*)0x20001468 = 0;
  *(uint32_t*)0x2000146c = 0;
  *(uint64_t*)0x20001470 = 0;
  *(uint32_t*)0x20001478 = 0;
  *(uint64_t*)0x20001480 = 0;
  *(uint8_t*)0x20001488 = 0;
  *(uint32_t*)0x20001520 = 0;
  *(uint32_t*)0x20001524 = 0;
  *(uint32_t*)0x20001528 = 0;
  *(uint32_t*)0x2000152c = 0;
  *(uint32_t*)0x20001530 = 0;
  *(uint32_t*)0x20001534 = 0;
  *(uint32_t*)0x20001538 = 0;
  *(uint32_t*)0x2000153c = 0;
  syscall(__NR_ioctl, r[0], 0xc100565c, 0x20001440);
  *(uint32_t*)0x20000040 = 0;
  *(uint32_t*)0x20000044 = 7;
  *(uint32_t*)0x20000048 = 2;
  *(uint32_t*)0x20000050 = 0xb;
  *(uint16_t*)0x20000058 = 0;
  *(uint16_t*)0x2000005a = 0;
  *(uint16_t*)0x2000005c = 0x3f;
  *(uint16_t*)0x2000005e = 0;
  *(uint16_t*)0x20000060 = 0;
  *(uint16_t*)0x20000062 = 0;
  *(uint16_t*)0x20000064 = 0;
  *(uint16_t*)0x20000066 = 0;
  *(uint16_t*)0x20000068 = 0;
  *(uint16_t*)0x2000006a = 0;
  *(uint16_t*)0x2000006c = 0;
  *(uint16_t*)0x2000006e = 0;
  *(uint16_t*)0x20000070 = 0;
  *(uint16_t*)0x20000072 = 0;
  *(uint16_t*)0x20000074 = 0;
  *(uint16_t*)0x20000076 = 0;
  *(uint16_t*)0x20000078 = 0;
  *(uint16_t*)0x2000007a = 0;
  *(uint16_t*)0x2000007c = 0;
  *(uint16_t*)0x2000007e = 0;
  *(uint16_t*)0x20000080 = 0;
  *(uint16_t*)0x20000082 = 0;
  *(uint16_t*)0x20000084 = 0;
  *(uint16_t*)0x20000086 = 0;
  *(uint16_t*)0x20000088 = 0;
  *(uint16_t*)0x2000008a = 0;
  *(uint16_t*)0x2000008c = 0;
  *(uint16_t*)0x2000008e = 0;
  *(uint16_t*)0x20000090 = 0;
  *(uint16_t*)0x20000092 = 0;
  *(uint16_t*)0x20000094 = 0;
  *(uint16_t*)0x20000096 = 0;
  *(uint16_t*)0x20000098 = 0;
  *(uint16_t*)0x2000009a = 0;
  *(uint16_t*)0x2000009c = 0;
  *(uint16_t*)0x2000009e = 0;
  *(uint16_t*)0x200000a0 = 0;
  *(uint16_t*)0x200000a2 = 0;
  *(uint16_t*)0x200000a4 = 0;
  *(uint16_t*)0x200000a6 = 0;
  *(uint16_t*)0x200000a8 = 0;
  *(uint16_t*)0x200000aa = 0;
  *(uint16_t*)0x200000ac = 0;
  *(uint16_t*)0x200000ae = 0;
  *(uint16_t*)0x200000b0 = 0;
  *(uint16_t*)0x200000b2 = 0;
  *(uint16_t*)0x200000b4 = 0;
  *(uint16_t*)0x200000b6 = 0;
  *(uint16_t*)0x200000b8 = 0;
  *(uint32_t*)0x200000bc = 0;
  *(uint32_t*)0x200000c0 = 0;
  *(uint32_t*)0x200000c4 = 0;
  *(uint32_t*)0x20000120 = 0;
  *(uint32_t*)0x20000124 = 0;
  *(uint32_t*)0x20000128 = 0;
  *(uint32_t*)0x2000012c = 0;
  *(uint32_t*)0x20000130 = 0;
  *(uint32_t*)0x20000134 = 0;
  *(uint32_t*)0x20000138 = 0;
  *(uint32_t*)0x2000013c = 0;
  syscall(__NR_ioctl, r[0], 0xc100565c, 0x20000040);
  return 0;
}