_wapi_lock_file_region (int fd, off_t offset, off_t length)
{
  gboolean D.9785;
  int * D.9787;
  int D.9788;
  struct flock lock_data;
  int ret;

  try
    {
      if (offset < 0) goto <D.9782>; else goto <D.9784>;
      <D.9784>:
      if (length < 0) goto <D.9782>; else goto <D.9783>;
      <D.9782>:
      SetLastError (87);
      D.9785 = 0;
      return D.9785;
      <D.9783>:
      lock_data.l_type = 1;
      lock_data.l_whence = 0;
      lock_data.l_start = offset;
      lock_data.l_len = length;
      <D.9744>:
      ret = fcntl (fd, 6, &lock_data);
      if (ret == -1) goto <D.9786>; else goto <D.9745>;
      <D.9786>:
      D.9787 = __errno_location ();
      D.9788 = *D.9787;
      if (D.9788 == 4) goto <D.9744>; else goto <D.9745>;
      <D.9745>:
      if (ret == -1) goto <D.9789>; else goto <D.9790>;
      <D.9789>:
      D.9787 = __errno_location ();
      D.9788 = *D.9787;
      if (D.9788 == 37) goto <D.9791>; else goto <D.9793>;
      <D.9793>:
      D.9787 = __errno_location ();
      D.9788 = *D.9787;
      if (D.9788 == 95) goto <D.9791>; else goto <D.9794>;
      <D.9794>:
      D.9787 = __errno_location ();
      D.9788 = *D.9787;
      if (D.9788 == 95) goto <D.9791>; else goto <D.9792>;
      <D.9791>:
      D.9785 = 1;
      return D.9785;
      <D.9792>:
      SetLastError (33);
      D.9785 = 0;
      return D.9785;
      <D.9790>:
      D.9785 = 1;
      return D.9785;
    }
  finally
    {
      lock_data = {CLOBBER};
    }
}


_wapi_unlock_file_region (int fd, off_t offset, off_t length)
{
  int * D.9798;
  int D.9799;
  gboolean D.9806;
  struct flock lock_data;
  int ret;

  try
    {
      lock_data.l_type = 2;
      lock_data.l_whence = 0;
      lock_data.l_start = offset;
      lock_data.l_len = length;
      <D.9753>:
      ret = fcntl (fd, 6, &lock_data);
      if (ret == -1) goto <D.9797>; else goto <D.9754>;
      <D.9797>:
      D.9798 = __errno_location ();
      D.9799 = *D.9798;
      if (D.9799 == 4) goto <D.9753>; else goto <D.9754>;
      <D.9754>:
      if (ret == -1) goto <D.9800>; else goto <D.9801>;
      <D.9800>:
      D.9798 = __errno_location ();
      D.9799 = *D.9798;
      if (D.9799 == 37) goto <D.9802>; else goto <D.9804>;
      <D.9804>:
      D.9798 = __errno_location ();
      D.9799 = *D.9798;
      if (D.9799 == 95) goto <D.9802>; else goto <D.9805>;
      <D.9805>:
      D.9798 = __errno_location ();
      D.9799 = *D.9798;
      if (D.9799 == 95) goto <D.9802>; else goto <D.9803>;
      <D.9802>:
      D.9806 = 1;
      return D.9806;
      <D.9803>:
      SetLastError (33);
      D.9806 = 0;
      return D.9806;
      <D.9801>:
      D.9806 = 1;
      return D.9806;
    }
  finally
    {
      lock_data = {CLOBBER};
    }
}


LockFile (void * handle, guint32 offset_low, guint32 offset_high, guint32 length_low, guint32 length_high)
{
  long int handle.0;
  gboolean D.9812;
  struct _WapiHandle_file * file_handle.1;
  unsigned int D.9814;
  signed int D.9815;
  long unsigned int D.9818;
  long unsigned int D.9819;
  long int D.9822;
  long int D.9823;
  long int D.9824;
  long int D.9825;
  long int D.9826;
  long int D.9827;
  struct _WapiHandle_file * file_handle;
  gboolean ok;
  off_t offset;
  off_t length;
  int fd;
  static const char __func__[9] = "LockFile";

  try
    {
      handle.0 = (long int) handle;
      fd = (int) handle.0;
      ok = _wapi_lookup_handle (handle, 1, &file_handle);
      if (ok == 0) goto <D.9810>; else goto <D.9811>;
      <D.9810>:
      monoeg_g_log (0B, 16, "%s: error looking up file handle %p", &__func__, handle);
      SetLastError (6);
      D.9812 = 0;
      return D.9812;
      <D.9811>:
      file_handle.1 = file_handle;
      D.9814 = file_handle.1->fileaccess;
      D.9815 = (signed int) D.9814;
      if (D.9815 >= 0) goto <D.9816>; else goto <D.9817>;
      <D.9816>:
      file_handle.1 = file_handle;
      D.9818 = BIT_FIELD_REF <*file_handle.1, 64, 192>;
      D.9819 = D.9818 & 5764607523034234880;
      if (D.9819 == 0) goto <D.9820>; else goto <D.9821>;
      <D.9820>:
      SetLastError (5);
      D.9812 = 0;
      return D.9812;
      <D.9821>:
      <D.9817>:
      D.9822 = (long int) offset_high;
      D.9823 = D.9822 << 32;
      D.9824 = (long int) offset_low;
      offset = D.9823 | D.9824;
      D.9825 = (long int) length_high;
      D.9826 = D.9825 << 32;
      D.9827 = (long int) length_low;
      length = D.9826 | D.9827;
      D.9812 = _wapi_lock_file_region (fd, offset, length);
      return D.9812;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


UnlockFile (void * handle, guint32 offset_low, guint32 offset_high, guint32 length_low, guint32 length_high)
{
  long int handle.2;
  gboolean D.9833;
  struct _WapiHandle_file * file_handle.3;
  unsigned int D.9835;
  signed int D.9836;
  long unsigned int D.9839;
  long unsigned int D.9840;
  long int D.9843;
  long int D.9844;
  long int D.9845;
  long int D.9846;
  long int D.9847;
  long int D.9848;
  struct _WapiHandle_file * file_handle;
  gboolean ok;
  off_t offset;
  off_t length;
  int fd;
  static const char __func__[11] = "UnlockFile";

  try
    {
      handle.2 = (long int) handle;
      fd = (int) handle.2;
      ok = _wapi_lookup_handle (handle, 1, &file_handle);
      if (ok == 0) goto <D.9831>; else goto <D.9832>;
      <D.9831>:
      monoeg_g_log (0B, 16, "%s: error looking up file handle %p", &__func__, handle);
      SetLastError (6);
      D.9833 = 0;
      return D.9833;
      <D.9832>:
      file_handle.3 = file_handle;
      D.9835 = file_handle.3->fileaccess;
      D.9836 = (signed int) D.9835;
      if (D.9836 >= 0) goto <D.9837>; else goto <D.9838>;
      <D.9837>:
      file_handle.3 = file_handle;
      D.9839 = BIT_FIELD_REF <*file_handle.3, 64, 192>;
      D.9840 = D.9839 & 5764607523034234880;
      if (D.9840 == 0) goto <D.9841>; else goto <D.9842>;
      <D.9841>:
      SetLastError (5);
      D.9833 = 0;
      return D.9833;
      <D.9842>:
      <D.9838>:
      D.9843 = (long int) offset_high;
      D.9844 = D.9843 << 32;
      D.9845 = (long int) offset_low;
      offset = D.9844 | D.9845;
      D.9846 = (long int) length_high;
      D.9847 = D.9846 << 32;
      D.9848 = (long int) length_low;
      length = D.9847 | D.9848;
      D.9833 = _wapi_unlock_file_region (fd, offset, length);
      return D.9833;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


