mono_pagesize ()
{
  int saved_pagesize.0;
  int D.6580;
  int saved_pagesize.1;
  static int saved_pagesize = 0;

  saved_pagesize.0 = saved_pagesize;
  if (saved_pagesize.0 != 0) goto <D.6578>; else goto <D.6579>;
  <D.6578>:
  D.6580 = saved_pagesize;
  return D.6580;
  <D.6579>:
  saved_pagesize.1 = getpagesize ();
  saved_pagesize = saved_pagesize.1;
  D.6580 = saved_pagesize;
  return D.6580;
}


mono_valloc (void * addr, size_t length, int flags)
{
  int D.6583;
  int D.6586;
  void * D.6595;
  void * ptr;
  int mflags;
  int prot;

  mflags = 0;
  prot = prot_from_flags (flags);
  D.6583 = flags & 128;
  if (D.6583 != 0) goto <D.6584>; else goto <D.6585>;
  <D.6584>:
  mflags = mflags | 16;
  <D.6585>:
  D.6586 = flags & 256;
  if (D.6586 != 0) goto <D.6587>; else goto <D.6588>;
  <D.6587>:
  mflags = mflags;
  <D.6588>:
  mflags = mflags | 2048;
  mflags = mflags | 2;
  ptr = mmap (addr, length, prot, mflags, -1, 0);
  if (ptr == 4294967295B) goto <D.6589>; else goto <D.6590>;
  <D.6589>:
  {
    int fd;

    fd = open ("/dev/zero", 0);
    if (fd != -1) goto <D.6591>; else goto <D.6592>;
    <D.6591>:
    ptr = mmap (addr, length, prot, mflags, fd, 0);
    close (fd);
    <D.6592>:
    if (ptr == 4294967295B) goto <D.6593>; else goto <D.6594>;
    <D.6593>:
    D.6595 = 0B;
    return D.6595;
    <D.6594>:
  }
  <D.6590>:
  D.6595 = ptr;
  return D.6595;
}


prot_from_flags (int flags)
{
  int D.6597;
  int D.6600;
  int D.6603;
  int D.6606;
  int prot;

  prot = 0;
  D.6597 = flags & 1;
  if (D.6597 != 0) goto <D.6598>; else goto <D.6599>;
  <D.6598>:
  prot = prot | 1;
  <D.6599>:
  D.6600 = flags & 2;
  if (D.6600 != 0) goto <D.6601>; else goto <D.6602>;
  <D.6601>:
  prot = prot | 2;
  <D.6602>:
  D.6603 = flags & 4;
  if (D.6603 != 0) goto <D.6604>; else goto <D.6605>;
  <D.6604>:
  prot = prot | 4;
  <D.6605>:
  D.6606 = prot;
  return D.6606;
}


open (const char * __path, int __oflag)
{
  int D.6608;
  int D.6611;
  int D.6616;
  int D.6618;
  int D.6619;
  int D.6622;
  int D.6623;

  D.6608 = __builtin_va_arg_pack_len ();
  if (D.6608 > 1) goto <D.6609>; else goto <D.6610>;
  <D.6609>:
  __open_too_many_args ();
  <D.6610>:
  D.6611 = __builtin_constant_p (__oflag);
  if (D.6611 != 0) goto <D.6612>; else goto <D.6613>;
  <D.6612>:
  D.6616 = __oflag & 256;
  if (D.6616 != 0) goto <D.6614>; else goto <D.6617>;
  <D.6617>:
  D.6618 = __oflag & 4259840;
  if (D.6618 == 4259840) goto <D.6614>; else goto <D.6615>;
  <D.6614>:
  D.6619 = __builtin_va_arg_pack_len ();
  if (D.6619 <= 0) goto <D.6620>; else goto <D.6621>;
  <D.6620>:
  __open_missing_mode ();
  D.6622 = __open_2 (__path, __oflag);
  return D.6622;
  <D.6621>:
  <D.6615>:
  D.6622 = __open_alias (__path, __oflag, __builtin_va_arg_pack ());
  return D.6622;
  <D.6613>:
  D.6623 = __builtin_va_arg_pack_len ();
  if (D.6623 <= 0) goto <D.6624>; else goto <D.6625>;
  <D.6624>:
  D.6622 = __open_2 (__path, __oflag);
  return D.6622;
  <D.6625>:
  D.6622 = __open_alias (__path, __oflag, __builtin_va_arg_pack ());
  return D.6622;
}


mono_vfree (void * addr, size_t length)
{
  int D.6627;

  D.6627 = munmap (addr, length);
  return D.6627;
}


mono_file_map (size_t length, int flags, int fd, guint64 offset, void * * ret_handle)
{
  int D.6629;
  int D.6632;
  int D.6635;
  int D.6638;
  long long int offset.2;
  void * D.6644;
  void * length.3;
  void * ptr;
  int mflags;
  int prot;

  mflags = 0;
  prot = prot_from_flags (flags);
  D.6629 = flags & 16;
  if (D.6629 != 0) goto <D.6630>; else goto <D.6631>;
  <D.6630>:
  mflags = mflags | 2;
  <D.6631>:
  D.6632 = flags & 32;
  if (D.6632 != 0) goto <D.6633>; else goto <D.6634>;
  <D.6633>:
  mflags = mflags | 1;
  <D.6634>:
  D.6635 = flags & 128;
  if (D.6635 != 0) goto <D.6636>; else goto <D.6637>;
  <D.6636>:
  mflags = mflags | 16;
  <D.6637>:
  D.6638 = flags & 256;
  if (D.6638 != 0) goto <D.6639>; else goto <D.6640>;
  <D.6639>:
  mflags = mflags;
  <D.6640>:
  offset.2 = (long long int) offset;
  ptr = mmap (0B, length, prot, mflags, fd, offset.2);
  if (ptr == 4294967295B) goto <D.6642>; else goto <D.6643>;
  <D.6642>:
  D.6644 = 0B;
  return D.6644;
  <D.6643>:
  length.3 = (void *) length;
  *ret_handle = length.3;
  D.6644 = ptr;
  return D.6644;
}


mono_file_unmap (void * addr, void * handle)
{
  int D.6647;
  unsigned int handle.4;

  handle.4 = (unsigned int) handle;
  D.6647 = munmap (addr, handle.4);
  return D.6647;
}


mono_mprotect (void * addr, size_t length, int flags)
{
  int D.6650;
  int D.6653;
  int D.6656;
  int prot;

  prot = prot_from_flags (flags);
  D.6650 = flags & 8;
  if (D.6650 != 0) goto <D.6651>; else goto <D.6652>;
  <D.6651>:
  D.6653 = madvise (addr, length, 4);
  if (D.6653 != 0) goto <D.6654>; else goto <D.6655>;
  <D.6654>:
  memset (addr, 0, length);
  <D.6655>:
  <D.6652>:
  D.6656 = mprotect (addr, length, prot);
  return D.6656;
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.6660;
  int D.6665;
  void * D.6667;
  unsigned int D.6668;

  D.6660 = __builtin_constant_p (__len);
  if (D.6660 != 0) goto <D.6661>; else goto <D.6662>;
  <D.6661>:
  if (__len == 0) goto <D.6663>; else goto <D.6664>;
  <D.6663>:
  D.6665 = __builtin_constant_p (__ch);
  if (D.6665 == 0) goto <D.6658>; else goto <D.6666>;
  <D.6666>:
  if (__ch != 0) goto <D.6658>; else goto <D.6659>;
  <D.6658>:
  __warn_memset_zero_len ();
  D.6667 = __dest;
  return D.6667;
  <D.6659>:
  <D.6664>:
  <D.6662>:
  D.6668 = __builtin_object_size (__dest, 0);
  D.6667 = __builtin___memset_chk (__dest, __ch, __len, D.6668);
  return D.6667;
}


mono_shared_area ()
{
  int D.6670;
  void * malloced_shared_area.5;
  void * malloced_shared_area.6;
  void * D.6677;
  int * D.6680;
  int D.6681;
  long long int D.6686;
  int D.6687;
  unsigned int size.7;
  int fd;
  int pid;
  int size;
  char buf[128];
  void * res;
  struct SAreaHeader * header;

  try
    {
      pid = getpid ();
      size = mono_pagesize ();
      D.6670 = shared_area_disabled ();
      if (D.6670 != 0) goto <D.6671>; else goto <D.6672>;
      <D.6671>:
      malloced_shared_area.5 = malloced_shared_area;
      if (malloced_shared_area.5 == 0B) goto <D.6674>; else goto <D.6675>;
      <D.6674>:
      malloced_shared_area.6 = malloc_shared_area (0);
      malloced_shared_area = malloced_shared_area.6;
      <D.6675>:
      D.6677 = malloced_shared_area;
      return D.6677;
      <D.6672>:
      mono_shared_area_instances_helper (0B, 0, 1);
      monoeg_g_snprintf (&buf, 128, "/mono.%d", pid);
      fd = shm_open (&buf, 1282, 416);
      if (fd == -1) goto <D.6678>; else goto <D.6679>;
      <D.6678>:
      D.6680 = __errno_location ();
      D.6681 = *D.6680;
      if (D.6681 == 17) goto <D.6682>; else goto <D.6683>;
      <D.6682>:
      shm_unlink (&buf);
      fd = shm_open (&buf, 1282, 416);
      <D.6683>:
      <D.6679>:
      if (fd == -1) goto <D.6684>; else goto <D.6685>;
      <D.6684>:
      D.6677 = malloc_shared_area (pid);
      return D.6677;
      <D.6685>:
      D.6686 = (long long int) size;
      D.6687 = ftruncate (fd, D.6686);
      if (D.6687 != 0) goto <D.6688>; else goto <D.6689>;
      <D.6688>:
      shm_unlink (&buf);
      close (fd);
      <D.6689>:
      size.7 = (unsigned int) size;
      res = mmap (0B, size.7, 3, 1, fd, 0);
      if (res == 4294967295B) goto <D.6691>; else goto <D.6692>;
      <D.6691>:
      shm_unlink (&buf);
      close (fd);
      D.6677 = malloc_shared_area (pid);
      return D.6677;
      <D.6692>:
      close (fd);
      header = res;
      header->size = size;
      header->pid = pid;
      header->stats_start = 16;
      header->stats_end = 16;
      atexit (mono_shared_area_remove);
      D.6677 = res;
      return D.6677;
    }
  finally
    {
      buf = {CLOBBER};
    }
}


shared_area_disabled ()
{
  int use_shared_area.8;
  const gchar * D.6698;
  gboolean D.6702;
  _Bool D.6703;

  use_shared_area.8 = use_shared_area;
  if (use_shared_area.8 == 0) goto <D.6696>; else goto <D.6697>;
  <D.6696>:
  D.6698 = monoeg_g_getenv ("MONO_DISABLE_SHARED_AREA");
  if (D.6698 != 0B) goto <D.6699>; else goto <D.6700>;
  <D.6699>:
  use_shared_area = -1;
  goto <D.6701>;
  <D.6700>:
  use_shared_area = 1;
  <D.6701>:
  <D.6697>:
  use_shared_area.8 = use_shared_area;
  D.6703 = use_shared_area.8 == -1;
  D.6702 = (gboolean) D.6703;
  return D.6702;
}


mono_shared_area_instances_helper (void * * array, int count, gboolean cleanup)
{
  int D.6707;
  int D.6708;
  const char * D.6711;
  char * nend.9;
  char D.6717;
  int i.10;
  unsigned int i.11;
  unsigned int D.6723;
  void * * D.6724;
  void * pid.12;
  int D.6730;
  int * D.6733;
  int D.6734;
  const char * name;
  int i;
  int curpid;
  struct GDir * dir;

  i = 0;
  curpid = getpid ();
  dir = monoeg_g_dir_open ("/dev/shm/", 0, 0B);
  if (dir == 0B) goto <D.6705>; else goto <D.6706>;
  <D.6705>:
  D.6707 = mono_shared_area_instances_slow (array, count, cleanup);
  return D.6707;
  <D.6706>:
  goto <D.6538>;
  <D.6541>:
  {
    int pid;
    char * nend;

    try
      {
        D.6708 = strncmp (name, "mono.", 5);
        if (D.6708 != 0) goto <D.6709>; else goto <D.6710>;
        <D.6709>:
        // predicted unlikely by continue predictor.
        goto <D.6538>;
        <D.6710>:
        D.6711 = name + 5;
        pid = strtol (D.6711, &nend, 10);
        if (pid <= 0) goto <D.6712>; else goto <D.6714>;
        <D.6714>:
        D.6711 = name + 5;
        nend.9 = nend;
        if (D.6711 == nend.9) goto <D.6712>; else goto <D.6716>;
        <D.6716>:
        nend.9 = nend;
        D.6717 = *nend.9;
        if (D.6717 != 0) goto <D.6712>; else goto <D.6713>;
        <D.6712>:
        // predicted unlikely by continue predictor.
        goto <D.6538>;
        <D.6713>:
        if (cleanup == 0) goto <D.6718>; else goto <D.6719>;
        <D.6718>:
        if (i < count) goto <D.6720>; else goto <D.6539>;
        <D.6720>:
        i.10 = i;
        i = i.10 + 1;
        i.11 = (unsigned int) i.10;
        D.6723 = i.11 * 4;
        D.6724 = array + D.6723;
        pid.12 = (void *) pid;
        *D.6724 = pid.12;
        <D.6719>:
        if (curpid != pid) goto <D.6728>; else goto <D.6729>;
        <D.6728>:
        D.6730 = kill (pid, 0);
        if (D.6730 == -1) goto <D.6731>; else goto <D.6732>;
        <D.6731>:
        D.6733 = __errno_location ();
        D.6734 = *D.6733;
        if (D.6734 == 3) goto <D.6726>; else goto <D.6735>;
        <D.6735>:
        D.6733 = __errno_location ();
        D.6734 = *D.6733;
        if (D.6734 == 12) goto <D.6726>; else goto <D.6727>;
        <D.6726>:
        {
          char buf[128];

          try
            {
              monoeg_g_snprintf (&buf, 128, "/mono.%d", pid);
              shm_unlink (&buf);
            }
          finally
            {
              buf = {CLOBBER};
            }
        }
        <D.6727>:
        <D.6732>:
        <D.6729>:
      }
    finally
      {
        nend = {CLOBBER};
      }
  }
  <D.6538>:
  name = monoeg_g_dir_read_name (dir);
  if (name != 0B) goto <D.6541>; else goto <D.6539>;
  <D.6539>:
  monoeg_g_dir_close (dir);
  D.6707 = i;
  return D.6707;
}


mono_shared_area_instances_slow (void * * array, int count, gboolean cleanup)
{
  unsigned int i.13;
  unsigned int D.6741;
  void * * D.6742;
  void * D.6743;
  int j.14;
  unsigned int j.15;
  unsigned int D.6751;
  void * * D.6752;
  int num.16;
  int D.6754;
  int i;
  int j;
  int num;
  void * data;
  void * * processes;

  try
    {
      j = 0;
      processes = mono_process_list (&num);
      i = 0;
      goto <D.6517>;
      <D.6516>:
      i.13 = (unsigned int) i;
      D.6741 = i.13 * 4;
      D.6742 = processes + D.6741;
      D.6743 = *D.6742;
      data = mono_shared_area_for_pid (D.6743);
      if (data == 0B) goto <D.6744>; else goto <D.6745>;
      <D.6744>:
      // predicted unlikely by continue predictor.
      goto <D.6514>;
      <D.6745>:
      mono_shared_area_unload (data);
      if (cleanup == 0) goto <D.6746>; else goto <D.6747>;
      <D.6746>:
      if (j < count) goto <D.6748>; else goto <D.6515>;
      <D.6748>:
      j.14 = j;
      j = j.14 + 1;
      j.15 = (unsigned int) j.14;
      D.6751 = j.15 * 4;
      D.6752 = array + D.6751;
      i.13 = (unsigned int) i;
      D.6741 = i.13 * 4;
      D.6742 = processes + D.6741;
      D.6743 = *D.6742;
      *D.6752 = D.6743;
      <D.6747>:
      <D.6514>:
      i = i + 1;
      <D.6517>:
      num.16 = num;
      if (i < num.16) goto <D.6516>; else goto <D.6515>;
      <D.6515>:
      monoeg_g_free (processes);
      D.6754 = j;
      return D.6754;
    }
  finally
    {
      num = {CLOBBER};
    }
}


malloc_shared_area (int pid)
{
  unsigned int size.17;
  void * D.6758;
  int size;
  struct SAreaHeader * sarea;

  size = mono_pagesize ();
  size.17 = (unsigned int) size;
  sarea = monoeg_malloc0 (size.17);
  sarea->size = size;
  sarea->pid = pid;
  sarea->stats_start = 16;
  sarea->stats_end = 16;
  D.6758 = sarea;
  return D.6758;
}


mono_shared_area_remove ()
{
  int D.6760;
  void * malloced_shared_area.18;
  int D.6766;
  char buf[128];

  try
    {
      D.6760 = shared_area_disabled ();
      if (D.6760 != 0) goto <D.6761>; else goto <D.6762>;
      <D.6761>:
      malloced_shared_area.18 = malloced_shared_area;
      if (malloced_shared_area.18 != 0B) goto <D.6764>; else goto <D.6765>;
      <D.6764>:
      malloced_shared_area.18 = malloced_shared_area;
      monoeg_g_free (malloced_shared_area.18);
      <D.6765>:
      return;
      <D.6762>:
      D.6766 = getpid ();
      monoeg_g_snprintf (&buf, 128, "/mono.%d", D.6766);
      shm_unlink (&buf);
      malloced_shared_area.18 = malloced_shared_area;
      if (malloced_shared_area.18 != 0B) goto <D.6767>; else goto <D.6768>;
      <D.6767>:
      malloced_shared_area.18 = malloced_shared_area;
      monoeg_g_free (malloced_shared_area.18);
      <D.6768>:
    }
  finally
    {
      buf = {CLOBBER};
    }
}


mono_shared_area_for_pid (void * pid)
{
  int D.6772;
  void * D.6775;
  int pid.19;
  unsigned int size.20;
  int fd;
  int size;
  char buf[128];
  void * res;

  try
    {
      size = mono_pagesize ();
      D.6772 = shared_area_disabled ();
      if (D.6772 != 0) goto <D.6773>; else goto <D.6774>;
      <D.6773>:
      D.6775 = 0B;
      return D.6775;
      <D.6774>:
      pid.19 = (int) pid;
      monoeg_g_snprintf (&buf, 128, "/mono.%d", pid.19);
      fd = shm_open (&buf, 0, 288);
      if (fd == -1) goto <D.6777>; else goto <D.6778>;
      <D.6777>:
      D.6775 = 0B;
      return D.6775;
      <D.6778>:
      size.20 = (unsigned int) size;
      res = mmap (0B, size.20, 1, 1, fd, 0);
      if (res == 4294967295B) goto <D.6780>; else goto <D.6781>;
      <D.6780>:
      close (fd);
      D.6775 = 0B;
      return D.6775;
      <D.6781>:
      close (fd);
      D.6775 = res;
      return D.6775;
    }
  finally
    {
      buf = {CLOBBER};
    }
}


mono_shared_area_unload (void * area)
{
  int D.6784;
  unsigned int D.6785;

  D.6784 = mono_pagesize ();
  D.6785 = (unsigned int) D.6784;
  munmap (area, D.6785);
}


mono_shared_area_instances (void * * array, int count)
{
  int D.6786;

  D.6786 = mono_shared_area_instances_helper (array, count, 0);
  return D.6786;
}


mono_valloc_aligned (size_t size, size_t alignment, int flags)
{
  unsigned int D.6788;
  void * D.6791;
  int aligned.21;
  int mem.22;
  int D.6796;
  unsigned int D.6797;
  char * D.6798;
  sizetype D.6799;
  char * D.6800;
  void * D.6803;
  int mem.23;
  int aligned.24;
  int D.6806;
  int D.6807;
  int size.25;
  int D.6809;
  int D.6810;
  unsigned int D.6811;
  char * mem;
  char * aligned;

  D.6788 = size + alignment;
  mem = mono_valloc (0B, D.6788, flags);
  if (mem == 0B) goto <D.6789>; else goto <D.6790>;
  <D.6789>:
  D.6791 = 0B;
  return D.6791;
  <D.6790>:
  aligned = aligned_address (mem, size, alignment);
  if (aligned > mem) goto <D.6792>; else goto <D.6793>;
  <D.6792>:
  aligned.21 = (int) aligned;
  mem.22 = (int) mem;
  D.6796 = aligned.21 - mem.22;
  D.6797 = (unsigned int) D.6796;
  mono_vfree (mem, D.6797);
  <D.6793>:
  D.6798 = aligned + size;
  D.6799 = size + alignment;
  D.6800 = mem + D.6799;
  if (D.6798 < D.6800) goto <D.6801>; else goto <D.6802>;
  <D.6801>:
  D.6803 = aligned + size;
  mem.23 = (int) mem;
  aligned.24 = (int) aligned;
  D.6806 = mem.23 - aligned.24;
  D.6799 = size + alignment;
  D.6807 = (int) D.6799;
  size.25 = (int) size;
  D.6809 = D.6807 - size.25;
  D.6810 = D.6806 + D.6809;
  D.6811 = (unsigned int) D.6810;
  mono_vfree (D.6803, D.6811);
  <D.6802>:
  D.6791 = aligned;
  return D.6791;
}


aligned_address (char * mem, size_t size, size_t alignment)
{
  sizetype D.6813;
  char * D.6814;
  long unsigned int D.6815;
  unsigned int D.6816;
  long unsigned int D.6817;
  int iftmp.26;
  char * D.6823;
  sizetype D.6824;
  char * D.6825;
  unsigned int D.6827;
  long unsigned int aligned.27;
  long unsigned int D.6829;
  _Bool D.6830;
  long int D.6831;
  long int D.6832;
  char * D.6835;
  char * aligned;

  D.6813 = alignment + 4294967295;
  D.6814 = mem + D.6813;
  D.6815 = (long unsigned int) D.6814;
  D.6816 = -alignment;
  D.6817 = D.6815 & D.6816;
  aligned = (char *) D.6817;
  if (aligned < mem) goto <D.6819>; else goto <D.6822>;
  <D.6822>:
  D.6823 = aligned + size;
  D.6824 = size + alignment;
  D.6825 = mem + D.6824;
  if (D.6823 > D.6825) goto <D.6819>; else goto <D.6826>;
  <D.6826>:
  D.6827 = alignment + 4294967295;
  aligned.27 = (long unsigned int) aligned;
  D.6829 = D.6827 & aligned.27;
  if (D.6829 != 0) goto <D.6819>; else goto <D.6820>;
  <D.6819>:
  iftmp.26 = 1;
  goto <D.6821>;
  <D.6820>:
  iftmp.26 = 0;
  <D.6821>:
  D.6830 = iftmp.26 != 0;
  D.6831 = (long int) D.6830;
  D.6832 = __builtin_expect (D.6831, 0);
  if (D.6832 != 0) goto <D.6833>; else goto <D.6834>;
  <D.6833>:
  monoeg_assertion_message ("* Assertion at %s:%d, condition `%s\' not met\n", "mono-mmap.c", 69, "aligned >= mem && aligned + size <= mem + size + alignment && !((gulong)aligned & (alignment - 1))");
  <D.6834>:
  D.6835 = aligned;
  return D.6835;
}


