_wapi_stdhandle_create (int fd, const gchar * name)
{
  int * D.10169;
  int D.10170;
  int D.10173;
  unsigned int D.10174;
  void * D.10175;
  unsigned int D.10176;
  gchar * D.10177;
  unsigned int D.10180;
  unsigned int D.10181;
  struct _WapiHandle_file file_handle;
  void * handle;
  int flags;
  static const char __func__[23] = "_wapi_stdhandle_create";

  try
    {
      file_handle = {};
      <D.10164>:
      flags = fcntl (fd, 3);
      if (flags == -1) goto <D.10168>; else goto <D.10165>;
      <D.10168>:
      D.10169 = __errno_location ();
      D.10170 = *D.10169;
      if (D.10170 == 4) goto <D.10164>; else goto <D.10165>;
      <D.10165>:
      if (flags == -1) goto <D.10171>; else goto <D.10172>;
      <D.10171>:
      D.10169 = __errno_location ();
      D.10170 = *D.10169;
      D.10173 = _wapi_get_win32_file_error (D.10170);
      D.10174 = (unsigned int) D.10173;
      SetLastError (D.10174);
      D.10175 = 4294967295B;
      return D.10175;
      <D.10172>:
      D.10176 = convert_from_flags (flags);
      file_handle.fileaccess = D.10176;
      file_handle.fd = fd;
      D.10177 = monoeg_strdup (name);
      file_handle.filename = D.10177;
      file_handle.security_attributes = 0;
      if (fd == 0) goto <D.10178>; else goto <D.10179>;
      <D.10178>:
      D.10180 = file_handle.fileaccess;
      D.10181 = D.10180 & 3221225471;
      file_handle.fileaccess = D.10181;
      <D.10179>:
      file_handle.sharemode = 0;
      file_handle.attrs = 0;
      handle = _wapi_handle_new_fd (2, fd, &file_handle);
      if (handle == 4294967295B) goto <D.10182>; else goto <D.10183>;
      <D.10182>:
      monoeg_g_log (0B, 16, "%s: error creating file handle", &__func__);
      SetLastError (31);
      D.10175 = 4294967295B;
      return D.10175;
      <D.10183>:
      D.10175 = handle;
      return D.10175;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


convert_from_flags (int flags)
{
  int D.10186;
  guint32 D.10196;
  guint32 fileaccess;

  fileaccess = 0;
  D.10186 = flags & 3;
  if (D.10186 == 0) goto <D.10187>; else goto <D.10188>;
  <D.10187>:
  fileaccess = 2147483648;
  goto <D.10189>;
  <D.10188>:
  D.10186 = flags & 3;
  if (D.10186 == 1) goto <D.10190>; else goto <D.10191>;
  <D.10190>:
  fileaccess = 1073741824;
  goto <D.10192>;
  <D.10191>:
  D.10186 = flags & 3;
  if (D.10186 == 2) goto <D.10193>; else goto <D.10194>;
  <D.10193>:
  fileaccess = 3221225472;
  goto <D.10195>;
  <D.10194>:
  <D.10195>:
  <D.10192>:
  <D.10189>:
  D.10196 = fileaccess;
  return D.10196;
}


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

  if (str != 0B) goto <D.10198>; else goto <D.10199>;
  <D.10198>:
  D.10200 = __strdup (str);
  return D.10200;
  <D.10199>:
  D.10200 = 0B;
  return D.10200;
}


