decompiled_code:
__int64 dmp_tm_console_write()
{
if ( console_write )
return console_write();
g_assertion_message_expr(0LL, "dmp_trigger_module.c", 95LL, "dmp_tm_console_write", "console_write != NULL");
return dmp_tm_edit_config();
}

canonical_decompiled_code:
__int64 func7()
{
if ( console_write )
return console_write();
g_assertion_message_expr(0LL, "dmp_trigger_module.c", 95LL, "dmp_tm_console_write", "console_write != NULL");
return func8();
}

original_code:
int dmp_tm_console_write(const gchar * to_write)
{
 do { if (console_write != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "dmp_trigger_module.c", 95, ((const char*) (__func__)), "console_write != NULL"); } while (0);
 return (*console_write)(to_write);
}

canonical_original_code:
int dmp_tm_console_write(char *to_write)
{
 do { if (console_write != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "dmp_trigger_module.c", 95, ((char *) (__func__)), "console_write != NULL"); } while (0);
 return (*console_write)(to_write);
}


repo: christetreault/dmp-photo-booth

decompiled_code:
__int64 dmp_tm_call_trigger_handler()
{
if ( trigger_handler )
return trigger_handler();
g_assertion_message_expr(0LL, "dmp_trigger_module.c", 101LL, "dmp_tm_call_trigger_handler", "trigger_handler != NULL");
return dmp_tm_set_status();
}

canonical_decompiled_code:
__int64 func9()
{
if ( trigger_handler )
return trigger_handler();
g_assertion_message_expr(0LL, "dmp_trigger_module.c", 101LL, "dmp_tm_call_trigger_handler", "trigger_handler != NULL");
return func10();
}

original_code:
void dmp_tm_call_trigger_handler(void)
{
 do { if (trigger_handler != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "dmp_trigger_module.c", 101, ((const char*) (__func__)), "trigger_handler != NULL"); } while (0);
 (*trigger_handler)();
}

canonical_original_code:
void dmp_tm_call_trigger_handler()
{
 do { if (trigger_handler != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "dmp_trigger_module.c", 101, ((char *) (__func__)), "trigger_handler != NULL"); } while (0);
 (*trigger_handler)();
}

return_type: void


decompiled_code:
__int64 dmp_tm_set_status()
{
if ( !status_handler )
{
g_assertion_message_expr(0LL, "dmp_trigger_module.c", 107LL, "dmp_tm_set_status", "status_handler != NULL");
JUMPOUT(0x236LL);
}
return status_handler();
}

canonical_decompiled_code:
__int64 func10()
{
if ( !status_handler )
{
g_assertion_message_expr(0LL, "dmp_trigger_module.c", 107LL, "dmp_tm_set_status", "status_handler != NULL");
JUMPOUT(0x236LL);
}
return status_handler();
}

original_code:
void dmp_tm_set_status(gboolean status)
{
 do { if (status_handler != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "dmp_trigger_module.c", 107, ((const char*) (__func__)), "status_handler != NULL"); } while (0);
 (*status_handler)(status);
}

canonical_original_code:
void dmp_tm_set_status(int status)
{
 do { if (status_handler != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "dmp_trigger_module.c", 107, ((char *) (__func__)), "status_handler != NULL"); } while (0);
 (*status_handler)(status);
}

variable_types: status int


decompiled_code:
void __fastcall dmp_pb_config_initialize(__int64 a1)
{
__int64 v1; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
if ( !dmp_pb_config )
{
g_mutex_lock(&g__dmp_pb_config_lock);
dmp_pb_config = g_key_file_new();
if ( (unsigned int)g_file_test("dmp_photo_booth.rc", 16LL)
&& (g_key_file_load_from_file(dmp_pb_config, "dmp_photo_booth.rc", 3LL, &v1), v1) )
{
g_propagate_error(a1);
g_mutex_unlock(&g__dmp_pb_config_lock);
}
else
{
g_mutex_unlock(&g__dmp_pb_config_lock);
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
__int64 v1; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
if ( !dmp_pb_config )
{
g_mutex_lock(&g__dmp_pb_config_lock);
dmp_pb_config = g_key_file_new();
if ( (unsigned int)g_file_test("dmp_photo_booth.rc", 16LL)
&& (g_key_file_load_from_file(dmp_pb_config, "dmp_photo_booth.rc", 3LL, &v1), v1) )
{
g_propagate_error(a1);
g_mutex_unlock(&g__dmp_pb_config_lock);
}
else
{
g_mutex_unlock(&g__dmp_pb_config_lock);
}
}
}

original_code:
void dmp_pb_config_initialize(GError ** error)
{
 GError * working = ((void *)0);
 if (dmp_pb_config != ((void *)0)) return;
 g_mutex_lock (&g__dmp_pb_config_lock);
 dmp_pb_config = g_key_file_new();
 if (g_file_test("dmp_photo_booth.rc", G_FILE_TEST_EXISTS))
 {
  g_key_file_load_from_file(dmp_pb_config,
    "dmp_photo_booth.rc",
    G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
    &working);
  if (working != ((void *)0))
  {
   g_propagate_error(error, working);
   g_mutex_unlock (&g__dmp_pb_config_lock);
   return;
  }
 }
 g_mutex_unlock (&g__dmp_pb_config_lock);
}

canonical_original_code:
void dmp_pb_config_initialize(struct _GError **error)
{
 struct _GError *working = ((void *)0);
 if (dmp_pb_config != ((void *)0)) return;
 g_mutex_lock (&g__dmp_pb_config_lock);
 dmp_pb_config = g_key_file_new();
 if (g_file_test("dmp_photo_booth.rc", G_FILE_TEST_EXISTS))
 {
  g_key_file_load_from_file(dmp_pb_config,
    "dmp_photo_booth.rc",
    G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
    &working);
  if (working != ((void *)0))
  {
   g_propagate_error(error, working);
   g_mutex_unlock (&g__dmp_pb_config_lock);
   return;
  }
 }
 g_mutex_unlock (&g__dmp_pb_config_lock);
}

variable_types: struct _GError { unsigned int domain; int code; char *message; } **


decompiled_code:
__int64 dmp_pb_config_finalize()
{
__int64 result; // rax

if ( dmp_pb_config )
{
g_mutex_lock(&g__dmp_pb_config_lock);
g_key_file_free(dmp_pb_config);
result = g_mutex_unlock(&g__dmp_pb_config_lock);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

if ( dmp_pb_config )
{
g_mutex_lock(&g__dmp_pb_config_lock);
g_key_file_free(dmp_pb_config);
result = g_mutex_unlock(&g__dmp_pb_config_lock);
}
return result;
}

original_code:
void dmp_pb_config_finalize(void)
{
 if (dmp_pb_config == ((void *)0)) return;
 g_mutex_lock (&g__dmp_pb_config_lock);
 g_key_file_free(dmp_pb_config);
 g_mutex_unlock (&g__dmp_pb_config_lock);
}

canonical_original_code:
void dmp_pb_config_finalize()
{
 if (dmp_pb_config == ((void *)0)) return;
 g_mutex_lock (&g__dmp_pb_config_lock);
 g_key_file_free(dmp_pb_config);
 g_mutex_unlock (&g__dmp_pb_config_lock);
}


decompiled_code:
__int64 __fastcall dmp_pb_config_write(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

if ( dmp_pb_config )
{
v3 = 0LL;
g_mutex_lock(&g__dmp_pb_config_lock);
v1 = g_key_file_to_data(dmp_pb_config, 0LL, 0LL);
g_file_set_contents("dmp_photo_booth.rc", v1, -1LL, &v3);
result = g_mutex_unlock(&g__dmp_pb_config_lock);
if ( v3 )
result = g_propagate_error(a1);
}
else
{
g_assertion_message_expr(0LL, "configuration.c", 41LL, "dmp_pb_config_write", "dmp_pb_config != NULL");
result = dmp_pb_config_read_string();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

if ( dmp_pb_config )
{
v3 = 0LL;
g_mutex_lock(&g__dmp_pb_config_lock);
v1 = g_key_file_to_data(dmp_pb_config, 0LL, 0LL);
g_file_set_contents("dmp_photo_booth.rc", v1, -1LL, &v3);
result = g_mutex_unlock(&g__dmp_pb_config_lock);
if ( v3 )
result = g_propagate_error(a1);
}
else
{
g_assertion_message_expr(0LL, "configuration.c", 41LL, "dmp_pb_config_write", "dmp_pb_config != NULL");
result = func3();
}
return result;
}

original_code:
void dmp_pb_config_write(GError ** error)
{
 do { if (dmp_pb_config != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "configuration.c", 41, ((const char*) (__func__)), "dmp_pb_config != NULL"); } while (0);
 GError * working = ((void *)0);
 g_mutex_lock (&g__dmp_pb_config_lock);
 g_file_set_contents
   (
    "dmp_photo_booth.rc",
    g_key_file_to_data(dmp_pb_config, ((void *)0), ((void *)0)),
    -1,
    &working
   );
 g_mutex_unlock (&g__dmp_pb_config_lock);
 if (working != ((void *)0)) g_propagate_error(error, working);
 return;
}

canonical_original_code:
void dmp_pb_config_write(struct _GError **error)
{
 do { if (dmp_pb_config != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "configuration.c", 41, ((char *) (__func__)), "dmp_pb_config != NULL"); } while (0);
 struct _GError *working = ((void *)0);
 g_mutex_lock (&g__dmp_pb_config_lock);
 g_file_set_contents
   (
    "dmp_photo_booth.rc",
    g_key_file_to_data(dmp_pb_config, ((void *)0), ((void *)0)),
    -1,
    &working
   );
 g_mutex_unlock (&g__dmp_pb_config_lock);
 if (working != ((void *)0)) g_propagate_error(error, working);
 return;
}

variable_types: struct _GError { unsigned int domain; int code; char *message; } *


decompiled_code:
__int64 __fastcall dmp_pb_config_read_string(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

g_mutex_lock(&g__dmp_pb_config_lock);
v2 = g_key_file_get_string(dmp_pb_config, a1, a2, 0LL);
g_mutex_unlock(&g__dmp_pb_config_lock);
v3 = g_string_new(v2);
g_free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

g_mutex_lock(&g__dmp_pb_config_lock);
v2 = g_key_file_get_string(dmp_pb_config, a1, a2, 0LL);
g_mutex_unlock(&g__dmp_pb_config_lock);
v3 = g_string_new(v2);
g_free(v2);
return v3;
}

original_code:
GString * dmp_pb_config_read_string(const gchar * group, const gchar * key)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 gchar * working = g_key_file_get_string(dmp_pb_config, group, key, ((void *)0));
 g_mutex_unlock (&g__dmp_pb_config_lock);
 GString * return_value = g_string_new(working);
 g_free(working);
 return return_value;
}

canonical_original_code:
struct _GString *dmp_pb_config_read_string(char *group, char *key)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 char *working = g_key_file_get_string(dmp_pb_config, group, key, ((void *)0));
 g_mutex_unlock (&g__dmp_pb_config_lock);
 struct _GString *return_value = g_string_new(working);
 g_free(working);
 return return_value;
}

variable_types:
group
char *

variable_types:
key
char *

variable_types:
working
char *

variable_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; } *


decompiled_code:
__int64 __fastcall dmp_pb_config_write_string(__int64 a1, __int64 a2, _QWORD *a3)
{
g_mutex_lock(&g__dmp_pb_config_lock);
g_key_file_set_string(dmp_pb_config, a1, a2, *a3);
return g_mutex_unlock(&g__dmp_pb_config_lock);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, _QWORD *a3)
{
g_mutex_lock(&g__dmp_pb_config_lock);
g_key_file_set_string(dmp_pb_config, a1, a2, *a3);
return g_mutex_unlock(&g__dmp_pb_config_lock);
}

original_code:
void dmp_pb_config_write_string(const gchar * group, const gchar * key, const GString * value)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 g_key_file_set_string(dmp_pb_config, group, key, value->str);
 g_mutex_unlock (&g__dmp_pb_config_lock);
}

canonical_original_code:
void dmp_pb_config_write_string(char *group, char *key, struct _GString *value)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 g_key_file_set_string(dmp_pb_config, group, key, value->str);
 g_mutex_unlock (&g__dmp_pb_config_lock);
}

user_defined_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; }


decompiled_code:
__int64 __fastcall dmp_pb_config_read_int(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx

g_mutex_lock(&g__dmp_pb_config_lock);
v2 = g_key_file_get_integer(dmp_pb_config, a1, a2, 0LL);
g_mutex_unlock(&g__dmp_pb_config_lock);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
unsigned int v2; // ebx

g_mutex_lock(&g__dmp_pb_config_lock);
v2 = g_key_file_get_integer(dmp_pb_config, a1, a2, 0LL);
g_mutex_unlock(&g__dmp_pb_config_lock);
return v2;
}

original_code:
gint dmp_pb_config_read_int(const gchar * group, const gchar * key)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 gint return_value = g_key_file_get_integer(dmp_pb_config, group, key, ((void *)0));
 g_mutex_unlock (&g__dmp_pb_config_lock);
 return return_value;
}

canonical_original_code:
int dmp_pb_config_read_int(char *group, char *key)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 int return_value = g_key_file_get_integer(dmp_pb_config, group, key, ((void *)0));
 g_mutex_unlock (&g__dmp_pb_config_lock);
 return return_value;
}

return_type: int


decompiled_code:
__int64 __fastcall dmp_pb_config_write_int(__int64 a1, __int64 a2, unsigned int a3)
{
g_mutex_lock(&g__dmp_pb_config_lock);
g_key_file_set_integer(dmp_pb_config, a1, a2, a3);
return g_mutex_unlock(&g__dmp_pb_config_lock);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int a3)
{
g_mutex_lock(&g__dmp_pb_config_lock);
g_key_file_set_integer(dmp_pb_config, a1, a2, a3);
return g_mutex_unlock(&g__dmp_pb_config_lock);
}

original_code:
void dmp_pb_config_write_int(const gchar * group, const gchar * key, gint value)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 g_key_file_set_integer(dmp_pb_config, group, key, value);
 g_mutex_unlock (&g__dmp_pb_config_lock);
}

canonical_original_code:
void dmp_pb_config_write_int(char *group, char *key, int value)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 g_key_file_set_integer(dmp_pb_config, group, key, value);
 g_mutex_unlock (&g__dmp_pb_config_lock);
}

variable_types: value int


decompiled_code:
double __fastcall dmp_pb_config_read_double(__int64 a1, __int64 a2)
{
double v2; // rbx

g_mutex_lock(&g__dmp_pb_config_lock);
v2 = g_key_file_get_double(dmp_pb_config, a1, a2, 0LL);
g_mutex_unlock(&g__dmp_pb_config_lock);
return v2;
}

canonical_decompiled_code:
double __fastcall func7(__int64 a1, __int64 a2)
{
double v2; // rbx

g_mutex_lock(&g__dmp_pb_config_lock);
v2 = g_key_file_get_double(dmp_pb_config, a1, a2, 0LL);
g_mutex_unlock(&g__dmp_pb_config_lock);
return v2;
}

original_code:
gdouble dmp_pb_config_read_double(const gchar * group, const gchar * key)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 gdouble return_value = g_key_file_get_double(dmp_pb_config, group, key, ((void *)0));
 g_mutex_unlock (&g__dmp_pb_config_lock);
 return return_value;
}

canonical_original_code:
double dmp_pb_config_read_double(char *group, char *key)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 double return_value = g_key_file_get_double(dmp_pb_config, group, key, ((void *)0));
 g_mutex_unlock (&g__dmp_pb_config_lock);
 return return_value;
}

return_type: double


decompiled_code:
__int64 __fastcall dmp_pb_config_write_double(__int64 a1, __int64 a2, double a3)
{
g_mutex_lock(&g__dmp_pb_config_lock);
g_key_file_set_double(dmp_pb_config, a1, a2, a3);
return g_mutex_unlock(&g__dmp_pb_config_lock);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, double a3)
{
g_mutex_lock(&g__dmp_pb_config_lock);
g_key_file_set_double(dmp_pb_config, a1, a2, a3);
return g_mutex_unlock(&g__dmp_pb_config_lock);
}

original_code:
void dmp_pb_config_write_double(const gchar * group, const gchar * key, gdouble value)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 g_key_file_set_double(dmp_pb_config, group, key, value);
 g_mutex_unlock (&g__dmp_pb_config_lock);
}

canonical_original_code:
void dmp_pb_config_write_double(char *group, char *key, double value)
{
 g_mutex_lock (&g__dmp_pb_config_lock);
 g_key_file_set_double(dmp_pb_config, group, key, value);
 g_mutex_unlock (&g__dmp_pb_config_lock);
}

variable_types: value double


decompiled_code:
__int64 __fastcall dmp_pm_install_status_handler(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
status_handler = a1;
result = 0LL;
}
else
{
g_assertion_message_expr(0LL, "dmp_printer_module.c", 8LL, "dmp_pm_install_status_handler", "sh != NULL");
result = dmp_pm_install_console();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
status_handler = a1;
result = 0LL;
}
else
{
g_assertion_message_expr(0LL, "dmp_printer_module.c", 8LL, "dmp_pm_install_status_handler", "sh != NULL");
result = func1();
}
return result;
}

original_code:
int dmp_pm_install_status_handler(void (*sh)(int status))
{
 do { if (sh != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "dmp_printer_module.c", 8, ((const char*) (__func__)), "sh != NULL"); } while (0);
 status_handler = sh;
 return 0;
}

canonical_original_code:
int dmp_pm_install_status_handler(void (*sh)(int status))
{
 do { if (sh != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "dmp_printer_module.c", 8, ((char *) (__func__)), "sh != NULL"); } while (0);
 status_handler = sh;
 return 0;
}

variable_types:
sh
void (*)(int status)


decompiled_code:
__int64 __fastcall dmp_pm_install_console(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
console_write = a1;
result = 0LL;
}
else
{
g_assertion_message_expr(0LL, "dmp_printer_module.c", 17LL, "dmp_pm_install_console", "c_cb != NULL");
result = dmp_pm_print();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
console_write = a1;
result = 0LL;
}
else
{
g_assertion_message_expr(0LL, "dmp_printer_module.c", 17LL, "dmp_pm_install_console", "c_cb != NULL");
result = func2();
}
return result;
}

original_code:
int dmp_pm_install_console(int (*c_cb)(const char * message))
{
 do { if (c_cb != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "dmp_printer_module.c", 17, ((const char*) (__func__)), "c_cb != NULL"); } while (0);
 console_write = c_cb;
 return 0;
}

canonical_original_code:
int dmp_pm_install_console(int (*c_cb)(char *message))
{
 do { if (c_cb != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "dmp_printer_module.c", 17, ((char *) (__func__)), "c_cb != NULL"); } while (0);
 console_write = c_cb;
 return 0;
}


decompiled_code:
__int64 __fastcall dmp_pm_print(__int64 a1)
{
if ( a1 )
return dmp_pm_process_print();
g_assertion_message_expr(0LL, "dmp_printer_module.c", 26LL, "dmp_pm_print", "to_print != NULL");
return dmp_pm_initialize();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( a1 )
return dmp_pm_process_print();
g_assertion_message_expr(0LL, "dmp_printer_module.c", 26LL, "dmp_pm_print", "to_print != NULL");
return func3();
}

original_code:
int dmp_pm_print(const char * to_print)
{
 do { if (to_print != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "dmp_printer_module.c", 26, ((const char*) (__func__)), "to_print != NULL"); } while (0);
 return dmp_pm_process_print(to_print);
}

canonical_original_code:
int dmp_pm_print(char *to_print)
{
 do { if (to_print != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "dmp_printer_module.c", 26, ((char *) (__func__)), "to_print != NULL"); } while (0);
 return dmp_pm_process_print(to_print);
}


decompiled_code:
__int64 dmp_pm_initialize()
{
dmp_pm_config_init();
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
dmp_pm_config_init();
return 0LL;
}

original_code:
int dmp_pm_initialize(void)
{
 dmp_pm_config_init();
 return 0;
}

canonical_original_code:
int dmp_pm_initialize()
{
 dmp_pm_config_init();
 return 0;
}


decompiled_code:
__int64 dmp_pm_finalize()
{
dmp_pm_config_finalize();
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
dmp_pm_config_finalize();
return 0LL;
}

original_code:
int dmp_pm_finalize(void)
{
 dmp_pm_config_finalize();
 return 0;
}

canonical_original_code:
int dmp_pm_finalize()
{
 dmp_pm_config_finalize();
 return 0;
}


decompiled_code:
__int64 dmp_pm_console_write()
{
if ( console_write )
return console_write();
g_assertion_message_expr(0LL, "dmp_printer_module.c", 56LL, "dmp_pm_console_write", "console_write != NULL");
return dmp_pm_edit_config();
}

canonical_decompiled_code:
__int64 func5()
{
if ( console_write )
return console_write();
g_assertion_message_expr(0LL, "dmp_printer_module.c", 56LL, "dmp_pm_console_write", "console_write != NULL");
return func6();
}

original_code:
int dmp_pm_console_write(const gchar * to_write)
{
 do { if (console_write != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "dmp_printer_module.c", 56, ((const char*) (__func__)), "console_write != NULL"); } while (0);
 return (*console_write)(to_write);
}

canonical_original_code:
int dmp_pm_console_write(char *to_write)
{
 do { if (console_write != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "dmp_printer_module.c", 56, ((char *) (__func__)), "console_write != NULL"); } while (0);
 return (*console_write)(to_write);
}


decompiled_code:
__int64 dmp_pm_set_status()
{
if ( !status_handler )
{
g_assertion_message_expr(0LL, "dmp_printer_module.c", 62LL, "dmp_pm_set_status", "status_handler != NULL");
JUMPOUT(0x182LL);
}
return status_handler();
}

canonical_decompiled_code:
__int64 func7()
{
if ( !status_handler )
{
g_assertion_message_expr(0LL, "dmp_printer_module.c", 62LL, "dmp_pm_set_status", "status_handler != NULL");
JUMPOUT(0x182LL);
}
return status_handler();
}

original_code:
void dmp_pm_set_status(gboolean status)
{
 do { if (status_handler != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "dmp_printer_module.c", 62, ((const char*) (__func__)), "status_handler != NULL"); } while (0);
 (*status_handler)(status);
}

canonical_original_code:
void dmp_pm_set_status(int status)
{
 do { if (status_handler != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "dmp_printer_module.c", 62, ((char *) (__func__)), "status_handler != NULL"); } while (0);
 (*status_handler)(status);
}


decompiled_code:
__int64 dmp_tm_io_read_byte()
{
int v0; // eax
unsigned int v1; // edx
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = read(serial_descriptor, buf, 1uLL);
if ( v0 == -1 )
{
dmp_tm_console_write("Failed to read data from the trigger\n");
dmp_tm_set_status(0LL);
return (unsigned __int8)buf[0];
}
v1 = 0;
if ( v0 )
return (unsigned __int8)buf[0];
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
unsigned int v1; // edx
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

v0 = read(serial_descriptor, buf, 1uLL);
if ( v0 == -1 )
{
dmp_tm_console_write("Failed to read data from the trigger\n");
dmp_tm_set_status(0LL);
return (unsigned __int8)buf[0];
}
v1 = 0;
if ( v0 )
return (unsigned __int8)buf[0];
return v1;
}

original_code:
static guint8 dmp_tm_io_read_byte(void)
{
 char working[1];
 gint len = read(serial_descriptor, working, 1);
 if (len == -1)
 {
  dmp_tm_console_write("Failed to read data from the trigger\n");
  dmp_tm_set_status((0));
 }
 else if (len == 0) return 0;
 guint8 return_value = working[0];
 return return_value;
}

canonical_original_code:
static unsigned char dmp_tm_io_read_byte()
{
 char working[1];
 int len = read(serial_descriptor, working, 1);
 if (len == -1)
 {
  dmp_tm_console_write("Failed to read data from the trigger\n");
  dmp_tm_set_status((0));
 }
 else if (len == 0) return 0;
 unsigned char return_value = working[0];
 return return_value;
}

variable_types:
working
char [1]

variable_types: len int

return_type: unsigned char


decompiled_code:
__int64 dmp_tm_serial_io_error_quark()
{
if ( !q_0 )
q_0 = g_quark_from_static_string("DMP_TM_SERIAL_IO_ERROR");
return (unsigned int)q_0;
}

canonical_decompiled_code:
__int64 func1()
{
if ( !q_0 )
q_0 = g_quark_from_static_string("DMP_TM_SERIAL_IO_ERROR");
return (unsigned int)q_0;
}

original_code: GQuark dmp_tm_serial_io_error_quark (void) { static GQuark q; if (q == 0) q = g_quark_from_static_string ("DMP_TM_SERIAL_IO_ERROR"); return q; }

canonical_original_code: unsigned int dmp_tm_serial_io_error_quark() { static unsigned int q; if (q == 0) q = g_quark_from_static_string ("DMP_TM_SERIAL_IO_ERROR"); return q; }

variable_types:
q
unsigned int

return_type: unsigned int


decompiled_code:
ssize_t __fastcall dmp_tm_io_write_byte(char a1)
{
ssize_t result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = a1;
result = write(serial_descriptor, buf, 1uLL);
if ( (_DWORD)result != 1 )
{
dmp_tm_console_write("Failed to write data to the trigger\n");
result = dmp_tm_set_status(0LL);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(char a1)
{
ssize_t result; // rax
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = a1;
result = write(serial_descriptor, buf, 1uLL);
if ( (_DWORD)result != 1 )
{
dmp_tm_console_write("Failed to write data to the trigger\n");
result = dmp_tm_set_status(0LL);
}
return result;
}

original_code:
void dmp_tm_io_write_byte(gint8 in)
{
 gchar to_write = (gchar) in;
 if (write(serial_descriptor, &to_write, 1) != 1)
 {
  dmp_tm_console_write("Failed to write data to the trigger\n");
  dmp_tm_set_status((0));
 }
}

canonical_original_code:
void dmp_tm_io_write_byte(char in)
{
 char to_write = (gchar) in;
 if (write(serial_descriptor, &to_write, 1) != 1)
 {
  dmp_tm_console_write("Failed to write data to the trigger\n");
  dmp_tm_set_status((0));
 }
}

variable_types: in char


decompiled_code:
int dmp_tm_io_start_serial()
{
const char *v0; // rbx
__int64 v1; // rax

v0 = (const char *)dmp_tm_config_get_device_name();
serial_descriptor = open(v0, 258);
if ( serial_descriptor < 0 )
{
if ( *_errno_location() == 13 )
LODWORD(v1) = dmp_tm_console_write("Failed to open serial connection! Is the current user a member of the dailout group?\n");
else
LODWORD(v1) = dmp_tm_console_write("Failed to open serial connection!\n");
}
else
{
g_free(v0);
if ( tcgetattr(serial_descriptor, &saved_options) < 0 || tcgetattr(serial_descriptor, &trigger_options) < 0 )
{
dmp_tm_console_write("Failed to get serial attributes\n");
LODWORD(v1) = close(serial_descriptor);
}
else
{
cfsetispeed(&trigger_options, 0xDu);
cfsetospeed(&trigger_options, 0xDu);
trigger_options.c_cflag = trigger_options.c_cflag & 0x7FFFFE8F | 0x8B0;
trigger_options.c_iflag &= 0xFFFFE3FF;
trigger_options.c_lflag &= 0xFFFFFFE4;
trigger_options.c_oflag &= 0xFFFFFFFE;
trigger_options.c_cc[6] = 0;
trigger_options.c_cc[5] = 20;
if ( tcsetattr(serial_descriptor, 0, &trigger_options) < 0 )
{
dmp_tm_console_write("Failed to set serial attributes\n");
LODWORD(v1) = close(serial_descriptor);
}
else
{
g_usleep(3000000LL);
tcflush(serial_descriptor, 2);
dmp_tm_serial_io_thread_should_die = 0;
dmp_tm_set_status(1LL);
v1 = g_thread_new("serial thread", dmp_tm_serial_io_thread_function, 0LL);
dmp_tm_serial_io_thread = v1;
}
}
}
return v1;
}

canonical_decompiled_code:
int func3()
{
const char *v0; // rbx
__int64 v1; // rax

v0 = (const char *)dmp_tm_config_get_device_name();
serial_descriptor = open(v0, 258);
if ( serial_descriptor < 0 )
{
if ( *_errno_location() == 13 )
LODWORD(v1) = dmp_tm_console_write("Failed to open serial connection! Is the current user a member of the dailout group?\n");
else
LODWORD(v1) = dmp_tm_console_write("Failed to open serial connection!\n");
}
else
{
g_free(v0);
if ( tcgetattr(serial_descriptor, &saved_options) < 0 || tcgetattr(serial_descriptor, &trigger_options) < 0 )
{
dmp_tm_console_write("Failed to get serial attributes\n");
LODWORD(v1) = close(serial_descriptor);
}
else
{
cfsetispeed(&trigger_options, 0xDu);
cfsetospeed(&trigger_options, 0xDu);
trigger_options.c_cflag = trigger_options.c_cflag & 0x7FFFFE8F | 0x8B0;
trigger_options.c_iflag &= 0xFFFFE3FF;
trigger_options.c_lflag &= 0xFFFFFFE4;
trigger_options.c_oflag &= 0xFFFFFFFE;
trigger_options.c_cc[6] = 0;
trigger_options.c_cc[5] = 20;
if ( tcsetattr(serial_descriptor, 0, &trigger_options) < 0 )
{
dmp_tm_console_write("Failed to set serial attributes\n");
LODWORD(v1) = close(serial_descriptor);
}
else
{
g_usleep(3000000LL);
tcflush(serial_descriptor, 2);
dmp_tm_serial_io_thread_should_die = 0;
dmp_tm_set_status(1LL);
v1 = g_thread_new("serial thread", dmp_tm_serial_io_thread_function, 0LL);
dmp_tm_serial_io_thread = v1;
}
}
}
return v1;
}

original_code:
void dmp_tm_io_start_serial(void)
{
 gchar * serial_port = dmp_tm_config_get_device_name();
 if ((serial_descriptor = open(serial_port, 02 | 0400)) < 0)
 {
  if ((*__errno_location ()) == 13) dmp_tm_console_write("Failed to open serial connection! Is the current user a member of the dailout group?\n");
  else dmp_tm_console_write("Failed to open serial connection!\n");
  return;
 }
 g_free(serial_port);
 if (tcgetattr(serial_descriptor, &saved_options) < 0)
 {
  dmp_tm_console_write("Failed to get serial attributes\n");
  close(serial_descriptor);
  return;
 }
 if (tcgetattr(serial_descriptor, &trigger_options) < 0)
 {
  dmp_tm_console_write("Failed to get serial attributes\n");
  close(serial_descriptor);
  return;
 }
 cfsetispeed(&trigger_options, 0000015);
    cfsetospeed(&trigger_options, 0000015);
 trigger_options.c_cflag &= ~0000400;
    trigger_options.c_cflag &= ~0000100;
    trigger_options.c_cflag &= ~0000060;
    trigger_options.c_cflag |= 0000060;
    trigger_options.c_cflag &= ~020000000000;
    trigger_options.c_cflag |= 0000200 | 0004000;
    trigger_options.c_iflag &= ~(0002000 | 0010000 | 0004000);
    trigger_options.c_lflag &= ~(0000002 | 0000010 | 0000020 | 0000001);
    trigger_options.c_oflag &= ~0000001;
 trigger_options.c_cc[6] = 0;
    trigger_options.c_cc[5] = 20;
 if (tcsetattr(serial_descriptor, 0, &trigger_options) < 0)
 {
  dmp_tm_console_write("Failed to set serial attributes\n");
  close(serial_descriptor);
  return;
 }
 g_usleep(1000000 * 3);
 tcflush(serial_descriptor, 2);
 dmp_tm_serial_io_thread_should_die = (0);
 dmp_tm_set_status((!(0)));
 dmp_tm_serial_io_thread = g_thread_new("serial thread", dmp_tm_serial_io_thread_function, ((void *)0));
}

canonical_original_code:
void dmp_tm_io_start_serial()
{
 char *serial_port = dmp_tm_config_get_device_name();
 if ((serial_descriptor = open(serial_port, 02 | 0400)) < 0)
 {
  if ((*__errno_location ()) == 13) dmp_tm_console_write("Failed to open serial connection! Is the current user a member of the dailout group?\n");
  else dmp_tm_console_write("Failed to open serial connection!\n");
  return;
 }
 g_free(serial_port);
 if (tcgetattr(serial_descriptor, &saved_options) < 0)
 {
  dmp_tm_console_write("Failed to get serial attributes\n");
  close(serial_descriptor);
  return;
 }
 if (tcgetattr(serial_descriptor, &trigger_options) < 0)
 {
  dmp_tm_console_write("Failed to get serial attributes\n");
  close(serial_descriptor);
  return;
 }
 cfsetispeed(&trigger_options, 0000015);
    cfsetospeed(&trigger_options, 0000015);
 trigger_options.c_cflag &= ~0000400;
    trigger_options.c_cflag &= ~0000100;
    trigger_options.c_cflag &= ~0000060;
    trigger_options.c_cflag |= 0000060;
    trigger_options.c_cflag &= ~020000000000;
    trigger_options.c_cflag |= 0000200 | 0004000;
    trigger_options.c_iflag &= ~(0002000 | 0010000 | 0004000);
    trigger_options.c_lflag &= ~(0000002 | 0000010 | 0000020 | 0000001);
    trigger_options.c_oflag &= ~0000001;
 trigger_options.c_cc[6] = 0;
    trigger_options.c_cc[5] = 20;
 if (tcsetattr(serial_descriptor, 0, &trigger_options) < 0)
 {
  dmp_tm_console_write("Failed to set serial attributes\n");
  close(serial_descriptor);
  return;
 }
 g_usleep(1000000 * 3);
 tcflush(serial_descriptor, 2);
 dmp_tm_serial_io_thread_should_die = (0);
 dmp_tm_set_status((!(0)));
 dmp_tm_serial_io_thread = g_thread_new("serial thread", dmp_tm_serial_io_thread_function, ((void *)0));
}


decompiled_code:
int dmp_tm_io_stop_serial()
{
dmp_tm_serial_io_thread_should_die = 1;
dmp_tm_set_status(0LL);
g_thread_join(dmp_tm_serial_io_thread);
if ( tcsetattr(serial_descriptor, 0, &saved_options) < 0 )
dmp_tm_console_write("Failed to restore saved serial attributes\n");
return close(serial_descriptor);
}

canonical_decompiled_code:
int func4()
{
dmp_tm_serial_io_thread_should_die = 1;
dmp_tm_set_status(0LL);
g_thread_join(dmp_tm_serial_io_thread);
if ( tcsetattr(serial_descriptor, 0, &saved_options) < 0 )
dmp_tm_console_write("Failed to restore saved serial attributes\n");
return close(serial_descriptor);
}

original_code:
void dmp_tm_io_stop_serial(void)
{
 dmp_tm_serial_io_thread_should_die = (!(0));
 dmp_tm_set_status((0));
 g_thread_join(dmp_tm_serial_io_thread);
 if (tcsetattr(serial_descriptor, 0, &saved_options) < 0)
 {
  dmp_tm_console_write("Failed to restore saved serial attributes\n");
 }
 close(serial_descriptor);
}

canonical_original_code:
void dmp_tm_io_stop_serial()
{
 dmp_tm_serial_io_thread_should_die = (!(0));
 dmp_tm_set_status((0));
 g_thread_join(dmp_tm_serial_io_thread);
 if (tcsetattr(serial_descriptor, 0, &saved_options) < 0)
 {
  dmp_tm_console_write("Failed to restore saved serial attributes\n");
 }
 close(serial_descriptor);
}


decompiled_code:
_BOOL8 dmp_tm_io_thread_running()
{
return dmp_tm_serial_io_thread_should_die == 0;
}

canonical_decompiled_code:
_BOOL8 func5()
{
return dmp_tm_serial_io_thread_should_die == 0;
}

original_code:
gboolean dmp_tm_io_thread_running(void)
{
 return !dmp_tm_serial_io_thread_should_die;
}

canonical_original_code:
int dmp_tm_io_thread_running()
{
 return !dmp_tm_serial_io_thread_should_die;
}


decompiled_code:
__int64 dmp_tm_serial_io_thread_function()
{
while ( dmp_tm_io_thread_running() )
{
if ( (dmp_tm_io_read_byte() & 1) != 0 )
dmp_tm_call_trigger_handler();
}
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
while ( func5() )
{
if ( (func0() & 1) != 0 )
dmp_tm_call_trigger_handler();
}
return 0LL;
}

original_code:
static gpointer dmp_tm_serial_io_thread_function(gpointer user_data)
{
 guint8 read_value = 0;
 while (dmp_tm_io_thread_running())
 {
  read_value = dmp_tm_io_read_byte();
  if (read_value & OUTPUT_BUTTON_PRESS) dmp_tm_call_trigger_handler();
 }
 return ((void *)0);
}

canonical_original_code:
static void *dmp_tm_serial_io_thread_function(void *user_data)
{
 unsigned char read_value = 0;
 while (dmp_tm_io_thread_running())
 {
  read_value = dmp_tm_io_read_byte();
  if (read_value & OUTPUT_BUTTON_PRESS) dmp_tm_call_trigger_handler();
 }
 return ((void *)0);
}

return_type: void *


decompiled_code:
void dmp_pm_config_init()
{
_QWORD *v0; // rbx
__int64 v1; // rbp
const char *v2; // rax
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

v3[0] = 0LL;
if ( !dmp_pm_config )
{
dmp_pm_config = g_key_file_new();
if ( (unsigned int)g_file_test("dmp_printer_module.rc", 16LL)
&& (g_key_file_load_from_file(dmp_pm_config, "dmp_printer_module.rc", 3LL, v3), v3[0]) )
{
v0 = (_QWORD *)g_string_new(0LL);
v1 = v3[0];
v2 = (const char *)g_quark_to_string(*(unsigned int *)v3[0]);
g_string_printf(v0, "%s %d: %s\n", v2, *(unsigned int *)(v1 + 4), *(const char **)(v1 + 8));
dmp_pm_console_write(*v0);
g_string_free(v0, 1LL);
g_clear_error(v3);
dmp_pm_set_status(0LL);
}
else
{
dmp_pm_set_status(1LL);
}
}
}

canonical_decompiled_code:
void func0()
{
_QWORD *v0; // rbx
__int64 v1; // rbp
const char *v2; // rax
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

v3[0] = 0LL;
if ( !dmp_pm_config )
{
dmp_pm_config = g_key_file_new();
if ( (unsigned int)g_file_test("dmp_printer_module.rc", 16LL)
&& (g_key_file_load_from_file(dmp_pm_config, "dmp_printer_module.rc", 3LL, v3), v3[0]) )
{
v0 = (_QWORD *)g_string_new(0LL);
v1 = v3[0];
v2 = (const char *)g_quark_to_string(*(unsigned int *)v3[0]);
g_string_printf(v0, "%s %d: %s\n", v2, *(unsigned int *)(v1 + 4), *(const char **)(v1 + 8));
dmp_pm_console_write(*v0);
g_string_free(v0, 1LL);
g_clear_error(v3);
dmp_pm_set_status(0LL);
}
else
{
dmp_pm_set_status(1LL);
}
}
}

original_code:
void dmp_pm_config_init(void)
{
 GError * working = ((void *)0);
 GString * error_string;
 if (dmp_pm_config != ((void *)0)) return;
 dmp_pm_config = g_key_file_new();
 if (g_file_test("dmp_printer_module.rc", G_FILE_TEST_EXISTS))
 {
  g_key_file_load_from_file(dmp_pm_config,
    "dmp_printer_module.rc",
    G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
    &working);
  if (working != ((void *)0))
  {
   error_string = g_string_new(((void *)0));
   g_string_printf(error_string, "%s %d: %s\n", g_quark_to_string(working->domain),
    working->code, working->message);
   dmp_pm_console_write(error_string->str);
   g_string_free(error_string, (!(0)));
   g_clear_error(&working);
   dmp_pm_set_status((0));
   return;
  }
 }
 dmp_pm_set_status((!(0)));
}

canonical_original_code:
void dmp_pm_config_init()
{
 struct _GError *working = ((void *)0);
 struct _GString *error_string;
 if (dmp_pm_config != ((void *)0)) return;
 dmp_pm_config = g_key_file_new();
 if (g_file_test("dmp_printer_module.rc", G_FILE_TEST_EXISTS))
 {
  g_key_file_load_from_file(dmp_pm_config,
    "dmp_printer_module.rc",
    G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
    &working);
  if (working != ((void *)0))
  {
   error_string = g_string_new(((void *)0));
   g_string_printf(error_string, "%s %d: %s\n", g_quark_to_string(working->domain),
    working->code, working->message);
   dmp_pm_console_write(error_string->str);
   g_string_free(error_string, (!(0)));
   g_clear_error(&working);
   dmp_pm_set_status((0));
   return;
  }
 }
 dmp_pm_set_status((!(0)));
}

user_defined_types: struct _GError { unsigned int domain; int code; char *message; }


decompiled_code:
__int64 dmp_pm_config_finalize()
{
__int64 result; // rax

dmp_pm_set_status(0LL);
result = g_key_file_free(dmp_pm_config);
dmp_pm_config = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

dmp_pm_set_status(0LL);
result = g_key_file_free(dmp_pm_config);
dmp_pm_config = 0LL;
return result;
}

original_code:
void dmp_pm_config_finalize(void)
{
 dmp_pm_set_status((0));
 g_key_file_free(dmp_pm_config);
 dmp_pm_config = ((void *)0);
}

canonical_original_code:
void dmp_pm_config_finalize()
{
 dmp_pm_set_status((0));
 g_key_file_free(dmp_pm_config);
 dmp_pm_config = ((void *)0);
}


decompiled_code:
__int64 dmp_pm_config_get_dpi()
{
__int64 result; // rax
__int64 v1[2]; // [rsp+8h] [rbp-10h] BYREF

if ( dmp_pm_config )
{
v1[0] = 0LL;
result = (int)g_key_file_get_integer(dmp_pm_config, "Printer Module", "dpi", v1);
if ( !v1[0] )
return result;
}
else
{
g_assertion_message_expr(dmp_pm_config, "printer_config.c", 51LL, "dmp_pm_config_get_dpi", "dmp_pm_config != NULL");
}
g_clear_error(v1);
result = 72LL;
if ( !warned_7 )
{
dmp_pm_console_write("DPI not set in configuration! Defaulting to 72.\n");
warned_7 = 1;
result = 72LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
__int64 v1[2]; // [rsp+8h] [rbp-10h] BYREF

if ( dmp_pm_config )
{
v1[0] = 0LL;
result = (int)g_key_file_get_integer(dmp_pm_config, "Printer Module", "dpi", v1);
if ( !v1[0] )
return result;
}
else
{
g_assertion_message_expr(dmp_pm_config, "printer_config.c", 51LL, "dmp_pm_config_get_dpi", "dmp_pm_config != NULL");
}
g_clear_error(v1);
result = 72LL;
if ( !warned_7 )
{
dmp_pm_console_write("DPI not set in configuration! Defaulting to 72.\n");
warned_7 = 1;
result = 72LL;
}
return result;
}

original_code:
gsize dmp_pm_config_get_dpi(void)
{
 static gboolean warned = (0);
 do { if (dmp_pm_config != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "printer_config.c", 51, ((const char*) (__func__)), "dmp_pm_config != NULL"); } while (0);
 GError * error = ((void *)0);
 gsize return_value = g_key_file_get_integer(dmp_pm_config, "Printer Module", "dpi", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  if (!warned)
  {
   dmp_pm_console_write("DPI not set in configuration! Defaulting to 72.\n");
   warned = (!(0));
  }
  return 72;
 }
 return return_value;
}

canonical_original_code:
unsigned long dmp_pm_config_get_dpi()
{
 static int warned = (0);
 do { if (dmp_pm_config != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "printer_config.c", 51, ((char *) (__func__)), "dmp_pm_config != NULL"); } while (0);
 struct _GError *error = ((void *)0);
 unsigned long return_value = g_key_file_get_integer(dmp_pm_config, "Printer Module", "dpi", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  if (!warned)
  {
   dmp_pm_console_write("DPI not set in configuration! Defaulting to 72.\n");
   warned = (!(0));
  }
  return 72;
 }
 return return_value;
}

variable_types: warned int

return_type: unsigned long


decompiled_code:
__int64 dmp_pm_config_get_canvas_height()
{
__int64 result; // rax
__int64 v1[2]; // [rsp+8h] [rbp-10h] BYREF

if ( dmp_pm_config )
{
v1[0] = 0LL;
result = (int)g_key_file_get_integer(dmp_pm_config, "Printer Module", "height", v1);
if ( !v1[0] )
return result;
}
else
{
g_assertion_message_expr(
dmp_pm_config,
"printer_config.c",
72LL,
"dmp_pm_config_get_canvas_height",
"dmp_pm_config != NULL");
}
g_clear_error(v1);
result = 6LL;
if ( !warned_5 )
{
dmp_pm_console_write("Canvas Height not set in configuration! Defaulting to 6 Inches.\n");
warned_5 = 1;
result = 6LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
__int64 v1[2]; // [rsp+8h] [rbp-10h] BYREF

if ( dmp_pm_config )
{
v1[0] = 0LL;
result = (int)g_key_file_get_integer(dmp_pm_config, "Printer Module", "height", v1);
if ( !v1[0] )
return result;
}
else
{
g_assertion_message_expr(
dmp_pm_config,
"printer_config.c",
72LL,
"dmp_pm_config_get_canvas_height",
"dmp_pm_config != NULL");
}
g_clear_error(v1);
result = 6LL;
if ( !warned_5 )
{
dmp_pm_console_write("Canvas Height not set in configuration! Defaulting to 6 Inches.\n");
warned_5 = 1;
result = 6LL;
}
return result;
}

original_code:
gsize dmp_pm_config_get_canvas_height(void)
{
 static gboolean warned = (0);
 do { if (dmp_pm_config != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "printer_config.c", 72, ((const char*) (__func__)), "dmp_pm_config != NULL"); } while (0);
 GError * error = ((void *)0);
 gsize return_value = g_key_file_get_integer(dmp_pm_config, "Printer Module", "height", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  if (!warned)
  {
   dmp_pm_console_write("Canvas Height not set in configuration! Defaulting to 6 Inches.\n");
   warned = (!(0));
  }
  return 6;
 }
 return return_value;
}

canonical_original_code:
unsigned long dmp_pm_config_get_canvas_height()
{
 static int warned = (0);
 do { if (dmp_pm_config != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "printer_config.c", 72, ((char *) (__func__)), "dmp_pm_config != NULL"); } while (0);
 struct _GError *error = ((void *)0);
 unsigned long return_value = g_key_file_get_integer(dmp_pm_config, "Printer Module", "height", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  if (!warned)
  {
   dmp_pm_console_write("Canvas Height not set in configuration! Defaulting to 6 Inches.\n");
   warned = (!(0));
  }
  return 6;
 }
 return return_value;
}


decompiled_code:
__int64 dmp_pm_config_get_canvas_width()
{
__int64 result; // rax
__int64 v1[2]; // [rsp+8h] [rbp-10h] BYREF

if ( dmp_pm_config )
{
v1[0] = 0LL;
result = (int)g_key_file_get_integer(dmp_pm_config, "Printer Module", "width", v1);
if ( !v1[0] )
return result;
}
else
{
g_assertion_message_expr(
dmp_pm_config,
"printer_config.c",
93LL,
"dmp_pm_config_get_canvas_width",
"dmp_pm_config != NULL");
}
g_clear_error(v1);
result = 6LL;
if ( !warned_3 )
{
dmp_pm_console_write("Canvas Width not set in configuration! Defaulting to 6 Inches.\n");
warned_3 = 1;
result = 6LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
__int64 v1[2]; // [rsp+8h] [rbp-10h] BYREF

if ( dmp_pm_config )
{
v1[0] = 0LL;
result = (int)g_key_file_get_integer(dmp_pm_config, "Printer Module", "width", v1);
if ( !v1[0] )
return result;
}
else
{
g_assertion_message_expr(
dmp_pm_config,
"printer_config.c",
93LL,
"dmp_pm_config_get_canvas_width",
"dmp_pm_config != NULL");
}
g_clear_error(v1);
result = 6LL;
if ( !warned_3 )
{
dmp_pm_console_write("Canvas Width not set in configuration! Defaulting to 6 Inches.\n");
warned_3 = 1;
result = 6LL;
}
return result;
}

original_code:
gsize dmp_pm_config_get_canvas_width(void)
{
 static gboolean warned = (0);
 do { if (dmp_pm_config != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "printer_config.c", 93, ((const char*) (__func__)), "dmp_pm_config != NULL"); } while (0);
 GError * error = ((void *)0);
 gsize return_value = g_key_file_get_integer(dmp_pm_config, "Printer Module", "width", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  if (!warned)
  {
   dmp_pm_console_write("Canvas Width not set in configuration! Defaulting to 6 Inches.\n");
   warned = (!(0));
  }
  return 6;
 }
 return return_value;
}

canonical_original_code:
unsigned long dmp_pm_config_get_canvas_width()
{
 static int warned = (0);
 do { if (dmp_pm_config != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "printer_config.c", 93, ((char *) (__func__)), "dmp_pm_config != NULL"); } while (0);
 struct _GError *error = ((void *)0);
 unsigned long return_value = g_key_file_get_integer(dmp_pm_config, "Printer Module", "width", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  if (!warned)
  {
   dmp_pm_console_write("Canvas Width not set in configuration! Defaulting to 6 Inches.\n");
   warned = (!(0));
  }
  return 6;
 }
 return return_value;
}


decompiled_code:
const char *dmp_pm_config_get_printer_name()
{
const char *v0; // rbx
__int64 v2; // rax
_QWORD *v3; // rbp
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

if ( dmp_pm_config )
{
v4[0] = 0LL;
v0 = (const char *)g_key_file_get_string(dmp_pm_config, "Printer Module", "printer name", v4);
if ( !v4[0] )
return v0;
}
else
{
g_assertion_message_expr(
dmp_pm_config,
"printer_config.c",
114LL,
"dmp_pm_config_get_printer_name",
"dmp_pm_config != NULL");
}
g_clear_error(v4);
v2 = cupsGetDefault();
v0 = (const char *)g_strdup(v2);
if ( !warned_1 )
{
v3 = (_QWORD *)g_string_new(0LL);
g_string_printf(v3, "Printer Name not set in configuration! Defaulting to \"%s\".\n", v0);
dmp_pm_console_write(*v3);
warned_1 = 1;
g_string_free(v3, 1LL);
}
return v0;
}

canonical_decompiled_code:
const char *func5()
{
const char *v0; // rbx
__int64 v2; // rax
_QWORD *v3; // rbp
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

if ( dmp_pm_config )
{
v4[0] = 0LL;
v0 = (const char *)g_key_file_get_string(dmp_pm_config, "Printer Module", "printer name", v4);
if ( !v4[0] )
return v0;
}
else
{
g_assertion_message_expr(
dmp_pm_config,
"printer_config.c",
114LL,
"dmp_pm_config_get_printer_name",
"dmp_pm_config != NULL");
}
g_clear_error(v4);
v2 = cupsGetDefault();
v0 = (const char *)g_strdup(v2);
if ( !warned_1 )
{
v3 = (_QWORD *)g_string_new(0LL);
g_string_printf(v3, "Printer Name not set in configuration! Defaulting to \"%s\".\n", v0);
dmp_pm_console_write(*v3);
warned_1 = 1;
g_string_free(v3, 1LL);
}
return v0;
}

original_code:
gchar * dmp_pm_config_get_printer_name(void)
{
 static gboolean warned = (0);
 do { if (dmp_pm_config != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "printer_config.c", 114, ((const char*) (__func__)), "dmp_pm_config != NULL"); } while (0);
 GError * error = ((void *)0);
 GString * error_builder;
 gchar * return_value = g_key_file_get_string(dmp_pm_config, "Printer Module", "printer name", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  return_value = g_strdup(cupsGetDefault());
  if (!warned)
  {
   error_builder = g_string_new(((void *)0));
   g_string_printf(error_builder,
       "Printer Name not set in configuration! Defaulting to \"%s\".\n",
       return_value);
   dmp_pm_console_write(error_builder->str);
   warned = (!(0));
   g_string_free(error_builder, (!(0)));
  }
  return return_value;
 }
 return return_value;
}

canonical_original_code:
char *dmp_pm_config_get_printer_name()
{
 static int warned = (0);
 do { if (dmp_pm_config != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "printer_config.c", 114, ((char *) (__func__)), "dmp_pm_config != NULL"); } while (0);
 struct _GError *error = ((void *)0);
 struct _GString *error_builder;
 char *return_value = g_key_file_get_string(dmp_pm_config, "Printer Module", "printer name", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  return_value = g_strdup(cupsGetDefault());
  if (!warned)
  {
   error_builder = g_string_new(((void *)0));
   g_string_printf(error_builder,
       "Printer Name not set in configuration! Defaulting to \"%s\".\n",
       return_value);
   dmp_pm_console_write(error_builder->str);
   warned = (!(0));
   g_string_free(error_builder, (!(0)));
  }
  return return_value;
 }
 return return_value;
}

return_type: char *


decompiled_code:
__int64 dmp_pm_config_print_to_file()
{
__int64 result; // rax
__int64 v1[2]; // [rsp+8h] [rbp-10h] BYREF

if ( !dmp_pm_config )
{
g_assertion_message_expr(
dmp_pm_config,
"printer_config.c",
141LL,
"dmp_pm_config_print_to_file",
"dmp_pm_config != NULL");
goto LABEL_5;
}
v1[0] = 0LL;
result = g_key_file_get_boolean(dmp_pm_config, "Printer Module", "print to file", v1);
if ( v1[0] )
{
LABEL_5:
g_clear_error(v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
__int64 v1[2]; // [rsp+8h] [rbp-10h] BYREF

if ( !dmp_pm_config )
{
g_assertion_message_expr(
dmp_pm_config,
"printer_config.c",
141LL,
"dmp_pm_config_print_to_file",
"dmp_pm_config != NULL");
goto LABEL_5;
}
v1[0] = 0LL;
result = g_key_file_get_boolean(dmp_pm_config, "Printer Module", "print to file", v1);
if ( v1[0] )
{
LABEL_5:
g_clear_error(v1);
result = 0LL;
}
return result;
}

original_code:
gboolean dmp_pm_config_print_to_file(void)
{
 do { if (dmp_pm_config != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "printer_config.c", 141, ((const char*) (__func__)), "dmp_pm_config != NULL"); } while (0);
 GError * error = ((void *)0);
 gboolean return_value = g_key_file_get_boolean(dmp_pm_config, "Printer Module", "print to file", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  return (0);
 }
 return return_value;
}

canonical_original_code:
int dmp_pm_config_print_to_file()
{
 do { if (dmp_pm_config != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "printer_config.c", 141, ((char *) (__func__)), "dmp_pm_config != NULL"); } while (0);
 struct _GError *error = ((void *)0);
 int return_value = g_key_file_get_boolean(dmp_pm_config, "Printer Module", "print to file", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  return (0);
 }
 return return_value;
}


decompiled_code:
unsigned __int64 __fastcall dmp_pm_find_center_origin(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 >= a2 )
result = (a1 >> 1) - (a2 >> 1);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

result = 0LL;
if ( a1 >= a2 )
result = (a1 >> 1) - (a2 >> 1);
return result;
}

original_code:
static gsize dmp_pm_find_center_origin(gsize canvas_width, gsize image_width)
{
 if (canvas_width < image_width) return 0;
 return (canvas_width / 2) - (image_width / 2);
}

canonical_original_code:
static unsigned long dmp_pm_find_center_origin(unsigned long canvas_width, unsigned long image_width)
{
 if (canvas_width < image_width) return 0;
 return (canvas_width / 2) - (image_width / 2);
}


decompiled_code:
__int64 __fastcall dmp_pm_resolve_dests_index(_QWORD *a1, int a2, const char *a3)
{
unsigned int v5; // ebp
__int64 v6; // rbx
__int64 v7; // rax

if ( a2 <= 0 )
{
LABEL_5:
v6 = g_string_new(0LL);
g_string_printf(v6, "Invalid printer name: \"%s\"!\n", a3);
v7 = g_string_free(v6, 0LL);
dmp_pm_console_write(v7);
v5 = -1;
}
else
{
v5 = 0;
while ( (unsigned int)g_strcmp0(a3, *a1) )
{
++v5;
a1 += 4;
if ( a2 == v5 )
goto LABEL_5;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, int a2, const char *a3)
{
unsigned int v5; // ebp
__int64 v6; // rbx
__int64 v7; // rax

if ( a2 <= 0 )
{
LABEL_5:
v6 = g_string_new(0LL);
g_string_printf(v6, "Invalid printer name: \"%s\"!\n", a3);
v7 = g_string_free(v6, 0LL);
dmp_pm_console_write(v7);
v5 = -1;
}
else
{
v5 = 0;
while ( (unsigned int)g_strcmp0(a3, *a1) )
{
++v5;
a1 += 4;
if ( a2 == v5 )
goto LABEL_5;
}
}
return v5;
}

original_code:
static gint dmp_pm_resolve_dests_index(const cups_dest_t * to_resolve,
          gint num_dests,
          const gchar * name)
{
 int count;
 for (count = 0; count < num_dests; ++count)
 {
  if (g_strcmp0(name, to_resolve[count].name) == 0) return count;
 }
 GString * working = g_string_new(((void *)0));
 g_string_printf(working, "Invalid printer name: \"%s\"!\n", name);
 dmp_pm_console_write(g_string_free(working, (0)));
 return -1;
}

canonical_original_code:
static int dmp_pm_resolve_dests_index(struct cups_dest_s *to_resolve, int num_dests, char *name)
{
 int count;
 for (count = 0; count < num_dests; ++count)
 {
  if (g_strcmp0(name, to_resolve[count].name) == 0) return count;
 }
 struct _GString *working = g_string_new(((void *)0));
 g_string_printf(working, "Invalid printer name: \"%s\"!\n", name);
 dmp_pm_console_write(g_string_free(working, (0)));
 return -1;
}

variable_types: struct cups_dest_s { char *name; int is_default; int num_options; struct cups_option_s { char *name; char *value; } *options; } *

variable_types:
name
char *

variable_types: count int

user_defined_types: struct cups_dest_s { char *name; int is_default; int num_options; struct cups_option_s *options; }


decompiled_code:
void dmp_tm_config_init()
{
__int64 v0[2]; // [rsp+8h] [rbp-10h] BYREF

v0[0] = 0LL;
if ( !dmp_tm_config )
{
dmp_tm_config = g_key_file_new();
if ( (unsigned int)g_file_test("dmp_trigger_module.rc", 16LL) )
{
g_key_file_load_from_file(dmp_tm_config, "dmp_trigger_module.rc", 3LL, v0);
if ( v0[0] )
{
dmp_tm_lifecycle_push_error();
g_clear_error(v0);
}
}
}
}

canonical_decompiled_code:
void func0()
{
__int64 v0[2]; // [rsp+8h] [rbp-10h] BYREF

v0[0] = 0LL;
if ( !dmp_tm_config )
{
dmp_tm_config = g_key_file_new();
if ( (unsigned int)g_file_test("dmp_trigger_module.rc", 16LL) )
{
g_key_file_load_from_file(dmp_tm_config, "dmp_trigger_module.rc", 3LL, v0);
if ( v0[0] )
{
dmp_tm_lifecycle_push_error();
g_clear_error(v0);
}
}
}
}

original_code:
void dmp_tm_config_init(void)
{
 GError * working = ((void *)0);
 if (dmp_tm_config != ((void *)0)) return;
 dmp_tm_config = g_key_file_new();
 if (g_file_test("dmp_trigger_module.rc", G_FILE_TEST_EXISTS))
 {
  g_key_file_load_from_file(dmp_tm_config,
    "dmp_trigger_module.rc",
    G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
    &working);
  if (working != ((void *)0))
  {
   dmp_tm_lifecycle_push_error(working);
   g_clear_error(&working);
  }
 }
}

canonical_original_code:
void dmp_tm_config_init()
{
 struct _GError *working = ((void *)0);
 if (dmp_tm_config != ((void *)0)) return;
 dmp_tm_config = g_key_file_new();
 if (g_file_test("dmp_trigger_module.rc", G_FILE_TEST_EXISTS))
 {
  g_key_file_load_from_file(dmp_tm_config,
    "dmp_trigger_module.rc",
    G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
    &working);
  if (working != ((void *)0))
  {
   dmp_tm_lifecycle_push_error(working);
   g_clear_error(&working);
  }
 }
}


decompiled_code:
__int64 dmp_tm_config_finalize()
{
return g_key_file_free(dmp_tm_config);
}

canonical_decompiled_code:
__int64 func1()
{
return g_key_file_free(dmp_tm_config);
}

original_code:
void dmp_tm_config_finalize(void)
{
 g_key_file_free(dmp_tm_config);
}

canonical_original_code:
void dmp_tm_config_finalize()
{
 g_key_file_free(dmp_tm_config);
}


decompiled_code:
_BOOL8 dmp_tm_config_is_initialized()
{
return dmp_tm_config != 0;
}

canonical_decompiled_code:
_BOOL8 func2()
{
return dmp_tm_config != 0;
}

original_code:
gboolean dmp_tm_config_is_initialized(void)
{
 return (dmp_tm_config != ((void *)0));
}

canonical_original_code:
int dmp_tm_config_is_initialized()
{
 return (dmp_tm_config != ((void *)0));
}


decompiled_code:
__int64 __fastcall dmp_tm_config_get_device_name()
{
__int64 v0; // rbx
_QWORD *v2; // rbp
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !dmp_tm_config_is_initialized() )
{
g_assertion_message_expr(
0LL,
"trigger_config.c",
42LL,
"dmp_tm_config_get_device_name",
"dmp_tm_config_is_initialized()");
LABEL_6:
v2 = (_QWORD *)g_string_new(0LL);
g_string_printf(v2, "Device Name not set in configuration! Defaulting to \"/dev/ttyACM0\".\n");
dmp_tm_console_write(*v2);
warned_0 = 1;
g_string_free(v2, 1LL);
return v0;
}
v3[0] = 0LL;
v0 = g_key_file_get_string(dmp_tm_config, "Trigger Module", "device name", v3);
if ( v3[0] )
{
g_clear_error(v3);
v0 = g_strdup("/dev/ttyACM0");
if ( !warned_0 )
goto LABEL_6;
}
return v0;
}

canonical_decompiled_code:
__int64 __fastcall func3()
{
__int64 v0; // rbx
_QWORD *v2; // rbp
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !func2() )
{
g_assertion_message_expr(
0LL,
"trigger_config.c",
42LL,
"dmp_tm_config_get_device_name",
"dmp_tm_config_is_initialized()");
LABEL_6:
v2 = (_QWORD *)g_string_new(0LL);
g_string_printf(v2, "Device Name not set in configuration! Defaulting to \"/dev/ttyACM0\".\n");
dmp_tm_console_write(*v2);
warned_0 = 1;
g_string_free(v2, 1LL);
return v0;
}
v3[0] = 0LL;
v0 = g_key_file_get_string(dmp_tm_config, "Trigger Module", "device name", v3);
if ( v3[0] )
{
g_clear_error(v3);
v0 = g_strdup("/dev/ttyACM0");
if ( !warned_0 )
goto LABEL_6;
}
return v0;
}

original_code:
gchar * dmp_tm_config_get_device_name(void)
{
 static gboolean warned = (0);
 do { if (dmp_tm_config_is_initialized()) ; else g_assertion_message_expr (((gchar*) 0), "trigger_config.c", 42, ((const char*) (__func__)), "dmp_tm_config_is_initialized()"); } while (0);
 GError * error = ((void *)0);
 GString * error_builder;
 gchar * return_value = g_key_file_get_string(dmp_tm_config, "Trigger Module", "device name", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  return_value = g_strdup("/dev/ttyACM0");
  if (!warned)
  {
   error_builder = g_string_new(((void *)0));
   g_string_printf(error_builder,
       "Device Name not set in configuration! Defaulting to \"/dev/ttyACM0\".\n");
   dmp_tm_console_write(error_builder->str);
   warned = (!(0));
   g_string_free(error_builder, (!(0)));
  }
 }
 return return_value;
}

canonical_original_code:
char *dmp_tm_config_get_device_name()
{
 static int warned = (0);
 do { if (dmp_tm_config_is_initialized()) ; else g_assertion_message_expr (((char *) 0), "trigger_config.c", 42, ((char *) (__func__)), "dmp_tm_config_is_initialized()"); } while (0);
 struct _GError *error = ((void *)0);
 struct _GString *error_builder;
 char *return_value = g_key_file_get_string(dmp_tm_config, "Trigger Module", "device name", &error);
 if (error != ((void *)0))
 {
  g_clear_error(&error);
  return_value = g_strdup("/dev/ttyACM0");
  if (!warned)
  {
   error_builder = g_string_new(((void *)0));
   g_string_printf(error_builder,
       "Device Name not set in configuration! Defaulting to \"/dev/ttyACM0\".\n");
   dmp_tm_console_write(error_builder->str);
   warned = (!(0));
   g_string_free(error_builder, (!(0)));
  }
 }
 return return_value;
}


decompiled_code:
__int64 __fastcall dmp_tm_lifecycle_push_error(const char **a1)
{
_QWORD *v1; // rbp
const char *v2; // rax
__int64 result; // rax

if ( a1 )
{
v1 = (_QWORD *)g_string_new(0LL);
v2 = (const char *)g_quark_to_string(*(unsigned int *)a1);
g_string_printf(v1, "%s %d: %s\n", v2, *((unsigned int *)a1 + 1), a1[1]);
dmp_tm_console_write(*v1);
result = g_string_free(v1, 1LL);
}
else
{
g_assertion_message_expr(0LL, "lifecycle.c", 7LL, "dmp_tm_lifecycle_push_error", "error != NULL");
result = dmp_tm_lifecycle_initialize();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
_QWORD *v1; // rbp
const char *v2; // rax
__int64 result; // rax

if ( a1 )
{
v1 = (_QWORD *)g_string_new(0LL);
v2 = (const char *)g_quark_to_string(*(unsigned int *)a1);
g_string_printf(v1, "%s %d: %s\n", v2, *((unsigned int *)a1 + 1), a1[1]);
dmp_tm_console_write(*v1);
result = g_string_free(v1, 1LL);
}
else
{
g_assertion_message_expr(0LL, "lifecycle.c", 7LL, "dmp_tm_lifecycle_push_error", "error != NULL");
result = func1();
}
return result;
}

original_code:
void dmp_tm_lifecycle_push_error(const GError * error)
{
 do { if (error != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "lifecycle.c", 7, ((const char*) (__func__)), "error != NULL"); } while (0);
 GString * message = g_string_new(((void *)0));
 g_string_printf(message, "%s %d: %s\n", g_quark_to_string(error->domain),
    error->code, error->message);
 dmp_tm_console_write(message->str);
 g_string_free(message, (!(0)));
}

canonical_original_code:
void dmp_tm_lifecycle_push_error(struct _GError *error)
{
 do { if (error != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "lifecycle.c", 7, ((char *) (__func__)), "error != NULL"); } while (0);
 struct _GString *message = g_string_new(((void *)0));
 g_string_printf(message, "%s %d: %s\n", g_quark_to_string(error->domain),
    error->code, error->message);
 dmp_tm_console_write(message->str);
 g_string_free(message, (!(0)));
}


decompiled_code:
__int64 dmp_tm_lifecycle_initialize()
{
if ( !is_initialized )
{
dmp_tm_io_start_serial();
is_initialized = 1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
if ( !is_initialized )
{
dmp_tm_io_start_serial();
is_initialized = 1;
}
return 0LL;
}

original_code:
gint dmp_tm_lifecycle_initialize(void)
{
 if (is_initialized) return 0;
 dmp_tm_io_start_serial();
 is_initialized = (!(0));
 return 0;
}

canonical_original_code:
int dmp_tm_lifecycle_initialize()
{
 if (is_initialized) return 0;
 dmp_tm_io_start_serial();
 is_initialized = (!(0));
 return 0;
}


decompiled_code:
__int64 dmp_tm_lifecycle_finalize()
{
dmp_tm_io_stop_serial();
is_initialized = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
dmp_tm_io_stop_serial();
is_initialized = 0;
return 0LL;
}

original_code:
gint dmp_tm_lifecycle_finalize(void)
{
 dmp_tm_io_stop_serial();
 is_initialized = (0);
 return 0;
}

canonical_original_code:
int dmp_tm_lifecycle_finalize()
{
 dmp_tm_io_stop_serial();
 is_initialized = (0);
 return 0;
}


decompiled_code:
__int64 __fastcall dmp_pb_error_to_string(const char **a1)
{
__int64 v1; // rbp
const char *v2; // rax

if ( !a1 )
{
g_assertion_message_expr(0LL, "error_handling.c", 5LL, "dmp_pb_error_to_string", "error != NULL");
JUMPOUT(0x67LL);
}
v1 = g_string_new(0LL);
v2 = (const char *)g_quark_to_string(*(unsigned int *)a1);
g_string_printf(v1, "%s %d: %s\n", v2, *((unsigned int *)a1 + 1), a1[1]);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
__int64 v1; // rbp
const char *v2; // rax

if ( !a1 )
{
g_assertion_message_expr(0LL, "error_handling.c", 5LL, "dmp_pb_error_to_string", "error != NULL");
JUMPOUT(0x67LL);
}
v1 = g_string_new(0LL);
v2 = (const char *)g_quark_to_string(*(unsigned int *)a1);
g_string_printf(v1, "%s %d: %s\n", v2, *((unsigned int *)a1 + 1), a1[1]);
return v1;
}

original_code:
GString * dmp_pb_error_to_string(const GError * error)
{
 do { if (error != ((void *)0)) ; else g_assertion_message_expr (((gchar*) 0), "error_handling.c", 5, ((const char*) (__func__)), "error != NULL"); } while (0);
 GString * message = g_string_new(((void *)0));
 g_string_printf(message, "%s %d: %s\n", g_quark_to_string(error->domain),
    error->code, error->message);
 return message;
}

canonical_original_code:
struct _GString *dmp_pb_error_to_string(struct _GError *error)
{
 do { if (error != ((void *)0)) ; else g_assertion_message_expr (((char *) 0), "error_handling.c", 5, ((char *) (__func__)), "error != NULL"); } while (0);
 struct _GString *message = g_string_new(((void *)0));
 g_string_printf(message, "%s %d: %s\n", g_quark_to_string(error->domain),
    error->code, error->message);
 return message;
}

return_type: struct _GString { char *str; unsigned long len; unsigned long allocated_len; } *


original_code:
static inline int64_t ts_to_int64(struct timespec ts) {
 return ts.tv_sec * 1000000000L + ts.tv_nsec;
}

canonical_original_code:
static inline long ts_to_int64(struct timespec ts) {
 return ts.tv_sec * 1000000000L + ts.tv_nsec;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: long


decompiled_code:
__int64 __fastcall get_reference_clock(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0xB )
result = 4LL;
else
result = 4 * (unsigned int)(((1LL << a1) & 0x921) == 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
__int64 result; // rax

if ( a1 > 0xB )
result = 4LL;
else
result = 4 * (unsigned int)(((1LL << a1) & 0x921) == 0);
return result;
}

original_code:
static clockid_t get_reference_clock(clockid_t clockid) {
 switch (clockid) {
 case 0:
 case 5:
 case 8:
 case 11:
  return 0;
 default:
  return 4;
 }
}

canonical_original_code:
static int get_reference_clock(int clockid) {
 switch (clockid) {
 case 0:
 case 5:
 case 8:
 case 11:
  return 0;
 default:
  return 4;
 }
}

variable_types: clockid int


initialize

decompiled_code:
int initialize()
{
return pthread_once(&once_0, do_initialize);
}

canonical_decompiled_code:
int func8()
{
return pthread_once(&once_0, do_initialize);
}

original_code:
static void initialize(void) {
 static pthread_once_t once = 0;
 pthread_once(&once, &do_initialize);
}

canonical_original_code:
static void initialize() {
 static int once = 0;
 pthread_once(&once, &do_initialize);
}

variable_types: once int


decompiled_code:
void do_initialize(void)
{
char *v0; // rax
double v1; // xmm0_8
char *v2; // rax
struct tm v3; // [rsp+0h] [rbp-48h] BYREF

v0 = getenv("SLOWER_FACTOR");
if ( v0 )
{
v1 = strtod(v0, 0LL);
if ( v1 >= 0.01 && v1 <= 100.0 )
*(double *)&g_factor = 1.0 / v1;
}
real_clock_gettime = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "clock_gettime");
real_clock_gettime(4LL, &v3);
qword_40E0 = ts_to_int64(*(__int64 *)&v3.tm_sec, *(__int64 *)&v3.tm_hour);
qword_40E8 = qword_40E0;
real_clock_gettime(0LL, &v3);
g_clocks = ts_to_int64(*(__int64 *)&v3.tm_sec, *(__int64 *)&v3.tm_hour);
qword_40A8 = g_clocks;
v2 = getenv("SLOWER_TIME");
if ( v2 )
{
if ( strptime(v2, "%Y-%m-%d %H:%M:%S", &v3) )
qword_40A8 = 1000000000 * mktime(&v3);
}
}

canonical_decompiled_code:
void func9(void)
{
char *v0; // rax
double v1; // xmm0_8
char *v2; // rax
struct tm v3; // [rsp+0h] [rbp-48h] BYREF

v0 = getenv("SLOWER_FACTOR");
if ( v0 )
{
v1 = strtod(v0, 0LL);
if ( v1 >= 0.01 && v1 <= 100.0 )
*(double *)&g_factor = 1.0 / v1;
}
real_clock_gettime = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "clock_gettime");
real_clock_gettime(4LL, &v3);
qword_40E0 = func6(*(__int64 *)&v3.tm_sec, *(__int64 *)&v3.tm_hour);
qword_40E8 = qword_40E0;
real_clock_gettime(0LL, &v3);
g_clocks = func6(*(__int64 *)&v3.tm_sec, *(__int64 *)&v3.tm_hour);
qword_40A8 = g_clocks;
v2 = getenv("SLOWER_TIME");
if ( v2 )
{
if ( strptime(v2, "%Y-%m-%d %H:%M:%S", &v3) )
qword_40A8 = 1000000000 * mktime(&v3);
}
}

original_code:
static void do_initialize(void) {
 const char *mul_s = getenv("SLOWER_FACTOR");
 if (mul_s) {
  double mul = strtod(mul_s, ((void *)0));
  if ((mul >= 0.01) && (mul <= 100))
   g_factor = 1. / mul;
 }
 real_clock_gettime = dlsym(((void *) -1l), "clock_gettime");
 {
  struct timespec ts;
  real_clock_gettime(4, &ts);
  g_clocks[4].init_time = ts_to_int64(ts);
  g_clocks[4].fake_init_time = g_clocks[4].init_time;
 }
 {
  struct timespec ts;
  real_clock_gettime(0, &ts);
  g_clocks[0].init_time = ts_to_int64(ts);
  g_clocks[0].fake_init_time = g_clocks[0].init_time;
 }
 const char *time_s = getenv("SLOWER_TIME");
 if (time_s) {
  struct tm tm;
  if (strptime(time_s, "%Y-%m-%d %H:%M:%S", &tm) != ((void *)0)) {
   g_clocks[0].fake_init_time = mktime(&tm) * 1000000000L;
  }
 }
}

canonical_original_code:
static void do_initialize() {
 char *mul_s = getenv("SLOWER_FACTOR");
 if (mul_s) {
  double mul = strtod(mul_s, ((void *)0));
  if ((mul >= 0.01) && (mul <= 100))
   g_factor = 1. / mul;
 }
 real_clock_gettime = dlsym(((void *) -1l), "clock_gettime");
 {
  struct timespec ts;
  real_clock_gettime(4, &ts);
  g_clocks[4].init_time = ts_to_int64(ts);
  g_clocks[4].fake_init_time = g_clocks[4].init_time;
 }
 {
  struct timespec ts;
  real_clock_gettime(0, &ts);
  g_clocks[0].init_time = ts_to_int64(ts);
  g_clocks[0].fake_init_time = g_clocks[0].init_time;
 }
 char *time_s = getenv("SLOWER_TIME");
 if (time_s) {
  struct tm tm;
  if (strptime(time_s, "%Y-%m-%d %H:%M:%S", &tm) != ((void *)0)) {
   g_clocks[0].fake_init_time = mktime(&tm) * 1000000000L;
  }
 }
}

variable_types: mul double

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__int64 __fastcall hack_clock_gettime(unsigned int a1, __int64 *a2)
{
unsigned int v2; // er13
unsigned int v3; // er12
__int64 v4; // r14
__int64 v5; // r15
__int64 v6; // rax
__int64 *v7; // rdx
__int64 v8; // rcx
__int64 v9; // rdx
__int64 v10; // rcx

initialize();
if ( a1 > 0xB )
return (unsigned int)real_clock_gettime(a1, a2);
if ( !g_clocks[2 * (int)a1] && !g_clocks[2 * (int)a1 + 1] )
{
v2 = get_reference_clock(a1);
v3 = real_clock_gettime(v2, a2);
if ( v3 )
return v3;
v4 = ts_to_int64(*a2, a2[1]);
v5 = g_clocks[2 * (int)v2];
v3 = real_clock_gettime(a1, a2);
if ( v3 )
return v3;
v6 = ts_to_int64(*a2, a2[1]) - (v4 - v5);
v7 = &g_clocks[2 * (int)a1];
*v7 = v6;
v7[1] = g_clocks[2 * (int)v2 + 1] + v6 - g_clocks[2 * (int)v2];
}
v3 = real_clock_gettime(a1, a2);
if ( !v3 )
{
v8 = g_clocks[2 * (int)a1 + 1]
+ (unsigned int)(int)((double)(int)(ts_to_int64(*a2, a2[1]) - LODWORD(g_clocks[2 * (int)a1]))
* *(double *)&g_factor);
v9 = v8 / 1000000000;
*a2 = v8 / 1000000000;
v10 = v8 % 1000000000;
a2[1] = v10;
if ( v10 < 0 )
{
*a2 = v9 - 1;
a2[1] = v10 + 1000000000;
}
}
return v3;
}

original_code:
static int hack_clock_gettime(clockid_t clockid, struct timespec *ts) {
 initialize();
 if (clockid < 0 || clockid >= 12) {
  return real_clock_gettime(clockid, ts);
 }
 clockid_t clockid_ref = get_reference_clock(clockid);
 ClockInfo *clock_ref = &g_clocks[clockid_ref];
 ClockInfo *clock = &g_clocks[clockid];
 if (clock->init_time == 0 && clock->fake_init_time == 0) {
  int ret = real_clock_gettime(clockid_ref, ts);
  if (ret != 0) {
   return ret;
  }
  int64_t now_ref = ts_to_int64(*ts);
  int64_t elapsed_ref = now_ref - clock_ref->init_time;
  ret = real_clock_gettime(clockid, ts);
  if (ret != 0) {
   return ret;
  }
  int64_t now = ts_to_int64(*ts);
  clock->init_time = now - elapsed_ref;
  clock->fake_init_time = clock->init_time + (clock_ref->fake_init_time - clock_ref->init_time);
 }
 int ret = real_clock_gettime(clockid, ts);
 if (ret != 0) {
  return ret;
 }
 int64_t now = ts_to_int64(*ts);
 int64_t fake_now = clock->fake_init_time + (int64_t)((now - clock->init_time) * g_factor);
 ts->tv_sec = fake_now / 1000000000;
 ts->tv_nsec = fake_now % 1000000000;
 if (ts->tv_nsec < 0) {
  ts->tv_sec--;
  ts->tv_nsec += 1000000000;
 }
 return 0;
}

canonical_original_code:
static int hack_clock_gettime(int clockid, struct timespec *ts) {
 initialize();
 if (clockid < 0 || clockid >= 12) {
  return real_clock_gettime(clockid, ts);
 }
 int clockid_ref = get_reference_clock(clockid);
 struct ClockInfo *clock_ref = &g_clocks[clockid_ref];
 struct ClockInfo *clock = &g_clocks[clockid];
 if (clock->init_time == 0 && clock->fake_init_time == 0) {
  int ret = real_clock_gettime(clockid_ref, ts);
  if (ret != 0) {
   return ret;
  }
  long now_ref = ts_to_int64(*ts);
  long elapsed_ref = now_ref - clock_ref->init_time;
  ret = real_clock_gettime(clockid, ts);
  if (ret != 0) {
   return ret;
  }
  long now = ts_to_int64(*ts);
  clock->init_time = now - elapsed_ref;
  clock->fake_init_time = clock->init_time + (clock_ref->fake_init_time - clock_ref->init_time);
 }
 int ret = real_clock_gettime(clockid, ts);
 if (ret != 0) {
  return ret;
 }
 long now = ts_to_int64(*ts);
 long fake_now = clock->fake_init_time + (int64_t)((now - clock->init_time) * g_factor);
 ts->tv_sec = fake_now / 1000000000;
 ts->tv_nsec = fake_now % 1000000000;
 if (ts->tv_nsec < 0) {
  ts->tv_sec--;
  ts->tv_nsec += 1000000000;
 }
 return 0;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *

variable_types: struct ClockInfo { long init_time; long fake_init_time; } *

variable_types: ret int

variable_types: now long


decompiled_code:
__int64 __fastcall hack_gettimeofday(_QWORD *a1, __int64 a2)
{
unsigned int v2; // ecx
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

if ( a2 )
{
*__errno_location() = 38;
v2 = -1;
}
else
{
v2 = hack_clock_gettime(0, v4);
if ( !v2 )
{
*a1 = v4[0];
a1[1] = v4[1] / 1000;
}
}
return v2;
}

original_code:
static int hack_gettimeofday(struct timeval *tv, struct timezone *tz) {
 if (tz != ((void *)0)) {
  (*__errno_location ()) = 38;
  return -1;
 }
 struct timespec ts;
 int ret = hack_clock_gettime(0, &ts);
 if (ret != 0) {
  return ret;
 }
 tv->tv_sec = ts.tv_sec;
 tv->tv_usec = ts.tv_nsec / 1000;
 return 0;
}

variable_types: struct timeval { long tv_sec; long tv_usec; } *

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; } *


trataResp

decompiled_code:
void *__fastcall trataResp(void *a1)
{
unsigned int *v1; // r14
__int64 v2; // r12
void *v4; // r15
char *v5; // rbx
int v6; // ebp
char v7[1026]; // [rsp+10h] [rbp-448h] BYREF
char s[10]; // [rsp+412h] [rbp-46h] BYREF
int v9[15]; // [rsp+41Ch] [rbp-3Ch] BYREF

v1 = (unsigned int *)parseRequest();
pthread_mutex_lock(&mlista);
v2 = processRequest(v1, &lcliente);
pthread_mutex_unlock(&mlista);
sprintf(s, "ans%d", v1[35]);
writeFifo(s, v2);
if ( v1[36] == 6 && !strcmp((const char *)(v2 + 128), "OK") )
{
v9[0] = 0;
usleep((__useconds_t)&unk_186A0);
v4 = &lcliente;
while ( 1 )
{
*(_QWORD *)v2 = 0LL;
*(_QWORD *)(v2 + 120) = 0LL;
memset(
(void *)((v2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 128) >> 3));
memset(v7, 0, 0x400uLL);
pthread_mutex_lock(&mlista);
v4 = (void *)listarClientes(v4, v7, v9);
pthread_mutex_unlock(&mlista);
if ( !v4 )
break;
v5 = strtok(v7, " ");
v6 = 1;
do
{
if ( v6 != 3 )
{
*(_WORD *)(v2 + strlen((const char *)v2)) = 32;
strcat((char *)v2, v5);
}
v5 = strtok(0LL, " ");
++v6;
}
while ( v5 );
writeFifo(s, v2);
usleep((__useconds_t)&unk_186A0);
}
writeFifo(s, "end");
}
free(a1);
free((void *)v2);
free(v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
unsigned int *v1; // r14
__int64 v2; // r12
void *v4; // r15
char *v5; // rbx
int v6; // ebp
char v7[1026]; // [rsp+10h] [rbp-448h] BYREF
char s[10]; // [rsp+412h] [rbp-46h] BYREF
int v9[15]; // [rsp+41Ch] [rbp-3Ch] BYREF

v1 = (unsigned int *)parseRequest();
pthread_mutex_lock(&mlista);
v2 = processRequest(v1, &lcliente);
pthread_mutex_unlock(&mlista);
sprintf(s, "ans%d", v1[35]);
writeFifo(s, v2);
if ( v1[36] == 6 && !strcmp((const char *)(v2 + 128), "OK") )
{
v9[0] = 0;
usleep((__useconds_t)&unk_186A0);
v4 = &lcliente;
while ( 1 )
{
*(_QWORD *)v2 = 0LL;
*(_QWORD *)(v2 + 120) = 0LL;
memset(
(void *)((v2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 128) >> 3));
memset(v7, 0, 0x400uLL);
pthread_mutex_lock(&mlista);
v4 = (void *)listarClientes(v4, v7, v9);
pthread_mutex_unlock(&mlista);
if ( !v4 )
break;
v5 = strtok(v7, " ");
v6 = 1;
do
{
if ( v6 != 3 )
{
*(_WORD *)(v2 + strlen((const char *)v2)) = 32;
strcat((char *)v2, v5);
}
v5 = strtok(0LL, " ");
++v6;
}
while ( v5 );
writeFifo(s, v2);
usleep((__useconds_t)&unk_186A0);
}
writeFifo(s, "end");
}
free(a1);
free((void *)v2);
free(v1);
return 0LL;
}

original_code:
void * trataResp( void* str){
 int ret, i, n;
 arrCliente lcl;
 Cliente *cl;
 Response *response;
 char fifo[10], temp[1024];
 char * tmp;
 char * tmp2;
 Request * request = parseRequest(str);
 pthread_mutex_lock(&mlista);
 response = processRequest(request,lcliente);
 pthread_mutex_unlock(&mlista);
 sprintf(fifo, "ans%d",(int) request->pid_cli);
 writeFifo(fifo,response->respOriginal);
 lcl = lcliente;
 if(request->tipo == LISTAR && strcmp(response->status, "OK") == 0){
  n=0;
  usleep(100*1000);
  while(lcl != ((void *)0)){
   memset(response->respOriginal,0,128);
   memset(temp,0,1024);
   i=1;
   pthread_mutex_lock(&mlista);
   lcl = listarClientes(lcl,temp,&n);
   pthread_mutex_unlock(&mlista);
   if(lcl == ((void *)0))
    break;
   tmp = strtok(temp," ");
   do {
    if(i++ != 3) {
     strcat(response->respOriginal," ");
     strcat(response->respOriginal,tmp);
    }
    tmp = strtok(((void *)0)," ");
   }while(tmp != ((void *)0));
   writeFifo(fifo,response->respOriginal);
   usleep(100*1000);
  }
  writeFifo(fifo,"end\0");
 }
 free(str);
 free(response);
 free(request);
 return ((void *)0);
}

canonical_original_code:
void *trataResp(void *str){
 int ret; int i; int n;
 struct Cliente **lcl;
 struct Cliente *cl;
 struct Response *response;
 char fifo[10]; char temp[1024];
 char *tmp;
 char *tmp2;
 struct Request *request = parseRequest(str);
 pthread_mutex_lock(&mlista);
 response = processRequest(request,lcliente);
 pthread_mutex_unlock(&mlista);
 sprintf(fifo, "ans%d",(int) request->pid_cli);
 writeFifo(fifo,response->respOriginal);
 lcl = lcliente;
 if(request->tipo == LISTAR && strcmp(response->status, "OK") == 0){
  n=0;
  usleep(100*1000);
  while(lcl != ((void *)0)){
   memset(response->respOriginal,0,128);
   memset(temp,0,1024);
   i=1;
   pthread_mutex_lock(&mlista);
   lcl = listarClientes(lcl,temp,&n);
   pthread_mutex_unlock(&mlista);
   if(lcl == ((void *)0))
    break;
   tmp = strtok(temp," ");
   do {
    if(i++ != 3) {
     strcat(response->respOriginal," ");
     strcat(response->respOriginal,tmp);
    }
    tmp = strtok(((void *)0)," ");
   }while(tmp != ((void *)0));
   writeFifo(fifo,response->respOriginal);
   usleep(100*1000);
  }
  writeFifo(fifo,"end\0");
 }
 free(str);
 free(response);
 free(request);
 return ((void *)0);
}

variable_types:
str
void *

variable_types: i int

variable_types: n int

variable_types: struct Cliente { char nome[20]; char pin[5]; unsigned int numconta; double saldo; } **

variable_types: struct Response { char respOriginal[128]; char status[128]; char msg[128]; } *

variable_types:
fifo
char [10]

variable_types:
temp
char [1024]

variable_types:
tmp
char *

variable_types: struct Request { char pedidoOriginal[128]; unsigned int numConta; char pin[5]; int pid_cli; enum Tipo { CONSULTAR=0, LEVANTAR=1, DEPOSITAR=2, TRANSFERENCIA=3, ADICIONAR=4, REMOVER=5, LISTAR=6, INVALID=-1 } tipo; unsigned int numConta2; char pin2[5]; char nome[21]; double valor; enum User { ADMIN=0, CLIENTE=1, SERVER=2 } user; } *

user_defined_types: struct Request { char pedidoOriginal[128]; unsigned int numConta; char pin[5]; int pid_cli; enum Tipo tipo; unsigned int numConta2; char pin2[5]; char nome[21]; double valor; enum User user; }


debugIni

decompiled_code:
__int64 debugIni()
{
createArrayclient(&lcliente);
addCliente("nelson", "1234", &lcliente);
addCliente("Miguel", "5678", &lcliente);
addCliente("Da", "1656", &lcliente);
addCliente("Costa", "2465", &lcliente);
addCliente("Martins", "8714", &lcliente);
addCliente("Pereira", "9832", &lcliente);
addCliente("Miguel", "4164", &lcliente);
addCliente("Marcos", "9165", &lcliente);
addCliente("Juliana", "6519", &lcliente);
addCliente("Joao", "9720", &lcliente);
addCliente("Joana", "1642", &lcliente);
return escreveAcounts(&lcliente);
}

canonical_decompiled_code:
__int64 func1()
{
createArrayclient(&lcliente);
addCliente("nelson", "1234", &lcliente);
addCliente("Miguel", "5678", &lcliente);
addCliente("Da", "1656", &lcliente);
addCliente("Costa", "2465", &lcliente);
addCliente("Martins", "8714", &lcliente);
addCliente("Pereira", "9832", &lcliente);
addCliente("Miguel", "4164", &lcliente);
addCliente("Marcos", "9165", &lcliente);
addCliente("Juliana", "6519", &lcliente);
addCliente("Joao", "9720", &lcliente);
addCliente("Joana", "1642", &lcliente);
return escreveAcounts(&lcliente);
}

original_code:
void debugIni() {
 createArrayclient(lcliente);
 addCliente("nelson","1234",lcliente);
 addCliente("Miguel","5678",lcliente);
 addCliente("Da","1656",lcliente);
 addCliente("Costa","2465",lcliente);
 addCliente("Martins","8714",lcliente);
 addCliente("Pereira","9832",lcliente);
 addCliente("Miguel","4164",lcliente);
 addCliente("Marcos","9165",lcliente);
 addCliente("Juliana","6519",lcliente);
 addCliente("Joao","9720",lcliente);
 addCliente("Joana","1642",lcliente);
 escreveAcounts(lcliente);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
pthread_attr_t v4; // [rsp+0h] [rbp-458h] BYREF
pthread_t newthread; // [rsp+38h] [rbp-420h] BYREF
char src[1048]; // [rsp+40h] [rbp-418h] BYREF

pthread_attr_init(&v4);
pthread_attr_setdetachstate(&v4, 1);
createFifo("requests");
if ( !(unsigned __int8)lerAcounts(&lcliente) )
createArrayclient(&lcliente);
while ( 1 )
{
memset(src, 0, 0x400uLL);
if ( !readFifo("requests", 0LL, src) )
break;
v3 = (char *)calloc(0x400uLL, 1uLL);
strcat(v3, src);
if ( !strcmp(src, "shutdown") )
break;
pthread_create(&newthread, &v4, trataResp, v3);
}
remove("requests");
pthread_exit(0LL);
}

original_code:
int main() {
 int fifo;
 char str[1024];
 char *thread;
 pthread_t th;
 pthread_attr_t th_attr;
 int nth = 0;
 pthread_attr_init(&th_attr);
 pthread_attr_setdetachstate(&th_attr,PTHREAD_CREATE_DETACHED);
 fifo = createFifo("requests");
 if( !lerAcounts(lcliente) )
  createArrayclient(lcliente);
 do{
  memset(str,0,1024);
  if(readFifo("requests",0,str) == ((void *)0))
   break;
  thread = (char *) calloc(1024,sizeof(char));
  strcat(thread,str);
  if(strcmp(str,"shutdown")==0)
   break;
  pthread_create(&th, &th_attr, trataResp,thread);
  nth++;
 }while(1);
 remove("requests");
 pthread_exit(((void *)0));
}

canonical_original_code:
int main() {
 int fifo;
 char str[1024];
 char *thread;
 unsigned long th;
 union pthread_attr_t th_attr;
 int nth = 0;
 pthread_attr_init(&th_attr);
 pthread_attr_setdetachstate(&th_attr,PTHREAD_CREATE_DETACHED);
 fifo = createFifo("requests");
 if( !lerAcounts(lcliente) )
  createArrayclient(lcliente);
 do{
  memset(str,0,1024);
  if(readFifo("requests",0,str) == ((void *)0))
   break;
  thread = (char *) calloc(1024,sizeof(char));
  strcat(thread,str);
  if(strcmp(str,"shutdown")==0)
   break;
  pthread_create(&th, &th_attr, trataResp,thread);
  nth++;
 }while(1);
 remove("requests");
 pthread_exit(((void *)0));
}

variable_types: fifo int

variable_types:
str
char [1024]

variable_types:
thread
char *

variable_types:
th
unsigned long

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types: nth int


decompiled_code:
__int64 __fastcall get_time(int *a1)
{
struct tm *v2; // rax
int v3; // edi
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(&timer);
if ( timer <= 0 )
{
printf("no time returned");
result = 0xFFFFFFFFLL;
}
else
{
v2 = localtime(&timer);
if ( v2 )
{
v3 = v2->tm_year;
v2->tm_year = v3 + 1900;
++v2->tm_mon;
a1[10] = (v3 + 1900) / 1000;
a1[11] = v2->tm_year % 1000 / 100;
a1[12] = v2->tm_year % 100 / 10;
a1[13] = v2->tm_year % 10;
a1[8] = v2->tm_mon / 10;
a1[9] = v2->tm_mon % 10;
a1[6] = v2->tm_mday / 10;
a1[7] = v2->tm_mday % 10;
a1[4] = v2->tm_hour / 10;
a1[5] = v2->tm_hour % 10;
a1[2] = v2->tm_min / 10;
a1[3] = v2->tm_min % 10;
*a1 = v2->tm_sec / 10;
a1[1] = v2->tm_sec % 10;
result = 1LL;
}
else
{
puts("bad struct from localtime");
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
struct tm *v2; // rax
int v3; // edi
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(&timer);
if ( timer <= 0 )
{
printf("no time returned");
result = 0xFFFFFFFFLL;
}
else
{
v2 = localtime(&timer);
if ( v2 )
{
v3 = v2->tm_year;
v2->tm_year = v3 + 1900;
++v2->tm_mon;
a1[10] = (v3 + 1900) / 1000;
a1[11] = v2->tm_year % 1000 / 100;
a1[12] = v2->tm_year % 100 / 10;
a1[13] = v2->tm_year % 10;
a1[8] = v2->tm_mon / 10;
a1[9] = v2->tm_mon % 10;
a1[6] = v2->tm_mday / 10;
a1[7] = v2->tm_mday % 10;
a1[4] = v2->tm_hour / 10;
a1[5] = v2->tm_hour % 10;
a1[2] = v2->tm_min / 10;
a1[3] = v2->tm_min % 10;
*a1 = v2->tm_sec / 10;
a1[1] = v2->tm_sec % 10;
result = 1LL;
}
else
{
puts("bad struct from localtime");
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int get_time( int * buff)
{
 time_t now = time(&now);
 if( now <= 0 ){
  printf("no time returned");
  return (-1);
 }
 struct tm *newtm = localtime(&now);
 if ( newtm == 0){
  printf("bad struct from localtime\n");
  return -1;
 }
         newtm->tm_year = newtm->tm_year+1900;
         newtm->tm_mon = newtm->tm_mon+1;
  buff[10] = newtm->tm_year/1000;
  buff[11] = (newtm->tm_year%1000)/100;
  buff[12] = (newtm->tm_year%100)/10;
  buff[13] = newtm->tm_year%10;
  buff[8] = newtm->tm_mon/10;
  buff[9] = newtm->tm_mon%10;
  buff[6] = newtm->tm_mday/10;
  buff[7] = newtm->tm_mday%10;
  buff[4] = newtm->tm_hour/10;
  buff[5] = newtm->tm_hour%10;
  buff[2] = newtm->tm_min/10;
  buff[3] = newtm->tm_min%10;
  buff[0] = newtm->tm_sec/10;
  buff[1] = newtm->tm_sec%10;
 return 1;
}

canonical_original_code:
int get_time(int *buff)
{
 long now = time(&now);
 if( now <= 0 ){
  printf("no time returned");
  return (-1);
 }
 struct tm *newtm = localtime(&now);
 if ( newtm == 0){
  printf("bad struct from localtime\n");
  return -1;
 }
         newtm->tm_year = newtm->tm_year+1900;
         newtm->tm_mon = newtm->tm_mon+1;
  buff[10] = newtm->tm_year/1000;
  buff[11] = (newtm->tm_year%1000)/100;
  buff[12] = (newtm->tm_year%100)/10;
  buff[13] = newtm->tm_year%10;
  buff[8] = newtm->tm_mon/10;
  buff[9] = newtm->tm_mon%10;
  buff[6] = newtm->tm_mday/10;
  buff[7] = newtm->tm_mday%10;
  buff[4] = newtm->tm_hour/10;
  buff[5] = newtm->tm_hour%10;
  buff[2] = newtm->tm_min/10;
  buff[3] = newtm->tm_min%10;
  buff[0] = newtm->tm_sec/10;
  buff[1] = newtm->tm_sec%10;
 return 1;
}

variable_types:
buff
int *

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


setDigit

decompiled_code:
__int64 __fastcall setDigit(int a1, int a2, unsigned int a3)
{
return setLed((unsigned int)(a2 + 12 * a1), a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, unsigned int a3)
{
return setLed((unsigned int)(a2 + 12 * a1), a3);
}

original_code:
void setDigit(int nixie, int val, int brightness)
{
 int which = (nixie*12) + val;
 setLed(which, brightness);
}

variable_types: nixie int

variable_types: val int

variable_types: brightness int

variable_types: which int


showAll

decompiled_code:
unsigned int showAll()
{
int i; // ebx
unsigned int result; // eax

for ( i = 0; i != 12; ++i )
{
clearLeds();
setDigit(0, i, 0x320u);
usleep(1u);
setDigit(1, i, 0x320u);
updateLeds();
result = sleep(1u);
}
return result;
}

canonical_decompiled_code:
unsigned int func2()
{
int i; // ebx
unsigned int result; // eax

for ( i = 0; i != 12; ++i )
{
clearLeds();
func1(0, i, 0x320u);
usleep(1u);
func1(1, i, 0x320u);
updateLeds();
result = sleep(1u);
}
return result;
}

original_code:
void showAll()
{
 int yy=0;
 while( yy < 12)
 {
  clearLeds();
  setDigit(0, yy, 800);
  usleep(1);
  setDigit(1, yy, 800);
  updateLeds();
  sleep(1);
  yy++;
 }
}

canonical_original_code:
void showAll()
{
 int yy = 0;
 while( yy < 12)
 {
  clearLeds();
  setDigit(0, yy, 800);
  usleep(1);
  setDigit(1, yy, 800);
  updateLeds();
  sleep(1);
  yy++;
 }
}

variable_types: yy int


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
__int64 *v7; // rbx
__int64 v8; // [rsp+0h] [rbp-A8h] BYREF
__int64 v9; // [rsp+8h] [rbp-A0h]
__int64 v10; // [rsp+10h] [rbp-98h]
__int64 v11; // [rsp+18h] [rbp-90h]
int v12; // [rsp+20h] [rbp-88h]
int v13; // [rsp+24h] [rbp-84h]
int v14; // [rsp+28h] [rbp-80h]
int v15; // [rsp+2Ch] [rbp-7Ch]
int v16; // [rsp+30h] [rbp-78h]
int v17; // [rsp+34h] [rbp-74h]
int v18; // [rsp+38h] [rbp-70h]
int v19; // [rsp+3Ch] [rbp-6Ch]
int v20; // [rsp+40h] [rbp-68h]
int v21; // [rsp+44h] [rbp-64h]
int v22; // [rsp+48h] [rbp-60h]
int v23; // [rsp+4Ch] [rbp-5Ch]
int v24[22]; // [rsp+50h] [rbp-58h] BYREF

tlc5947init(argc, argv, envp);
v8 = 0xC0000000DLL;
v9 = 0xA0000000BLL;
v10 = 0x700000002LL;
v11 = 0x900000006LL;
v12 = 8;
v13 = 2;
v14 = 3;
v15 = 2;
v16 = 5;
v17 = 4;
v18 = 5;
v19 = 1;
v20 = 0;
v21 = 3;
v22 = 2;
v23 = 3;
while ( 1 )
{
v7 = &v8;
do
{
clearLeds(*(_QWORD *)&argc, argv, v3, v4, v5, v6, v8, v9, v10, v11);
usleep(0xAu);
if ( (unsigned int)get_time(v24) == -1 )
{
*(_QWORD *)&argc = "Bad time";
printf("Bad time");
}
else
{
setDigit(0, v24[*(int *)v7], 0x320u);
usleep(0xAu);
setDigit(1, v24[*((int *)v7 + 1)], 0x320u);
usleep(0xAu);
setDigit(2, v24[*((int *)v7 + 2)], 0x320u);
usleep(0xAu);
argv = (const char **)(unsigned int)v24[*((int *)v7 + 3)];
setDigit(3, (int)argv, 0x320u);
usleep(0xAu);
updateLeds();
*(_QWORD *)&argc = *((unsigned int *)v7 + 4);
sleep(argc);
}
v7 = (__int64 *)((char *)v7 + 20);
}
while ( v7 != (__int64 *)v24 );
}
}

original_code:
int main(int argc, char * argv[])
{
 tlc5947init();
 int tm_ar[14];
 int what[4][5] = {{13,12,11,10,2}, {7,6, 9,8, 2}, {3,2, 5,4, 5}, {1,0, 3,2, 3}};
 while ( 1){
  for( int xx=0 ; xx <=3; xx++)
  {
   clearLeds();
   usleep(10);
   if ( get_time(tm_ar) == -1){
      printf("Bad time");
    continue;
     }
    setDigit(0, tm_ar[what[xx][0]], 800);
    usleep(10);
    setDigit(1, tm_ar[what[xx][1]], 800);
    usleep(10);
    setDigit(2, tm_ar[what[xx][2]], 800);
    usleep(10);
    setDigit(3, tm_ar[what[xx][3]], 800);
    usleep(10);
    updateLeds();
    sleep(what[xx][4]);
  }
 }
 tlc5947cleanup();
}

canonical_original_code:
int main(int argc, char *argv[])
{
 tlc5947init();
 int tm_ar[14];
 int what[4][5] = {{13,12,11,10,2}, {7,6, 9,8, 2}, {3,2, 5,4, 5}, {1,0, 3,2, 3}};
 while ( 1){
  for( int xx = 0; xx <=3; xx++)
  {
   clearLeds();
   usleep(10);
   if ( get_time(tm_ar) == -1){
      printf("Bad time");
    continue;
     }
    setDigit(0, tm_ar[what[xx][0]], 800);
    usleep(10);
    setDigit(1, tm_ar[what[xx][1]], 800);
    usleep(10);
    setDigit(2, tm_ar[what[xx][2]], 800);
    usleep(10);
    setDigit(3, tm_ar[what[xx][3]], 800);
    usleep(10);
    updateLeds();
    sleep(what[xx][4]);
  }
 }
 tlc5947cleanup();
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
what
int [4][5]

variable_types: xx int


repo: cincodenada/editor-on-fire

decompiled_code:
void __fastcall ocd3d_set_projection(float a1, float a2, float a3, float a4, float a5, float a6)
{
*(float *)&ocd3d_internal_state = a1;
*((float *)&ocd3d_internal_state + 1) = a2;
*((float *)&ocd3d_internal_state + 2) = a3;
*((float *)&ocd3d_internal_state + 3) = a4;
*(float *)&qword_270 = a5;
*((float *)&qword_270 + 1) = a6;
}

canonical_decompiled_code:
void __fastcall func0(float a1, float a2, float a3, float a4, float a5, float a6)
{
*(float *)&ocd3d_internal_state = a1;
*((float *)&ocd3d_internal_state + 1) = a2;
*((float *)&ocd3d_internal_state + 2) = a3;
*((float *)&ocd3d_internal_state + 3) = a4;
*(float *)&qword_270 = a5;
*((float *)&qword_270 + 1) = a6;
}

original_code:
void ocd3d_set_projection(float sx, float sy, float vx, float vy, float vw, float vh)
{
 ocd3d_internal_state.scale_x = sx;
 ocd3d_internal_state.scale_y = sy;
 ocd3d_internal_state.vp_x = vx;
 ocd3d_internal_state.vp_y = vy;
 ocd3d_internal_state.view_w = vw;
 ocd3d_internal_state.view_h = vh;
}

variable_types: sx float

variable_types: sy float

variable_types: vx float

variable_types: vy float

variable_types: vw float

variable_types: vh float


decompiled_code:
__int64 __fastcall ocd3d_store_state(__m128i *a1)
{
__int64 result; // rax

*a1 = _mm_load_si128((const __m128i *)&ocd3d_internal_state);
result = qword_270;
a1[1].m128i_i64[0] = qword_270;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__m128i *a1)
{
__int64 result; // rax

*a1 = _mm_load_si128((const __m128i *)&ocd3d_internal_state);
result = qword_270;
a1[1].m128i_i64[0] = qword_270;
return result;
}

original_code:
void ocd3d_store_state(OCD3D_STATE * sp)
{
 memcpy(sp, &ocd3d_internal_state, sizeof(OCD3D_STATE));
}

canonical_original_code:
void ocd3d_store_state(struct OCD3D_STATE *sp)
{
 memcpy(sp, &ocd3d_internal_state, sizeof(OCD3D_STATE));
}

variable_types: struct OCD3D_STATE { float scale_x; float scale_y; float vp_x; float vp_y; float view_w; float view_h; } *


decompiled_code:
__int64 __fastcall ocd3d_restore_state(const __m128i *a1)
{
__int64 result; // rax

ocd3d_internal_state = (__int128)_mm_loadu_si128(a1);
result = a1[1].m128i_i64[0];
qword_270 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const __m128i *a1)
{
__int64 result; // rax

ocd3d_internal_state = (__int128)_mm_loadu_si128(a1);
result = a1[1].m128i_i64[0];
qword_270 = result;
return result;
}

original_code:
void ocd3d_restore_state(OCD3D_STATE * sp)
{
 memcpy(&ocd3d_internal_state, sp, sizeof(OCD3D_STATE));
}

canonical_original_code:
void ocd3d_restore_state(struct OCD3D_STATE *sp)
{
 memcpy(&ocd3d_internal_state, sp, sizeof(OCD3D_STATE));
}

user_defined_types: struct OCD3D_STATE { float scale_x; float scale_y; float vp_x; float vp_y; float view_w; float view_h; }


decompiled_code:
float __fastcall ocd3d_project_x(float a1, float a2)
{
float v2; // xmm1_4
float result; // xmm0_4

v2 = a2 + *(float *)&qword_270;
if ( v2 <= 0.0 )
result = *(float *)&LC0;
else
result = (float)((float)((float)((float)(a1 - *((float *)&ocd3d_internal_state + 2)) * *(float *)&qword_270) / v2)
+ *((float *)&ocd3d_internal_state + 2))
* *(float *)&ocd3d_internal_state;
return result;
}

canonical_decompiled_code:
float __fastcall func3(float a1, float a2)
{
float v2; // xmm1_4
float result; // xmm0_4

v2 = a2 + *(float *)&qword_270;
if ( v2 <= 0.0 )
result = *(float *)&LC0;
else
result = (float)((float)((float)((float)(a1 - *((float *)&ocd3d_internal_state + 2)) * *(float *)&qword_270) / v2)
+ *((float *)&ocd3d_internal_state + 2))
* *(float *)&ocd3d_internal_state;
return result;
}

original_code:
float ocd3d_project_x(float x, float z)
{
 float rx;
 if(z + ocd3d_internal_state.view_w > 0)
 {
  rx = ocd3d_internal_state.scale_x * (((x - ocd3d_internal_state.vp_x) * ocd3d_internal_state.view_w) / (z + ocd3d_internal_state.view_w) + ocd3d_internal_state.vp_x);
  return rx;
 }
 else
 {
  return -65536;
 }
}

variable_types: x float

variable_types: z float

variable_types: rx float

return_type: float


decompiled_code:
float __fastcall ocd3d_project_y(float a1, float a2)
{
float v2; // xmm1_4
float result; // xmm0_4

v2 = a2 + *((float *)&qword_270 + 1);
if ( v2 <= 0.0 )
result = *(float *)&LC0;
else
result = (float)((float)((float)((float)(a1 - *((float *)&ocd3d_internal_state + 3)) * *((float *)&qword_270 + 1))
/ v2)
+ *((float *)&ocd3d_internal_state + 3))
* *((float *)&ocd3d_internal_state + 1);
return result;
}

canonical_decompiled_code:
float __fastcall func4(float a1, float a2)
{
float v2; // xmm1_4
float result; // xmm0_4

v2 = a2 + *((float *)&qword_270 + 1);
if ( v2 <= 0.0 )
result = *(float *)&LC0;
else
result = (float)((float)((float)((float)(a1 - *((float *)&ocd3d_internal_state + 3)) * *((float *)&qword_270 + 1))
/ v2)
+ *((float *)&ocd3d_internal_state + 3))
* *((float *)&ocd3d_internal_state + 1);
return result;
}

original_code:
float ocd3d_project_y(float y, float z)
{
 float ry;
 if(z + ocd3d_internal_state.view_h > 0)
 {
  ry = ocd3d_internal_state.scale_y * (((y - ocd3d_internal_state.vp_y) * ocd3d_internal_state.view_h) / (z + ocd3d_internal_state.view_h) + ocd3d_internal_state.vp_y);
  return ry;
 }
 else
 {
  return -65536;
 }
}

variable_types: y float

variable_types: ry float