decompiled_code:
void config_set_defaults()
{
config_set_string_default((char **)&config_pid_path, "/run/mediator.pid");
config_set_string_default((char **)&config_med_host, "localhost");
config_set_string_default((char **)&config_med_user, "mediator");
config_set_string_default((char **)&config_med_pass, "GimmeAllUr$$$");
config_set_string_default((char **)&config_med_db, "accounting");
config_set_string_default((char **)&config_cdr_host, "localhost");
config_set_string_default((char **)&config_cdr_user, "mediator");
config_set_string_default((char **)&config_cdr_pass, "GimmeAllUr$$$");
config_set_string_default((char **)&config_cdr_db, "accounting");
config_set_string_default((char **)&config_intermediate_cdr_host, "localhost");
config_set_string_default((char **)&config_prov_host, "localhost");
config_set_string_default((char **)&config_prov_user, "mediator");
config_set_string_default((char **)&config_prov_pass, "GimmeAllUr$$$");
config_set_string_default((char **)&config_prov_db, "provisioning");
config_set_string_default((char **)&config_stats_host, "localhost");
config_set_string_default((char **)&config_stats_user, "mediator");
config_set_string_default((char **)&config_stats_pass, "GimmeAllUr$$$");
config_set_string_default((char **)&config_stats_db, "stats");
config_set_string_default((char **)&config_redis_host, "localhost");
}

canonical_decompiled_code:
void func5()
{
func4((char **)&config_pid_path, "/run/mediator.pid");
func4((char **)&config_med_host, "localhost");
func4((char **)&config_med_user, "mediator");
func4((char **)&config_med_pass, "GimmeAllUr$$$");
func4((char **)&config_med_db, "accounting");
func4((char **)&config_cdr_host, "localhost");
func4((char **)&config_cdr_user, "mediator");
func4((char **)&config_cdr_pass, "GimmeAllUr$$$");
func4((char **)&config_cdr_db, "accounting");
func4((char **)&config_intermediate_cdr_host, "localhost");
func4((char **)&config_prov_host, "localhost");
func4((char **)&config_prov_user, "mediator");
func4((char **)&config_prov_pass, "GimmeAllUr$$$");
func4((char **)&config_prov_db, "provisioning");
func4((char **)&config_stats_host, "localhost");
func4((char **)&config_stats_user, "mediator");
func4((char **)&config_stats_pass, "GimmeAllUr$$$");
func4((char **)&config_stats_db, "stats");
func4((char **)&config_redis_host, "localhost");
}

original_code:
static void config_set_defaults(void)
{
    config_set_string_default(&config_pid_path, "/run/mediator.pid");
    config_set_string_default(&config_med_host, "localhost");
    config_set_string_default(&config_med_user, "mediator");
    config_set_string_default(&config_med_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_med_db, "accounting");
    config_set_string_default(&config_cdr_host, "localhost");
    config_set_string_default(&config_cdr_user, "mediator");
    config_set_string_default(&config_cdr_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_cdr_db, "accounting");
    config_set_string_default(&config_intermediate_cdr_host, "localhost");
    config_set_string_default(&config_prov_host, "localhost");
    config_set_string_default(&config_prov_user, "mediator");
    config_set_string_default(&config_prov_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_prov_db, "provisioning");
    config_set_string_default(&config_stats_host, "localhost");
    config_set_string_default(&config_stats_user, "mediator");
    config_set_string_default(&config_stats_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_stats_db, "stats");
    config_set_string_default(&config_redis_host, "localhost");
}

canonical_original_code:
static void config_set_defaults()
{
    config_set_string_default(&config_pid_path, "/run/mediator.pid");
    config_set_string_default(&config_med_host, "localhost");
    config_set_string_default(&config_med_user, "mediator");
    config_set_string_default(&config_med_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_med_db, "accounting");
    config_set_string_default(&config_cdr_host, "localhost");
    config_set_string_default(&config_cdr_user, "mediator");
    config_set_string_default(&config_cdr_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_cdr_db, "accounting");
    config_set_string_default(&config_intermediate_cdr_host, "localhost");
    config_set_string_default(&config_prov_host, "localhost");
    config_set_string_default(&config_prov_user, "mediator");
    config_set_string_default(&config_prov_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_prov_db, "provisioning");
    config_set_string_default(&config_stats_host, "localhost");
    config_set_string_default(&config_stats_user, "mediator");
    config_set_string_default(&config_stats_pass, "GimmeAllUr$$$");
    config_set_string_default(&config_stats_db, "stats");
    config_set_string_default(&config_redis_host, "localhost");
}


repo: sipwise/mediator

decompiled_code:
__int64 __fastcall config_parse_line(char *s2)
{
char v1; // bl
const unsigned __int16 *v2; // rsi
char *v3; // rdx
const char *v4; // rbx
char v5; // al
const char *v6; // r14
struct option *v7; // r13
unsigned int v8; // ebp
int v9; // eax

v1 = *s2;
if ( *s2 )
{
v2 = *_ctype_b_loc();
v3 = s2;
while ( (v2[v1] & 0x2000) == 0 && v1 != 61 )
{
v1 = *++v3;
if ( !*v3 )
goto LABEL_6;
}
v5 = *v3;
if ( *v3 )
{
v4 = v3;
do
{
if ( (v2[v5] & 0x2000) == 0 && v5 != 61 )
break;
v5 = *++v4;
}
while ( *v4 );
if ( v3 != v4 )
*v3 = 0;
}
else
{
v4 = v3;
}
}
else
{
v3 = s2;
LABEL_6:
v4 = v3;
}
v6 = long_options.name;
if ( long_options.name )
{
v7 = &long_options;
while ( 1 )
{
v8 = strcmp(v6, s2);
if ( !v8 )
break;
++v7;
v6 = v7->name;
if ( !v7->name )
goto LABEL_19;
}
v9 = v7->has_arg;
if ( v9 )
{
if ( v9 != 1 || *v4 )
goto LABEL_29;
v8 = -1;
if ( (unsigned int)config_loglevel > 2 )
syslog(3, "%s:%d [%s]: Missing value in config file option '%s'", "config.c", 384LL, "config_parse_line", v6);
}
else
{
if ( !*v4 )
{
LABEL_29:
config_set_option(v7->val, v4);
return v8;
}
v8 = -1;
if ( (unsigned int)config_loglevel > 2 )
syslog(3, "%s:%d [%s]: Unexpected value in config file option '%s'", "config.c", 380LL, "config_parse_line", v6);
}
}
else
{
LABEL_19:
v8 = -1;
if ( (unsigned int)config_loglevel > 2 )
{
syslog(3, "%s:%d [%s]: No option found in config file line '%s'", "config.c", 375LL, "config_parse_line", s2);
v8 = -1;
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2)
{
char v1; // bl
const unsigned __int16 *v2; // rsi
char *v3; // rdx
const char *v4; // rbx
char v5; // al
const char *v6; // r14
struct option *v7; // r13
unsigned int v8; // ebp
int v9; // eax

v1 = *s2;
if ( *s2 )
{
v2 = *_ctype_b_loc();
v3 = s2;
while ( (v2[v1] & 0x2000) == 0 && v1 != 61 )
{
v1 = *++v3;
if ( !*v3 )
goto LABEL_6;
}
v5 = *v3;
if ( *v3 )
{
v4 = v3;
do
{
if ( (v2[v5] & 0x2000) == 0 && v5 != 61 )
break;
v5 = *++v4;
}
while ( *v4 );
if ( v3 != v4 )
*v3 = 0;
}
else
{
v4 = v3;
}
}
else
{
v3 = s2;
LABEL_6:
v4 = v3;
}
v6 = long_options.name;
if ( long_options.name )
{
v7 = &long_options;
while ( 1 )
{
v8 = strcmp(v6, s2);
if ( !v8 )
break;
++v7;
v6 = v7->name;
if ( !v7->name )
goto LABEL_19;
}
v9 = v7->has_arg;
if ( v9 )
{
if ( v9 != 1 || *v4 )
goto LABEL_29;
v8 = -1;
if ( (unsigned int)config_loglevel > 2 )
syslog(3, "%s:%d [%s]: Missing value in config file option '%s'", "config.c", 384LL, "config_parse_line", v6);
}
else
{
if ( !*v4 )
{
LABEL_29:
func2(v7->val, v4);
return v8;
}
v8 = -1;
if ( (unsigned int)config_loglevel > 2 )
syslog(3, "%s:%d [%s]: Unexpected value in config file option '%s'", "config.c", 380LL, "config_parse_line", v6);
}
}
else
{
LABEL_19:
v8 = -1;
if ( (unsigned int)config_loglevel > 2 )
{
syslog(3, "%s:%d [%s]: No option found in config file line '%s'", "config.c", 375LL, "config_parse_line", s2);
v8 = -1;
}
}
return v8;
}

original_code:
static int config_parse_line(char *line)
{
    char *sep;
    const char *value;
    struct option *option;
    for (sep = line; *sep; sep++)
        if (((*__ctype_b_loc ())[(int) ((*sep))] & (unsigned short int) _ISspace) || *sep == '=')
            break;
    for (value = sep; *value; value++)
        if (!((*__ctype_b_loc ())[(int) ((*value))] & (unsigned short int) _ISspace) && *value != '=')
            break;
    if (value != sep)
        *sep = '\0';
    for (option = long_options; option->name; option++)
        if (strcmp(option->name, line) == 0)
            break;
    if (option->name == ((void *)0)) {
        do { if (config_loglevel >= MED_LOG_ERROR) { do { syslog((3), "%s:%d [%s]: " "No option found in config file line '%s'", "config.c", 375, __func__, line); } while(0); } } while(0);
        return -1;
    }
    if (option->has_arg == 0 && *value != '\0') {
        do { if (config_loglevel >= MED_LOG_ERROR) { do { syslog((3), "%s:%d [%s]: " "Unexpected value in config file option '%s'", "config.c", 380, __func__, option->name); } while(0); } } while(0);
        return -1;
    } else if (option->has_arg == 1 && *value == '\0') {
        do { if (config_loglevel >= MED_LOG_ERROR) { do { syslog((3), "%s:%d [%s]: " "Missing value in config file option '%s'", "config.c", 384, __func__, option->name); } while(0); } } while(0);
        return -1;
    }
    config_set_option(option->val, value);
    return 0;
}

canonical_original_code:
static int config_parse_line(char *line)
{
    char *sep;
    char *value;
    struct option *option;
    for (sep = line; *sep; sep++)
        if (((*__ctype_b_loc ())[(int) ((*sep))] & (unsigned short) _ISspace) || *sep == '=')
            break;
    for (value = sep; *value; value++)
        if (!((*__ctype_b_loc ())[(int) ((*value))] & (unsigned short) _ISspace) && *value != '=')
            break;
    if (value != sep)
        *sep = '\0';
    for (option = long_options; option->name; option++)
        if (strcmp(option->name, line) == 0)
            break;
    if (option->name == ((void *)0)) {
        do { if (config_loglevel >= MED_LOG_ERROR) { do { syslog((3), "%s:%d [%s]: " "No option found in config file line '%s'", "config.c", 375, __func__, line); } while(0); } } while(0);
        return -1;
    }
    if (option->has_arg == 0 && *value != '\0') {
        do { if (config_loglevel >= MED_LOG_ERROR) { do { syslog((3), "%s:%d [%s]: " "Unexpected value in config file option '%s'", "config.c", 380, __func__, option->name); } while(0); } } while(0);
        return -1;
    } else if (option->has_arg == 1 && *value == '\0') {
        do { if (config_loglevel >= MED_LOG_ERROR) { do { syslog((3), "%s:%d [%s]: " "Missing value in config file option '%s'", "config.c", 384, __func__, option->name); } while(0); } } while(0);
        return -1;
    }
    config_set_option(option->val, value);
    return 0;
}

variable_types:
line
char *

variable_types:
sep
char *

variable_types:
value
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } *

return_type: int


decompiled_code:
__int64 __fastcall config_parse(int a1, char **a2)
{
int v2; // ebx
unsigned int v3; // ebx

v2 = config_parse_cmdopts(a1, a2);
config_set_string_default(&config_file_path, "/etc/ngcp-mediator/ngcp-mediator.conf");
v3 = config_parse_file(config_file_path) | v2;
config_set_defaults();
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, char **a2)
{
int v2; // ebx
unsigned int v3; // ebx

v2 = func3(a1, a2);
func4(&config_file_path, "/etc/ngcp-mediator/ngcp-mediator.conf");
v3 = func7(config_file_path) | v2;
func5();
return v3;
}

original_code:
int config_parse(int argc, char **argv)
{
    int rc = 0;
    rc |= config_parse_cmdopts(argc, argv);
    config_set_string_default(&config_file_path, "/etc/ngcp-mediator/ngcp-mediator.conf");
    rc |= config_parse_file(config_file_path);
    config_set_defaults();
    return rc;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: rc int


decompiled_code:
void config_cleanup()
{
free(config_pid_path);
free(config_cdr_host);
free(config_cdr_user);
free(config_cdr_pass);
free(config_cdr_db);
free(config_intermediate_cdr_host);
free(config_med_host);
free(config_med_user);
free(config_med_pass);
free(config_med_db);
free(config_prov_host);
free(config_prov_user);
free(config_prov_pass);
free(config_prov_db);
free(config_stats_host);
free(config_stats_user);
free(config_stats_pass);
free(config_stats_db);
free(config_redis_host);
if ( config_redis_pass )
free(config_redis_pass);
}

canonical_decompiled_code:
void func9()
{
free(config_pid_path);
free(config_cdr_host);
free(config_cdr_user);
free(config_cdr_pass);
free(config_cdr_db);
free(config_intermediate_cdr_host);
free(config_med_host);
free(config_med_user);
free(config_med_pass);
free(config_med_db);
free(config_prov_host);
free(config_prov_user);
free(config_prov_pass);
free(config_prov_db);
free(config_stats_host);
free(config_stats_user);
free(config_stats_pass);
free(config_stats_db);
free(config_redis_host);
if ( config_redis_pass )
free(config_redis_pass);
}

original_code:
void config_cleanup()
{
    free(config_pid_path);
    free(config_cdr_host);
    free(config_cdr_user);
    free(config_cdr_pass);
    free(config_cdr_db);
    free(config_intermediate_cdr_host);
    free(config_med_host);
    free(config_med_user);
    free(config_med_pass);
    free(config_med_db);
    free(config_prov_host);
    free(config_prov_user);
    free(config_prov_pass);
    free(config_prov_db);
    free(config_stats_host);
    free(config_stats_user);
    free(config_stats_pass);
    free(config_stats_db);
    free(config_redis_host);
    if (config_redis_pass)
        free(config_redis_pass);
}

return_type: void


decompiled_code:
__int64 __fastcall records_sort(__int64 a1)
{
return g_queue_sort(a1, records_sort_func, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return g_queue_sort(a1, records_sort_func, 0LL);
}

original_code:
void records_sort(GQueue *records)
{
    g_queue_sort(records, records_sort_func, ((void *)0));
}

canonical_original_code:
void records_sort(struct _GQueue *records)
{
    g_queue_sort(records, records_sort_func, ((void *)0));
}

variable_types: struct _GQueue { struct _GList { void *data; struct _GList *next; struct _GList *prev; } *head; struct _GList *tail; unsigned int length; } *

user_defined_types: struct _GQueue { struct _GList *head; struct _GList *tail; unsigned int length; }


daemonize

decompiled_code:
__int64 daemonize()
{
__pid_t v0; // eax
int v1; // ebx
__int64 result; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax

v0 = fork();
if ( v0 < 0 )
return 0xFFFFFFFFLL;
if ( v0 > 0 )
exit(0);
setsid();
v1 = getdtablesize();
if ( v1 > 2 )
{
do
{
if ( mediator_lockfd != v1 )
close(v1);
--v1;
}
while ( v1 != 2 );
}
if ( freopen64("/dev/null", "r", stdin) )
{
if ( freopen64("/dev/null", "w", stdout) )
{
if ( freopen64("/dev/null", "w", stderr) )
{
umask(0x17u);
if ( chdir("/") < 0 )
{
result = 0xFFFFFFFFLL;
if ( config_loglevel > 1u )
{
v9 = _errno_location();
v10 = strerror(*v9);
syslog(2, "%s:%d [%s]: Failed to chdir to root: %s", "daemonizer.c", 43LL, "daemonize", v10);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( config_loglevel > 1u )
{
v7 = _errno_location();
v8 = strerror(*v7);
syslog(2, "%s:%d [%s]: Failed to reopen stderr to /dev/null: %s", "daemonizer.c", 38LL, "daemonize", v8);
result = 0xFFFFFFFFLL;
}
}
}
else
{
result = 0xFFFFFFFFLL;
if ( config_loglevel > 1u )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "%s:%d [%s]: Failed to reopen stdout to /dev/null: %s", "daemonizer.c", 34LL, "daemonize", v6);
result = 0xFFFFFFFFLL;
}
}
}
else
{
result = 0xFFFFFFFFLL;
if ( config_loglevel > 1u )
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "%s:%d [%s]: Failed to reopen stdin to /dev/null: %s", "daemonizer.c", 30LL, "daemonize", v4);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__pid_t v0; // eax
int v1; // ebx
__int64 result; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax

v0 = fork();
if ( v0 < 0 )
return 0xFFFFFFFFLL;
if ( v0 > 0 )
exit(0);
setsid();
v1 = getdtablesize();
if ( v1 > 2 )
{
do
{
if ( mediator_lockfd != v1 )
close(v1);
--v1;
}
while ( v1 != 2 );
}
if ( freopen64("/dev/null", "r", stdin) )
{
if ( freopen64("/dev/null", "w", stdout) )
{
if ( freopen64("/dev/null", "w", stderr) )
{
umask(0x17u);
if ( chdir("/") < 0 )
{
result = 0xFFFFFFFFLL;
if ( config_loglevel > 1u )
{
v9 = _errno_location();
v10 = strerror(*v9);
syslog(2, "%s:%d [%s]: Failed to chdir to root: %s", "daemonizer.c", 43LL, "daemonize", v10);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( config_loglevel > 1u )
{
v7 = _errno_location();
v8 = strerror(*v7);
syslog(2, "%s:%d [%s]: Failed to reopen stderr to /dev/null: %s", "daemonizer.c", 38LL, "daemonize", v8);
result = 0xFFFFFFFFLL;
}
}
}
else
{
result = 0xFFFFFFFFLL;
if ( config_loglevel > 1u )
{
v5 = _errno_location();
v6 = strerror(*v5);
syslog(2, "%s:%d [%s]: Failed to reopen stdout to /dev/null: %s", "daemonizer.c", 34LL, "daemonize", v6);
result = 0xFFFFFFFFLL;
}
}
}
else
{
result = 0xFFFFFFFFLL;
if ( config_loglevel > 1u )
{
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "%s:%d [%s]: Failed to reopen stdin to /dev/null: %s", "daemonizer.c", 30LL, "daemonize", v4);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int daemonize()
{
    pid_t pid = fork();
    if(pid < 0)
    {
        return -1;
    }
    else if(pid > 0)
    {
        _exit(0);
    }
    else if(pid == 0)
    {
        int fds;
        setsid();
        for(fds = getdtablesize(); fds >= 3; --fds)
        {
            if(fds != mediator_lockfd)
                close(fds);
        }
        if (freopen("/dev/null", "r", stdin) == ((void *)0)) {
            do { if (config_loglevel >= MED_LOG_CRITICAL) { do { syslog((2), "%s:%d [%s]: " "Failed to reopen stdin to /dev/null: %s", "daemonizer.c", 30, __func__, strerror((*__errno_location ()))); } while(0); } } while(0);
            return -1;
        }
        if (freopen("/dev/null", "w", stdout) == ((void *)0)) {
            do { if (config_loglevel >= MED_LOG_CRITICAL) { do { syslog((2), "%s:%d [%s]: " "Failed to reopen stdout to /dev/null: %s", "daemonizer.c", 34, __func__, strerror((*__errno_location ()))); } while(0); } } while(0);
            return -1;
        }
        if (freopen("/dev/null", "w", stderr) == ((void *)0)) {
            do { if (config_loglevel >= MED_LOG_CRITICAL) { do { syslog((2), "%s:%d [%s]: " "Failed to reopen stderr to /dev/null: %s", "daemonizer.c", 38, __func__, strerror((*__errno_location ()))); } while(0); } } while(0);
            return -1;
        }
        umask(027);
        if(chdir("/") < 0) {
            do { if (config_loglevel >= MED_LOG_CRITICAL) { do { syslog((2), "%s:%d [%s]: " "Failed to chdir to root: %s", "daemonizer.c", 43, __func__, strerror((*__errno_location ()))); } while(0); } } while(0);
            return -1;
        }
    }
    return 0;
}

canonical_original_code:
int daemonize()
{
    int pid = fork();
    if(pid < 0)
    {
        return -1;
    }
    else if(pid > 0)
    {
        _exit(0);
    }
    else if(pid == 0)
    {
        int fds;
        setsid();
        for(fds = getdtablesize(); fds >= 3; --fds)
        {
            if(fds != mediator_lockfd)
                close(fds);
        }
        if (freopen("/dev/null", "r", stdin) == ((void *)0)) {
            do { if (config_loglevel >= MED_LOG_CRITICAL) { do { syslog((2), "%s:%d [%s]: " "Failed to reopen stdin to /dev/null: %s", "daemonizer.c", 30, __func__, strerror((*__errno_location ()))); } while(0); } } while(0);
            return -1;
        }
        if (freopen("/dev/null", "w", stdout) == ((void *)0)) {
            do { if (config_loglevel >= MED_LOG_CRITICAL) { do { syslog((2), "%s:%d [%s]: " "Failed to reopen stdout to /dev/null: %s", "daemonizer.c", 34, __func__, strerror((*__errno_location ()))); } while(0); } } while(0);
            return -1;
        }
        if (freopen("/dev/null", "w", stderr) == ((void *)0)) {
            do { if (config_loglevel >= MED_LOG_CRITICAL) { do { syslog((2), "%s:%d [%s]: " "Failed to reopen stderr to /dev/null: %s", "daemonizer.c", 38, __func__, strerror((*__errno_location ()))); } while(0); } } while(0);
            return -1;
        }
        umask(027);
        if(chdir("/") < 0) {
            do { if (config_loglevel >= MED_LOG_CRITICAL) { do { syslog((2), "%s:%d [%s]: " "Failed to chdir to root: %s", "daemonizer.c", 43, __func__, strerror((*__errno_location ()))); } while(0); } } while(0);
            return -1;
        }
    }
    return 0;
}

variable_types: pid int

variable_types: fds int


repo: siqiaochen/openjxr

decompiled_code:
__int64 __fastcall fwd_conv1(_DWORD *a1, _DWORD *a2, int *a3)
{
int v5; // esi
int v6; // eax
__int64 result; // rax

v5 = *a3 - *a1;
v6 = ((v5 + 1) >> 1) + *a1 - *a2;
*a1 = *a2 + (v6 >> 1);
result = (unsigned int)-v6;
*a2 = result;
*a3 = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, _DWORD *a2, int *a3)
{
int v5; // esi
int v6; // eax
__int64 result; // rax

v5 = *a3 - *a1;
v6 = ((v5 + 1) >> 1) + *a1 - *a2;
*a1 = *a2 + (v6 >> 1);
result = (unsigned int)-v6;
*a2 = result;
*a3 = v5;
return result;
}

original_code:
static inline void fwd_conv1(int *r, int *g, int *b)
{
    int v = *b - *r;
    int t = *r - *g + ((v + 1) >> 1);
    int y = *g + (t >> 1);
    int u = -t;
    *r = y;
    *g = u;
    *b = v;
}

variable_types:
r
int *

variable_types:
g
int *

variable_types:
b
int *

variable_types: v int

variable_types: t int

variable_types: y int

variable_types: u int


decompiled_code:
__int64 __fastcall fwd_conv3(_DWORD *a1, _DWORD *a2, _DWORD *a3, _DWORD *a4)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a4;
*a4 = *a3;
*a3 = *a2;
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2, _DWORD *a3, _DWORD *a4)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a4;
*a4 = *a3;
*a3 = *a2;
*a2 = result;
return result;
}

original_code:
static inline void fwd_conv3(int *c, int *m, int *y, int *k)
{
    int t;
    t = *c;
    *c = *k;
    *k = *y;
    *y = *m;
    *m = t;
}

variable_types:
c
int *

variable_types:
m
int *

variable_types:
y
int *

variable_types:
k
int *


decompiled_code:
__int64 __fastcall get_color_conv_idx(int a1, unsigned int a2, int a3)
{
__int64 result; // rax
unsigned __int8 v4; // al

if ( a1 != 4 || (result = 3LL, a3 != 4) )
{
if ( a1 != 5 || (result = 4LL, a3 != 4) )
{
v4 = a1 == 7 && a3 == 0;
if ( v4 )
{
if ( a2 <= 0xA )
v4 = ((0x74EuLL >> a2) ^ 1) & 1;
result = v4 ^ 1u;
}
else if ( (unsigned int)(a3 - 1) <= 2 && a1 == 7 )
{
result = 2LL;
if ( a2 - 8 > 2 && a2 - 1 > 2 )
result = 2 * (unsigned int)(a3 == 3);
}
else
{
result = 0LL;
if ( a3 == 3 )
result = 2 * (unsigned int)((unsigned int)(a1 - 7) < 2);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, unsigned int a2, int a3)
{
__int64 result; // rax
unsigned __int8 v4; // al

if ( a1 != 4 || (result = 3LL, a3 != 4) )
{
if ( a1 != 5 || (result = 4LL, a3 != 4) )
{
v4 = a1 == 7 && a3 == 0;
if ( v4 )
{
if ( a2 <= 0xA )
v4 = ((0x74EuLL >> a2) ^ 1) & 1;
result = v4 ^ 1u;
}
else if ( (unsigned int)(a3 - 1) <= 2 && a1 == 7 )
{
result = 2LL;
if ( a2 - 8 > 2 && a2 - 1 > 2 )
result = 2 * (unsigned int)(a3 == 3);
}
else
{
result = 0LL;
if ( a3 == 3 )
result = 2 * (unsigned int)((unsigned int)(a1 - 7) < 2);
}
}
}
return result;
}

original_code:
int get_color_conv_idx(int ex_color_format, int ex_bitdepth,
                       int in_color_format)
{
    if (in_color_format == 4 && ex_color_format == 4) {
        return 3;
    } else if (in_color_format == 4 && ex_color_format == 5) {
        return 4;
    } else if ((in_color_format == 0) &&
               (ex_color_format == 7 &&
                (ex_bitdepth == 8 || ex_bitdepth == 10 ||
                 ex_bitdepth == 9 || ex_bitdepth == 1 ||
                 ex_bitdepth == 2 || ex_bitdepth == 3 ||
                 ex_bitdepth == 6))) {
        return 1;
    } else if ((in_color_format == 3 || in_color_format == 2 ||
                in_color_format == 1) &&
               (ex_color_format == 7 &&
                (ex_bitdepth == 8 || ex_bitdepth == 10 ||
                 ex_bitdepth == 9 || ex_bitdepth == 1 ||
                 ex_bitdepth == 2 || ex_bitdepth == 3))) {
        return 2;
    } else if (in_color_format == 3 &&
               (ex_color_format == 7 || ex_color_format == 8)) {
        return 2;
    } else {
        return 0;
    }
}


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

result = a1;
if ( a1 )
{
switch ( a1 )
{
case 1u:
result = 128LL;
break;
case 2u:
result = 0x8000LL;
break;
case 8u:
result = 16LL;
break;
case 9u:
result = 512LL;
break;
default:
result = 32 * (unsigned int)(a1 == 10);
break;
}
}
return result;
}

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

result = a1;
if ( a1 )
{
switch ( a1 )
{
case 1u:
result = 128LL;
break;
case 2u:
result = 0x8000LL;
break;
case 8u:
result = 16LL;
break;
case 9u:
result = 512LL;
break;
default:
result = 32 * (unsigned int)(a1 == 10);
break;
}
}
return result;
}

original_code:
int get_bias(int ex_bitdepth)
{
    if (ex_bitdepth == 0) {
        return 0;
    } else if (ex_bitdepth == 1) {
        return (1 << 7);
    } else if (ex_bitdepth == 2) {
        return (1 << 15);
    } else if (ex_bitdepth == 8) {
        return (1 << 4);
    } else if (ex_bitdepth == 9) {
        return (1 << 9);
    } else if (ex_bitdepth == 10) {
        return (1 << 5);
    } else {
        return 0;
    }
}


original_code:
void fwd_color_conv(int **mb, rect_t *rect, color_t *color)
{
    int left = rect->left;
    int right = rect->right;
    int top = rect->top;
    int bottom = rect->bottom;
    int bias = color->bias;
    int scale = color->scale;
    int i, j;
    switch (color->conv_idx) {
    case 0:
        break;
    case 1:
    case 2:
        if (color->is_yuv42x) {
            left = left == -2 ? -4 : 0;
            right = right == 18 ? 20 : 16;
            if (color->is_yuv420) {
                top = top == -2 ? - 4 : 0;
                bottom = bottom == 18 ? 20 : 16;
            }
        }
        for (i = top; i < bottom; i++) {
            for (j = left; j < right; j += 1) {
                sub_bias_add_scale(mb[0] + i * 24 + j, mb[1] + i * 24 + j,
                                   mb[2] + i * 24 + j, bias, scale);
                fwd_conv1(mb[0] + i * 24 + j, mb[1] + i * 24 + j, mb[2] + i * 24 + j);
            }
        }
        if (color->is_yuv42x) {
            int vs = 1 << color->is_yuv420;
            for (i = top; i < bottom; i += vs) {
                for (j = left; j < right; j += 2) {
                    mb[1][(i >> color->is_yuv420) * 24 + (j >> 1)] = mb[1][i * 24 + j];
                    mb[2][(i >> color->is_yuv420) * 24 + (j >> 1)] = mb[2][i * 24 + j];
                }
            }
        }
        break;
    case 3:
        for (i = top; i < bottom; i++) {
            for (j = left; j < right; j++) {
                fwd_conv2(mb[0] + i * 24 + j, mb[1] + i * 24 + j,
                          mb[2] + i * 24 + j, mb[2] + i * 24 + j);
            }
        }
        break;
    case 4:
        for (i = top; i < bottom; i++) {
            for (j = left; j < right; j++) {
                fwd_conv3(mb[0] + i * 24 + j, mb[1] + i * 24 + j,
                          mb[2] + i * 24 + j, mb[2] + i * 24 + j);
            }
        }
        break;
    }
}

canonical_original_code:
void fwd_color_conv(int **mb, struct rect_t *rect, struct color_t *color)
{
    int left = rect->left;
    int right = rect->right;
    int top = rect->top;
    int bottom = rect->bottom;
    int bias = color->bias;
    int scale = color->scale;
    int i; int j;
    switch (color->conv_idx) {
    case 0:
        break;
    case 1:
    case 2:
        if (color->is_yuv42x) {
            left = left == -2 ? -4 : 0;
            right = right == 18 ? 20 : 16;
            if (color->is_yuv420) {
                top = top == -2 ? - 4 : 0;
                bottom = bottom == 18 ? 20 : 16;
            }
        }
        for (i = top; i < bottom; i++) {
            for (j = left; j < right; j += 1) {
                sub_bias_add_scale(mb[0] + i * 24 + j, mb[1] + i * 24 + j,
                                   mb[2] + i * 24 + j, bias, scale);
                fwd_conv1(mb[0] + i * 24 + j, mb[1] + i * 24 + j, mb[2] + i * 24 + j);
            }
        }
        if (color->is_yuv42x) {
            int vs = 1 << color->is_yuv420;
            for (i = top; i < bottom; i += vs) {
                for (j = left; j < right; j += 2) {
                    mb[1][(i >> color->is_yuv420) * 24 + (j >> 1)] = mb[1][i * 24 + j];
                    mb[2][(i >> color->is_yuv420) * 24 + (j >> 1)] = mb[2][i * 24 + j];
                }
            }
        }
        break;
    case 3:
        for (i = top; i < bottom; i++) {
            for (j = left; j < right; j++) {
                fwd_conv2(mb[0] + i * 24 + j, mb[1] + i * 24 + j,
                          mb[2] + i * 24 + j, mb[2] + i * 24 + j);
            }
        }
        break;
    case 4:
        for (i = top; i < bottom; i++) {
            for (j = left; j < right; j++) {
                fwd_conv3(mb[0] + i * 24 + j, mb[1] + i * 24 + j,
                          mb[2] + i * 24 + j, mb[2] + i * 24 + j);
            }
        }
        break;
    }
}

variable_types:
mb
int **

variable_types: struct rect_t { int left; int right; int top; int bottom; } *

variable_types: struct color_t { int conv_idx; int bias; int scale; int num_comp; int is_yuv420; int is_yuv422; int is_yuv444; int is_yuv42x; int is_yuv4xx; int is_yuv; int is_yonly; } *

variable_types: left int

variable_types: right int

variable_types: top int

variable_types: bottom int

variable_types: bias int

variable_types: scale int

variable_types: i int

variable_types: j int

variable_types: vs int


decompiled_code:
void add_bias()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void add_bias()
{
}

canonical_original_code:
void add_bias()
{
}


upsample

decompiled_code:
void upsample()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void upsample()
{
}

canonical_original_code:
void upsample()
{
}


decompiled_code:
void compute_scaling()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void compute_scaling()
{
}

canonical_original_code:
void compute_scaling()
{
}


decompiled_code:
void inverse_conv_color()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void inverse_conv_color(uint8_t *image, int step,
                        int **mb, rect_t *ex, int color_conv)
{
}

canonical_original_code:
void inverse_conv_color(unsigned char *image, int step, int **mb, struct rect_t *ex, int color_conv)
{
}

variable_types:
image
unsigned char *

variable_types: step int

user_defined_types: struct rect_t { int left; int right; int top; int bottom; }


original_code:
void enc_mb_stage1(jxr_t *p, rect_t *mb_window, rect_t *is_tile_edge, uint32_t mbx, uint32_t mby)
{
    int lpqp_idx = 0;
    int n;
    load_mb(p->mb, p->image, p->step, p->color.num_comp, mbx, mby, mb_window);
    fwd_color_conv(p->mb, mb_window, &p->color);
    for (n = 0; n < p->color.num_comp; n++) {
        int ch = n > 0 && p->color.is_yuv42x;
        fwd_trx_stage1(p->mb[n], p->mb_dclp[n], &mb_window[ch], p->param.overlap_mode);
        fwd_trx_stage2(p->mb_dclp[n], &mb_window[ch], p->param.overlap_mode);
    }
    store_dclp(p->dclp_buf, p->mb_dclp, &p->color);
    store_param(&p->lpqp_idx_buf, lpqp_idx);
}

canonical_original_code:
void enc_mb_stage1(struct jxr_t *p, struct rect_t *mb_window, struct rect_t *is_tile_edge, unsigned int mbx, unsigned int mby)
{
    int lpqp_idx = 0;
    int n;
    load_mb(p->mb, p->image, p->step, p->color.num_comp, mbx, mby, mb_window);
    fwd_color_conv(p->mb, mb_window, &p->color);
    for (n = 0; n < p->color.num_comp; n++) {
        int ch = n > 0 && p->color.is_yuv42x;
        fwd_trx_stage1(p->mb[n], p->mb_dclp[n], &mb_window[ch], p->param.overlap_mode);
        fwd_trx_stage2(p->mb_dclp[n], &mb_window[ch], p->param.overlap_mode);
    }
    store_dclp(p->dclp_buf, p->mb_dclp, &p->color);
    store_param(&p->lpqp_idx_buf, lpqp_idx);
}

variable_types: struct jxr_t { int mode; int is_ready; struct param_t { unsigned int flags; unsigned int width; unsigned int height; unsigned int ex_width; unsigned int ex_height; unsigned int mb_width; unsigned int mb_height; unsigned int num_ver_tiles; unsigned int num_hor_tiles; unsigned short *tile_width_in_mb; unsigned short *tile_height_in_mb; struct rect_t { int left; int right; int top; int bottom; } margin; unsigned int overlap_mode; int trim_flexbits; int spatial_xfrm_subordinate; int ex_color_format; int ex_bitdepth; int num_comp; int in_color_format; int chroma_centering_x; int chroma_centering_y; int bands_present; int component_mode; int shift_bits; int len_mantissa; int exp_bias; unsigned int num_lpqps; unsigned int num_hpqps; unsigned char dc_qp[16]; unsigned char lp_qps[16][16]; unsigned char hp_qps[16][16]; } param; struct color_t { int conv_idx; int bias; int scale; int num_comp; int is_yuv420; int is_yuv422; int is_yuv444; int is_yuv42x; int is_yuv4xx; int is_yuv; int is_yonly; } color; struct mbdc_param_t { struct model_t { int state[2]; int bits[2]; } model; struct adapt_vlc_t { int discrim_val1; int discrim_val2; int table_index; int delta_table_index; int delta2_table_index; } vlc[2]; } mbdc_param; struct mblp_param_t { struct model_t model; struct adapt_vlc_t vlc[8]; struct scan_t { int order[15]; int totals[15]; } scan; struct cbplp_t { int count_max; int count_zero; } cbplp; } mblp_param; struct mbhp_param_t { struct model_t model; struct adapt_vlc_t vlc[10]; struct scan_t scan[2]; struct cbphp_model_t { int count_ones[2]; int count_zeros[2]; int state[2]; } cbphp_model; int mode_hp; int trim_flexbits; } mbhp_param; unsigned char *image; int step; struct bitbuf_t { unsigned int *buf; unsigned int *p; int left; unsigned int *mark; int l; } *out; int **mb_buf; int **mb; int **mb_dclp_buf; int **mb_dclp; int **pred_dclp; int ***hp; struct ringbuf_t { int *buf; int *p; int size; int step; } *dclp_buf; struct ringbuf_t *cbphp_buf; struct ringbuf_t lpqp_idx_buf; } *

variable_types:
mbx
unsigned int

variable_types:
mby
unsigned int

variable_types: n int

variable_types: ch int

user_defined_types: struct jxr_t { int mode; int is_ready; struct param_t param; struct color_t color; struct mbdc_param_t mbdc_param; struct mblp_param_t mblp_param; struct mbhp_param_t mbhp_param; unsigned char *image; int step; struct bitbuf_t *out; int **mb_buf; int **mb; int **mb_dclp_buf; int **mb_dclp; int **pred_dclp; int ***hp; struct ringbuf_t *dclp_buf; struct ringbuf_t *cbphp_buf; struct ringbuf_t lpqp_idx_buf; }

user_defined_types: struct param_t { unsigned int flags; unsigned int width; unsigned int height; unsigned int ex_width; unsigned int ex_height; unsigned int mb_width; unsigned int mb_height; unsigned int num_ver_tiles; unsigned int num_hor_tiles; unsigned short *tile_width_in_mb; unsigned short *tile_height_in_mb; struct rect_t margin; unsigned int overlap_mode; int trim_flexbits; int spatial_xfrm_subordinate; int ex_color_format; int ex_bitdepth; int num_comp; int in_color_format; int chroma_centering_x; int chroma_centering_y; int bands_present; int component_mode; int shift_bits; int len_mantissa; int exp_bias; unsigned int num_lpqps; unsigned int num_hpqps; unsigned char dc_qp[16]; unsigned char lp_qps[16][16]; unsigned char hp_qps[16][16]; }

user_defined_types: struct mbdc_param_t { struct model_t model; struct adapt_vlc_t vlc[2]; }

user_defined_types: struct mblp_param_t { struct model_t model; struct adapt_vlc_t vlc[8]; struct scan_t scan; struct cbplp_t cbplp; }

user_defined_types: struct mbhp_param_t { struct model_t model; struct adapt_vlc_t vlc[10]; struct scan_t scan[2]; struct cbphp_model_t cbphp_model; int mode_hp; int trim_flexbits; }


original_code:
void enc_mb_stage2(jxr_t *p, rect_t *tile, rect_t *is_tile_edge, uint32_t mbx, uint32_t mby)
{
    int diff_cbphp[16];
    int lpqp_idx = 0;
    int hpqp_idx = 0;
    int n;
    int nbits, total = 0;
    load_pred_dclp(p->pred_dclp, p->dclp_buf, &p->color);
    load_hp(p->hp, p->mb, &p->color);
    fwd_pred_dclp(p->pred_dclp, p->dclp_buf, &p->lpqp_idx_buf, &p->color, is_tile_edge);
    p->mbhp_param.mode_hp = fwd_pred_hp(p->hp, p->mb_dclp, &p->color);
    if (is_tile_edge->left && is_tile_edge->top) {
        init_mbdc_param(&p->mbdc_param);
        init_mblp_param(&p->mblp_param);
        init_mbhp_param(&p->mbhp_param);
    }
    if ((mbx - tile->left) % 16 == 0) {
        reset_totals_adapt_scan_lp(&p->mblp_param.scan);
        reset_totals_adapt_scan_hp(p->mbhp_param.scan);
    }
    if (p->param.bands_present != 3) {
        if (p->param.num_lpqps > 1) {
            enc_qp_index(p->out, p->param.num_lpqps, lpqp_idx);
        }
        if (p->param.bands_present != 2
            && p->param.num_hpqps > 1) {
            enc_qp_index(p->out, p->param.num_hpqps, hpqp_idx);
        }
    }
    enc_mb_dc(p->out, &p->mbdc_param, &p->color, p->pred_dclp);
    if (p->param.bands_present != 3) {
        enc_mb_lp(p->out, &p->mblp_param, &p->color, p->pred_dclp);
        if (p->param.bands_present != 2) {
            fwd_pred_cbphp(diff_cbphp, &p->mbhp_param, &p->color, is_tile_edge, p->cbphp_buf, p->hp);
            enc_mb_cbphp(p->out, &p->mbhp_param, &p->color, diff_cbphp);
            enc_mb_hp_flex(p->out, &p->mbhp_param, &p->color, p->cbphp_buf, p->hp);
        }
    }
    if (is_tile_edge->right || (mbx - tile->left) % 16 == 0) {
        adapt_dc(p->mbdc_param.vlc);
        adapt_lp(p->mblp_param.vlc);
        adapt_hp(p->mbhp_param.vlc);
    }
    ringbuf_update(&p->lpqp_idx_buf);
    for (n = 0; n < p->color.num_comp; n++) {
        ringbuf_update(&p->dclp_buf[n]);
        ringbuf_update(&p->cbphp_buf[n]);
    }
}

canonical_original_code:
void enc_mb_stage2(struct jxr_t *p, struct rect_t *tile, struct rect_t *is_tile_edge, unsigned int mbx, unsigned int mby)
{
    int diff_cbphp[16];
    int lpqp_idx = 0;
    int hpqp_idx = 0;
    int n;
    int nbits; int total = 0;
    load_pred_dclp(p->pred_dclp, p->dclp_buf, &p->color);
    load_hp(p->hp, p->mb, &p->color);
    fwd_pred_dclp(p->pred_dclp, p->dclp_buf, &p->lpqp_idx_buf, &p->color, is_tile_edge);
    p->mbhp_param.mode_hp = fwd_pred_hp(p->hp, p->mb_dclp, &p->color);
    if (is_tile_edge->left && is_tile_edge->top) {
        init_mbdc_param(&p->mbdc_param);
        init_mblp_param(&p->mblp_param);
        init_mbhp_param(&p->mbhp_param);
    }
    if ((mbx - tile->left) % 16 == 0) {
        reset_totals_adapt_scan_lp(&p->mblp_param.scan);
        reset_totals_adapt_scan_hp(p->mbhp_param.scan);
    }
    if (p->param.bands_present != 3) {
        if (p->param.num_lpqps > 1) {
            enc_qp_index(p->out, p->param.num_lpqps, lpqp_idx);
        }
        if (p->param.bands_present != 2
            && p->param.num_hpqps > 1) {
            enc_qp_index(p->out, p->param.num_hpqps, hpqp_idx);
        }
    }
    enc_mb_dc(p->out, &p->mbdc_param, &p->color, p->pred_dclp);
    if (p->param.bands_present != 3) {
        enc_mb_lp(p->out, &p->mblp_param, &p->color, p->pred_dclp);
        if (p->param.bands_present != 2) {
            fwd_pred_cbphp(diff_cbphp, &p->mbhp_param, &p->color, is_tile_edge, p->cbphp_buf, p->hp);
            enc_mb_cbphp(p->out, &p->mbhp_param, &p->color, diff_cbphp);
            enc_mb_hp_flex(p->out, &p->mbhp_param, &p->color, p->cbphp_buf, p->hp);
        }
    }
    if (is_tile_edge->right || (mbx - tile->left) % 16 == 0) {
        adapt_dc(p->mbdc_param.vlc);
        adapt_lp(p->mblp_param.vlc);
        adapt_hp(p->mbhp_param.vlc);
    }
    ringbuf_update(&p->lpqp_idx_buf);
    for (n = 0; n < p->color.num_comp; n++) {
        ringbuf_update(&p->dclp_buf[n]);
        ringbuf_update(&p->cbphp_buf[n]);
    }
}

variable_types:
tile
struct rect_t *

variable_types: nbits int

variable_types: total int

user_defined_types: struct color_t { int conv_idx; int bias; int scale; int num_comp; int is_yuv420; int is_yuv422; int is_yuv444; int is_yuv42x; int is_yuv4xx; int is_yuv; int is_yonly; }

user_defined_types: struct model_t { int state[2]; int bits[2]; }

user_defined_types: struct scan_t { int order[15]; int totals[15]; }

user_defined_types: struct cbplp_t { int count_max; int count_zero; }

user_defined_types: struct cbphp_model_t { int count_ones[2]; int count_zeros[2]; int state[2]; }

user_defined_types: struct bitbuf_t { unsigned int *buf; unsigned int *p; int left; unsigned int *mark; int l; }

user_defined_types: struct ringbuf_t { int *buf; int *p; int size; int step; }

user_defined_types: struct adapt_vlc_t { int discrim_val1; int discrim_val2; int table_index; int delta_table_index; int delta2_table_index; }


decompiled_code:
void dec_mb_stage1()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void dec_mb_stage1()
{
}

canonical_original_code:
void dec_mb_stage1()
{
}


decompiled_code:
void dec_mb_stage2()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void dec_mb_stage2()
{
}

canonical_original_code:
void dec_mb_stage2()
{
}


decompiled_code:
__int64 __fastcall conv_endian(unsigned int a1)
{
return ((a1 >> 8) & 0xFF00) + (a1 << 24) + HIBYTE(a1) + ((a1 << 8) & 0xFF0000);
}

canonical_original_code:
static inline unsigned int conv_endian(unsigned int x)
{
    return (x << 24) + ((x & 0xff00) << 8) + ((x & 0xff0000) >> 8) + (x >> 24);
}

variable_types:
x
unsigned int

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall get_flag(int a1, int a2)
{
return (a2 & a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1, int a2)
{
return (a2 & a1) != 0;
}

original_code:
static inline int get_flag(uint32_t flags, uint32_t flag)
{
    return (flags & flag) != 0;
}

canonical_original_code:
static inline int get_flag(unsigned int flags, unsigned int flag)
{
    return (flags & flag) != 0;
}

variable_types:
flags
unsigned int

variable_types:
flag
unsigned int


original_code:
void enc_free(jxr_t *p)
{
    int n, k;
    if (!get_flag(p->param.flags, 1 << 2)) {
        free(p->out[0].buf);
        free(p->out);
    } else {
        for (k = 0; k < 4; k++) {
            free(p->out[k].buf);
        }
        free(p->out);
    }
    for (n = 0; n < p->color.num_comp; n++) {
        int w = n > 0 && p->color.is_yuv42x ? 2 : 4;
        int h = n > 0 && p->color.is_yuv420 ? 2 : 4;
        free(p->cbphp_buf[n].buf);
        free(p->dclp_buf[n].buf);
        for (k = 0; k < w * h; k++) {
            free(p->hp[n][k]);
        }
        free(p->hp[n]);
        free(p->pred_dclp[n]);
        free(p->mb_dclp_buf[n]);
        free(p->mb_buf[n]);
    }
    free(p->lpqp_idx_buf.buf);
    free(p->hp);
    free(p->cbphp_buf);
    free(p->dclp_buf);
    free(p->mb_dclp_buf);
    free(p->mb_dclp);
    free(p->pred_dclp);
    free(p->mb);
    free(p->mb_buf);
    free(p);
}

canonical_original_code:
void enc_free(struct jxr_t *p)
{
    int n; int k;
    if (!get_flag(p->param.flags, 1 << 2)) {
        free(p->out[0].buf);
        free(p->out);
    } else {
        for (k = 0; k < 4; k++) {
            free(p->out[k].buf);
        }
        free(p->out);
    }
    for (n = 0; n < p->color.num_comp; n++) {
        int w = n > 0 && p->color.is_yuv42x ? 2 : 4;
        int h = n > 0 && p->color.is_yuv420 ? 2 : 4;
        free(p->cbphp_buf[n].buf);
        free(p->dclp_buf[n].buf);
        for (k = 0; k < w * h; k++) {
            free(p->hp[n][k]);
        }
        free(p->hp[n]);
        free(p->pred_dclp[n]);
        free(p->mb_dclp_buf[n]);
        free(p->mb_buf[n]);
    }
    free(p->lpqp_idx_buf.buf);
    free(p->hp);
    free(p->cbphp_buf);
    free(p->dclp_buf);
    free(p->mb_dclp_buf);
    free(p->mb_dclp);
    free(p->pred_dclp);
    free(p->mb);
    free(p->mb_buf);
    free(p);
}

variable_types: k int

variable_types: w int

variable_types: h int


original_code:
static inline int read_u1(bitbuf_t *b)
{
    int v;
    b->left--;
    v = (*b->p >> b->left) & 1;
    if (b->left == 0) {
        *b->p = conv_endian(*b->p);
        b->p++;
        b->left = 32;
    }
    return v;
}

canonical_original_code:
static inline int read_u1(struct bitbuf_t *b)
{
    int v;
    b->left--;
    v = (*b->p >> b->left) & 1;
    if (b->left == 0) {
        *b->p = conv_endian(*b->p);
        b->p++;
        b->left = 32;
    }
    return v;
}

variable_types: struct bitbuf_t { unsigned int *buf; unsigned int *p; int left; unsigned int *mark; int l; } *

variable_types: v int


original_code:
static inline uint32_t read_u(bitbuf_t *b, int n)
{
    int l = n - b->left;
    uint32_t v = 0;
    if (l < 0) {
        b->left = -l;
        v = (*b->p >> b->left) & ((1 << n) - 1);
    } else {
        v = (*b->p & ((1 << b->left) - 1)) << l;
        b->p++;
        *b->p = conv_endian(*b->p);
        b->left = 32 - l;
        if (b->left < 32) {
            v |= *b->p >> b->left;
        }
    }
    return v;
}

canonical_original_code:
static inline unsigned int read_u(struct bitbuf_t *b, int n)
{
    int l = n - b->left;
    unsigned int v = 0;
    if (l < 0) {
        b->left = -l;
        v = (*b->p >> b->left) & ((1 << n) - 1);
    } else {
        v = (*b->p & ((1 << b->left) - 1)) << l;
        b->p++;
        *b->p = conv_endian(*b->p);
        b->left = 32 - l;
        if (b->left < 32) {
            v |= *b->p >> b->left;
        }
    }
    return v;
}

variable_types: l int

variable_types:
v
unsigned int


unstack

decompiled_code:
__int64 __fastcall unstack(_QWORD **a1)
{
void *v2; // rax
_QWORD *v3; // rdi
unsigned int v4; // ebp

v2 = malloc(8uLL);
if ( !a1 || !v2 )
return 0;
v3 = *a1;
v4 = 0;
if ( *a1 )
{
v4 = *(unsigned __int8 *)v3;
*a1 = (_QWORD *)v3[2];
free(v3);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD **a1)
{
void *v2; // rax
_QWORD *v3; // rdi
unsigned int v4; // ebp

v2 = malloc(8uLL);
if ( !a1 || !v2 )
return 0;
v3 = *a1;
v4 = 0;
if ( *a1 )
{
v4 = *(unsigned __int8 *)v3;
*a1 = (_QWORD *)v3[2];
free(v3);
}
return v4;
}

original_code:
char unstack(t_pile *pile)
{
  char token_unstacked;
  t_elem *elem_unstacked;
  elem_unstacked = malloc(sizeof(elem_unstacked));
  if (pile == ((void *)0) || elem_unstacked == ((void *)0))
    return ('\0');
  token_unstacked = 0;
  elem_unstacked = pile->first;
  if (pile != ((void *)0) && pile->first != ((void *)0))
    {
      token_unstacked = elem_unstacked->token;
      pile->first = elem_unstacked->next;
      free(elem_unstacked);
    }
  return (token_unstacked);
}

canonical_original_code:
char unstack(struct s_pile *pile)
{
  char token_unstacked;
  struct s_elem *elem_unstacked;
  elem_unstacked = malloc(sizeof(elem_unstacked));
  if (pile == ((void *)0) || elem_unstacked == ((void *)0))
    return ('\0');
  token_unstacked = 0;
  elem_unstacked = pile->first;
  if (pile != ((void *)0) && pile->first != ((void *)0))
    {
      token_unstacked = elem_unstacked->token;
      pile->first = elem_unstacked->next;
      free(elem_unstacked);
    }
  return (token_unstacked);
}

variable_types: struct s_pile { struct s_elem { char token; char *str; struct s_elem *next; } *first; } *

return_type: char


calcrpn

decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall calcrpn(__int64 a1)
{
int v1; // eax

*(_QWORD *)((char *)&loc_C + 4) = 0LL;
*(_QWORD *)str_to_rpn = 0LL;
*(_DWORD *)a1 = 0;
if ( **(_BYTE **)(a1 + 8) )
{
do
{
checking(a1, 0LL, 0LL);
v1 = *(_DWORD *)a1 + 1;
*(_DWORD *)a1 = v1;
}
while ( *(_BYTE *)(*(_QWORD *)(a1 + 8) + v1) );
}
return my_putstr(*(_QWORD *)((char *)&loc_6 + 2));
}

original_code:
void calcrpn(t_control *control)
{
  t_elem *actual;
  t_pile *pile;
  actual->next = ((void *)0);
  pile->first = actual;
  control->i = 0;
  while (control->tmp[control->i] != '\0')
    {
      checking(control, actual, pile);
      control->i += 1;
    }
  my_putstr(actual->str);
}

canonical_original_code:
void calcrpn(struct s_control *control)
{
  struct s_elem *actual;
  struct s_pile *pile;
  actual->next = ((void *)0);
  pile->first = actual;
  control->i = 0;
  while (control->tmp[control->i] != '\0')
    {
      checking(control, actual, pile);
      control->i += 1;
    }
  my_putstr(actual->str);
}

variable_types: struct s_control { int i; int k; char *tmp; } *

variable_types: struct s_elem { char token; char *str; struct s_elem *next; } *


decompiled_code:
void __fastcall eval_expr(__int64 a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rbp

if ( a1 )
{
v1 = malloc(0x10uLL);
v2 = v1;
if ( v1 )
{
initctrl(v1);
str_to_rpn(a1, v2);
my_putstr(v2[1]);
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rbp

if ( a1 )
{
v1 = malloc(0x10uLL);
v2 = v1;
if ( v1 )
{
initctrl(v1);
str_to_rpn(a1, v2);
my_putstr(v2[1]);
}
}
}

original_code:
void eval_expr(char *str)
{
  t_control *ctrlstr;
  if (str != ((void *)0))
    {
      if ((ctrlstr = malloc(sizeof(*ctrlstr))) == ((void *)0))
 return;
      initctrl(ctrlstr);
      str_to_rpn(str, ctrlstr);
      my_putstr(ctrlstr->tmp);
    }
}

canonical_original_code:
void eval_expr(char *str)
{
  struct s_control *ctrlstr;
  if (str != ((void *)0))
    {
      if ((ctrlstr = malloc(sizeof(*ctrlstr))) == ((void *)0))
 return;
      initctrl(ctrlstr);
      str_to_rpn(str, ctrlstr);
      my_putstr(ctrlstr->tmp);
    }
}

variable_types:
str
char *

user_defined_types: struct s_control { int i; int k; char *tmp; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
eval_expr((__int64)argv[1]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
func1((__int64)argv[1]);
return 0;
}

original_code:
int main(int ac, char **av)
{
  if (ac > 1)
    eval_expr(av[1]);
  return (0);
}

variable_types: ac int

variable_types:
av
char **


less

decompiled_code:
__int64 less()
{
return my_putstr("Try Again");
}

canonical_decompiled_code:
__int64 func0()
{
return my_putstr("Try Again");
}

original_code:
char less(char *val1, char *val2)
{
  my_putstr("Try Again");
}


mult

decompiled_code:
__int64 mult()
{
return my_putstr("Try Again");
}

canonical_decompiled_code:
__int64 func1()
{
return my_putstr("Try Again");
}

original_code:
char mult(char *val1, char *val2)
{
  my_putstr("Try Again");
}


division

decompiled_code:
__int64 division()
{
return my_putstr("Try Again");
}

canonical_decompiled_code:
__int64 func2()
{
return my_putstr("Try Again");
}

original_code:
char division(char *val1, char *val2)
{
  my_putstr("Try Again");
}


modulo

decompiled_code:
__int64 modulo()
{
return my_putstr("Try Again");
}

canonical_decompiled_code:
__int64 func3()
{
return my_putstr("Try Again");
}

original_code:
char modulo(char *val1, char *val2)
{
  my_putstr("Try Again");
}


mmalloc

decompiled_code:
void *mmalloc()
{
void *v0; // rbx
void *v1; // rax
void *result; // rax

v0 = malloc(0x18uLL);
v1 = malloc(8uLL);
if ( v0 && v1 )
result = &unk_253;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
void *func0()
{
void *v0; // rbx
void *v1; // rax
void *result; // rax

v0 = malloc(0x18uLL);
v1 = malloc(8uLL);
if ( v0 && v1 )
result = &unk_253;
else
result = 0LL;
return result;
}

original_code:
char *mmalloc(t_elem *elem, t_pile *pile)
{
  elem = malloc(sizeof(*elem));
  pile = malloc(sizeof(*pile));
  if (elem == ((void *)0) || pile == ((void *)0))
    return (((void *)0));
  return ("OK");
}

canonical_original_code:
char *mmalloc(struct s_elem *elem, struct s_pile *pile)
{
  elem = malloc(sizeof(*elem));
  pile = malloc(sizeof(*pile));
  if (elem == ((void *)0) || pile == ((void *)0))
    return (((void *)0));
  return ("OK");
}

variable_types: struct s_pile { struct s_elem *first; } *

return_type: char *

user_defined_types: struct s_elem { char token; char *str; struct s_elem *next; }


original_code:
int check_nonop(char *str, t_pile *pile, t_elem *actual, t_control *ctrl)
{
  if (str[ctrl->i] == '(')
    {
      stack(pile, str[ctrl->i]);
      return (2);
    }
  else if (str[ctrl->i] == ')')
    {
      while (actual != ((void *)0) && actual->token != '(')
 {
   ctrl->tmp[ctrl->k] = unstack(pile);
   actual = actual->next;
   ctrl->tmp[(ctrl->k) + 1] = ' ';
   ctrl->k += 2;
 }
      return (2);
    }
  else if (str[ctrl->i] == ' ')
    {
      ctrl->tmp[ctrl->k] = ' ';
      ctrl->k += 1;
      return (2);
    }
  return (1);
}

canonical_original_code:
int check_nonop(char *str, struct s_pile *pile, struct s_elem *actual, struct s_control *ctrl)
{
  if (str[ctrl->i] == '(')
    {
      stack(pile, str[ctrl->i]);
      return (2);
    }
  else if (str[ctrl->i] == ')')
    {
      while (actual != ((void *)0) && actual->token != '(')
 {
   ctrl->tmp[ctrl->k] = unstack(pile);
   actual = actual->next;
   ctrl->tmp[(ctrl->k) + 1] = ' ';
   ctrl->k += 2;
 }
      return (2);
    }
  else if (str[ctrl->i] == ' ')
    {
      ctrl->tmp[ctrl->k] = ' ';
      ctrl->k += 1;
      return (2);
    }
  return (1);
}

variable_types:
actual
struct s_elem *


original_code:
int check_operator(char *str, t_pile *pile, t_elem *actual, t_control *ctrl)
{
  if (str[ctrl->i] == '+' || str[ctrl->i] == '-')
    {
      if (actual->token == '%' || actual->token == '/' || actual->token == '*')
 {
   ctrl->tmp[ctrl->k] = unstack(pile);
   actual = actual->next;
   ctrl->tmp[(ctrl->k) + 1] = ' ';
   ctrl->k += 2;
 }
      stack(pile, str[ctrl->i]);
      return (2);
    }
  else if (str[ctrl->i] == '/' || str[ctrl->i] == '%' || str[ctrl->i] == '*')
    {
      if (actual->token == '%' || actual->token == '/' || actual->token == '*')
 {
   ctrl->tmp[ctrl->k] = unstack(pile);
   actual = actual->next;
   ctrl->tmp[(ctrl->k) + 1] = ' ';
   ctrl->k += 2;
 }
      stack(pile, str[ctrl->i]);
      return (2);
    }
  return (1);
}

canonical_original_code:
int check_operator(char *str, struct s_pile *pile, struct s_elem *actual, struct s_control *ctrl)
{
  if (str[ctrl->i] == '+' || str[ctrl->i] == '-')
    {
      if (actual->token == '%' || actual->token == '/' || actual->token == '*')
 {
   ctrl->tmp[ctrl->k] = unstack(pile);
   actual = actual->next;
   ctrl->tmp[(ctrl->k) + 1] = ' ';
   ctrl->k += 2;
 }
      stack(pile, str[ctrl->i]);
      return (2);
    }
  else if (str[ctrl->i] == '/' || str[ctrl->i] == '%' || str[ctrl->i] == '*')
    {
      if (actual->token == '%' || actual->token == '/' || actual->token == '*')
 {
   ctrl->tmp[ctrl->k] = unstack(pile);
   actual = actual->next;
   ctrl->tmp[(ctrl->k) + 1] = ' ';
   ctrl->k += 2;
 }
      stack(pile, str[ctrl->i]);
      return (2);
    }
  return (1);
}


original_code:
void check_operande(char *str, t_control *ctrl)
{
  while (str[ctrl->i] != ' ')
    {
      ctrl->tmp[ctrl->k] = str[ctrl->i];
      ctrl->k += 1;
      ctrl->i += 1;
    }
  ctrl->tmp[ctrl->k] = str[ctrl->i];
  ctrl->k += 1;
}

canonical_original_code:
void check_operande(char *str, struct s_control *ctrl)
{
  while (str[ctrl->i] != ' ')
    {
      ctrl->tmp[ctrl->k] = str[ctrl->i];
      ctrl->k += 1;
      ctrl->i += 1;
    }
  ctrl->tmp[ctrl->k] = str[ctrl->i];
  ctrl->k += 1;
}


freestack

original_code:
void freestack(t_elem *actual, t_control *ctrl, t_pile *pile)
{
  while (actual != ((void *)0))
    {
      ctrl->tmp[ctrl->k] = unstack(pile);
      actual = actual->next;
      ctrl->tmp[(ctrl->k) + 1] = ' ';
      ctrl->k += 2;
    }
}

canonical_original_code:
void freestack(struct s_elem *actual, struct s_control *ctrl, struct s_pile *pile)
{
  while (actual != ((void *)0))
    {
      ctrl->tmp[ctrl->k] = unstack(pile);
      actual = actual->next;
      ctrl->tmp[(ctrl->k) + 1] = ' ';
      ctrl->k += 2;
    }
}


decompiled_code:
void __fastcall my_putstrwozero(_BYTE *a1)
{
__int64 v2; // rax
int v3; // ecx
char v4; // di
char *v5; // rbx

if ( *a1 == 48 )
{
v2 = 1LL;
do
v3 = v2++;
while ( a1[v2 - 1] == 48 );
}
else
{
v3 = 0;
}
v4 = a1[v3];
if ( v4 )
{
v5 = &a1[v3 + 1];
do
{
my_putchar((unsigned int)v4);
v4 = *v5++;
}
while ( v4 );
}
}

canonical_decompiled_code:
void __fastcall func0(_BYTE *a1)
{
__int64 v2; // rax
int v3; // ecx
char v4; // di
char *v5; // rbx

if ( *a1 == 48 )
{
v2 = 1LL;
do
v3 = v2++;
while ( a1[v2 - 1] == 48 );
}
else
{
v3 = 0;
}
v4 = a1[v3];
if ( v4 )
{
v5 = &a1[v3 + 1];
do
{
my_putchar((unsigned int)v4);
v4 = *v5++;
}
while ( v4 );
}
}

original_code:
void my_putstrwozero(char *str)
{
  int i;
  i = 0;
  while (str[i] == '0')
    i += 1;
  while (str[i] != '\0')
    {
      my_putchar(str[i]);
      i += 1;
    }
}

variable_types: i int


addition

original_code:
int addition(char *result, char *other)
{
  int a;
  int b;
  a = my_strlen(result);
  b = my_strlen(other);
  while (b >= 0)
    {
      result[a] = result[a] + other[b] - '0';
      a = a - 1;
      b = b - 1;
    }
  a = my_strlen(result);
  while (a >= 1)
    {
      if (result[a] > '9')
        {
          result[a] = result[a] - 10;
          result[a - 1] = result[a - 1] + 1;
        }
      a = a - 1;
    }
  my_putstrwozero(result);
}

variable_types:
result
char *

variable_types:
other
char *

variable_types: a int

variable_types: b int


size

decompiled_code:
void __fastcall size(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbx
int v4; // er12
_BYTE *v5; // rax

v2 = a1;
v3 = a2;
v4 = my_strlen(a1);
if ( v4 < (int)my_strlen(a2) )
{
v2 = a2;
v3 = a1;
}
v5 = change_result(v2);
addition(v5, v3);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbx
int v4; // er12
_BYTE *v5; // rax

v2 = a1;
v3 = a2;
v4 = my_strlen(a1);
if ( v4 < (int)my_strlen(a2) )
{
v2 = a2;
v3 = a1;
}
v5 = change_result(v2);
func1(v5, v3);
}

original_code:
int size(char *str, char *str2)
{
  char *result;
  int a;
  int b;
  char *other;
  char *result2;
  result = malloc(sizeof(*result));
  a = my_strlen(str);
  b = my_strlen(str2);
  if (a >= b)
    {
      result = str;
      other = str2;
    }
  else if (b > a)
    {
      result = str2;
      other = str;
    }
  result2 = change_result(result);
  addition(result2, other);
}


add

decompiled_code:
__int64 __fastcall add(__int64 a1, __int64 a2)
{
size(a1, a2);
return my_putchar(10LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
func2(a1, a2);
return my_putchar(10LL);
}

original_code:
char add(char *val1, char *val2)
{
  size(val1, val2);
  my_putchar('\n');
}


initctrl

decompiled_code:
void *__fastcall initctrl(__int64 a1)
{
void *result; // rax

*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
result = malloc(1uLL);
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
result = malloc(1uLL);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void initctrl(t_control *control)
{
  control->i = 0;
  control->k = 0;
  control->tmp = malloc(sizeof(*control->tmp));
  if (control->tmp == ((void *)0))
    return;
}

canonical_original_code:
void initctrl(struct s_control *control)
{
  control->i = 0;
  control->k = 0;
  control->tmp = malloc(sizeof(*control->tmp));
  if (control->tmp == ((void *)0))
    return;
}


decompiled_code:
__int64 __fastcall do_op(int *a1, __int64 a2, __int64 a3)
{
char v4; // al
__int64 v5; // rbp
__int64 v6; // rax
char v7; // al
__int64 result; // rax
__int64 v9; // rbp
__int64 v10; // rax
char v11; // al
__int64 v12; // rbp
__int64 v13; // rax
char v14; // al
__int64 v15; // rbp
__int64 v16; // rax
char v17; // al
__int64 v18; // rbp
__int64 v19; // rax

v4 = *(_BYTE *)(*((_QWORD *)a1 + 1) + *a1);
if ( v4 == 43 )
{
v9 = unstackstr(a3);
v10 = unstackstr(a3);
v11 = add(v10, v9);
result = stack(a3, (unsigned int)v11);
}
else if ( v4 == 45 )
{
v12 = unstackstr(a3);
v13 = unstackstr(a3);
v14 = less(v13, v12);
result = stack(a3, (unsigned int)v14);
}
else if ( v4 == 47 )
{
v15 = unstackstr(a3);
v16 = unstackstr(a3);
v17 = division(v16, v15);
result = stack(a3, (unsigned int)v17);
}
else
{
if ( v4 == 37 )
{
v18 = unstackstr(a3);
v19 = unstackstr(a3);
v7 = modulo(v19, v18);
}
else
{
v5 = unstackstr(a3);
v6 = unstackstr(a3);
v7 = mult(v6, v5);
}
result = stack(a3, (unsigned int)v7);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, __int64 a2, __int64 a3)
{
char v4; // al
__int64 v5; // rbp
__int64 v6; // rax
char v7; // al
__int64 result; // rax
__int64 v9; // rbp
__int64 v10; // rax
char v11; // al
__int64 v12; // rbp
__int64 v13; // rax
char v14; // al
__int64 v15; // rbp
__int64 v16; // rax
char v17; // al
__int64 v18; // rbp
__int64 v19; // rax

v4 = *(_BYTE *)(*((_QWORD *)a1 + 1) + *a1);
if ( v4 == 43 )
{
v9 = unstackstr(a3);
v10 = unstackstr(a3);
v11 = add(v10, v9);
result = stack(a3, (unsigned int)v11);
}
else if ( v4 == 45 )
{
v12 = unstackstr(a3);
v13 = unstackstr(a3);
v14 = less(v13, v12);
result = stack(a3, (unsigned int)v14);
}
else if ( v4 == 47 )
{
v15 = unstackstr(a3);
v16 = unstackstr(a3);
v17 = division(v16, v15);
result = stack(a3, (unsigned int)v17);
}
else
{
if ( v4 == 37 )
{
v18 = unstackstr(a3);
v19 = unstackstr(a3);
v7 = modulo(v19, v18);
}
else
{
v5 = unstackstr(a3);
v6 = unstackstr(a3);
v7 = mult(v6, v5);
}
result = stack(a3, (unsigned int)v7);
}
return result;
}

original_code:
void do_op(t_control *ctrl, t_elem *actual, t_pile *pile)
{
  char *val1;
  char *val2;
  if (ctrl->tmp[ctrl->i] == '+')
    {
      val2 = unstackstr(pile);
      val1 = unstackstr(pile);
      stack(pile, add(val1, val2));
    }
  else if (ctrl->tmp[ctrl->i] == '-')
    {
      val2 = unstackstr(pile);
      val1 = unstackstr(pile);
      stack(pile, less(val1, val2));
    }
  else if (ctrl->tmp[ctrl->i] == '/')
    {
      val2 = unstackstr(pile);
      val1 = unstackstr(pile);
      stack(pile, division(val1, val2));
    }
  else if (ctrl->tmp[ctrl->i] == '%')
    {
      val2 = unstackstr(pile);
      val1 = unstackstr(pile);
      stack(pile, modulo(val1, val2));
    }
  else
    {
      val2 = unstackstr(pile);
      val1 = unstackstr(pile);
      stack(pile, mult(val1, val2));
    }
}

canonical_original_code:
void do_op(struct s_control *ctrl, struct s_elem *actual, struct s_pile *pile)
{
  char *val1;
  char *val2;
  if (ctrl->tmp[ctrl->i] == '+')
    {
      val2 = unstackstr(pile);
      val1 = unstackstr(pile);
      stack(pile, add(val1, val2));
    }
  else if (ctrl->tmp[ctrl->i] == '-')
    {
      val2 = unstackstr(pile);
      val1 = unstackstr(pile);
      stack(pile, less(val1, val2));
    }
  else if (ctrl->tmp[ctrl->i] == '/')
    {
      val2 = unstackstr(pile);
      val1 = unstackstr(pile);
      stack(pile, division(val1, val2));
    }
  else if (ctrl->tmp[ctrl->i] == '%')
    {
      val2 = unstackstr(pile);
      val1 = unstackstr(pile);
      stack(pile, modulo(val1, val2));
    }
  else
    {
      val2 = unstackstr(pile);
      val1 = unstackstr(pile);
      stack(pile, mult(val1, val2));
    }
}


checking

decompiled_code:
__int64 __fastcall checking(int *a1, __int64 a2, __int64 a3)
{
__int64 v5; // rdx
__int64 v6; // rax
char v7; // si
__int64 result; // rax
__int64 v9; // rcx

v5 = *((_QWORD *)a1 + 1);
v6 = *a1;
v7 = *(_BYTE *)(v5 + v6);
if ( v7 == 32 )
{
result = (unsigned int)*(unsigned __int8 *)(v5 + v6 + 1) - 48;
if ( (unsigned __int8)result > 9u )
result = stack(a3, 32LL);
}
else if ( (unsigned __int8)(v7 - 48) > 9u )
{
result = do_op(a1, a2, a3);
}
else if ( (unsigned __int8)(*(_BYTE *)(v5 + v6 + 1) - 48) > 9u )
{
stackstr(a3, (unsigned int)v7, (unsigned int)a1[1], a2);
result = stackstr(a3, 0LL, (unsigned int)(a1[1] + 1), v9);
}
else
{
*(_BYTE *)(*(_QWORD *)(a2 + 8) + a1[1]) = v7;
*(_BYTE *)(*(_QWORD *)(a2 + 8) + a1[1] + 1LL) = *(_BYTE *)(*((_QWORD *)a1 + 1) + *a1 + 1LL);
result = stackstr(a3, 0LL, (unsigned int)(a1[1] + 2), a2);
++*a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, __int64 a2, __int64 a3)
{
__int64 v5; // rdx
__int64 v6; // rax
char v7; // si
__int64 result; // rax
__int64 v9; // rcx

v5 = *((_QWORD *)a1 + 1);
v6 = *a1;
v7 = *(_BYTE *)(v5 + v6);
if ( v7 == 32 )
{
result = (unsigned int)*(unsigned __int8 *)(v5 + v6 + 1) - 48;
if ( (unsigned __int8)result > 9u )
result = stack(a3, 32LL);
}
else if ( (unsigned __int8)(v7 - 48) > 9u )
{
result = func0(a1, a2, a3);
}
else if ( (unsigned __int8)(*(_BYTE *)(v5 + v6 + 1) - 48) > 9u )
{
stackstr(a3, (unsigned int)v7, (unsigned int)a1[1], a2);
result = stackstr(a3, 0LL, (unsigned int)(a1[1] + 1), v9);
}
else
{
*(_BYTE *)(*(_QWORD *)(a2 + 8) + a1[1]) = v7;
*(_BYTE *)(*(_QWORD *)(a2 + 8) + a1[1] + 1LL) = *(_BYTE *)(*((_QWORD *)a1 + 1) + *a1 + 1LL);
result = stackstr(a3, 0LL, (unsigned int)(a1[1] + 2), a2);
++*a1;
}
return result;
}

original_code:
void checking(t_control *ctrl, t_elem *actual, t_pile *pile)
{
  if (ctrl->tmp[ctrl->i] == ' ')
    {
      if (ctrl->tmp[ctrl->i + 1] >= '0' && ctrl->tmp[ctrl->i + 1] <= '9')
 return;
      else
 stack(pile, ' ');
    }
  else if (ctrl->tmp[ctrl->i] >= '0' && ctrl->tmp[ctrl->i] <= '9')
    {
      if (ctrl->tmp[ctrl->i + 1] >= '0' && ctrl->tmp[ctrl->i + 1] <= '9')
 {
   actual->str[ctrl->k] = ctrl->tmp[ctrl->i];
   actual->str[ctrl->k + 1] = ctrl->tmp[ctrl->i + 1];
   stackstr(pile, '\0', ctrl->k + 2);
   ctrl->i += 1;
 }
      else
 {
   stackstr(pile, ctrl->tmp[ctrl->i], ctrl->k);
   stackstr(pile, '\0', ctrl->k + 1);
 }
    }
  else
    do_op(ctrl, actual, pile);
}

canonical_original_code:
void checking(struct s_control *ctrl, struct s_elem *actual, struct s_pile *pile)
{
  if (ctrl->tmp[ctrl->i] == ' ')
    {
      if (ctrl->tmp[ctrl->i + 1] >= '0' && ctrl->tmp[ctrl->i + 1] <= '9')
 return;
      else
 stack(pile, ' ');
    }
  else if (ctrl->tmp[ctrl->i] >= '0' && ctrl->tmp[ctrl->i] <= '9')
    {
      if (ctrl->tmp[ctrl->i + 1] >= '0' && ctrl->tmp[ctrl->i + 1] <= '9')
 {
   actual->str[ctrl->k] = ctrl->tmp[ctrl->i];
   actual->str[ctrl->k + 1] = ctrl->tmp[ctrl->i + 1];
   stackstr(pile, '\0', ctrl->k + 2);
   ctrl->i += 1;
 }
      else
 {
   stackstr(pile, ctrl->tmp[ctrl->i], ctrl->k);
   stackstr(pile, '\0', ctrl->k + 1);
 }
    }
  else
    do_op(ctrl, actual, pile);
}


CloseSSPPort

repo: sixtyeight/Payout

decompiled_code:
int __fastcall CloseSSPPort(int a1)
{
int result; // eax

if ( a1 >= 0 )
result = close(a1);
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int result; // eax

if ( a1 >= 0 )
result = close(a1);
return result;
}

original_code:
void CloseSSPPort(const SSP_PORT port)
{
 if (port >= 0) {
  close(port);
 }
}

canonical_original_code:
void CloseSSPPort(int port)
{
 if (port >= 0) {
  close(port);
 }
}

variable_types: port int


SetupSSPPort

decompiled_code:
int __fastcall SetupSSPPort(int fd)
{
struct termios vars0; // [rsp+0h] [rbp+0h] BYREF

tcgetattr(fd, &vars0);
cfsetispeed(&vars0, 0xDu);
cfsetospeed(&vars0, 0xDu);
vars0.c_lflag &= 0xFFFFFFE4;
vars0.c_oflag &= 0xFFFFFFFE;
vars0.c_iflag = 0;
vars0.c_cflag = vars0.c_cflag & 0x7FFFFECF | 0x8F0;
fcntl(fd, 4, 2048LL);
return tcsetattr(fd, 0, &vars0);
}

canonical_decompiled_code:
int __fastcall func1(int fd)
{
struct termios vars0; // [rsp+0h] [rbp+0h] BYREF

tcgetattr(fd, &vars0);
cfsetispeed(&vars0, 0xDu);
cfsetospeed(&vars0, 0xDu);
vars0.c_lflag &= 0xFFFFFFE4;
vars0.c_oflag &= 0xFFFFFFFE;
vars0.c_iflag = 0;
vars0.c_cflag = vars0.c_cflag & 0x7FFFFECF | 0x8F0;
fcntl(fd, 4, 2048LL);
return tcsetattr(fd, 0, &vars0);
}

original_code:
void SetupSSPPort(const SSP_PORT port)
{
 struct termios options;
 tcgetattr(port, &options);
 cfsetispeed(&options, 0000015);
 cfsetospeed(&options, 0000015);
 options.c_cflag &= ~0000400;
 options.c_cflag |= 0000100;
 options.c_cflag &= ~0000060;
 options.c_cflag |= 0000060;
 options.c_lflag &= ~(0000002 | 0000010 | 0000020 | 0000001);
 options.c_oflag &= ~0000001;
 options.c_iflag = 0;
 options.c_iflag &= ~(0002000 | 0010000 | 0004000);
 options.c_cflag &= ~020000000000;
 options.c_cflag |= (0004000 | 0000200);
 fcntl(port, 4, 04000);
 tcsetattr(port, 0, &options);
}

canonical_original_code:
void SetupSSPPort(int port)
{
 struct termios options;
 tcgetattr(port, &options);
 cfsetispeed(&options, 0000015);
 cfsetospeed(&options, 0000015);
 options.c_cflag &= ~0000400;
 options.c_cflag |= 0000100;
 options.c_cflag &= ~0000060;
 options.c_cflag |= 0000060;
 options.c_lflag &= ~(0000002 | 0000010 | 0000020 | 0000001);
 options.c_oflag &= ~0000001;
 options.c_iflag = 0;
 options.c_iflag &= ~(0002000 | 0010000 | 0004000);
 options.c_cflag &= ~020000000000;
 options.c_cflag |= (0004000 | 0000200);
 fcntl(port, 4, 04000);
 tcsetattr(port, 0, &options);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


OpenSSPPort

decompiled_code:
__int64 __fastcall OpenSSPPort(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx

v1 = open(a1, 2306);
v2 = v1;
if ( v1 == -1 )
{
perror("Unable to open port");
}
else
{
fcntl(v1, 4, 1LL);
SetupSSPPort(v2);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx

v1 = open(a1, 2306);
v2 = v1;
if ( v1 == -1 )
{
perror("Unable to open port");
}
else
{
fcntl(v1, 4, 1LL);
func1(v2);
}
return v2;
}

original_code:
SSP_PORT OpenSSPPort(const char *port)
{
 int port_handle;
 port_handle = open(port, 02 | 0400 | 04000);
 if (port_handle == -1) {
  perror("Unable to open port");
 } else {
  fcntl(port_handle, 4, 1);
  SetupSSPPort(port_handle);
 }
 return port_handle;
}

canonical_original_code:
int OpenSSPPort(char *port)
{
 int port_handle;
 port_handle = open(port, 02 | 0400 | 04000);
 if (port_handle == -1) {
  perror("Unable to open port");
 } else {
  fcntl(port_handle, 4, 1);
  SetupSSPPort(port_handle);
 }
 return port_handle;
}

variable_types:
port
char *


BytesInBuffer

decompiled_code:
__int64 __fastcall BytesInBuffer(int a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

ioctl(a1, 0x541BuLL, v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

ioctl(a1, 0x541BuLL, v2);
return v2[0];
}

original_code:
int BytesInBuffer(SSP_PORT port)
{
 int bytes;
 ioctl(port, 0x541B, &bytes);
 return bytes;
}

canonical_original_code:
int BytesInBuffer(int port)
{
 int bytes;
 ioctl(port, 0x541B, &bytes);
 return bytes;
}

variable_types: bytes int


TransmitComplete

decompiled_code:
_BOOL8 __fastcall TransmitComplete(int a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

ioctl(a1, 0x5411uLL, v2);
return v2[0] == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

ioctl(a1, 0x5411uLL, v2);
return v2[0] == 0;
}

original_code:
int TransmitComplete(SSP_PORT port)
{
 int bytes;
 ioctl(port, 0x5411, &bytes);
 return (bytes == 0);
}

canonical_original_code:
int TransmitComplete(int port)
{
 int bytes;
 ioctl(port, 0x5411, &bytes);
 return (bytes == 0);
}


WriteData

decompiled_code:
__int64 __fastcall WriteData(__int64 a1, __int64 a2, int a3)
{
signed __int64 v4; // r12
__int64 v5; // r13
__int64 result; // rax
ssize_t v7; // rbp

v4 = a2;
v5 = 0LL;
result = 1LL;
if ( a2 > 0 )
{
while ( 1 )
{
while ( !TransmitComplete(a3) )
usleep(0x64u);
v7 = write(a3, (const void *)(a1 + v5), v4);
usleep(0x1F4u);
if ( v7 < 0 )
break;
v5 += v7;
v4 -= v7;
if ( v4 <= 0 )
return 1LL;
}
perror("Write Port Failed");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int a3)
{
signed __int64 v4; // r12
__int64 v5; // r13
__int64 result; // rax
ssize_t v7; // rbp

v4 = a2;
v5 = 0LL;
result = 1LL;
if ( a2 > 0 )
{
while ( 1 )
{
while ( !func4(a3) )
usleep(0x64u);
v7 = write(a3, (const void *)(a1 + v5), v4);
usleep(0x1F4u);
if ( v7 < 0 )
break;
v5 += v7;
v4 -= v7;
if ( v4 <= 0 )
return 1LL;
}
perror("Write Port Failed");
result = 0LL;
}
return result;
}

original_code:
int WriteData(const unsigned char *data, unsigned long length, const SSP_PORT port)
{
 long n;
 long offset;
 long bytes_left = length;
 offset = 0;
 while (bytes_left > 0) {
  while (TransmitComplete(port) == 0)
   usleep(100);
  n = write(port, &data[offset], bytes_left);
  usleep(500);
  if (n < 0) {
   perror("Write Port Failed");
   return 0;
  }
  offset += n;
  bytes_left -= n;
 }
 return 1;
}

canonical_original_code:
int WriteData(unsigned char *data, unsigned long length, int port)
{
 long n;
 long offset;
 long bytes_left = length;
 offset = 0;
 while (bytes_left > 0) {
  while (TransmitComplete(port) == 0)
   usleep(100);
  n = write(port, &data[offset], bytes_left);
  usleep(500);
  if (n < 0) {
   perror("Write Port Failed");
   return 0;
  }
  offset += n;
  bytes_left -= n;
 }
 return 1;
}

variable_types:
data
unsigned char *

variable_types:
length
unsigned long

variable_types: n long

variable_types: offset long


ReadData

decompiled_code:
ssize_t __fastcall ReadData(int a1, void *a2, size_t a3)
{
return read(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func6(int a1, void *a2, size_t a3)
{
return read(a1, a2, a3);
}

original_code:
int ReadData(const SSP_PORT port, unsigned char *buffer, unsigned long bytes_to_read)
{
 return read(port, buffer, bytes_to_read);
}

canonical_original_code:
int ReadData(int port, unsigned char *buffer, unsigned long bytes_to_read)
{
 return read(port, buffer, bytes_to_read);
}

variable_types:
buffer
unsigned char *


SetBaud

decompiled_code:
int __fastcall SetBaud(int fd, unsigned __int64 a2)
{
struct termios v3; // [rsp+0h] [rbp-58h] BYREF

tcgetattr(fd, &v3);
if ( a2 == 38400 )
{
cfsetispeed(&v3, 0xFu);
}
else if ( a2 <= 0x9600 )
{
if ( a2 == 9600 )
{
cfsetispeed(&v3, 0xDu);
}
else if ( a2 == 19200 )
{
cfsetispeed(&v3, 0xEu);
}
}
else if ( a2 == 57600 )
{
cfsetispeed(&v3, 0x1001u);
}
else if ( a2 == 115200 )
{
cfsetispeed(&v3, 0x1002u);
}
tcsetattr(fd, 0, &v3);
return tcgetattr(fd, &v3);
}

canonical_decompiled_code:
int __fastcall func7(int fd, unsigned __int64 a2)
{
struct termios v3; // [rsp+0h] [rbp-58h] BYREF

tcgetattr(fd, &v3);
if ( a2 == 38400 )
{
cfsetispeed(&v3, 0xFu);
}
else if ( a2 <= 0x9600 )
{
if ( a2 == 9600 )
{
cfsetispeed(&v3, 0xDu);
}
else if ( a2 == 19200 )
{
cfsetispeed(&v3, 0xEu);
}
}
else if ( a2 == 57600 )
{
cfsetispeed(&v3, 0x1001u);
}
else if ( a2 == 115200 )
{
cfsetispeed(&v3, 0x1002u);
}
tcsetattr(fd, 0, &v3);
return tcgetattr(fd, &v3);
}

original_code:
void SetBaud(const SSP_PORT port, const unsigned long baud)
{
 struct termios options;
 tcgetattr(port, &options);
 switch (baud) {
 case 9600:
  cfsetispeed(&options, 0000015);
  break;
 case 19200:
  cfsetispeed(&options, 0000016);
  break;
 case 38400:
  cfsetispeed(&options, 0000017);
  break;
 case 57600:
  cfsetispeed(&options, 0010001);
  break;
 case 115200:
  cfsetispeed(&options, 0010002);
  break;
 }
 tcsetattr(port, 0, &options);
 tcgetattr(port, &options);
}

canonical_original_code:
void SetBaud(int port, unsigned long baud)
{
 struct termios options;
 tcgetattr(port, &options);
 switch (baud) {
 case 9600:
  cfsetispeed(&options, 0000015);
  break;
 case 19200:
  cfsetispeed(&options, 0000016);
  break;
 case 38400:
  cfsetispeed(&options, 0000017);
  break;
 case 57600:
  cfsetispeed(&options, 0010001);
  break;
 case 115200:
  cfsetispeed(&options, 0010002);
  break;
 }
 tcsetattr(port, 0, &options);
 tcgetattr(port, &options);
}

variable_types:
baud
unsigned long

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


XpowYmodN

original_code:
long long XpowYmodN(long long x, long long y, long long N)
{
 int i;
 long long result = 1;
 const long long oneShift63 = ((long long) 1) << 63;
 if (y == 1)
  return (x % N);
 for (i = 0; i < 64; y <<= 1, i++) {
  result = result * result % N;
  if (y & oneShift63)
   result = result * x % N;
 }
 return result;
}

canonical_original_code:
long long XpowYmodN(long long x, long long y, long long N)
{
 int i;
 long long result = 1;
 long long oneShift63 = ((long long) 1) << 63;
 if (y == 1)
  return (x % N);
 for (i = 0; i < 64; y <<= 1, i++) {
  result = result * result % N;
  if (y & oneShift63)
   result = result * x % N;
 }
 return result;
}

variable_types:
x
long long

variable_types:
y
long long

variable_types:
N
long long

variable_types:
result
long long

return_type: long long


IsItPrime

decompiled_code:
bool __fastcall IsItPrime(__int64 a1, __int64 a2)
{
return XpowYmodN(a2, a1 - 1, a1) == 1;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, __int64 a2)
{
return func0(a2, a1 - 1, a1) == 1;
}

original_code:
unsigned char IsItPrime(long long n, long long a)
{
 long long d = XpowYmodN(a, n - 1, n);
 if (d == 1)
  return 1;
 else
  return 0;
}

variable_types:
n
long long

variable_types:
a
long long

variable_types:
d
long long

return_type: unsigned char


MillerRabin

decompiled_code:
bool __fastcall MillerRabin(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // eax
bool result; // al

if ( a2 <= 0 )
return 1;
v2 = 0LL;
while ( 1 )
{
v3 = rand();
result = IsItPrime(a1, v3 % (a1 - 3) + 2);
if ( !result )
break;
if ( a2 == ++v2 )
return 1;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // eax
bool result; // al

if ( a2 <= 0 )
return 1;
v2 = 0LL;
while ( 1 )
{
v3 = rand();
result = func1(a1, v3 % (a1 - 3) + 2);
if ( !result )
break;
if ( a2 == ++v2 )
return 1;
}
return result;
}

original_code:
unsigned char MillerRabin(long long n, long long trials)
{
 long long a = 0;
 long long i;
 for (i = 0; i < trials; i++) {
  a = (rand() % (n - 3)) + 2;
  if (IsItPrime(n, a) == 0) {
   return 0;
  }
 }
 return 1;
}

variable_types:
trials
long long

variable_types:
i
long long


GetRTSC

decompiled_code:
time_t GetRTSC()
{
return time(0LL);
}

canonical_decompiled_code:
time_t func3()
{
return time(0LL);
}

original_code:
long long GetRTSC(void)
{
 return (long long) time(((void *)0));
}

canonical_original_code:
long long GetRTSC()
{
 return (long long) time(((void *)0));
}


GenerateRandomNumber

decompiled_code:
unsigned __int64 GenerateRandomNumber()
{
time_t v0; // rax

v0 = GetRTSC();
return (((v0 ^ 0xB3B06C3uLL) >> 25) | ((v0 ^ 0xB3B06C3) << 7)) + GetRTSC();
}

original_code:
unsigned long long GenerateRandomNumber(void)
{
 unsigned long rnd = 0x41594c49;
 unsigned long x = 0x94c49514;
 long long n;
 unsigned long long ret;
 {if (x&1) x=((x^0x80000055)>>1)|0x80000000; else x>>=1;};
 n = GetRTSC();
 rnd ^= n ^ x;
 (rnd=(rnd<<7)|(rnd>>(32-7)));
 ret = (unsigned long long) GetRTSC() + (unsigned long long) rnd;
 return ret;
}

canonical_original_code:
unsigned long long GenerateRandomNumber()
{
 unsigned long rnd = 0x41594c49;
 unsigned long x = 0x94c49514;
 long long n;
 unsigned long long ret;
 {if (x&1) x=((x^0x80000055)>>1)|0x80000000; else x>>=1;};
 n = GetRTSC();
 rnd ^= n ^ x;
 (rnd=(rnd<<7)|(rnd>>(32-7)));
 ret = (unsigned long long) GetRTSC() + (unsigned long long) rnd;
 return ret;
}

variable_types:
rnd
unsigned long

variable_types:
x
unsigned long

variable_types:
ret
unsigned long long

return_type: unsigned long long


GeneratePrime

decompiled_code:
__int64 GeneratePrime()
{
int v0; // eax
__int64 i; // rbx

v0 = GenerateRandomNumber();
for ( i = ((v0 & 1) == 0LL) + (unsigned __int64)(v0 & 0x7FFFFFFF); !MillerRabin(i, 5LL); i += 2LL )
;
return i;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // eax
__int64 i; // rbx

v0 = func4();
for ( i = ((v0 & 1) == 0LL) + (unsigned __int64)(v0 & 0x7FFFFFFF); !func2(i, 5LL); i += 2LL )
;
return i;
}

original_code:
unsigned long long GeneratePrime(void)
{
 unsigned long long tmp = 0;
 tmp = GenerateRandomNumber();
 tmp %= 2147483648LL;
 if ((tmp & 1) == 0)
  tmp += 1;
 if (MillerRabin(tmp, 5) == 1)
  return tmp;
 do {
  tmp += 2;
 } while (MillerRabin(tmp, 5) == 0);
 return tmp;
}

canonical_original_code:
unsigned long long GeneratePrime()
{
 unsigned long long tmp = 0;
 tmp = GenerateRandomNumber();
 tmp %= 2147483648LL;
 if ((tmp & 1) == 0)
  tmp += 1;
 if (MillerRabin(tmp, 5) == 1)
  return tmp;
 do {
  tmp += 2;
 } while (MillerRabin(tmp, 5) == 0);
 return tmp;
}

variable_types:
tmp
unsigned long long


GetProcDLLVersion

decompiled_code:
__int64 __fastcall GetProcDLLVersion(_BYTE *a1)
{
*a1 = 1;
a1[1] = 1;
a1[2] = 0;
return 1LL;
}

original_code:
int GetProcDLLVersion(unsigned char *ver)
{
 ver[0] = 1;
 ver[1] = 1;
 ver[2] = 0;
 return 1;
}

variable_types:
ver
unsigned char *


CreateSSPHostEncryptionKey

decompiled_code:
__int64 __fastcall CreateSSPHostEncryptionKey(_QWORD *a1)
{
a1[6] = XpowYmodN(a1[4], a1[3], a1[1]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
a1[6] = XpowYmodN(a1[4], a1[3], a1[1]);
return 1LL;
}

original_code:
int CreateSSPHostEncryptionKey(SSP_KEYS * keyArray)
{
 keyArray->KeyHost = XpowYmodN(keyArray->SlaveInterKey, keyArray->HostRandom, keyArray->Modulus);
 return 1;
}

canonical_original_code:
int CreateSSPHostEncryptionKey(struct SSP_KEYS *keyArray)
{
 keyArray->KeyHost = XpowYmodN(keyArray->SlaveInterKey, keyArray->HostRandom, keyArray->Modulus);
 return 1;
}

variable_types: struct SSP_KEYS { long long Generator; long long Modulus; long long HostInter; long long HostRandom; long long SlaveInterKey; long long SlaveRandom; long long KeyHost; long long KeySlave; } *


EncryptSSPPacket

original_code:
int EncryptSSPPacket(unsigned char ptNum, unsigned char *dataIn, unsigned char *dataOut, unsigned char *lengthIn,
       unsigned char *lengthOut, unsigned long long *key)
{
 unsigned char pkLength, i, packLength = 0;
 unsigned short crc;
 unsigned char tmpData[255];
 pkLength = *lengthIn + 7;
 if (pkLength % 16 != 0) {
  packLength = 16 - (pkLength % 16);
 }
 pkLength += packLength;
 tmpData[0] = *lengthIn;
 for (i = 0; i < 4; i++)
  tmpData[1 + i] = (unsigned char) ((encPktCount[ptNum] >> (8 * i) & 0xFF));
 for (i = 0; i < *lengthIn; i++)
  tmpData[i + 5] = dataIn[i];
 for (i = 0; i < packLength; i++)
  tmpData[5 + *lengthIn + i] = (unsigned char) (rand() % 255);
 crc = cal_crc_loop_CCITT_A(pkLength - 2, tmpData, 0xFFFF, 0x8005);
 tmpData[pkLength - 2] = (unsigned char) (crc & 0xFF);
 tmpData[pkLength - 1] = (unsigned char) ((crc >> 8) & 0xFF);
 if (aes_encrypt
     (1, (unsigned char *) key, 16, ((void *)0), 0, tmpData, &dataOut[1],
      pkLength) != 0x0)
  return 0;
 pkLength++;
 *lengthOut = pkLength;
 dataOut[0] = 0x7E;
 encPktCount[ptNum]++;
 return 1;
}

canonical_original_code:
int EncryptSSPPacket(unsigned char ptNum, unsigned char *dataIn, unsigned char *dataOut, unsigned char *lengthIn, unsigned char *lengthOut, unsigned long long *key)
{
 unsigned char pkLength; unsigned char i; unsigned char packLength = 0;
 unsigned short crc;
 unsigned char tmpData[255];
 pkLength = *lengthIn + 7;
 if (pkLength % 16 != 0) {
  packLength = 16 - (pkLength % 16);
 }
 pkLength += packLength;
 tmpData[0] = *lengthIn;
 for (i = 0; i < 4; i++)
  tmpData[1 + i] = (unsigned char) ((encPktCount[ptNum] >> (8 * i) & 0xFF));
 for (i = 0; i < *lengthIn; i++)
  tmpData[i + 5] = dataIn[i];
 for (i = 0; i < packLength; i++)
  tmpData[5 + *lengthIn + i] = (unsigned char) (rand() % 255);
 crc = cal_crc_loop_CCITT_A(pkLength - 2, tmpData, 0xFFFF, 0x8005);
 tmpData[pkLength - 2] = (unsigned char) (crc & 0xFF);
 tmpData[pkLength - 1] = (unsigned char) ((crc >> 8) & 0xFF);
 if (aes_encrypt
     (1, (unsigned char *) key, 16, ((void *)0), 0, tmpData, &dataOut[1],
      pkLength) != 0x0)
  return 0;
 pkLength++;
 *lengthOut = pkLength;
 dataOut[0] = 0x7E;
 encPktCount[ptNum]++;
 return 1;
}

variable_types:
ptNum
unsigned char

variable_types:
dataIn
unsigned char *

variable_types:
dataOut
unsigned char *

variable_types:
lengthIn
unsigned char *

variable_types:
lengthOut
unsigned char *

variable_types:
key
unsigned long long *

variable_types:
pkLength
unsigned char

variable_types:
i
unsigned char

variable_types:
packLength
unsigned char

variable_types:
crc
unsigned short

variable_types:
tmpData
unsigned char [255]


DecryptSSPPacket

decompiled_code:
_BOOL8 __fastcall DecryptSSPPacket(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4, __int64 a5)
{
return (unsigned __int8)aes_decrypt(1LL, a5, 16LL, 0LL, 0LL, a2, a1, *a3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4, __int64 a5)
{
return (unsigned __int8)aes_decrypt(1LL, a5, 16LL, 0LL, 0LL, a2, a1, *a3) == 0;
}

original_code:
int DecryptSSPPacket(unsigned char *dataIn, unsigned char *dataOut, unsigned char *lengthIn, unsigned char *lengthOut,
       unsigned long long *key)
{
 if (aes_decrypt(1, (unsigned char *) key, 16, ((void *)0), 0, dataOut, dataIn, *lengthIn) !=
     0x0)
  return 0;
 return 1;
}


CreateHostInterKey

decompiled_code:
__int64 __fastcall CreateHostInterKey(_QWORD *a1)
{
__int64 v1; // rsi

if ( !*a1 )
return 0xFFFFFFFFLL;
if ( !a1[1] )
return 0xFFFFFFFFLL;
v1 = GenerateRandomNumber() & 0x7FFFFFFF;
a1[3] = (unsigned int)v1;
a1[2] = XpowYmodN(*a1, v1, a1[1]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
__int64 v1; // rsi

if ( !*a1 )
return 0xFFFFFFFFLL;
if ( !a1[1] )
return 0xFFFFFFFFLL;
v1 = GenerateRandomNumber() & 0x7FFFFFFF;
a1[3] = (unsigned int)v1;
a1[2] = XpowYmodN(*a1, v1, a1[1]);
return 0LL;
}

original_code:
int CreateHostInterKey(SSP_KEYS * keyArray)
{
 if (keyArray->Generator == 0 || keyArray->Modulus == 0)
  return -1;
 keyArray->HostRandom = (long long) (GenerateRandomNumber() % 2147483648LL);
 keyArray->HostInter = XpowYmodN(keyArray->Generator, keyArray->HostRandom, keyArray->Modulus);
 return 0;
}

canonical_original_code:
int CreateHostInterKey(struct SSP_KEYS *keyArray)
{
 if (keyArray->Generator == 0 || keyArray->Modulus == 0)
  return -1;
 keyArray->HostRandom = (long long) (GenerateRandomNumber() % 2147483648LL);
 keyArray->HostInter = XpowYmodN(keyArray->Generator, keyArray->HostRandom, keyArray->Modulus);
 return 0;
}

user_defined_types: struct SSP_KEYS { long long Generator; long long Modulus; long long HostInter; long long HostRandom; long long SlaveInterKey; long long SlaveRandom; long long KeyHost; long long KeySlave; }


InitiateSSPHostKeys

decompiled_code:
__int64 __fastcall InitiateSSPHostKeys(_QWORD *a1, unsigned __int8 a2)
{
int v2; // edx
__int64 result; // rax

*a1 = GeneratePrime();
a1[1] = GeneratePrime();
v2 = CreateHostInterKey(a1);
result = 0LL;
if ( v2 != -1 )
{
encPktCount[a2] = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, unsigned __int8 a2)
{
int v2; // edx
__int64 result; // rax

*a1 = GeneratePrime();
a1[1] = GeneratePrime();
v2 = func4(a1);
result = 0LL;
if ( v2 != -1 )
{
encPktCount[a2] = 0;
result = 1LL;
}
return result;
}

original_code:
int InitiateSSPHostKeys(SSP_KEYS * keyArray, const unsigned char ssp_address)
{
 long long swap = 0;
 keyArray->Generator = GeneratePrime();
 keyArray->Modulus = GeneratePrime();
 if (keyArray->Generator > keyArray->Modulus) {
  swap = keyArray->Generator;
  keyArray->Generator = keyArray->Modulus;
  keyArray->Generator = swap;
 }
 if (CreateHostInterKey(keyArray) == -1)
  return 0;
 encPktCount[ssp_address] = 0;
 return 1;
}

canonical_original_code:
int InitiateSSPHostKeys(struct SSP_KEYS *keyArray, unsigned char ssp_address)
{
 long long swap = 0;
 keyArray->Generator = GeneratePrime();
 keyArray->Modulus = GeneratePrime();
 if (keyArray->Generator > keyArray->Modulus) {
  swap = keyArray->Generator;
  keyArray->Generator = keyArray->Modulus;
  keyArray->Generator = swap;
 }
 if (CreateHostInterKey(keyArray) == -1)
  return 0;
 encPktCount[ssp_address] = 0;
 return 1;
}

variable_types:
swap
long long


decompiled_code:
void *__fastcall my_init(__int64 a1, __int64 a2)
{
__int64 i; // rax
unsigned int v3; // eax
void *result; // rax

for ( i = 0LL; i != 200; ++i )
{
encPktCount[i] = 0;
sspSeq[i] = 0x80;
}
v3 = GetRTSC(a1, a2, sspSeq, encPktCount);
srand(v3);
result = &download_in_progress;
download_in_progress = 0;
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, __int64 a2)
{
__int64 i; // rax
unsigned int v3; // eax
void *result; // rax

for ( i = 0LL; i != 200; ++i )
{
encPktCount[i] = 0;
sspSeq[i] = 0x80;
}
v3 = GetRTSC(a1, a2, sspSeq, encPktCount);
srand(v3);
result = &download_in_progress;
download_in_progress = 0;
return result;
}

original_code:
void __attribute__ ((constructor)) my_init(void)
{
 int i;
 for (i = 0; i < 200; i++) {
  encPktCount[i] = 0;
  sspSeq[i] = 0x80;
 }
 srand((int) GetRTSC());
 download_in_progress = 0;
}

canonical_original_code:
void my_init()
{
 int i;
 for (i = 0; i < 200; i++) {
  encPktCount[i] = 0;
  sspSeq[i] = 0x80;
 }
 srand((int) GetRTSC());
 download_in_progress = 0;
}

variable_types: i int


decompiled_code:
void *my_fini()
{
void *result; // rax

result = &download_in_progress;
if ( download_in_progress )
{
puts("Waiting for download to complete...");
for ( result = &download_in_progress; download_in_progress; result = &download_in_progress )
sleep(1u);
}
return result;
}

canonical_decompiled_code:
void *func7()
{
void *result; // rax

result = &download_in_progress;
if ( download_in_progress )
{
puts("Waiting for download to complete...");
for ( result = &download_in_progress; download_in_progress; result = &download_in_progress )
sleep(1u);
}
return result;
}

original_code:
void __attribute__ ((destructor)) my_fini(void)
{
 if (download_in_progress) {
  printf("Waiting for download to complete...\n");
  while (download_in_progress)
   sleep(1);
 }
}

canonical_original_code:
void my_fini()
{
 if (download_in_progress) {
  printf("Waiting for download to complete...\n");
  while (download_in_progress)
   sleep(1);
 }
}


NegotiateSSPEncryption

original_code:
int NegotiateSSPEncryption(SSP_PORT port, const char ssp_address, SSP_FULL_KEY * key)
{
 SSP_KEYS temp_keys;
 SSP_COMMAND sspc;
 unsigned char i;
 if (InitiateSSPHostKeys(&temp_keys, ssp_address) == 0)
  return 0;
 sspc.EncryptionStatus = 0;
 sspc.RetryLevel = 2;
 sspc.Timeout = 1000;
 sspc.SSPAddress = ssp_address;
 sspc.CommandDataLength = 1;
 sspc.CommandData[0] = 0x11;
 SSPSendCommand(port, &sspc);
 if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
  return 0;
 sspc.CommandDataLength = 9;
 sspc.CommandData[0] = 0x4A;
 for (i = 0; i < 8; ++i)
  sspc.CommandData[1 + i] = (unsigned char) (temp_keys.Generator >> (i * 8));
 SSPSendCommand(port, &sspc);
 if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
  return 0;
 sspc.CommandDataLength = 9;
 sspc.CommandData[0] = 0x4B;
 for (i = 0; i < 8; ++i)
  sspc.CommandData[1 + i] = (unsigned char) (temp_keys.Modulus >> (i * 8));
 SSPSendCommand(port, &sspc);
 if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
  return 0;
 sspc.CommandDataLength = 9;
 sspc.CommandData[0] = 0x4C;
 for (i = 0; i < 8; ++i)
  sspc.CommandData[1 + i] = (unsigned char) (temp_keys.HostInter >> (i * 8));
 SSPSendCommand(port, &sspc);
 if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
  return 0;
 temp_keys.SlaveInterKey = 0;
 for (i = 0; i < 8; ++i)
  temp_keys.SlaveInterKey += ((long long) (sspc.ResponseData[1 + i])) << (8 * i);
 if (CreateSSPHostEncryptionKey(&temp_keys) == 0)
  return 0;
 key->EncryptKey = temp_keys.KeyHost;
 return 1;
}

canonical_original_code:
int NegotiateSSPEncryption(int port, char ssp_address, struct SSP_FULL_KEY *key)
{
 struct SSP_KEYS temp_keys;
 struct SSP_COMMAND sspc;
 unsigned char i;
 if (InitiateSSPHostKeys(&temp_keys, ssp_address) == 0)
  return 0;
 sspc.EncryptionStatus = 0;
 sspc.RetryLevel = 2;
 sspc.Timeout = 1000;
 sspc.SSPAddress = ssp_address;
 sspc.CommandDataLength = 1;
 sspc.CommandData[0] = 0x11;
 SSPSendCommand(port, &sspc);
 if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
  return 0;
 sspc.CommandDataLength = 9;
 sspc.CommandData[0] = 0x4A;
 for (i = 0; i < 8; ++i)
  sspc.CommandData[1 + i] = (unsigned char) (temp_keys.Generator >> (i * 8));
 SSPSendCommand(port, &sspc);
 if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
  return 0;
 sspc.CommandDataLength = 9;
 sspc.CommandData[0] = 0x4B;
 for (i = 0; i < 8; ++i)
  sspc.CommandData[1 + i] = (unsigned char) (temp_keys.Modulus >> (i * 8));
 SSPSendCommand(port, &sspc);
 if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
  return 0;
 sspc.CommandDataLength = 9;
 sspc.CommandData[0] = 0x4C;
 for (i = 0; i < 8; ++i)
  sspc.CommandData[1 + i] = (unsigned char) (temp_keys.HostInter >> (i * 8));
 SSPSendCommand(port, &sspc);
 if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
  return 0;
 temp_keys.SlaveInterKey = 0;
 for (i = 0; i < 8; ++i)
  temp_keys.SlaveInterKey += ((long long) (sspc.ResponseData[1 + i])) << (8 * i);
 if (CreateSSPHostEncryptionKey(&temp_keys) == 0)
  return 0;
 key->EncryptKey = temp_keys.KeyHost;
 return 1;
}

variable_types: port int

variable_types: struct SSP_FULL_KEY { unsigned long long FixedKey; unsigned long long EncryptKey; } *

variable_types: struct SSP_KEYS { long long Generator; long long Modulus; long long HostInter; long long HostRandom; long long SlaveInterKey; long long SlaveRandom; long long KeyHost; long long KeySlave; }

variable_types: struct SSP_COMMAND { struct SSP_FULL_KEY { unsigned long long FixedKey; unsigned long long EncryptKey; } Key; unsigned long BaudRate; unsigned long Timeout; unsigned char PortNumber; unsigned char SSPAddress; unsigned char RetryLevel; unsigned char EncryptionStatus; unsigned char CommandDataLength; unsigned char CommandData[255]; unsigned char ResponseStatus; unsigned char ResponseDataLength; unsigned char ResponseData[255]; unsigned char IgnoreError; }

user_defined_types: struct SSP_COMMAND { struct SSP_FULL_KEY Key; unsigned long BaudRate; unsigned long Timeout; unsigned char PortNumber; unsigned char SSPAddress; unsigned char RetryLevel; unsigned char EncryptionStatus; unsigned char CommandDataLength; unsigned char CommandData[255]; unsigned char ResponseStatus; unsigned char ResponseDataLength; unsigned char ResponseData[255]; unsigned char IgnoreError; }


CompileSSPCommand

original_code:
int CompileSSPCommand(SSP_COMMAND * cmd, SSP_TX_RX_PACKET * ss)
{
 int i, j;
 unsigned short crc;
 unsigned char tBuffer[255];
 ss->rxPtr = 0;
 for (i = 0; i < 255; i++)
  ss->rxData[i] = 0x00;
 if (cmd->CommandData[0] == 0x11)
  sspSeq[cmd->SSPAddress] = 0x80;
 if (cmd->EncryptionStatus) {
  if (!EncryptSSPPacket
      (cmd->SSPAddress, cmd->CommandData, cmd->CommandData, &cmd->CommandDataLength,
       &cmd->CommandDataLength, (unsigned long long *) &cmd->Key))
   return 0;
 }
 ss->CheckStuff = 0;
 ss->SSPAddress = cmd->SSPAddress;
 ss->rxPtr = 0;
 ss->txPtr = 0;
 ss->rxBufferLength = 3;
 ss->txBufferLength = cmd->CommandDataLength + 5;
 ss->txData[0] = 0x7F;
 ss->txData[1] = cmd->SSPAddress | sspSeq[cmd->SSPAddress];
 ss->txData[2] = cmd->CommandDataLength;
 for (i = 0; i < cmd->CommandDataLength; i++)
  ss->txData[3 + i] = cmd->CommandData[i];
 crc = cal_crc_loop_CCITT_A(ss->txBufferLength - 3, &ss->txData[1], 0xFFFF, 0x8005);
 ss->txData[3 + cmd->CommandDataLength] = (unsigned char) (crc & 0xFF);
 ss->txData[4 + cmd->CommandDataLength] = (unsigned char) ((crc >> 8) & 0xFF);
 j = 0;
 tBuffer[j++] = ss->txData[0];
 for (i = 1; i < ss->txBufferLength; i++) {
  tBuffer[j] = ss->txData[i];
  if (ss->txData[i] == 0x7F) {
   tBuffer[++j] = 0x7F;
  }
  j++;
 }
 for (i = 0; i < j; i++)
  ss->txData[i] = tBuffer[i];
 ss->txBufferLength = j;
 return 1;
}

canonical_original_code:
int CompileSSPCommand(struct SSP_COMMAND *cmd, struct SSP_TX_RX_PACKET *ss)
{
 int i; int j;
 unsigned short crc;
 unsigned char tBuffer[255];
 ss->rxPtr = 0;
 for (i = 0; i < 255; i++)
  ss->rxData[i] = 0x00;
 if (cmd->CommandData[0] == 0x11)
  sspSeq[cmd->SSPAddress] = 0x80;
 if (cmd->EncryptionStatus) {
  if (!EncryptSSPPacket
      (cmd->SSPAddress, cmd->CommandData, cmd->CommandData, &cmd->CommandDataLength,
       &cmd->CommandDataLength, (unsigned long long *) &cmd->Key))
   return 0;
 }
 ss->CheckStuff = 0;
 ss->SSPAddress = cmd->SSPAddress;
 ss->rxPtr = 0;
 ss->txPtr = 0;
 ss->rxBufferLength = 3;
 ss->txBufferLength = cmd->CommandDataLength + 5;
 ss->txData[0] = 0x7F;
 ss->txData[1] = cmd->SSPAddress | sspSeq[cmd->SSPAddress];
 ss->txData[2] = cmd->CommandDataLength;
 for (i = 0; i < cmd->CommandDataLength; i++)
  ss->txData[3 + i] = cmd->CommandData[i];
 crc = cal_crc_loop_CCITT_A(ss->txBufferLength - 3, &ss->txData[1], 0xFFFF, 0x8005);
 ss->txData[3 + cmd->CommandDataLength] = (unsigned char) (crc & 0xFF);
 ss->txData[4 + cmd->CommandDataLength] = (unsigned char) ((crc >> 8) & 0xFF);
 j = 0;
 tBuffer[j++] = ss->txData[0];
 for (i = 1; i < ss->txBufferLength; i++) {
  tBuffer[j] = ss->txData[i];
  if (ss->txData[i] == 0x7F) {
   tBuffer[++j] = 0x7F;
  }
  j++;
 }
 for (i = 0; i < j; i++)
  ss->txData[i] = tBuffer[i];
 ss->txBufferLength = j;
 return 1;
}

variable_types: struct SSP_COMMAND { struct SSP_FULL_KEY { unsigned long long FixedKey; unsigned long long EncryptKey; } Key; unsigned long BaudRate; unsigned long Timeout; unsigned char PortNumber; unsigned char SSPAddress; unsigned char RetryLevel; unsigned char EncryptionStatus; unsigned char CommandDataLength; unsigned char CommandData[255]; unsigned char ResponseStatus; unsigned char ResponseDataLength; unsigned char ResponseData[255]; unsigned char IgnoreError; } *

variable_types: struct SSP_TX_RX_PACKET { unsigned char txData[255]; unsigned char txPtr; unsigned char rxData[255]; unsigned char rxPtr; unsigned char txBufferLength; unsigned char rxBufferLength; unsigned char SSPAddress; unsigned char NewResponse; unsigned char CheckStuff; } *

variable_types: j int

variable_types:
tBuffer
unsigned char [255]


GetClockMs

decompiled_code:
__suseconds_t GetClockMs()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec / 1000 + 1000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func1()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec / 1000 + 1000 * v1.tv_sec;
}

original_code:
clock_t GetClockMs()
{
 clock_t test;
 struct timeval tv;
 gettimeofday(&tv, 0);
 test = tv.tv_sec * 1000;
 test += (tv.tv_usec) / 1000;
 return test;
}

canonical_original_code:
long GetClockMs()
{
 long test;
 struct timeval tv;
 gettimeofday(&tv, 0);
 test = tv.tv_sec * 1000;
 test += (tv.tv_usec) / 1000;
 return test;
}

variable_types: test long

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

return_type: long