/* posix_empty_length_0.c generated by valac, the Vala compiler
 * generated from posix_empty_length_0.vala, do not modify */

#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <sys/types.h>
#include <assert.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

typedef struct _Manam Manam;
#define _free0(var) ((var == NULL) ? NULL : (var = (free (var), NULL)))
typedef void (*ValaDestroyNotify) (void* data);

struct _Manam {
	char* s;
};

VALA_EXTERN char** foo;
VALA_EXTERN int foo_length1;
char** foo = NULL;
int foo_length1 = 0;
static int _foo_size_ = 0;
VALA_EXTERN int* bar;
VALA_EXTERN int bar_length1;
int* bar = NULL;
int bar_length1 = 0;
static int _bar_size_ = 0;
VALA_EXTERN Manam* manam;
VALA_EXTERN int manam_length1;
Manam* manam = NULL;
int manam_length1 = 0;
static int _manam_size_ = 0;

VALA_EXTERN Manam* manam_dup (const Manam* self);
VALA_EXTERN void manam_free (Manam* self);
VALA_EXTERN void manam_copy (const Manam* self,
                 Manam* dest);
VALA_EXTERN void manam_destroy (Manam* self);
VALA_EXTERN char** get_foo (int* result_length1);
static char** _vala_array_dup1 (char** self,
                         ssize_t length);
VALA_EXTERN int* get_bar (int* result_length1);
static int* _vala_array_dup2 (int* self,
                       ssize_t length);
VALA_EXTERN Manam* get_manam (int* result_length1);
static Manam* _vala_array_dup3 (Manam* self,
                         ssize_t length);
static void _vala_main (void);
static void _vala_Manam_array_free (Manam * array,
                             ssize_t array_length);
static void _vala_array_destroy (void* array,
                          ssize_t array_length,
                          ValaDestroyNotify destroy_func);
static void _vala_array_free (void* array,
                       ssize_t array_length,
                       ValaDestroyNotify destroy_func);

static void*
_strdup0 (void* self)
{
	return self ? strdup (self) : NULL;
}

void
manam_copy (const Manam* self,
            Manam* dest)
{
	const char* _tmp0_;
	char* _tmp1_;
	_tmp0_ = (*self).s;
	_tmp1_ = _strdup0 (_tmp0_);
	_free0 ((*dest).s);
	(*dest).s = _tmp1_;
}

void
manam_destroy (Manam* self)
{
	_free0 ((*self).s);
}

Manam*
manam_dup (const Manam* self)
{
	Manam* dup;
	dup = calloc (1, sizeof (Manam));
	manam_copy (self, dup);
	return dup;
}

void
manam_free (Manam* self)
{
	manam_destroy (self);
	free (self);
}

static char**
_vala_array_dup1 (char** self,
                  ssize_t length)
{
	if (length >= 0) {
		char** result;
		ssize_t i;
		result = calloc (length + 1, sizeof (char*));
		for (i = 0; i < length; i++) {
			char* _tmp0_;
			_tmp0_ = _strdup0 (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

char**
get_foo (int* result_length1)
{
	char** _tmp0_;
	int _tmp0__length1;
	char** _tmp1_;
	int _tmp1__length1;
	char** _tmp2_;
	int _tmp2__length1;
	char** result;
	_tmp0_ = foo;
	_tmp0__length1 = foo_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup1 (_tmp0_, _tmp0__length1) : _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static int*
_vala_array_dup2 (int* self,
                  ssize_t length)
{
	if (length > 0) {
		int* result;
		result = calloc (length, sizeof (int));
		memcpy (result, self, length * sizeof (int));
		return result;
	}
	return NULL;
}

int*
get_bar (int* result_length1)
{
	int* _tmp0_;
	int _tmp0__length1;
	int* _tmp1_;
	int _tmp1__length1;
	int* _tmp2_;
	int _tmp2__length1;
	int* result;
	_tmp0_ = bar;
	_tmp0__length1 = bar_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup2 (_tmp0_, _tmp0__length1) : _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static Manam*
_vala_array_dup3 (Manam* self,
                  ssize_t length)
{
	if (length > 0) {
		Manam* result;
		ssize_t i;
		result = calloc (length, sizeof (Manam));
		for (i = 0; i < length; i++) {
			Manam _tmp0_;
			Manam _tmp1_ = {0};
			_tmp0_ = self[i];
			manam_copy (&_tmp0_, &_tmp1_);
			result[i] = _tmp1_;
		}
		return result;
	}
	return NULL;
}

Manam*
get_manam (int* result_length1)
{
	Manam* _tmp0_;
	int _tmp0__length1;
	Manam* _tmp1_;
	int _tmp1__length1;
	Manam* _tmp2_;
	int _tmp2__length1;
	Manam* result;
	_tmp0_ = manam;
	_tmp0__length1 = manam_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup3 (_tmp0_, _tmp0__length1) : _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static void
_vala_Manam_array_free (Manam * array,
                        ssize_t array_length)
{
	if (array != NULL) {
		ssize_t i;
		for (i = 0; i < array_length; i = i + 1) {
			manam_destroy (&array[i]);
		}
	}
	free (array);
}

static void
_vala_main (void)
{
	{
		char** _tmp0_;
		char** _tmp1_;
		int _tmp1__length1;
		int _tmp2_ = 0;
		char** _tmp3_;
		char** _tmp4_;
		int _tmp4__length1;
		_tmp0_ = calloc (0 + 1, sizeof (char*));
		foo = (_vala_array_free (foo, foo_length1, (ValaDestroyNotify) free), NULL);
		foo = _tmp0_;
		foo_length1 = 0;
		_foo_size_ = foo_length1;
		_tmp1_ = foo;
		_tmp1__length1 = foo_length1;
		assert (_tmp1_ != NULL);
		_tmp3_ = get_foo (&_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp4__length1 = _tmp2_;
		assert (_tmp4_ != NULL);
		_tmp4_ = (_vala_array_free (_tmp4_, _tmp4__length1, (ValaDestroyNotify) free), NULL);
	}
	{
		char** _tmp5_;
		char** _tmp6_;
		int _tmp6__length1;
		int _tmp7_ = 0;
		char** _tmp8_;
		char** _tmp9_;
		int _tmp9__length1;
		_tmp5_ = calloc (0 + 1, sizeof (char*));
		foo = (_vala_array_free (foo, foo_length1, (ValaDestroyNotify) free), NULL);
		foo = _tmp5_;
		foo_length1 = 0;
		_foo_size_ = foo_length1;
		_tmp6_ = foo;
		_tmp6__length1 = foo_length1;
		assert (_tmp6_ != NULL);
		_tmp8_ = get_foo (&_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp9__length1 = _tmp7_;
		assert (_tmp9_ != NULL);
		_tmp9_ = (_vala_array_free (_tmp9_, _tmp9__length1, (ValaDestroyNotify) free), NULL);
	}
	{
		int* _tmp10_;
		int _tmp11_ = 0;
		int* _tmp12_;
		int* _tmp13_;
		int _tmp13__length1;
		_tmp10_ = calloc (0, sizeof (int));
		bar = (free (bar), NULL);
		bar = _tmp10_;
		bar_length1 = 0;
		_bar_size_ = bar_length1;
		_tmp12_ = get_bar (&_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp13__length1 = _tmp11_;
		assert (_tmp13_ == NULL);
		_tmp13_ = (free (_tmp13_), NULL);
	}
	{
		int* _tmp14_;
		int _tmp15_ = 0;
		int* _tmp16_;
		int* _tmp17_;
		int _tmp17__length1;
		_tmp14_ = calloc (0, sizeof (int));
		bar = (free (bar), NULL);
		bar = _tmp14_;
		bar_length1 = 0;
		_bar_size_ = bar_length1;
		_tmp16_ = get_bar (&_tmp15_);
		_tmp17_ = _tmp16_;
		_tmp17__length1 = _tmp15_;
		assert (_tmp17_ == NULL);
		_tmp17_ = (free (_tmp17_), NULL);
	}
	{
		Manam* _tmp18_;
		int _tmp19_ = 0;
		Manam* _tmp20_;
		Manam* _tmp21_;
		int _tmp21__length1;
		_tmp18_ = calloc (0, sizeof (Manam));
		manam = (_vala_Manam_array_free (manam, manam_length1), NULL);
		manam = _tmp18_;
		manam_length1 = 0;
		_manam_size_ = manam_length1;
		_tmp20_ = get_manam (&_tmp19_);
		_tmp21_ = _tmp20_;
		_tmp21__length1 = _tmp19_;
		assert (_tmp21_ == NULL);
		_tmp21_ = (_vala_Manam_array_free (_tmp21_, _tmp21__length1), NULL);
	}
	{
		Manam* _tmp22_;
		int _tmp23_ = 0;
		Manam* _tmp24_;
		Manam* _tmp25_;
		int _tmp25__length1;
		_tmp22_ = calloc (0, sizeof (Manam));
		manam = (_vala_Manam_array_free (manam, manam_length1), NULL);
		manam = _tmp22_;
		manam_length1 = 0;
		_manam_size_ = manam_length1;
		_tmp24_ = get_manam (&_tmp23_);
		_tmp25_ = _tmp24_;
		_tmp25__length1 = _tmp23_;
		assert (_tmp25_ == NULL);
		_tmp25_ = (_vala_Manam_array_free (_tmp25_, _tmp25__length1), NULL);
	}
}

int
main (int argc,
      char ** argv)
{
	_vala_main ();
	return 0;
}

static void
_vala_array_destroy (void* array,
                     ssize_t array_length,
                     ValaDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		ssize_t i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((void**) array)[i] != NULL) {
				destroy_func (((void**) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (void* array,
                  ssize_t array_length,
                  ValaDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	free (array);
}

