_wapi_stdhandle_create (int fd, const gchar * name)
{
  int * D.12750;
  int D.12751;
  int D.12754;
  unsigned int D.12755;
  void * D.12756;
  unsigned int D.12757;
  gchar * D.12758;
  unsigned int D.12761;
  unsigned int D.12762;
  struct _WapiHandle_file file_handle;
  void * handle;
  int flags;
  static const char __func__[23] = "_wapi_stdhandle_create";

  try
    {
      file_handle = {};
      <D.12743>:
      flags = fcntl (fd, 3);
      if (flags == -1) goto <D.12749>; else goto <D.12744>;
      <D.12749>:
      D.12750 = __errno_location ();
      D.12751 = *D.12750;
      if (D.12751 == 4) goto <D.12743>; else goto <D.12744>;
      <D.12744>:
      if (flags == -1) goto <D.12752>; else goto <D.12753>;
      <D.12752>:
      D.12750 = __errno_location ();
      D.12751 = *D.12750;
      D.12754 = _wapi_get_win32_file_error (D.12751);
      D.12755 = (unsigned int) D.12754;
      SetLastError (D.12755);
      D.12756 = 4294967295B;
      return D.12756;
      <D.12753>:
      D.12757 = convert_from_flags (flags);
      file_handle.fileaccess = D.12757;
      file_handle.fd = fd;
      D.12758 = monoeg_strdup (name);
      file_handle.filename = D.12758;
      file_handle.security_attributes = 0;
      if (fd == 0) goto <D.12759>; else goto <D.12760>;
      <D.12759>:
      D.12761 = file_handle.fileaccess;
      D.12762 = D.12761 & 3221225471;
      file_handle.fileaccess = D.12762;
      <D.12760>:
      file_handle.sharemode = 0;
      file_handle.attrs = 0;
      handle = _wapi_handle_new_fd (2, fd, &file_handle);
      if (handle == 4294967295B) goto <D.12763>; else goto <D.12764>;
      <D.12763>:
      monoeg_g_log (0B, 16, "%s: error creating file handle", &__func__);
      SetLastError (31);
      D.12756 = 4294967295B;
      return D.12756;
      <D.12764>:
      D.12756 = handle;
      return D.12756;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


convert_from_flags (int flags)
{
  int D.12767;
  guint32 D.12777;
  guint32 fileaccess;

  fileaccess = 0;
  D.12767 = flags & 3;
  if (D.12767 == 0) goto <D.12768>; else goto <D.12769>;
  <D.12768>:
  fileaccess = 2147483648;
  goto <D.12770>;
  <D.12769>:
  D.12767 = flags & 3;
  if (D.12767 == 1) goto <D.12771>; else goto <D.12772>;
  <D.12771>:
  fileaccess = 1073741824;
  goto <D.12773>;
  <D.12772>:
  D.12767 = flags & 3;
  if (D.12767 == 2) goto <D.12774>; else goto <D.12775>;
  <D.12774>:
  fileaccess = 3221225472;
  goto <D.12776>;
  <D.12775>:
  <D.12776>:
  <D.12773>:
  <D.12770>:
  D.12777 = fileaccess;
  return D.12777;
}


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

  if (str != 0B) goto <D.12779>; else goto <D.12780>;
  <D.12779>:
  D.12781 = __strdup (str);
  return D.12781;
  <D.12780>:
  D.12781 = 0B;
  return D.12781;
}


