FormatMessage (guint32 flags, const void * source, guint32 messageid, guint32 languageid, gunichar2 * buf, guint32 size)
{
  unsigned int D.9646;
  guint32 D.9649;
  unsigned int D.9650;
  unsigned int D.9655;
  unsigned int D.9659;
  unsigned int D.9666;
  long unsigned int iftmp.0;
  unsigned int D.9670;
  long unsigned int D.9673;
  long unsigned int D.9675;
  void * D.9676;
  unsigned int D.9680;
  long unsigned int D.9681;
  long unsigned int D.9682;
  long unsigned int D.9683;
  gunichar2 * D.9684;
  guint32 strlen;
  guint32 cpy;
  gunichar2 * str;
  gboolean freestr;
  static const char __func__[14] = "FormatMessage";

  freestr = 0;
  D.9646 = flags & 10752;
  if (D.9646 != 512) goto <D.9647>; else goto <D.9648>;
  <D.9647>:
  monoeg_g_log (0B, 16, "%s: Unsupported flags passed: %d", &__func__, flags);
  SetLastError (50);
  D.9649 = 0;
  return D.9649;
  <D.9648>:
  D.9650 = flags & 255;
  if (D.9650 != 0) goto <D.9651>; else goto <D.9652>;
  <D.9651>:
  D.9650 = flags & 255;
  monoeg_g_log (0B, 16, "%s: Message width mask (%d) not supported", &__func__, D.9650);
  <D.9652>:
  if (languageid != 0) goto <D.9653>; else goto <D.9654>;
  <D.9653>:
  monoeg_g_log (0B, 16, "%s: Locale 0x%x not supported, returning language neutral string", &__func__, languageid);
  <D.9654>:
  D.9655 = flags & 1024;
  if (D.9655 != 0) goto <D.9656>; else goto <D.9657>;
  <D.9656>:
  str = source;
  goto <D.9658>;
  <D.9657>:
  D.9659 = flags & 4096;
  if (D.9659 != 0) goto <D.9660>; else goto <D.9661>;
  <D.9660>:
  {
    const char * msg;

    msg = message_string (messageid);
    if (msg != 0B) goto <D.9662>; else goto <D.9663>;
    <D.9662>:
    str = monoeg_g_utf8_to_utf16 (msg, -1, 0B, 0B, 0B);
    goto <D.9664>;
    <D.9663>:
    {
      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.9664>:
    freestr = 1;
  }
  goto <D.9665>;
  <D.9661>:
  str = monoeg_g_utf8_to_utf16 ("No message specified", -1, 0B, 0B, 0B);
  <D.9665>:
  <D.9658>:
  strlen = unicode_chars (str);
  D.9666 = flags & 256;
  if (D.9666 != 0) goto <D.9667>; else goto <D.9668>;
  <D.9667>:
  D.9670 = strlen + 2;
  if (D.9670 < size) goto <D.9671>; else goto <D.9672>;
  <D.9671>:
  D.9673 = (long unsigned int) size;
  iftmp.0 = D.9673 * 2;
  goto <D.9674>;
  <D.9672>:
  D.9670 = strlen + 2;
  D.9675 = (long unsigned int) D.9670;
  iftmp.0 = D.9675 * 2;
  <D.9674>:
  D.9676 = monoeg_malloc0 (iftmp.0);
  MEM[(void * *)buf] = D.9676;
  <D.9668>:
  if (strlen >= size) goto <D.9677>; else goto <D.9678>;
  <D.9677>:
  cpy = size + 4294967295;
  goto <D.9679>;
  <D.9678>:
  cpy = strlen;
  <D.9679>:
  D.9680 = cpy * 2;
  D.9681 = (long unsigned int) D.9680;
  memcpy (buf, str, D.9681);
  D.9682 = (long unsigned int) cpy;
  D.9683 = D.9682 * 2;
  D.9684 = buf + D.9683;
  *D.9684 = 0;
  if (freestr != 0) goto <D.9685>; else goto <D.9686>;
  <D.9685>:
  monoeg_g_free (str);
  <D.9686>:
  D.9649 = strlen;
  return D.9649;
}


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

  msg = find_msg (id, &common_messages, 85);
  if (msg != 0B) goto <D.9688>; else goto <D.9689>;
  <D.9688>:
  D.9690 = msg;
  return D.9690;
  <D.9689>:
  msg = find_msg (id, &messages, 1697);
  if (msg != 0B) goto <D.9691>; else goto <D.9692>;
  <D.9691>:
  stderr.1 = stderr;
  fprintf (stderr.1, "messages.c: A message was found on the uncommon code path: %d - %s", id, msg);
  D.9690 = msg;
  return D.9690;
  <D.9692>:
  msg = find_linear_msg (id, &common_messages, 85);
  if (msg != 0B) goto <D.9694>; else goto <D.9695>;
  <D.9694>:
  D.9690 = msg;
  return D.9690;
  <D.9695>:
  msg = find_linear_msg (id, &messages, 1697);
  if (msg != 0B) goto <D.9696>; else goto <D.9697>;
  <D.9696>:
  D.9690 = msg;
  return D.9690;
  <D.9697>:
  D.9690 = 0B;
  return D.9690;
}


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

  try
    {
      id.2 = (int) id;
      d.id = id.2;
      D.9700 = (long unsigned int) n;
      result = mono_binary_search (&d, base, D.9700, 16, msg_compare);
      if (result == 0B) goto <D.9701>; else goto <D.9702>;
      <D.9701>:
      D.9703 = 0B;
      return D.9703;
      <D.9702>:
      D.9703 = result->txt;
      return D.9703;
    }
  finally
    {
      d = {CLOBBER};
    }
}


msg_compare (const void * first, const void * second)
{
  int D.9706;
  int D.9707;
  int D.9708;
  struct ErrorDesc * efirst;
  struct ErrorDesc * esecond;

  efirst = first;
  esecond = second;
  D.9707 = efirst->id;
  D.9708 = esecond->id;
  D.9706 = D.9707 - D.9708;
  return D.9706;
}


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

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


find_linear_msg (guint32 id, struct ErrorDesc * base, int n)
{
  long unsigned int D.9712;
  long unsigned int D.9713;
  struct ErrorDesc * D.9714;
  int D.9715;
  int error_shown.3;
  struct _IO_FILE * stderr.4;
  const char * D.9723;
  unsigned int D.9724;
  int error_shown.5;
  const gchar * D.9730;
  int i;
  int prev;

  prev = -1;
  i = 0;
  goto <D.9619>;
  <D.9618>:
  D.9712 = (long unsigned int) i;
  D.9713 = D.9712 * 16;
  D.9714 = base + D.9713;
  D.9715 = D.9714->id;
  if (D.9715 > prev) goto <D.9716>; else goto <D.9717>;
  <D.9716>:
  D.9712 = (long unsigned int) i;
  D.9713 = D.9712 * 16;
  D.9714 = base + D.9713;
  prev = D.9714->id;
  goto <D.9718>;
  <D.9717>:
  {
    static int error_shown;

    error_shown.3 = error_shown;
    if (error_shown.3 == 0) goto <D.9720>; else goto <D.9721>;
    <D.9720>:
    error_shown = 1;
    stderr.4 = stderr;
    D.9712 = (long unsigned int) i;
    D.9713 = D.9712 * 16;
    D.9714 = base + D.9713;
    D.9723 = D.9714->txt;
    fprintf (stderr.4, "Mono: Incorrect message sorted in io-layer/messages.c at index %d (msg=%s)\n", i, D.9723);
    <D.9721>:
  }
  <D.9718>:
  D.9712 = (long unsigned int) i;
  D.9713 = D.9712 * 16;
  D.9714 = base + D.9713;
  D.9715 = D.9714->id;
  D.9724 = (unsigned int) D.9715;
  if (D.9724 == id) goto <D.9725>; else goto <D.9726>;
  <D.9725>:
  {
    static int error_shown;

    error_shown.5 = error_shown;
    if (error_shown.5 == 0) goto <D.9728>; else goto <D.9729>;
    <D.9728>:
    error_shown = 1;
    stderr.4 = stderr;
    D.9712 = (long unsigned int) i;
    D.9713 = D.9712 * 16;
    D.9714 = base + D.9713;
    D.9723 = D.9714->txt;
    fprintf (stderr.4, "Mono: Error %d with text %s is improperly sorted in io-layer/messages.c\n", id, D.9723);
    <D.9729>:
    D.9712 = (long unsigned int) i;
    D.9713 = D.9712 * 16;
    D.9714 = base + D.9713;
    D.9730 = D.9714->txt;
    return D.9730;
  }
  <D.9726>:
  i = i + 1;
  <D.9619>:
  if (i < n) goto <D.9618>; else goto <D.9620>;
  <D.9620>:
  D.9730 = 0B;
  return D.9730;
}


unicode_chars (const gunichar2 * str)
{
  long unsigned int D.9732;
  long unsigned int D.9733;
  const gunichar2 * D.9734;
  short unsigned int D.9735;
  guint32 D.9738;
  guint32 len;

  len = 0;
  <D.9629>:
  D.9732 = (long unsigned int) len;
  D.9733 = D.9732 * 2;
  D.9734 = str + D.9733;
  D.9735 = *D.9734;
  if (D.9735 == 0) goto <D.9736>; else goto <D.9737>;
  <D.9736>:
  D.9738 = len;
  return D.9738;
  <D.9737>:
  len = len + 1;
  goto <D.9629>;
}


memcpy (void * restrict __dest, const void * restrict __src, size_t __len)
{
  void * D.9740;
  long unsigned int D.9741;

  D.9741 = __builtin_object_size (__dest, 0);
  D.9740 = __builtin___memcpy_chk (__dest, __src, __len, D.9741);
  return D.9740;
}


