_wapi_stdhandle_create (int fd, const gchar * name)
{
  int * D.10648;
  int D.10649;
  int D.10652;
  unsigned int D.10653;
  void * D.10654;
  unsigned int D.10655;
  gchar * D.10656;
  unsigned int D.10659;
  unsigned int D.10660;
  struct _WapiHandle_file file_handle;
  void * handle;
  int flags;
  static const char __func__[23] = "_wapi_stdhandle_create";

  try
    {
      file_handle = {};
      <D.10643>:
      flags = fcntl (fd, 3);
      if (flags == -1) goto <D.10647>; else goto <D.10644>;
      <D.10647>:
      D.10648 = __errno_location ();
      D.10649 = *D.10648;
      if (D.10649 == 4) goto <D.10643>; else goto <D.10644>;
      <D.10644>:
      if (flags == -1) goto <D.10650>; else goto <D.10651>;
      <D.10650>:
      D.10648 = __errno_location ();
      D.10649 = *D.10648;
      D.10652 = _wapi_get_win32_file_error (D.10649);
      D.10653 = (unsigned int) D.10652;
      SetLastError (D.10653);
      D.10654 = -1B;
      return D.10654;
      <D.10651>:
      D.10655 = convert_from_flags (flags);
      file_handle.fileaccess = D.10655;
      file_handle.fd = fd;
      D.10656 = monoeg_strdup (name);
      file_handle.filename = D.10656;
      file_handle.security_attributes = 0;
      if (fd == 0) goto <D.10657>; else goto <D.10658>;
      <D.10657>:
      D.10659 = file_handle.fileaccess;
      D.10660 = D.10659 & 3221225471;
      file_handle.fileaccess = D.10660;
      <D.10658>:
      file_handle.sharemode = 0;
      file_handle.attrs = 0;
      handle = _wapi_handle_new_fd (2, fd, &file_handle);
      if (handle == -1B) goto <D.10661>; else goto <D.10662>;
      <D.10661>:
      monoeg_g_log (0B, 16, "%s: error creating file handle", &__func__);
      SetLastError (31);
      D.10654 = -1B;
      return D.10654;
      <D.10662>:
      D.10654 = handle;
      return D.10654;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


convert_from_flags (int flags)
{
  int D.10665;
  guint32 D.10675;
  guint32 fileaccess;

  fileaccess = 0;
  D.10665 = flags & 3;
  if (D.10665 == 0) goto <D.10666>; else goto <D.10667>;
  <D.10666>:
  fileaccess = 2147483648;
  goto <D.10668>;
  <D.10667>:
  D.10665 = flags & 3;
  if (D.10665 == 1) goto <D.10669>; else goto <D.10670>;
  <D.10669>:
  fileaccess = 1073741824;
  goto <D.10671>;
  <D.10670>:
  D.10665 = flags & 3;
  if (D.10665 == 2) goto <D.10672>; else goto <D.10673>;
  <D.10672>:
  fileaccess = 3221225472;
  goto <D.10674>;
  <D.10673>:
  <D.10674>:
  <D.10671>:
  <D.10668>:
  D.10675 = fileaccess;
  return D.10675;
}


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

  if (str != 0B) goto <D.10677>; else goto <D.10678>;
  <D.10677>:
  D.10679 = __strdup (str);
  return D.10679;
  <D.10678>:
  D.10679 = 0B;
  return D.10679;
}


