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

#define _GNU_SOURCE

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

#define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
#define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len)               \
  *(type*)(addr) =                                                             \
      htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) |           \
            (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))

#ifndef __NR_bind
#define __NR_bind 361
#endif
#ifndef __NR_getsockname
#define __NR_getsockname 367
#endif
#ifndef __NR_mmap
#define __NR_mmap 192
#endif
#ifndef __NR_sendmsg
#define __NR_sendmsg 370
#endif
#ifndef __NR_socket
#define __NR_socket 359
#endif
#undef __NR_mmap
#define __NR_mmap __NR_mmap2

uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
                 0x0};

int main(void)
{
  syscall(__NR_mmap, 0x1ffff000, 0x1000, 0, 0x32, -1, 0);
  syscall(__NR_mmap, 0x20000000, 0x1000000, 7, 0x32, -1, 0);
  syscall(__NR_mmap, 0x21000000, 0x1000, 0, 0x32, -1, 0);
  intptr_t res = 0;
  res = syscall(__NR_socket, 0x10, 3, 0);
  if (res != -1)
    r[0] = res;
  *(uint32_t*)0x20000300 = 0;
  *(uint32_t*)0x20000304 = 0;
  *(uint32_t*)0x20000308 = 0x200002c0;
  *(uint32_t*)0x200002c0 = 0x20000000;
  *(uint32_t*)0x20000000 = 0x1c;
  *(uint16_t*)0x20000004 = 0x68;
  *(uint16_t*)0x20000006 = 3;
  *(uint32_t*)0x20000008 = 0;
  *(uint32_t*)0x2000000c = 0;
  *(uint8_t*)0x20000010 = 0;
  *(uint8_t*)0x20000011 = 0;
  *(uint8_t*)0x20000012 = 0;
  *(uint8_t*)0x20000013 = 0;
  *(uint32_t*)0x20000014 = 0;
  *(uint16_t*)0x20000018 = 4;
  *(uint16_t*)0x2000001a = 2;
  *(uint32_t*)0x200002c4 = 0x1c;
  *(uint32_t*)0x2000030c = 1;
  *(uint32_t*)0x20000310 = 0;
  *(uint32_t*)0x20000314 = 0;
  *(uint32_t*)0x20000318 = 0;
  syscall(__NR_sendmsg, (intptr_t)r[0], 0x20000300, 0);
  res = syscall(__NR_socket, 0x10, 3, 0);
  if (res != -1)
    r[1] = res;
  res = syscall(__NR_socket, 0x11, 3, 0);
  if (res != -1)
    r[2] = res;
  *(uint16_t*)0x20000080 = 0x11;
  memcpy((void*)0x20000082,
         "\x00\x00\x01\x00\x00\x00\x00\x00\x08\x00\x44\x94\x4e\xeb\xa7\x1a\x49"
         "\x76\xe2\x52\x92\x2c\xb1\x8f\x6e\x2e\x2a\xc5\x00\x00\x00\x01\x2e\x0b"
         "\x38\x36\x00\x54\x04\xb0\xe0\x30\x1a\x06\x00\x75\xf2\xe3\xff\x5f\x16"
         "\x3e\xe3\x40\xb7\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\xfd\x79\x2b"
         "\xbf\x0e\x5b\xf5\xff\x1b\x08\x16\xf3\xf6\xdb\x1c\x00\x01\x00\x00\x00"
         "\x00\x00\x00\x00\x49\x74\x00\x00\x00\x00\x00\x00\x00\x06\xad\x8e\x5e"
         "\xcc\x32\x6d\x3a\x09\xff\xc2\xc6\x54\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00",
         126);
  syscall(__NR_bind, (intptr_t)r[2], 0x20000080, 0x80);
  *(uint32_t*)0x20000140 = 0x14;
  res = syscall(__NR_getsockname, (intptr_t)r[2], 0x20000040, 0x20000140);
  if (res != -1)
    r[3] = *(uint32_t*)0x20000044;
  *(uint32_t*)0x20000580 = 0;
  *(uint32_t*)0x20000584 = 0;
  *(uint32_t*)0x20000588 = 0x20000780;
  *(uint32_t*)0x20000780 = 0x20000240;
  *(uint32_t*)0x20000240 = 0x28;
  *(uint16_t*)0x20000244 = 0x18;
  *(uint16_t*)0x20000246 = 0x8ddd;
  *(uint32_t*)0x20000248 = 0;
  *(uint32_t*)0x2000024c = 0;
  *(uint8_t*)0x20000250 = 2;
  *(uint8_t*)0x20000251 = 0;
  *(uint8_t*)0x20000252 = 0;
  *(uint8_t*)0x20000253 = 0;
  *(uint8_t*)0x20000254 = 0;
  *(uint8_t*)0x20000255 = 0;
  *(uint8_t*)0x20000256 = 0;
  *(uint8_t*)0x20000257 = 9;
  *(uint32_t*)0x20000258 = 0;
  *(uint16_t*)0x2000025c = 8;
  *(uint16_t*)0x2000025e = 0x1e;
  *(uint32_t*)0x20000260 = r[3];
  *(uint16_t*)0x20000264 = 4;
  STORE_BY_BITMASK(uint16_t, , 0x20000266, 8, 0, 14);
  STORE_BY_BITMASK(uint16_t, , 0x20000267, 0, 6, 1);
  STORE_BY_BITMASK(uint16_t, , 0x20000267, 1, 7, 1);
  *(uint32_t*)0x20000784 = 0x28;
  *(uint32_t*)0x2000058c = 1;
  *(uint32_t*)0x20000590 = 0;
  *(uint32_t*)0x20000594 = 0;
  *(uint32_t*)0x20000598 = 0;
  syscall(__NR_sendmsg, (intptr_t)r[1], 0x20000580, 0);
  return 0;
}