FormatMessage (guint32 flags, const void * source, guint32 messageid, guint32 languageid, gunichar2 * buf, guint32 size)
{
  unsigned int D.8810;
  guint32 D.8813;
  unsigned int D.8814;
  unsigned int D.8819;
  unsigned int D.8823;
  unsigned int D.8830;
  unsigned int D.8833;
  unsigned int D.8834;
  unsigned int D.8835;
  void * D.8836;
  unsigned int D.8840;
  gunichar2 * D.8841;
  guint32 strlen;
  guint32 cpy;
  gunichar2 * str;
  gboolean freestr;
  static const char __func__[14] = "FormatMessage";

  freestr = 0;
  D.8810 = flags & 10752;
  if (D.8810 != 512) goto <D.8811>; else goto <D.8812>;
  <D.8811>:
  monoeg_g_log (0B, 16, "%s: Unsupported flags passed: %d", &__func__, flags);
  SetLastError (50);
  D.8813 = 0;
  return D.8813;
  <D.8812>:
  D.8814 = flags & 255;
  if (D.8814 != 0) goto <D.8815>; else goto <D.8816>;
  <D.8815>:
  D.8814 = flags & 255;
  monoeg_g_log (0B, 16, "%s: Message width mask (%d) not supported", &__func__, D.8814);
  <D.8816>:
  if (languageid != 0) goto <D.8817>; else goto <D.8818>;
  <D.8817>:
  monoeg_g_log (0B, 16, "%s: Locale 0x%x not supported, returning language neutral string", &__func__, languageid);
  <D.8818>:
  D.8819 = flags & 1024;
  if (D.8819 != 0) goto <D.8820>; else goto <D.8821>;
  <D.8820>:
  str = source;
  goto <D.8822>;
  <D.8821>:
  D.8823 = flags & 4096;
  if (D.8823 != 0) goto <D.8824>; else goto <D.8825>;
  <D.8824>:
  {
    const char * msg;

    msg = message_string (messageid);
    if (msg != 0B) goto <D.8826>; else goto <D.8827>;
    <D.8826>:
    str = monoeg_g_utf8_to_utf16 (msg, -1, 0B, 0B, 0B);
    goto <D.8828>;
    <D.8827>:
    {
      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.8828>:
    freestr = 1;
  }
  goto <D.8829>;
  <D.8825>:
  str = monoeg_g_utf8_to_utf16 ("No message specified", -1, 0B, 0B, 0B);
  <D.8829>:
  <D.8822>:
  strlen = unicode_chars (str);
  D.8830 = flags & 256;
  if (D.8830 != 0) goto <D.8831>; else goto <D.8832>;
  <D.8831>:
  D.8833 = strlen + 2;
  D.8834 = MAX_EXPR <D.8833, size>;
  D.8835 = D.8834 * 2;
  D.8836 = monoeg_malloc0 (D.8835);
  MEM[(void * *)buf] = D.8836;
  <D.8832>:
  if (strlen >= size) goto <D.8837>; else goto <D.8838>;
  <D.8837>:
  cpy = size + 4294967295;
  goto <D.8839>;
  <D.8838>:
  cpy = strlen;
  <D.8839>:
  D.8840 = cpy * 2;
  memcpy (buf, str, D.8840);
  D.8840 = cpy * 2;
  D.8841 = buf + D.8840;
  *D.8841 = 0;
  if (freestr != 0) goto <D.8842>; else goto <D.8843>;
  <D.8842>:
  monoeg_g_free (str);
  <D.8843>:
  D.8813 = strlen;
  return D.8813;
}


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

  msg = find_msg (id, &common_messages, 85);
  if (msg != 0B) goto <D.8845>; else goto <D.8846>;
  <D.8845>:
  D.8847 = msg;
  return D.8847;
  <D.8846>:
  msg = find_msg (id, &messages, 1697);
  if (msg != 0B) goto <D.8848>; else goto <D.8849>;
  <D.8848>:
  stderr.0 = stderr;
  fprintf (stderr.0, "messages.c: A message was found on the uncommon code path: %d - %s", id, msg);
  D.8847 = msg;
  return D.8847;
  <D.8849>:
  msg = find_linear_msg (id, &common_messages, 85);
  if (msg != 0B) goto <D.8851>; else goto <D.8852>;
  <D.8851>:
  D.8847 = msg;
  return D.8847;
  <D.8852>:
  msg = find_linear_msg (id, &messages, 1697);
  if (msg != 0B) goto <D.8853>; else goto <D.8854>;
  <D.8853>:
  D.8847 = msg;
  return D.8847;
  <D.8854>:
  D.8847 = 0B;
  return D.8847;
}


find_msg (guint32 id, struct ErrorDesc * base, int n)
{
  int id.1;
  unsigned int n.2;
  const gchar * D.8860;
  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.8858>; else goto <D.8859>;
      <D.8858>:
      D.8860 = 0B;
      return D.8860;
      <D.8859>:
      D.8860 = result->txt;
      return D.8860;
    }
  finally
    {
      d = {CLOBBER};
    }
}


msg_compare (const void * first, const void * second)
{
  int D.8863;
  int D.8864;
  int D.8865;
  struct ErrorDesc * efirst;
  struct ErrorDesc * esecond;

  efirst = first;
  esecond = second;
  D.8864 = efirst->id;
  D.8865 = esecond->id;
  D.8863 = D.8864 - D.8865;
  return D.8863;
}


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

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


find_linear_msg (guint32 id, struct ErrorDesc * base, int n)
{
  unsigned int i.3;
  unsigned int D.8870;
  struct ErrorDesc * D.8871;
  int D.8872;
  int error_shown.4;
  struct _IO_FILE * stderr.5;
  const char * D.8880;
  unsigned int D.8881;
  int error_shown.6;
  const gchar * D.8887;
  int i;
  int prev;

  prev = -1;
  i = 0;
  goto <D.8783>;
  <D.8782>:
  i.3 = (unsigned int) i;
  D.8870 = i.3 * 8;
  D.8871 = base + D.8870;
  D.8872 = D.8871->id;
  if (D.8872 > prev) goto <D.8873>; else goto <D.8874>;
  <D.8873>:
  i.3 = (unsigned int) i;
  D.8870 = i.3 * 8;
  D.8871 = base + D.8870;
  prev = D.8871->id;
  goto <D.8875>;
  <D.8874>:
  {
    static int error_shown;

    error_shown.4 = error_shown;
    if (error_shown.4 == 0) goto <D.8877>; else goto <D.8878>;
    <D.8877>:
    error_shown = 1;
    stderr.5 = stderr;
    i.3 = (unsigned int) i;
    D.8870 = i.3 * 8;
    D.8871 = base + D.8870;
    D.8880 = D.8871->txt;
    fprintf (stderr.5, "Mono: Incorrect message sorted in io-layer/messages.c at index %d (msg=%s)\n", i, D.8880);
    <D.8878>:
  }
  <D.8875>:
  i.3 = (unsigned int) i;
  D.8870 = i.3 * 8;
  D.8871 = base + D.8870;
  D.8872 = D.8871->id;
  D.8881 = (unsigned int) D.8872;
  if (D.8881 == id) goto <D.8882>; else goto <D.8883>;
  <D.8882>:
  {
    static int error_shown;

    error_shown.6 = error_shown;
    if (error_shown.6 == 0) goto <D.8885>; else goto <D.8886>;
    <D.8885>:
    error_shown = 1;
    stderr.5 = stderr;
    i.3 = (unsigned int) i;
    D.8870 = i.3 * 8;
    D.8871 = base + D.8870;
    D.8880 = D.8871->txt;
    fprintf (stderr.5, "Mono: Error %d with text %s is improperly sorted in io-layer/messages.c\n", id, D.8880);
    <D.8886>:
    i.3 = (unsigned int) i;
    D.8870 = i.3 * 8;
    D.8871 = base + D.8870;
    D.8887 = D.8871->txt;
    return D.8887;
  }
  <D.8883>:
  i = i + 1;
  <D.8783>:
  if (i < n) goto <D.8782>; else goto <D.8784>;
  <D.8784>:
  D.8887 = 0B;
  return D.8887;
}


unicode_chars (const gunichar2 * str)
{
  unsigned int D.8889;
  const gunichar2 * D.8890;
  short unsigned int D.8891;
  guint32 D.8894;
  guint32 len;

  len = 0;
  <D.8793>:
  D.8889 = len * 2;
  D.8890 = str + D.8889;
  D.8891 = *D.8890;
  if (D.8891 == 0) goto <D.8892>; else goto <D.8893>;
  <D.8892>:
  D.8894 = len;
  return D.8894;
  <D.8893>:
  len = len + 1;
  goto <D.8793>;
}


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

  D.8897 = __builtin_object_size (__dest, 0);
  D.8896 = __builtin___memcpy_chk (__dest, __src, __len, D.8897);
  return D.8896;
}


