_wapi_stdhandle_create (int fd, const gchar * name)
{
  int * D.10990;
  int D.10991;
  int D.10994;
  unsigned int D.10995;
  void * D.10996;
  unsigned int D.10997;
  gchar * D.10998;
  unsigned int D.11001;
  unsigned int D.11002;
  struct _WapiHandle_file file_handle;
  void * handle;
  int flags;
  static const char __func__[23] = "_wapi_stdhandle_create";

  try
    {
      file_handle = {};
      <D.10985>:
      flags = fcntl (fd, 3);
      if (flags == -1) goto <D.10989>; else goto <D.10986>;
      <D.10989>:
      D.10990 = __errno_location ();
      D.10991 = *D.10990;
      if (D.10991 == 4) goto <D.10985>; else goto <D.10986>;
      <D.10986>:
      if (flags == -1) goto <D.10992>; else goto <D.10993>;
      <D.10992>:
      D.10990 = __errno_location ();
      D.10991 = *D.10990;
      D.10994 = _wapi_get_win32_file_error (D.10991);
      D.10995 = (unsigned int) D.10994;
      SetLastError (D.10995);
      D.10996 = -1B;
      return D.10996;
      <D.10993>:
      D.10997 = convert_from_flags (flags);
      file_handle.fileaccess = D.10997;
      file_handle.fd = fd;
      D.10998 = monoeg_strdup (name);
      file_handle.filename = D.10998;
      file_handle.security_attributes = 0;
      if (fd == 0) goto <D.10999>; else goto <D.11000>;
      <D.10999>:
      D.11001 = file_handle.fileaccess;
      D.11002 = D.11001 & 3221225471;
      file_handle.fileaccess = D.11002;
      <D.11000>:
      file_handle.sharemode = 0;
      file_handle.attrs = 0;
      handle = _wapi_handle_new_fd (2, fd, &file_handle);
      if (handle == -1B) goto <D.11003>; else goto <D.11004>;
      <D.11003>:
      monoeg_g_log (0B, 16, "%s: error creating file handle", &__func__);
      SetLastError (31);
      D.10996 = -1B;
      return D.10996;
      <D.11004>:
      D.10996 = handle;
      return D.10996;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


convert_from_flags (int flags)
{
  int D.11007;
  guint32 D.11017;
  guint32 fileaccess;

  fileaccess = 0;
  D.11007 = flags & 3;
  if (D.11007 == 0) goto <D.11008>; else goto <D.11009>;
  <D.11008>:
  fileaccess = 2147483648;
  goto <D.11010>;
  <D.11009>:
  D.11007 = flags & 3;
  if (D.11007 == 1) goto <D.11011>; else goto <D.11012>;
  <D.11011>:
  fileaccess = 1073741824;
  goto <D.11013>;
  <D.11012>:
  D.11007 = flags & 3;
  if (D.11007 == 2) goto <D.11014>; else goto <D.11015>;
  <D.11014>:
  fileaccess = 3221225472;
  goto <D.11016>;
  <D.11015>:
  <D.11016>:
  <D.11013>:
  <D.11010>:
  D.11017 = fileaccess;
  return D.11017;
}


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

  if (str != 0B) goto <D.11019>; else goto <D.11020>;
  <D.11019>:
  D.11021 = __strdup (str);
  return D.11021;
  <D.11020>:
  D.11021 = 0B;
  return D.11021;
}


