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

  saved_pagesize.0 = saved_pagesize;
  if (saved_pagesize.0 != 0) goto <D.6623>; else goto <D.6624>;
  <D.6623>:
  D.6625 = saved_pagesize;
  return D.6625;
  <D.6624>:
  saved_pagesize.1 = getpagesize ();
  saved_pagesize = saved_pagesize.1;
  D.6625 = saved_pagesize;
  return D.6625;
}


mono_valloc (void * addr, size_t length, int flags)
{
  int D.6628;
  int D.6631;
  void * D.6640;
  void * ptr;
  int mflags;
  int prot;

  mflags = 0;
  prot = prot_from_flags (flags);
  D.6628 = flags & 128;
  if (D.6628 != 0) goto <D.6629>; else goto <D.6630>;
  <D.6629>:
  mflags = mflags | 16;
  <D.6630>:
  D.6631 = flags & 256;
  if (D.6631 != 0) goto <D.6632>; else goto <D.6633>;
  <D.6632>:
  mflags = mflags | 64;
  <D.6633>:
  mflags = mflags | 32;
  mflags = mflags | 2;
  ptr = mmap (addr, length, prot, mflags, -1, 0);
  if (ptr == 4294967295B) goto <D.6634>; else goto <D.6635>;
  <D.6634>:
  {
    int fd;

    fd = open ("/dev/zero", 0);
    if (fd != -1) goto <D.6636>; else goto <D.6637>;
    <D.6636>:
    ptr = mmap (addr, length, prot, mflags, fd, 0);
    close (fd);
    <D.6637>:
    if (ptr == 4294967295B) goto <D.6638>; else goto <D.6639>;
    <D.6638>:
    D.6640 = 0B;
    return D.6640;
    <D.6639>:
  }
  <D.6635>:
  D.6640 = ptr;
  return D.6640;
}


prot_from_flags (int flags)
{
  int D.6642;
  int D.6645;
  int D.6648;
  int D.6651;
  int prot;

  prot = 0;
  D.6642 = flags & 1;
  if (D.6642 != 0) goto <D.6643>; else goto <D.6644>;
  <D.6643>:
  prot = prot | 1;
  <D.6644>:
  D.6645 = flags & 2;
  if (D.6645 != 0) goto <D.6646>; else goto <D.6647>;
  <D.6646>:
  prot = prot | 2;
  <D.6647>:
  D.6648 = flags & 4;
  if (D.6648 != 0) goto <D.6649>; else goto <D.6650>;
  <D.6649>:
  prot = prot | 4;
  <D.6650>:
  D.6651 = prot;
  return D.6651;
}


open (const char * __path, int __oflag)
{
  int D.6653;
  int D.6656;
  int D.6661;
  int D.6663;
  int D.6664;
  int D.6667;
  int D.6668;

  D.6653 = __builtin_va_arg_pack_len ();
  if (D.6653 > 1) goto <D.6654>; else goto <D.6655>;
  <D.6654>:
  __open_too_many_args ();
  <D.6655>:
  D.6656 = __builtin_constant_p (__oflag);
  if (D.6656 != 0) goto <D.6657>; else goto <D.6658>;
  <D.6657>:
  D.6661 = __oflag & 64;
  if (D.6661 != 0) goto <D.6659>; else goto <D.6662>;
  <D.6662>:
  D.6663 = __oflag & 4259840;
  if (D.6663 == 4259840) goto <D.6659>; else goto <D.6660>;
  <D.6659>:
  D.6664 = __builtin_va_arg_pack_len ();
  if (D.6664 <= 0) goto <D.6665>; else goto <D.6666>;
  <D.6665>:
  __open_missing_mode ();
  D.6667 = __open_2 (__path, __oflag);
  return D.6667;
  <D.6666>:
  <D.6660>:
  D.6667 = __open_alias (__path, __oflag, __builtin_va_arg_pack ());
  return D.6667;
  <D.6658>:
  D.6668 = __builtin_va_arg_pack_len ();
  if (D.6668 <= 0) goto <D.6669>; else goto <D.6670>;
  <D.6669>:
  D.6667 = __open_2 (__path, __oflag);
  return D.6667;
  <D.6670>:
  D.6667 = __open_alias (__path, __oflag, __builtin_va_arg_pack ());
  return D.6667;
}


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

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


mono_file_map (size_t length, int flags, int fd, guint64 offset, void * * ret_handle)
{
  int D.6674;
  int D.6677;
  int D.6680;
  int D.6683;
  long long int offset.2;
  void * D.6689;
  void * length.3;
  void * ptr;
  int mflags;
  int prot;

  mflags = 0;
  prot = prot_from_flags (flags);
  D.6674 = flags & 16;
  if (D.6674 != 0) goto <D.6675>; else goto <D.6676>;
  <D.6675>:
  mflags = mflags | 2;
  <D.6676>:
  D.6677 = flags & 32;
  if (D.6677 != 0) goto <D.6678>; else goto <D.6679>;
  <D.6678>:
  mflags = mflags | 1;
  <D.6679>:
  D.6680 = flags & 128;
  if (D.6680 != 0) goto <D.6681>; else goto <D.6682>;
  <D.6681>:
  mflags = mflags | 16;
  <D.6682>:
  D.6683 = flags & 256;
  if (D.6683 != 0) goto <D.6684>; else goto <D.6685>;
  <D.6684>:
  mflags = mflags | 64;
  <D.6685>:
  offset.2 = (long long int) offset;
  ptr = mmap (0B, length, prot, mflags, fd, offset.2);
  if (ptr == 4294967295B) goto <D.6687>; else goto <D.6688>;
  <D.6687>:
  D.6689 = 0B;
  return D.6689;
  <D.6688>:
  length.3 = (void *) length;
  *ret_handle = length.3;
  D.6689 = ptr;
  return D.6689;
}


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

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


mono_mprotect (void * addr, size_t length, int flags)
{
  int D.6695;
  int D.6698;
  int D.6701;
  int prot;

  prot = prot_from_flags (flags);
  D.6695 = flags & 8;
  if (D.6695 != 0) goto <D.6696>; else goto <D.6697>;
  <D.6696>:
  D.6698 = madvise (addr, length, 4);
  if (D.6698 != 0) goto <D.6699>; else goto <D.6700>;
  <D.6699>:
  memset (addr, 0, length);
  <D.6700>:
  <D.6697>:
  D.6701 = mprotect (addr, length, prot);
  return D.6701;
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.6705;
  int D.6710;
  void * D.6712;
  unsigned int D.6713;

  D.6705 = __builtin_constant_p (__len);
  if (D.6705 != 0) goto <D.6706>; else goto <D.6707>;
  <D.6706>:
  if (__len == 0) goto <D.6708>; else goto <D.6709>;
  <D.6708>:
  D.6710 = __builtin_constant_p (__ch);
  if (D.6710 == 0) goto <D.6703>; else goto <D.6711>;
  <D.6711>:
  if (__ch != 0) goto <D.6703>; else goto <D.6704>;
  <D.6703>:
  __warn_memset_zero_len ();
  D.6712 = __dest;
  return D.6712;
  <D.6704>:
  <D.6709>:
  <D.6707>:
  D.6713 = __builtin_object_size (__dest, 0);
  D.6712 = __builtin___memset_chk (__dest, __ch, __len, D.6713);
  return D.6712;
}


mono_shared_area ()
{
  int D.6715;
  void * malloced_shared_area.5;
  void * malloced_shared_area.6;
  void * D.6722;
  int * D.6725;
  int D.6726;
  long long int D.6731;
  int D.6732;
  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.6715 = shared_area_disabled ();
      if (D.6715 != 0) goto <D.6716>; else goto <D.6717>;
      <D.6716>:
      malloced_shared_area.5 = malloced_shared_area;
      if (malloced_shared_area.5 == 0B) goto <D.6719>; else goto <D.6720>;
      <D.6719>:
      malloced_shared_area.6 = malloc_shared_area (0);
      malloced_shared_area = malloced_shared_area.6;
      <D.6720>:
      D.6722 = malloced_shared_area;
      return D.6722;
      <D.6717>:
      mono_shared_area_instances_helper (0B, 0, 1);
      monoeg_g_snprintf (&buf, 128, "/mono.%d", pid);
      fd = shm_open (&buf, 194, 416);
      if (fd == -1) goto <D.6723>; else goto <D.6724>;
      <D.6723>:
      D.6725 = __errno_location ();
      D.6726 = *D.6725;
      if (D.6726 == 17) goto <D.6727>; else goto <D.6728>;
      <D.6727>:
      shm_unlink (&buf);
      fd = shm_open (&buf, 194, 416);
      <D.6728>:
      <D.6724>:
      if (fd == -1) goto <D.6729>; else goto <D.6730>;
      <D.6729>:
      D.6722 = malloc_shared_area (pid);
      return D.6722;
      <D.6730>:
      D.6731 = (long long int) size;
      D.6732 = ftruncate (fd, D.6731);
      if (D.6732 != 0) goto <D.6733>; else goto <D.6734>;
      <D.6733>:
      shm_unlink (&buf);
      close (fd);
      <D.6734>:
      size.7 = (unsigned int) size;
      res = mmap (0B, size.7, 3, 1, fd, 0);
      if (res == 4294967295B) goto <D.6736>; else goto <D.6737>;
      <D.6736>:
      shm_unlink (&buf);
      close (fd);
      D.6722 = malloc_shared_area (pid);
      return D.6722;
      <D.6737>:
      close (fd);
      header = res;
      header->size = size;
      header->pid = pid;
      header->stats_start = 16;
      header->stats_end = 16;
      atexit (mono_shared_area_remove);
      D.6722 = res;
      return D.6722;
    }
  finally
    {
      buf = {CLOBBER};
    }
}


shared_area_disabled ()
{
  int use_shared_area.8;
  const gchar * D.6743;
  gboolean D.6747;
  _Bool D.6748;

  use_shared_area.8 = use_shared_area;
  if (use_shared_area.8 == 0) goto <D.6741>; else goto <D.6742>;
  <D.6741>:
  D.6743 = monoeg_g_getenv ("MONO_DISABLE_SHARED_AREA");
  if (D.6743 != 0B) goto <D.6744>; else goto <D.6745>;
  <D.6744>:
  use_shared_area = -1;
  goto <D.6746>;
  <D.6745>:
  use_shared_area = 1;
  <D.6746>:
  <D.6742>:
  use_shared_area.8 = use_shared_area;
  D.6748 = use_shared_area.8 == -1;
  D.6747 = (gboolean) D.6748;
  return D.6747;
}


mono_shared_area_instances_helper (void * * array, int count, gboolean cleanup)
{
  int D.6752;
  int D.6753;
  const char * D.6756;
  char * nend.9;
  char D.6762;
  int i.10;
  unsigned int i.11;
  unsigned int D.6768;
  void * * D.6769;
  void * pid.12;
  int D.6773;
  int * D.6776;
  int D.6777;
  _Bool D.6778;
  _Bool D.6779;
  _Bool D.6780;
  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.6750>; else goto <D.6751>;
  <D.6750>:
  D.6752 = mono_shared_area_instances_slow (array, count, cleanup);
  return D.6752;
  <D.6751>:
  goto <D.6583>;
  <D.6586>:
  {
    int pid;
    char * nend;

    try
      {
        D.6753 = strncmp (name, "mono.", 5);
        if (D.6753 != 0) goto <D.6754>; else goto <D.6755>;
        <D.6754>:
        // predicted unlikely by continue predictor.
        goto <D.6583>;
        <D.6755>:
        D.6756 = name + 5;
        pid = strtol (D.6756, &nend, 10);
        if (pid <= 0) goto <D.6757>; else goto <D.6759>;
        <D.6759>:
        D.6756 = name + 5;
        nend.9 = nend;
        if (D.6756 == nend.9) goto <D.6757>; else goto <D.6761>;
        <D.6761>:
        nend.9 = nend;
        D.6762 = *nend.9;
        if (D.6762 != 0) goto <D.6757>; else goto <D.6758>;
        <D.6757>:
        // predicted unlikely by continue predictor.
        goto <D.6583>;
        <D.6758>:
        if (cleanup == 0) goto <D.6763>; else goto <D.6764>;
        <D.6763>:
        if (i < count) goto <D.6765>; else goto <D.6584>;
        <D.6765>:
        i.10 = i;
        i = i.10 + 1;
        i.11 = (unsigned int) i.10;
        D.6768 = i.11 * 4;
        D.6769 = array + D.6768;
        pid.12 = (void *) pid;
        *D.6769 = pid.12;
        <D.6764>:
        if (curpid != pid) goto <D.6771>; else goto <D.6772>;
        <D.6771>:
        D.6773 = kill (pid, 0);
        if (D.6773 == -1) goto <D.6774>; else goto <D.6775>;
        <D.6774>:
        D.6776 = __errno_location ();
        D.6777 = *D.6776;
        D.6778 = D.6777 == 3;
        D.6779 = D.6777 == 12;
        D.6780 = D.6778 | D.6779;
        if (D.6780 != 0) goto <D.6781>; else goto <D.6782>;
        <D.6781>:
        {
          char buf[128];

          try
            {
              monoeg_g_snprintf (&buf, 128, "/mono.%d", pid);
              shm_unlink (&buf);
            }
          finally
            {
              buf = {CLOBBER};
            }
        }
        <D.6782>:
        <D.6775>:
        <D.6772>:
      }
    finally
      {
        nend = {CLOBBER};
      }
  }
  <D.6583>:
  name = monoeg_g_dir_read_name (dir);
  if (name != 0B) goto <D.6586>; else goto <D.6584>;
  <D.6584>:
  monoeg_g_dir_close (dir);
  D.6752 = i;
  return D.6752;
}


mono_shared_area_instances_slow (void * * array, int count, gboolean cleanup)
{
  unsigned int i.13;
  unsigned int D.6788;
  void * * D.6789;
  void * D.6790;
  int j.14;
  unsigned int j.15;
  unsigned int D.6798;
  void * * D.6799;
  int num.16;
  int D.6801;
  int i;
  int j;
  int num;
  void * data;
  void * * processes;

  try
    {
      j = 0;
      processes = mono_process_list (&num);
      i = 0;
      goto <D.6562>;
      <D.6561>:
      i.13 = (unsigned int) i;
      D.6788 = i.13 * 4;
      D.6789 = processes + D.6788;
      D.6790 = *D.6789;
      data = mono_shared_area_for_pid (D.6790);
      if (data == 0B) goto <D.6791>; else goto <D.6792>;
      <D.6791>:
      // predicted unlikely by continue predictor.
      goto <D.6559>;
      <D.6792>:
      mono_shared_area_unload (data);
      if (cleanup == 0) goto <D.6793>; else goto <D.6794>;
      <D.6793>:
      if (j < count) goto <D.6795>; else goto <D.6560>;
      <D.6795>:
      j.14 = j;
      j = j.14 + 1;
      j.15 = (unsigned int) j.14;
      D.6798 = j.15 * 4;
      D.6799 = array + D.6798;
      i.13 = (unsigned int) i;
      D.6788 = i.13 * 4;
      D.6789 = processes + D.6788;
      D.6790 = *D.6789;
      *D.6799 = D.6790;
      <D.6794>:
      <D.6559>:
      i = i + 1;
      <D.6562>:
      num.16 = num;
      if (i < num.16) goto <D.6561>; else goto <D.6560>;
      <D.6560>:
      monoeg_g_free (processes);
      D.6801 = j;
      return D.6801;
    }
  finally
    {
      num = {CLOBBER};
    }
}


malloc_shared_area (int pid)
{
  unsigned int size.17;
  void * D.6805;
  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.6805 = sarea;
  return D.6805;
}


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

  try
    {
      D.6807 = shared_area_disabled ();
      if (D.6807 != 0) goto <D.6808>; else goto <D.6809>;
      <D.6808>:
      malloced_shared_area.18 = malloced_shared_area;
      if (malloced_shared_area.18 != 0B) goto <D.6811>; else goto <D.6812>;
      <D.6811>:
      malloced_shared_area.18 = malloced_shared_area;
      monoeg_g_free (malloced_shared_area.18);
      <D.6812>:
      return;
      <D.6809>:
      D.6813 = getpid ();
      monoeg_g_snprintf (&buf, 128, "/mono.%d", D.6813);
      shm_unlink (&buf);
      malloced_shared_area.18 = malloced_shared_area;
      if (malloced_shared_area.18 != 0B) goto <D.6814>; else goto <D.6815>;
      <D.6814>:
      malloced_shared_area.18 = malloced_shared_area;
      monoeg_g_free (malloced_shared_area.18);
      <D.6815>:
    }
  finally
    {
      buf = {CLOBBER};
    }
}


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

  try
    {
      size = mono_pagesize ();
      D.6819 = shared_area_disabled ();
      if (D.6819 != 0) goto <D.6820>; else goto <D.6821>;
      <D.6820>:
      D.6822 = 0B;
      return D.6822;
      <D.6821>:
      pid.19 = (int) pid;
      monoeg_g_snprintf (&buf, 128, "/mono.%d", pid.19);
      fd = shm_open (&buf, 0, 288);
      if (fd == -1) goto <D.6824>; else goto <D.6825>;
      <D.6824>:
      D.6822 = 0B;
      return D.6822;
      <D.6825>:
      size.20 = (unsigned int) size;
      res = mmap (0B, size.20, 1, 1, fd, 0);
      if (res == 4294967295B) goto <D.6827>; else goto <D.6828>;
      <D.6827>:
      close (fd);
      D.6822 = 0B;
      return D.6822;
      <D.6828>:
      close (fd);
      D.6822 = res;
      return D.6822;
    }
  finally
    {
      buf = {CLOBBER};
    }
}


mono_shared_area_unload (void * area)
{
  int D.6831;
  unsigned int D.6832;

  D.6831 = mono_pagesize ();
  D.6832 = (unsigned int) D.6831;
  munmap (area, D.6832);
}


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

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


mono_valloc_aligned (size_t size, size_t alignment, int flags)
{
  unsigned int D.6835;
  void * D.6838;
  int aligned.21;
  int mem.22;
  int D.6843;
  unsigned int D.6844;
  char * D.6845;
  sizetype D.6846;
  char * D.6847;
  int mem.23;
  int aligned.24;
  int D.6852;
  int D.6853;
  int size.25;
  int D.6855;
  int D.6856;
  unsigned int D.6857;
  void * D.6858;
  char * mem;
  char * aligned;

  D.6835 = size + alignment;
  mem = mono_valloc (0B, D.6835, flags);
  if (mem == 0B) goto <D.6836>; else goto <D.6837>;
  <D.6836>:
  D.6838 = 0B;
  return D.6838;
  <D.6837>:
  aligned = aligned_address (mem, size, alignment);
  if (aligned > mem) goto <D.6839>; else goto <D.6840>;
  <D.6839>:
  aligned.21 = (int) aligned;
  mem.22 = (int) mem;
  D.6843 = aligned.21 - mem.22;
  D.6844 = (unsigned int) D.6843;
  mono_vfree (mem, D.6844);
  <D.6840>:
  D.6845 = aligned + size;
  D.6846 = size + alignment;
  D.6847 = mem + D.6846;
  if (D.6845 < D.6847) goto <D.6848>; else goto <D.6849>;
  <D.6848>:
  mem.23 = (int) mem;
  aligned.24 = (int) aligned;
  D.6852 = mem.23 - aligned.24;
  D.6846 = size + alignment;
  D.6853 = (int) D.6846;
  size.25 = (int) size;
  D.6855 = D.6853 - size.25;
  D.6856 = D.6852 + D.6855;
  D.6857 = (unsigned int) D.6856;
  D.6858 = aligned + size;
  mono_vfree (D.6858, D.6857);
  <D.6849>:
  D.6838 = aligned;
  return D.6838;
}


aligned_address (char * mem, size_t size, size_t alignment)
{
  sizetype D.6860;
  char * D.6861;
  long unsigned int D.6862;
  unsigned int D.6863;
  long unsigned int D.6864;
  int iftmp.26;
  char * D.6870;
  sizetype D.6871;
  char * D.6872;
  unsigned int D.6874;
  long unsigned int aligned.27;
  long unsigned int D.6876;
  _Bool D.6877;
  long int D.6878;
  long int D.6879;
  char * D.6882;
  char * aligned;

  D.6860 = alignment + 4294967295;
  D.6861 = mem + D.6860;
  D.6862 = (long unsigned int) D.6861;
  D.6863 = -alignment;
  D.6864 = D.6862 & D.6863;
  aligned = (char *) D.6864;
  if (aligned < mem) goto <D.6866>; else goto <D.6869>;
  <D.6869>:
  D.6870 = aligned + size;
  D.6871 = size + alignment;
  D.6872 = mem + D.6871;
  if (D.6870 > D.6872) goto <D.6866>; else goto <D.6873>;
  <D.6873>:
  D.6874 = alignment + 4294967295;
  aligned.27 = (long unsigned int) aligned;
  D.6876 = D.6874 & aligned.27;
  if (D.6876 != 0) goto <D.6866>; else goto <D.6867>;
  <D.6866>:
  iftmp.26 = 1;
  goto <D.6868>;
  <D.6867>:
  iftmp.26 = 0;
  <D.6868>:
  D.6877 = iftmp.26 != 0;
  D.6878 = (long int) D.6877;
  D.6879 = __builtin_expect (D.6878, 0);
  if (D.6879 != 0) goto <D.6880>; else goto <D.6881>;
  <D.6880>:
  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.6881>:
  D.6882 = aligned;
  return D.6882;
}


