_wapi_stdhandle_create (int fd, const gchar * name)
{
  int * D.10124;
  int D.10125;
  int D.10128;
  unsigned int D.10129;
  void * D.10130;
  unsigned int D.10131;
  gchar * D.10132;
  unsigned int D.10135;
  unsigned int D.10136;
  struct _WapiHandle_file file_handle;
  void * handle;
  int flags;
  static const char __func__[23] = "_wapi_stdhandle_create";

  try
    {
      file_handle = {};
      <D.10119>:
      flags = fcntl (fd, 3);
      if (flags == -1) goto <D.10123>; else goto <D.10120>;
      <D.10123>:
      D.10124 = __errno_location ();
      D.10125 = *D.10124;
      if (D.10125 == 4) goto <D.10119>; else goto <D.10120>;
      <D.10120>:
      if (flags == -1) goto <D.10126>; else goto <D.10127>;
      <D.10126>:
      D.10124 = __errno_location ();
      D.10125 = *D.10124;
      D.10128 = _wapi_get_win32_file_error (D.10125);
      D.10129 = (unsigned int) D.10128;
      SetLastError (D.10129);
      D.10130 = 4294967295B;
      return D.10130;
      <D.10127>:
      D.10131 = convert_from_flags (flags);
      file_handle.fileaccess = D.10131;
      file_handle.fd = fd;
      D.10132 = monoeg_strdup (name);
      file_handle.filename = D.10132;
      file_handle.security_attributes = 0;
      if (fd == 0) goto <D.10133>; else goto <D.10134>;
      <D.10133>:
      D.10135 = file_handle.fileaccess;
      D.10136 = D.10135 & 3221225471;
      file_handle.fileaccess = D.10136;
      <D.10134>:
      file_handle.sharemode = 0;
      file_handle.attrs = 0;
      handle = _wapi_handle_new_fd (2, fd, &file_handle);
      if (handle == 4294967295B) goto <D.10137>; else goto <D.10138>;
      <D.10137>:
      monoeg_g_log (0B, 16, "%s: error creating file handle", &__func__);
      SetLastError (31);
      D.10130 = 4294967295B;
      return D.10130;
      <D.10138>:
      D.10130 = handle;
      return D.10130;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


convert_from_flags (int flags)
{
  int D.10141;
  guint32 D.10151;
  guint32 fileaccess;

  fileaccess = 0;
  D.10141 = flags & 3;
  if (D.10141 == 0) goto <D.10142>; else goto <D.10143>;
  <D.10142>:
  fileaccess = 2147483648;
  goto <D.10144>;
  <D.10143>:
  D.10141 = flags & 3;
  if (D.10141 == 1) goto <D.10145>; else goto <D.10146>;
  <D.10145>:
  fileaccess = 1073741824;
  goto <D.10147>;
  <D.10146>:
  D.10141 = flags & 3;
  if (D.10141 == 2) goto <D.10148>; else goto <D.10149>;
  <D.10148>:
  fileaccess = 3221225472;
  goto <D.10150>;
  <D.10149>:
  <D.10150>:
  <D.10147>:
  <D.10144>:
  D.10151 = fileaccess;
  return D.10151;
}


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

  if (str != 0B) goto <D.10153>; else goto <D.10154>;
  <D.10153>:
  D.10155 = __strdup (str);
  return D.10155;
  <D.10154>:
  D.10155 = 0B;
  return D.10155;
}


