_wapi_lock_file_region (int fd, off_t offset, off_t length)
{
  gboolean D.10130;
  int * D.10132;
  int D.10133;
  struct flock lock_data;
  int ret;

  try
    {
      if (offset < 0) goto <D.10127>; else goto <D.10129>;
      <D.10129>:
      if (length < 0) goto <D.10127>; else goto <D.10128>;
      <D.10127>:
      SetLastError (87);
      D.10130 = 0;
      return D.10130;
      <D.10128>:
      lock_data.l_type = 1;
      lock_data.l_whence = 0;
      lock_data.l_start = offset;
      lock_data.l_len = length;
      <D.10089>:
      ret = fcntl (fd, 6, &lock_data);
      if (ret == -1) goto <D.10131>; else goto <D.10090>;
      <D.10131>:
      D.10132 = __errno_location ();
      D.10133 = *D.10132;
      if (D.10133 == 4) goto <D.10089>; else goto <D.10090>;
      <D.10090>:
      if (ret == -1) goto <D.10134>; else goto <D.10135>;
      <D.10134>:
      D.10132 = __errno_location ();
      D.10133 = *D.10132;
      if (D.10133 == 37) goto <D.10136>; else goto <D.10138>;
      <D.10138>:
      D.10132 = __errno_location ();
      D.10133 = *D.10132;
      if (D.10133 == 95) goto <D.10136>; else goto <D.10139>;
      <D.10139>:
      D.10132 = __errno_location ();
      D.10133 = *D.10132;
      if (D.10133 == 95) goto <D.10136>; else goto <D.10137>;
      <D.10136>:
      D.10130 = 1;
      return D.10130;
      <D.10137>:
      SetLastError (33);
      D.10130 = 0;
      return D.10130;
      <D.10135>:
      D.10130 = 1;
      return D.10130;
    }
  finally
    {
      lock_data = {CLOBBER};
    }
}


_wapi_unlock_file_region (int fd, off_t offset, off_t length)
{
  int * D.10143;
  int D.10144;
  gboolean D.10151;
  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.10098>:
      ret = fcntl (fd, 6, &lock_data);
      if (ret == -1) goto <D.10142>; else goto <D.10099>;
      <D.10142>:
      D.10143 = __errno_location ();
      D.10144 = *D.10143;
      if (D.10144 == 4) goto <D.10098>; else goto <D.10099>;
      <D.10099>:
      if (ret == -1) goto <D.10145>; else goto <D.10146>;
      <D.10145>:
      D.10143 = __errno_location ();
      D.10144 = *D.10143;
      if (D.10144 == 37) goto <D.10147>; else goto <D.10149>;
      <D.10149>:
      D.10143 = __errno_location ();
      D.10144 = *D.10143;
      if (D.10144 == 95) goto <D.10147>; else goto <D.10150>;
      <D.10150>:
      D.10143 = __errno_location ();
      D.10144 = *D.10143;
      if (D.10144 == 95) goto <D.10147>; else goto <D.10148>;
      <D.10147>:
      D.10151 = 1;
      return D.10151;
      <D.10148>:
      SetLastError (33);
      D.10151 = 0;
      return D.10151;
      <D.10146>:
      D.10151 = 1;
      return D.10151;
    }
  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.10157;
  struct _WapiHandle_file * file_handle.1;
  unsigned int D.10159;
  signed int D.10160;
  long unsigned int D.10163;
  long unsigned int D.10164;
  long int D.10167;
  long int D.10168;
  long int D.10169;
  long int D.10170;
  long int D.10171;
  long int D.10172;
  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.10155>; else goto <D.10156>;
      <D.10155>:
      monoeg_g_log (0B, 16, "%s: error looking up file handle %p", &__func__, handle);
      SetLastError (6);
      D.10157 = 0;
      return D.10157;
      <D.10156>:
      file_handle.1 = file_handle;
      D.10159 = file_handle.1->fileaccess;
      D.10160 = (signed int) D.10159;
      if (D.10160 >= 0) goto <D.10161>; else goto <D.10162>;
      <D.10161>:
      file_handle.1 = file_handle;
      D.10163 = BIT_FIELD_REF <*file_handle.1, 64, 192>;
      D.10164 = D.10163 & 1342177280;
      if (D.10164 == 0) goto <D.10165>; else goto <D.10166>;
      <D.10165>:
      SetLastError (5);
      D.10157 = 0;
      return D.10157;
      <D.10166>:
      <D.10162>:
      D.10167 = (long int) offset_high;
      D.10168 = D.10167 << 32;
      D.10169 = (long int) offset_low;
      offset = D.10168 | D.10169;
      D.10170 = (long int) length_high;
      D.10171 = D.10170 << 32;
      D.10172 = (long int) length_low;
      length = D.10171 | D.10172;
      D.10157 = _wapi_lock_file_region (fd, offset, length);
      return D.10157;
    }
  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.10178;
  struct _WapiHandle_file * file_handle.3;
  unsigned int D.10180;
  signed int D.10181;
  long unsigned int D.10184;
  long unsigned int D.10185;
  long int D.10188;
  long int D.10189;
  long int D.10190;
  long int D.10191;
  long int D.10192;
  long int D.10193;
  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.10176>; else goto <D.10177>;
      <D.10176>:
      monoeg_g_log (0B, 16, "%s: error looking up file handle %p", &__func__, handle);
      SetLastError (6);
      D.10178 = 0;
      return D.10178;
      <D.10177>:
      file_handle.3 = file_handle;
      D.10180 = file_handle.3->fileaccess;
      D.10181 = (signed int) D.10180;
      if (D.10181 >= 0) goto <D.10182>; else goto <D.10183>;
      <D.10182>:
      file_handle.3 = file_handle;
      D.10184 = BIT_FIELD_REF <*file_handle.3, 64, 192>;
      D.10185 = D.10184 & 1342177280;
      if (D.10185 == 0) goto <D.10186>; else goto <D.10187>;
      <D.10186>:
      SetLastError (5);
      D.10178 = 0;
      return D.10178;
      <D.10187>:
      <D.10183>:
      D.10188 = (long int) offset_high;
      D.10189 = D.10188 << 32;
      D.10190 = (long int) offset_low;
      offset = D.10189 | D.10190;
      D.10191 = (long int) length_high;
      D.10192 = D.10191 << 32;
      D.10193 = (long int) length_low;
      length = D.10192 | D.10193;
      D.10178 = _wapi_unlock_file_region (fd, offset, length);
      return D.10178;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


