_wapi_stdhandle_create (int fd, const gchar * name)
{
  int * D.10472;
  int D.10473;
  int D.10476;
  unsigned int D.10477;
  void * D.10478;
  unsigned int D.10479;
  gchar * D.10480;
  unsigned int D.10483;
  unsigned int D.10484;
  struct _WapiHandle_file file_handle;
  void * handle;
  int flags;
  static const char __func__[23] = "_wapi_stdhandle_create";

  try
    {
      file_handle = {};
      <D.10467>:
      flags = fcntl (fd, 3);
      if (flags == -1) goto <D.10471>; else goto <D.10468>;
      <D.10471>:
      D.10472 = __errno_location ();
      D.10473 = *D.10472;
      if (D.10473 == 4) goto <D.10467>; else goto <D.10468>;
      <D.10468>:
      if (flags == -1) goto <D.10474>; else goto <D.10475>;
      <D.10474>:
      D.10472 = __errno_location ();
      D.10473 = *D.10472;
      D.10476 = _wapi_get_win32_file_error (D.10473);
      D.10477 = (unsigned int) D.10476;
      SetLastError (D.10477);
      D.10478 = -1B;
      return D.10478;
      <D.10475>:
      D.10479 = convert_from_flags (flags);
      file_handle.fileaccess = D.10479;
      file_handle.fd = fd;
      D.10480 = monoeg_strdup (name);
      file_handle.filename = D.10480;
      file_handle.security_attributes = 0;
      if (fd == 0) goto <D.10481>; else goto <D.10482>;
      <D.10481>:
      D.10483 = file_handle.fileaccess;
      D.10484 = D.10483 & 3221225471;
      file_handle.fileaccess = D.10484;
      <D.10482>:
      file_handle.sharemode = 0;
      file_handle.attrs = 0;
      handle = _wapi_handle_new_fd (2, fd, &file_handle);
      if (handle == -1B) goto <D.10485>; else goto <D.10486>;
      <D.10485>:
      monoeg_g_log (0B, 16, "%s: error creating file handle", &__func__);
      SetLastError (31);
      D.10478 = -1B;
      return D.10478;
      <D.10486>:
      D.10478 = handle;
      return D.10478;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


convert_from_flags (int flags)
{
  int D.10489;
  guint32 D.10499;
  guint32 fileaccess;

  fileaccess = 0;
  D.10489 = flags & 3;
  if (D.10489 == 0) goto <D.10490>; else goto <D.10491>;
  <D.10490>:
  fileaccess = 2147483648;
  goto <D.10492>;
  <D.10491>:
  D.10489 = flags & 3;
  if (D.10489 == 1) goto <D.10493>; else goto <D.10494>;
  <D.10493>:
  fileaccess = 1073741824;
  goto <D.10495>;
  <D.10494>:
  D.10489 = flags & 3;
  if (D.10489 == 2) goto <D.10496>; else goto <D.10497>;
  <D.10496>:
  fileaccess = 3221225472;
  goto <D.10498>;
  <D.10497>:
  <D.10498>:
  <D.10495>:
  <D.10492>:
  D.10499 = fileaccess;
  return D.10499;
}


monoeg_strdup (const gchar * str)
{
  gchar * D.10503;

  if (str != 0B) goto <D.10501>; else goto <D.10502>;
  <D.10501>:
  D.10503 = __strdup (str);
  return D.10503;
  <D.10502>:
  D.10503 = 0B;
  return D.10503;
}


