/* umockdev-record.c generated by valac 0.18.1, the Vala compiler
 * generated from umockdev-record.vala, do not modify */

/*
 * Record Linux devices and their ancestors from sysfs/udev.
 * All attributes and properties are included, non-ASCII ones get printed in hex.
 * The record is written to the standard output.
 *
 * Copyright (C) 2013 Canonical Ltd.
 * Author: Martin Pitt <martin.pitt@ubuntu.com>
 *
 * umockdev is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * umockdev is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <errno.h>
#include "sys/types.h"
#include <glib/gstdio.h>
#include <fcntl.h>
#include <unistd.h>

#define _g_dir_close0(var) ((var == NULL) ? NULL : (var = (g_dir_close (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define __g_list_free__g_free0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__g_free0_ (var), NULL)))
#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);


extern gchar** opt_devices;
gchar** opt_devices = NULL;
extern gboolean opt_all;
gboolean opt_all = FALSE;
extern gchar* opt_ioctl;
gchar* opt_ioctl = NULL;

void exit_error (const gchar* message, ...);
void devices_from_dir (const gchar* dir, GPtrArray** devs);
gchar** all_devices (void);
static void _g_free0_ (gpointer var);
static gchar** _vala_array_dup1 (gchar** self, int length);
gchar* resolve (const gchar* dev);
gchar* parent (const gchar* dev);
gchar* format_hex (guint8* bytes, int bytes_length1, gint len);
void write_attr (const gchar* name, guint8* val, int val_length1);
gchar* dev_contents (const gchar* dev);
void record_device (const gchar* dev);
static void _g_list_free__g_free0_ (GList* self);
void record_ioctl (const gchar* dev, const gchar* outfile, gchar** argv, int argv_length1);
gint _vala_main (gchar** args, int args_length1);
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);
static gint _vala_array_length (gpointer array);

const GOptionEntry options[4] = {{"all", 'a', 0, G_OPTION_ARG_NONE, &opt_all, "Record all devices"}, {"ioctl", 'i', 0, G_OPTION_ARG_FILENAME, &opt_ioctl, "Trace ioctls on the device, record into given file. In this case, the " \
"first argument specifies the device, and all remaining arguments are a" \
" command (and its arguments) to run that gets traced.", "FILE"}, {"", (gchar) 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_devices, "Path of a device in /dev or /sys.", "DEVICE [...]"}, {NULL}};

void exit_error (const gchar* message, ...) {
	FILE* _tmp0_;
	const gchar* _tmp1_;
	va_list _tmp2_ = {0};
	FILE* _tmp3_;
	g_return_if_fail (message != NULL);
	_tmp0_ = stderr;
	_tmp1_ = message;
	va_start (_tmp2_, message);
	vfprintf (_tmp0_, _tmp1_, _tmp2_);
	va_end (_tmp2_);
	_tmp3_ = stderr;
	fputs ("\n", _tmp3_);
	exit (1);
}


void devices_from_dir (const gchar* dir, GPtrArray** devs) {
	GDir* d = NULL;
	gboolean has_uevent;
	gboolean has_subsystem;
	gchar* entry = NULL;
	gboolean _tmp26_ = FALSE;
	gboolean _tmp27_;
	gboolean _tmp29_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (dir != NULL);
	g_return_if_fail (*devs != NULL);
	{
		const gchar* _tmp0_;
		GDir* _tmp1_ = NULL;
		GDir* _tmp2_;
		_tmp0_ = dir;
		_tmp1_ = g_dir_open (_tmp0_, (guint) 0, &_inner_error_);
		_tmp2_ = _tmp1_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				goto __catch0_g_file_error;
			}
			_g_dir_close0 (d);
			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;
		}
		_g_dir_close0 (d);
		d = _tmp2_;
	}
	goto __finally0;
	__catch0_g_file_error:
	{
		GError* e = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_g_error_free0 (e);
		_g_dir_close0 (d);
		return;
	}
	__finally0:
	if (_inner_error_ != NULL) {
		_g_dir_close0 (d);
		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;
	}
	has_uevent = FALSE;
	has_subsystem = FALSE;
	while (TRUE) {
		GDir* _tmp3_;
		const gchar* _tmp4_ = NULL;
		gchar* _tmp5_;
		const gchar* _tmp6_;
		const gchar* _tmp7_;
		_tmp3_ = d;
		_tmp4_ = g_dir_read_name (_tmp3_);
		_tmp5_ = g_strdup (_tmp4_);
		_g_free0 (entry);
		entry = _tmp5_;
		_tmp6_ = entry;
		if (!(_tmp6_ != NULL)) {
			break;
		}
		_tmp7_ = entry;
		if (g_strcmp0 (_tmp7_, "uevent") == 0) {
			has_uevent = TRUE;
		} else {
			const gchar* _tmp8_;
			_tmp8_ = entry;
			if (g_strcmp0 (_tmp8_, "subsystem") == 0) {
				has_subsystem = TRUE;
			} else {
				const gchar* _tmp9_;
				const gchar* _tmp10_;
				gchar* _tmp11_ = NULL;
				gchar* p;
				struct stat st = {0};
				gboolean _tmp12_ = FALSE;
				gboolean _tmp13_ = FALSE;
				const gchar* _tmp14_;
				struct stat _tmp15_ = {0};
				gint _tmp16_ = 0;
				gboolean _tmp20_;
				gboolean _tmp24_;
				_tmp9_ = dir;
				_tmp10_ = entry;
				_tmp11_ = g_build_filename (_tmp9_, _tmp10_, NULL);
				p = _tmp11_;
				_tmp14_ = p;
				_tmp16_ = lstat (_tmp14_, &_tmp15_);
				st = _tmp15_;
				if (_tmp16_ == 0) {
					struct stat _tmp17_;
					mode_t _tmp18_;
					gboolean _tmp19_ = FALSE;
					_tmp17_ = st;
					_tmp18_ = _tmp17_.st_mode;
					_tmp19_ = S_ISDIR (_tmp18_);
					_tmp13_ = _tmp19_;
				} else {
					_tmp13_ = FALSE;
				}
				_tmp20_ = _tmp13_;
				if (_tmp20_) {
					struct stat _tmp21_;
					mode_t _tmp22_;
					gboolean _tmp23_ = FALSE;
					_tmp21_ = st;
					_tmp22_ = _tmp21_.st_mode;
					_tmp23_ = S_ISLNK (_tmp22_);
					_tmp12_ = !_tmp23_;
				} else {
					_tmp12_ = FALSE;
				}
				_tmp24_ = _tmp12_;
				if (_tmp24_) {
					const gchar* _tmp25_;
					_tmp25_ = p;
					devices_from_dir (_tmp25_, devs);
				}
				_g_free0 (p);
			}
		}
	}
	_tmp27_ = has_uevent;
	if (_tmp27_) {
		gboolean _tmp28_;
		_tmp28_ = has_subsystem;
		_tmp26_ = _tmp28_;
	} else {
		_tmp26_ = FALSE;
	}
	_tmp29_ = _tmp26_;
	if (_tmp29_) {
		GPtrArray* _tmp30_;
		const gchar* _tmp31_;
		gchar* _tmp32_;
		_tmp30_ = *devs;
		_tmp31_ = dir;
		_tmp32_ = g_strdup (_tmp31_);
		g_ptr_array_add (_tmp30_, _tmp32_);
	}
	_g_free0 (entry);
	_g_dir_close0 (d);
}


static void _g_free0_ (gpointer var) {
	var = (g_free (var), NULL);
}


static gchar** _vala_array_dup1 (gchar** self, int length) {
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


gchar** all_devices (void) {
	gchar** result = NULL;
	GPtrArray* _tmp0_;
	GPtrArray* devs;
	GPtrArray* _tmp1_;
	gpointer* _tmp2_;
	gint _tmp2__length1;
	gchar** _tmp3_;
	gint _tmp3__length1;
	_tmp0_ = g_ptr_array_new_with_free_func (_g_free0_);
	devs = _tmp0_;
	devices_from_dir ("/sys/devices", &devs);
	_tmp1_ = devs;
	_tmp2_ = _tmp1_->pdata;
	_tmp2__length1 = (gint) _tmp1_->len;
	_tmp3_ = (_tmp2_ != NULL) ? _vala_array_dup1 (_tmp2_, _tmp2__length1) : ((gpointer) _tmp2_);
	_tmp3__length1 = _tmp2__length1;
	result = _tmp3_;
	_g_ptr_array_unref0 (devs);
	return result;
}


gchar* resolve (const gchar* dev) {
	gchar* result = NULL;
	struct stat st = {0};
	const gchar* _tmp0_;
	struct stat _tmp1_ = {0};
	gint _tmp2_ = 0;
	struct stat _tmp6_;
	dev_t _tmp7_;
	guint _tmp8_ = 0U;
	guint major;
	struct stat _tmp9_;
	dev_t _tmp10_;
	guint _tmp11_ = 0U;
	guint minor;
	gchar* link = NULL;
	struct stat _tmp12_;
	mode_t _tmp13_;
	gboolean _tmp14_ = FALSE;
	const gchar* _tmp26_;
	gchar* _tmp27_ = NULL;
	gchar* real;
	const gchar* _tmp28_;
	const gchar* _tmp31_;
	gchar* _tmp32_ = NULL;
	gchar* _tmp33_;
	gboolean _tmp34_ = FALSE;
	gboolean _tmp35_;
	g_return_val_if_fail (dev != NULL, NULL);
	_tmp0_ = dev;
	_tmp2_ = stat (_tmp0_, &_tmp1_);
	st = _tmp1_;
	if (_tmp2_ != 0) {
		const gchar* _tmp3_;
		gint _tmp4_;
		const gchar* _tmp5_ = NULL;
		_tmp3_ = dev;
		_tmp4_ = errno;
		_tmp5_ = g_strerror (_tmp4_);
		exit_error ("Cannot access device %s: %s", _tmp3_, _tmp5_, NULL);
	}
	_tmp6_ = st;
	_tmp7_ = _tmp6_.st_rdev;
	_tmp8_ = major (_tmp7_);
	major = _tmp8_;
	_tmp9_ = st;
	_tmp10_ = _tmp9_.st_rdev;
	_tmp11_ = minor (_tmp10_);
	minor = _tmp11_;
	_tmp12_ = st;
	_tmp13_ = _tmp12_.st_mode;
	_tmp14_ = S_ISCHR (_tmp13_);
	if (_tmp14_) {
		guint _tmp15_;
		guint _tmp16_;
		gchar* _tmp17_ = NULL;
		_tmp15_ = major;
		_tmp16_ = minor;
		_tmp17_ = g_strdup_printf ("/sys/dev/char/%u:%u", _tmp15_, _tmp16_);
		_g_free0 (link);
		link = _tmp17_;
	} else {
		struct stat _tmp18_;
		mode_t _tmp19_;
		gboolean _tmp20_ = FALSE;
		_tmp18_ = st;
		_tmp19_ = _tmp18_.st_mode;
		_tmp20_ = S_ISBLK (_tmp19_);
		if (_tmp20_) {
			guint _tmp21_;
			guint _tmp22_;
			gchar* _tmp23_ = NULL;
			_tmp21_ = major;
			_tmp22_ = minor;
			_tmp23_ = g_strdup_printf ("/sys/dev/block/%u:%u", _tmp21_, _tmp22_);
			_g_free0 (link);
			link = _tmp23_;
		} else {
			const gchar* _tmp24_;
			gchar* _tmp25_;
			_tmp24_ = dev;
			_tmp25_ = g_strdup (_tmp24_);
			_g_free0 (link);
			link = _tmp25_;
		}
	}
	_tmp26_ = link;
	_tmp27_ = realpath (_tmp26_, NULL);
	real = _tmp27_;
	_tmp28_ = real;
	if (_tmp28_ == NULL) {
		const gchar* _tmp29_;
		gchar* _tmp30_;
		_tmp29_ = link;
		_tmp30_ = g_strdup (_tmp29_);
		_g_free0 (real);
		real = _tmp30_;
	}
	_tmp31_ = real;
	_tmp32_ = g_build_filename (_tmp31_, "uevent", NULL);
	_tmp33_ = _tmp32_;
	_tmp34_ = g_file_test (_tmp33_, G_FILE_TEST_EXISTS);
	_tmp35_ = !_tmp34_;
	_g_free0 (_tmp33_);
	if (_tmp35_) {
		const gchar* _tmp36_;
		_tmp36_ = real;
		exit_error ("Invalid device %s, has no uevent attribute", _tmp36_, NULL);
	}
	result = real;
	_g_free0 (link);
	return result;
}


gchar* parent (const gchar* dev) {
	gchar* result = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_ = NULL;
	gchar* p;
	const gchar* _tmp2_;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_;
	gboolean _tmp8_ = FALSE;
	gboolean _tmp9_;
	gboolean _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_ = NULL;
	g_return_val_if_fail (dev != NULL, NULL);
	_tmp0_ = dev;
	_tmp1_ = g_path_get_dirname (_tmp0_);
	p = _tmp1_;
	_tmp2_ = p;
	_tmp3_ = g_str_has_prefix (_tmp2_, "/sys");
	if (!_tmp3_) {
		result = NULL;
		_g_free0 (p);
		return result;
	}
	_tmp5_ = p;
	_tmp6_ = g_build_filename (_tmp5_, "uevent", NULL);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_file_test (_tmp7_, G_FILE_TEST_EXISTS);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	if (_tmp9_) {
		const gchar* _tmp10_;
		gchar* _tmp11_ = NULL;
		gchar* _tmp12_;
		gboolean _tmp13_ = FALSE;
		_tmp10_ = p;
		_tmp11_ = g_build_filename (_tmp10_, "subsystem", NULL);
		_tmp12_ = _tmp11_;
		_tmp13_ = g_file_test (_tmp12_, G_FILE_TEST_EXISTS);
		_tmp4_ = _tmp13_;
		_g_free0 (_tmp12_);
	} else {
		_tmp4_ = FALSE;
	}
	_tmp14_ = _tmp4_;
	if (_tmp14_) {
		result = p;
		return result;
	}
	_tmp15_ = p;
	_tmp16_ = parent (_tmp15_);
	result = _tmp16_;
	_g_free0 (p);
	return result;
}


gchar* format_hex (guint8* bytes, int bytes_length1, gint len) {
	gchar* result = NULL;
	gint _tmp0_;
	GString* _tmp2_;
	GString* _result_;
	GString* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	_tmp0_ = len;
	if (_tmp0_ < 0) {
		guint8* _tmp1_;
		gint _tmp1__length1;
		_tmp1_ = bytes;
		_tmp1__length1 = bytes_length1;
		len = _tmp1__length1;
	}
	_tmp2_ = g_string_new ("");
	_result_ = _tmp2_;
	{
		gint i;
		i = 0;
		{
			gboolean _tmp3_;
			_tmp3_ = TRUE;
			while (TRUE) {
				gboolean _tmp4_;
				gint _tmp6_;
				gint _tmp7_;
				GString* _tmp8_;
				guint8* _tmp9_;
				gint _tmp9__length1;
				gint _tmp10_;
				guint8 _tmp11_;
				_tmp4_ = _tmp3_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp3_ = FALSE;
				_tmp6_ = i;
				_tmp7_ = len;
				if (!(_tmp6_ < _tmp7_)) {
					break;
				}
				_tmp8_ = _result_;
				_tmp9_ = bytes;
				_tmp9__length1 = bytes_length1;
				_tmp10_ = i;
				_tmp11_ = _tmp9_[_tmp10_];
				g_string_append_printf (_tmp8_, "%02X", (guint) _tmp11_);
			}
		}
	}
	_tmp12_ = _result_;
	_tmp13_ = _tmp12_->str;
	_tmp14_ = g_strdup (_tmp13_);
	result = _tmp14_;
	_g_string_free0 (_result_);
	return result;
}


static gchar* string_chomp (const gchar* self) {
	gchar* result = NULL;
	gchar* _tmp0_ = NULL;
	gchar* _result_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	g_strchomp (_tmp1_);
	result = _result_;
	return result;
}


void write_attr (const gchar* name, guint8* val, int val_length1) {
	guint8* _tmp0_;
	gint _tmp0__length1;
	gchar* _tmp1_;
	gchar* strval;
	gboolean _tmp2_ = FALSE;
	guint8* _tmp3_;
	gint _tmp3__length1;
	const gchar* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gboolean _tmp9_;
	FILE* _tmp22_;
	g_return_if_fail (name != NULL);
	_tmp0_ = val;
	_tmp0__length1 = val_length1;
	_tmp1_ = g_strdup ((const gchar*) _tmp0_);
	strval = _tmp1_;
	_tmp3_ = val;
	_tmp3__length1 = val_length1;
	_tmp4_ = strval;
	_tmp5_ = strlen (_tmp4_);
	_tmp6_ = _tmp5_;
	if (_tmp3__length1 == _tmp6_) {
		const gchar* _tmp7_;
		gboolean _tmp8_ = FALSE;
		_tmp7_ = strval;
		_tmp8_ = g_utf8_validate (_tmp7_, (gssize) (-1), NULL);
		_tmp2_ = _tmp8_;
	} else {
		_tmp2_ = FALSE;
	}
	_tmp9_ = _tmp2_;
	if (_tmp9_) {
		FILE* _tmp10_;
		const gchar* _tmp11_;
		const gchar* _tmp12_;
		gchar* _tmp13_ = NULL;
		gchar* _tmp14_;
		gchar* _tmp15_ = NULL;
		gchar* _tmp16_;
		_tmp10_ = stdout;
		_tmp11_ = name;
		_tmp12_ = strval;
		_tmp13_ = string_chomp (_tmp12_);
		_tmp14_ = _tmp13_;
		_tmp15_ = g_strescape (_tmp14_, "");
		_tmp16_ = _tmp15_;
		fprintf (_tmp10_, "A: %s=%s", _tmp11_, _tmp16_);
		_g_free0 (_tmp16_);
		_g_free0 (_tmp14_);
	} else {
		FILE* _tmp17_;
		const gchar* _tmp18_;
		guint8* _tmp19_;
		gint _tmp19__length1;
		gchar* _tmp20_ = NULL;
		gchar* _tmp21_;
		_tmp17_ = stdout;
		_tmp18_ = name;
		_tmp19_ = val;
		_tmp19__length1 = val_length1;
		_tmp20_ = format_hex (_tmp19_, _tmp19__length1, -1);
		_tmp21_ = _tmp20_;
		fprintf (_tmp17_, "H: %s=%s", _tmp18_, _tmp21_);
		_g_free0 (_tmp21_);
	}
	_tmp22_ = stdout;
	fputc ('\n', _tmp22_);
	_g_free0 (strval);
}


gchar* dev_contents (const gchar* dev) {
	gchar* result = NULL;
	struct stat st = {0};
	const gchar* _tmp0_;
	struct stat _tmp1_ = {0};
	gint _tmp2_ = 0;
	gboolean _tmp4_ = FALSE;
	struct stat _tmp5_;
	mode_t _tmp6_;
	gboolean _tmp7_ = FALSE;
	gboolean _tmp11_;
	const gchar* _tmp13_;
	gint _tmp14_ = 0;
	gint fd;
	gint _tmp15_;
	guint8* _tmp17_ = NULL;
	guint8* buffer;
	gint buffer_length1;
	gint _buffer_size_;
	gint _tmp18_;
	guint8* _tmp19_;
	gint _tmp19__length1;
	gssize _tmp20_ = 0L;
	gssize len;
	gchar* _tmp21_;
	gchar* _result_;
	gboolean _tmp22_ = FALSE;
	gssize _tmp23_;
	gboolean _tmp25_;
	gint _tmp31_;
	g_return_val_if_fail (dev != NULL, NULL);
	_tmp0_ = dev;
	_tmp2_ = lstat (_tmp0_, &_tmp1_);
	st = _tmp1_;
	if (_tmp2_ != 0) {
		gchar* _tmp3_;
		_tmp3_ = g_strdup ("");
		result = _tmp3_;
		return result;
	}
	_tmp5_ = st;
	_tmp6_ = _tmp5_.st_mode;
	_tmp7_ = S_ISCHR (_tmp6_);
	if (!_tmp7_) {
		_tmp4_ = TRUE;
	} else {
		struct stat _tmp8_;
		dev_t _tmp9_;
		guint _tmp10_ = 0U;
		_tmp8_ = st;
		_tmp9_ = _tmp8_.st_rdev;
		_tmp10_ = major (_tmp9_);
		_tmp4_ = _tmp10_ != ((guint) 189);
	}
	_tmp11_ = _tmp4_;
	if (_tmp11_) {
		gchar* _tmp12_;
		_tmp12_ = g_strdup ("");
		result = _tmp12_;
		return result;
	}
	_tmp13_ = dev;
	_tmp14_ = open (_tmp13_, O_RDONLY | O_NONBLOCK, (mode_t) 0);
	fd = _tmp14_;
	_tmp15_ = fd;
	if (_tmp15_ < 0) {
		gchar* _tmp16_;
		_tmp16_ = g_strdup ("");
		result = _tmp16_;
		return result;
	}
	_tmp17_ = g_new0 (guint8, 1025);
	buffer = _tmp17_;
	buffer_length1 = 1025;
	_buffer_size_ = buffer_length1;
	_tmp18_ = fd;
	_tmp19_ = buffer;
	_tmp19__length1 = buffer_length1;
	_tmp20_ = read (_tmp18_, _tmp19_, (gsize) 1025);
	len = _tmp20_;
	_tmp21_ = g_strdup ("");
	_result_ = _tmp21_;
	_tmp23_ = len;
	if (_tmp23_ > ((gssize) 0)) {
		gssize _tmp24_;
		_tmp24_ = len;
		_tmp22_ = _tmp24_ <= ((gssize) 1024);
	} else {
		_tmp22_ = FALSE;
	}
	_tmp25_ = _tmp22_;
	if (_tmp25_) {
		guint8* _tmp26_;
		gint _tmp26__length1;
		gssize _tmp27_;
		gchar* _tmp28_ = NULL;
		gchar* _tmp29_;
		gchar* _tmp30_;
		_tmp26_ = buffer;
		_tmp26__length1 = buffer_length1;
		_tmp27_ = len;
		_tmp28_ = format_hex (_tmp26_, _tmp26__length1, (gint) _tmp27_);
		_tmp29_ = _tmp28_;
		_tmp30_ = g_strconcat ("=", _tmp29_, NULL);
		_g_free0 (_result_);
		_result_ = _tmp30_;
		_g_free0 (_tmp29_);
	}
	_tmp31_ = fd;
	close (_tmp31_);
	result = _result_;
	buffer = (g_free (buffer), NULL);
	return result;
}


static glong string_strnlen (gchar* str, glong maxlen) {
	glong result = 0L;
	gchar* _tmp0_;
	glong _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* end;
	gchar* _tmp3_;
	_tmp0_ = str;
	_tmp1_ = maxlen;
	_tmp2_ = memchr (_tmp0_, 0, (gsize) _tmp1_);
	end = _tmp2_;
	_tmp3_ = end;
	if (_tmp3_ == NULL) {
		glong _tmp4_;
		_tmp4_ = maxlen;
		result = _tmp4_;
		return result;
	} else {
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp5_ = end;
		_tmp6_ = str;
		result = (glong) (_tmp5_ - _tmp6_);
		return result;
	}
}


static gchar* string_substring (const gchar* self, glong offset, glong len) {
	gchar* result = NULL;
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	glong _tmp1_;
	gboolean _tmp3_;
	glong _tmp9_;
	glong _tmp15_;
	glong _tmp18_;
	glong _tmp19_;
	glong _tmp20_;
	glong _tmp21_;
	glong _tmp22_;
	gchar* _tmp23_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = offset;
	if (_tmp1_ >= ((glong) 0)) {
		glong _tmp2_;
		_tmp2_ = len;
		_tmp0_ = _tmp2_ >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	_tmp3_ = _tmp0_;
	if (_tmp3_) {
		glong _tmp4_;
		glong _tmp5_;
		glong _tmp6_ = 0L;
		_tmp4_ = offset;
		_tmp5_ = len;
		_tmp6_ = string_strnlen ((gchar*) self, _tmp4_ + _tmp5_);
		string_length = _tmp6_;
	} else {
		gint _tmp7_;
		gint _tmp8_;
		_tmp7_ = strlen (self);
		_tmp8_ = _tmp7_;
		string_length = (glong) _tmp8_;
	}
	_tmp9_ = offset;
	if (_tmp9_ < ((glong) 0)) {
		glong _tmp10_;
		glong _tmp11_;
		glong _tmp12_;
		_tmp10_ = string_length;
		_tmp11_ = offset;
		offset = _tmp10_ + _tmp11_;
		_tmp12_ = offset;
		g_return_val_if_fail (_tmp12_ >= ((glong) 0), NULL);
	} else {
		glong _tmp13_;
		glong _tmp14_;
		_tmp13_ = offset;
		_tmp14_ = string_length;
		g_return_val_if_fail (_tmp13_ <= _tmp14_, NULL);
	}
	_tmp15_ = len;
	if (_tmp15_ < ((glong) 0)) {
		glong _tmp16_;
		glong _tmp17_;
		_tmp16_ = string_length;
		_tmp17_ = offset;
		len = _tmp16_ - _tmp17_;
	}
	_tmp18_ = offset;
	_tmp19_ = len;
	_tmp20_ = string_length;
	g_return_val_if_fail ((_tmp18_ + _tmp19_) <= _tmp20_, NULL);
	_tmp21_ = offset;
	_tmp22_ = len;
	_tmp23_ = g_strndup (((gchar*) self) + _tmp21_, (gsize) _tmp22_);
	result = _tmp23_;
	return result;
}


static void _g_list_free__g_free0_ (GList* self) {
	g_list_foreach (self, (GFunc) _g_free0_, NULL);
	g_list_free (self);
}


void record_device (const gchar* dev) {
	const gchar* _tmp0_;
	gchar* u_out = NULL;
	gint exitcode = 0;
	const gchar* _tmp19_;
	gchar** _tmp20_;
	gchar** _tmp21_ = NULL;
	GDir* d = NULL;
	GList* attributes;
	gchar* entry = NULL;
	GCompareFunc _tmp76_;
	GList* _tmp77_;
	FILE* _tmp100_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (dev != NULL);
	_tmp0_ = dev;
	g_debug ("umockdev-record.vala:170: recording device %s", _tmp0_);
	{
		gchar* _tmp1_;
		gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		gchar** _tmp7_ = NULL;
		gchar** _tmp8_;
		gint _tmp8__length1;
		gchar* _tmp9_ = NULL;
		gint _tmp10_ = 0;
		gint _tmp11_;
		_tmp1_ = g_strdup ("udevadm");
		_tmp2_ = g_strdup ("info");
		_tmp3_ = g_strdup ("--query=all");
		_tmp4_ = g_strdup ("--path");
		_tmp5_ = dev;
		_tmp6_ = g_strdup (_tmp5_);
		_tmp7_ = g_new0 (gchar*, 5 + 1);
		_tmp7_[0] = _tmp1_;
		_tmp7_[1] = _tmp2_;
		_tmp7_[2] = _tmp3_;
		_tmp7_[3] = _tmp4_;
		_tmp7_[4] = _tmp6_;
		_tmp8_ = _tmp7_;
		_tmp8__length1 = 5;
		g_spawn_sync (NULL, _tmp8_, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &_tmp9_, NULL, &_tmp10_, &_inner_error_);
		_g_free0 (u_out);
		u_out = _tmp9_;
		exitcode = _tmp10_;
		_tmp8_ = (_vala_array_free (_tmp8_, _tmp8__length1, (GDestroyNotify) g_free), NULL);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_SPAWN_ERROR) {
				goto __catch1_g_spawn_error;
			}
			_g_free0 (u_out);
			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;
		}
		_tmp11_ = exitcode;
		if (_tmp11_ != 0) {
			gint _tmp12_;
			gchar* _tmp13_ = NULL;
			gchar* _tmp14_;
			GError* _tmp15_;
			GError* _tmp16_;
			_tmp12_ = exitcode;
			_tmp13_ = g_strdup_printf ("udevadm exited with code %i", _tmp12_);
			_tmp14_ = _tmp13_;
			_tmp15_ = g_error_new_literal (G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED, _tmp14_);
			_tmp16_ = _tmp15_;
			_g_free0 (_tmp14_);
			_inner_error_ = _tmp16_;
			if (_inner_error_->domain == G_SPAWN_ERROR) {
				goto __catch1_g_spawn_error;
			}
			_g_free0 (u_out);
			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;
		}
	}
	goto __finally1;
	__catch1_g_spawn_error:
	{
		GError* e = NULL;
		GError* _tmp17_;
		const gchar* _tmp18_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp17_ = e;
		_tmp18_ = _tmp17_->message;
		exit_error ("Cannot call udevadm: %s", _tmp18_, NULL);
		_g_error_free0 (e);
	}
	__finally1:
	if (_inner_error_ != NULL) {
		_g_free0 (u_out);
		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;
	}
	_tmp19_ = u_out;
	_tmp21_ = _tmp20_ = g_strsplit (_tmp19_, "\n", 0);
	{
		gchar** line_collection = NULL;
		gint line_collection_length1 = 0;
		gint _line_collection_size_ = 0;
		gint line_it = 0;
		line_collection = _tmp21_;
		line_collection_length1 = _vala_array_length (_tmp20_);
		for (line_it = 0; line_it < _vala_array_length (_tmp20_); line_it = line_it + 1) {
			gchar* _tmp22_;
			gchar* line = NULL;
			_tmp22_ = g_strdup (line_collection[line_it]);
			line = _tmp22_;
			{
				gboolean _tmp23_ = FALSE;
				gboolean _tmp24_ = FALSE;
				gboolean _tmp25_ = FALSE;
				const gchar* _tmp26_;
				gint _tmp27_;
				gint _tmp28_;
				gboolean _tmp31_;
				gboolean _tmp34_;
				gboolean _tmp37_;
				const gchar* _tmp38_;
				gboolean _tmp39_ = FALSE;
				FILE* _tmp51_;
				const gchar* _tmp52_;
				FILE* _tmp53_;
				_tmp26_ = line;
				_tmp27_ = strlen (_tmp26_);
				_tmp28_ = _tmp27_;
				if (_tmp28_ == 0) {
					_tmp25_ = TRUE;
				} else {
					const gchar* _tmp29_;
					gboolean _tmp30_ = FALSE;
					_tmp29_ = line;
					_tmp30_ = g_str_has_prefix (_tmp29_, "E: DEVPATH=");
					_tmp25_ = _tmp30_;
				}
				_tmp31_ = _tmp25_;
				if (_tmp31_) {
					_tmp24_ = TRUE;
				} else {
					const gchar* _tmp32_;
					gboolean _tmp33_ = FALSE;
					_tmp32_ = line;
					_tmp33_ = g_str_has_prefix (_tmp32_, "E: UDEV_LOG=");
					_tmp24_ = _tmp33_;
				}
				_tmp34_ = _tmp24_;
				if (_tmp34_) {
					_tmp23_ = TRUE;
				} else {
					const gchar* _tmp35_;
					gboolean _tmp36_ = FALSE;
					_tmp35_ = line;
					_tmp36_ = g_str_has_prefix (_tmp35_, "E: USEC_INITIALIZED=");
					_tmp23_ = _tmp36_;
				}
				_tmp37_ = _tmp23_;
				if (_tmp37_) {
					_g_free0 (line);
					continue;
				}
				_tmp38_ = line;
				_tmp39_ = g_str_has_prefix (_tmp38_, "N: ");
				if (_tmp39_) {
					const gchar* _tmp40_;
					const gchar* _tmp41_;
					gchar* _tmp42_ = NULL;
					gchar* _tmp43_;
					gchar* _tmp44_ = NULL;
					gchar* _tmp45_;
					gchar* _tmp46_;
					gchar* _tmp47_;
					gchar* _tmp48_ = NULL;
					gchar* _tmp49_;
					gchar* _tmp50_;
					_tmp40_ = line;
					_tmp41_ = line;
					_tmp42_ = string_substring (_tmp41_, (glong) 3, (glong) (-1));
					_tmp43_ = _tmp42_;
					_tmp44_ = string_chomp (_tmp43_);
					_tmp45_ = _tmp44_;
					_tmp46_ = g_strconcat ("/dev/", _tmp45_, NULL);
					_tmp47_ = _tmp46_;
					_tmp48_ = dev_contents (_tmp47_);
					_tmp49_ = _tmp48_;
					_tmp50_ = g_strconcat (_tmp40_, _tmp49_, NULL);
					_g_free0 (line);
					line = _tmp50_;
					_g_free0 (_tmp49_);
					_g_free0 (_tmp47_);
					_g_free0 (_tmp45_);
					_g_free0 (_tmp43_);
				}
				_tmp51_ = stdout;
				_tmp52_ = line;
				fputs (_tmp52_, _tmp51_);
				_tmp53_ = stdout;
				fputc ('\n', _tmp53_);
				_g_free0 (line);
			}
		}
		line_collection = (_vala_array_free (line_collection, line_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	{
		const gchar* _tmp54_;
		GDir* _tmp55_ = NULL;
		GDir* _tmp56_;
		_tmp54_ = dev;
		_tmp55_ = g_dir_open (_tmp54_, (guint) 0, &_inner_error_);
		_tmp56_ = _tmp55_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				goto __catch2_g_file_error;
			}
			_g_dir_close0 (d);
			_g_free0 (u_out);
			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;
		}
		_g_dir_close0 (d);
		d = _tmp56_;
	}
	goto __finally2;
	__catch2_g_file_error:
	{
		GError* e = NULL;
		const gchar* _tmp57_;
		GError* _tmp58_;
		const gchar* _tmp59_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp57_ = dev;
		_tmp58_ = e;
		_tmp59_ = _tmp58_->message;
		exit_error ("Cannot open directory %s: %s", _tmp57_, _tmp59_, NULL);
		_g_error_free0 (e);
		_g_dir_close0 (d);
		_g_free0 (u_out);
		return;
	}
	__finally2:
	if (_inner_error_ != NULL) {
		_g_dir_close0 (d);
		_g_free0 (u_out);
		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;
	}
	attributes = NULL;
	while (TRUE) {
		GDir* _tmp60_;
		const gchar* _tmp61_ = NULL;
		gchar* _tmp62_;
		const gchar* _tmp63_;
		gboolean _tmp64_ = FALSE;
		gboolean _tmp65_ = FALSE;
		gboolean _tmp66_ = FALSE;
		const gchar* _tmp67_;
		gboolean _tmp69_;
		gboolean _tmp71_;
		gboolean _tmp73_;
		_tmp60_ = d;
		_tmp61_ = g_dir_read_name (_tmp60_);
		_tmp62_ = g_strdup (_tmp61_);
		_g_free0 (entry);
		entry = _tmp62_;
		_tmp63_ = entry;
		if (!(_tmp63_ != NULL)) {
			break;
		}
		_tmp67_ = entry;
		if (g_strcmp0 (_tmp67_, "subsystem") != 0) {
			const gchar* _tmp68_;
			_tmp68_ = entry;
			_tmp66_ = g_strcmp0 (_tmp68_, "firmware_node") != 0;
		} else {
			_tmp66_ = FALSE;
		}
		_tmp69_ = _tmp66_;
		if (_tmp69_) {
			const gchar* _tmp70_;
			_tmp70_ = entry;
			_tmp65_ = g_strcmp0 (_tmp70_, "driver") != 0;
		} else {
			_tmp65_ = FALSE;
		}
		_tmp71_ = _tmp65_;
		if (_tmp71_) {
			const gchar* _tmp72_;
			_tmp72_ = entry;
			_tmp64_ = g_strcmp0 (_tmp72_, "uevent") != 0;
		} else {
			_tmp64_ = FALSE;
		}
		_tmp73_ = _tmp64_;
		if (_tmp73_) {
			const gchar* _tmp74_;
			gchar* _tmp75_;
			_tmp74_ = entry;
			_tmp75_ = g_strdup (_tmp74_);
			attributes = g_list_append (attributes, _tmp75_);
		}
	}
	_tmp76_ = g_strcmp0;
	attributes = g_list_sort (attributes, _tmp76_);
	_tmp77_ = attributes;
	{
		GList* attr_collection = NULL;
		GList* attr_it = NULL;
		attr_collection = _tmp77_;
		for (attr_it = attr_collection; attr_it != NULL; attr_it = attr_it->next) {
			gchar* _tmp78_;
			gchar* attr = NULL;
			_tmp78_ = g_strdup ((const gchar*) attr_it->data);
			attr = _tmp78_;
			{
				const gchar* _tmp79_;
				const gchar* _tmp80_;
				gchar* _tmp81_ = NULL;
				gchar* attr_path;
				const gchar* _tmp82_;
				gboolean _tmp83_ = FALSE;
				const gchar* _tmp84_;
				gboolean _tmp85_ = FALSE;
				_tmp79_ = dev;
				_tmp80_ = attr;
				_tmp81_ = g_build_filename (_tmp79_, _tmp80_, NULL);
				attr_path = _tmp81_;
				_tmp82_ = attr_path;
				_tmp83_ = g_file_test (_tmp82_, G_FILE_TEST_IS_REGULAR);
				if (!_tmp83_) {
					_g_free0 (attr_path);
					_g_free0 (attr);
					continue;
				}
				_tmp84_ = attr_path;
				_tmp85_ = g_file_test (_tmp84_, G_FILE_TEST_IS_SYMLINK);
				if (_tmp85_) {
					{
						const gchar* _tmp86_;
						gchar* _tmp87_ = NULL;
						gchar* _tmp88_;
						FILE* _tmp89_;
						const gchar* _tmp90_;
						gchar* _tmp91_;
						_tmp86_ = attr_path;
						_tmp87_ = g_file_read_link (_tmp86_, &_inner_error_);
						_tmp88_ = _tmp87_;
						if (_inner_error_ != NULL) {
							if (_inner_error_->domain == G_FILE_ERROR) {
								goto __catch3_g_file_error;
							}
							_g_free0 (attr_path);
							_g_free0 (attr);
							_g_free0 (entry);
							__g_list_free__g_free0_0 (attributes);
							_g_dir_close0 (d);
							_g_free0 (u_out);
							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;
						}
						_tmp89_ = stdout;
						_tmp90_ = attr;
						_tmp91_ = _tmp88_;
						fprintf (_tmp89_, "L: %s=%s\n", _tmp90_, _tmp91_);
						_g_free0 (_tmp91_);
					}
					goto __finally3;
					__catch3_g_file_error:
					{
						GError* e = NULL;
						const gchar* _tmp92_;
						GError* _tmp93_;
						const gchar* _tmp94_;
						e = _inner_error_;
						_inner_error_ = NULL;
						_tmp92_ = attr;
						_tmp93_ = e;
						_tmp94_ = _tmp93_->message;
						exit_error ("Cannot read link %s: %s", _tmp92_, _tmp94_, NULL);
						_g_error_free0 (e);
					}
					__finally3:
					if (_inner_error_ != NULL) {
						_g_free0 (attr_path);
						_g_free0 (attr);
						_g_free0 (entry);
						__g_list_free__g_free0_0 (attributes);
						_g_dir_close0 (d);
						_g_free0 (u_out);
						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;
					}
				} else {
					guint8* contents = NULL;
					gint contents_length1 = 0;
					gint _contents_size_ = 0;
					{
						const gchar* _tmp95_;
						guint8* _tmp96_ = NULL;
						size_t _tmp97_;
						const gchar* _tmp98_;
						guint8* _tmp99_;
						gint _tmp99__length1;
						_tmp95_ = attr_path;
						g_file_get_contents (_tmp95_, (gchar**) (&_tmp96_), &_tmp97_, &_inner_error_);
						contents = (g_free (contents), NULL);
						contents = _tmp96_;
						contents_length1 = _tmp97_;
						_contents_size_ = contents_length1;
						if (_inner_error_ != NULL) {
							if (_inner_error_->domain == G_FILE_ERROR) {
								goto __catch4_g_file_error;
							}
							contents = (g_free (contents), NULL);
							_g_free0 (attr_path);
							_g_free0 (attr);
							_g_free0 (entry);
							__g_list_free__g_free0_0 (attributes);
							_g_dir_close0 (d);
							_g_free0 (u_out);
							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;
						}
						_tmp98_ = attr;
						_tmp99_ = contents;
						_tmp99__length1 = contents_length1;
						write_attr (_tmp98_, _tmp99_, _tmp99__length1);
					}
					goto __finally4;
					__catch4_g_file_error:
					{
						GError* e = NULL;
						e = _inner_error_;
						_inner_error_ = NULL;
						_g_error_free0 (e);
					}
					__finally4:
					if (_inner_error_ != NULL) {
						contents = (g_free (contents), NULL);
						_g_free0 (attr_path);
						_g_free0 (attr);
						_g_free0 (entry);
						__g_list_free__g_free0_0 (attributes);
						_g_dir_close0 (d);
						_g_free0 (u_out);
						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;
					}
					contents = (g_free (contents), NULL);
				}
				_g_free0 (attr_path);
				_g_free0 (attr);
			}
		}
	}
	_tmp100_ = stdout;
	fputc ('\n', _tmp100_);
	_g_free0 (entry);
	__g_list_free__g_free0_0 (attributes);
	_g_dir_close0 (d);
	_g_free0 (u_out);
}


static gchar* string_strip (const gchar* self) {
	gchar* result = NULL;
	gchar* _tmp0_ = NULL;
	gchar* _result_;
	const gchar* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	g_strstrip (_tmp1_);
	result = _result_;
	return result;
}


void record_ioctl (const gchar* dev, const gchar* outfile, gchar** argv, int argv_length1) {
	gchar* contents = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_;
	gchar** _tmp9_;
	gchar** _tmp10_ = NULL;
	gchar** _tmp11_;
	gint _tmp11__length1;
	gchar** fields;
	gint fields_length1;
	gint _fields_size_;
	const gchar* _tmp12_;
	gint _tmp13_ = 0;
	const gchar* _tmp14_;
	gint _tmp15_ = 0;
	gchar* _tmp16_ = NULL;
	gchar* devnum;
	const gchar* _tmp17_;
	gchar** _tmp18_;
	gint _tmp18__length1;
	const gchar* _tmp19_;
	gchar** _tmp20_;
	gint _tmp20__length1;
	gchar** _tmp21_;
	gint _tmp21__length1;
	const gchar* _tmp22_;
	gint _tmp23_;
	const gchar* _tmp24_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_if_fail (dev != NULL);
	g_return_if_fail (outfile != NULL);
	{
		const gchar* _tmp0_;
		gchar* _tmp1_ = NULL;
		gchar* _tmp2_;
		gchar* _tmp3_ = NULL;
		_tmp0_ = dev;
		_tmp1_ = g_build_filename (_tmp0_, "dev", NULL);
		_tmp2_ = _tmp1_;
		g_file_get_contents (_tmp2_, &_tmp3_, NULL, &_inner_error_);
		_g_free0 (contents);
		contents = _tmp3_;
		_g_free0 (_tmp2_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_FILE_ERROR) {
				goto __catch5_g_file_error;
			}
			_g_free0 (contents);
			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;
		}
	}
	goto __finally5;
	__catch5_g_file_error:
	{
		GError* e = NULL;
		const gchar* _tmp4_;
		GError* _tmp5_;
		const gchar* _tmp6_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = dev;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		exit_error ("Cannot open %s/dev: %s", _tmp4_, _tmp6_, NULL);
		_g_error_free0 (e);
	}
	__finally5:
	if (_inner_error_ != NULL) {
		_g_free0 (contents);
		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;
	}
	_tmp7_ = string_strip (contents);
	_tmp8_ = _tmp7_;
	_tmp10_ = _tmp9_ = g_strsplit (_tmp8_, ":", 0);
	_tmp11_ = _tmp10_;
	_tmp11__length1 = _vala_array_length (_tmp9_);
	_g_free0 (_tmp8_);
	fields = _tmp11_;
	fields_length1 = _tmp11__length1;
	_fields_size_ = fields_length1;
	_vala_assert (fields_length1 == 2, "fields.length == 2");
	_tmp12_ = fields[0];
	_tmp13_ = atoi (_tmp12_);
	_tmp14_ = fields[1];
	_tmp15_ = atoi (_tmp14_);
	_tmp16_ = g_strdup_printf ("%i", (_tmp13_ << 8) | _tmp15_);
	devnum = _tmp16_;
	g_setenv ("LD_PRELOAD", "libumockdev-preload.so.0", TRUE);
	_tmp17_ = outfile;
	g_setenv ("UMOCKDEV_IOCTL_RECORD_FILE", _tmp17_, TRUE);
	g_setenv ("UMOCKDEV_IOCTL_RECORD_DEV", devnum, TRUE);
	_tmp18_ = argv;
	_tmp18__length1 = argv_length1;
	_tmp19_ = _tmp18_[0];
	_tmp20_ = argv;
	_tmp20__length1 = argv_length1;
	execvp (_tmp19_, _tmp20_);
	_tmp21_ = argv;
	_tmp21__length1 = argv_length1;
	_tmp22_ = _tmp21_[0];
	_tmp23_ = errno;
	_tmp24_ = g_strerror (_tmp23_);
	exit_error ("Cannot run program %s: %s", _tmp22_, _tmp24_, NULL);
	_g_free0 (devnum);
	fields = (_vala_array_free (fields, fields_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (contents);
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	GOptionContext* _tmp0_;
	GOptionContext* oc;
	gboolean _tmp5_ = FALSE;
	gboolean _tmp6_;
	gboolean _tmp8_;
	gboolean _tmp9_ = FALSE;
	gboolean _tmp10_;
	gboolean _tmp12_;
	gboolean _tmp13_ = FALSE;
	const gchar* _tmp14_;
	gboolean _tmp19_;
	gboolean _tmp20_;
	const gchar* _tmp41_;
	GError * _inner_error_ = NULL;
	_tmp0_ = g_option_context_new ("");
	oc = _tmp0_;
	g_option_context_set_summary (oc, "Record Linux devices and their ancestors from sysfs/udev, or record io" \
"ctls for a device.");
	g_option_context_add_main_entries (oc, options, NULL);
	{
		g_option_context_parse (oc, &args_length1, &args, &_inner_error_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == G_OPTION_ERROR) {
				goto __catch6_g_option_error;
			}
			_g_option_context_free0 (oc);
			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 0;
		}
	}
	goto __finally6;
	__catch6_g_option_error:
	{
		GError* e = NULL;
		GError* _tmp1_;
		const gchar* _tmp2_;
		gchar** _tmp3_;
		gint _tmp3__length1;
		const gchar* _tmp4_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp1_ = e;
		_tmp2_ = _tmp1_->message;
		_tmp3_ = args;
		_tmp3__length1 = args_length1;
		_tmp4_ = _tmp3_[0];
		exit_error ("Error: %s\nRun %s --help for how to use this program", _tmp2_, _tmp4_, NULL);
		_g_error_free0 (e);
	}
	__finally6:
	if (_inner_error_ != NULL) {
		_g_option_context_free0 (oc);
		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 0;
	}
	_tmp6_ = opt_all;
	if (_tmp6_) {
		gchar** _tmp7_;
		gint _tmp7__length1;
		_tmp7_ = opt_devices;
		_tmp7__length1 = _vala_array_length (opt_devices);
		_tmp5_ = _tmp7__length1 > 0;
	} else {
		_tmp5_ = FALSE;
	}
	_tmp8_ = _tmp5_;
	if (_tmp8_) {
		exit_error ("Specifying a device list together with --all is invalid.", NULL);
	}
	_tmp10_ = opt_all;
	if (!_tmp10_) {
		gchar** _tmp11_;
		gint _tmp11__length1;
		_tmp11_ = opt_devices;
		_tmp11__length1 = _vala_array_length (opt_devices);
		_tmp9_ = _tmp11__length1 == 0;
	} else {
		_tmp9_ = FALSE;
	}
	_tmp12_ = _tmp9_;
	if (_tmp12_) {
		exit_error ("Need to specify at least one device or --all.", NULL);
	}
	_tmp14_ = opt_ioctl;
	if (_tmp14_ != NULL) {
		gboolean _tmp15_ = FALSE;
		gboolean _tmp16_;
		gboolean _tmp18_;
		_tmp16_ = opt_all;
		if (_tmp16_) {
			_tmp15_ = TRUE;
		} else {
			gchar** _tmp17_;
			gint _tmp17__length1;
			_tmp17_ = opt_devices;
			_tmp17__length1 = _vala_array_length (opt_devices);
			_tmp15_ = _tmp17__length1 < 1;
		}
		_tmp18_ = _tmp15_;
		_tmp13_ = _tmp18_;
	} else {
		_tmp13_ = FALSE;
	}
	_tmp19_ = _tmp13_;
	if (_tmp19_) {
		exit_error ("For tracing ioctls you have to specify exactly one device and a comman" \
"d to run", NULL);
	}
	_tmp20_ = opt_all;
	if (_tmp20_) {
		gchar** _tmp21_;
		gchar** _tmp22_ = NULL;
		_tmp22_ = _tmp21_ = all_devices ();
		opt_devices = (_vala_array_free (opt_devices, _vala_array_length (opt_devices), (GDestroyNotify) g_free), NULL);
		opt_devices = _tmp22_;
	} else {
		const gchar* _tmp23_;
		_tmp23_ = opt_ioctl;
		if (_tmp23_ != NULL) {
			gchar** _tmp24_;
			gint _tmp24__length1;
			gchar** _tmp25_;
			gint _tmp25__length1;
			const gchar* _tmp26_;
			gchar* _tmp27_ = NULL;
			gchar* _tmp28_;
			_tmp24_ = opt_devices;
			_tmp24__length1 = _vala_array_length (opt_devices);
			_tmp25_ = opt_devices;
			_tmp25__length1 = _vala_array_length (opt_devices);
			_tmp26_ = _tmp25_[0];
			_tmp27_ = resolve (_tmp26_);
			_g_free0 (_tmp24_[0]);
			_tmp24_[0] = _tmp27_;
			_tmp28_ = _tmp24_[0];
		} else {
			{
				gint i;
				i = 0;
				{
					gboolean _tmp29_;
					_tmp29_ = TRUE;
					while (TRUE) {
						gboolean _tmp30_;
						gint _tmp32_;
						gchar** _tmp33_;
						gint _tmp33__length1;
						gchar** _tmp34_;
						gint _tmp34__length1;
						gint _tmp35_;
						gchar** _tmp36_;
						gint _tmp36__length1;
						gint _tmp37_;
						const gchar* _tmp38_;
						gchar* _tmp39_ = NULL;
						gchar* _tmp40_;
						_tmp30_ = _tmp29_;
						if (!_tmp30_) {
							gint _tmp31_;
							_tmp31_ = i;
							i = _tmp31_ + 1;
						}
						_tmp29_ = FALSE;
						_tmp32_ = i;
						_tmp33_ = opt_devices;
						_tmp33__length1 = _vala_array_length (opt_devices);
						if (!(_tmp32_ < _tmp33__length1)) {
							break;
						}
						_tmp34_ = opt_devices;
						_tmp34__length1 = _vala_array_length (opt_devices);
						_tmp35_ = i;
						_tmp36_ = opt_devices;
						_tmp36__length1 = _vala_array_length (opt_devices);
						_tmp37_ = i;
						_tmp38_ = _tmp36_[_tmp37_];
						_tmp39_ = resolve (_tmp38_);
						_g_free0 (_tmp34_[_tmp35_]);
						_tmp34_[_tmp35_] = _tmp39_;
						_tmp40_ = _tmp34_[_tmp35_];
					}
				}
			}
		}
	}
	_tmp41_ = opt_ioctl;
	if (_tmp41_ != NULL) {
		gchar** _tmp42_;
		gint _tmp42__length1;
		const gchar* _tmp43_;
		const gchar* _tmp44_;
		gchar** _tmp45_;
		gint _tmp45__length1;
		gchar** _tmp46_;
		gint _tmp46__length1;
		_tmp42_ = opt_devices;
		_tmp42__length1 = _vala_array_length (opt_devices);
		_tmp43_ = _tmp42_[0];
		_tmp44_ = opt_ioctl;
		_tmp45_ = opt_devices;
		_tmp45__length1 = _vala_array_length (opt_devices);
		_tmp46_ = opt_devices;
		_tmp46__length1 = _vala_array_length (opt_devices);
		record_ioctl (_tmp43_, _tmp44_, _tmp45_ + 1, (_tmp46__length1 - 1) - 1);
	} else {
		GHashFunc _tmp47_;
		GEqualFunc _tmp48_;
		GHashTable* _tmp49_;
		GHashTable* seen;
		gchar** _tmp50_;
		gint _tmp50__length1;
		_tmp47_ = g_str_hash;
		_tmp48_ = g_str_equal;
		_tmp49_ = g_hash_table_new_full (_tmp47_, _tmp48_, _g_free0_, NULL);
		seen = _tmp49_;
		_tmp50_ = opt_devices;
		_tmp50__length1 = _vala_array_length (opt_devices);
		{
			gchar** device_collection = NULL;
			gint device_collection_length1 = 0;
			gint _device_collection_size_ = 0;
			gint device_it = 0;
			device_collection = _tmp50_;
			device_collection_length1 = _tmp50__length1;
			for (device_it = 0; device_it < _tmp50__length1; device_it = device_it + 1) {
				gchar* _tmp51_;
				gchar* device = NULL;
				_tmp51_ = g_strdup (device_collection[device_it]);
				device = _tmp51_;
				{
					while (TRUE) {
						const gchar* _tmp52_;
						GHashTable* _tmp53_;
						const gchar* _tmp54_;
						gboolean _tmp55_ = FALSE;
						const gchar* _tmp60_;
						gchar* _tmp61_ = NULL;
						_tmp52_ = device;
						if (!(_tmp52_ != NULL)) {
							break;
						}
						_tmp53_ = seen;
						_tmp54_ = device;
						_tmp55_ = g_hash_table_contains (_tmp53_, _tmp54_);
						if (!_tmp55_) {
							GHashTable* _tmp56_;
							const gchar* _tmp57_;
							gchar* _tmp58_ = NULL;
							const gchar* _tmp59_;
							_tmp56_ = seen;
							_tmp57_ = device;
							_tmp58_ = g_strdup (_tmp57_);
							g_hash_table_add (_tmp56_, _tmp58_);
							_tmp59_ = device;
							record_device (_tmp59_);
						}
						_tmp60_ = device;
						_tmp61_ = parent (_tmp60_);
						_g_free0 (device);
						device = _tmp61_;
					}
					_g_free0 (device);
				}
			}
		}
		_g_hash_table_unref0 (seen);
	}
	result = 0;
	_g_option_context_free0 (oc);
	return result;
}


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


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);
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



