/* ai-profile.c generated by valac 0.16.0, the Vala compiler
 * generated from ai-profile.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>


#define TYPE_AI_PROFILE (ai_profile_get_type ())
#define AI_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_AI_PROFILE, AIProfile))
#define AI_PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_AI_PROFILE, AIProfileClass))
#define IS_AI_PROFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_AI_PROFILE))
#define IS_AI_PROFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_AI_PROFILE))
#define AI_PROFILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_AI_PROFILE, AIProfileClass))

typedef struct _AIProfile AIProfile;
typedef struct _AIProfileClass AIProfileClass;
typedef struct _AIProfilePrivate AIProfilePrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _ParamSpecAIProfile ParamSpecAIProfile;
#define _g_key_file_free0(var) ((var == NULL) ? NULL : (var = (g_key_file_free (var), NULL)))
#define __g_list_free__ai_profile_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__ai_profile_unref0_ (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _ai_profile_unref0(var) ((var == NULL) ? NULL : (var = (ai_profile_unref (var), NULL)))

struct _AIProfile {
	GTypeInstance parent_instance;
	volatile int ref_count;
	AIProfilePrivate * priv;
	gchar* name;
	gchar* protocol;
	gchar* binary;
	gchar* path;
	gchar* args;
	gchar** easy_options;
	gint easy_options_length1;
	gchar** normal_options;
	gint normal_options_length1;
	gchar** hard_options;
	gint hard_options_length1;
};

struct _AIProfileClass {
	GTypeClass parent_class;
	void (*finalize) (AIProfile *self);
};

struct _ParamSpecAIProfile {
	GParamSpec parent_instance;
};


static gpointer ai_profile_parent_class = NULL;

gpointer ai_profile_ref (gpointer instance);
void ai_profile_unref (gpointer instance);
GParamSpec* param_spec_ai_profile (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_ai_profile (GValue* value, gpointer v_object);
void value_take_ai_profile (GValue* value, gpointer v_object);
gpointer value_get_ai_profile (const GValue* value);
GType ai_profile_get_type (void) G_GNUC_CONST;
enum  {
	AI_PROFILE_DUMMY_PROPERTY
};
AIProfile* ai_profile_new (void);
AIProfile* ai_profile_construct (GType object_type);
static void ai_profile_finalize (AIProfile* obj);
GList* load_ai_profiles (const gchar* filename);
static void _ai_profile_unref0_ (gpointer var);
static void _g_list_free__ai_profile_unref0_ (GList* self);
gchar** load_options (GKeyFile* file, const gchar* name, const gchar* difficulty, int* result_length1, GError** error);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


AIProfile* ai_profile_construct (GType object_type) {
	AIProfile* self = NULL;
	self = (AIProfile*) g_type_create_instance (object_type);
	return self;
}


AIProfile* ai_profile_new (void) {
	return ai_profile_construct (TYPE_AI_PROFILE);
}


static void value_ai_profile_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void value_ai_profile_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		ai_profile_unref (value->data[0].v_pointer);
	}
}


static void value_ai_profile_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = ai_profile_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer value_ai_profile_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* value_ai_profile_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		AIProfile* object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = ai_profile_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* value_ai_profile_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	AIProfile** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = ai_profile_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* param_spec_ai_profile (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ParamSpecAIProfile* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_AI_PROFILE), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer value_get_ai_profile (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_AI_PROFILE), NULL);
	return value->data[0].v_pointer;
}


void value_set_ai_profile (GValue* value, gpointer v_object) {
	AIProfile* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_AI_PROFILE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_AI_PROFILE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		ai_profile_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		ai_profile_unref (old);
	}
}


void value_take_ai_profile (GValue* value, gpointer v_object) {
	AIProfile* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_AI_PROFILE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_AI_PROFILE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		ai_profile_unref (old);
	}
}


static void ai_profile_class_init (AIProfileClass * klass) {
	ai_profile_parent_class = g_type_class_peek_parent (klass);
	AI_PROFILE_CLASS (klass)->finalize = ai_profile_finalize;
}


static void ai_profile_instance_init (AIProfile * self) {
	gchar* _tmp0_;
	_tmp0_ = g_strdup ("");
	self->args = _tmp0_;
	self->ref_count = 1;
}


static void ai_profile_finalize (AIProfile* obj) {
	AIProfile * self;
	self = AI_PROFILE (obj);
	_g_free0 (self->name);
	_g_free0 (self->protocol);
	_g_free0 (self->binary);
	_g_free0 (self->path);
	_g_free0 (self->args);
	self->easy_options = (_vala_array_free (self->easy_options, self->easy_options_length1, (GDestroyNotify) g_free), NULL);
	self->normal_options = (_vala_array_free (self->normal_options, self->normal_options_length1, (GDestroyNotify) g_free), NULL);
	self->hard_options = (_vala_array_free (self->hard_options, self->hard_options_length1, (GDestroyNotify) g_free), NULL);
}


GType ai_profile_get_type (void) {
	static volatile gsize ai_profile_type_id__volatile = 0;
	if (g_once_init_enter (&ai_profile_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { value_ai_profile_init, value_ai_profile_free_value, value_ai_profile_copy_value, value_ai_profile_peek_pointer, "p", value_ai_profile_collect_value, "p", value_ai_profile_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (AIProfileClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ai_profile_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AIProfile), 0, (GInstanceInitFunc) ai_profile_instance_init, &g_define_type_value_table };
		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
		GType ai_profile_type_id;
		ai_profile_type_id = g_type_register_fundamental (g_type_fundamental_next (), "AIProfile", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&ai_profile_type_id__volatile, ai_profile_type_id);
	}
	return ai_profile_type_id__volatile;
}


gpointer ai_profile_ref (gpointer instance) {
	AIProfile* self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void ai_profile_unref (gpointer instance) {
	AIProfile* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		AI_PROFILE_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


static void _ai_profile_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (ai_profile_unref (var), NULL));
}


static void _g_list_free__ai_profile_unref0_ (GList* self) {
	g_list_foreach (self, (GFunc) _ai_profile_unref0_, NULL);
	g_list_free (self);
}


static gpointer _ai_profile_ref0 (gpointer self) {
	return self ? ai_profile_ref (self) : NULL;
}


GList* load_ai_profiles (const gchar* filename) {
	GList* result = NULL;
	GList* profiles;
	GKeyFile* _tmp0_;
	GKeyFile* file;
	GKeyFile* _tmp7_;
	gsize _tmp8_;
	gchar** _tmp9_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (filename != NULL, NULL);
	profiles = NULL;
	_tmp0_ = g_key_file_new ();
	file = _tmp0_;
	{
		GKeyFile* _tmp1_;
		const gchar* _tmp2_;
		_tmp1_ = file;
		_tmp2_ = filename;
		g_key_file_load_from_file (_tmp1_, _tmp2_, G_KEY_FILE_NONE, &_inner_error_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_KEY_FILE_ERROR) {
				goto __catch8_g_key_file_error;
			}
			if (_inner_error_->domain == G_FILE_ERROR) {
				goto __catch8_g_file_error;
			}
			_g_key_file_free0 (file);
			__g_list_free__ai_profile_unref0_0 (profiles);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	goto __finally8;
	__catch8_g_key_file_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_warning ("ai-profile.vala:24: Failed to load AI profiles: %s", _tmp4_);
		result = profiles;
		_g_error_free0 (e);
		_g_key_file_free0 (file);
		return result;
	}
	goto __finally8;
	__catch8_g_file_error:
	{
		GError* e = NULL;
		GError* _tmp5_;
		const gchar* _tmp6_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		g_warning ("ai-profile.vala:29: Failed to load AI profiles: %s", _tmp6_);
		result = profiles;
		_g_error_free0 (e);
		_g_key_file_free0 (file);
		return result;
	}
	__finally8:
	if (_inner_error_ != NULL) {
		_g_key_file_free0 (file);
		__g_list_free__ai_profile_unref0_0 (profiles);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	_tmp7_ = file;
	_tmp9_ = g_key_file_get_groups (_tmp7_, &_tmp8_);
	{
		gchar** name_collection = NULL;
		gint name_collection_length1 = 0;
		gint _name_collection_size_ = 0;
		gint name_it = 0;
		name_collection = _tmp9_;
		name_collection_length1 = _tmp8_;
		for (name_it = 0; name_it < _tmp8_; name_it = name_it + 1) {
			gchar* _tmp10_;
			gchar* name = NULL;
			_tmp10_ = g_strdup (name_collection[name_it]);
			name = _tmp10_;
			{
				const gchar* _tmp11_;
				AIProfile* _tmp12_;
				AIProfile* profile;
				AIProfile* _tmp53_;
				const gchar* _tmp54_;
				gchar* _tmp55_ = NULL;
				gchar* path;
				const gchar* _tmp56_;
				_tmp11_ = name;
				g_debug ("ai-profile.vala:35: Loading AI profile %s", _tmp11_);
				_tmp12_ = ai_profile_new ();
				profile = _tmp12_;
				{
					AIProfile* _tmp13_;
					const gchar* _tmp14_;
					gchar* _tmp15_;
					GKeyFile* _tmp16_;
					const gchar* _tmp17_;
					gchar* _tmp18_ = NULL;
					gchar* _tmp19_;
					AIProfile* _tmp20_;
					GKeyFile* _tmp21_;
					const gchar* _tmp22_;
					gchar* _tmp23_ = NULL;
					gchar* _tmp24_;
					AIProfile* _tmp25_;
					GKeyFile* _tmp26_;
					const gchar* _tmp27_;
					gboolean _tmp28_ = FALSE;
					gboolean _tmp29_;
					GKeyFile* _tmp35_;
					const gchar* _tmp36_;
					gint _tmp37_ = 0;
					gchar** _tmp38_ = NULL;
					gchar** _tmp39_;
					gint _tmp39__length1;
					gint __tmp39__size_;
					AIProfile* _tmp40_;
					GKeyFile* _tmp41_;
					const gchar* _tmp42_;
					gint _tmp43_ = 0;
					gchar** _tmp44_ = NULL;
					gchar** _tmp45_;
					gint _tmp45__length1;
					gint __tmp45__size_;
					AIProfile* _tmp46_;
					GKeyFile* _tmp47_;
					const gchar* _tmp48_;
					gint _tmp49_ = 0;
					gchar** _tmp50_ = NULL;
					gchar** _tmp51_;
					gint _tmp51__length1;
					gint __tmp51__size_;
					AIProfile* _tmp52_;
					_tmp13_ = profile;
					_tmp14_ = name;
					_tmp15_ = g_strdup (_tmp14_);
					_g_free0 (_tmp13_->name);
					_tmp13_->name = _tmp15_;
					_tmp16_ = file;
					_tmp17_ = name;
					_tmp18_ = g_key_file_get_value (_tmp16_, _tmp17_, "protocol", &_inner_error_);
					_tmp19_ = _tmp18_;
					if (_inner_error_ != NULL) {
						if (_inner_error_->domain == G_KEY_FILE_ERROR) {
							goto __catch9_g_key_file_error;
						}
						_ai_profile_unref0 (profile);
						_g_free0 (name);
						name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
						_g_key_file_free0 (file);
						__g_list_free__ai_profile_unref0_0 (profiles);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return NULL;
					}
					_tmp20_ = profile;
					_g_free0 (_tmp20_->protocol);
					_tmp20_->protocol = _tmp19_;
					_tmp21_ = file;
					_tmp22_ = name;
					_tmp23_ = g_key_file_get_value (_tmp21_, _tmp22_, "binary", &_inner_error_);
					_tmp24_ = _tmp23_;
					if (_inner_error_ != NULL) {
						if (_inner_error_->domain == G_KEY_FILE_ERROR) {
							goto __catch9_g_key_file_error;
						}
						_ai_profile_unref0 (profile);
						_g_free0 (name);
						name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
						_g_key_file_free0 (file);
						__g_list_free__ai_profile_unref0_0 (profiles);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return NULL;
					}
					_tmp25_ = profile;
					_g_free0 (_tmp25_->binary);
					_tmp25_->binary = _tmp24_;
					_tmp26_ = file;
					_tmp27_ = name;
					_tmp28_ = g_key_file_has_key (_tmp26_, _tmp27_, "args", &_inner_error_);
					_tmp29_ = _tmp28_;
					if (_inner_error_ != NULL) {
						if (_inner_error_->domain == G_KEY_FILE_ERROR) {
							goto __catch9_g_key_file_error;
						}
						_ai_profile_unref0 (profile);
						_g_free0 (name);
						name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
						_g_key_file_free0 (file);
						__g_list_free__ai_profile_unref0_0 (profiles);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return NULL;
					}
					if (_tmp29_) {
						GKeyFile* _tmp30_;
						const gchar* _tmp31_;
						gchar* _tmp32_ = NULL;
						gchar* _tmp33_;
						AIProfile* _tmp34_;
						_tmp30_ = file;
						_tmp31_ = name;
						_tmp32_ = g_key_file_get_value (_tmp30_, _tmp31_, "args", &_inner_error_);
						_tmp33_ = _tmp32_;
						if (_inner_error_ != NULL) {
							if (_inner_error_->domain == G_KEY_FILE_ERROR) {
								goto __catch9_g_key_file_error;
							}
							_ai_profile_unref0 (profile);
							_g_free0 (name);
							name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
							_g_key_file_free0 (file);
							__g_list_free__ai_profile_unref0_0 (profiles);
							g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
							g_clear_error (&_inner_error_);
							return NULL;
						}
						_tmp34_ = profile;
						_g_free0 (_tmp34_->args);
						_tmp34_->args = _tmp33_;
					}
					_tmp35_ = file;
					_tmp36_ = name;
					_tmp38_ = load_options (_tmp35_, _tmp36_, "easy", &_tmp37_, &_inner_error_);
					_tmp39_ = _tmp38_;
					_tmp39__length1 = _tmp37_;
					__tmp39__size_ = _tmp39__length1;
					if (_inner_error_ != NULL) {
						if (_inner_error_->domain == G_KEY_FILE_ERROR) {
							goto __catch9_g_key_file_error;
						}
						_ai_profile_unref0 (profile);
						_g_free0 (name);
						name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
						_g_key_file_free0 (file);
						__g_list_free__ai_profile_unref0_0 (profiles);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return NULL;
					}
					_tmp40_ = profile;
					_tmp40_->easy_options = (_vala_array_free (_tmp40_->easy_options, _tmp40_->easy_options_length1, (GDestroyNotify) g_free), NULL);
					_tmp40_->easy_options = _tmp39_;
					_tmp40_->easy_options_length1 = _tmp39__length1;
					_tmp41_ = file;
					_tmp42_ = name;
					_tmp44_ = load_options (_tmp41_, _tmp42_, "normal", &_tmp43_, &_inner_error_);
					_tmp45_ = _tmp44_;
					_tmp45__length1 = _tmp43_;
					__tmp45__size_ = _tmp45__length1;
					if (_inner_error_ != NULL) {
						if (_inner_error_->domain == G_KEY_FILE_ERROR) {
							goto __catch9_g_key_file_error;
						}
						_ai_profile_unref0 (profile);
						_g_free0 (name);
						name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
						_g_key_file_free0 (file);
						__g_list_free__ai_profile_unref0_0 (profiles);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return NULL;
					}
					_tmp46_ = profile;
					_tmp46_->normal_options = (_vala_array_free (_tmp46_->normal_options, _tmp46_->normal_options_length1, (GDestroyNotify) g_free), NULL);
					_tmp46_->normal_options = _tmp45_;
					_tmp46_->normal_options_length1 = _tmp45__length1;
					_tmp47_ = file;
					_tmp48_ = name;
					_tmp50_ = load_options (_tmp47_, _tmp48_, "hard", &_tmp49_, &_inner_error_);
					_tmp51_ = _tmp50_;
					_tmp51__length1 = _tmp49_;
					__tmp51__size_ = _tmp51__length1;
					if (_inner_error_ != NULL) {
						if (_inner_error_->domain == G_KEY_FILE_ERROR) {
							goto __catch9_g_key_file_error;
						}
						_ai_profile_unref0 (profile);
						_g_free0 (name);
						name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
						_g_key_file_free0 (file);
						__g_list_free__ai_profile_unref0_0 (profiles);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return NULL;
					}
					_tmp52_ = profile;
					_tmp52_->hard_options = (_vala_array_free (_tmp52_->hard_options, _tmp52_->hard_options_length1, (GDestroyNotify) g_free), NULL);
					_tmp52_->hard_options = _tmp51_;
					_tmp52_->hard_options_length1 = _tmp51__length1;
				}
				goto __finally9;
				__catch9_g_key_file_error:
				{
					GError* e = NULL;
					e = _inner_error_;
					_inner_error_ = NULL;
					_g_error_free0 (e);
					_ai_profile_unref0 (profile);
					_g_free0 (name);
					continue;
				}
				__finally9:
				if (_inner_error_ != NULL) {
					_ai_profile_unref0 (profile);
					_g_free0 (name);
					name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
					_g_key_file_free0 (file);
					__g_list_free__ai_profile_unref0_0 (profiles);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
					g_clear_error (&_inner_error_);
					return NULL;
				}
				_tmp53_ = profile;
				_tmp54_ = _tmp53_->binary;
				_tmp55_ = g_find_program_in_path (_tmp54_);
				path = _tmp55_;
				_tmp56_ = path;
				if (_tmp56_ != NULL) {
					AIProfile* _tmp57_;
					const gchar* _tmp58_;
					gchar* _tmp59_;
					AIProfile* _tmp60_;
					AIProfile* _tmp61_;
					_tmp57_ = profile;
					_tmp58_ = path;
					_tmp59_ = g_strdup (_tmp58_);
					_g_free0 (_tmp57_->path);
					_tmp57_->path = _tmp59_;
					_tmp60_ = profile;
					_tmp61_ = _ai_profile_ref0 (_tmp60_);
					profiles = g_list_append (profiles, _tmp61_);
				}
				_g_free0 (path);
				_ai_profile_unref0 (profile);
				_g_free0 (name);
			}
		}
		name_collection = (_vala_array_free (name_collection, name_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	result = profiles;
	_g_key_file_free0 (file);
	return result;
}


gchar** load_options (GKeyFile* file, const gchar* name, const gchar* difficulty, int* result_length1, GError** error) {
	gchar** result = NULL;
	gint count;
	gint _tmp10_;
	gchar** _tmp11_ = NULL;
	gchar** options;
	gint options_length1;
	gint _options_size_;
	gchar** _tmp29_;
	gint _tmp29__length1;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (file != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (difficulty != NULL, NULL);
	count = 0;
	while (TRUE) {
		GKeyFile* _tmp0_;
		const gchar* _tmp1_;
		const gchar* _tmp2_;
		gint _tmp3_;
		gchar* _tmp4_ = NULL;
		gchar* _tmp5_;
		gboolean _tmp6_ = FALSE;
		gboolean _tmp7_;
		gboolean _tmp8_;
		gint _tmp9_;
		_tmp0_ = file;
		_tmp1_ = name;
		_tmp2_ = difficulty;
		_tmp3_ = count;
		_tmp4_ = g_strdup_printf ("option-%s-%d", _tmp2_, _tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = g_key_file_has_key (_tmp0_, _tmp1_, _tmp5_, &_inner_error_);
		_tmp7_ = _tmp6_;
		_g_free0 (_tmp5_);
		_tmp8_ = _tmp7_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_KEY_FILE_ERROR) {
				g_propagate_error (error, _inner_error_);
				return NULL;
			} else {
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return NULL;
			}
		}
		if (!_tmp8_) {
			break;
		}
		_tmp9_ = count;
		count = _tmp9_ + 1;
	}
	_tmp10_ = count;
	_tmp11_ = g_new0 (gchar*, _tmp10_ + 1);
	options = _tmp11_;
	options_length1 = _tmp10_;
	_options_size_ = options_length1;
	{
		gint i;
		i = 0;
		{
			gboolean _tmp12_;
			_tmp12_ = TRUE;
			while (TRUE) {
				gboolean _tmp13_;
				gint _tmp15_;
				gint _tmp16_;
				GKeyFile* _tmp17_;
				const gchar* _tmp18_;
				const gchar* _tmp19_;
				gint _tmp20_;
				gchar* _tmp21_ = NULL;
				gchar* _tmp22_;
				gchar* _tmp23_ = NULL;
				gchar* _tmp24_;
				gchar* _tmp25_;
				gchar** _tmp26_;
				gint _tmp26__length1;
				gint _tmp27_;
				gchar* _tmp28_;
				_tmp13_ = _tmp12_;
				if (!_tmp13_) {
					gint _tmp14_;
					_tmp14_ = i;
					i = _tmp14_ + 1;
				}
				_tmp12_ = FALSE;
				_tmp15_ = i;
				_tmp16_ = count;
				if (!(_tmp15_ < _tmp16_)) {
					break;
				}
				_tmp17_ = file;
				_tmp18_ = name;
				_tmp19_ = difficulty;
				_tmp20_ = i;
				_tmp21_ = g_strdup_printf ("option-%s-%d", _tmp19_, _tmp20_);
				_tmp22_ = _tmp21_;
				_tmp23_ = g_key_file_get_value (_tmp17_, _tmp18_, _tmp22_, &_inner_error_);
				_tmp24_ = _tmp23_;
				_g_free0 (_tmp22_);
				_tmp25_ = _tmp24_;
				if (_inner_error_ != NULL) {
					if (_inner_error_->domain == G_KEY_FILE_ERROR) {
						g_propagate_error (error, _inner_error_);
						options = (_vala_array_free (options, options_length1, (GDestroyNotify) g_free), NULL);
						return NULL;
					} else {
						options = (_vala_array_free (options, options_length1, (GDestroyNotify) g_free), NULL);
						g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
						g_clear_error (&_inner_error_);
						return NULL;
					}
				}
				_tmp26_ = options;
				_tmp26__length1 = options_length1;
				_tmp27_ = i;
				_g_free0 (_tmp26_[_tmp27_]);
				_tmp26_[_tmp27_] = _tmp25_;
				_tmp28_ = _tmp26_[_tmp27_];
			}
		}
	}
	_tmp29_ = options;
	_tmp29__length1 = options_length1;
	if (result_length1) {
		*result_length1 = _tmp29__length1;
	}
	result = _tmp29_;
	return result;
}


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


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



