_wapi_lock_file_region (int fd, off_t offset, off_t length)
{
  _Bool D.11884;
  _Bool D.11885;
  _Bool D.11886;
  gboolean D.11889;
  int * D.11891;
  int D.11892;
  int D.11897;
  _Bool D.11898;
  _Bool D.11899;
  _Bool D.11900;
  struct flock lock_data;
  int ret;

  try
    {
      D.11884 = offset < 0;
      D.11885 = length < 0;
      D.11886 = D.11884 | D.11885;
      if (D.11886 != 0) goto <D.11887>; else goto <D.11888>;
      <D.11887>:
      SetLastError (87);
      D.11889 = 0;
      return D.11889;
      <D.11888>:
      lock_data.l_type = 1;
      lock_data.l_whence = 0;
      lock_data.l_start = offset;
      lock_data.l_len = length;
      <D.11844>:
      ret = fcntl (fd, 13, &lock_data);
      if (ret == -1) goto <D.11890>; else goto <D.11845>;
      <D.11890>:
      D.11891 = __errno_location ();
      D.11892 = *D.11891;
      if (D.11892 == 4) goto <D.11844>; else goto <D.11845>;
      <D.11845>:
      if (ret == -1) goto <D.11893>; else goto <D.11894>;
      <D.11893>:
      D.11891 = __errno_location ();
      D.11897 = *D.11891;
      D.11898 = D.11897 == 37;
      D.11899 = D.11897 == 95;
      D.11900 = D.11898 | D.11899;
      if (D.11900 != 0) goto <D.11895>; else goto <D.11901>;
      <D.11901>:
      D.11891 = __errno_location ();
      D.11892 = *D.11891;
      if (D.11892 == 95) goto <D.11895>; else goto <D.11896>;
      <D.11895>:
      D.11889 = 1;
      return D.11889;
      <D.11896>:
      SetLastError (33);
      D.11889 = 0;
      return D.11889;
      <D.11894>:
      D.11889 = 1;
      return D.11889;
    }
  finally
    {
      lock_data = {CLOBBER};
    }
}


_wapi_unlock_file_region (int fd, off_t offset, off_t length)
{
  int * D.11905;
  int D.11906;
  int D.11911;
  _Bool D.11912;
  _Bool D.11913;
  _Bool D.11914;
  gboolean D.11916;
  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.11853>:
      ret = fcntl (fd, 13, &lock_data);
      if (ret == -1) goto <D.11904>; else goto <D.11854>;
      <D.11904>:
      D.11905 = __errno_location ();
      D.11906 = *D.11905;
      if (D.11906 == 4) goto <D.11853>; else goto <D.11854>;
      <D.11854>:
      if (ret == -1) goto <D.11907>; else goto <D.11908>;
      <D.11907>:
      D.11905 = __errno_location ();
      D.11911 = *D.11905;
      D.11912 = D.11911 == 37;
      D.11913 = D.11911 == 95;
      D.11914 = D.11912 | D.11913;
      if (D.11914 != 0) goto <D.11909>; else goto <D.11915>;
      <D.11915>:
      D.11905 = __errno_location ();
      D.11906 = *D.11905;
      if (D.11906 == 95) goto <D.11909>; else goto <D.11910>;
      <D.11909>:
      D.11916 = 1;
      return D.11916;
      <D.11910>:
      SetLastError (33);
      D.11916 = 0;
      return D.11916;
      <D.11908>:
      D.11916 = 1;
      return D.11916;
    }
  finally
    {
      lock_data = {CLOBBER};
    }
}


LockFile (void * handle, guint32 offset_low, guint32 offset_high, guint32 length_low, guint32 length_high)
{
  gboolean D.11921;
  struct _WapiHandle_file * file_handle.0;
  unsigned int D.11923;
  signed int D.11924;
  unsigned int D.11927;
  unsigned int D.11928;
  long long int D.11931;
  long long int D.11932;
  long long int D.11933;
  long long int D.11934;
  long long int D.11935;
  long long int D.11936;
  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.11919>; else goto <D.11920>;
      <D.11919>:
      monoeg_g_log (0B, 16, "%s: error looking up file handle %p", &__func__, handle);
      SetLastError (6);
      D.11921 = 0;
      return D.11921;
      <D.11920>:
      file_handle.0 = file_handle;
      D.11923 = file_handle.0->fileaccess;
      D.11924 = (signed int) D.11923;
      if (D.11924 >= 0) goto <D.11925>; else goto <D.11926>;
      <D.11925>:
      file_handle.0 = file_handle;
      D.11927 = BIT_FIELD_REF <*file_handle.0, 32, 128>;
      D.11928 = D.11927 & 1342177280;
      if (D.11928 == 0) goto <D.11929>; else goto <D.11930>;
      <D.11929>:
      SetLastError (5);
      D.11921 = 0;
      return D.11921;
      <D.11930>:
      <D.11926>:
      D.11931 = (long long int) offset_high;
      D.11932 = D.11931 << 32;
      D.11933 = (long long int) offset_low;
      offset = D.11932 | D.11933;
      D.11934 = (long long int) length_high;
      D.11935 = D.11934 << 32;
      D.11936 = (long long int) length_low;
      length = D.11935 | D.11936;
      D.11921 = _wapi_lock_file_region (fd, offset, length);
      return D.11921;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


UnlockFile (void * handle, guint32 offset_low, guint32 offset_high, guint32 length_low, guint32 length_high)
{
  gboolean D.11941;
  struct _WapiHandle_file * file_handle.1;
  unsigned int D.11943;
  signed int D.11944;
  unsigned int D.11947;
  unsigned int D.11948;
  long long int D.11951;
  long long int D.11952;
  long long int D.11953;
  long long int D.11954;
  long long int D.11955;
  long long int D.11956;
  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.11939>; else goto <D.11940>;
      <D.11939>:
      monoeg_g_log (0B, 16, "%s: error looking up file handle %p", &__func__, handle);
      SetLastError (6);
      D.11941 = 0;
      return D.11941;
      <D.11940>:
      file_handle.1 = file_handle;
      D.11943 = file_handle.1->fileaccess;
      D.11944 = (signed int) D.11943;
      if (D.11944 >= 0) goto <D.11945>; else goto <D.11946>;
      <D.11945>:
      file_handle.1 = file_handle;
      D.11947 = BIT_FIELD_REF <*file_handle.1, 32, 128>;
      D.11948 = D.11947 & 1342177280;
      if (D.11948 == 0) goto <D.11949>; else goto <D.11950>;
      <D.11949>:
      SetLastError (5);
      D.11941 = 0;
      return D.11941;
      <D.11950>:
      <D.11946>:
      D.11951 = (long long int) offset_high;
      D.11952 = D.11951 << 32;
      D.11953 = (long long int) offset_low;
      offset = D.11952 | D.11953;
      D.11954 = (long long int) length_high;
      D.11955 = D.11954 << 32;
      D.11956 = (long long int) length_low;
      length = D.11955 | D.11956;
      D.11941 = _wapi_unlock_file_region (fd, offset, length);
      return D.11941;
    }
  finally
    {
      file_handle = {CLOBBER};
    }
}


