_wapi_lock_file_region (int fd, off_t offset, off_t length)
{
  gboolean D.9309;
  int * D.9311;
  int D.9312;
  struct flock lock_data;
  int ret;

  try
    {
      if (offset < 0) goto <D.9306>; else goto <D.9308>;
      <D.9308>:
      if (length < 0) goto <D.9306>; else goto <D.9307>;
      <D.9306>:
      SetLastError (87);
      D.9309 = 0;
      return D.9309;
      <D.9307>:
      lock_data.l_type = 1;
      lock_data.l_whence = 0;
      lock_data.l_start = offset;
      lock_data.l_len = length;
      <D.9268>:
      ret = fcntl (fd, 34, &lock_data);
      if (ret == -1) goto <D.9310>; else goto <D.9269>;
      <D.9310>:
      D.9311 = __errno_location ();
      D.9312 = *D.9311;
      if (D.9312 == 4) goto <D.9268>; else goto <D.9269>;
      <D.9269>:
      if (ret == -1) goto <D.9313>; else goto <D.9314>;
      <D.9313>:
      D.9311 = __errno_location ();
      D.9312 = *D.9311;
      if (D.9312 == 46) goto <D.9315>; else goto <D.9317>;
      <D.9317>:
      D.9311 = __errno_location ();
      D.9312 = *D.9311;
      if (D.9312 == 122) goto <D.9315>; else goto <D.9318>;
      <D.9318>:
      D.9311 = __errno_location ();
      D.9312 = *D.9311;
      if (D.9312 == 122) goto <D.9315>; else goto <D.9316>;
      <D.9315>:
      D.9309 = 1;
      return D.9309;
      <D.9316>:
      SetLastError (33);
      D.9309 = 0;
      return D.9309;
      <D.9314>:
      D.9309 = 1;
      return D.9309;
    }
  finally
    {
      lock_data = {CLOBBER};
    }
}


_wapi_unlock_file_region (int fd, off_t offset, off_t length)
{
  int * D.9322;
  int D.9323;
  gboolean D.9330;
  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.9277>:
      ret = fcntl (fd, 34, &lock_data);
      if (ret == -1) goto <D.9321>; else goto <D.9278>;
      <D.9321>:
      D.9322 = __errno_location ();
      D.9323 = *D.9322;
      if (D.9323 == 4) goto <D.9277>; else goto <D.9278>;
      <D.9278>:
      if (ret == -1) goto <D.9324>; else goto <D.9325>;
      <D.9324>:
      D.9322 = __errno_location ();
      D.9323 = *D.9322;
      if (D.9323 == 46) goto <D.9326>; else goto <D.9328>;
      <D.9328>:
      D.9322 = __errno_location ();
      D.9323 = *D.9322;
      if (D.9323 == 122) goto <D.9326>; else goto <D.9329>;
      <D.9329>:
      D.9322 = __errno_location ();
      D.9323 = *D.9322;
      if (D.9323 == 122) goto <D.9326>; else goto <D.9327>;
      <D.9326>:
      D.9330 = 1;
      return D.9330;
      <D.9327>:
      SetLastError (33);
      D.9330 = 0;
      return D.9330;
      <D.9325>:
      D.9330 = 1;
      return D.9330;
    }
  finally
    {
      lock_data = {CLOBBER};
    }
}


LockFile (void * handle, guint32 offset_low, guint32 offset_high, guint32 length_low, guint32 length_high)
{
  gboolean D.9335;
  struct _WapiHandle_file * file_handle.0;
  unsigned int D.9337;
  signed int D.9338;
  unsigned int D.9341;
  unsigned int D.9342;
  long long int D.9345;
  long long int D.9346;
  long long int D.9347;
  long long int D.9348;
  long long int D.9349;
  long long int D.9350;
  struct _WapiHandle_file * file_handle;
  gboolean ok;
  off_t offset;
  off_t length;
  int fd;
  static const char __func__[9] = "LockFile";

  try
    {
      fd = (int) handle;
      ok = _wapi_lookup_handle (handle, 1, &file_handle);
      if (ok == 0) goto <D.9333>; else goto <D.9334>;
      <D.9333>:
      monoeg_g_log (0B, 16, "%s: error looking up file handle %p", &__func__, handle);
      SetLastError (6);
      D.9335 = 0;
      return D.9335;
      <D.9334>:
      file_handle.0 = file_handle;
      D.9337 = file_handle.0->fileaccess;
      D.9338 = (signed int) D.9337;
      if (D.9338 >= 0) goto <D.9339>; else goto <D.9340>;
      <D.9339>:
      file_handle.0 = file_handle;
      D.9341 = BIT_FIELD_REF <*file_handle.0, 32, 128>;
      D.9342 = D.9341 & 1342177280;
      if (D.9342 == 0) goto <D.9343>; else goto <D.9344>;
      <D.9343>:
      SetLastError (5);
      D.9335 = 0;
      return D.9335;
      <D.9344>:
      <D.9340>:
      D.9345 = (long long int) offset_high;
      D.9346 = D.9345 << 32;
      D.9347 = (long long int) offset_low;
      offset = D.9346 | D.9347;
      D.9348 = (long long int) length_high;
      D.9349 = D.9348 << 32;
      D.9350 = (long long int) length_low;
      length = D.9349 | D.9350;
      D.9335 = _wapi_lock_file_region (fd, offset, length);
      return D.9335;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


UnlockFile (void * handle, guint32 offset_low, guint32 offset_high, guint32 length_low, guint32 length_high)
{
  gboolean D.9355;
  struct _WapiHandle_file * file_handle.1;
  unsigned int D.9357;
  signed int D.9358;
  unsigned int D.9361;
  unsigned int D.9362;
  long long int D.9365;
  long long int D.9366;
  long long int D.9367;
  long long int D.9368;
  long long int D.9369;
  long long int D.9370;
  struct _WapiHandle_file * file_handle;
  gboolean ok;
  off_t offset;
  off_t length;
  int fd;
  static const char __func__[11] = "UnlockFile";

  try
    {
      fd = (int) handle;
      ok = _wapi_lookup_handle (handle, 1, &file_handle);
      if (ok == 0) goto <D.9353>; else goto <D.9354>;
      <D.9353>:
      monoeg_g_log (0B, 16, "%s: error looking up file handle %p", &__func__, handle);
      SetLastError (6);
      D.9355 = 0;
      return D.9355;
      <D.9354>:
      file_handle.1 = file_handle;
      D.9357 = file_handle.1->fileaccess;
      D.9358 = (signed int) D.9357;
      if (D.9358 >= 0) goto <D.9359>; else goto <D.9360>;
      <D.9359>:
      file_handle.1 = file_handle;
      D.9361 = BIT_FIELD_REF <*file_handle.1, 32, 128>;
      D.9362 = D.9361 & 1342177280;
      if (D.9362 == 0) goto <D.9363>; else goto <D.9364>;
      <D.9363>:
      SetLastError (5);
      D.9355 = 0;
      return D.9355;
      <D.9364>:
      <D.9360>:
      D.9365 = (long long int) offset_high;
      D.9366 = D.9365 << 32;
      D.9367 = (long long int) offset_low;
      offset = D.9366 | D.9367;
      D.9368 = (long long int) length_high;
      D.9369 = D.9368 << 32;
      D.9370 = (long long int) length_low;
      length = D.9369 | D.9370;
      D.9355 = _wapi_unlock_file_region (fd, offset, length);
      return D.9355;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


