_wapi_lock_file_region (int fd, off_t offset, off_t length)
{
  _Bool D.9609;
  _Bool D.9610;
  _Bool D.9611;
  gboolean D.9614;
  int * D.9616;
  int D.9617;
  int D.9622;
  _Bool D.9623;
  _Bool D.9624;
  _Bool D.9625;
  struct flock lock_data;
  int ret;

  try
    {
      D.9609 = offset < 0;
      D.9610 = length < 0;
      D.9611 = D.9609 | D.9610;
      if (D.9611 != 0) goto <D.9612>; else goto <D.9613>;
      <D.9612>:
      SetLastError (87);
      D.9614 = 0;
      return D.9614;
      <D.9613>:
      lock_data.l_type = 1;
      lock_data.l_whence = 0;
      lock_data.l_start = offset;
      lock_data.l_len = length;
      <D.9571>:
      ret = fcntl (fd, 6, &lock_data);
      if (ret == -1) goto <D.9615>; else goto <D.9572>;
      <D.9615>:
      D.9616 = __errno_location ();
      D.9617 = *D.9616;
      if (D.9617 == 4) goto <D.9571>; else goto <D.9572>;
      <D.9572>:
      if (ret == -1) goto <D.9618>; else goto <D.9619>;
      <D.9618>:
      D.9616 = __errno_location ();
      D.9622 = *D.9616;
      D.9623 = D.9622 == 37;
      D.9624 = D.9622 == 95;
      D.9625 = D.9623 | D.9624;
      if (D.9625 != 0) goto <D.9620>; else goto <D.9626>;
      <D.9626>:
      D.9616 = __errno_location ();
      D.9617 = *D.9616;
      if (D.9617 == 95) goto <D.9620>; else goto <D.9621>;
      <D.9620>:
      D.9614 = 1;
      return D.9614;
      <D.9621>:
      SetLastError (33);
      D.9614 = 0;
      return D.9614;
      <D.9619>:
      D.9614 = 1;
      return D.9614;
    }
  finally
    {
      lock_data = {CLOBBER};
    }
}


_wapi_unlock_file_region (int fd, off_t offset, off_t length)
{
  int * D.9630;
  int D.9631;
  int D.9636;
  _Bool D.9637;
  _Bool D.9638;
  _Bool D.9639;
  gboolean D.9641;
  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.9580>:
      ret = fcntl (fd, 6, &lock_data);
      if (ret == -1) goto <D.9629>; else goto <D.9581>;
      <D.9629>:
      D.9630 = __errno_location ();
      D.9631 = *D.9630;
      if (D.9631 == 4) goto <D.9580>; else goto <D.9581>;
      <D.9581>:
      if (ret == -1) goto <D.9632>; else goto <D.9633>;
      <D.9632>:
      D.9630 = __errno_location ();
      D.9636 = *D.9630;
      D.9637 = D.9636 == 37;
      D.9638 = D.9636 == 95;
      D.9639 = D.9637 | D.9638;
      if (D.9639 != 0) goto <D.9634>; else goto <D.9640>;
      <D.9640>:
      D.9630 = __errno_location ();
      D.9631 = *D.9630;
      if (D.9631 == 95) goto <D.9634>; else goto <D.9635>;
      <D.9634>:
      D.9641 = 1;
      return D.9641;
      <D.9635>:
      SetLastError (33);
      D.9641 = 0;
      return D.9641;
      <D.9633>:
      D.9641 = 1;
      return D.9641;
    }
  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.9647;
  struct _WapiHandle_file * file_handle.1;
  unsigned int D.9649;
  signed int D.9650;
  unsigned int D.9653;
  unsigned int D.9654;
  long int D.9657;
  long int D.9658;
  long int D.9659;
  long int D.9660;
  long int D.9661;
  long int D.9662;
  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.9645>; else goto <D.9646>;
      <D.9645>:
      monoeg_g_log (0B, 16, "%s: error looking up file handle %p", &__func__, handle);
      SetLastError (6);
      D.9647 = 0;
      return D.9647;
      <D.9646>:
      file_handle.1 = file_handle;
      D.9649 = file_handle.1->fileaccess;
      D.9650 = (signed int) D.9649;
      if (D.9650 >= 0) goto <D.9651>; else goto <D.9652>;
      <D.9651>:
      file_handle.1 = file_handle;
      D.9653 = BIT_FIELD_REF <*file_handle.1, 32, 192>;
      D.9654 = D.9653 & 1342177280;
      if (D.9654 == 0) goto <D.9655>; else goto <D.9656>;
      <D.9655>:
      SetLastError (5);
      D.9647 = 0;
      return D.9647;
      <D.9656>:
      <D.9652>:
      D.9657 = (long int) offset_high;
      D.9658 = D.9657 << 32;
      D.9659 = (long int) offset_low;
      offset = D.9658 | D.9659;
      D.9660 = (long int) length_high;
      D.9661 = D.9660 << 32;
      D.9662 = (long int) length_low;
      length = D.9661 | D.9662;
      D.9647 = _wapi_lock_file_region (fd, offset, length);
      return D.9647;
    }
  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.9668;
  struct _WapiHandle_file * file_handle.3;
  unsigned int D.9670;
  signed int D.9671;
  unsigned int D.9674;
  unsigned int D.9675;
  long int D.9678;
  long int D.9679;
  long int D.9680;
  long int D.9681;
  long int D.9682;
  long int D.9683;
  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.9666>; else goto <D.9667>;
      <D.9666>:
      monoeg_g_log (0B, 16, "%s: error looking up file handle %p", &__func__, handle);
      SetLastError (6);
      D.9668 = 0;
      return D.9668;
      <D.9667>:
      file_handle.3 = file_handle;
      D.9670 = file_handle.3->fileaccess;
      D.9671 = (signed int) D.9670;
      if (D.9671 >= 0) goto <D.9672>; else goto <D.9673>;
      <D.9672>:
      file_handle.3 = file_handle;
      D.9674 = BIT_FIELD_REF <*file_handle.3, 32, 192>;
      D.9675 = D.9674 & 1342177280;
      if (D.9675 == 0) goto <D.9676>; else goto <D.9677>;
      <D.9676>:
      SetLastError (5);
      D.9668 = 0;
      return D.9668;
      <D.9677>:
      <D.9673>:
      D.9678 = (long int) offset_high;
      D.9679 = D.9678 << 32;
      D.9680 = (long int) offset_low;
      offset = D.9679 | D.9680;
      D.9681 = (long int) length_high;
      D.9682 = D.9681 << 32;
      D.9683 = (long int) length_low;
      length = D.9682 | D.9683;
      D.9668 = _wapi_unlock_file_region (fd, offset, length);
      return D.9668;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


