#include <pthread.h>
#include <stdio.h>

/* minimal version of GLib :-) */
#define G_OS_UNIX
#undef G_OS_WIN32
typedef struct _GCond GCond;
typedef int gboolean;
typedef unsigned int guint;
typedef double gdouble;

typedef struct
{
  struct _230Mutex *runtime_mutex;
  union
    {
      char pad[sizeof (pthread_mutex_t)];
      double dummy_double;
      void *dummy_pointer;
      long dummy_long;
    } static_mutex;
} _230StaticMutex;

typedef struct
{
  union _232Mutex *mutex;
#ifndef G_OS_WIN32
  /* only for ABI compatibility reasons */
  pthread_mutex_t unused;
#endif
} _232StaticMutex;

typedef union
{
#if defined(G_OS_WIN32)
  char data[sizeof (struct _GThreadData *)];
#else
  /* assumed to be pthreads */
  char data[sizeof (pthread_t)];
#endif
  double dummy_double;
  void *dummy_pointer;
  long dummy_long;
} _230SystemThread;

typedef struct
{
  _230StaticMutex mutex;
  guint depth;
  _230SystemThread owner;
} _230StaticRecMutex;

typedef struct
{
  _232StaticMutex mutex;
  guint depth;

  union {
#ifdef G_OS_WIN32
    void *owner;
#else
    pthread_t owner;
#endif
    gdouble dummy;
  } unused;
} _232StaticRecMutex;

typedef struct
{
  _230StaticMutex mutex;
  GCond *read_cond;
  GCond *write_cond;
  guint read_counter;
  gboolean have_writer;
  guint want_to_read;
  guint want_to_write;
} _230StaticRWLock;

typedef struct
{
  _232StaticMutex mutex;
  GCond *read_cond;
  GCond *write_cond;
  guint read_counter;
  gboolean have_writer;
  guint want_to_read;
  guint want_to_write;
} _232StaticRWLock;

static int
check (const char *type,
    size_t _230_size,
    size_t _232_size,
    size_t _230_align,
    size_t _232_align)
{
  int ok = 1;

  if (_230_size == _232_size && _230_align == _232_align)
    {
      printf ("PASS: G%s\tsize=%zu\talign=%zu\n", type, _230_size, _230_align);
    }
  else
    {
      printf ("FAIL: G%s\tsize=%zu/%zu\talign=%zu/%zu\n",
          type, _230_size, _232_size, _230_align, _232_align);
    }
}

#define CHECK(x) \
    check (#x, \
      sizeof (_230 ## x), \
      sizeof (_232 ## x), \
      __alignof__ (_230 ## x), \
      __alignof__ (_232 ## x))

int main (void)
{
  int ok = 1;

  ok = CHECK (StaticMutex) && ok;
  ok = CHECK (StaticRWLock) && ok;
  ok = CHECK (StaticRecMutex) && ok;

  return !ok;
}
