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

/*
 * Copyright (C) 2011-2014 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2011-2014 Red Hat, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <float.h>
#include <math.h>
#include <glib-object.h>
#include "libkkc/libkkc.h"
#include <stdlib.h>
#include <string.h>
#include <gee.h>

#define KKC_MIN_UNIGRAM_COST (-5.0)
#define KKC_DECODER_MAX_DISTANCE 2.0
#define KKC_DECODER_MIN_PATH_COST (-3.0)
#define KKC_DECODER_NBEST 20
#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

#define KKC_TYPE_STATE (kkc_state_get_type ())
#define KKC_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_STATE, KkcState))
#define KKC_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_STATE, KkcStateClass))
#define KKC_IS_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_STATE))
#define KKC_IS_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_STATE))
#define KKC_STATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_STATE, KkcStateClass))

typedef struct _KkcState KkcState;
typedef struct _KkcStateClass KkcStateClass;
typedef struct _KkcStatePrivate KkcStatePrivate;
enum  {
	KKC_STATE_0_PROPERTY,
	KKC_STATE_INPUT_MODE_PROPERTY,
	KKC_STATE_INPUT_CURSOR_POS_PROPERTY,
	KKC_STATE_INPUT_CURSOR_WIDTH_PROPERTY,
	KKC_STATE_PUNCTUATION_STYLE_PROPERTY,
	KKC_STATE_AUTO_CORRECT_PROPERTY,
	KKC_STATE_TYPING_RULE_PROPERTY,
	KKC_STATE_NUM_PROPERTIES
};
static GParamSpec* kkc_state_properties[KKC_STATE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _Block4Data Block4Data;

#define KKC_TYPE_PREFIX_ENTRY (kkc_prefix_entry_get_type ())
typedef struct _KkcPrefixEntry KkcPrefixEntry;
#define _kkc_prefix_entry_free0(var) ((var == NULL) ? NULL : (var = (kkc_prefix_entry_free (var), NULL)))
typedef struct _Block5Data Block5Data;

#define KKC_TYPE_STATE_HANDLER (kkc_state_handler_get_type ())
#define KKC_STATE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_STATE_HANDLER, KkcStateHandler))
#define KKC_STATE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_STATE_HANDLER, KkcStateHandlerClass))
#define KKC_IS_STATE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_STATE_HANDLER))
#define KKC_IS_STATE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_STATE_HANDLER))
#define KKC_STATE_HANDLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_STATE_HANDLER, KkcStateHandlerClass))

typedef struct _KkcStateHandler KkcStateHandler;
typedef struct _KkcStateHandlerClass KkcStateHandlerClass;

#define KKC_TYPE_INITIAL_STATE_HANDLER (kkc_initial_state_handler_get_type ())
#define KKC_INITIAL_STATE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_INITIAL_STATE_HANDLER, KkcInitialStateHandler))
#define KKC_INITIAL_STATE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_INITIAL_STATE_HANDLER, KkcInitialStateHandlerClass))
#define KKC_IS_INITIAL_STATE_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_INITIAL_STATE_HANDLER))
#define KKC_IS_INITIAL_STATE_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_INITIAL_STATE_HANDLER))
#define KKC_INITIAL_STATE_HANDLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_INITIAL_STATE_HANDLER, KkcInitialStateHandlerClass))

typedef struct _KkcInitialStateHandler KkcInitialStateHandler;
typedef struct _KkcInitialStateHandlerClass KkcInitialStateHandlerClass;

#define KKC_TYPE_TEMPLATE (kkc_template_get_type ())
#define KKC_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_TEMPLATE, KkcTemplate))
#define KKC_IS_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_TEMPLATE))
#define KKC_TEMPLATE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), KKC_TYPE_TEMPLATE, KkcTemplateIface))

typedef struct _KkcTemplate KkcTemplate;
typedef struct _KkcTemplateIface KkcTemplateIface;

#define KKC_TYPE_SIMPLE_TEMPLATE (kkc_simple_template_get_type ())
#define KKC_SIMPLE_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_SIMPLE_TEMPLATE, KkcSimpleTemplate))
#define KKC_SIMPLE_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_SIMPLE_TEMPLATE, KkcSimpleTemplateClass))
#define KKC_IS_SIMPLE_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_SIMPLE_TEMPLATE))
#define KKC_IS_SIMPLE_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_SIMPLE_TEMPLATE))
#define KKC_SIMPLE_TEMPLATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_SIMPLE_TEMPLATE, KkcSimpleTemplateClass))

typedef struct _KkcSimpleTemplate KkcSimpleTemplate;
typedef struct _KkcSimpleTemplateClass KkcSimpleTemplateClass;

#define KKC_TYPE_OKURIGANA_TEMPLATE (kkc_okurigana_template_get_type ())
#define KKC_OKURIGANA_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_OKURIGANA_TEMPLATE, KkcOkuriganaTemplate))
#define KKC_OKURIGANA_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_OKURIGANA_TEMPLATE, KkcOkuriganaTemplateClass))
#define KKC_IS_OKURIGANA_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_OKURIGANA_TEMPLATE))
#define KKC_IS_OKURIGANA_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_OKURIGANA_TEMPLATE))
#define KKC_OKURIGANA_TEMPLATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_OKURIGANA_TEMPLATE, KkcOkuriganaTemplateClass))

typedef struct _KkcOkuriganaTemplate KkcOkuriganaTemplate;
typedef struct _KkcOkuriganaTemplateClass KkcOkuriganaTemplateClass;
typedef struct _Block6Data Block6Data;
#define _kkc_language_model_entry_free0(var) ((var == NULL) ? NULL : (var = (kkc_language_model_entry_free (var), NULL)))

#define KKC_TYPE_NUMERIC_TEMPLATE (kkc_numeric_template_get_type ())
#define KKC_NUMERIC_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_NUMERIC_TEMPLATE, KkcNumericTemplate))
#define KKC_NUMERIC_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_NUMERIC_TEMPLATE, KkcNumericTemplateClass))
#define KKC_IS_NUMERIC_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_NUMERIC_TEMPLATE))
#define KKC_IS_NUMERIC_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_NUMERIC_TEMPLATE))
#define KKC_NUMERIC_TEMPLATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_NUMERIC_TEMPLATE, KkcNumericTemplateClass))

typedef struct _KkcNumericTemplate KkcNumericTemplate;
typedef struct _KkcNumericTemplateClass KkcNumericTemplateClass;
#define _g_type_class_unref0(var) ((var == NULL) ? NULL : (var = (g_type_class_unref (var), NULL)))
typedef struct _Block7Data Block7Data;
typedef struct _Block8Data Block8Data;
typedef struct _Block9Data Block9Data;
typedef struct _Block10Data Block10Data;

#define KKC_TYPE_MAP_FILE (kkc_map_file_get_type ())
#define KKC_MAP_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_MAP_FILE, KkcMapFile))
#define KKC_MAP_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_MAP_FILE, KkcMapFileClass))
#define KKC_IS_MAP_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_MAP_FILE))
#define KKC_IS_MAP_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_MAP_FILE))
#define KKC_MAP_FILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_MAP_FILE, KkcMapFileClass))

typedef struct _KkcMapFile KkcMapFile;
typedef struct _KkcMapFileClass KkcMapFileClass;

#define KKC_TYPE_ROM_KANA_MAP_FILE (kkc_rom_kana_map_file_get_type ())
#define KKC_ROM_KANA_MAP_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_ROM_KANA_MAP_FILE, KkcRomKanaMapFile))
#define KKC_ROM_KANA_MAP_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_ROM_KANA_MAP_FILE, KkcRomKanaMapFileClass))
#define KKC_IS_ROM_KANA_MAP_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_ROM_KANA_MAP_FILE))
#define KKC_IS_ROM_KANA_MAP_FILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_ROM_KANA_MAP_FILE))
#define KKC_ROM_KANA_MAP_FILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_ROM_KANA_MAP_FILE, KkcRomKanaMapFileClass))

typedef struct _KkcRomKanaMapFile KkcRomKanaMapFile;
typedef struct _KkcRomKanaMapFileClass KkcRomKanaMapFileClass;
enum  {
	KKC_STATE_REQUEST_SELECTION_TEXT_SIGNAL,
	KKC_STATE_NUM_SIGNALS
};
static guint kkc_state_signals[KKC_STATE_NUM_SIGNALS] = {0};

#define KKC_TYPE_COMMAND_HANDLER (kkc_command_handler_get_type ())
#define KKC_COMMAND_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_COMMAND_HANDLER, KkcCommandHandler))
#define KKC_IS_COMMAND_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_COMMAND_HANDLER))
#define KKC_COMMAND_HANDLER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), KKC_TYPE_COMMAND_HANDLER, KkcCommandHandlerIface))

typedef struct _KkcCommandHandler KkcCommandHandler;
typedef struct _KkcCommandHandlerIface KkcCommandHandlerIface;
typedef gboolean (*KkcCommandCallback) (const gchar* command, KkcState* state, KkcKeyEvent* key, gpointer user_data);

#define KKC_TYPE_CALLBACK_COMMAND_HANDLER (kkc_callback_command_handler_get_type ())
#define KKC_CALLBACK_COMMAND_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_TYPE_CALLBACK_COMMAND_HANDLER, KkcCallbackCommandHandler))
#define KKC_CALLBACK_COMMAND_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_TYPE_CALLBACK_COMMAND_HANDLER, KkcCallbackCommandHandlerClass))
#define KKC_IS_CALLBACK_COMMAND_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_TYPE_CALLBACK_COMMAND_HANDLER))
#define KKC_IS_CALLBACK_COMMAND_HANDLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_TYPE_CALLBACK_COMMAND_HANDLER))
#define KKC_CALLBACK_COMMAND_HANDLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_TYPE_CALLBACK_COMMAND_HANDLER, KkcCallbackCommandHandlerClass))

typedef struct _KkcCallbackCommandHandler KkcCallbackCommandHandler;
typedef struct _KkcCallbackCommandHandlerClass KkcCallbackCommandHandlerClass;
typedef struct _KkcCallbackCommandHandlerPrivate KkcCallbackCommandHandlerPrivate;
enum  {
	KKC_CALLBACK_COMMAND_HANDLER_0_PROPERTY,
	KKC_CALLBACK_COMMAND_HANDLER_NUM_PROPERTIES
};
static GParamSpec* kkc_callback_command_handler_properties[KKC_CALLBACK_COMMAND_HANDLER_NUM_PROPERTIES];
typedef struct _KkcStateHandlerPrivate KkcStateHandlerPrivate;
enum  {
	KKC_STATE_HANDLER_0_PROPERTY,
	KKC_STATE_HANDLER_NUM_PROPERTIES
};
static GParamSpec* kkc_state_handler_properties[KKC_STATE_HANDLER_NUM_PROPERTIES];
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _KkcState {
	GObject parent_instance;
	KkcStatePrivate * priv;
	GType handler_type;
	KkcLanguageModel* model;
	KkcDecoder* decoder;
	KkcSegmentList* segments;
	KkcCandidateList* candidates;
	KkcDictionaryList* dictionaries;
	KkcRomKanaConverter* rom_kana_converter;
	KkcRomKanaCharacterList* input_characters;
	gint input_characters_cursor_pos;
	GString* selection;
	GString* output;
	gboolean quoted;
	KkcKeyEvent* this_command_key;
	KkcKeyEvent* last_command_key;
	gchar* overriding_input;
	GeeIterator* completion_iterator;
};

struct _KkcStateClass {
	GObjectClass parent_class;
};

struct _KkcStatePrivate {
	KkcInputMode _input_mode;
	gboolean segments_changed;
	gboolean latin_conversion_upper;
	GeeArrayList* completion;
	KkcRule* _typing_rule;
};

struct _Block4Data {
	int _ref_count_;
	KkcState* self;
	KkcCandidate* candidate;
};

struct _KkcPrefixEntry {
	gint offset;
	gchar** sequence;
	gint sequence_length1;
	gint _sequence_size_;
};

struct _Block5Data {
	int _ref_count_;
	KkcState* self;
	GeeList* prefixes;
};

struct _KkcTemplateIface {
	GTypeInterface parent_iface;
	gchar* (*expand) (KkcTemplate* self, const gchar* text);
	const gchar* (*get_source) (KkcTemplate* self);
	void (*set_source) (KkcTemplate* self, const gchar* value);
	gboolean (*get_okuri) (KkcTemplate* self);
	void (*set_okuri) (KkcTemplate* self, gboolean value);
};

struct _Block6Data {
	int _ref_count_;
	KkcState* self;
	gchar* normalized_input;
	gchar* _result_;
};

struct _Block7Data {
	int _ref_count_;
	KkcState* self;
	KkcTemplate* template;
	gboolean user;
};

struct _Block8Data {
	int _ref_count_;
	KkcState* self;
	gchar* input;
};

struct _Block9Data {
	int _ref_count_;
	KkcState* self;
	KkcCandidate* candidate;
};

struct _Block10Data {
	int _ref_count_;
	KkcState* self;
	gchar* input;
};

struct _KkcCommandHandlerIface {
	GTypeInterface parent_iface;
	gboolean (*call) (KkcCommandHandler* self, const gchar* command, KkcState* state, KkcKeyEvent* key);
};

struct _KkcCallbackCommandHandler {
	GObject parent_instance;
	KkcCallbackCommandHandlerPrivate * priv;
};

struct _KkcCallbackCommandHandlerClass {
	GObjectClass parent_class;
};

struct _KkcCallbackCommandHandlerPrivate {
	KkcCommandCallback cb;
	gpointer cb_target;
};

struct _KkcStateHandler {
	GObject parent_instance;
	KkcStateHandlerPrivate * priv;
};

struct _KkcStateHandlerClass {
	GObjectClass parent_class;
	gboolean (*process_key_event) (KkcStateHandler* self, KkcState* state, KkcKeyEvent* key);
};

struct _KkcStateHandlerPrivate {
	GeeMap* command_handlers;
	KkcCommandHandler* default_command_handler;
};

static gint KkcState_private_offset;
static gpointer kkc_state_parent_class = NULL;
static gint KkcCallbackCommandHandler_private_offset;
static gpointer kkc_callback_command_handler_parent_class = NULL;
static KkcCommandHandlerIface * kkc_callback_command_handler_kkc_command_handler_parent_iface = NULL;
static gint KkcStateHandler_private_offset;
static gpointer kkc_state_handler_parent_class = NULL;

VALA_EXTERN GType kkc_state_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void kkc_state_reset (KkcState* self);
VALA_EXTERN void kkc_state_finish_input_editing (KkcState* self);
VALA_EXTERN void kkc_state_convert_segment_by_kana_mode (KkcState* self,
                                             KkcKanaMode mode);
VALA_EXTERN gchar* kkc_state_convert_rom_kana_characters_by_kana_mode (KkcState* self,
                                                           KkcRomKanaCharacterList* characters,
                                                           KkcKanaMode mode);
static void kkc_state_update_latin_conversion_case (KkcState* self,
                                             KkcKanaMode mode);
VALA_EXTERN gchar* kkc_rom_kana_utils_convert_by_kana_mode (const gchar* str,
                                                KkcKanaMode mode);
VALA_EXTERN gchar* kkc_state_lookup_key (KkcState* self,
                             KkcKeyEvent* key);
VALA_EXTERN gchar* kkc_state_get_input (KkcState* self);
VALA_EXTERN KkcInputMode kkc_state_get_input_mode (KkcState* self);
VALA_EXTERN KkcState* kkc_state_new (KkcLanguageModel* model,
                         KkcDictionaryList* dictionaries);
VALA_EXTERN KkcState* kkc_state_construct (GType object_type,
                               KkcLanguageModel* model,
                               KkcDictionaryList* dictionaries);
static void kkc_state_candidates_cursor_pos_changed (KkcState* self,
                                              GObject* s,
                                              GParamSpec* p);
static void _kkc_state_candidates_cursor_pos_changed_g_object_notify (GObject* _sender,
                                                               GParamSpec* pspec,
                                                               gpointer self);
static void kkc_state_candidates_selected (KkcState* self,
                                    KkcCandidate* candidate);
static void _kkc_state_candidates_selected_kkc_candidate_list_selected (KkcCandidateList* _sender,
                                                                 KkcCandidate* candidate,
                                                                 gpointer self);
static Block4Data* block4_data_ref (Block4Data* _data4_);
static void block4_data_unref (void * _userdata_);
static KkcDictionaryCallbackReturn __lambda10_ (Block4Data* _data4_,
                                         KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn ___lambda10__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                                                  gpointer self);
VALA_EXTERN GType kkc_prefix_entry_get_type (void) G_GNUC_CONST ;
VALA_EXTERN KkcPrefixEntry* kkc_prefix_entry_dup (const KkcPrefixEntry* self);
VALA_EXTERN void kkc_prefix_entry_free (KkcPrefixEntry* self);
VALA_EXTERN void kkc_prefix_entry_copy (const KkcPrefixEntry* self,
                            KkcPrefixEntry* dest);
VALA_EXTERN void kkc_prefix_entry_destroy (KkcPrefixEntry* self);
static void kkc_state_select_sentence_for_dictionary (KkcState* self,
                                               KkcDictionary* dictionary,
                                               GeeList* prefixes);
static KkcSegment** _vala_array_dup1 (KkcSegment** self,
                               gssize length);
VALA_EXTERN void kkc_state_select_sentence (KkcState* self);
static Block5Data* block5_data_ref (Block5Data* _data5_);
static void block5_data_unref (void * _userdata_);
VALA_EXTERN GeeList* kkc_sequence_utils_enumerate_prefixes (gchar** sequence,
                                                gint sequence_length1,
                                                gint min,
                                                gint max);
static KkcDictionaryCallbackReturn __lambda16_ (Block5Data* _data5_,
                                         KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn ___lambda16__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                                                  gpointer self);
VALA_EXTERN GType kkc_state_handler_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType kkc_initial_state_handler_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void kkc_candidate_list_clear (KkcCandidateList* self);
static gchar* kkc_state_lookup_single_for_dictionary (KkcState* self,
                                               KkcDictionary* dictionary,
                                               const gchar* input);
VALA_EXTERN GType kkc_template_get_type (void) G_GNUC_CONST ;
VALA_EXTERN KkcSimpleTemplate* kkc_simple_template_new (const gchar* source);
VALA_EXTERN KkcSimpleTemplate* kkc_simple_template_construct (GType object_type,
                                                  const gchar* source);
VALA_EXTERN GType kkc_simple_template_get_type (void) G_GNUC_CONST ;
VALA_EXTERN const gchar* kkc_template_get_source (KkcTemplate* self);
VALA_EXTERN gboolean kkc_template_get_okuri (KkcTemplate* self);
VALA_EXTERN gchar* kkc_template_expand (KkcTemplate* self,
                            const gchar* text);
VALA_EXTERN KkcOkuriganaTemplate* kkc_okurigana_template_new (const gchar* source);
VALA_EXTERN KkcOkuriganaTemplate* kkc_okurigana_template_construct (GType object_type,
                                                        const gchar* source);
VALA_EXTERN GType kkc_okurigana_template_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gchar* kkc_state_lookup_single (KkcState* self,
                                const gchar* input);
static Block6Data* block6_data_ref (Block6Data* _data6_);
static void block6_data_unref (void * _userdata_);
VALA_EXTERN gchar* kkc_rom_kana_utils_normalize (const gchar* input);
static KkcDictionaryCallbackReturn __lambda17_ (Block6Data* _data6_,
                                         KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn ___lambda17__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                                                  gpointer self);
static KkcDictionaryCallbackReturn __lambda18_ (Block6Data* _data6_,
                                         KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn ___lambda18__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                                                  gpointer self);
VALA_EXTERN void kkc_state_lookup (KkcState* self,
                       KkcSegment* segment);
VALA_EXTERN gboolean kkc_candidate_list_add (KkcCandidateList* self,
                                 KkcCandidate* candidate);
static void kkc_state_lookup_template (KkcState* self,
                                KkcTemplate* template,
                                gboolean user);
VALA_EXTERN KkcNumericTemplate* kkc_numeric_template_new (const gchar* source);
VALA_EXTERN KkcNumericTemplate* kkc_numeric_template_construct (GType object_type,
                                                    const gchar* source);
VALA_EXTERN GType kkc_numeric_template_get_type (void) G_GNUC_CONST ;
static GEnumValue* _g_enum_value_dup (GEnumValue* self);
VALA_EXTERN gboolean kkc_candidate_list_contains (KkcCandidateList* self,
                                      KkcCandidate* candidate);
VALA_EXTERN gboolean kkc_candidate_list_add_all (KkcCandidateList* self,
                                     KkcCandidateList* other);
static void kkc_state_lookup_template_for_dictionary (KkcState* self,
                                               KkcDictionary* dictionary,
                                               KkcTemplate* template);
VALA_EXTERN gchar* kkc_expression_eval (const gchar* text);
static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (void * _userdata_);
static KkcDictionaryCallbackReturn __lambda12_ (Block7Data* _data7_,
                                         KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn ___lambda12__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                                                  gpointer self);
static void kkc_state_merge_possible_okurigana_segments (KkcState* self,
                                                  gint start);
VALA_EXTERN gboolean kkc_rom_kana_utils_is_hiragana (const gchar* str);
VALA_EXTERN void kkc_state_convert_sentence (KkcState* self,
                                 const gchar* input,
                                 gint* constraint,
                                 gint constraint_length1);
static gint* _vala_array_dup2 (gint* self,
                        gssize length);
static void kkc_state_apply_constraint (KkcState* self,
                                 const gchar* input);
static void kkc_state_apply_phrase (KkcState* self);
static void kkc_state_apply_constraint_for_dictionary (KkcState* self,
                                                KkcDictionary* dictionary,
                                                const gchar* input);
VALA_EXTERN gchar** kkc_utils_split_utf8 (const gchar* str,
                              gint* result_length1);
static Block8Data* block8_data_ref (Block8Data* _data8_);
static void block8_data_unref (void * _userdata_);
static KkcDictionaryCallbackReturn __lambda14_ (Block8Data* _data8_,
                                         KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn ___lambda14__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                                                  gpointer self);
static void kkc_state_apply_phrase_for_dictionary (KkcState* self,
                                            KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn __lambda15_ (KkcState* self,
                                         KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn ___lambda15__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                                                  gpointer self);
VALA_EXTERN void kkc_state_resize_segment (KkcState* self,
                               gint amount);
static void _vala_array_add6 (gint* * array,
                       gint* length,
                       gint* size,
                       gint value);
static void _vala_array_add7 (gint* * array,
                       gint* length,
                       gint* size,
                       gint value);
VALA_EXTERN void kkc_state_purge_candidate (KkcState* self,
                                KkcCandidate* candidate);
static Block9Data* block9_data_ref (Block9Data* _data9_);
static void block9_data_unref (void * _userdata_);
static KkcDictionaryCallbackReturn __lambda13_ (Block9Data* _data9_,
                                         KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn ___lambda13__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                                                  gpointer self);
VALA_EXTERN void kkc_state_completion_start (KkcState* self,
                                 const gchar* input);
static Block10Data* block10_data_ref (Block10Data* _data10_);
static void block10_data_unref (void * _userdata_);
static KkcDictionaryCallbackReturn __lambda11_ (Block10Data* _data10_,
                                         KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn ___lambda11__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                                                  gpointer self);
VALA_EXTERN void kkc_state_set_input_mode (KkcState* self,
                               KkcInputMode value);
VALA_EXTERN gint kkc_state_get_input_cursor_pos (KkcState* self);
VALA_EXTERN guint kkc_state_get_input_cursor_width (KkcState* self);
VALA_EXTERN KkcPunctuationStyle kkc_state_get_punctuation_style (KkcState* self);
VALA_EXTERN void kkc_state_set_punctuation_style (KkcState* self,
                                      KkcPunctuationStyle value);
VALA_EXTERN gboolean kkc_state_get_auto_correct (KkcState* self);
VALA_EXTERN void kkc_state_set_auto_correct (KkcState* self,
                                 gboolean value);
VALA_EXTERN KkcRule* kkc_state_get_typing_rule (KkcState* self);
VALA_EXTERN void kkc_state_set_typing_rule (KkcState* self,
                                KkcRule* value);
VALA_EXTERN GType kkc_map_file_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType kkc_rom_kana_map_file_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void kkc_rom_kana_converter_set_rule (KkcRomKanaConverter* self,
                                      KkcRomKanaMapFile* value);
static void kkc_state_finalize (GObject * obj);
static GType kkc_state_get_type_once (void);
static void _vala_kkc_state_get_property (GObject * object,
                                   guint property_id,
                                   GValue * value,
                                   GParamSpec * pspec);
static void _vala_kkc_state_set_property (GObject * object,
                                   guint property_id,
                                   const GValue * value,
                                   GParamSpec * pspec);
VALA_EXTERN GType kkc_command_handler_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gboolean kkc_command_handler_call (KkcCommandHandler* self,
                                   const gchar* command,
                                   KkcState* state,
                                   KkcKeyEvent* key);
static GType kkc_command_handler_get_type_once (void);
VALA_EXTERN GType kkc_callback_command_handler_get_type (void) G_GNUC_CONST ;
VALA_EXTERN KkcCallbackCommandHandler* kkc_callback_command_handler_new (KkcCommandCallback cb,
                                                             gpointer cb_target);
VALA_EXTERN KkcCallbackCommandHandler* kkc_callback_command_handler_construct (GType object_type,
                                                                   KkcCommandCallback cb,
                                                                   gpointer cb_target);
static gboolean kkc_callback_command_handler_real_call (KkcCommandHandler* base,
                                                 const gchar* command,
                                                 KkcState* state,
                                                 KkcKeyEvent* key);
static void kkc_callback_command_handler_finalize (GObject * obj);
static GType kkc_callback_command_handler_get_type_once (void);
VALA_EXTERN gboolean kkc_state_handler_process_key_event (KkcStateHandler* self,
                                              KkcState* state,
                                              KkcKeyEvent* key);
VALA_EXTERN void kkc_state_handler_register_command_handler (KkcStateHandler* self,
                                                 const gchar* command,
                                                 KkcCommandHandler* handler);
VALA_EXTERN void kkc_state_handler_register_command_callback (KkcStateHandler* self,
                                                  const gchar* command,
                                                  KkcCommandCallback cb,
                                                  gpointer cb_target);
VALA_EXTERN gboolean kkc_state_handler_dispatch_command (KkcStateHandler* self,
                                             KkcState* state,
                                             KkcKeyEvent* key);
static gboolean kkc_state_handler_real_process_key_event (KkcStateHandler* self,
                                                   KkcState* state,
                                                   KkcKeyEvent* key);
VALA_EXTERN KkcStateHandler* kkc_state_handler_construct (GType object_type);
static void kkc_state_handler_finalize (GObject * obj);
static GType kkc_state_handler_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
kkc_state_get_instance_private (KkcState* self)
{
	return G_STRUCT_MEMBER_P (self, KkcState_private_offset);
}

void
kkc_state_finish_input_editing (KkcState* self)
{
	KkcRomKanaConverter* _tmp0_;
	KkcRomKanaConverter* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->rom_kana_converter;
	kkc_rom_kana_converter_flush_partial (_tmp0_);
	if (self->input_characters_cursor_pos >= 0) {
		KkcRomKanaCharacterList* _tmp1_;
		KkcRomKanaConverter* _tmp2_;
		KkcRomKanaCharacterList* _tmp3_;
		KkcRomKanaCharacterList* _tmp4_;
		_tmp1_ = self->input_characters;
		_tmp2_ = self->rom_kana_converter;
		_tmp3_ = kkc_rom_kana_converter_get_produced (_tmp2_);
		_tmp4_ = _tmp3_;
		kkc_rom_kana_character_list_insert_all (_tmp1_, self->input_characters_cursor_pos, _tmp4_);
	} else {
		KkcRomKanaCharacterList* _tmp5_;
		KkcRomKanaConverter* _tmp6_;
		KkcRomKanaCharacterList* _tmp7_;
		KkcRomKanaCharacterList* _tmp8_;
		_tmp5_ = self->input_characters;
		_tmp6_ = self->rom_kana_converter;
		_tmp7_ = kkc_rom_kana_converter_get_produced (_tmp6_);
		_tmp8_ = _tmp7_;
		kkc_rom_kana_character_list_add_all (_tmp5_, _tmp8_);
	}
	_tmp9_ = self->rom_kana_converter;
	kkc_rom_kana_converter_reset (_tmp9_);
}

void
kkc_state_convert_segment_by_kana_mode (KkcState* self,
                                        KkcKanaMode mode)
{
	gint start_char_pos = 0;
	KkcSegmentList* _tmp0_;
	KkcSegmentList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gint stop_char_pos = 0;
	KkcSegmentList* _tmp4_;
	KkcSegmentList* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	KkcSegment* _tmp8_;
	KkcSegment* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp11_;
	gint _tmp12_;
	KkcRomKanaCharacterList* characters = NULL;
	KkcRomKanaCharacterList* _tmp13_;
	KkcRomKanaCharacterList* _tmp14_;
	KkcSegmentList* _tmp15_;
	KkcSegmentList* _tmp16_;
	gint _tmp17_;
	gint _tmp18_;
	KkcSegment* _tmp19_;
	KkcSegment* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->segments;
	_tmp1_ = self->segments;
	_tmp2_ = kkc_segment_list_get_cursor_pos (_tmp1_);
	_tmp3_ = _tmp2_;
	start_char_pos = kkc_segment_list_get_offset (_tmp0_, _tmp3_);
	_tmp4_ = self->segments;
	_tmp5_ = self->segments;
	_tmp6_ = kkc_segment_list_get_cursor_pos (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = kkc_segment_list_get (_tmp4_, _tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = kkc_segment_get_input (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = start_char_pos + g_utf8_strlen (_tmp11_, (gssize) -1);
	_g_object_unref0 (_tmp9_);
	stop_char_pos = _tmp12_;
	_tmp13_ = self->input_characters;
	_tmp14_ = kkc_rom_kana_character_list_slice (_tmp13_, start_char_pos, stop_char_pos);
	characters = _tmp14_;
	_tmp15_ = self->segments;
	_tmp16_ = self->segments;
	_tmp17_ = kkc_segment_list_get_cursor_pos (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = kkc_segment_list_get (_tmp15_, _tmp18_);
	_tmp20_ = _tmp19_;
	_tmp21_ = kkc_state_convert_rom_kana_characters_by_kana_mode (self, characters, mode);
	_tmp22_ = _tmp21_;
	kkc_segment_set_output (_tmp20_, _tmp22_);
	_g_free0 (_tmp22_);
	_g_object_unref0 (_tmp20_);
	_g_object_unref0 (characters);
}

gchar*
kkc_state_convert_rom_kana_characters_by_kana_mode (KkcState* self,
                                                    KkcRomKanaCharacterList* characters,
                                                    KkcKanaMode mode)
{
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (characters != NULL, NULL);
	kkc_state_update_latin_conversion_case (self, mode);
	switch (mode) {
		case KKC_KANA_MODE_HIRAGANA:
		case KKC_KANA_MODE_KATAKANA:
		case KKC_KANA_MODE_HANKAKU_KATAKANA:
		{
			gchar* _tmp0_;
			gchar* _tmp1_;
			gchar* _tmp2_;
			gchar* _tmp3_;
			_tmp0_ = kkc_rom_kana_character_list_get_output (characters);
			_tmp1_ = _tmp0_;
			_tmp2_ = kkc_rom_kana_utils_convert_by_kana_mode (_tmp1_, mode);
			_tmp3_ = _tmp2_;
			_g_free0 (_tmp1_);
			result = _tmp3_;
			return result;
		}
		case KKC_KANA_MODE_LATIN:
		case KKC_KANA_MODE_WIDE_LATIN:
		{
			gchar* _tmp4_ = NULL;
			gchar* _tmp9_;
			if (self->priv->latin_conversion_upper) {
				gchar* _tmp5_;
				gchar* _tmp6_;
				gchar* _tmp7_;
				_tmp5_ = kkc_rom_kana_character_list_get_input (characters);
				_tmp6_ = _tmp5_;
				_tmp7_ = g_utf8_strup (_tmp6_, (gssize) -1);
				_g_free0 (_tmp4_);
				_tmp4_ = _tmp7_;
				_g_free0 (_tmp6_);
			} else {
				gchar* _tmp8_;
				_tmp8_ = kkc_rom_kana_character_list_get_input (characters);
				_g_free0 (_tmp4_);
				_tmp4_ = _tmp8_;
			}
			_tmp9_ = kkc_rom_kana_utils_convert_by_kana_mode (_tmp4_, mode);
			result = _tmp9_;
			_g_free0 (_tmp4_);
			return result;
		}
		default:
		break;
	}
	g_return_val_if_reached (NULL);
}

static void
kkc_state_update_latin_conversion_case (KkcState* self,
                                        KkcKanaMode mode)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (mode == KKC_KANA_MODE_LATIN) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = mode == KKC_KANA_MODE_WIDE_LATIN;
	}
	if (_tmp0_) {
		gboolean _tmp1_ = FALSE;
		KkcKeyEvent* _tmp2_;
		_tmp2_ = self->last_command_key;
		if (_tmp2_ != NULL) {
			KkcKeyEvent* _tmp3_;
			_tmp3_ = self->this_command_key;
			_tmp1_ = _tmp3_ != NULL;
		} else {
			_tmp1_ = FALSE;
		}
		if (_tmp1_) {
			gchar* last_command = NULL;
			KkcKeyEvent* _tmp4_;
			gchar* _tmp5_;
			gchar* this_command = NULL;
			KkcKeyEvent* _tmp6_;
			gchar* _tmp7_;
			const gchar* _tmp8_;
			const gchar* _tmp9_;
			_tmp4_ = self->last_command_key;
			_tmp5_ = kkc_state_lookup_key (self, _tmp4_);
			last_command = _tmp5_;
			_tmp6_ = self->this_command_key;
			_tmp7_ = kkc_state_lookup_key (self, _tmp6_);
			this_command = _tmp7_;
			_tmp8_ = last_command;
			_tmp9_ = this_command;
			if (g_strcmp0 (_tmp8_, _tmp9_) == 0) {
				self->priv->latin_conversion_upper = !self->priv->latin_conversion_upper;
			} else {
				self->priv->latin_conversion_upper = FALSE;
			}
			_g_free0 (this_command);
			_g_free0 (last_command);
		} else {
			self->priv->latin_conversion_upper = FALSE;
		}
	}
}

gchar*
kkc_state_get_input (KkcState* self)
{
	const gchar* _tmp0_;
	GString* builder = NULL;
	GString* _tmp3_;
	gint _tmp4_ = 0;
	gint stop = 0;
	GString* _tmp15_;
	KkcRomKanaConverter* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	GString* _tmp29_;
	const gchar* _tmp30_;
	gchar* _tmp31_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->overriding_input;
	if (_tmp0_ != NULL) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = self->overriding_input;
		_tmp2_ = g_strdup (_tmp1_);
		result = _tmp2_;
		return result;
	}
	_tmp3_ = g_string_new ("");
	builder = _tmp3_;
	if (self->input_characters_cursor_pos >= 0) {
		_tmp4_ = self->input_characters_cursor_pos;
	} else {
		KkcRomKanaCharacterList* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		_tmp5_ = self->input_characters;
		_tmp6_ = kkc_rom_kana_character_list_get_size (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp4_ = _tmp7_;
	}
	stop = _tmp4_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp8_ = FALSE;
			_tmp8_ = TRUE;
			while (TRUE) {
				GString* _tmp10_;
				KkcRomKanaCharacterList* _tmp11_;
				KkcRomKanaCharacter _tmp12_ = {0};
				KkcRomKanaCharacter _tmp13_;
				const gchar* _tmp14_;
				if (!_tmp8_) {
					gint _tmp9_;
					_tmp9_ = i;
					i = _tmp9_ + 1;
				}
				_tmp8_ = FALSE;
				if (!(i < stop)) {
					break;
				}
				_tmp10_ = builder;
				_tmp11_ = self->input_characters;
				kkc_rom_kana_character_list_get (_tmp11_, i, &_tmp12_);
				_tmp13_ = _tmp12_;
				_tmp14_ = _tmp13_.output;
				g_string_append (_tmp10_, _tmp14_);
				kkc_rom_kana_character_destroy (&_tmp13_);
			}
		}
	}
	_tmp15_ = builder;
	_tmp16_ = self->rom_kana_converter;
	_tmp17_ = kkc_rom_kana_converter_get_pending_output (_tmp16_);
	_tmp18_ = _tmp17_;
	g_string_append (_tmp15_, _tmp18_);
	{
		gboolean _tmp19_ = FALSE;
		_tmp19_ = TRUE;
		while (TRUE) {
			KkcRomKanaCharacterList* _tmp21_;
			gint _tmp22_;
			gint _tmp23_;
			GString* _tmp24_;
			KkcRomKanaCharacterList* _tmp25_;
			KkcRomKanaCharacter _tmp26_ = {0};
			KkcRomKanaCharacter _tmp27_;
			const gchar* _tmp28_;
			if (!_tmp19_) {
				gint _tmp20_;
				_tmp20_ = stop;
				stop = _tmp20_ + 1;
			}
			_tmp19_ = FALSE;
			_tmp21_ = self->input_characters;
			_tmp22_ = kkc_rom_kana_character_list_get_size (_tmp21_);
			_tmp23_ = _tmp22_;
			if (!(stop < _tmp23_)) {
				break;
			}
			_tmp24_ = builder;
			_tmp25_ = self->input_characters;
			kkc_rom_kana_character_list_get (_tmp25_, stop, &_tmp26_);
			_tmp27_ = _tmp26_;
			_tmp28_ = _tmp27_.output;
			g_string_append (_tmp24_, _tmp28_);
			kkc_rom_kana_character_destroy (&_tmp27_);
		}
	}
	_tmp29_ = builder;
	_tmp30_ = _tmp29_->str;
	_tmp31_ = g_strdup (_tmp30_);
	result = _tmp31_;
	_g_string_free0 (builder);
	return result;
}

gchar*
kkc_state_lookup_key (KkcState* self,
                      KkcKeyEvent* key)
{
	KkcKeymap* keymap = NULL;
	KkcRule* _tmp0_;
	KkcInputMode _tmp1_;
	KkcInputMode _tmp2_;
	KkcKeymap* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	_tmp0_ = self->priv->_typing_rule;
	_tmp1_ = kkc_state_get_input_mode (self);
	_tmp2_ = _tmp1_;
	_tmp3_ = kkc_rule_get_keymap (_tmp0_, _tmp2_);
	keymap = _tmp3_;
	g_return_val_if_fail (keymap != NULL, NULL);
	_tmp4_ = kkc_keymap_lookup_key (keymap, key);
	result = _tmp4_;
	_g_object_unref0 (keymap);
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
_kkc_state_candidates_cursor_pos_changed_g_object_notify (GObject* _sender,
                                                          GParamSpec* pspec,
                                                          gpointer self)
{
	kkc_state_candidates_cursor_pos_changed ((KkcState*) self, _sender, pspec);
}

static void
_kkc_state_candidates_selected_kkc_candidate_list_selected (KkcCandidateList* _sender,
                                                            KkcCandidate* candidate,
                                                            gpointer self)
{
	kkc_state_candidates_selected ((KkcState*) self, candidate);
}

KkcState*
kkc_state_construct (GType object_type,
                     KkcLanguageModel* model,
                     KkcDictionaryList* dictionaries)
{
	KkcState * self = NULL;
	KkcLanguageModel* _tmp0_;
	KkcDecoder* _tmp1_;
	KkcDictionaryList* _tmp2_;
	KkcSegmentList* _tmp3_;
	KkcCandidateList* _tmp4_;
	KkcCandidateList* _tmp5_;
	KkcCandidateList* _tmp6_;
	KkcCandidateList* _tmp7_;
	KkcRomKanaConverter* _tmp8_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (model != NULL, NULL);
	g_return_val_if_fail (dictionaries != NULL, NULL);
	self = (KkcState*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (model);
	_g_object_unref0 (self->model);
	self->model = _tmp0_;
	_tmp1_ = kkc_decoder_create (model);
	_g_object_unref0 (self->decoder);
	self->decoder = _tmp1_;
	_tmp2_ = _g_object_ref0 (dictionaries);
	_g_object_unref0 (self->dictionaries);
	self->dictionaries = _tmp2_;
	_tmp3_ = kkc_segment_list_new ();
	_g_object_unref0 (self->segments);
	self->segments = _tmp3_;
	_tmp4_ = kkc_candidate_list_new ((guint) 4, (guint) 7, FALSE);
	_g_object_unref0 (self->candidates);
	self->candidates = _tmp4_;
	_tmp5_ = self->candidates;
	kkc_candidate_list_set_round (_tmp5_, TRUE);
	_tmp6_ = self->candidates;
	g_signal_connect_object ((GObject*) _tmp6_, "notify::cursor-pos", (GCallback) _kkc_state_candidates_cursor_pos_changed_g_object_notify, self, 0);
	_tmp7_ = self->candidates;
	g_signal_connect_object (_tmp7_, "selected", (GCallback) _kkc_state_candidates_selected_kkc_candidate_list_selected, self, 0);
	_tmp8_ = kkc_rom_kana_converter_new ();
	_g_object_unref0 (self->rom_kana_converter);
	self->rom_kana_converter = _tmp8_;
	{
		KkcRuleMetadata* metadata = NULL;
		KkcRuleMetadata* _tmp9_;
		KkcRule* _tmp10_ = NULL;
		KkcRule* _tmp11_;
		KkcRule* _tmp12_;
		_tmp9_ = kkc_rule_metadata_find ("default");
		metadata = _tmp9_;
		_vala_assert (metadata != NULL, "metadata != null");
		_tmp11_ = kkc_rule_new (metadata, &_inner_error0_);
		_tmp10_ = _tmp11_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (metadata);
			goto __catch0_g_error;
		}
		_tmp12_ = _tmp10_;
		_tmp10_ = NULL;
		_g_object_unref0 (self->priv->_typing_rule);
		self->priv->_typing_rule = _tmp12_;
		_g_object_unref0 (_tmp10_);
		_g_object_unref0 (metadata);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp13_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp13_ = e->message;
		g_warning ("state.vala:233: cannot load default rule: %s", _tmp13_);
		g_assert_not_reached ();
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	kkc_state_reset (self);
	return self;
}

KkcState*
kkc_state_new (KkcLanguageModel* model,
               KkcDictionaryList* dictionaries)
{
	return kkc_state_construct (KKC_TYPE_STATE, model, dictionaries);
}

static void
kkc_state_candidates_cursor_pos_changed (KkcState* self,
                                         GObject* s,
                                         GParamSpec* p)
{
	gboolean _tmp0_ = FALSE;
	KkcSegmentList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (s != NULL);
	_tmp1_ = self->segments;
	_tmp2_ = kkc_segment_list_get_cursor_pos (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ >= 0) {
		KkcCandidateList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		_tmp4_ = self->candidates;
		_tmp5_ = kkc_candidate_list_get_cursor_pos (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp0_ = _tmp6_ >= 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		KkcCandidate* candidate = NULL;
		KkcCandidateList* _tmp7_;
		KkcCandidateList* _tmp8_;
		gint _tmp9_;
		gint _tmp10_;
		KkcCandidate* _tmp11_;
		KkcSegmentList* _tmp12_;
		KkcSegmentList* _tmp13_;
		gint _tmp14_;
		gint _tmp15_;
		KkcSegment* _tmp16_;
		KkcSegment* _tmp17_;
		const gchar* _tmp18_;
		const gchar* _tmp19_;
		KkcCandidate* _tmp20_;
		const gchar* _tmp21_;
		const gchar* _tmp22_;
		gboolean _tmp23_;
		_tmp7_ = self->candidates;
		_tmp8_ = self->candidates;
		_tmp9_ = kkc_candidate_list_get_cursor_pos (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = kkc_candidate_list_get (_tmp7_, _tmp10_);
		candidate = _tmp11_;
		_tmp12_ = self->segments;
		_tmp13_ = self->segments;
		_tmp14_ = kkc_segment_list_get_cursor_pos (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = kkc_segment_list_get (_tmp12_, _tmp15_);
		_tmp17_ = _tmp16_;
		_tmp18_ = kkc_segment_get_output (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = candidate;
		_tmp21_ = kkc_candidate_get_output (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp23_ = g_strcmp0 (_tmp19_, _tmp22_) != 0;
		_g_object_unref0 (_tmp17_);
		if (_tmp23_) {
			KkcSegmentList* _tmp24_;
			KkcSegmentList* _tmp25_;
			gint _tmp26_;
			gint _tmp27_;
			KkcSegment* _tmp28_;
			KkcSegment* _tmp29_;
			KkcCandidate* _tmp30_;
			const gchar* _tmp31_;
			const gchar* _tmp32_;
			_tmp24_ = self->segments;
			_tmp25_ = self->segments;
			_tmp26_ = kkc_segment_list_get_cursor_pos (_tmp25_);
			_tmp27_ = _tmp26_;
			_tmp28_ = kkc_segment_list_get (_tmp24_, _tmp27_);
			_tmp29_ = _tmp28_;
			_tmp30_ = candidate;
			_tmp31_ = kkc_candidate_get_output (_tmp30_);
			_tmp32_ = _tmp31_;
			kkc_segment_set_output (_tmp29_, _tmp32_);
			_g_object_unref0 (_tmp29_);
			self->priv->segments_changed = TRUE;
		}
		_g_object_unref0 (candidate);
	}
}

static Block4Data*
block4_data_ref (Block4Data* _data4_)
{
	g_atomic_int_inc (&_data4_->_ref_count_);
	return _data4_;
}

static void
block4_data_unref (void * _userdata_)
{
	Block4Data* _data4_;
	_data4_ = (Block4Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data4_->_ref_count_)) {
		KkcState* self;
		self = _data4_->self;
		_g_object_unref0 (_data4_->candidate);
		_g_object_unref0 (self);
		g_slice_free (Block4Data, _data4_);
	}
}

static KkcDictionaryCallbackReturn
__lambda10_ (Block4Data* _data4_,
             KkcDictionary* dictionary)
{
	KkcState* self;
	KkcSegmentDictionary* segment_dict = NULL;
	KkcSegmentDictionary* _tmp0_;
	KkcDictionaryCallbackReturn result;
	self = _data4_->self;
	g_return_val_if_fail (dictionary != NULL, 0);
	_tmp0_ = _g_object_ref0 (KKC_IS_SEGMENT_DICTIONARY (dictionary) ? ((KkcSegmentDictionary*) dictionary) : NULL);
	segment_dict = _tmp0_;
	kkc_segment_dictionary_select_candidate (segment_dict, _data4_->candidate);
	result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
	_g_object_unref0 (segment_dict);
	return result;
}

static KkcDictionaryCallbackReturn
___lambda10__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                      gpointer self)
{
	KkcDictionaryCallbackReturn result;
	result = __lambda10_ (self, dictionary);
	return result;
}

static void
kkc_state_candidates_selected (KkcState* self,
                               KkcCandidate* candidate)
{
	Block4Data* _data4_;
	KkcCandidate* _tmp0_;
	KkcDictionaryList* _tmp1_;
	GType _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (candidate != NULL);
	_data4_ = g_slice_new0 (Block4Data);
	_data4_->_ref_count_ = 1;
	_data4_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (candidate);
	_g_object_unref0 (_data4_->candidate);
	_data4_->candidate = _tmp0_;
	_tmp1_ = self->dictionaries;
	_tmp2_ = KKC_TYPE_SEGMENT_DICTIONARY;
	kkc_dictionary_list_call (_tmp1_, &_tmp2_, ___lambda10__kkc_dictionary_list_dictionary_callback, _data4_);
	block4_data_unref (_data4_);
	_data4_ = NULL;
}

static KkcSegment**
_vala_array_dup1 (KkcSegment** self,
                  gssize length)
{
	if (length >= 0) {
		KkcSegment** result;
		gssize i;
		result = g_new0 (KkcSegment*, length + 1);
		for (i = 0; i < length; i++) {
			KkcSegment* _tmp0_;
			_tmp0_ = _g_object_ref0 (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static void
kkc_state_select_sentence_for_dictionary (KkcState* self,
                                          KkcDictionary* dictionary,
                                          GeeList* prefixes)
{
	KkcSentenceDictionary* sentence_dict = NULL;
	KkcSentenceDictionary* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dictionary != NULL);
	g_return_if_fail (prefixes != NULL);
	_tmp0_ = _g_object_ref0 (KKC_IS_SENTENCE_DICTIONARY (dictionary) ? ((KkcSentenceDictionary*) dictionary) : NULL);
	sentence_dict = _tmp0_;
	{
		GeeList* _prefix_list = NULL;
		gint _prefix_size = 0;
		GeeList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _prefix_index = 0;
		_prefix_list = prefixes;
		_tmp1_ = _prefix_list;
		_tmp2_ = gee_collection_get_size ((GeeCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_prefix_size = _tmp3_;
		_prefix_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			KkcPrefixEntry* prefix = NULL;
			GeeList* _tmp6_;
			gpointer _tmp7_;
			KkcSegment** _segments = NULL;
			KkcSegmentList* _tmp8_;
			gint _tmp9_ = 0;
			KkcSegment** _tmp10_;
			gint _segments_length1;
			gint __segments_size_;
			gint stop = 0;
			KkcPrefixEntry* _tmp11_;
			KkcPrefixEntry* _tmp12_;
			gchar** _tmp13_;
			gint _tmp13__length1;
			KkcSegment** _tmp14_;
			gint _tmp14__length1;
			KkcPrefixEntry* _tmp15_;
			KkcSegment** _tmp16_;
			gint _tmp16__length1;
			KkcSentenceDictionary* _tmp17_;
			KkcSegment** _tmp18_;
			gint _tmp18__length1;
			_prefix_index = _prefix_index + 1;
			_tmp4_ = _prefix_index;
			_tmp5_ = _prefix_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _prefix_list;
			_tmp7_ = gee_list_get (_tmp6_, _prefix_index);
			prefix = (KkcPrefixEntry*) _tmp7_;
			_tmp8_ = self->segments;
			_tmp10_ = kkc_segment_list_to_array (_tmp8_, &_tmp9_);
			_segments = _tmp10_;
			_segments_length1 = _tmp9_;
			__segments_size_ = _segments_length1;
			_tmp11_ = prefix;
			_tmp12_ = prefix;
			_tmp13_ = (*_tmp12_).sequence;
			_tmp13__length1 = (*_tmp12_).sequence_length1;
			stop = (*_tmp11_).offset + _tmp13__length1;
			_tmp14_ = _segments;
			_tmp14__length1 = _segments_length1;
			_tmp15_ = prefix;
			_tmp16_ = (_tmp14_ != NULL) ? _vala_array_dup1 (_tmp14_ + (*_tmp15_).offset, stop - (*_tmp15_).offset) : _tmp14_;
			_tmp16__length1 = stop - (*_tmp15_).offset;
			_segments = (_vala_array_free (_segments, _segments_length1, (GDestroyNotify) g_object_unref), NULL);
			_segments = _tmp16_;
			_segments_length1 = _tmp16__length1;
			__segments_size_ = _segments_length1;
			_tmp17_ = sentence_dict;
			_tmp18_ = _segments;
			_tmp18__length1 = _segments_length1;
			kkc_sentence_dictionary_select_segments (_tmp17_, _tmp18_, (gint) _tmp18__length1);
			_segments = (_vala_array_free (_segments, _segments_length1, (GDestroyNotify) g_object_unref), NULL);
			_kkc_prefix_entry_free0 (prefix);
		}
	}
	_g_object_unref0 (sentence_dict);
}

static Block5Data*
block5_data_ref (Block5Data* _data5_)
{
	g_atomic_int_inc (&_data5_->_ref_count_);
	return _data5_;
}

static void
block5_data_unref (void * _userdata_)
{
	Block5Data* _data5_;
	_data5_ = (Block5Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data5_->_ref_count_)) {
		KkcState* self;
		self = _data5_->self;
		_g_object_unref0 (_data5_->prefixes);
		_g_object_unref0 (self);
		g_slice_free (Block5Data, _data5_);
	}
}

static KkcDictionaryCallbackReturn
__lambda16_ (Block5Data* _data5_,
             KkcDictionary* dictionary)
{
	KkcState* self;
	GeeList* _tmp0_;
	KkcDictionaryCallbackReturn result;
	self = _data5_->self;
	g_return_val_if_fail (dictionary != NULL, 0);
	_tmp0_ = _data5_->prefixes;
	kkc_state_select_sentence_for_dictionary (self, dictionary, _tmp0_);
	result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
	return result;
}

static KkcDictionaryCallbackReturn
___lambda16__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                      gpointer self)
{
	KkcDictionaryCallbackReturn result;
	result = __lambda16_ (self, dictionary);
	return result;
}

void
kkc_state_select_sentence (KkcState* self)
{
	Block5Data* _data5_;
	gchar** sequence = NULL;
	KkcSegmentList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gchar** _tmp3_;
	gint sequence_length1;
	gint _sequence_size_;
	gchar** _tmp14_;
	gint _tmp14__length1;
	KkcSegmentList* _tmp15_;
	gint _tmp16_;
	gint _tmp17_;
	KkcSegmentList* _tmp18_;
	gint _tmp19_;
	gint _tmp20_;
	GeeList* _tmp21_;
	KkcDictionaryList* _tmp22_;
	GType _tmp23_;
	g_return_if_fail (self != NULL);
	_data5_ = g_slice_new0 (Block5Data);
	_data5_->_ref_count_ = 1;
	_data5_->self = g_object_ref (self);
	if (!self->priv->segments_changed) {
		block5_data_unref (_data5_);
		_data5_ = NULL;
		return;
	}
	_tmp0_ = self->segments;
	_tmp1_ = kkc_segment_list_get_size (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_new0 (gchar*, _tmp2_ + 1);
	sequence = _tmp3_;
	sequence_length1 = _tmp2_;
	_sequence_size_ = sequence_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				gchar** _tmp6_;
				gint _tmp6__length1;
				gchar** _tmp7_;
				gint _tmp7__length1;
				KkcSegmentList* _tmp8_;
				KkcSegment* _tmp9_;
				KkcSegment* _tmp10_;
				const gchar* _tmp11_;
				const gchar* _tmp12_;
				gchar* _tmp13_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				_tmp6_ = sequence;
				_tmp6__length1 = sequence_length1;
				if (!(i < _tmp6__length1)) {
					break;
				}
				_tmp7_ = sequence;
				_tmp7__length1 = sequence_length1;
				_tmp8_ = self->segments;
				_tmp9_ = kkc_segment_list_get (_tmp8_, i);
				_tmp10_ = _tmp9_;
				_tmp11_ = kkc_segment_get_input (_tmp10_);
				_tmp12_ = _tmp11_;
				_tmp13_ = g_strdup (_tmp12_);
				_g_free0 (_tmp7_[i]);
				_tmp7_[i] = _tmp13_;
				_g_object_unref0 (_tmp10_);
			}
		}
	}
	_tmp14_ = sequence;
	_tmp14__length1 = sequence_length1;
	_tmp15_ = self->segments;
	_tmp16_ = kkc_segment_list_get_size (_tmp15_);
	_tmp17_ = _tmp16_;
	_tmp18_ = self->segments;
	_tmp19_ = kkc_segment_list_get_size (_tmp18_);
	_tmp20_ = _tmp19_;
	_tmp21_ = kkc_sequence_utils_enumerate_prefixes (_tmp14_, (gint) _tmp14__length1, MIN (2, _tmp17_), MIN (5, _tmp20_));
	_data5_->prefixes = _tmp21_;
	_tmp22_ = self->dictionaries;
	_tmp23_ = KKC_TYPE_SENTENCE_DICTIONARY;
	kkc_dictionary_list_call (_tmp22_, &_tmp23_, ___lambda16__kkc_dictionary_list_dictionary_callback, _data5_);
	sequence = (_vala_array_free (sequence, sequence_length1, (GDestroyNotify) g_free), NULL);
	block5_data_unref (_data5_);
	_data5_ = NULL;
}

void
kkc_state_reset (KkcState* self)
{
	KkcRomKanaConverter* _tmp0_;
	KkcRule* _tmp1_;
	KkcKeyEventFilter* _tmp2_;
	KkcKeyEventFilter* _tmp3_;
	KkcSegmentList* _tmp4_;
	KkcCandidateList* _tmp5_;
	KkcRomKanaCharacterList* _tmp6_;
	GeeArrayList* _tmp7_;
	g_return_if_fail (self != NULL);
	self->handler_type = KKC_TYPE_INITIAL_STATE_HANDLER;
	_tmp0_ = self->rom_kana_converter;
	kkc_rom_kana_converter_reset (_tmp0_);
	_tmp1_ = self->priv->_typing_rule;
	_tmp2_ = kkc_rule_get_filter (_tmp1_);
	_tmp3_ = _tmp2_;
	kkc_key_event_filter_reset (_tmp3_);
	_tmp4_ = self->segments;
	kkc_segment_list_clear (_tmp4_);
	self->priv->segments_changed = FALSE;
	_tmp5_ = self->candidates;
	kkc_candidate_list_clear (_tmp5_);
	_tmp6_ = self->input_characters;
	kkc_rom_kana_character_list_clear (_tmp6_);
	self->input_characters_cursor_pos = -1;
	_g_free0 (self->overriding_input);
	self->overriding_input = NULL;
	_g_object_unref0 (self->completion_iterator);
	self->completion_iterator = NULL;
	_tmp7_ = self->priv->completion;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp7_);
	self->quoted = FALSE;
	self->priv->latin_conversion_upper = FALSE;
}

static gchar*
kkc_state_lookup_single_for_dictionary (KkcState* self,
                                        KkcDictionary* dictionary,
                                        const gchar* input)
{
	KkcSegmentDictionary* segment_dict = NULL;
	KkcSegmentDictionary* _tmp0_;
	KkcCandidate** _candidates = NULL;
	gint _candidates_length1 = 0;
	gint __candidates_size_ = 0;
	KkcTemplate* template = NULL;
	KkcSimpleTemplate* _tmp1_;
	KkcSegmentDictionary* _tmp2_;
	KkcTemplate* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	KkcTemplate* _tmp6_;
	gboolean _tmp7_;
	gboolean _tmp8_;
	KkcCandidate** _tmp9_ = NULL;
	gint _tmp10_ = 0;
	gboolean _tmp11_;
	KkcOkuriganaTemplate* _tmp18_;
	KkcSegmentDictionary* _tmp19_;
	KkcTemplate* _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	KkcTemplate* _tmp23_;
	gboolean _tmp24_;
	gboolean _tmp25_;
	KkcCandidate** _tmp26_ = NULL;
	gint _tmp27_ = 0;
	gboolean _tmp28_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (dictionary != NULL, NULL);
	g_return_val_if_fail (input != NULL, NULL);
	_tmp0_ = _g_object_ref0 (KKC_IS_SEGMENT_DICTIONARY (dictionary) ? ((KkcSegmentDictionary*) dictionary) : NULL);
	segment_dict = _tmp0_;
	_tmp1_ = kkc_simple_template_new (input);
	_g_object_unref0 (template);
	template = (KkcTemplate*) _tmp1_;
	_tmp2_ = segment_dict;
	_tmp3_ = template;
	_tmp4_ = kkc_template_get_source (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = template;
	_tmp7_ = kkc_template_get_okuri (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp11_ = kkc_segment_dictionary_lookup_candidates (_tmp2_, _tmp5_, _tmp8_, &_tmp9_, &_tmp10_);
	_candidates = (_vala_array_free (_candidates, _candidates_length1, (GDestroyNotify) g_object_unref), NULL);
	_candidates = _tmp9_;
	_candidates_length1 = _tmp10_;
	__candidates_size_ = _candidates_length1;
	if (_tmp11_) {
		KkcTemplate* _tmp12_;
		KkcCandidate** _tmp13_;
		gint _tmp13__length1;
		KkcCandidate* _tmp14_;
		const gchar* _tmp15_;
		const gchar* _tmp16_;
		gchar* _tmp17_;
		_tmp12_ = template;
		_tmp13_ = _candidates;
		_tmp13__length1 = _candidates_length1;
		_tmp14_ = _tmp13_[0];
		_tmp15_ = kkc_candidate_get_text (_tmp14_);
		_tmp16_ = _tmp15_;
		_tmp17_ = kkc_template_expand (_tmp12_, _tmp16_);
		result = _tmp17_;
		_g_object_unref0 (template);
		_candidates = (_vala_array_free (_candidates, _candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		_g_object_unref0 (segment_dict);
		return result;
	}
	_tmp18_ = kkc_okurigana_template_new (input);
	_g_object_unref0 (template);
	template = (KkcTemplate*) _tmp18_;
	_tmp19_ = segment_dict;
	_tmp20_ = template;
	_tmp21_ = kkc_template_get_source (_tmp20_);
	_tmp22_ = _tmp21_;
	_tmp23_ = template;
	_tmp24_ = kkc_template_get_okuri (_tmp23_);
	_tmp25_ = _tmp24_;
	_tmp28_ = kkc_segment_dictionary_lookup_candidates (_tmp19_, _tmp22_, _tmp25_, &_tmp26_, &_tmp27_);
	_candidates = (_vala_array_free (_candidates, _candidates_length1, (GDestroyNotify) g_object_unref), NULL);
	_candidates = _tmp26_;
	_candidates_length1 = _tmp27_;
	__candidates_size_ = _candidates_length1;
	if (_tmp28_) {
		KkcTemplate* _tmp29_;
		KkcCandidate** _tmp30_;
		gint _tmp30__length1;
		KkcCandidate* _tmp31_;
		const gchar* _tmp32_;
		const gchar* _tmp33_;
		gchar* _tmp34_;
		_tmp29_ = template;
		_tmp30_ = _candidates;
		_tmp30__length1 = _candidates_length1;
		_tmp31_ = _tmp30_[0];
		_tmp32_ = kkc_candidate_get_text (_tmp31_);
		_tmp33_ = _tmp32_;
		_tmp34_ = kkc_template_expand (_tmp29_, _tmp33_);
		result = _tmp34_;
		_g_object_unref0 (template);
		_candidates = (_vala_array_free (_candidates, _candidates_length1, (GDestroyNotify) g_object_unref), NULL);
		_g_object_unref0 (segment_dict);
		return result;
	}
	result = NULL;
	_g_object_unref0 (template);
	_candidates = (_vala_array_free (_candidates, _candidates_length1, (GDestroyNotify) g_object_unref), NULL);
	_g_object_unref0 (segment_dict);
	return result;
}

static Block6Data*
block6_data_ref (Block6Data* _data6_)
{
	g_atomic_int_inc (&_data6_->_ref_count_);
	return _data6_;
}

static void
block6_data_unref (void * _userdata_)
{
	Block6Data* _data6_;
	_data6_ = (Block6Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data6_->_ref_count_)) {
		KkcState* self;
		self = _data6_->self;
		_g_free0 (_data6_->_result_);
		_g_free0 (_data6_->normalized_input);
		_g_object_unref0 (self);
		g_slice_free (Block6Data, _data6_);
	}
}

static KkcDictionaryCallbackReturn
__lambda17_ (Block6Data* _data6_,
             KkcDictionary* dictionary)
{
	KkcState* self;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	KkcDictionaryCallbackReturn result;
	self = _data6_->self;
	g_return_val_if_fail (dictionary != NULL, 0);
	if (!KKC_IS_USER_DICTIONARY (dictionary)) {
		result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
		return result;
	}
	_tmp0_ = _data6_->normalized_input;
	_tmp1_ = kkc_state_lookup_single_for_dictionary (self, dictionary, _tmp0_);
	_g_free0 (_data6_->_result_);
	_data6_->_result_ = _tmp1_;
	_tmp2_ = _data6_->_result_;
	if (_tmp2_ != NULL) {
		result = KKC_DICTIONARY_CALLBACK_RETURN_REMOVE;
		return result;
	}
	result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
	return result;
}

static KkcDictionaryCallbackReturn
___lambda17__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                      gpointer self)
{
	KkcDictionaryCallbackReturn result;
	result = __lambda17_ (self, dictionary);
	return result;
}

static KkcDictionaryCallbackReturn
__lambda18_ (Block6Data* _data6_,
             KkcDictionary* dictionary)
{
	KkcState* self;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	KkcDictionaryCallbackReturn result;
	self = _data6_->self;
	g_return_val_if_fail (dictionary != NULL, 0);
	_tmp0_ = _data6_->normalized_input;
	_tmp1_ = kkc_state_lookup_single_for_dictionary (self, dictionary, _tmp0_);
	_g_free0 (_data6_->_result_);
	_data6_->_result_ = _tmp1_;
	_tmp2_ = _data6_->_result_;
	if (_tmp2_ != NULL) {
		result = KKC_DICTIONARY_CALLBACK_RETURN_REMOVE;
		return result;
	}
	result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
	return result;
}

static KkcDictionaryCallbackReturn
___lambda18__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                      gpointer self)
{
	KkcDictionaryCallbackReturn result;
	result = __lambda18_ (self, dictionary);
	return result;
}

gchar*
kkc_state_lookup_single (KkcState* self,
                         const gchar* input)
{
	Block6Data* _data6_;
	gchar* _tmp0_;
	KkcDictionaryList* _tmp1_;
	GType _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp6_;
	KkcDictionaryList* _tmp25_;
	GType _tmp26_;
	const gchar* _tmp27_;
	gchar* _tmp28_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (input != NULL, NULL);
	_data6_ = g_slice_new0 (Block6Data);
	_data6_->_ref_count_ = 1;
	_data6_->self = g_object_ref (self);
	_tmp0_ = kkc_rom_kana_utils_normalize (input);
	_data6_->normalized_input = _tmp0_;
	_data6_->_result_ = NULL;
	_tmp1_ = self->dictionaries;
	_tmp2_ = KKC_TYPE_SEGMENT_DICTIONARY;
	kkc_dictionary_list_call (_tmp1_, &_tmp2_, ___lambda17__kkc_dictionary_list_dictionary_callback, _data6_);
	_tmp3_ = _data6_->_result_;
	if (_tmp3_ != NULL) {
		const gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = _data6_->_result_;
		_tmp5_ = g_strdup (_tmp4_);
		result = _tmp5_;
		block6_data_unref (_data6_);
		_data6_ = NULL;
		return result;
	}
	_tmp6_ = _data6_->normalized_input;
	if (g_utf8_strlen (_tmp6_, (gssize) -1) > 1) {
		GeeCollection* entries = NULL;
		KkcLanguageModel* _tmp7_;
		const gchar* _tmp8_;
		GeeCollection* _tmp9_;
		_tmp7_ = self->model;
		_tmp8_ = _data6_->normalized_input;
		_tmp9_ = kkc_language_model_unigram_entries (_tmp7_, _tmp8_);
		entries = _tmp9_;
		{
			GeeIterator* _entry_it = NULL;
			GeeCollection* _tmp10_;
			GeeIterator* _tmp11_;
			_tmp10_ = entries;
			_tmp11_ = gee_iterable_iterator ((GeeIterable*) _tmp10_);
			_entry_it = _tmp11_;
			while (TRUE) {
				GeeIterator* _tmp12_;
				KkcLanguageModelEntry* entry = NULL;
				GeeIterator* _tmp13_;
				gpointer _tmp14_;
				gboolean _tmp15_ = FALSE;
				KkcLanguageModelEntry* _tmp16_;
				const gchar* _tmp17_;
				const gchar* _tmp18_;
				_tmp12_ = _entry_it;
				if (!gee_iterator_next (_tmp12_)) {
					break;
				}
				_tmp13_ = _entry_it;
				_tmp14_ = gee_iterator_get (_tmp13_);
				entry = (KkcLanguageModelEntry*) _tmp14_;
				_tmp16_ = entry;
				_tmp17_ = (*_tmp16_).output;
				_tmp18_ = _data6_->normalized_input;
				if (g_strcmp0 (_tmp17_, _tmp18_) != 0) {
					KkcLanguageModel* _tmp19_;
					KkcLanguageModelEntry* _tmp20_;
					KkcLanguageModelEntry _tmp21_;
					_tmp19_ = self->model;
					_tmp20_ = entry;
					_tmp21_ = *_tmp20_;
					_tmp15_ = kkc_unigram_language_model_unigram_cost (G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, KKC_TYPE_UNIGRAM_LANGUAGE_MODEL, KkcUnigramLanguageModel), &_tmp21_) > KKC_MIN_UNIGRAM_COST;
				} else {
					_tmp15_ = FALSE;
				}
				if (_tmp15_) {
					KkcLanguageModelEntry* _tmp22_;
					const gchar* _tmp23_;
					gchar* _tmp24_;
					_tmp22_ = entry;
					_tmp23_ = (*_tmp22_).output;
					_tmp24_ = g_strdup (_tmp23_);
					result = _tmp24_;
					_kkc_language_model_entry_free0 (entry);
					_g_object_unref0 (_entry_it);
					_g_object_unref0 (entries);
					block6_data_unref (_data6_);
					_data6_ = NULL;
					return result;
				}
				_kkc_language_model_entry_free0 (entry);
			}
			_g_object_unref0 (_entry_it);
		}
		_g_object_unref0 (entries);
	}
	_tmp25_ = self->dictionaries;
	_tmp26_ = KKC_TYPE_SEGMENT_DICTIONARY;
	kkc_dictionary_list_call (_tmp25_, &_tmp26_, ___lambda18__kkc_dictionary_list_dictionary_callback, _data6_);
	_tmp27_ = _data6_->_result_;
	_tmp28_ = g_strdup (_tmp27_);
	result = _tmp28_;
	block6_data_unref (_data6_);
	_data6_ = NULL;
	return result;
}

static GEnumValue*
_g_enum_value_dup (GEnumValue* self)
{
	GEnumValue* dup;
	dup = g_new0 (GEnumValue, 1);
	memcpy (dup, self, sizeof (GEnumValue));
	return dup;
}

static gpointer
__g_enum_value_dup0 (gpointer self)
{
	return self ? _g_enum_value_dup (self) : NULL;
}

void
kkc_state_lookup (KkcState* self,
                  KkcSegment* segment)
{
	KkcCandidateList* _tmp0_;
	gchar* normalized_input = NULL;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	KkcCandidate* original = NULL;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	KkcCandidate* _tmp7_;
	KkcCandidateList* _tmp8_;
	KkcCandidate* _tmp9_;
	const gchar* _tmp10_;
	KkcNumericTemplate* _tmp11_;
	KkcNumericTemplate* _tmp12_;
	const gchar* _tmp13_;
	KkcSimpleTemplate* _tmp14_;
	KkcSimpleTemplate* _tmp15_;
	const gchar* _tmp16_;
	KkcOkuriganaTemplate* _tmp17_;
	KkcOkuriganaTemplate* _tmp18_;
	const gchar* _tmp19_;
	const gchar* _tmp37_;
	KkcNumericTemplate* _tmp38_;
	KkcNumericTemplate* _tmp39_;
	const gchar* _tmp40_;
	KkcSimpleTemplate* _tmp41_;
	KkcSimpleTemplate* _tmp42_;
	const gchar* _tmp43_;
	KkcOkuriganaTemplate* _tmp44_;
	KkcOkuriganaTemplate* _tmp45_;
	KkcCandidateList* kana_candidates = NULL;
	KkcCandidateList* _tmp46_;
	GEnumClass* enum_class = NULL;
	GTypeClass* _tmp47_;
	KkcSegment** _segments = NULL;
	KkcDecoder* _tmp67_;
	const gchar* _tmp68_;
	gint* _tmp69_;
	gint* _tmp70_;
	gint _tmp70__length1;
	gint _tmp71_ = 0;
	KkcSegment** _tmp72_;
	KkcSegment** _tmp73_;
	gint _tmp73__length1;
	gint _segments_length1;
	gint __segments_size_;
	KkcSegment** _tmp74_;
	gint _tmp74__length1;
	KkcCandidateList* _tmp93_;
	KkcCandidateList* _tmp94_;
	KkcCandidateList* _tmp95_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (segment != NULL);
	_tmp0_ = self->candidates;
	kkc_candidate_list_clear (_tmp0_);
	_tmp1_ = kkc_segment_get_input (segment);
	_tmp2_ = _tmp1_;
	_tmp3_ = kkc_rom_kana_utils_normalize (_tmp2_);
	normalized_input = _tmp3_;
	_tmp4_ = normalized_input;
	_tmp5_ = kkc_segment_get_output (segment);
	_tmp6_ = _tmp5_;
	_tmp7_ = kkc_candidate_new (_tmp4_, FALSE, _tmp6_, NULL, NULL);
	original = _tmp7_;
	_tmp8_ = self->candidates;
	_tmp9_ = original;
	kkc_candidate_list_add (_tmp8_, _tmp9_);
	_tmp10_ = normalized_input;
	_tmp11_ = kkc_numeric_template_new (_tmp10_);
	_tmp12_ = _tmp11_;
	kkc_state_lookup_template (self, (KkcTemplate*) _tmp12_, TRUE);
	_g_object_unref0 (_tmp12_);
	_tmp13_ = normalized_input;
	_tmp14_ = kkc_simple_template_new (_tmp13_);
	_tmp15_ = _tmp14_;
	kkc_state_lookup_template (self, (KkcTemplate*) _tmp15_, TRUE);
	_g_object_unref0 (_tmp15_);
	_tmp16_ = normalized_input;
	_tmp17_ = kkc_okurigana_template_new (_tmp16_);
	_tmp18_ = _tmp17_;
	kkc_state_lookup_template (self, (KkcTemplate*) _tmp18_, TRUE);
	_g_object_unref0 (_tmp18_);
	_tmp19_ = normalized_input;
	if (g_utf8_strlen (_tmp19_, (gssize) -1) > 1) {
		GeeCollection* entries = NULL;
		KkcLanguageModel* _tmp20_;
		const gchar* _tmp21_;
		GeeCollection* _tmp22_;
		_tmp20_ = self->model;
		_tmp21_ = normalized_input;
		_tmp22_ = kkc_language_model_unigram_entries (_tmp20_, _tmp21_);
		entries = _tmp22_;
		{
			GeeIterator* _entry_it = NULL;
			GeeCollection* _tmp23_;
			GeeIterator* _tmp24_;
			_tmp23_ = entries;
			_tmp24_ = gee_iterable_iterator ((GeeIterable*) _tmp23_);
			_entry_it = _tmp24_;
			while (TRUE) {
				GeeIterator* _tmp25_;
				KkcLanguageModelEntry* entry = NULL;
				GeeIterator* _tmp26_;
				gpointer _tmp27_;
				KkcLanguageModel* _tmp28_;
				KkcLanguageModelEntry* _tmp29_;
				KkcLanguageModelEntry _tmp30_;
				_tmp25_ = _entry_it;
				if (!gee_iterator_next (_tmp25_)) {
					break;
				}
				_tmp26_ = _entry_it;
				_tmp27_ = gee_iterator_get (_tmp26_);
				entry = (KkcLanguageModelEntry*) _tmp27_;
				_tmp28_ = self->model;
				_tmp29_ = entry;
				_tmp30_ = *_tmp29_;
				if (kkc_unigram_language_model_unigram_cost (G_TYPE_CHECK_INSTANCE_CAST (_tmp28_, KKC_TYPE_UNIGRAM_LANGUAGE_MODEL, KkcUnigramLanguageModel), &_tmp30_) > KKC_MIN_UNIGRAM_COST) {
					KkcCandidate* unigram = NULL;
					const gchar* _tmp31_;
					KkcLanguageModelEntry* _tmp32_;
					const gchar* _tmp33_;
					KkcCandidate* _tmp34_;
					KkcCandidateList* _tmp35_;
					KkcCandidate* _tmp36_;
					_tmp31_ = normalized_input;
					_tmp32_ = entry;
					_tmp33_ = (*_tmp32_).output;
					_tmp34_ = kkc_candidate_new (_tmp31_, FALSE, _tmp33_, NULL, NULL);
					unigram = _tmp34_;
					_tmp35_ = self->candidates;
					_tmp36_ = unigram;
					kkc_candidate_list_add (_tmp35_, _tmp36_);
					_g_object_unref0 (unigram);
					_kkc_language_model_entry_free0 (entry);
					break;
				}
				_kkc_language_model_entry_free0 (entry);
			}
			_g_object_unref0 (_entry_it);
		}
		_g_object_unref0 (entries);
	}
	_tmp37_ = normalized_input;
	_tmp38_ = kkc_numeric_template_new (_tmp37_);
	_tmp39_ = _tmp38_;
	kkc_state_lookup_template (self, (KkcTemplate*) _tmp39_, FALSE);
	_g_object_unref0 (_tmp39_);
	_tmp40_ = normalized_input;
	_tmp41_ = kkc_simple_template_new (_tmp40_);
	_tmp42_ = _tmp41_;
	kkc_state_lookup_template (self, (KkcTemplate*) _tmp42_, FALSE);
	_g_object_unref0 (_tmp42_);
	_tmp43_ = normalized_input;
	_tmp44_ = kkc_okurigana_template_new (_tmp43_);
	_tmp45_ = _tmp44_;
	kkc_state_lookup_template (self, (KkcTemplate*) _tmp45_, FALSE);
	_g_object_unref0 (_tmp45_);
	_tmp46_ = kkc_candidate_list_new ((guint) 4, (guint) 7, FALSE);
	kana_candidates = _tmp46_;
	_tmp47_ = g_type_class_ref (KKC_TYPE_KANA_MODE);
	enum_class = (GEnumClass*) _tmp47_;
	{
		gint i = 0;
		GEnumClass* _tmp48_;
		_tmp48_ = enum_class;
		i = _tmp48_->minimum;
		{
			gboolean _tmp49_ = FALSE;
			_tmp49_ = TRUE;
			while (TRUE) {
				GEnumClass* _tmp51_;
				GEnumValue* enum_value = NULL;
				GEnumClass* _tmp52_;
				GEnumValue* _tmp53_;
				GEnumValue* _tmp54_;
				if (!_tmp49_) {
					gint _tmp50_;
					_tmp50_ = i;
					i = _tmp50_ + 1;
				}
				_tmp49_ = FALSE;
				_tmp51_ = enum_class;
				if (!(i <= _tmp51_->maximum)) {
					break;
				}
				_tmp52_ = enum_class;
				_tmp53_ = __g_enum_value_dup0 (g_enum_get_value (_tmp52_, i));
				enum_value = _tmp53_;
				_tmp54_ = enum_value;
				if (_tmp54_ != NULL) {
					gchar* output = NULL;
					const gchar* _tmp55_;
					GEnumValue* _tmp56_;
					gchar* _tmp57_;
					const gchar* _tmp58_;
					KkcCandidate* _tmp59_;
					const gchar* _tmp60_;
					const gchar* _tmp61_;
					_tmp55_ = normalized_input;
					_tmp56_ = enum_value;
					_tmp57_ = kkc_rom_kana_utils_convert_by_kana_mode (_tmp55_, (KkcKanaMode) (*_tmp56_).value);
					output = _tmp57_;
					_tmp58_ = output;
					_tmp59_ = original;
					_tmp60_ = kkc_candidate_get_output (_tmp59_);
					_tmp61_ = _tmp60_;
					if (g_strcmp0 (_tmp58_, _tmp61_) != 0) {
						KkcCandidate* candidate = NULL;
						const gchar* _tmp62_;
						const gchar* _tmp63_;
						KkcCandidate* _tmp64_;
						KkcCandidateList* _tmp65_;
						KkcCandidate* _tmp66_;
						_tmp62_ = normalized_input;
						_tmp63_ = output;
						_tmp64_ = kkc_candidate_new (_tmp62_, FALSE, _tmp63_, NULL, NULL);
						candidate = _tmp64_;
						_tmp65_ = kana_candidates;
						_tmp66_ = candidate;
						kkc_candidate_list_add (_tmp65_, _tmp66_);
						_g_object_unref0 (candidate);
					}
					_g_free0 (output);
				}
				_g_free0 (enum_value);
			}
		}
	}
	_tmp67_ = self->decoder;
	_tmp68_ = normalized_input;
	_tmp69_ = g_new0 (gint, 0);
	_tmp70_ = _tmp69_;
	_tmp70__length1 = 0;
	_tmp72_ = kkc_decoder_decode_with_costs (_tmp67_, _tmp68_, KKC_DECODER_NBEST, _tmp70_, (gint) 0, KKC_DECODER_MAX_DISTANCE, KKC_DECODER_MIN_PATH_COST, &_tmp71_);
	_tmp73_ = _tmp72_;
	_tmp73__length1 = _tmp71_;
	_tmp70_ = (g_free (_tmp70_), NULL);
	_segments = _tmp73_;
	_segments_length1 = _tmp73__length1;
	__segments_size_ = _segments_length1;
	_tmp74_ = _segments;
	_tmp74__length1 = _segments_length1;
	{
		KkcSegment** _segment_collection = NULL;
		gint _segment_collection_length1 = 0;
		gint __segment_collection_size_ = 0;
		gint _segment_it = 0;
		_segment_collection = _tmp74_;
		_segment_collection_length1 = _tmp74__length1;
		for (_segment_it = 0; _segment_it < _segment_collection_length1; _segment_it = _segment_it + 1) {
			KkcSegment* _tmp75_;
			KkcSegment* _segment = NULL;
			_tmp75_ = _g_object_ref0 (_segment_collection[_segment_it]);
			_segment = _tmp75_;
			{
				GString* builder = NULL;
				GString* _tmp76_;
				KkcCandidate* sentence = NULL;
				const gchar* _tmp85_;
				GString* _tmp86_;
				const gchar* _tmp87_;
				KkcCandidate* _tmp88_;
				KkcCandidateList* _tmp89_;
				KkcCandidate* _tmp90_;
				_tmp76_ = g_string_new ("");
				builder = _tmp76_;
				while (TRUE) {
					KkcSegment* _tmp77_;
					GString* _tmp78_;
					KkcSegment* _tmp79_;
					const gchar* _tmp80_;
					const gchar* _tmp81_;
					KkcSegment* _tmp82_;
					KkcSegment* _tmp83_;
					KkcSegment* _tmp84_;
					_tmp77_ = _segment;
					if (!(_tmp77_ != NULL)) {
						break;
					}
					_tmp78_ = builder;
					_tmp79_ = _segment;
					_tmp80_ = kkc_segment_get_output (_tmp79_);
					_tmp81_ = _tmp80_;
					g_string_append (_tmp78_, _tmp81_);
					_tmp82_ = _segment;
					_tmp83_ = _tmp82_->next;
					_tmp84_ = _g_object_ref0 (_tmp83_);
					_g_object_unref0 (_segment);
					_segment = _tmp84_;
				}
				_tmp85_ = normalized_input;
				_tmp86_ = builder;
				_tmp87_ = _tmp86_->str;
				_tmp88_ = kkc_candidate_new (_tmp85_, FALSE, _tmp87_, NULL, NULL);
				sentence = _tmp88_;
				_tmp89_ = kana_candidates;
				_tmp90_ = sentence;
				if (!kkc_candidate_list_contains (_tmp89_, _tmp90_)) {
					KkcCandidateList* _tmp91_;
					KkcCandidate* _tmp92_;
					_tmp91_ = self->candidates;
					_tmp92_ = sentence;
					kkc_candidate_list_add (_tmp91_, _tmp92_);
				}
				_g_object_unref0 (sentence);
				_g_string_free0 (builder);
				_g_object_unref0 (_segment);
			}
		}
	}
	_tmp93_ = self->candidates;
	_tmp94_ = kana_candidates;
	kkc_candidate_list_add_all (_tmp93_, _tmp94_);
	_tmp95_ = self->candidates;
	g_signal_emit_by_name (_tmp95_, "populated");
	_segments = (_vala_array_free (_segments, _segments_length1, (GDestroyNotify) g_object_unref), NULL);
	_g_type_class_unref0 (enum_class);
	_g_object_unref0 (kana_candidates);
	_g_object_unref0 (original);
	_g_free0 (normalized_input);
}

static void
kkc_state_lookup_template_for_dictionary (KkcState* self,
                                          KkcDictionary* dictionary,
                                          KkcTemplate* template)
{
	KkcSegmentDictionary* segment_dict = NULL;
	KkcSegmentDictionary* _tmp0_;
	KkcCandidate** _candidates = NULL;
	gint _candidates_length1 = 0;
	gint __candidates_size_ = 0;
	KkcSegmentDictionary* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	KkcCandidate** _tmp6_ = NULL;
	gint _tmp7_ = 0;
	gboolean _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dictionary != NULL);
	g_return_if_fail (template != NULL);
	_tmp0_ = _g_object_ref0 (KKC_IS_SEGMENT_DICTIONARY (dictionary) ? ((KkcSegmentDictionary*) dictionary) : NULL);
	segment_dict = _tmp0_;
	_tmp1_ = segment_dict;
	_tmp2_ = kkc_template_get_source (template);
	_tmp3_ = _tmp2_;
	_tmp4_ = kkc_template_get_okuri (template);
	_tmp5_ = _tmp4_;
	_tmp8_ = kkc_segment_dictionary_lookup_candidates (_tmp1_, _tmp3_, _tmp5_, &_tmp6_, &_tmp7_);
	_candidates = (_vala_array_free (_candidates, _candidates_length1, (GDestroyNotify) g_object_unref), NULL);
	_candidates = _tmp6_;
	_candidates_length1 = _tmp7_;
	__candidates_size_ = _candidates_length1;
	if (_tmp8_) {
		KkcCandidate** _tmp9_;
		gint _tmp9__length1;
		_tmp9_ = _candidates;
		_tmp9__length1 = _candidates_length1;
		{
			KkcCandidate** candidate_collection = NULL;
			gint candidate_collection_length1 = 0;
			gint _candidate_collection_size_ = 0;
			gint candidate_it = 0;
			candidate_collection = _tmp9_;
			candidate_collection_length1 = _tmp9__length1;
			for (candidate_it = 0; candidate_it < candidate_collection_length1; candidate_it = candidate_it + 1) {
				KkcCandidate* _tmp10_;
				KkcCandidate* candidate = NULL;
				_tmp10_ = _g_object_ref0 (candidate_collection[candidate_it]);
				candidate = _tmp10_;
				{
					gchar* text = NULL;
					KkcCandidate* _tmp11_;
					const gchar* _tmp12_;
					const gchar* _tmp13_;
					gchar* _tmp14_;
					KkcCandidate* _tmp15_;
					const gchar* _tmp16_;
					gchar* _tmp17_;
					gchar* _tmp18_;
					KkcCandidate* _tmp19_;
					const gchar* _tmp20_;
					const gchar* _tmp21_;
					KkcCandidateList* _tmp28_;
					KkcCandidate* _tmp29_;
					_tmp11_ = candidate;
					_tmp12_ = kkc_candidate_get_text (_tmp11_);
					_tmp13_ = _tmp12_;
					_tmp14_ = kkc_expression_eval (_tmp13_);
					text = _tmp14_;
					_tmp15_ = candidate;
					_tmp16_ = text;
					_tmp17_ = kkc_template_expand (template, _tmp16_);
					_tmp18_ = _tmp17_;
					kkc_candidate_set_output (_tmp15_, _tmp18_);
					_g_free0 (_tmp18_);
					_tmp19_ = candidate;
					_tmp20_ = kkc_candidate_get_annotation (_tmp19_);
					_tmp21_ = _tmp20_;
					if (_tmp21_ != NULL) {
						KkcCandidate* _tmp22_;
						KkcCandidate* _tmp23_;
						const gchar* _tmp24_;
						const gchar* _tmp25_;
						gchar* _tmp26_;
						gchar* _tmp27_;
						_tmp22_ = candidate;
						_tmp23_ = candidate;
						_tmp24_ = kkc_candidate_get_annotation (_tmp23_);
						_tmp25_ = _tmp24_;
						_tmp26_ = kkc_expression_eval (_tmp25_);
						_tmp27_ = _tmp26_;
						kkc_candidate_set_annotation (_tmp22_, _tmp27_);
						_g_free0 (_tmp27_);
					}
					_tmp28_ = self->candidates;
					_tmp29_ = candidate;
					kkc_candidate_list_add (_tmp28_, _tmp29_);
					_g_free0 (text);
					_g_object_unref0 (candidate);
				}
			}
		}
	}
	_candidates = (_vala_array_free (_candidates, _candidates_length1, (GDestroyNotify) g_object_unref), NULL);
	_g_object_unref0 (segment_dict);
}

static Block7Data*
block7_data_ref (Block7Data* _data7_)
{
	g_atomic_int_inc (&_data7_->_ref_count_);
	return _data7_;
}

static void
block7_data_unref (void * _userdata_)
{
	Block7Data* _data7_;
	_data7_ = (Block7Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		KkcState* self;
		self = _data7_->self;
		_g_object_unref0 (_data7_->template);
		_g_object_unref0 (self);
		g_slice_free (Block7Data, _data7_);
	}
}

static KkcDictionaryCallbackReturn
__lambda12_ (Block7Data* _data7_,
             KkcDictionary* dictionary)
{
	KkcState* self;
	gboolean _tmp0_ = FALSE;
	KkcDictionaryCallbackReturn result;
	self = _data7_->self;
	g_return_val_if_fail (dictionary != NULL, 0);
	if (_data7_->user) {
		_tmp0_ = !KKC_IS_USER_DICTIONARY (dictionary);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
		return result;
	}
	kkc_state_lookup_template_for_dictionary (self, dictionary, _data7_->template);
	result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
	return result;
}

static KkcDictionaryCallbackReturn
___lambda12__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                      gpointer self)
{
	KkcDictionaryCallbackReturn result;
	result = __lambda12_ (self, dictionary);
	return result;
}

static void
kkc_state_lookup_template (KkcState* self,
                           KkcTemplate* template,
                           gboolean user)
{
	Block7Data* _data7_;
	KkcTemplate* _tmp0_;
	KkcDictionaryList* _tmp1_;
	GType _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (template != NULL);
	_data7_ = g_slice_new0 (Block7Data);
	_data7_->_ref_count_ = 1;
	_data7_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (template);
	_g_object_unref0 (_data7_->template);
	_data7_->template = _tmp0_;
	_data7_->user = user;
	_tmp1_ = self->dictionaries;
	_tmp2_ = KKC_TYPE_SEGMENT_DICTIONARY;
	kkc_dictionary_list_call (_tmp1_, &_tmp2_, ___lambda12__kkc_dictionary_list_dictionary_callback, _data7_);
	block7_data_unref (_data7_);
	_data7_ = NULL;
}

static void
kkc_state_merge_possible_okurigana_segments (KkcState* self,
                                             gint start)
{
	GeeArrayList* _segments = NULL;
	GeeArrayList* _tmp0_;
	KkcSegmentList* _tmp11_;
	gint index = 0;
	gint offset = 0;
	KkcSegment* previous = NULL;
	KkcSegment* _tmp67_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gee_array_list_new (KKC_TYPE_SEGMENT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_segments = _tmp0_;
	{
		KkcSegmentList* _segment_list = NULL;
		KkcSegmentList* _tmp1_;
		gint _segment_size = 0;
		KkcSegmentList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _segment_index = 0;
		_tmp1_ = self->segments;
		_segment_list = _tmp1_;
		_tmp2_ = _segment_list;
		_tmp3_ = kkc_segment_list_get_size (_tmp2_);
		_tmp4_ = _tmp3_;
		_segment_size = _tmp4_;
		_segment_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			KkcSegment* segment = NULL;
			KkcSegmentList* _tmp7_;
			KkcSegment* _tmp8_;
			GeeArrayList* _tmp9_;
			KkcSegment* _tmp10_;
			_segment_index = _segment_index + 1;
			_tmp5_ = _segment_index;
			_tmp6_ = _segment_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _segment_list;
			_tmp8_ = kkc_segment_list_get (_tmp7_, _segment_index);
			segment = _tmp8_;
			_tmp9_ = _segments;
			_tmp10_ = segment;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp9_, _tmp10_);
			_g_object_unref0 (segment);
		}
	}
	_tmp11_ = self->segments;
	kkc_segment_list_clear (_tmp11_);
	index = 0;
	offset = 0;
	{
		gboolean _tmp12_ = FALSE;
		_tmp12_ = TRUE;
		while (TRUE) {
			gboolean _tmp14_ = FALSE;
			GeeArrayList* _tmp15_;
			gint _tmp16_;
			gint _tmp17_;
			GeeArrayList* _tmp18_;
			gpointer _tmp19_;
			KkcSegment* _tmp20_;
			const gchar* _tmp21_;
			const gchar* _tmp22_;
			KkcSegmentList* _tmp23_;
			GeeArrayList* _tmp24_;
			gpointer _tmp25_;
			KkcSegment* _tmp26_;
			if (!_tmp12_) {
				gint _tmp13_;
				_tmp13_ = index;
				index = _tmp13_ + 1;
			}
			_tmp12_ = FALSE;
			_tmp15_ = _segments;
			_tmp16_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp15_);
			_tmp17_ = _tmp16_;
			if (index < _tmp17_) {
				_tmp14_ = offset < start;
			} else {
				_tmp14_ = FALSE;
			}
			if (!_tmp14_) {
				break;
			}
			_tmp18_ = _segments;
			_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp18_, index);
			_tmp20_ = (KkcSegment*) _tmp19_;
			_tmp21_ = kkc_segment_get_output (_tmp20_);
			_tmp22_ = _tmp21_;
			offset += g_utf8_strlen (_tmp22_, (gssize) -1);
			_g_object_unref0 (_tmp20_);
			_tmp23_ = self->segments;
			_tmp24_ = _segments;
			_tmp25_ = gee_abstract_list_get ((GeeAbstractList*) _tmp24_, index);
			_tmp26_ = (KkcSegment*) _tmp25_;
			kkc_segment_list_add (_tmp23_, _tmp26_);
			_g_object_unref0 (_tmp26_);
		}
	}
	previous = NULL;
	{
		gboolean _tmp27_ = FALSE;
		_tmp27_ = TRUE;
		while (TRUE) {
			GeeArrayList* _tmp29_;
			gint _tmp30_;
			gint _tmp31_;
			KkcSegment* _tmp32_;
			if (!_tmp27_) {
				gint _tmp28_;
				_tmp28_ = index;
				index = _tmp28_ + 1;
			}
			_tmp27_ = FALSE;
			_tmp29_ = _segments;
			_tmp30_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp29_);
			_tmp31_ = _tmp30_;
			if (!(index < _tmp31_)) {
				break;
			}
			_tmp32_ = previous;
			if (_tmp32_ != NULL) {
				GeeArrayList* _tmp33_;
				gpointer _tmp34_;
				KkcSegment* _tmp35_;
				const gchar* _tmp36_;
				const gchar* _tmp37_;
				gboolean _tmp38_;
				_tmp33_ = _segments;
				_tmp34_ = gee_abstract_list_get ((GeeAbstractList*) _tmp33_, index);
				_tmp35_ = (KkcSegment*) _tmp34_;
				_tmp36_ = kkc_segment_get_output (_tmp35_);
				_tmp37_ = _tmp36_;
				_tmp38_ = kkc_rom_kana_utils_is_hiragana (_tmp37_);
				_g_object_unref0 (_tmp35_);
				if (_tmp38_) {
					KkcSegment* _tmp39_;
					KkcSegment* _tmp40_;
					const gchar* _tmp41_;
					const gchar* _tmp42_;
					GeeArrayList* _tmp43_;
					gpointer _tmp44_;
					KkcSegment* _tmp45_;
					const gchar* _tmp46_;
					const gchar* _tmp47_;
					gchar* _tmp48_;
					gchar* _tmp49_;
					KkcSegment* _tmp50_;
					KkcSegment* _tmp51_;
					const gchar* _tmp52_;
					const gchar* _tmp53_;
					GeeArrayList* _tmp54_;
					gpointer _tmp55_;
					KkcSegment* _tmp56_;
					const gchar* _tmp57_;
					const gchar* _tmp58_;
					gchar* _tmp59_;
					gchar* _tmp60_;
					_tmp39_ = previous;
					_tmp40_ = previous;
					_tmp41_ = kkc_segment_get_input (_tmp40_);
					_tmp42_ = _tmp41_;
					_tmp43_ = _segments;
					_tmp44_ = gee_abstract_list_get ((GeeAbstractList*) _tmp43_, index);
					_tmp45_ = (KkcSegment*) _tmp44_;
					_tmp46_ = kkc_segment_get_input (_tmp45_);
					_tmp47_ = _tmp46_;
					_tmp48_ = g_strconcat (_tmp42_, _tmp47_, NULL);
					_tmp49_ = _tmp48_;
					kkc_segment_set_input (_tmp40_, _tmp49_);
					_g_free0 (_tmp49_);
					_g_object_unref0 (_tmp45_);
					_tmp50_ = previous;
					_tmp51_ = previous;
					_tmp52_ = kkc_segment_get_output (_tmp51_);
					_tmp53_ = _tmp52_;
					_tmp54_ = _segments;
					_tmp55_ = gee_abstract_list_get ((GeeAbstractList*) _tmp54_, index);
					_tmp56_ = (KkcSegment*) _tmp55_;
					_tmp57_ = kkc_segment_get_output (_tmp56_);
					_tmp58_ = _tmp57_;
					_tmp59_ = g_strconcat (_tmp53_, _tmp58_, NULL);
					_tmp60_ = _tmp59_;
					kkc_segment_set_output (_tmp51_, _tmp60_);
					_g_free0 (_tmp60_);
					_g_object_unref0 (_tmp56_);
				} else {
					KkcSegmentList* _tmp61_;
					KkcSegment* _tmp62_;
					GeeArrayList* _tmp63_;
					gpointer _tmp64_;
					_tmp61_ = self->segments;
					_tmp62_ = previous;
					kkc_segment_list_add (_tmp61_, _tmp62_);
					_tmp63_ = _segments;
					_tmp64_ = gee_abstract_list_get ((GeeAbstractList*) _tmp63_, index);
					_g_object_unref0 (previous);
					previous = (KkcSegment*) _tmp64_;
				}
			} else {
				GeeArrayList* _tmp65_;
				gpointer _tmp66_;
				_tmp65_ = _segments;
				_tmp66_ = gee_abstract_list_get ((GeeAbstractList*) _tmp65_, index);
				_g_object_unref0 (previous);
				previous = (KkcSegment*) _tmp66_;
			}
		}
	}
	_tmp67_ = previous;
	if (_tmp67_ != NULL) {
		KkcSegmentList* _tmp68_;
		KkcSegment* _tmp69_;
		_tmp68_ = self->segments;
		_tmp69_ = previous;
		kkc_segment_list_add (_tmp68_, _tmp69_);
	}
	_g_object_unref0 (previous);
	_g_object_unref0 (_segments);
}

static gint*
_vala_array_dup2 (gint* self,
                  gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (gint));
	}
	return NULL;
}

void
kkc_state_convert_sentence (KkcState* self,
                            const gchar* input,
                            gint* constraint,
                            gint constraint_length1)
{
	gchar* normalized_input = NULL;
	gchar* _tmp0_;
	gint* _tmp1_ = NULL;
	gint* _tmp2_;
	gint _tmp2__length1;
	gint _tmp1__length1;
	gint __tmp1__size_;
	KkcSegment** _segments = NULL;
	KkcDecoder* _tmp4_;
	const gchar* _tmp5_;
	gint _tmp6_ = 0;
	KkcSegment** _tmp7_;
	gint _segments_length1;
	gint __segments_size_;
	KkcSegmentList* _tmp8_;
	KkcSegment** _tmp9_;
	gint _tmp9__length1;
	KkcSegment* _tmp10_;
	gint _tmp11_ = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (input != NULL);
	_tmp0_ = kkc_rom_kana_utils_normalize (input);
	normalized_input = _tmp0_;
	_tmp2_ = (constraint != NULL) ? _vala_array_dup2 (constraint, constraint_length1) : constraint;
	_tmp2__length1 = constraint_length1;
	_tmp1_ = _tmp2_;
	_tmp1__length1 = _tmp2__length1;
	__tmp1__size_ = _tmp1__length1;
	if (_tmp1_ == NULL) {
		gint* _tmp3_;
		_tmp3_ = g_new0 (gint, 0);
		_tmp1_ = (g_free (_tmp1_), NULL);
		_tmp1_ = _tmp3_;
		_tmp1__length1 = 0;
		__tmp1__size_ = _tmp1__length1;
	}
	_tmp4_ = self->decoder;
	_tmp5_ = normalized_input;
	_tmp7_ = kkc_decoder_decode (_tmp4_, _tmp5_, 1, _tmp1_, (gint) _tmp1__length1, &_tmp6_);
	_segments = _tmp7_;
	_segments_length1 = _tmp6_;
	__segments_size_ = _segments_length1;
	_tmp8_ = self->segments;
	_tmp9_ = _segments;
	_tmp9__length1 = _segments_length1;
	_tmp10_ = _tmp9_[0];
	kkc_segment_list_set_segments (_tmp8_, _tmp10_);
	if (constraint == NULL) {
		kkc_state_apply_constraint (self, input);
	}
	kkc_state_apply_phrase (self);
	if (constraint == NULL) {
		_tmp11_ = 0;
	} else {
		gint _tmp12_;
		_tmp12_ = constraint[constraint_length1 - 1];
		_tmp11_ = _tmp12_;
	}
	kkc_state_merge_possible_okurigana_segments (self, _tmp11_);
	_segments = (_vala_array_free (_segments, _segments_length1, (GDestroyNotify) g_object_unref), NULL);
	_tmp1_ = (g_free (_tmp1_), NULL);
	_g_free0 (normalized_input);
}

static gchar*
_vala_g_strjoinv (const gchar* separator,
                  gchar** str_array,
                  gint str_array_length1)
{
	gboolean _tmp0_ = FALSE;
	gchar* result;
	if (separator == NULL) {
		separator = "";
	}
	if (str_array != NULL) {
		gboolean _tmp1_ = FALSE;
		if (str_array_length1 > 0) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp2_ = FALSE;
			if (str_array_length1 == -1) {
				const gchar* _tmp3_;
				_tmp3_ = str_array[0];
				_tmp2_ = _tmp3_ != NULL;
			} else {
				_tmp2_ = FALSE;
			}
			_tmp1_ = _tmp2_;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint i = 0;
		gsize len = 0UL;
		gint _tmp16_;
		gint _tmp17_;
		const gchar* res = NULL;
		void* _tmp18_;
		const gchar* _tmp19_ = NULL;
		const gchar* _tmp20_;
		void* ptr = NULL;
		const gchar* _tmp22_;
		void* _tmp23_;
		const gchar* _tmp33_;
		len = (gsize) 1;
		{
			gboolean _tmp4_ = FALSE;
			i = 0;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gint _tmp10_ = 0;
				const gchar* _tmp11_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (str_array_length1 != -1) {
					_tmp7_ = i < str_array_length1;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp8_ = FALSE;
					if (str_array_length1 == -1) {
						const gchar* _tmp9_;
						_tmp9_ = str_array[i];
						_tmp8_ = _tmp9_ != NULL;
					} else {
						_tmp8_ = FALSE;
					}
					_tmp6_ = _tmp8_;
				}
				if (!_tmp6_) {
					break;
				}
				_tmp11_ = str_array[i];
				if (_tmp11_ != NULL) {
					const gchar* _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					_tmp12_ = str_array[i];
					_tmp13_ = strlen ((const gchar*) _tmp12_);
					_tmp14_ = _tmp13_;
					_tmp10_ = _tmp14_;
				} else {
					_tmp10_ = 0;
				}
				len += (gsize) _tmp10_;
			}
		}
		if (i == 0) {
			gchar* _tmp15_;
			_tmp15_ = g_strdup ("");
			result = _tmp15_;
			return result;
		}
		str_array_length1 = i;
		_tmp16_ = strlen ((const gchar*) separator);
		_tmp17_ = _tmp16_;
		len += (gsize) (_tmp17_ * (i - 1));
		_tmp18_ = g_malloc (len);
		res = _tmp18_;
		_tmp20_ = str_array[0];
		if (_tmp20_ != NULL) {
			const gchar* _tmp21_;
			_tmp21_ = str_array[0];
			_tmp19_ = (const gchar*) _tmp21_;
		} else {
			_tmp19_ = "";
		}
		_tmp22_ = res;
		_tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
		ptr = _tmp23_;
		{
			gboolean _tmp24_ = FALSE;
			i = 1;
			_tmp24_ = TRUE;
			while (TRUE) {
				void* _tmp26_;
				void* _tmp27_;
				const gchar* _tmp28_ = NULL;
				const gchar* _tmp29_;
				void* _tmp31_;
				void* _tmp32_;
				if (!_tmp24_) {
					gint _tmp25_;
					_tmp25_ = i;
					i = _tmp25_ + 1;
				}
				_tmp24_ = FALSE;
				if (!(i < str_array_length1)) {
					break;
				}
				_tmp26_ = ptr;
				_tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
				ptr = _tmp27_;
				_tmp29_ = str_array[i];
				if (_tmp29_ != NULL) {
					const gchar* _tmp30_;
					_tmp30_ = str_array[i];
					_tmp28_ = (const gchar*) _tmp30_;
				} else {
					_tmp28_ = "";
				}
				_tmp31_ = ptr;
				_tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
				ptr = _tmp32_;
			}
		}
		_tmp33_ = res;
		res = NULL;
		result = (gchar*) _tmp33_;
		return result;
	} else {
		gchar* _tmp34_;
		_tmp34_ = g_strdup ("");
		result = _tmp34_;
		return result;
	}
}

static void
kkc_state_apply_constraint_for_dictionary (KkcState* self,
                                           KkcDictionary* dictionary,
                                           const gchar* input)
{
	KkcSentenceDictionary* sentence_dict = NULL;
	KkcSentenceDictionary* _tmp0_;
	gchar** sequence = NULL;
	gint _tmp1_ = 0;
	gchar** _tmp2_;
	gint sequence_length1;
	gint _sequence_size_;
	GeeList* prefixes = NULL;
	gchar** _tmp3_;
	gint _tmp3__length1;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gchar** _tmp5_;
	gint _tmp5__length1;
	GeeList* _tmp6_;
	gint next_offset = 0;
	gint next_constraint_index = 0;
	GeeArrayList* constraint = NULL;
	GeeArrayList* _tmp7_;
	KkcSegment** _segments = NULL;
	KkcDecoder* _tmp95_;
	GeeArrayList* _tmp96_;
	gint _tmp97_ = 0;
	gpointer* _tmp98_;
	gint* _tmp99_;
	gint _tmp99__length1;
	gint _tmp100_ = 0;
	KkcSegment** _tmp101_;
	KkcSegment** _tmp102_;
	gint _tmp102__length1;
	gint _segments_length1;
	gint __segments_size_;
	KkcSegmentList* _tmp103_;
	KkcSegment* _tmp104_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dictionary != NULL);
	g_return_if_fail (input != NULL);
	_tmp0_ = _g_object_ref0 (KKC_IS_SENTENCE_DICTIONARY (dictionary) ? ((KkcSentenceDictionary*) dictionary) : NULL);
	sentence_dict = _tmp0_;
	_tmp2_ = kkc_utils_split_utf8 (input, &_tmp1_);
	sequence = _tmp2_;
	sequence_length1 = _tmp1_;
	_sequence_size_ = sequence_length1;
	_tmp3_ = sequence;
	_tmp3__length1 = sequence_length1;
	_tmp4_ = sequence;
	_tmp4__length1 = sequence_length1;
	_tmp5_ = sequence;
	_tmp5__length1 = sequence_length1;
	_tmp6_ = kkc_sequence_utils_enumerate_prefixes (_tmp3_, (gint) _tmp3__length1, MIN (4, _tmp4__length1), _tmp5__length1);
	prefixes = _tmp6_;
	next_offset = 0;
	next_constraint_index = 0;
	_tmp7_ = gee_array_list_new (G_TYPE_INT, NULL, NULL, NULL, NULL, NULL);
	constraint = _tmp7_;
	{
		GeeList* _prefix_list = NULL;
		GeeList* _tmp8_;
		gint _prefix_size = 0;
		GeeList* _tmp9_;
		gint _tmp10_;
		gint _tmp11_;
		gint _prefix_index = 0;
		_tmp8_ = prefixes;
		_prefix_list = _tmp8_;
		_tmp9_ = _prefix_list;
		_tmp10_ = gee_collection_get_size ((GeeCollection*) _tmp9_);
		_tmp11_ = _tmp10_;
		_prefix_size = _tmp11_;
		_prefix_index = -1;
		while (TRUE) {
			gint _tmp12_;
			gint _tmp13_;
			KkcPrefixEntry* prefix = NULL;
			GeeList* _tmp14_;
			gpointer _tmp15_;
			KkcPrefixEntry* _tmp16_;
			gint* _constraint = NULL;
			gint _constraint_length1 = 0;
			gint __constraint_size_ = 0;
			gchar* _input = NULL;
			KkcPrefixEntry* _tmp17_;
			gchar** _tmp18_;
			gint _tmp18__length1;
			gchar* _tmp19_;
			KkcSentenceDictionary* _tmp20_;
			const gchar* _tmp21_;
			gint* _tmp22_ = NULL;
			gint _tmp23_ = 0;
			gboolean _tmp24_;
			_prefix_index = _prefix_index + 1;
			_tmp12_ = _prefix_index;
			_tmp13_ = _prefix_size;
			if (!(_tmp12_ < _tmp13_)) {
				break;
			}
			_tmp14_ = _prefix_list;
			_tmp15_ = gee_list_get (_tmp14_, _prefix_index);
			prefix = (KkcPrefixEntry*) _tmp15_;
			_tmp16_ = prefix;
			if ((*_tmp16_).offset < next_offset) {
				_kkc_prefix_entry_free0 (prefix);
				continue;
			}
			_tmp17_ = prefix;
			_tmp18_ = (*_tmp17_).sequence;
			_tmp18__length1 = (*_tmp17_).sequence_length1;
			_tmp19_ = _vala_g_strjoinv ("", _tmp18_, (gint) _tmp18__length1);
			_input = _tmp19_;
			_tmp20_ = sentence_dict;
			_tmp21_ = _input;
			_tmp24_ = kkc_sentence_dictionary_lookup_constraint (_tmp20_, _tmp21_, &_tmp22_, &_tmp23_);
			_constraint = (g_free (_constraint), NULL);
			_constraint = _tmp22_;
			_constraint_length1 = _tmp23_;
			__constraint_size_ = _constraint_length1;
			if (_tmp24_) {
				gint* _tmp25_;
				gint _tmp25__length1;
				gint constraint_index = 0;
				GeeArrayList* _tmp26_;
				gint _tmp27_;
				gint _tmp28_;
				gint* _tmp92_;
				gint _tmp92__length1;
				gint _tmp93_;
				KkcPrefixEntry* _tmp94_;
				_tmp25_ = _constraint;
				_tmp25__length1 = _constraint_length1;
				_vala_assert (_tmp25__length1 > 0, "_constraint.length > 0");
				constraint_index = 0;
				_tmp26_ = constraint;
				_tmp27_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp26_);
				_tmp28_ = _tmp27_;
				if (_tmp28_ > 0) {
					gint last_offset = 0;
					GeeArrayList* _tmp29_;
					GeeArrayList* _tmp30_;
					gint _tmp31_;
					gint _tmp32_;
					gpointer _tmp33_;
					gint* _tmp34_;
					gint _tmp34__length1;
					gint _tmp35_;
					KkcPrefixEntry* _tmp36_;
					_tmp29_ = constraint;
					_tmp30_ = constraint;
					_tmp31_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp30_);
					_tmp32_ = _tmp31_;
					_tmp33_ = gee_abstract_list_get ((GeeAbstractList*) _tmp29_, _tmp32_ - 1);
					last_offset = (gint) ((gintptr) _tmp33_);
					_tmp34_ = _constraint;
					_tmp34__length1 = _constraint_length1;
					_tmp35_ = _tmp34_[0];
					_tmp36_ = prefix;
					if (last_offset < (_tmp35_ + (*_tmp36_).offset)) {
						gint _offset = 0;
						GeeArrayList* _tmp52_;
						gint _tmp53_;
						gint _tmp54_;
						_offset = 0;
						{
							gint i = 0;
							i = 0;
							{
								gboolean _tmp37_ = FALSE;
								_tmp37_ = TRUE;
								while (TRUE) {
									KkcSegmentList* _tmp39_;
									gint _tmp40_;
									gint _tmp41_;
									KkcSegmentList* _tmp42_;
									KkcSegment* _tmp43_;
									KkcSegment* _tmp44_;
									const gchar* _tmp45_;
									const gchar* _tmp46_;
									gboolean _tmp47_ = FALSE;
									if (!_tmp37_) {
										gint _tmp38_;
										_tmp38_ = i;
										i = _tmp38_ + 1;
									}
									_tmp37_ = FALSE;
									_tmp39_ = self->segments;
									_tmp40_ = kkc_segment_list_get_size (_tmp39_);
									_tmp41_ = _tmp40_;
									if (!(i < _tmp41_)) {
										break;
									}
									_tmp42_ = self->segments;
									_tmp43_ = kkc_segment_list_get (_tmp42_, i);
									_tmp44_ = _tmp43_;
									_tmp45_ = kkc_segment_get_input (_tmp44_);
									_tmp46_ = _tmp45_;
									_offset += g_utf8_strlen (_tmp46_, (gssize) -1);
									_g_object_unref0 (_tmp44_);
									if (last_offset < _offset) {
										gint* _tmp48_;
										gint _tmp48__length1;
										gint _tmp49_;
										KkcPrefixEntry* _tmp50_;
										_tmp48_ = _constraint;
										_tmp48__length1 = _constraint_length1;
										_tmp49_ = _tmp48_[0];
										_tmp50_ = prefix;
										_tmp47_ = _offset < (_tmp49_ + (*_tmp50_).offset);
									} else {
										_tmp47_ = FALSE;
									}
									if (_tmp47_) {
										GeeArrayList* _tmp51_;
										_tmp51_ = constraint;
										gee_abstract_collection_add ((GeeAbstractCollection*) _tmp51_, (gpointer) ((gintptr) _offset));
									}
								}
							}
						}
						_tmp52_ = constraint;
						_tmp53_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp52_);
						_tmp54_ = _tmp53_;
						next_constraint_index = _tmp54_;
					} else {
						gboolean found_overlap = FALSE;
						gint _tmp66_;
						found_overlap = FALSE;
						{
							gint i = 0;
							i = next_constraint_index;
							{
								gboolean _tmp55_ = FALSE;
								_tmp55_ = TRUE;
								while (TRUE) {
									GeeArrayList* _tmp57_;
									gint _tmp58_;
									gint _tmp59_;
									GeeArrayList* _tmp60_;
									gpointer _tmp61_;
									gint* _tmp62_;
									gint _tmp62__length1;
									gint _tmp63_;
									KkcPrefixEntry* _tmp64_;
									gint _tmp65_;
									if (!_tmp55_) {
										gint _tmp56_;
										_tmp56_ = i;
										i = _tmp56_ + 1;
									}
									_tmp55_ = FALSE;
									_tmp57_ = constraint;
									_tmp58_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp57_);
									_tmp59_ = _tmp58_;
									if (!(i < _tmp59_)) {
										break;
									}
									_tmp60_ = constraint;
									_tmp61_ = gee_abstract_list_get ((GeeAbstractList*) _tmp60_, i);
									_tmp62_ = _constraint;
									_tmp62__length1 = _constraint_length1;
									_tmp63_ = _tmp62_[i - next_constraint_index];
									_tmp64_ = prefix;
									if (((gint) ((gintptr) _tmp61_)) != (_tmp63_ + (*_tmp64_).offset)) {
										found_overlap = TRUE;
										break;
									}
									_tmp65_ = constraint_index;
									constraint_index = _tmp65_ + 1;
								}
							}
						}
						if (found_overlap) {
							_g_free0 (_input);
							_constraint = (g_free (_constraint), NULL);
							_kkc_prefix_entry_free0 (prefix);
							continue;
						}
						_tmp66_ = next_constraint_index;
						next_constraint_index = _tmp66_ + 1;
					}
				} else {
					KkcPrefixEntry* _tmp67_;
					_tmp67_ = prefix;
					if ((*_tmp67_).offset > 0) {
						gint _offset = 0;
						GeeArrayList* _tmp82_;
						gint _tmp83_;
						gint _tmp84_;
						_offset = 0;
						{
							gint i = 0;
							i = 0;
							{
								gboolean _tmp68_ = FALSE;
								_tmp68_ = TRUE;
								while (TRUE) {
									KkcSegmentList* _tmp70_;
									gint _tmp71_;
									gint _tmp72_;
									KkcSegmentList* _tmp73_;
									KkcSegment* _tmp74_;
									KkcSegment* _tmp75_;
									const gchar* _tmp76_;
									const gchar* _tmp77_;
									gint* _tmp78_;
									gint _tmp78__length1;
									gint _tmp79_;
									KkcPrefixEntry* _tmp80_;
									if (!_tmp68_) {
										gint _tmp69_;
										_tmp69_ = i;
										i = _tmp69_ + 1;
									}
									_tmp68_ = FALSE;
									_tmp70_ = self->segments;
									_tmp71_ = kkc_segment_list_get_size (_tmp70_);
									_tmp72_ = _tmp71_;
									if (!(i < _tmp72_)) {
										break;
									}
									_tmp73_ = self->segments;
									_tmp74_ = kkc_segment_list_get (_tmp73_, i);
									_tmp75_ = _tmp74_;
									_tmp76_ = kkc_segment_get_input (_tmp75_);
									_tmp77_ = _tmp76_;
									_offset += g_utf8_strlen (_tmp77_, (gssize) -1);
									_g_object_unref0 (_tmp75_);
									_tmp78_ = _constraint;
									_tmp78__length1 = _constraint_length1;
									_tmp79_ = _tmp78_[0];
									_tmp80_ = prefix;
									if (_offset < (_tmp79_ + (*_tmp80_).offset)) {
										GeeArrayList* _tmp81_;
										_tmp81_ = constraint;
										gee_abstract_collection_add ((GeeAbstractCollection*) _tmp81_, (gpointer) ((gintptr) _offset));
									}
								}
							}
						}
						_tmp82_ = constraint;
						_tmp83_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp82_);
						_tmp84_ = _tmp83_;
						next_constraint_index = _tmp84_;
					}
				}
				{
					gint i = 0;
					i = constraint_index;
					{
						gboolean _tmp85_ = FALSE;
						_tmp85_ = TRUE;
						while (TRUE) {
							gint* _tmp87_;
							gint _tmp87__length1;
							GeeArrayList* _tmp88_;
							gint* _tmp89_;
							gint _tmp89__length1;
							gint _tmp90_;
							KkcPrefixEntry* _tmp91_;
							if (!_tmp85_) {
								gint _tmp86_;
								_tmp86_ = i;
								i = _tmp86_ + 1;
							}
							_tmp85_ = FALSE;
							_tmp87_ = _constraint;
							_tmp87__length1 = _constraint_length1;
							if (!(i < _tmp87__length1)) {
								break;
							}
							_tmp88_ = constraint;
							_tmp89_ = _constraint;
							_tmp89__length1 = _constraint_length1;
							_tmp90_ = _tmp89_[i];
							_tmp91_ = prefix;
							gee_abstract_collection_add ((GeeAbstractCollection*) _tmp88_, (gpointer) ((gintptr) (_tmp90_ + (*_tmp91_).offset)));
						}
					}
				}
				_tmp92_ = _constraint;
				_tmp92__length1 = _constraint_length1;
				_tmp93_ = _tmp92_[0];
				_tmp94_ = prefix;
				next_offset = _tmp93_ + (*_tmp94_).offset;
			}
			_g_free0 (_input);
			_constraint = (g_free (_constraint), NULL);
			_kkc_prefix_entry_free0 (prefix);
		}
	}
	_tmp95_ = self->decoder;
	_tmp96_ = constraint;
	_tmp98_ = gee_collection_to_array ((GeeCollection*) _tmp96_, &_tmp97_);
	_tmp99_ = _tmp98_;
	_tmp99__length1 = _tmp97_;
	_tmp101_ = kkc_decoder_decode (_tmp95_, input, 1, _tmp99_, (gint) _tmp97_, &_tmp100_);
	_tmp102_ = _tmp101_;
	_tmp102__length1 = _tmp100_;
	_tmp99_ = (g_free (_tmp99_), NULL);
	_segments = _tmp102_;
	_segments_length1 = _tmp102__length1;
	__segments_size_ = _segments_length1;
	_tmp103_ = self->segments;
	_tmp104_ = _segments[0];
	kkc_segment_list_set_segments (_tmp103_, _tmp104_);
	_segments = (_vala_array_free (_segments, _segments_length1, (GDestroyNotify) g_object_unref), NULL);
	_g_object_unref0 (constraint);
	_g_object_unref0 (prefixes);
	sequence = (_vala_array_free (sequence, sequence_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (sentence_dict);
}

static Block8Data*
block8_data_ref (Block8Data* _data8_)
{
	g_atomic_int_inc (&_data8_->_ref_count_);
	return _data8_;
}

static void
block8_data_unref (void * _userdata_)
{
	Block8Data* _data8_;
	_data8_ = (Block8Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data8_->_ref_count_)) {
		KkcState* self;
		self = _data8_->self;
		_g_free0 (_data8_->input);
		_g_object_unref0 (self);
		g_slice_free (Block8Data, _data8_);
	}
}

static KkcDictionaryCallbackReturn
__lambda14_ (Block8Data* _data8_,
             KkcDictionary* dictionary)
{
	KkcState* self;
	KkcDictionaryCallbackReturn result;
	self = _data8_->self;
	g_return_val_if_fail (dictionary != NULL, 0);
	kkc_state_apply_constraint_for_dictionary (self, dictionary, _data8_->input);
	result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
	return result;
}

static KkcDictionaryCallbackReturn
___lambda14__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                      gpointer self)
{
	KkcDictionaryCallbackReturn result;
	result = __lambda14_ (self, dictionary);
	return result;
}

static void
kkc_state_apply_constraint (KkcState* self,
                            const gchar* input)
{
	Block8Data* _data8_;
	gchar* _tmp0_;
	KkcDictionaryList* _tmp1_;
	GType _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (input != NULL);
	_data8_ = g_slice_new0 (Block8Data);
	_data8_->_ref_count_ = 1;
	_data8_->self = g_object_ref (self);
	_tmp0_ = g_strdup (input);
	_g_free0 (_data8_->input);
	_data8_->input = _tmp0_;
	_tmp1_ = self->dictionaries;
	_tmp2_ = KKC_TYPE_SENTENCE_DICTIONARY;
	kkc_dictionary_list_call (_tmp1_, &_tmp2_, ___lambda14__kkc_dictionary_list_dictionary_callback, _data8_);
	block8_data_unref (_data8_);
	_data8_ = NULL;
}

static void
kkc_state_apply_phrase_for_dictionary (KkcState* self,
                                       KkcDictionary* dictionary)
{
	KkcSentenceDictionary* sentence_dict = NULL;
	KkcSentenceDictionary* _tmp0_;
	gchar** sequence = NULL;
	KkcSegmentList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gchar** _tmp4_;
	gint sequence_length1;
	gint _sequence_size_;
	GeeList* prefixes = NULL;
	gchar** _tmp17_;
	gint _tmp17__length1;
	gchar** _tmp18_;
	gint _tmp18__length1;
	gchar** _tmp19_;
	gint _tmp19__length1;
	GeeList* _tmp20_;
	gint offset = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dictionary != NULL);
	_tmp0_ = _g_object_ref0 (KKC_IS_SENTENCE_DICTIONARY (dictionary) ? ((KkcSentenceDictionary*) dictionary) : NULL);
	sentence_dict = _tmp0_;
	_tmp1_ = self->segments;
	_tmp2_ = kkc_segment_list_get_size (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_new0 (gchar*, _tmp3_ + 1);
	sequence = _tmp4_;
	sequence_length1 = _tmp3_;
	_sequence_size_ = sequence_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				KkcSegmentList* _tmp7_;
				gint _tmp8_;
				gint _tmp9_;
				gchar** _tmp10_;
				gint _tmp10__length1;
				KkcSegmentList* _tmp11_;
				KkcSegment* _tmp12_;
				KkcSegment* _tmp13_;
				const gchar* _tmp14_;
				const gchar* _tmp15_;
				gchar* _tmp16_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				_tmp7_ = self->segments;
				_tmp8_ = kkc_segment_list_get_size (_tmp7_);
				_tmp9_ = _tmp8_;
				if (!(i < _tmp9_)) {
					break;
				}
				_tmp10_ = sequence;
				_tmp10__length1 = sequence_length1;
				_tmp11_ = self->segments;
				_tmp12_ = kkc_segment_list_get (_tmp11_, i);
				_tmp13_ = _tmp12_;
				_tmp14_ = kkc_segment_get_input (_tmp13_);
				_tmp15_ = _tmp14_;
				_tmp16_ = g_strdup (_tmp15_);
				_g_free0 (_tmp10_[i]);
				_tmp10_[i] = _tmp16_;
				_g_object_unref0 (_tmp13_);
			}
		}
	}
	_tmp17_ = sequence;
	_tmp17__length1 = sequence_length1;
	_tmp18_ = sequence;
	_tmp18__length1 = sequence_length1;
	_tmp19_ = sequence;
	_tmp19__length1 = sequence_length1;
	_tmp20_ = kkc_sequence_utils_enumerate_prefixes (_tmp17_, (gint) _tmp17__length1, MIN (2, _tmp18__length1), MIN (5, _tmp19__length1));
	prefixes = _tmp20_;
	offset = 0;
	{
		GeeList* _prefix_list = NULL;
		GeeList* _tmp21_;
		gint _prefix_size = 0;
		GeeList* _tmp22_;
		gint _tmp23_;
		gint _tmp24_;
		gint _prefix_index = 0;
		_tmp21_ = prefixes;
		_prefix_list = _tmp21_;
		_tmp22_ = _prefix_list;
		_tmp23_ = gee_collection_get_size ((GeeCollection*) _tmp22_);
		_tmp24_ = _tmp23_;
		_prefix_size = _tmp24_;
		_prefix_index = -1;
		while (TRUE) {
			gint _tmp25_;
			gint _tmp26_;
			KkcPrefixEntry* prefix = NULL;
			GeeList* _tmp27_;
			gpointer _tmp28_;
			KkcPrefixEntry* _tmp29_;
			gchar** _value = NULL;
			gint _value_length1 = 0;
			gint __value_size_ = 0;
			KkcSentenceDictionary* _tmp30_;
			KkcPrefixEntry* _tmp31_;
			gchar** _tmp32_;
			gint _tmp32__length1;
			gchar** _tmp33_ = NULL;
			gint _tmp34_ = 0;
			gboolean _tmp35_;
			_prefix_index = _prefix_index + 1;
			_tmp25_ = _prefix_index;
			_tmp26_ = _prefix_size;
			if (!(_tmp25_ < _tmp26_)) {
				break;
			}
			_tmp27_ = _prefix_list;
			_tmp28_ = gee_list_get (_tmp27_, _prefix_index);
			prefix = (KkcPrefixEntry*) _tmp28_;
			_tmp29_ = prefix;
			if ((*_tmp29_).offset < offset) {
				_kkc_prefix_entry_free0 (prefix);
				continue;
			}
			_tmp30_ = sentence_dict;
			_tmp31_ = prefix;
			_tmp32_ = (*_tmp31_).sequence;
			_tmp32__length1 = (*_tmp31_).sequence_length1;
			_tmp35_ = kkc_sentence_dictionary_lookup_phrase (_tmp30_, _tmp32_, (gint) _tmp32__length1, &_tmp33_, &_tmp34_);
			_value = (_vala_array_free (_value, _value_length1, (GDestroyNotify) g_free), NULL);
			_value = _tmp33_;
			_value_length1 = _tmp34_;
			__value_size_ = _value_length1;
			if (_tmp35_) {
				gchar** _tmp45_;
				gint _tmp45__length1;
				{
					gint i = 0;
					i = 0;
					{
						gboolean _tmp36_ = FALSE;
						_tmp36_ = TRUE;
						while (TRUE) {
							gchar** _tmp38_;
							gint _tmp38__length1;
							KkcSegmentList* _tmp39_;
							KkcPrefixEntry* _tmp40_;
							KkcSegment* _tmp41_;
							KkcSegment* _tmp42_;
							gchar** _tmp43_;
							gint _tmp43__length1;
							const gchar* _tmp44_;
							if (!_tmp36_) {
								gint _tmp37_;
								_tmp37_ = i;
								i = _tmp37_ + 1;
							}
							_tmp36_ = FALSE;
							_tmp38_ = _value;
							_tmp38__length1 = _value_length1;
							if (!(i < _tmp38__length1)) {
								break;
							}
							_tmp39_ = self->segments;
							_tmp40_ = prefix;
							_tmp41_ = kkc_segment_list_get (_tmp39_, (*_tmp40_).offset + i);
							_tmp42_ = _tmp41_;
							_tmp43_ = _value;
							_tmp43__length1 = _value_length1;
							_tmp44_ = _tmp43_[i];
							kkc_segment_set_output (_tmp42_, _tmp44_);
							_g_object_unref0 (_tmp42_);
						}
					}
				}
				_tmp45_ = _value;
				_tmp45__length1 = _value_length1;
				offset += _tmp45__length1;
			}
			_value = (_vala_array_free (_value, _value_length1, (GDestroyNotify) g_free), NULL);
			_kkc_prefix_entry_free0 (prefix);
		}
	}
	_g_object_unref0 (prefixes);
	sequence = (_vala_array_free (sequence, sequence_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (sentence_dict);
}

static KkcDictionaryCallbackReturn
__lambda15_ (KkcState* self,
             KkcDictionary* dictionary)
{
	KkcDictionaryCallbackReturn result;
	g_return_val_if_fail (dictionary != NULL, 0);
	kkc_state_apply_phrase_for_dictionary (self, dictionary);
	result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
	return result;
}

static KkcDictionaryCallbackReturn
___lambda15__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                      gpointer self)
{
	KkcDictionaryCallbackReturn result;
	result = __lambda15_ ((KkcState*) self, dictionary);
	return result;
}

static void
kkc_state_apply_phrase (KkcState* self)
{
	KkcDictionaryList* _tmp0_;
	GType _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->dictionaries;
	_tmp1_ = KKC_TYPE_SENTENCE_DICTIONARY;
	kkc_dictionary_list_call (_tmp0_, &_tmp1_, ___lambda15__kkc_dictionary_list_dictionary_callback, self);
}

static void
_vala_array_add6 (gint* * array,
                  gint* length,
                  gint* size,
                  gint value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gint, *array, *size);
	}
	(*array)[(*length)++] = value;
}

static void
_vala_array_add7 (gint* * array,
                  gint* length,
                  gint* size,
                  gint value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gint, *array, *size);
	}
	(*array)[(*length)++] = value;
}

void
kkc_state_resize_segment (KkcState* self,
                          gint amount)
{
	gboolean _tmp0_ = FALSE;
	KkcSegmentList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->segments;
	_tmp2_ = kkc_segment_list_get_cursor_pos (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ >= 0) {
		KkcSegmentList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		KkcSegmentList* _tmp7_;
		gint _tmp8_;
		gint _tmp9_;
		_tmp4_ = self->segments;
		_tmp5_ = kkc_segment_list_get_cursor_pos (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = self->segments;
		_tmp8_ = kkc_segment_list_get_size (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp0_ = _tmp6_ < _tmp9_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gboolean _tmp10_ = FALSE;
		gint segment_size = 0;
		KkcSegmentList* _tmp17_;
		KkcSegmentList* _tmp18_;
		gint _tmp19_;
		gint _tmp20_;
		KkcSegment* _tmp21_;
		KkcSegment* _tmp22_;
		const gchar* _tmp23_;
		const gchar* _tmp24_;
		gint _tmp25_;
		gint* constraint = NULL;
		gint* _tmp26_;
		gint constraint_length1;
		gint _constraint_size_;
		gint offset = 0;
		gchar** output = NULL;
		KkcSegmentList* _tmp37_;
		gint _tmp38_;
		gint _tmp39_;
		gchar** _tmp40_;
		gint output_length1;
		gint _output_size_;
		gint cursor_pos = 0;
		KkcSegmentList* _tmp51_;
		gint _tmp52_;
		gint _tmp53_;
		KkcSegmentList* _tmp54_;
		gchar* _tmp55_;
		gchar* _tmp56_;
		gint* _tmp57_;
		gint _tmp57__length1;
		KkcSegmentList* _tmp58_;
		if (amount > 0) {
			KkcSegmentList* _tmp11_;
			gint _tmp12_;
			gint _tmp13_;
			KkcSegmentList* _tmp14_;
			gint _tmp15_;
			gint _tmp16_;
			_tmp11_ = self->segments;
			_tmp12_ = kkc_segment_list_get_cursor_pos (_tmp11_);
			_tmp13_ = _tmp12_;
			_tmp14_ = self->segments;
			_tmp15_ = kkc_segment_list_get_size (_tmp14_);
			_tmp16_ = _tmp15_;
			_tmp10_ = _tmp13_ > (_tmp16_ - 1);
		} else {
			_tmp10_ = FALSE;
		}
		if (_tmp10_) {
			return;
		}
		_tmp17_ = self->segments;
		_tmp18_ = self->segments;
		_tmp19_ = kkc_segment_list_get_cursor_pos (_tmp18_);
		_tmp20_ = _tmp19_;
		_tmp21_ = kkc_segment_list_get (_tmp17_, _tmp20_);
		_tmp22_ = _tmp21_;
		_tmp23_ = kkc_segment_get_input (_tmp22_);
		_tmp24_ = _tmp23_;
		_tmp25_ = g_utf8_strlen (_tmp24_, (gssize) -1) + amount;
		_g_object_unref0 (_tmp22_);
		segment_size = _tmp25_;
		if (segment_size <= 0) {
			return;
		}
		_tmp26_ = g_new0 (gint, 0);
		constraint = _tmp26_;
		constraint_length1 = 0;
		_constraint_size_ = constraint_length1;
		offset = 0;
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp27_ = FALSE;
				_tmp27_ = TRUE;
				while (TRUE) {
					KkcSegmentList* _tmp29_;
					gint _tmp30_;
					gint _tmp31_;
					KkcSegmentList* _tmp32_;
					KkcSegment* _tmp33_;
					KkcSegment* _tmp34_;
					const gchar* _tmp35_;
					const gchar* _tmp36_;
					if (!_tmp27_) {
						gint _tmp28_;
						_tmp28_ = i;
						i = _tmp28_ + 1;
					}
					_tmp27_ = FALSE;
					_tmp29_ = self->segments;
					_tmp30_ = kkc_segment_list_get_cursor_pos (_tmp29_);
					_tmp31_ = _tmp30_;
					if (!(i < _tmp31_)) {
						break;
					}
					_tmp32_ = self->segments;
					_tmp33_ = kkc_segment_list_get (_tmp32_, i);
					_tmp34_ = _tmp33_;
					_tmp35_ = kkc_segment_get_input (_tmp34_);
					_tmp36_ = _tmp35_;
					offset += g_utf8_strlen (_tmp36_, (gssize) -1);
					_g_object_unref0 (_tmp34_);
					_vala_array_add6 (&constraint, &constraint_length1, &_constraint_size_, offset);
				}
			}
		}
		offset += segment_size;
		_vala_array_add7 (&constraint, &constraint_length1, &_constraint_size_, offset);
		_tmp37_ = self->segments;
		_tmp38_ = kkc_segment_list_get_cursor_pos (_tmp37_);
		_tmp39_ = _tmp38_;
		_tmp40_ = g_new0 (gchar*, _tmp39_ + 1);
		output = _tmp40_;
		output_length1 = _tmp39_;
		_output_size_ = output_length1;
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp41_ = FALSE;
				_tmp41_ = TRUE;
				while (TRUE) {
					gchar** _tmp43_;
					gint _tmp43__length1;
					gchar** _tmp44_;
					gint _tmp44__length1;
					KkcSegmentList* _tmp45_;
					KkcSegment* _tmp46_;
					KkcSegment* _tmp47_;
					const gchar* _tmp48_;
					const gchar* _tmp49_;
					gchar* _tmp50_;
					if (!_tmp41_) {
						gint _tmp42_;
						_tmp42_ = i;
						i = _tmp42_ + 1;
					}
					_tmp41_ = FALSE;
					_tmp43_ = output;
					_tmp43__length1 = output_length1;
					if (!(i < _tmp43__length1)) {
						break;
					}
					_tmp44_ = output;
					_tmp44__length1 = output_length1;
					_tmp45_ = self->segments;
					_tmp46_ = kkc_segment_list_get (_tmp45_, i);
					_tmp47_ = _tmp46_;
					_tmp48_ = kkc_segment_get_output (_tmp47_);
					_tmp49_ = _tmp48_;
					_tmp50_ = g_strdup (_tmp49_);
					_g_free0 (_tmp44_[i]);
					_tmp44_[i] = _tmp50_;
					_g_object_unref0 (_tmp47_);
				}
			}
		}
		_tmp51_ = self->segments;
		_tmp52_ = kkc_segment_list_get_cursor_pos (_tmp51_);
		_tmp53_ = _tmp52_;
		cursor_pos = _tmp53_;
		_tmp54_ = self->segments;
		_tmp55_ = kkc_segment_list_get_input (_tmp54_);
		_tmp56_ = _tmp55_;
		_tmp57_ = constraint;
		_tmp57__length1 = constraint_length1;
		kkc_state_convert_sentence (self, _tmp56_, _tmp57_, (gint) _tmp57__length1);
		_g_free0 (_tmp56_);
		kkc_state_apply_phrase (self);
		_tmp58_ = self->segments;
		kkc_segment_list_set_cursor_pos (_tmp58_, cursor_pos);
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp59_ = FALSE;
				_tmp59_ = TRUE;
				while (TRUE) {
					gchar** _tmp61_;
					gint _tmp61__length1;
					KkcSegmentList* _tmp62_;
					KkcSegment* _tmp63_;
					KkcSegment* _tmp64_;
					gchar** _tmp65_;
					gint _tmp65__length1;
					const gchar* _tmp66_;
					if (!_tmp59_) {
						gint _tmp60_;
						_tmp60_ = i;
						i = _tmp60_ + 1;
					}
					_tmp59_ = FALSE;
					_tmp61_ = output;
					_tmp61__length1 = output_length1;
					if (!(i < _tmp61__length1)) {
						break;
					}
					_tmp62_ = self->segments;
					_tmp63_ = kkc_segment_list_get (_tmp62_, i);
					_tmp64_ = _tmp63_;
					_tmp65_ = output;
					_tmp65__length1 = output_length1;
					_tmp66_ = _tmp65_[i];
					kkc_segment_set_output (_tmp64_, _tmp66_);
					_g_object_unref0 (_tmp64_);
				}
			}
		}
		self->priv->segments_changed = TRUE;
		output = (_vala_array_free (output, output_length1, (GDestroyNotify) g_free), NULL);
		constraint = (g_free (constraint), NULL);
	}
}

static Block9Data*
block9_data_ref (Block9Data* _data9_)
{
	g_atomic_int_inc (&_data9_->_ref_count_);
	return _data9_;
}

static void
block9_data_unref (void * _userdata_)
{
	Block9Data* _data9_;
	_data9_ = (Block9Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data9_->_ref_count_)) {
		KkcState* self;
		self = _data9_->self;
		_g_object_unref0 (_data9_->candidate);
		_g_object_unref0 (self);
		g_slice_free (Block9Data, _data9_);
	}
}

static KkcDictionaryCallbackReturn
__lambda13_ (Block9Data* _data9_,
             KkcDictionary* dictionary)
{
	KkcState* self;
	KkcSegmentDictionary* segment_dict = NULL;
	KkcSegmentDictionary* _tmp0_;
	KkcDictionaryCallbackReturn result;
	self = _data9_->self;
	g_return_val_if_fail (dictionary != NULL, 0);
	_tmp0_ = _g_object_ref0 (KKC_IS_SEGMENT_DICTIONARY (dictionary) ? ((KkcSegmentDictionary*) dictionary) : NULL);
	segment_dict = _tmp0_;
	kkc_segment_dictionary_purge_candidate (segment_dict, _data9_->candidate);
	result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
	_g_object_unref0 (segment_dict);
	return result;
}

static KkcDictionaryCallbackReturn
___lambda13__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                      gpointer self)
{
	KkcDictionaryCallbackReturn result;
	result = __lambda13_ (self, dictionary);
	return result;
}

void
kkc_state_purge_candidate (KkcState* self,
                           KkcCandidate* candidate)
{
	Block9Data* _data9_;
	KkcCandidate* _tmp0_;
	KkcDictionaryList* _tmp1_;
	GType _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (candidate != NULL);
	_data9_ = g_slice_new0 (Block9Data);
	_data9_->_ref_count_ = 1;
	_data9_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (candidate);
	_g_object_unref0 (_data9_->candidate);
	_data9_->candidate = _tmp0_;
	_tmp1_ = self->dictionaries;
	_tmp2_ = KKC_TYPE_SEGMENT_DICTIONARY;
	kkc_dictionary_list_call (_tmp1_, &_tmp2_, ___lambda13__kkc_dictionary_list_dictionary_callback, _data9_);
	block9_data_unref (_data9_);
	_data9_ = NULL;
}

static Block10Data*
block10_data_ref (Block10Data* _data10_)
{
	g_atomic_int_inc (&_data10_->_ref_count_);
	return _data10_;
}

static void
block10_data_unref (void * _userdata_)
{
	Block10Data* _data10_;
	_data10_ = (Block10Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data10_->_ref_count_)) {
		KkcState* self;
		self = _data10_->self;
		_g_free0 (_data10_->input);
		_g_object_unref0 (self);
		g_slice_free (Block10Data, _data10_);
	}
}

static KkcDictionaryCallbackReturn
__lambda11_ (Block10Data* _data10_,
             KkcDictionary* dictionary)
{
	KkcState* self;
	KkcSegmentDictionary* segment_dict = NULL;
	KkcSegmentDictionary* _tmp0_;
	gchar** _completion = NULL;
	KkcSegmentDictionary* _tmp1_;
	gint _tmp2_ = 0;
	gchar** _tmp3_;
	gint _completion_length1;
	gint __completion_size_;
	gchar** _tmp4_;
	gint _tmp4__length1;
	KkcDictionaryCallbackReturn result;
	self = _data10_->self;
	g_return_val_if_fail (dictionary != NULL, 0);
	_tmp0_ = _g_object_ref0 (KKC_IS_SEGMENT_DICTIONARY (dictionary) ? ((KkcSegmentDictionary*) dictionary) : NULL);
	segment_dict = _tmp0_;
	_tmp1_ = segment_dict;
	_tmp3_ = kkc_segment_dictionary_complete (_tmp1_, _data10_->input, &_tmp2_);
	_completion = _tmp3_;
	_completion_length1 = _tmp2_;
	__completion_size_ = _completion_length1;
	_tmp4_ = _completion;
	_tmp4__length1 = _completion_length1;
	{
		gchar** word_collection = NULL;
		gint word_collection_length1 = 0;
		gint _word_collection_size_ = 0;
		gint word_it = 0;
		word_collection = _tmp4_;
		word_collection_length1 = _tmp4__length1;
		for (word_it = 0; word_it < word_collection_length1; word_it = word_it + 1) {
			gchar* _tmp5_;
			gchar* word = NULL;
			_tmp5_ = g_strdup (word_collection[word_it]);
			word = _tmp5_;
			{
				GeeArrayList* _tmp6_;
				const gchar* _tmp7_;
				_tmp6_ = self->priv->completion;
				_tmp7_ = word;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp6_, _tmp7_);
				_g_free0 (word);
			}
		}
	}
	result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
	_completion = (_vala_array_free (_completion, _completion_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (segment_dict);
	return result;
}

static KkcDictionaryCallbackReturn
___lambda11__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                      gpointer self)
{
	KkcDictionaryCallbackReturn result;
	result = __lambda11_ (self, dictionary);
	return result;
}

void
kkc_state_completion_start (KkcState* self,
                            const gchar* input)
{
	Block10Data* _data10_;
	gchar* _tmp0_;
	GeeArrayList* _tmp1_;
	KkcDictionaryList* _tmp2_;
	GType _tmp3_;
	GeeArrayList* _tmp4_;
	GeeArrayList* _tmp5_;
	GeeIterator* _tmp6_;
	GeeIterator* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (input != NULL);
	_data10_ = g_slice_new0 (Block10Data);
	_data10_->_ref_count_ = 1;
	_data10_->self = g_object_ref (self);
	_tmp0_ = g_strdup (input);
	_g_free0 (_data10_->input);
	_data10_->input = _tmp0_;
	_tmp1_ = self->priv->completion;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp1_);
	_tmp2_ = self->dictionaries;
	_tmp3_ = KKC_TYPE_SEGMENT_DICTIONARY;
	kkc_dictionary_list_call (_tmp2_, &_tmp3_, ___lambda11__kkc_dictionary_list_dictionary_callback, _data10_);
	_tmp4_ = self->priv->completion;
	gee_list_sort ((GeeList*) _tmp4_, NULL, NULL, NULL);
	_tmp5_ = self->priv->completion;
	_tmp6_ = gee_abstract_collection_iterator ((GeeAbstractCollection*) _tmp5_);
	_g_object_unref0 (self->completion_iterator);
	self->completion_iterator = _tmp6_;
	_tmp7_ = self->completion_iterator;
	if (!gee_iterator_next (_tmp7_)) {
		_g_object_unref0 (self->completion_iterator);
		self->completion_iterator = NULL;
	}
	block10_data_unref (_data10_);
	_data10_ = NULL;
}

KkcInputMode
kkc_state_get_input_mode (KkcState* self)
{
	KkcInputMode result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_input_mode;
	return result;
}

void
kkc_state_set_input_mode (KkcState* self,
                          KkcInputMode value)
{
	KkcInputMode _last_input_mode = 0;
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	_last_input_mode = self->priv->_input_mode;
	self->priv->_input_mode = value;
	if (self->priv->_input_mode >= KKC_KANA_MODE_HIRAGANA) {
		_tmp0_ = self->priv->_input_mode <= KKC_KANA_MODE_WIDE_LATIN;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		KkcRomKanaConverter* _tmp1_;
		_tmp1_ = self->rom_kana_converter;
		kkc_rom_kana_converter_set_kana_mode (_tmp1_, (KkcKanaMode) self->priv->_input_mode);
	}
	if (_last_input_mode != self->priv->_input_mode) {
		g_object_notify ((GObject*) self, "input-mode");
	}
}

gint
kkc_state_get_input_cursor_pos (KkcState* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	if (self->input_characters_cursor_pos >= 0) {
		gint index = 0;
		gint offset = 0;
		KkcRomKanaConverter* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		index = 0;
		offset = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				KkcRomKanaCharacterList* _tmp2_;
				KkcRomKanaCharacter _tmp3_ = {0};
				KkcRomKanaCharacter _tmp4_;
				const gchar* _tmp5_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = index;
					index = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(index < self->input_characters_cursor_pos)) {
					break;
				}
				_tmp2_ = self->input_characters;
				kkc_rom_kana_character_list_get (_tmp2_, index, &_tmp3_);
				_tmp4_ = _tmp3_;
				_tmp5_ = _tmp4_.output;
				offset += g_utf8_strlen (_tmp5_, (gssize) -1);
				kkc_rom_kana_character_destroy (&_tmp4_);
			}
		}
		_tmp6_ = self->rom_kana_converter;
		_tmp7_ = kkc_rom_kana_converter_get_pending_output (_tmp6_);
		_tmp8_ = _tmp7_;
		offset += g_utf8_strlen (_tmp8_, (gssize) -1);
		result = offset;
		return result;
	}
	result = self->input_characters_cursor_pos;
	return result;
}

guint
kkc_state_get_input_cursor_width (KkcState* self)
{
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	if (self->input_characters_cursor_pos >= 0) {
		KkcRomKanaCharacterList* _tmp0_;
		KkcRomKanaCharacter _tmp1_ = {0};
		KkcRomKanaCharacter _tmp2_;
		const gchar* _tmp3_;
		guint _tmp4_;
		_tmp0_ = self->input_characters;
		kkc_rom_kana_character_list_get (_tmp0_, self->input_characters_cursor_pos, &_tmp1_);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_.output;
		_tmp4_ = (guint) g_utf8_strlen (_tmp3_, (gssize) -1);
		kkc_rom_kana_character_destroy (&_tmp2_);
		result = _tmp4_;
		return result;
	}
	result = (guint) self->input_characters_cursor_pos;
	return result;
}

KkcPunctuationStyle
kkc_state_get_punctuation_style (KkcState* self)
{
	KkcPunctuationStyle result;
	KkcRomKanaConverter* _tmp0_;
	KkcPunctuationStyle _tmp1_;
	KkcPunctuationStyle _tmp2_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->rom_kana_converter;
	_tmp1_ = kkc_rom_kana_converter_get_punctuation_style (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

void
kkc_state_set_punctuation_style (KkcState* self,
                                 KkcPunctuationStyle value)
{
	KkcRomKanaConverter* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->rom_kana_converter;
	kkc_rom_kana_converter_set_punctuation_style (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, kkc_state_properties[KKC_STATE_PUNCTUATION_STYLE_PROPERTY]);
}

gboolean
kkc_state_get_auto_correct (KkcState* self)
{
	gboolean result;
	KkcRomKanaConverter* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->rom_kana_converter;
	_tmp1_ = kkc_rom_kana_converter_get_auto_correct (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

void
kkc_state_set_auto_correct (KkcState* self,
                            gboolean value)
{
	KkcRomKanaConverter* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->rom_kana_converter;
	kkc_rom_kana_converter_set_auto_correct (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, kkc_state_properties[KKC_STATE_AUTO_CORRECT_PROPERTY]);
}

KkcRule*
kkc_state_get_typing_rule (KkcState* self)
{
	KkcRule* result;
	KkcRule* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_typing_rule;
	result = _tmp0_;
	return result;
}

void
kkc_state_set_typing_rule (KkcState* self,
                           KkcRule* value)
{
	KkcRule* _tmp0_;
	KkcRomKanaConverter* _tmp1_;
	KkcRule* _tmp2_;
	KkcRomKanaMapFile* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_typing_rule);
	self->priv->_typing_rule = _tmp0_;
	_tmp1_ = self->rom_kana_converter;
	_tmp2_ = self->priv->_typing_rule;
	_tmp3_ = _tmp2_->rom_kana;
	kkc_rom_kana_converter_set_rule (_tmp1_, _tmp3_);
	g_object_notify_by_pspec ((GObject *) self, kkc_state_properties[KKC_STATE_TYPING_RULE_PROPERTY]);
}

static void
kkc_state_class_init (KkcStateClass * klass,
                      gpointer klass_data)
{
	kkc_state_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcState_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_kkc_state_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_kkc_state_set_property;
	G_OBJECT_CLASS (klass)->finalize = kkc_state_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_STATE_INPUT_MODE_PROPERTY, kkc_state_properties[KKC_STATE_INPUT_MODE_PROPERTY] = g_param_spec_enum ("input-mode", "input-mode", "input-mode", KKC_TYPE_INPUT_MODE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_STATE_INPUT_CURSOR_POS_PROPERTY, kkc_state_properties[KKC_STATE_INPUT_CURSOR_POS_PROPERTY] = g_param_spec_int ("input-cursor-pos", "input-cursor-pos", "input-cursor-pos", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_STATE_INPUT_CURSOR_WIDTH_PROPERTY, kkc_state_properties[KKC_STATE_INPUT_CURSOR_WIDTH_PROPERTY] = g_param_spec_uint ("input-cursor-width", "input-cursor-width", "input-cursor-width", 0, G_MAXUINT, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_STATE_PUNCTUATION_STYLE_PROPERTY, kkc_state_properties[KKC_STATE_PUNCTUATION_STYLE_PROPERTY] = g_param_spec_enum ("punctuation-style", "punctuation-style", "punctuation-style", KKC_TYPE_PUNCTUATION_STYLE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_STATE_AUTO_CORRECT_PROPERTY, kkc_state_properties[KKC_STATE_AUTO_CORRECT_PROPERTY] = g_param_spec_boolean ("auto-correct", "auto-correct", "auto-correct", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_STATE_TYPING_RULE_PROPERTY, kkc_state_properties[KKC_STATE_TYPING_RULE_PROPERTY] = g_param_spec_object ("typing-rule", "typing-rule", "typing-rule", KKC_TYPE_RULE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	kkc_state_signals[KKC_STATE_REQUEST_SELECTION_TEXT_SIGNAL] = g_signal_new ("request-selection-text", KKC_TYPE_STATE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
kkc_state_instance_init (KkcState * self,
                         gpointer klass)
{
	KkcRomKanaCharacterList* _tmp0_;
	GString* _tmp1_;
	GString* _tmp2_;
	GeeArrayList* _tmp3_;
	self->priv = kkc_state_get_instance_private (self);
	self->priv->segments_changed = FALSE;
	_tmp0_ = kkc_rom_kana_character_list_new ();
	self->input_characters = _tmp0_;
	self->input_characters_cursor_pos = -1;
	_tmp1_ = g_string_new ("");
	self->selection = _tmp1_;
	_tmp2_ = g_string_new ("");
	self->output = _tmp2_;
	self->quoted = FALSE;
	self->this_command_key = NULL;
	self->last_command_key = NULL;
	self->priv->latin_conversion_upper = FALSE;
	self->overriding_input = NULL;
	_tmp3_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	self->priv->completion = _tmp3_;
}

static void
kkc_state_finalize (GObject * obj)
{
	KkcState * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_STATE, KkcState);
	kkc_state_reset (self);
	_g_object_unref0 (self->model);
	_g_object_unref0 (self->decoder);
	_g_object_unref0 (self->segments);
	_g_object_unref0 (self->candidates);
	_g_object_unref0 (self->dictionaries);
	_g_object_unref0 (self->rom_kana_converter);
	_g_object_unref0 (self->input_characters);
	_g_string_free0 (self->selection);
	_g_string_free0 (self->output);
	_g_object_unref0 (self->this_command_key);
	_g_object_unref0 (self->last_command_key);
	_g_free0 (self->overriding_input);
	_g_object_unref0 (self->priv->completion);
	_g_object_unref0 (self->completion_iterator);
	_g_object_unref0 (self->priv->_typing_rule);
	G_OBJECT_CLASS (kkc_state_parent_class)->finalize (obj);
}

static GType
kkc_state_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcStateClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_state_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcState), 0, (GInstanceInitFunc) kkc_state_instance_init, NULL };
	GType kkc_state_type_id;
	kkc_state_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcState", &g_define_type_info, 0);
	KkcState_private_offset = g_type_add_instance_private (kkc_state_type_id, sizeof (KkcStatePrivate));
	return kkc_state_type_id;
}

GType
kkc_state_get_type (void)
{
	static volatile gsize kkc_state_type_id__once = 0;
	if (g_once_init_enter (&kkc_state_type_id__once)) {
		GType kkc_state_type_id;
		kkc_state_type_id = kkc_state_get_type_once ();
		g_once_init_leave (&kkc_state_type_id__once, kkc_state_type_id);
	}
	return kkc_state_type_id__once;
}

static void
_vala_kkc_state_get_property (GObject * object,
                              guint property_id,
                              GValue * value,
                              GParamSpec * pspec)
{
	KkcState * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_STATE, KkcState);
	switch (property_id) {
		case KKC_STATE_INPUT_MODE_PROPERTY:
		g_value_set_enum (value, kkc_state_get_input_mode (self));
		break;
		case KKC_STATE_INPUT_CURSOR_POS_PROPERTY:
		g_value_set_int (value, kkc_state_get_input_cursor_pos (self));
		break;
		case KKC_STATE_INPUT_CURSOR_WIDTH_PROPERTY:
		g_value_set_uint (value, kkc_state_get_input_cursor_width (self));
		break;
		case KKC_STATE_PUNCTUATION_STYLE_PROPERTY:
		g_value_set_enum (value, kkc_state_get_punctuation_style (self));
		break;
		case KKC_STATE_AUTO_CORRECT_PROPERTY:
		g_value_set_boolean (value, kkc_state_get_auto_correct (self));
		break;
		case KKC_STATE_TYPING_RULE_PROPERTY:
		g_value_set_object (value, kkc_state_get_typing_rule (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_kkc_state_set_property (GObject * object,
                              guint property_id,
                              const GValue * value,
                              GParamSpec * pspec)
{
	KkcState * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_STATE, KkcState);
	switch (property_id) {
		case KKC_STATE_INPUT_MODE_PROPERTY:
		kkc_state_set_input_mode (self, g_value_get_enum (value));
		break;
		case KKC_STATE_PUNCTUATION_STYLE_PROPERTY:
		kkc_state_set_punctuation_style (self, g_value_get_enum (value));
		break;
		case KKC_STATE_AUTO_CORRECT_PROPERTY:
		kkc_state_set_auto_correct (self, g_value_get_boolean (value));
		break;
		case KKC_STATE_TYPING_RULE_PROPERTY:
		kkc_state_set_typing_rule (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

gboolean
kkc_command_handler_call (KkcCommandHandler* self,
                          const gchar* command,
                          KkcState* state,
                          KkcKeyEvent* key)
{
	KkcCommandHandlerIface* _iface_;
	g_return_val_if_fail (self != NULL, FALSE);
	_iface_ = KKC_COMMAND_HANDLER_GET_INTERFACE (self);
	if (_iface_->call) {
		return _iface_->call (self, command, state, key);
	}
	return FALSE;
}

static void
kkc_command_handler_default_init (KkcCommandHandlerIface * iface,
                                  gpointer iface_data)
{
}

static GType
kkc_command_handler_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcCommandHandlerIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_command_handler_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType kkc_command_handler_type_id;
	kkc_command_handler_type_id = g_type_register_static (G_TYPE_INTERFACE, "KkcCommandHandler", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (kkc_command_handler_type_id, G_TYPE_OBJECT);
	return kkc_command_handler_type_id;
}

GType
kkc_command_handler_get_type (void)
{
	static volatile gsize kkc_command_handler_type_id__once = 0;
	if (g_once_init_enter (&kkc_command_handler_type_id__once)) {
		GType kkc_command_handler_type_id;
		kkc_command_handler_type_id = kkc_command_handler_get_type_once ();
		g_once_init_leave (&kkc_command_handler_type_id__once, kkc_command_handler_type_id);
	}
	return kkc_command_handler_type_id__once;
}

static inline gpointer
kkc_callback_command_handler_get_instance_private (KkcCallbackCommandHandler* self)
{
	return G_STRUCT_MEMBER_P (self, KkcCallbackCommandHandler_private_offset);
}

KkcCallbackCommandHandler*
kkc_callback_command_handler_construct (GType object_type,
                                        KkcCommandCallback cb,
                                        gpointer cb_target)
{
	KkcCallbackCommandHandler * self = NULL;
	self = (KkcCallbackCommandHandler*) g_object_new (object_type, NULL);
	self->priv->cb = cb;
	self->priv->cb_target = cb_target;
	return self;
}

KkcCallbackCommandHandler*
kkc_callback_command_handler_new (KkcCommandCallback cb,
                                  gpointer cb_target)
{
	return kkc_callback_command_handler_construct (KKC_TYPE_CALLBACK_COMMAND_HANDLER, cb, cb_target);
}

static gboolean
kkc_callback_command_handler_real_call (KkcCommandHandler* base,
                                        const gchar* command,
                                        KkcState* state,
                                        KkcKeyEvent* key)
{
	KkcCallbackCommandHandler * self;
	KkcCommandCallback _tmp0_;
	gpointer _tmp0__target;
	gboolean result;
	self = (KkcCallbackCommandHandler*) base;
	g_return_val_if_fail (state != NULL, FALSE);
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp0_ = self->priv->cb;
	_tmp0__target = self->priv->cb_target;
	result = _tmp0_ (command, state, key, _tmp0__target);
	return result;
}

static void
kkc_callback_command_handler_class_init (KkcCallbackCommandHandlerClass * klass,
                                         gpointer klass_data)
{
	kkc_callback_command_handler_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcCallbackCommandHandler_private_offset);
	G_OBJECT_CLASS (klass)->finalize = kkc_callback_command_handler_finalize;
}

static void
kkc_callback_command_handler_kkc_command_handler_interface_init (KkcCommandHandlerIface * iface,
                                                                 gpointer iface_data)
{
	kkc_callback_command_handler_kkc_command_handler_parent_iface = g_type_interface_peek_parent (iface);
	iface->call = (gboolean (*) (KkcCommandHandler*, const gchar*, KkcState*, KkcKeyEvent*)) kkc_callback_command_handler_real_call;
}

static void
kkc_callback_command_handler_instance_init (KkcCallbackCommandHandler * self,
                                            gpointer klass)
{
	self->priv = kkc_callback_command_handler_get_instance_private (self);
}

static void
kkc_callback_command_handler_finalize (GObject * obj)
{
	KkcCallbackCommandHandler * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_CALLBACK_COMMAND_HANDLER, KkcCallbackCommandHandler);
	G_OBJECT_CLASS (kkc_callback_command_handler_parent_class)->finalize (obj);
}

static GType
kkc_callback_command_handler_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcCallbackCommandHandlerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_callback_command_handler_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcCallbackCommandHandler), 0, (GInstanceInitFunc) kkc_callback_command_handler_instance_init, NULL };
	static const GInterfaceInfo kkc_command_handler_info = { (GInterfaceInitFunc) kkc_callback_command_handler_kkc_command_handler_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType kkc_callback_command_handler_type_id;
	kkc_callback_command_handler_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcCallbackCommandHandler", &g_define_type_info, 0);
	g_type_add_interface_static (kkc_callback_command_handler_type_id, KKC_TYPE_COMMAND_HANDLER, &kkc_command_handler_info);
	KkcCallbackCommandHandler_private_offset = g_type_add_instance_private (kkc_callback_command_handler_type_id, sizeof (KkcCallbackCommandHandlerPrivate));
	return kkc_callback_command_handler_type_id;
}

GType
kkc_callback_command_handler_get_type (void)
{
	static volatile gsize kkc_callback_command_handler_type_id__once = 0;
	if (g_once_init_enter (&kkc_callback_command_handler_type_id__once)) {
		GType kkc_callback_command_handler_type_id;
		kkc_callback_command_handler_type_id = kkc_callback_command_handler_get_type_once ();
		g_once_init_leave (&kkc_callback_command_handler_type_id__once, kkc_callback_command_handler_type_id);
	}
	return kkc_callback_command_handler_type_id__once;
}

static inline gpointer
kkc_state_handler_get_instance_private (KkcStateHandler* self)
{
	return G_STRUCT_MEMBER_P (self, KkcStateHandler_private_offset);
}

void
kkc_state_handler_register_command_handler (KkcStateHandler* self,
                                            const gchar* command,
                                            KkcCommandHandler* handler)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (handler != NULL);
	if (command != NULL) {
		GeeMap* _tmp0_;
		_tmp0_ = self->priv->command_handlers;
		gee_map_set (_tmp0_, command, handler);
	} else {
		KkcCommandHandler* _tmp1_;
		_tmp1_ = _g_object_ref0 (handler);
		_g_object_unref0 (self->priv->default_command_handler);
		self->priv->default_command_handler = _tmp1_;
	}
}

void
kkc_state_handler_register_command_callback (KkcStateHandler* self,
                                             const gchar* command,
                                             KkcCommandCallback cb,
                                             gpointer cb_target)
{
	KkcCallbackCommandHandler* _tmp0_;
	KkcCallbackCommandHandler* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = kkc_callback_command_handler_new (cb, cb_target);
	_tmp1_ = _tmp0_;
	kkc_state_handler_register_command_handler (self, command, (KkcCommandHandler*) _tmp1_);
	_g_object_unref0 (_tmp1_);
}

gboolean
kkc_state_handler_dispatch_command (KkcStateHandler* self,
                                    KkcState* state,
                                    KkcKeyEvent* key)
{
	gchar* command = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	KkcCommandHandler* _tmp11_;
	const gchar* _tmp12_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (state != NULL, FALSE);
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp0_ = kkc_state_lookup_key (state, key);
	command = _tmp0_;
	_tmp2_ = command;
	if (_tmp2_ != NULL) {
		GeeMap* _tmp3_;
		const gchar* _tmp4_;
		_tmp3_ = self->priv->command_handlers;
		_tmp4_ = command;
		_tmp1_ = gee_map_has_key (_tmp3_, _tmp4_);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GeeMap* _tmp5_;
		const gchar* _tmp6_;
		gpointer _tmp7_;
		KkcCommandHandler* _tmp8_;
		const gchar* _tmp9_;
		gboolean _tmp10_;
		_tmp5_ = self->priv->command_handlers;
		_tmp6_ = command;
		_tmp7_ = gee_map_get (_tmp5_, _tmp6_);
		_tmp8_ = (KkcCommandHandler*) _tmp7_;
		_tmp9_ = command;
		_tmp10_ = kkc_command_handler_call (_tmp8_, _tmp9_, state, key);
		_g_object_unref0 (_tmp8_);
		result = _tmp10_;
		_g_free0 (command);
		return result;
	}
	_tmp11_ = self->priv->default_command_handler;
	_tmp12_ = command;
	result = kkc_command_handler_call (_tmp11_, _tmp12_, state, key);
	_g_free0 (command);
	return result;
}

static gboolean
kkc_state_handler_real_process_key_event (KkcStateHandler* self,
                                          KkcState* state,
                                          KkcKeyEvent* key)
{
	gboolean _tmp0_ = FALSE;
	g_critical ("Type `%s' does not implement abstract method `kkc_state_handler_process_key_event'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return _tmp0_;
}

gboolean
kkc_state_handler_process_key_event (KkcStateHandler* self,
                                     KkcState* state,
                                     KkcKeyEvent* key)
{
	KkcStateHandlerClass* _klass_;
	g_return_val_if_fail (self != NULL, FALSE);
	_klass_ = KKC_STATE_HANDLER_GET_CLASS (self);
	if (_klass_->process_key_event) {
		return _klass_->process_key_event (self, state, key);
	}
	return FALSE;
}

KkcStateHandler*
kkc_state_handler_construct (GType object_type)
{
	KkcStateHandler * self = NULL;
	self = (KkcStateHandler*) g_object_new (object_type, NULL);
	return self;
}

static void
kkc_state_handler_class_init (KkcStateHandlerClass * klass,
                              gpointer klass_data)
{
	kkc_state_handler_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcStateHandler_private_offset);
	((KkcStateHandlerClass *) klass)->process_key_event = (gboolean (*) (KkcStateHandler*, KkcState*, KkcKeyEvent*)) kkc_state_handler_real_process_key_event;
	G_OBJECT_CLASS (klass)->finalize = kkc_state_handler_finalize;
}

static void
kkc_state_handler_instance_init (KkcStateHandler * self,
                                 gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = kkc_state_handler_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, KKC_TYPE_COMMAND_HANDLER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->command_handlers = (GeeMap*) _tmp0_;
	self->priv->default_command_handler = NULL;
}

static void
kkc_state_handler_finalize (GObject * obj)
{
	KkcStateHandler * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_STATE_HANDLER, KkcStateHandler);
	_g_object_unref0 (self->priv->command_handlers);
	_g_object_unref0 (self->priv->default_command_handler);
	G_OBJECT_CLASS (kkc_state_handler_parent_class)->finalize (obj);
}

static GType
kkc_state_handler_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcStateHandlerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_state_handler_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcStateHandler), 0, (GInstanceInitFunc) kkc_state_handler_instance_init, NULL };
	GType kkc_state_handler_type_id;
	kkc_state_handler_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcStateHandler", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	KkcStateHandler_private_offset = g_type_add_instance_private (kkc_state_handler_type_id, sizeof (KkcStateHandlerPrivate));
	return kkc_state_handler_type_id;
}

GType
kkc_state_handler_get_type (void)
{
	static volatile gsize kkc_state_handler_type_id__once = 0;
	if (g_once_init_enter (&kkc_state_handler_type_id__once)) {
		GType kkc_state_handler_type_id;
		kkc_state_handler_type_id = kkc_state_handler_get_type_once ();
		g_once_init_leave (&kkc_state_handler_type_id__once, kkc_state_handler_type_id);
	}
	return kkc_state_handler_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize 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,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

