FormatMessage (guint32 flags, const void * source, guint32 messageid, guint32 languageid, gunichar2 * buf, guint32 size)
{
  unsigned int D.8780;
  guint32 D.8783;
  unsigned int D.8784;
  unsigned int D.8789;
  unsigned int D.8793;
  unsigned int D.8800;
  unsigned int D.8803;
  unsigned int D.8804;
  unsigned int D.8805;
  void * D.8806;
  unsigned int D.8810;
  gunichar2 * D.8811;
  guint32 strlen;
  guint32 cpy;
  gunichar2 * str;
  gboolean freestr;
  static const char __func__[14] = "FormatMessage";

  freestr = 0;
  D.8780 = flags & 10752;
  if (D.8780 != 512) goto <D.8781>; else goto <D.8782>;
  <D.8781>:
  monoeg_g_log (0B, 16, "%s: Unsupported flags passed: %d", &__func__, flags);
  SetLastError (50);
  D.8783 = 0;
  return D.8783;
  <D.8782>:
  D.8784 = flags & 255;
  if (D.8784 != 0) goto <D.8785>; else goto <D.8786>;
  <D.8785>:
  D.8784 = flags & 255;
  monoeg_g_log (0B, 16, "%s: Message width mask (%d) not supported", &__func__, D.8784);
  <D.8786>:
  if (languageid != 0) goto <D.8787>; else goto <D.8788>;
  <D.8787>:
  monoeg_g_log (0B, 16, "%s: Locale 0x%x not supported, returning language neutral string", &__func__, languageid);
  <D.8788>:
  D.8789 = flags & 1024;
  if (D.8789 != 0) goto <D.8790>; else goto <D.8791>;
  <D.8790>:
  str = source;
  goto <D.8792>;
  <D.8791>:
  D.8793 = flags & 4096;
  if (D.8793 != 0) goto <D.8794>; else goto <D.8795>;
  <D.8794>:
  {
    const char * msg;

    msg = message_string (messageid);
    if (msg != 0B) goto <D.8796>; else goto <D.8797>;
    <D.8796>:
    str = monoeg_g_utf8_to_utf16 (msg, -1, 0B, 0B, 0B);
    goto <D.8798>;
    <D.8797>:
    {
      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.8798>:
    freestr = 1;
  }
  goto <D.8799>;
  <D.8795>:
  str = monoeg_g_utf8_to_utf16 ("No message specified", -1, 0B, 0B, 0B);
  <D.8799>:
  <D.8792>:
  strlen = unicode_chars (str);
  D.8800 = flags & 256;
  if (D.8800 != 0) goto <D.8801>; else goto <D.8802>;
  <D.8801>:
  D.8803 = strlen + 2;
  D.8804 = MAX_EXPR <D.8803, size>;
  D.8805 = D.8804 * 2;
  D.8806 = monoeg_malloc0 (D.8805);
  MEM[(void * *)buf] = D.8806;
  <D.8802>:
  if (strlen >= size) goto <D.8807>; else goto <D.8808>;
  <D.8807>:
  cpy = size + 4294967295;
  goto <D.8809>;
  <D.8808>:
  cpy = strlen;
  <D.8809>:
  D.8810 = cpy * 2;
  memcpy (buf, str, D.8810);
  D.8810 = cpy * 2;
  D.8811 = buf + D.8810;
  *D.8811 = 0;
  if (freestr != 0) goto <D.8812>; else goto <D.8813>;
  <D.8812>:
  monoeg_g_free (str);
  <D.8813>:
  D.8783 = strlen;
  return D.8783;
}


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

  msg = find_msg (id, &common_messages, 85);
  if (msg != 0B) goto <D.8815>; else goto <D.8816>;
  <D.8815>:
  D.8817 = msg;
  return D.8817;
  <D.8816>:
  msg = find_msg (id, &messages, 1697);
  if (msg != 0B) goto <D.8818>; else goto <D.8819>;
  <D.8818>:
  stderr.0 = stderr;
  fprintf (stderr.0, "messages.c: A message was found on the uncommon code path: %d - %s", id, msg);
  D.8817 = msg;
  return D.8817;
  <D.8819>:
  msg = find_linear_msg (id, &common_messages, 85);
  if (msg != 0B) goto <D.8821>; else goto <D.8822>;
  <D.8821>:
  D.8817 = msg;
  return D.8817;
  <D.8822>:
  msg = find_linear_msg (id, &messages, 1697);
  if (msg != 0B) goto <D.8823>; else goto <D.8824>;
  <D.8823>:
  D.8817 = msg;
  return D.8817;
  <D.8824>:
  D.8817 = 0B;
  return D.8817;
}


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


msg_compare (const void * first, const void * second)
{
  int D.8833;
  int D.8834;
  int D.8835;
  struct ErrorDesc * efirst;
  struct ErrorDesc * esecond;

  efirst = first;
  esecond = second;
  D.8834 = efirst->id;
  D.8835 = esecond->id;
  D.8833 = D.8834 - D.8835;
  return D.8833;
}


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

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


find_linear_msg (guint32 id, struct ErrorDesc * base, int n)
{
  unsigned int i.3;
  unsigned int D.8840;
  struct ErrorDesc * D.8841;
  int D.8842;
  int error_shown.4;
  const char * D.8849;
  struct _IO_FILE * stderr.5;
  unsigned int D.8851;
  int error_shown.6;
  const gchar * D.8857;
  int i;
  int prev;

  prev = -1;
  i = 0;
  goto <D.8753>;
  <D.8752>:
  i.3 = (unsigned int) i;
  D.8840 = i.3 * 8;
  D.8841 = base + D.8840;
  D.8842 = D.8841->id;
  if (D.8842 > prev) goto <D.8843>; else goto <D.8844>;
  <D.8843>:
  i.3 = (unsigned int) i;
  D.8840 = i.3 * 8;
  D.8841 = base + D.8840;
  prev = D.8841->id;
  goto <D.8845>;
  <D.8844>:
  {
    static int error_shown;

    error_shown.4 = error_shown;
    if (error_shown.4 == 0) goto <D.8847>; else goto <D.8848>;
    <D.8847>:
    error_shown = 1;
    i.3 = (unsigned int) i;
    D.8840 = i.3 * 8;
    D.8841 = base + D.8840;
    D.8849 = D.8841->txt;
    stderr.5 = stderr;
    fprintf (stderr.5, "Mono: Incorrect message sorted in io-layer/messages.c at index %d (msg=%s)\n", i, D.8849);
    <D.8848>:
  }
  <D.8845>:
  i.3 = (unsigned int) i;
  D.8840 = i.3 * 8;
  D.8841 = base + D.8840;
  D.8842 = D.8841->id;
  D.8851 = (unsigned int) D.8842;
  if (D.8851 == id) goto <D.8852>; else goto <D.8853>;
  <D.8852>:
  {
    static int error_shown;

    error_shown.6 = error_shown;
    if (error_shown.6 == 0) goto <D.8855>; else goto <D.8856>;
    <D.8855>:
    error_shown = 1;
    i.3 = (unsigned int) i;
    D.8840 = i.3 * 8;
    D.8841 = base + D.8840;
    D.8849 = D.8841->txt;
    stderr.5 = stderr;
    fprintf (stderr.5, "Mono: Error %d with text %s is improperly sorted in io-layer/messages.c\n", id, D.8849);
    <D.8856>:
    i.3 = (unsigned int) i;
    D.8840 = i.3 * 8;
    D.8841 = base + D.8840;
    D.8857 = D.8841->txt;
    return D.8857;
  }
  <D.8853>:
  i = i + 1;
  <D.8753>:
  if (i < n) goto <D.8752>; else goto <D.8754>;
  <D.8754>:
  D.8857 = 0B;
  return D.8857;
}


unicode_chars (const gunichar2 * str)
{
  unsigned int D.8859;
  const gunichar2 * D.8860;
  short unsigned int D.8861;
  guint32 D.8864;
  guint32 len;

  len = 0;
  <D.8763>:
  D.8859 = len * 2;
  D.8860 = str + D.8859;
  D.8861 = *D.8860;
  if (D.8861 == 0) goto <D.8862>; else goto <D.8863>;
  <D.8862>:
  D.8864 = len;
  return D.8864;
  <D.8863>:
  len = len + 1;
  goto <D.8763>;
}


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

  D.8867 = __builtin_object_size (__dest, 0);
  D.8866 = __builtin___memcpy_chk (__dest, __src, __len, D.8867);
  return D.8866;
}


