FormatMessage (guint32 flags, const void * source, guint32 messageid, guint32 languageid, gunichar2 * buf, guint32 size)
{
  unsigned int D.11389;
  guint32 D.11392;
  unsigned int D.11393;
  unsigned int D.11398;
  unsigned int D.11402;
  unsigned int D.11409;
  unsigned int D.11412;
  unsigned int D.11413;
  unsigned int D.11414;
  void * D.11415;
  unsigned int D.11419;
  gunichar2 * D.11420;
  guint32 strlen;
  guint32 cpy;
  gunichar2 * str;
  gboolean freestr;
  static const char __func__[14] = "FormatMessage";

  freestr = 0;
  D.11389 = flags & 10752;
  if (D.11389 != 512) goto <D.11390>; else goto <D.11391>;
  <D.11390>:
  monoeg_g_log (0B, 16, "%s: Unsupported flags passed: %d", &__func__, flags);
  SetLastError (50);
  D.11392 = 0;
  return D.11392;
  <D.11391>:
  D.11393 = flags & 255;
  if (D.11393 != 0) goto <D.11394>; else goto <D.11395>;
  <D.11394>:
  D.11393 = flags & 255;
  monoeg_g_log (0B, 16, "%s: Message width mask (%d) not supported", &__func__, D.11393);
  <D.11395>:
  if (languageid != 0) goto <D.11396>; else goto <D.11397>;
  <D.11396>:
  monoeg_g_log (0B, 16, "%s: Locale 0x%x not supported, returning language neutral string", &__func__, languageid);
  <D.11397>:
  D.11398 = flags & 1024;
  if (D.11398 != 0) goto <D.11399>; else goto <D.11400>;
  <D.11399>:
  str = source;
  goto <D.11401>;
  <D.11400>:
  D.11402 = flags & 4096;
  if (D.11402 != 0) goto <D.11403>; else goto <D.11404>;
  <D.11403>:
  {
    const char * msg;

    msg = message_string (messageid);
    if (msg != 0B) goto <D.11405>; else goto <D.11406>;
    <D.11405>:
    str = monoeg_g_utf8_to_utf16 (msg, -1, 0B, 0B, 0B);
    goto <D.11407>;
    <D.11406>:
    {
      char * msg2;

      msg2 = monoeg_g_strdup_printf ("mono-io-layer-error (%d)", messageid);
      str = monoeg_g_utf8_to_utf16 (msg2, -1, 0B, 0B, 0B);
      monoeg_g_free (msg2);
    }
    <D.11407>:
    freestr = 1;
  }
  goto <D.11408>;
  <D.11404>:
  str = monoeg_g_utf8_to_utf16 ("No message specified", -1, 0B, 0B, 0B);
  <D.11408>:
  <D.11401>:
  strlen = unicode_chars (str);
  D.11409 = flags & 256;
  if (D.11409 != 0) goto <D.11410>; else goto <D.11411>;
  <D.11410>:
  D.11412 = strlen + 2;
  D.11413 = MAX_EXPR <D.11412, size>;
  D.11414 = D.11413 * 2;
  D.11415 = monoeg_malloc0 (D.11414);
  MEM[(void * *)buf] = D.11415;
  <D.11411>:
  if (strlen >= size) goto <D.11416>; else goto <D.11417>;
  <D.11416>:
  cpy = size + 4294967295;
  goto <D.11418>;
  <D.11417>:
  cpy = strlen;
  <D.11418>:
  D.11419 = cpy * 2;
  memcpy (buf, str, D.11419);
  D.11419 = cpy * 2;
  D.11420 = buf + D.11419;
  *D.11420 = 0;
  if (freestr != 0) goto <D.11421>; else goto <D.11422>;
  <D.11421>:
  monoeg_g_free (str);
  <D.11422>:
  D.11392 = strlen;
  return D.11392;
}


message_string (guint32 id)
{
  const gchar * D.11426;
  struct _IO_FILE * stderr.0;
  const char * msg;

  msg = find_msg (id, &common_messages, 85);
  if (msg != 0B) goto <D.11424>; else goto <D.11425>;
  <D.11424>:
  D.11426 = msg;
  return D.11426;
  <D.11425>:
  msg = find_msg (id, &messages, 1697);
  if (msg != 0B) goto <D.11427>; else goto <D.11428>;
  <D.11427>:
  stderr.0 = stderr;
  fprintf (stderr.0, "messages.c: A message was found on the uncommon code path: %d - %s", id, msg);
  D.11426 = msg;
  return D.11426;
  <D.11428>:
  msg = find_linear_msg (id, &common_messages, 85);
  if (msg != 0B) goto <D.11430>; else goto <D.11431>;
  <D.11430>:
  D.11426 = msg;
  return D.11426;
  <D.11431>:
  msg = find_linear_msg (id, &messages, 1697);
  if (msg != 0B) goto <D.11432>; else goto <D.11433>;
  <D.11432>:
  D.11426 = msg;
  return D.11426;
  <D.11433>:
  D.11426 = 0B;
  return D.11426;
}


find_msg (guint32 id, struct ErrorDesc * base, int n)
{
  int id.1;
  unsigned int n.2;
  const gchar * D.11439;
  struct ErrorDesc d;
  struct ErrorDesc * result;

  try
    {
      id.1 = (int) id;
      d.id = id.1;
      n.2 = (unsigned int) n;
      result = mono_binary_search (&d, base, n.2, 8, msg_compare);
      if (result == 0B) goto <D.11437>; else goto <D.11438>;
      <D.11437>:
      D.11439 = 0B;
      return D.11439;
      <D.11438>:
      D.11439 = result->txt;
      return D.11439;
    }
  finally
    {
      d = {CLOBBER};
    }
}


msg_compare (const void * first, const void * second)
{
  int D.11442;
  int D.11443;
  int D.11444;
  struct ErrorDesc * efirst;
  struct ErrorDesc * esecond;

  efirst = first;
  esecond = second;
  D.11443 = efirst->id;
  D.11444 = esecond->id;
  D.11442 = D.11443 - D.11444;
  return D.11442;
}


fprintf (struct FILE * restrict __stream, const char * restrict __fmt)
{
  int D.11446;

  D.11446 = __fprintf_chk (__stream, 1, __fmt, __builtin_va_arg_pack ());
  return D.11446;
}


find_linear_msg (guint32 id, struct ErrorDesc * base, int n)
{
  unsigned int i.3;
  unsigned int D.11449;
  struct ErrorDesc * D.11450;
  int D.11451;
  int error_shown.4;
  struct _IO_FILE * stderr.5;
  const char * D.11459;
  unsigned int D.11460;
  int error_shown.6;
  const gchar * D.11466;
  int i;
  int prev;

  prev = -1;
  i = 0;
  goto <D.11360>;
  <D.11359>:
  i.3 = (unsigned int) i;
  D.11449 = i.3 * 8;
  D.11450 = base + D.11449;
  D.11451 = D.11450->id;
  if (D.11451 > prev) goto <D.11452>; else goto <D.11453>;
  <D.11452>:
  i.3 = (unsigned int) i;
  D.11449 = i.3 * 8;
  D.11450 = base + D.11449;
  prev = D.11450->id;
  goto <D.11454>;
  <D.11453>:
  {
    static int error_shown;

    error_shown.4 = error_shown;
    if (error_shown.4 == 0) goto <D.11456>; else goto <D.11457>;
    <D.11456>:
    error_shown = 1;
    stderr.5 = stderr;
    i.3 = (unsigned int) i;
    D.11449 = i.3 * 8;
    D.11450 = base + D.11449;
    D.11459 = D.11450->txt;
    fprintf (stderr.5, "Mono: Incorrect message sorted in io-layer/messages.c at index %d (msg=%s)\n", i, D.11459);
    <D.11457>:
  }
  <D.11454>:
  i.3 = (unsigned int) i;
  D.11449 = i.3 * 8;
  D.11450 = base + D.11449;
  D.11451 = D.11450->id;
  D.11460 = (unsigned int) D.11451;
  if (D.11460 == id) goto <D.11461>; else goto <D.11462>;
  <D.11461>:
  {
    static int error_shown;

    error_shown.6 = error_shown;
    if (error_shown.6 == 0) goto <D.11464>; else goto <D.11465>;
    <D.11464>:
    error_shown = 1;
    stderr.5 = stderr;
    i.3 = (unsigned int) i;
    D.11449 = i.3 * 8;
    D.11450 = base + D.11449;
    D.11459 = D.11450->txt;
    fprintf (stderr.5, "Mono: Error %d with text %s is improperly sorted in io-layer/messages.c\n", id, D.11459);
    <D.11465>:
    i.3 = (unsigned int) i;
    D.11449 = i.3 * 8;
    D.11450 = base + D.11449;
    D.11466 = D.11450->txt;
    return D.11466;
  }
  <D.11462>:
  i = i + 1;
  <D.11360>:
  if (i < n) goto <D.11359>; else goto <D.11361>;
  <D.11361>:
  D.11466 = 0B;
  return D.11466;
}


unicode_chars (const gunichar2 * str)
{
  unsigned int D.11468;
  const gunichar2 * D.11469;
  short unsigned int D.11470;
  guint32 D.11473;
  guint32 len;

  len = 0;
  <D.11370>:
  D.11468 = len * 2;
  D.11469 = str + D.11468;
  D.11470 = *D.11469;
  if (D.11470 == 0) goto <D.11471>; else goto <D.11472>;
  <D.11471>:
  D.11473 = len;
  return D.11473;
  <D.11472>:
  len = len + 1;
  goto <D.11370>;
}


memcpy (void * restrict __dest, const void * restrict __src, size_t __len)
{
  void * D.11475;
  unsigned int D.11476;

  D.11476 = __builtin_object_size (__dest, 0);
  D.11475 = __builtin___memcpy_chk (__dest, __src, __len, D.11476);
  return D.11475;
}


