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

  saved_pagesize.0 = saved_pagesize;
  if (saved_pagesize.0 != 0) goto <D.9169>; else goto <D.9170>;
  <D.9169>:
  D.9171 = saved_pagesize;
  return D.9171;
  <D.9170>:
  saved_pagesize.1 = getpagesize ();
  saved_pagesize = saved_pagesize.1;
  D.9171 = saved_pagesize;
  return D.9171;
}


mono_valloc (void * addr, size_t length, int flags)
{
  int D.9174;
  int D.9177;
  void * D.9186;
  void * ptr;
  int mflags;
  int prot;

  mflags = 0;
  prot = prot_from_flags (flags);
  D.9174 = flags & 128;
  if (D.9174 != 0) goto <D.9175>; else goto <D.9176>;
  <D.9175>:
  mflags = mflags | 16;
  <D.9176>:
  D.9177 = flags & 256;
  if (D.9177 != 0) goto <D.9178>; else goto <D.9179>;
  <D.9178>:
  mflags = mflags;
  <D.9179>:
  mflags = mflags | 32;
  mflags = mflags | 2;
  ptr = mmap (addr, length, prot, mflags, -1, 0);
  if (ptr == 4294967295B) goto <D.9180>; else goto <D.9181>;
  <D.9180>:
  {
    int fd;

    fd = open ("/dev/zero", 0);
    if (fd != -1) goto <D.9182>; else goto <D.9183>;
    <D.9182>:
    ptr = mmap (addr, length, prot, mflags, fd, 0);
    close (fd);
    <D.9183>:
    if (ptr == 4294967295B) goto <D.9184>; else goto <D.9185>;
    <D.9184>:
    D.9186 = 0B;
    return D.9186;
    <D.9185>:
  }
  <D.9181>:
  D.9186 = ptr;
  return D.9186;
}


prot_from_flags (int flags)
{
  int D.9188;
  int D.9191;
  int D.9194;
  int D.9197;
  int prot;

  prot = 0;
  D.9188 = flags & 1;
  if (D.9188 != 0) goto <D.9189>; else goto <D.9190>;
  <D.9189>:
  prot = prot | 1;
  <D.9190>:
  D.9191 = flags & 2;
  if (D.9191 != 0) goto <D.9192>; else goto <D.9193>;
  <D.9192>:
  prot = prot | 2;
  <D.9193>:
  D.9194 = flags & 4;
  if (D.9194 != 0) goto <D.9195>; else goto <D.9196>;
  <D.9195>:
  prot = prot | 4;
  <D.9196>:
  D.9197 = prot;
  return D.9197;
}


open (const char * __path, int __oflag)
{
  int D.9199;
  int D.9202;
  int D.9207;
  int D.9209;
  int D.9210;
  int D.9213;
  int D.9214;

  D.9199 = __builtin_va_arg_pack_len ();
  if (D.9199 > 1) goto <D.9200>; else goto <D.9201>;
  <D.9200>:
  __open_too_many_args ();
  <D.9201>:
  D.9202 = __builtin_constant_p (__oflag);
  if (D.9202 != 0) goto <D.9203>; else goto <D.9204>;
  <D.9203>:
  D.9207 = __oflag & 64;
  if (D.9207 != 0) goto <D.9205>; else goto <D.9208>;
  <D.9208>:
  D.9209 = __oflag & 4210688;
  if (D.9209 == 4210688) goto <D.9205>; else goto <D.9206>;
  <D.9205>:
  D.9210 = __builtin_va_arg_pack_len ();
  if (D.9210 <= 0) goto <D.9211>; else goto <D.9212>;
  <D.9211>:
  __open_missing_mode ();
  D.9213 = __open_2 (__path, __oflag);
  return D.9213;
  <D.9212>:
  <D.9206>:
  D.9213 = __open_alias (__path, __oflag, __builtin_va_arg_pack ());
  return D.9213;
  <D.9204>:
  D.9214 = __builtin_va_arg_pack_len ();
  if (D.9214 <= 0) goto <D.9215>; else goto <D.9216>;
  <D.9215>:
  D.9213 = __open_2 (__path, __oflag);
  return D.9213;
  <D.9216>:
  D.9213 = __open_alias (__path, __oflag, __builtin_va_arg_pack ());
  return D.9213;
}


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

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


mono_file_map (size_t length, int flags, int fd, guint64 offset, void * * ret_handle)
{
  int D.9220;
  int D.9223;
  int D.9226;
  int D.9229;
  long long int offset.2;
  void * D.9235;
  void * length.3;
  void * ptr;
  int mflags;
  int prot;

  mflags = 0;
  prot = prot_from_flags (flags);
  D.9220 = flags & 16;
  if (D.9220 != 0) goto <D.9221>; else goto <D.9222>;
  <D.9221>:
  mflags = mflags | 2;
  <D.9222>:
  D.9223 = flags & 32;
  if (D.9223 != 0) goto <D.9224>; else goto <D.9225>;
  <D.9224>:
  mflags = mflags | 1;
  <D.9225>:
  D.9226 = flags & 128;
  if (D.9226 != 0) goto <D.9227>; else goto <D.9228>;
  <D.9227>:
  mflags = mflags | 16;
  <D.9228>:
  D.9229 = flags & 256;
  if (D.9229 != 0) goto <D.9230>; else goto <D.9231>;
  <D.9230>:
  mflags = mflags;
  <D.9231>:
  offset.2 = (long long int) offset;
  ptr = mmap (0B, length, prot, mflags, fd, offset.2);
  if (ptr == 4294967295B) goto <D.9233>; else goto <D.9234>;
  <D.9233>:
  D.9235 = 0B;
  return D.9235;
  <D.9234>:
  length.3 = (void *) length;
  *ret_handle = length.3;
  D.9235 = ptr;
  return D.9235;
}


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

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


mono_mprotect (void * addr, size_t length, int flags)
{
  int D.9241;
  int D.9244;
  int D.9247;
  int prot;

  prot = prot_from_flags (flags);
  D.9241 = flags & 8;
  if (D.9241 != 0) goto <D.9242>; else goto <D.9243>;
  <D.9242>:
  D.9244 = madvise (addr, length, 4);
  if (D.9244 != 0) goto <D.9245>; else goto <D.9246>;
  <D.9245>:
  memset (addr, 0, length);
  <D.9246>:
  <D.9243>:
  D.9247 = mprotect (addr, length, prot);
  return D.9247;
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.9251;
  int D.9256;
  void * D.9258;
  unsigned int D.9259;

  D.9251 = __builtin_constant_p (__len);
  if (D.9251 != 0) goto <D.9252>; else goto <D.9253>;
  <D.9252>:
  if (__len == 0) goto <D.9254>; else goto <D.9255>;
  <D.9254>:
  D.9256 = __builtin_constant_p (__ch);
  if (D.9256 == 0) goto <D.9249>; else goto <D.9257>;
  <D.9257>:
  if (__ch != 0) goto <D.9249>; else goto <D.9250>;
  <D.9249>:
  __warn_memset_zero_len ();
  D.9258 = __dest;
  return D.9258;
  <D.9250>:
  <D.9255>:
  <D.9253>:
  D.9259 = __builtin_object_size (__dest, 0);
  D.9258 = __builtin___memset_chk (__dest, __ch, __len, D.9259);
  return D.9258;
}


mono_shared_area ()
{
  int D.9261;
  void * malloced_shared_area.5;
  void * malloced_shared_area.6;
  void * D.9268;
  int * D.9271;
  int D.9272;
  long long int D.9277;
  int D.9278;
  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.9261 = shared_area_disabled ();
      if (D.9261 != 0) goto <D.9262>; else goto <D.9263>;
      <D.9262>:
      malloced_shared_area.5 = malloced_shared_area;
      if (malloced_shared_area.5 == 0B) goto <D.9265>; else goto <D.9266>;
      <D.9265>:
      malloced_shared_area.6 = malloc_shared_area (0);
      malloced_shared_area = malloced_shared_area.6;
      <D.9266>:
      D.9268 = malloced_shared_area;
      return D.9268;
      <D.9263>:
      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.9269>; else goto <D.9270>;
      <D.9269>:
      D.9271 = __errno_location ();
      D.9272 = *D.9271;
      if (D.9272 == 17) goto <D.9273>; else goto <D.9274>;
      <D.9273>:
      shm_unlink (&buf);
      fd = shm_open (&buf, 194, 416);
      <D.9274>:
      <D.9270>:
      if (fd == -1) goto <D.9275>; else goto <D.9276>;
      <D.9275>:
      D.9268 = malloc_shared_area (pid);
      return D.9268;
      <D.9276>:
      D.9277 = (long long int) size;
      D.9278 = ftruncate (fd, D.9277);
      if (D.9278 != 0) goto <D.9279>; else goto <D.9280>;
      <D.9279>:
      shm_unlink (&buf);
      close (fd);
      <D.9280>:
      size.7 = (unsigned int) size;
      res = mmap (0B, size.7, 3, 1, fd, 0);
      if (res == 4294967295B) goto <D.9282>; else goto <D.9283>;
      <D.9282>:
      shm_unlink (&buf);
      close (fd);
      D.9268 = malloc_shared_area (pid);
      return D.9268;
      <D.9283>:
      close (fd);
      header = res;
      header->size = size;
      header->pid = pid;
      header->stats_start = 16;
      header->stats_end = 16;
      atexit (mono_shared_area_remove);
      D.9268 = res;
      return D.9268;
    }
  finally
    {
      buf = {CLOBBER};
    }
}


shared_area_disabled ()
{
  int use_shared_area.8;
  const gchar * D.9289;
  gboolean D.9293;
  _Bool D.9294;

  use_shared_area.8 = use_shared_area;
  if (use_shared_area.8 == 0) goto <D.9287>; else goto <D.9288>;
  <D.9287>:
  D.9289 = monoeg_g_getenv ("MONO_DISABLE_SHARED_AREA");
  if (D.9289 != 0B) goto <D.9290>; else goto <D.9291>;
  <D.9290>:
  use_shared_area = -1;
  goto <D.9292>;
  <D.9291>:
  use_shared_area = 1;
  <D.9292>:
  <D.9288>:
  use_shared_area.8 = use_shared_area;
  D.9294 = use_shared_area.8 == -1;
  D.9293 = (gboolean) D.9294;
  return D.9293;
}


mono_shared_area_instances_helper (void * * array, int count, gboolean cleanup)
{
  int D.9298;
  int D.9299;
  const char * D.9302;
  char * nend.9;
  char D.9308;
  int i.10;
  unsigned int i.11;
  unsigned int D.9314;
  void * * D.9315;
  void * pid.12;
  int D.9319;
  int * D.9322;
  int D.9323;
  _Bool D.9324;
  _Bool D.9325;
  _Bool D.9326;
  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.9296>; else goto <D.9297>;
  <D.9296>:
  D.9298 = mono_shared_area_instances_slow (array, count, cleanup);
  return D.9298;
  <D.9297>:
  goto <D.9127>;
  <D.9130>:
  {
    int pid;
    char * nend;

    try
      {
        D.9299 = strncmp (name, "mono.", 5);
        if (D.9299 != 0) goto <D.9300>; else goto <D.9301>;
        <D.9300>:
        // predicted unlikely by continue predictor.
        goto <D.9127>;
        <D.9301>:
        D.9302 = name + 5;
        pid = strtol (D.9302, &nend, 10);
        if (pid <= 0) goto <D.9303>; else goto <D.9305>;
        <D.9305>:
        D.9302 = name + 5;
        nend.9 = nend;
        if (D.9302 == nend.9) goto <D.9303>; else goto <D.9307>;
        <D.9307>:
        nend.9 = nend;
        D.9308 = *nend.9;
        if (D.9308 != 0) goto <D.9303>; else goto <D.9304>;
        <D.9303>:
        // predicted unlikely by continue predictor.
        goto <D.9127>;
        <D.9304>:
        if (cleanup == 0) goto <D.9309>; else goto <D.9310>;
        <D.9309>:
        if (i < count) goto <D.9311>; else goto <D.9128>;
        <D.9311>:
        i.10 = i;
        i = i.10 + 1;
        i.11 = (unsigned int) i.10;
        D.9314 = i.11 * 4;
        D.9315 = array + D.9314;
        pid.12 = (void *) pid;
        *D.9315 = pid.12;
        <D.9310>:
        if (curpid != pid) goto <D.9317>; else goto <D.9318>;
        <D.9317>:
        D.9319 = kill (pid, 0);
        if (D.9319 == -1) goto <D.9320>; else goto <D.9321>;
        <D.9320>:
        D.9322 = __errno_location ();
        D.9323 = *D.9322;
        D.9324 = D.9323 == 3;
        D.9325 = D.9323 == 12;
        D.9326 = D.9324 | D.9325;
        if (D.9326 != 0) goto <D.9327>; else goto <D.9328>;
        <D.9327>:
        {
          char buf[128];

          try
            {
              monoeg_g_snprintf (&buf, 128, "/mono.%d", pid);
              shm_unlink (&buf);
            }
          finally
            {
              buf = {CLOBBER};
            }
        }
        <D.9328>:
        <D.9321>:
        <D.9318>:
      }
    finally
      {
        nend = {CLOBBER};
      }
  }
  <D.9127>:
  name = monoeg_g_dir_read_name (dir);
  if (name != 0B) goto <D.9130>; else goto <D.9128>;
  <D.9128>:
  monoeg_g_dir_close (dir);
  D.9298 = i;
  return D.9298;
}


mono_shared_area_instances_slow (void * * array, int count, gboolean cleanup)
{
  unsigned int i.13;
  unsigned int D.9334;
  void * * D.9335;
  void * D.9336;
  int j.14;
  unsigned int j.15;
  unsigned int D.9344;
  void * * D.9345;
  int num.16;
  int D.9347;
  int i;
  int j;
  int num;
  void * data;
  void * * processes;

  try
    {
      j = 0;
      processes = mono_process_list (&num);
      i = 0;
      goto <D.9106>;
      <D.9105>:
      i.13 = (unsigned int) i;
      D.9334 = i.13 * 4;
      D.9335 = processes + D.9334;
      D.9336 = *D.9335;
      data = mono_shared_area_for_pid (D.9336);
      if (data == 0B) goto <D.9337>; else goto <D.9338>;
      <D.9337>:
      // predicted unlikely by continue predictor.
      goto <D.9103>;
      <D.9338>:
      mono_shared_area_unload (data);
      if (cleanup == 0) goto <D.9339>; else goto <D.9340>;
      <D.9339>:
      if (j < count) goto <D.9341>; else goto <D.9104>;
      <D.9341>:
      j.14 = j;
      j = j.14 + 1;
      j.15 = (unsigned int) j.14;
      D.9344 = j.15 * 4;
      D.9345 = array + D.9344;
      i.13 = (unsigned int) i;
      D.9334 = i.13 * 4;
      D.9335 = processes + D.9334;
      D.9336 = *D.9335;
      *D.9345 = D.9336;
      <D.9340>:
      <D.9103>:
      i = i + 1;
      <D.9106>:
      num.16 = num;
      if (i < num.16) goto <D.9105>; else goto <D.9104>;
      <D.9104>:
      monoeg_g_free (processes);
      D.9347 = j;
      return D.9347;
    }
  finally
    {
      num = {CLOBBER};
    }
}


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


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

  try
    {
      D.9353 = shared_area_disabled ();
      if (D.9353 != 0) goto <D.9354>; else goto <D.9355>;
      <D.9354>:
      malloced_shared_area.18 = malloced_shared_area;
      if (malloced_shared_area.18 != 0B) goto <D.9357>; else goto <D.9358>;
      <D.9357>:
      malloced_shared_area.18 = malloced_shared_area;
      monoeg_g_free (malloced_shared_area.18);
      <D.9358>:
      return;
      <D.9355>:
      D.9359 = getpid ();
      monoeg_g_snprintf (&buf, 128, "/mono.%d", D.9359);
      shm_unlink (&buf);
      malloced_shared_area.18 = malloced_shared_area;
      if (malloced_shared_area.18 != 0B) goto <D.9360>; else goto <D.9361>;
      <D.9360>:
      malloced_shared_area.18 = malloced_shared_area;
      monoeg_g_free (malloced_shared_area.18);
      <D.9361>:
    }
  finally
    {
      buf = {CLOBBER};
    }
}


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

  try
    {
      size = mono_pagesize ();
      D.9365 = shared_area_disabled ();
      if (D.9365 != 0) goto <D.9366>; else goto <D.9367>;
      <D.9366>:
      D.9368 = 0B;
      return D.9368;
      <D.9367>:
      pid.19 = (int) pid;
      monoeg_g_snprintf (&buf, 128, "/mono.%d", pid.19);
      fd = shm_open (&buf, 0, 288);
      if (fd == -1) goto <D.9370>; else goto <D.9371>;
      <D.9370>:
      D.9368 = 0B;
      return D.9368;
      <D.9371>:
      size.20 = (unsigned int) size;
      res = mmap (0B, size.20, 1, 1, fd, 0);
      if (res == 4294967295B) goto <D.9373>; else goto <D.9374>;
      <D.9373>:
      close (fd);
      D.9368 = 0B;
      return D.9368;
      <D.9374>:
      close (fd);
      D.9368 = res;
      return D.9368;
    }
  finally
    {
      buf = {CLOBBER};
    }
}


mono_shared_area_unload (void * area)
{
  int D.9377;
  unsigned int D.9378;

  D.9377 = mono_pagesize ();
  D.9378 = (unsigned int) D.9377;
  munmap (area, D.9378);
}


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

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


mono_valloc_aligned (size_t size, size_t alignment, int flags)
{
  unsigned int D.9381;
  void * D.9384;
  int aligned.21;
  int mem.22;
  int D.9389;
  unsigned int D.9390;
  char * D.9391;
  sizetype D.9392;
  char * D.9393;
  void * D.9396;
  int mem.23;
  int aligned.24;
  int D.9399;
  int D.9400;
  int size.25;
  int D.9402;
  int D.9403;
  unsigned int D.9404;
  char * mem;
  char * aligned;

  D.9381 = size + alignment;
  mem = mono_valloc (0B, D.9381, flags);
  if (mem == 0B) goto <D.9382>; else goto <D.9383>;
  <D.9382>:
  D.9384 = 0B;
  return D.9384;
  <D.9383>:
  aligned = aligned_address (mem, size, alignment);
  if (aligned > mem) goto <D.9385>; else goto <D.9386>;
  <D.9385>:
  aligned.21 = (int) aligned;
  mem.22 = (int) mem;
  D.9389 = aligned.21 - mem.22;
  D.9390 = (unsigned int) D.9389;
  mono_vfree (mem, D.9390);
  <D.9386>:
  D.9391 = aligned + size;
  D.9392 = size + alignment;
  D.9393 = mem + D.9392;
  if (D.9391 < D.9393) goto <D.9394>; else goto <D.9395>;
  <D.9394>:
  D.9396 = aligned + size;
  mem.23 = (int) mem;
  aligned.24 = (int) aligned;
  D.9399 = mem.23 - aligned.24;
  D.9392 = size + alignment;
  D.9400 = (int) D.9392;
  size.25 = (int) size;
  D.9402 = D.9400 - size.25;
  D.9403 = D.9399 + D.9402;
  D.9404 = (unsigned int) D.9403;
  mono_vfree (D.9396, D.9404);
  <D.9395>:
  D.9384 = aligned;
  return D.9384;
}


aligned_address (char * mem, size_t size, size_t alignment)
{
  sizetype D.9406;
  char * D.9407;
  long unsigned int D.9408;
  unsigned int D.9409;
  long unsigned int D.9410;
  int iftmp.26;
  char * D.9416;
  sizetype D.9417;
  char * D.9418;
  unsigned int D.9420;
  long unsigned int aligned.27;
  long unsigned int D.9422;
  _Bool D.9423;
  long int D.9424;
  long int D.9425;
  char * D.9428;
  char * aligned;

  D.9406 = alignment + 4294967295;
  D.9407 = mem + D.9406;
  D.9408 = (long unsigned int) D.9407;
  D.9409 = -alignment;
  D.9410 = D.9408 & D.9409;
  aligned = (char *) D.9410;
  if (aligned < mem) goto <D.9412>; else goto <D.9415>;
  <D.9415>:
  D.9416 = aligned + size;
  D.9417 = size + alignment;
  D.9418 = mem + D.9417;
  if (D.9416 > D.9418) goto <D.9412>; else goto <D.9419>;
  <D.9419>:
  D.9420 = alignment + 4294967295;
  aligned.27 = (long unsigned int) aligned;
  D.9422 = D.9420 & aligned.27;
  if (D.9422 != 0) goto <D.9412>; else goto <D.9413>;
  <D.9412>:
  iftmp.26 = 1;
  goto <D.9414>;
  <D.9413>:
  iftmp.26 = 0;
  <D.9414>:
  D.9423 = iftmp.26 != 0;
  D.9424 = (long int) D.9423;
  D.9425 = __builtin_expect (D.9424, 0);
  if (D.9425 != 0) goto <D.9426>; else goto <D.9427>;
  <D.9426>:
  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.9427>:
  D.9428 = aligned;
  return D.9428;
}


