/* test.c generated by valac 0.13.0.13-73a73, the Vala compiler
 * generated from test.vala, do not modify */


#include <glib.h>
#include <glib-object.h>

typedef struct _Block1Data Block1Data;
typedef struct _Block2Data Block2Data;

typedef gint (*MyDelegate) (void* user_data);
struct _Block1Data {
	int _ref_count_;
	MyDelegate f;
	gpointer f_target;
	GDestroyNotify f_target_destroy_notify;
};

struct _Block2Data {
	int _ref_count_;
	gint i;
};



MyDelegate do_ret (MyDelegate f, void* f_target, GDestroyNotify f_target_destroy_notify, void** result_target, GDestroyNotify* result_target_destroy_notify);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (Block1Data* _data1_);
static gint _lambda0_ (Block1Data* _data1_);
static gint __lambda0__my_delegate (gpointer self);
gint _vala_main (void);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (Block2Data* _data2_);
static gint _lambda1_ (Block2Data* _data2_);
static gint __lambda1__my_delegate (gpointer self);


static Block1Data* block1_data_ref (Block1Data* _data1_) {
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}


static void block1_data_unref (Block1Data* _data1_) {
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		(_data1_->f_target_destroy_notify == NULL) ? NULL : (_data1_->f_target_destroy_notify (_data1_->f_target), NULL);
		_data1_->f = NULL;
		_data1_->f_target = NULL;
		_data1_->f_target_destroy_notify = NULL;
		g_slice_free (Block1Data, _data1_);
	}
}


static gint _lambda0_ (Block1Data* _data1_) {
	gint result = 0;
	gint _tmp0_;
	_tmp0_ = _data1_->f (_data1_->f_target);
	result = _tmp0_;
	return result;
}


static gint __lambda0__my_delegate (gpointer self) {
	gint result;
	result = _lambda0_ (self);
	return result;
}


MyDelegate do_ret (MyDelegate f, void* f_target, GDestroyNotify f_target_destroy_notify, void** result_target, GDestroyNotify* result_target_destroy_notify) {
	MyDelegate result = NULL;
	Block1Data* _data1_;
	gpointer _tmp0_;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	(_data1_->f_target_destroy_notify == NULL) ? NULL : (_data1_->f_target_destroy_notify (_data1_->f_target), NULL);
	_data1_->f = NULL;
	_data1_->f_target = NULL;
	_data1_->f_target_destroy_notify = NULL;
	_data1_->f = f;
	_data1_->f_target = f_target;
	_data1_->f_target_destroy_notify = f_target_destroy_notify;
	_data1_->f (_data1_->f_target);
	_tmp0_ = __lambda0__my_delegate;
	*result_target = block1_data_ref (_data1_);
	*result_target_destroy_notify = block1_data_unref;
	result = _tmp0_;
	block1_data_unref (_data1_);
	_data1_ = NULL;
	(_data1_->f_target_destroy_notify == NULL) ? NULL : (_data1_->f_target_destroy_notify (_data1_->f_target), NULL);
	_data1_->f = NULL;
	_data1_->f_target = NULL;
	_data1_->f_target_destroy_notify = NULL;
	return result;
}


static Block2Data* block2_data_ref (Block2Data* _data2_) {
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}


static void block2_data_unref (Block2Data* _data2_) {
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		g_slice_free (Block2Data, _data2_);
	}
}


static gint _lambda1_ (Block2Data* _data2_) {
	gint result = 0;
	gint _tmp0_;
	_tmp0_ = _data2_->i;
	_data2_->i = _tmp0_ + 1;
	result = _tmp0_;
	return result;
}


static gint __lambda1__my_delegate (gpointer self) {
	gint result;
	result = _lambda1_ (self);
	return result;
}


gint _vala_main (void) {
	gint result = 0;
	Block2Data* _data2_;
	void* _tmp0_ = NULL;
	GDestroyNotify _tmp1_ = NULL;
	MyDelegate _tmp2_ = NULL;
	MyDelegate f;
	void* f_target = NULL;
	GDestroyNotify f_target_destroy_notify = NULL;
	gint _tmp3_;
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->i = 0;
	_tmp2_ = do_ret (__lambda1__my_delegate, block2_data_ref (_data2_), block2_data_unref, &_tmp0_, &_tmp1_);
	f = _tmp2_;
	f_target = _tmp0_;
	f_target_destroy_notify = _tmp1_;
	_tmp3_ = f (f_target);
	result = _tmp3_;
	(f_target_destroy_notify == NULL) ? NULL : (f_target_destroy_notify (f_target), NULL);
	f = NULL;
	f_target = NULL;
	f_target_destroy_notify = NULL;
	block2_data_unref (_data2_);
	_data2_ = NULL;
	return result;
}


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



