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

#define _GNU_SOURCE

#include <endian.h>
#include <pwd.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

#ifndef SYS___clone
#define SYS___clone 287
#endif
#ifndef SYS_ioctl
#define SYS_ioctl 54
#endif
#ifndef SYS_mmap
#define SYS_mmap 197
#endif
#ifndef SYS_socket
#define SYS_socket 394
#endif

static unsigned long long procid;

static void kill_and_wait(int pid, int* status)
{
  kill(pid, SIGKILL);
  while (waitpid(-1, status, 0) != pid) {
  }
}

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 execute_one(void);

#define WAIT_FLAGS 0

static void loop(void)
{
  int iter = 0;
  for (;; iter++) {
    int pid = fork();
    if (pid < 0)
      exit(1);
    if (pid == 0) {
      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[1] = {0xffffffffffffffff};

void execute_one(void)
{
  intptr_t res = 0;
  memcpy((void*)0x200000c0,
         "\xdb\x61\xd3\x3c\x83\x71\xe0\x00\xde\x73\x89\x6f\x19\x4c\xf9\x45\x62"
         "\x54\xcc\x0d\xbc\xb8\xd8\xd0\x08\xce\x36\xdb\x2d\x48\x67\xbe\xd1\xc4"
         "\xd3\x7e\x8c\x2e\x7e\x5e\xcd\xbb\xca\xba\x18\xb8\x31\xc4\x2b\x20\x05"
         "\x11\x77\xd5\x79\x06\xbd\x92\x40\x7e\x48\x8e\x80\x3a\x52\x76\xaf\x5f"
         "\x16\xca\xf1\x7a\x7e\x46\x87\x15\xb2\x82\x63\x95\x4e\xb8\x54\x15\x1e"
         "\xae\x2f\x98\x72\x62\xac\x38\x2b\x4a\xbf\x87\xca\xf0\x8c\x1c\xe4\xfa"
         "\x46\x39\xfa\x2e\x94\xf2\x89\x25\x83\x50\x0f\x16\x48\x8b\xfb\x94\x23"
         "\x5c\x94\xe3\x81\x35\x61\x74\xea\xbf\xdd\x3e\xdc\x74\xad\x38\x35\x8c"
         "\x87\x6d\xf3\x5f\x35\xdf\x2e\x33\xa5\xd1\x16\xfa\x44\x20\xcd\x9d\x7f"
         "\xbd\xe6\x84\x49\x9a\xc0\x77\x41\xbc\xf0\xa2\x12\x33\x70\xc6\x5e\x2d"
         "\xf4\x7d\x4b\xe4\x44\x60\xae\xf5\x9b\x91\x29\x56\x04\x62\xd8\x50\xba"
         "\x51\xf1\x4b\x90\x2a\xc8\x9f\xa4\xa6\x4f\xf2\x3b\x81\x19\x2f\xac\x51"
         "\x76\xa0\x54\x03\xac\x18\x42\xaf\xee\x24\xf4\x3e\xe3\x92\xf2\x6e\x24"
         "\x21\x2d\x77\x21\x5f\x2a\x0d\xfb\x39\xb0\x23\x73\x3b\x52\xb5\x1f\xa0"
         "\x29\xff\xa0\x7e\x48\x33\xb8\x05\x54\x20\xd9\xb4\x7e\x56",
         252);
  syscall(SYS___clone, 0x2800ul, 0x200000c0ul);
  res = syscall(SYS_socket, 0x10ul, 2ul, 0);
  if (res != -1)
    r[0] = res;
  *(uint64_t*)0x20000180 = 0x8000000000000032;
  syscall(SYS_ioctl, r[0], 0x8020690cul, 0x20000180ul);
}
int main(void)
{
  syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul);
  for (procid = 0; procid < 6; procid++) {
    if (fork() == 0) {
      loop();
    }
  }
  sleep(1000000);
  return 0;
}