repo: abgood/tsar

original_code:
static void set_part_record(struct module *mod, double st_array[], unsigned long long pre_array[], unsigned long long cur_array[], int inter) {
    st_array[0] = cur_array[3] * cur_array[0];
    st_array[1] = (cur_array[2] - cur_array[1]) * cur_array[0];
    st_array[2] = cur_array[2] * cur_array[0];
    unsigned long long used = cur_array[2] - cur_array[1];
    unsigned long long nonroot_total = cur_array[2] - cur_array[1] + cur_array[3];
    if (nonroot_total != 0)
        st_array[3] = (used * 100.0) / nonroot_total + ((used * 100) % nonroot_total != 0);
}

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: inter int

variable_types:
used
unsigned long long

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


decompiled_code:
__int64 __fastcall store_single_partition(char *a1, const char *a2, unsigned int *a3)
{
int v4; // eax

v4 = sprintf(a1, "%s=", a2);
return (unsigned int)(v4
+ sprintf(
&a1[v4],
"%d,%lld,%lld,%lld",
*a3,
*((_QWORD *)a3 + 2),
*((_QWORD *)a3 + 1),
*((_QWORD *)a3 + 3)));
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, const char *a2, unsigned int *a3)
{
int v4; // eax

v4 = sprintf(a1, "%s=", a2);
return (unsigned int)(v4
+ sprintf(
&a1[v4],
"%d,%lld,%lld,%lld",
*a3,
*((_QWORD *)a3 + 2),
*((_QWORD *)a3 + 1),
*((_QWORD *)a3 + 3)));
}

original_code:
int store_single_partition(char *buf, char *mntpath, struct stats_partition *sp) {
    int len = 0;
    len += sprintf(buf, "%s=", mntpath);
    len += sprintf(buf + len, "%d,%lld,%lld,%lld",
            sp->bsize,
            sp->bfree,
            sp->blocks,
            sp->bavail);
    return len;
}

variable_types:
buf
char *

variable_types:
mntpath
char *

variable_types: struct stats_partition { int bsize; unsigned long long blocks; unsigned long long bfree; unsigned long long bavail; unsigned long long itotal; unsigned long long ifree; } *

variable_types: len int

return_type: int


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

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

original_code:
void mod_register(struct module *mod) {
    register_mod_fileds(mod, "--partion", partition_usage, part_info, 4, read_partition_stat, set_part_record);
}

return_type: void

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


usage

decompiled_code:
void __noreturn usage()
{
const char *v0; // rbp
int v1; // ebx

fwrite(
"Usage: tsar [options]\n"
"Options:\n"
" --check/-C display last record for alert.example:tsar --check / tsar --check --cpu --io\n"
" --cron/-c run in cron mode, output data to file\n"
" --interval/-i specify intervals numbers, in minutes if with --live, it is in seconds\n"
" --list/-L list enabled modules\n"
" --live/-l running print live mode, which module will print\n"
" --file/-f specify a filepath as input\n"
" --ndays/-n show the value for the past days (default: 1)\n"
" --date/-d show the value for the specify day(n or YYYYMMDD)\n"
" --merge/-m merge multiply item to one\n"
" --detail/-D do not conver data to K/M/G\n"
" --spec/-s show spec field data, tsar --cpu -s sys,util\n"
" --item/-I show spec item data, tsar --io -I sda\n"
" --encry/-e DES encrypt the string, tsar -e <string> \n"
" --decry/-j DES decrypt the string, tsar -j <string> \n"
" --aesenc/-a AES encrypt the string, tsar -a <string> \n"
" --aesdec/-x AES decrypt the string, tsar -x <string> \n"
" --help/-h help\n",
1uLL,
0x415uLL,
stderr);
fwrite("Modules Enabled:\n", 1uLL, 0x11uLL, stderr);
if ( (int)statis > 0 )
{
v0 = (const char *)(unsigned int)((_DWORD)mods + 320);
v1 = 0;
do
{
fputs(v0, stderr);
fputc(10, stderr);
++v1;
v0 += 4832;
}
while ( (int)statis > v1 );
}
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
const char *v0; // rbp
int v1; // ebx

fwrite(
"Usage: tsar [options]\n"
"Options:\n"
" --check/-C display last record for alert.example:tsar --check / tsar --check --cpu --io\n"
" --cron/-c run in cron mode, output data to file\n"
" --interval/-i specify intervals numbers, in minutes if with --live, it is in seconds\n"
" --list/-L list enabled modules\n"
" --live/-l running print live mode, which module will print\n"
" --file/-f specify a filepath as input\n"
" --ndays/-n show the value for the past days (default: 1)\n"
" --date/-d show the value for the specify day(n or YYYYMMDD)\n"
" --merge/-m merge multiply item to one\n"
" --detail/-D do not conver data to K/M/G\n"
" --spec/-s show spec field data, tsar --cpu -s sys,util\n"
" --item/-I show spec item data, tsar --io -I sda\n"
" --encry/-e DES encrypt the string, tsar -e <string> \n"
" --decry/-j DES decrypt the string, tsar -j <string> \n"
" --aesenc/-a AES encrypt the string, tsar -a <string> \n"
" --aesdec/-x AES decrypt the string, tsar -x <string> \n"
" --help/-h help\n",
1uLL,
0x415uLL,
stderr);
fwrite("Modules Enabled:\n", 1uLL, 0x11uLL, stderr);
if ( (int)statis > 0 )
{
v0 = (const char *)(unsigned int)((_DWORD)mods + 320);
v1 = 0;
do
{
fputs(v0, stderr);
fputc(10, stderr);
++v1;
v0 += 4832;
}
while ( (int)statis > v1 );
}
exit(0);
}

original_code:
void usage(void) {
    int i;
    struct module *mod;
    fprintf(stderr,
            "Usage: tsar [options]\n"
            "Options:\n"
            "    --check/-C     display last record for alert.example:tsar --check / tsar --check --cpu --io\n"
            "    --cron/-c      run in cron mode, output data to file\n"
            "    --interval/-i  specify intervals numbers, in minutes if with --live, it is in seconds\n"
            "    --list/-L      list enabled modules\n"
            "    --live/-l      running print live mode, which module will print\n"
            "    --file/-f      specify a filepath as input\n"
            "    --ndays/-n     show the value for the past days (default: 1)\n"
            "    --date/-d      show the value for the specify day(n or YYYYMMDD)\n"
            "    --merge/-m     merge multiply item to one\n"
            "    --detail/-D    do not conver data to K/M/G\n"
            "    --spec/-s      show spec field data, tsar --cpu -s sys,util\n"
            "    --item/-I      show spec item data, tsar --io -I sda\n"
            "    --encry/-e     DES encrypt the string, tsar -e <string> \n"
            "    --decry/-j     DES decrypt the string, tsar -j <string> \n"
            "    --aesenc/-a    AES encrypt the string, tsar -a <string> \n"
            "    --aesdec/-x    AES decrypt the string, tsar -x <string> \n"
            "    --help/-h      help\n");
    fprintf(stderr,
            "Modules Enabled:\n"
           );
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        if (mod->usage) {
            fprintf(stderr, "%s", mod->usage);
            fprintf(stderr, "\n");
        }
    }
    exit(0);
}

canonical_original_code:
void usage() {
    int i;
    struct module *mod;
    fprintf(stderr,
            "Usage: tsar [options]\n"
            "Options:\n"
            "    --check/-C     display last record for alert.example:tsar --check / tsar --check --cpu --io\n"
            "    --cron/-c      run in cron mode, output data to file\n"
            "    --interval/-i  specify intervals numbers, in minutes if with --live, it is in seconds\n"
            "    --list/-L      list enabled modules\n"
            "    --live/-l      running print live mode, which module will print\n"
            "    --file/-f      specify a filepath as input\n"
            "    --ndays/-n     show the value for the past days (default: 1)\n"
            "    --date/-d      show the value for the specify day(n or YYYYMMDD)\n"
            "    --merge/-m     merge multiply item to one\n"
            "    --detail/-D    do not conver data to K/M/G\n"
            "    --spec/-s      show spec field data, tsar --cpu -s sys,util\n"
            "    --item/-I      show spec item data, tsar --io -I sda\n"
            "    --encry/-e     DES encrypt the string, tsar -e <string> \n"
            "    --decry/-j     DES decrypt the string, tsar -j <string> \n"
            "    --aesenc/-a    AES encrypt the string, tsar -a <string> \n"
            "    --aesdec/-x    AES decrypt the string, tsar -x <string> \n"
            "    --help/-h      help\n");
    fprintf(stderr,
            "Modules Enabled:\n"
           );
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        if (mod->usage) {
            fprintf(stderr, "%s", mod->usage);
            fprintf(stderr, "\n");
        }
    }
    exit(0);
}

variable_types: i int


decompiled_code:
int __fastcall main_init(int argc, char **argv)
{
int i; // ebx
int v3; // eax
int v4; // er13
const char *v5; // rbx
int v6; // eax
int result; // eax

for ( i = 0; ; i = v4 )
{
v3 = getopt_long(argc, argv, ":cCi:Llf:n:d:s:I:e:j:a:x:mhD", &longopts, 0LL);
if ( v3 == -1 )
break;
v4 = i + 1;
switch ( v3 )
{
case ':':
puts("must have parameter");
usage();
return result;
case '?':
v5 = argv[v4];
if ( !v5 || !strstr(argv[v4], "--") )
usage();
strcat((char *)(unsigned int)((_DWORD)conf + 2596), v5);
*(_WORD *)&conf[strlen((const char *)(unsigned int)((_DWORD)conf + 2596)) + 2596] = 44;
break;
case 'C':
*(_DWORD *)&conf[6212] = 3;
break;
case 'D':
*(_DWORD *)&conf[6224] = 1;
break;
case 'I':
set_special_item(optarg);
break;
case 'L':
*(_DWORD *)&conf[6212] = 1;
break;
case 'a':
*(_DWORD *)&conf[6212] = 6;
aes_enc(optarg);
break;
case 'c':
*(_DWORD *)&conf[6212] = 2;
break;
case 'd':
*(_DWORD *)&conf[6204] = atoi(optarg);
v4 = i + 2;
break;
case 'e':
*(_DWORD *)&conf[6212] = 6;
enc_code(optarg);
break;
case 'f':
strcpy((char *)(unsigned int)((_DWORD)conf + 388), optarg);
break;
case 'h':
usage();
return result;
case 'i':
*(_DWORD *)&conf[6216] = atoi(optarg);
v4 = i + 2;
break;
case 'j':
*(_DWORD *)&conf[6212] = 6;
dec_code(optarg, 1LL);
break;
case 'l':
*(_DWORD *)&conf[6212] = 5;
break;
case 'm':
*(_DWORD *)&conf[6220] = 1;
break;
case 'n':
*(_DWORD *)&conf[6208] = atoi(optarg);
v4 = i + 2;
break;
case 's':
set_special_field(optarg);
break;
case 'x':
*(_DWORD *)&conf[6212] = 6;
aes_dec(optarg, 1LL);
break;
default:
continue;
}
}
if ( !*(_DWORD *)&conf[6208] )
*(_DWORD *)&conf[6208] = 1;
if ( !*(_DWORD *)&conf[6216] )
*(_DWORD *)&conf[6216] = 5;
v6 = *(_DWORD *)&conf[6212];
if ( v6 )
{
if ( v6 == 3 )
{
*(_DWORD *)&conf[6216] = 60;
*(_DWORD *)&conf[6236] = 0;
*(_DWORD *)&conf[6228] = 60;
}
}
else
{
*(_DWORD *)&conf[6212] = 4;
}
*(_DWORD *)&conf[6232] = 1 - ((conf[2596] == 0) - 1);
strcpy(&conf[4], "tsar.conf");
result = access((const char *)(unsigned int)((_DWORD)conf + 4), 0);
if ( result )
result = do_debug(4LL, "main_init: can't find tsar.conf\n");
return result;
}

canonical_decompiled_code:
int __fastcall func1(int argc, char **argv)
{
int i; // ebx
int v3; // eax
int v4; // er13
const char *v5; // rbx
int v6; // eax
int result; // eax

for ( i = 0; ; i = v4 )
{
v3 = getopt_long(argc, argv, ":cCi:Llf:n:d:s:I:e:j:a:x:mhD", &longopts, 0LL);
if ( v3 == -1 )
break;
v4 = i + 1;
switch ( v3 )
{
case ':':
puts("must have parameter");
func0();
return result;
case '?':
v5 = argv[v4];
if ( !v5 || !strstr(argv[v4], "--") )
func0();
strcat((char *)(unsigned int)((_DWORD)conf + 2596), v5);
*(_WORD *)&conf[strlen((const char *)(unsigned int)((_DWORD)conf + 2596)) + 2596] = 44;
break;
case 'C':
*(_DWORD *)&conf[6212] = 3;
break;
case 'D':
*(_DWORD *)&conf[6224] = 1;
break;
case 'I':
set_special_item(optarg);
break;
case 'L':
*(_DWORD *)&conf[6212] = 1;
break;
case 'a':
*(_DWORD *)&conf[6212] = 6;
aes_enc(optarg);
break;
case 'c':
*(_DWORD *)&conf[6212] = 2;
break;
case 'd':
*(_DWORD *)&conf[6204] = atoi(optarg);
v4 = i + 2;
break;
case 'e':
*(_DWORD *)&conf[6212] = 6;
enc_code(optarg);
break;
case 'f':
strcpy((char *)(unsigned int)((_DWORD)conf + 388), optarg);
break;
case 'h':
func0();
return result;
case 'i':
*(_DWORD *)&conf[6216] = atoi(optarg);
v4 = i + 2;
break;
case 'j':
*(_DWORD *)&conf[6212] = 6;
dec_code(optarg, 1LL);
break;
case 'l':
*(_DWORD *)&conf[6212] = 5;
break;
case 'm':
*(_DWORD *)&conf[6220] = 1;
break;
case 'n':
*(_DWORD *)&conf[6208] = atoi(optarg);
v4 = i + 2;
break;
case 's':
set_special_field(optarg);
break;
case 'x':
*(_DWORD *)&conf[6212] = 6;
aes_dec(optarg, 1LL);
break;
default:
continue;
}
}
if ( !*(_DWORD *)&conf[6208] )
*(_DWORD *)&conf[6208] = 1;
if ( !*(_DWORD *)&conf[6216] )
*(_DWORD *)&conf[6216] = 5;
v6 = *(_DWORD *)&conf[6212];
if ( v6 )
{
if ( v6 == 3 )
{
*(_DWORD *)&conf[6216] = 60;
*(_DWORD *)&conf[6236] = 0;
*(_DWORD *)&conf[6228] = 60;
}
}
else
{
*(_DWORD *)&conf[6212] = 4;
}
*(_DWORD *)&conf[6232] = 1 - ((conf[2596] == 0) - 1);
strcpy(&conf[4], "tsar.conf");
result = access((const char *)(unsigned int)((_DWORD)conf + 4), 0);
if ( result )
result = do_debug(4LL, "main_init: can't find tsar.conf\n");
return result;
}

original_code:
static void main_init(int argc, char **argv) {
    int opt, oind = 0;
    while ((opt = getopt_long(argc, argv, ":cCi:Llf:n:d:s:I:e:j:a:x:mhD", longopts, ((void *)0))) != -1) {
        oind++;
        switch (opt) {
            case 'c':
                conf.running_mode = RUN_CRON;
                break;
            case 'C':
                conf.running_mode = RUN_CHECK_NEW;
                break;
            case 'l':
                conf.running_mode = RUN_PRINT_LIVE;
                break;
            case 'L':
                conf.running_mode = RUN_LIST;
                break;
            case 'i':
                conf.print_interval = atoi(optarg);
                oind++;
                break;
            case 'f':
                strcpy(conf.output_file_path, optarg);
                break;
            case 's':
                set_special_field(optarg);
                break;
            case 'I':
                set_special_item(optarg);
                break;
            case 'n':
                conf.print_ndays = atoi(optarg);
                oind++;
                break;
            case 'd':
                conf.print_day = atoi(optarg);
                oind++;
                break;
            case 'm':
                conf.print_merge = MERGE_ITEM;
                break;
            case 'D':
                conf.print_detail = 1;
                break;
            case 'e':
                conf.running_mode = RUN_ENCRY;
                enc_code(optarg);
                break;
            case 'j':
                conf.running_mode = RUN_ENCRY;
                dec_code(optarg, 1);
                break;
            case 'a':
                conf.running_mode = RUN_ENCRY;
                aes_enc(optarg);
                break;
            case 'x':
                conf.running_mode = RUN_ENCRY;
                aes_dec(optarg, 1);
                break;
            case 'h':
                usage();
            case ':':
                printf("must have parameter\n");
                usage();
            case '?':
                if (argv[oind] && strstr(argv[oind], "--")) {
                    strcat(conf.output_print_mod, argv[oind]);
                    strcat(conf.output_print_mod, ",");
                } else
                    usage();
        }
    }
    if (!conf.print_ndays)
        conf.print_ndays = 1;
    if (!conf.print_interval)
        conf.print_interval = 5;
    if (RUN_NULL == conf.running_mode)
        conf.running_mode = RUN_PRINT;
    if (conf.running_mode == RUN_CHECK_NEW) {
        conf.print_interval = 60;
        conf.print_tail = 0;
        conf.print_nline_interval = conf.print_interval;
    }
    if (!strlen(conf.output_print_mod))
        conf.print_mode = DATA_SUMMARY;
    else
        conf.print_mode = DATA_DETAIL;
    strcpy(conf.config_file, "tsar.conf");
    if (access(conf.config_file, 0))
        do_debug(LOG_FATAL, "main_init: can't find tsar.conf\n");
}

canonical_original_code:
static void main_init(int argc, char **argv) {
    int opt; int oind = 0;
    while ((opt = getopt_long(argc, argv, ":cCi:Llf:n:d:s:I:e:j:a:x:mhD", longopts, ((void *)0))) != -1) {
        oind++;
        switch (opt) {
            case 'c':
                conf.running_mode = RUN_CRON;
                break;
            case 'C':
                conf.running_mode = RUN_CHECK_NEW;
                break;
            case 'l':
                conf.running_mode = RUN_PRINT_LIVE;
                break;
            case 'L':
                conf.running_mode = RUN_LIST;
                break;
            case 'i':
                conf.print_interval = atoi(optarg);
                oind++;
                break;
            case 'f':
                strcpy(conf.output_file_path, optarg);
                break;
            case 's':
                set_special_field(optarg);
                break;
            case 'I':
                set_special_item(optarg);
                break;
            case 'n':
                conf.print_ndays = atoi(optarg);
                oind++;
                break;
            case 'd':
                conf.print_day = atoi(optarg);
                oind++;
                break;
            case 'm':
                conf.print_merge = MERGE_ITEM;
                break;
            case 'D':
                conf.print_detail = 1;
                break;
            case 'e':
                conf.running_mode = RUN_ENCRY;
                enc_code(optarg);
                break;
            case 'j':
                conf.running_mode = RUN_ENCRY;
                dec_code(optarg, 1);
                break;
            case 'a':
                conf.running_mode = RUN_ENCRY;
                aes_enc(optarg);
                break;
            case 'x':
                conf.running_mode = RUN_ENCRY;
                aes_dec(optarg, 1);
                break;
            case 'h':
                usage();
            case ':':
                printf("must have parameter\n");
                usage();
            case '?':
                if (argv[oind] && strstr(argv[oind], "--")) {
                    strcat(conf.output_print_mod, argv[oind]);
                    strcat(conf.output_print_mod, ",");
                } else
                    usage();
        }
    }
    if (!conf.print_ndays)
        conf.print_ndays = 1;
    if (!conf.print_interval)
        conf.print_interval = 5;
    if (RUN_NULL == conf.running_mode)
        conf.running_mode = RUN_PRINT;
    if (conf.running_mode == RUN_CHECK_NEW) {
        conf.print_interval = 60;
        conf.print_tail = 0;
        conf.print_nline_interval = conf.print_interval;
    }
    if (!strlen(conf.output_print_mod))
        conf.print_mode = DATA_SUMMARY;
    else
        conf.print_mode = DATA_DETAIL;
    strcpy(conf.config_file, "tsar.conf");
    if (access(conf.config_file, 0))
        do_debug(LOG_FATAL, "main_init: can't find tsar.conf\n");
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types: oind int


decompiled_code:
int running_list()
{
int result; // eax
unsigned __int64 v1; // rbp
int v2; // ebx

result = puts("tsar enable follow modules:");
if ( (int)statis > 0 )
{
v1 = (unsigned int)((_DWORD)mods + 4);
v2 = 0;
do
{
result = printf("\t%s\n", (const char *)v1);
++v2;
v1 += 4832LL;
}
while ( (int)statis > v2 );
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax
unsigned __int64 v1; // rbp
int v2; // ebx

result = puts("tsar enable follow modules:");
if ( (int)statis > 0 )
{
v1 = (unsigned int)((_DWORD)mods + 4);
v2 = 0;
do
{
result = printf("\t%s\n", (const char *)v1);
++v2;
v1 += 4832LL;
}
while ( (int)statis > v2 );
}
return result;
}

original_code:
void running_list(void) {
    int i;
    struct module *mod;
    printf("tsar enable follow modules:\n");
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        printf("\t%s\n", mod->name + 4);
    }
}

canonical_original_code:
void running_list() {
    int i;
    struct module *mod;
    printf("tsar enable follow modules:\n");
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        printf("\t%s\n", mod->name + 4);
    }
}


decompiled_code:
char *running_cron()
{
char *result; // rax

collect_record();
if ( strstr((const char *)(unsigned int)((_DWORD)conf + 260), "file") )
output_file();
if ( strstr((const char *)(unsigned int)((_DWORD)conf + 260), "db") )
output_db();
result = strstr((const char *)(unsigned int)((_DWORD)conf + 260), "nagios");
if ( result )
result = (char *)output_nagios();
return result;
}

canonical_decompiled_code:
char *func3()
{
char *result; // rax

collect_record();
if ( strstr((const char *)(unsigned int)((_DWORD)conf + 260), "file") )
output_file();
if ( strstr((const char *)(unsigned int)((_DWORD)conf + 260), "db") )
output_db();
result = strstr((const char *)(unsigned int)((_DWORD)conf + 260), "nagios");
if ( result )
result = (char *)output_nagios();
return result;
}

original_code:
void running_cron(void) {
    collect_record();
    if (strstr(conf.output_interface, "file"))
        output_file();
    if (strstr(conf.output_interface, "db"))
        output_db();
    if (strstr(conf.output_interface, "nagios"))
        output_nagios();
}

canonical_original_code:
void running_cron() {
    collect_record();
    if (strstr(conf.output_interface, "file"))
        output_file();
    if (strstr(conf.output_interface, "db"))
        output_db();
    if (strstr(conf.output_interface, "nagios"))
        output_nagios();
}


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

free_modules();
memset(conf, 0, 0x18B0uLL);
result = memset(mods, 0, (size_t)&unk_25C00);
statis = 0LL;
*(&statis + 1) = 0LL;
return result;
}

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

free_modules();
memset(conf, 0, 0x18B0uLL);
result = memset(mods, 0, (size_t)&unk_25C00);
statis = 0LL;
*(&statis + 1) = 0LL;
return result;
}

original_code:
void shut_down(void) {
    free_modules();
    memset(&conf, 0, sizeof(struct configure));
    memset(&mods, 0, sizeof(struct module) * 32);
    memset(&statis, 0, sizeof(struct statistic));
}

canonical_original_code:
void shut_down() {
    free_modules();
    memset(&conf, 0, sizeof(struct configure));
    memset(&mods, 0, sizeof(struct module) * 32);
    memset(&statis, 0, sizeof(struct statistic));
}

user_defined_types: struct configure { int debug_level; char config_file[128]; char module_path[128]; char output_interface[128]; char output_file_path[128]; char output_db_addr[512]; char output_db_pawd[32]; char output_db_mod[512]; char output_nagios_mod[512]; char output_stdio_mod[512]; char output_print_mod[512]; char server_addr[512]; int *server_port; int *cycle_time; char send_nsca_cmd[512]; char send_nsca_conf[512]; int mod_num; char check_name[32][32]; float wmin[32]; float wmax[32]; float cmin[32]; float cmax[32]; int print_day; int print_ndays; int running_mode; int print_interval; int print_merge; int print_detail; int print_nline_interval; int print_mode; int print_tail; int print_file_number; int print_start_time; int print_end_time; char host_name[32]; char host_ip[32]; }

user_defined_types: struct statistic { int total_mod_num; long cur_time; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
parse_config_file("tsar.conf", argv, envp);
load_modules();
*(&statis + 1) = time(0LL);
*(_DWORD *)&conf[6204] = -1;
main_init(argc, (char **)argv);
switch ( *(_DWORD *)&conf[6212] )
{
case 1:
running_list();
break;
case 2:
*(_DWORD *)&conf[6232] = 2;
running_cron();
break;
case 3:
if ( (unsigned int)reload_modules((unsigned int)((_DWORD)conf + 2596)) )
*(_DWORD *)&conf[6232] = 2;
disable_col_zero();
running_check(3LL);
break;
case 4:
reload_modules((unsigned int)((_DWORD)conf + 2084));
reload_modules((unsigned int)((_DWORD)conf + 2596));
disable_col_zero();
*(_DWORD *)&conf[6228] = *(_DWORD *)&conf[6216];
running_print();
break;
case 5:
reload_modules((unsigned int)((_DWORD)conf + 2084));
reload_modules((unsigned int)((_DWORD)conf + 2596));
disable_col_zero();
running_print_live();
break;
default:
break;
}
shut_down();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
parse_config_file("tsar.conf", argv, envp);
load_modules();
*(&statis + 1) = time(0LL);
*(_DWORD *)&conf[6204] = -1;
func1(argc, (char **)argv);
switch ( *(_DWORD *)&conf[6212] )
{
case 1:
func2();
break;
case 2:
*(_DWORD *)&conf[6232] = 2;
func3();
break;
case 3:
if ( (unsigned int)reload_modules((unsigned int)((_DWORD)conf + 2596)) )
*(_DWORD *)&conf[6232] = 2;
disable_col_zero();
running_check(3LL);
break;
case 4:
reload_modules((unsigned int)((_DWORD)conf + 2084));
reload_modules((unsigned int)((_DWORD)conf + 2596));
disable_col_zero();
*(_DWORD *)&conf[6228] = *(_DWORD *)&conf[6216];
running_print();
break;
case 5:
reload_modules((unsigned int)((_DWORD)conf + 2084));
reload_modules((unsigned int)((_DWORD)conf + 2596));
disable_col_zero();
running_print_live();
break;
default:
break;
}
func4();
return 0;
}

original_code:
int main (int argc, char **argv) {
    parse_config_file("tsar.conf");
    load_modules();
    statis.cur_time = time(((void *)0));
    conf.print_day = -1;
    main_init(argc, argv);
    switch (conf.running_mode) {
        case RUN_LIST:
            running_list();
            break;
        case RUN_CRON:
            conf.print_mode = DATA_DETAIL;
            running_cron();
            break;
        case RUN_CHECK_NEW:
            if (reload_modules(conf.output_print_mod))
                conf.print_mode = DATA_DETAIL;
            disable_col_zero();
            running_check(RUN_CHECK_NEW);
            break;
        case RUN_PRINT:
            reload_modules(conf.output_stdio_mod);
            reload_modules(conf.output_print_mod);
            disable_col_zero();
            conf.print_nline_interval = conf.print_interval;
            running_print();
            break;
        case RUN_PRINT_LIVE:
            reload_modules(conf.output_stdio_mod);
            reload_modules(conf.output_print_mod);
            disable_col_zero();
            running_print_live();
            break;
        default:
            break;
    }
    shut_down();
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    parse_config_file("tsar.conf");
    load_modules();
    statis.cur_time = time(((void *)0));
    conf.print_day = -1;
    main_init(argc, argv);
    switch (conf.running_mode) {
        case RUN_LIST:
            running_list();
            break;
        case RUN_CRON:
            conf.print_mode = DATA_DETAIL;
            running_cron();
            break;
        case RUN_CHECK_NEW:
            if (reload_modules(conf.output_print_mod))
                conf.print_mode = DATA_DETAIL;
            disable_col_zero();
            running_check(RUN_CHECK_NEW);
            break;
        case RUN_PRINT:
            reload_modules(conf.output_stdio_mod);
            reload_modules(conf.output_print_mod);
            disable_col_zero();
            conf.print_nline_interval = conf.print_interval;
            running_print();
            break;
        case RUN_PRINT_LIVE:
            reload_modules(conf.output_stdio_mod);
            reload_modules(conf.output_print_mod);
            disable_col_zero();
            running_print_live();
            break;
        default:
            break;
    }
    shut_down();
    return 0;
}


original_code:
static void set_cpu_record(struct module *mod, double st_array[],
        unsigned long long pre_array[], unsigned long long cur_array[], int inter) {
    int i, j;
    unsigned long long pre_total, cur_total;
    pre_total = cur_total = 0;
    for (i = 0; i < mod->n_col; i++) {
        if (cur_array[i] < pre_array[i]) {
            for (j = 0; j < 9; j++)
                st_array[j] = -1;
            return;
        }
        pre_total += pre_array[i];
        cur_total += cur_array[i];
    }
    if (cur_total <= pre_total)
        return;
    for (i = 0; i < 9; i++) {
        if ((i != 5) && (cur_array[i] >= pre_array[i]))
            st_array[i] = (cur_array[i] - pre_array[i]) * 100.0 / (cur_total - pre_total);
    }
    st_array[5] = st_array[0] + st_array[1] + st_array[3] + st_array[4] + st_array[6];
}

canonical_original_code:
static void set_cpu_record(struct module *mod, double st_array[], unsigned long long pre_array[], unsigned long long cur_array[], int inter) {
    int i; int j;
    unsigned long long pre_total; unsigned long long cur_total;
    pre_total = cur_total = 0;
    for (i = 0; i < mod->n_col; i++) {
        if (cur_array[i] < pre_array[i]) {
            for (j = 0; j < 9; j++)
                st_array[j] = -1;
            return;
        }
        pre_total += pre_array[i];
        cur_total += cur_array[i];
    }
    if (cur_total <= pre_total)
        return;
    for (i = 0; i < 9; i++) {
        if ((i != 5) && (cur_array[i] >= pre_array[i]))
            st_array[i] = (cur_array[i] - pre_array[i]) * 100.0 / (cur_total - pre_total);
    }
    st_array[5] = st_array[0] + st_array[1] + st_array[3] + st_array[4] + st_array[6];
}

variable_types: j int


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

original_code:
void mod_register(struct module *mod) {
    register_mod_fileds(mod, "--cpu", cpu_usage, cpu_info, 9, read_cpu_stats, set_cpu_record);
}


original_code:
void byte2hexstr(char *dest, unsigned char *src, int len) {
    int i;
    unsigned char high_byte, low_byte;
    for (i = 0; i < len; i++) {
        high_byte = src[i] >> 4;
        low_byte = src[i] & 0x0f;
        high_byte += 0x30;
        if (high_byte > 0x39) {
            dest[i * 2] = high_byte + 0x07;
        } else {
            dest[i * 2] = high_byte;
        }
        low_byte += 0x30;
        if (low_byte > 0x39) {
            dest[i * 2 + 1] = low_byte + 0x07;
        } else {
            dest[i * 2 + 1] = low_byte;
        }
    }
}

canonical_original_code:
void byte2hexstr(char *dest, unsigned char *src, int len) {
    int i;
    unsigned char high_byte; unsigned char low_byte;
    for (i = 0; i < len; i++) {
        high_byte = src[i] >> 4;
        low_byte = src[i] & 0x0f;
        high_byte += 0x30;
        if (high_byte > 0x39) {
            dest[i * 2] = high_byte + 0x07;
        } else {
            dest[i * 2] = high_byte;
        }
        low_byte += 0x30;
        if (low_byte > 0x39) {
            dest[i * 2 + 1] = low_byte + 0x07;
        } else {
            dest[i * 2 + 1] = low_byte;
        }
    }
}

variable_types:
dest
char *

variable_types:
src
unsigned char *


original_code:
void hexstr2byte(unsigned char *dest, char *src, int len) {
    int i;
    unsigned char high_byte, low_byte;
    for (i = 0; i < len; i += 2) {
        high_byte = toupper(src[i]);
        low_byte = toupper(src[i + 1]);
        if (high_byte > 0x39) {
            high_byte -= 0x37;
        } else {
            high_byte -= 0x30;
        }
        if (low_byte > 0x39) {
            low_byte -= 0x37;
        } else {
            low_byte -= 0x30;
        }
        dest[i / 2] = (high_byte << 4) | low_byte;
    }
}

canonical_original_code:
void hexstr2byte(unsigned char *dest, char *src, int len) {
    int i;
    unsigned char high_byte; unsigned char low_byte;
    for (i = 0; i < len; i += 2) {
        high_byte = toupper(src[i]);
        low_byte = toupper(src[i + 1]);
        if (high_byte > 0x39) {
            high_byte -= 0x37;
        } else {
            high_byte -= 0x30;
        }
        if (low_byte > 0x39) {
            low_byte -= 0x37;
        } else {
            low_byte -= 0x30;
        }
        dest[i / 2] = (high_byte << 4) | low_byte;
    }
}

variable_types:
dest
unsigned char *

variable_types:
src
char *


decompiled_code:
int __fastcall aes_enc(char *s)
{
size_t v1; // rax
int v2; // ebx
_BYTE *v3; // r12
const char *v4; // rbp
_BYTE v6[256]; // [rsp+0h] [rbp-138h] BYREF
__int64 v7[7]; // [rsp+100h] [rbp-38h] BYREF

v7[0] = 0LL;
v7[1] = 0LL;
if ( (int)AES_set_encrypt_key("yunwei@love7road", 128LL, v6) < 0 )
do_debug(4LL, "Unable to set encryption key in AES\n");
v1 = strlen(s);
v2 = v1 + 1;
if ( (((_BYTE)v1 + 1) & 0xF) != 0 )
v2 = 16 * (((v1 + 1) >> 4) + 1);
v3 = calloc(v2, 1uLL);
v4 = (const char *)calloc(v2, 8uLL);
AES_cbc_encrypt(s, v3, v2, v6, v7, 1LL);
byte2hexstr((__int64)v4, v3, v2);
return printf("Your Message is Encrypted: %s\n", v4);
}

canonical_decompiled_code:
int __fastcall func2(char *s)
{
size_t v1; // rax
int v2; // ebx
_BYTE *v3; // r12
const char *v4; // rbp
_BYTE v6[256]; // [rsp+0h] [rbp-138h] BYREF
__int64 v7[7]; // [rsp+100h] [rbp-38h] BYREF

v7[0] = 0LL;
v7[1] = 0LL;
if ( (int)AES_set_encrypt_key("yunwei@love7road", 128LL, v6) < 0 )
do_debug(4LL, "Unable to set encryption key in AES\n");
v1 = strlen(s);
v2 = v1 + 1;
if ( (((_BYTE)v1 + 1) & 0xF) != 0 )
v2 = 16 * (((v1 + 1) >> 4) + 1);
v3 = calloc(v2, 1uLL);
v4 = (const char *)calloc(v2, 8uLL);
AES_cbc_encrypt(s, v3, v2, v6, v7, 1LL);
func0((__int64)v4, v3, v2);
return printf("Your Message is Encrypted: %s\n", v4);
}

original_code:
void aes_enc(char *string) {
    char *plain = "yunwei@love7road";
    unsigned char iv[16] = {0};
    unsigned char *output;
    int len;
    AES_KEY key;
    if (AES_set_encrypt_key((const unsigned char *)plain, 128, &key) < 0) {
        do_debug(LOG_FATAL, "Unable to set encryption key in AES\n");
    }
    if ((strlen(string) + 1) % 16 == 0) {
        len = strlen(string) + 1;
    } else {
        len = ((strlen(string) + 1) / 16 + 1) * 16;
    }
    output = (unsigned char *)calloc(len, sizeof(unsigned char));
    char *pawd = (char *)calloc(len, sizeof(char *));
    AES_cbc_encrypt((unsigned char *)string, output, len, &key, iv, 1);
    byte2hexstr(pawd, output, len);
    printf("Your Message is Encrypted: %s\n", pawd);
}

canonical_original_code:
void aes_enc(char *string) {
    char *plain = "yunwei@love7road";
    unsigned char iv[16] = {0};
    unsigned char *output;
    int len;
    struct aes_key_st key;
    if (AES_set_encrypt_key((unsigned char *)plain, 128, &key) < 0) {
        do_debug(LOG_FATAL, "Unable to set encryption key in AES\n");
    }
    if ((strlen(string) + 1) % 16 == 0) {
        len = strlen(string) + 1;
    } else {
        len = ((strlen(string) + 1) / 16 + 1) * 16;
    }
    output = (unsigned char *)calloc(len, sizeof(unsigned char));
    char *pawd = (char *)calloc(len, sizeof(char *));
    AES_cbc_encrypt((unsigned char *)string, output, len, &key, iv, 1);
    byte2hexstr(pawd, output, len);
    printf("Your Message is Encrypted: %s\n", pawd);
}

variable_types:
string
char *

variable_types:
plain
char *

variable_types:
iv
unsigned char [16]

variable_types:
output
unsigned char *

variable_types: struct aes_key_st { unsigned int rd_key[-1]; int rounds; }

variable_types:
pawd
char *


decompiled_code:
const char *__fastcall aes_dec(char *s, int a2)
{
int v2; // er13
void *v3; // rbp
const char *v4; // rbx
_BYTE v6[256]; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[9]; // [rsp+100h] [rbp-48h] BYREF

v7[0] = 0LL;
v7[1] = 0LL;
if ( (int)AES_set_decrypt_key("yunwei@love7road", 128LL, v6) < 0 )
do_debug(4LL, "Unable to set encryption key in AES\n");
v2 = strlen(s);
v3 = calloc(v2, 1uLL);
v4 = (const char *)calloc(v2, 8uLL);
hexstr2byte((__int64)v3, (__int64)s, v2);
AES_cbc_encrypt(v3, v4, v2, v6, v7, 0LL);
if ( a2 )
puts(v4);
return v4;
}

canonical_decompiled_code:
const char *__fastcall func3(char *s, int a2)
{
int v2; // er13
void *v3; // rbp
const char *v4; // rbx
_BYTE v6[256]; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[9]; // [rsp+100h] [rbp-48h] BYREF

v7[0] = 0LL;
v7[1] = 0LL;
if ( (int)AES_set_decrypt_key("yunwei@love7road", 128LL, v6) < 0 )
do_debug(4LL, "Unable to set encryption key in AES\n");
v2 = strlen(s);
v3 = calloc(v2, 1uLL);
v4 = (const char *)calloc(v2, 8uLL);
func1((__int64)v3, (__int64)s, v2);
AES_cbc_encrypt(v3, v4, v2, v6, v7, 0LL);
if ( a2 )
puts(v4);
return v4;
}

original_code:
char *aes_dec(char *pawd, int is_print) {
    char *plain = "yunwei@love7road";
    unsigned char iv[16] = {0};
    unsigned char *input;
    int len;
    AES_KEY key;
    if (AES_set_decrypt_key((const unsigned char *)plain, 128, &key) < 0) {
        do_debug(LOG_FATAL, "Unable to set encryption key in AES\n");
    }
    len = strlen(pawd);
    input = (unsigned char *)calloc(len, sizeof(unsigned char));
    char *string = (char *)calloc(len, sizeof(char *));
    hexstr2byte(input, pawd, len);
    AES_cbc_encrypt(input, (unsigned char *)string, len, &key, iv, 0);
    if (is_print) {
        printf("%s\n", string);
    }
    return string;
}

canonical_original_code:
char *aes_dec(char *pawd, int is_print) {
    char *plain = "yunwei@love7road";
    unsigned char iv[16] = {0};
    unsigned char *input;
    int len;
    struct aes_key_st key;
    if (AES_set_decrypt_key((unsigned char *)plain, 128, &key) < 0) {
        do_debug(LOG_FATAL, "Unable to set encryption key in AES\n");
    }
    len = strlen(pawd);
    input = (unsigned char *)calloc(len, sizeof(unsigned char));
    char *string = (char *)calloc(len, sizeof(char *));
    hexstr2byte(input, pawd, len);
    AES_cbc_encrypt(input, (unsigned char *)string, len, &key, iv, 0);
    if (is_print) {
        printf("%s\n", string);
    }
    return string;
}

variable_types:
input
unsigned char *

variable_types: len int

return_type: char *

user_defined_types: struct aes_key_st { unsigned int rd_key[-1]; int rounds; }


decompiled_code:
int __fastcall parse_mod(char *src)
{
int v1; // er13
const char *v2; // rbx
char *v3; // rbp
char *v4; // rax
__int64 v5; // r13
char *v6; // rax
const char *v7; // rbx
size_t v8; // rax
const char *v9; // rbx
size_t v10; // rax

v1 = statis;
if ( statis <= 0 )
{
LABEL_5:
statis = v1 + 1;
v5 = 4832LL * v1;
v6 = strtok(0LL, " \t\r\n");
v7 = v6;
if ( v6 && (!strcasecmp(v6, "on") || !strcasecmp(v7, "enable")) )
{
v8 = strlen(src);
strncpy(&mods[v5], src, v8);
v4 = strtok(0LL, " \t\r\n");
v9 = v4;
if ( v4 )
{
v10 = strlen(v4);
LODWORD(v4) = (unsigned int)strncpy(&mods[v5 + 32], v9, v10);
}
}
else
{
LODWORD(v4) = 0;
memset(&mods[v5], 0, 0x12E0uLL);
--statis;
}
}
else
{
v2 = mods;
v3 = &mods[4832 * (statis - 1) + 4832];
while ( 1 )
{
LODWORD(v4) = strcmp(src, v2);
if ( !(_DWORD)v4 )
break;
v2 += 4832;
if ( v2 == v3 )
goto LABEL_5;
}
}
return (int)v4;
}

canonical_decompiled_code:
int __fastcall func0(char *src)
{
int v1; // er13
const char *v2; // rbx
char *v3; // rbp
char *v4; // rax
__int64 v5; // r13
char *v6; // rax
const char *v7; // rbx
size_t v8; // rax
const char *v9; // rbx
size_t v10; // rax

v1 = statis;
if ( statis <= 0 )
{
LABEL_5:
statis = v1 + 1;
v5 = 4832LL * v1;
v6 = strtok(0LL, " \t\r\n");
v7 = v6;
if ( v6 && (!strcasecmp(v6, "on") || !strcasecmp(v7, "enable")) )
{
v8 = strlen(src);
strncpy(&mods[v5], src, v8);
v4 = strtok(0LL, " \t\r\n");
v9 = v4;
if ( v4 )
{
v10 = strlen(v4);
LODWORD(v4) = (unsigned int)strncpy(&mods[v5 + 32], v9, v10);
}
}
else
{
LODWORD(v4) = 0;
memset(&mods[v5], 0, 0x12E0uLL);
--statis;
}
}
else
{
v2 = mods;
v3 = &mods[4832 * (statis - 1) + 4832];
while ( 1 )
{
LODWORD(v4) = strcmp(src, v2);
if ( !(_DWORD)v4 )
break;
v2 += 4832;
if ( v2 == v3 )
goto LABEL_5;
}
}
return (int)v4;
}

original_code:
void parse_mod(const char *mod_name) {
    int i;
    for (i = 0; i < statis.total_mod_num; i++) {
        struct module *mod = &mods[i];
        if (!strcmp(mod_name, mod->name))
            return;
    }
    struct module *mod = &mods[statis.total_mod_num++];
    char *token = strtok(((void *)0), " \t\r\n");
    if (token && (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))) {
        strncpy(mod->name, mod_name, strlen(mod_name));
        token = strtok(((void *)0), " \t\r\n");
        if (token)
            strncpy(mod->parameter, token, strlen(token));
        return;
    } else {
        memset(mod, 0, sizeof(struct module));
        statis.total_mod_num--;
    }
}

canonical_original_code:
void parse_mod(char *mod_name) {
    int i;
    for (i = 0; i < statis.total_mod_num; i++) {
        struct module *mod = &mods[i];
        if (!strcmp(mod_name, mod->name))
            return;
    }
    struct module *mod = &mods[statis.total_mod_num++];
    char *token = strtok(((void *)0), " \t\r\n");
    if (token && (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))) {
        strncpy(mod->name, mod_name, strlen(mod_name));
        token = strtok(((void *)0), " \t\r\n");
        if (token)
            strncpy(mod->parameter, token, strlen(token));
        return;
    } else {
        memset(mod, 0, sizeof(struct module));
        statis.total_mod_num--;
    }
}

variable_types: i int

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:
token
char *


original_code:
void special_mod(const char *spec_mod) {
    char mod_name[32] = {0};
    int i, j;
    struct module *mod;
    sprintf(mod_name, "mod_%s", spec_mod + 5);
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        if (!strcmp(mod->name, mod_name)) {
            load_modules();
            char *token = strtok(((void *)0), " \t\r\n");
            struct mod_info *info = mod->info;
            for (j = 0; j < mod->n_col; j++) {
                char *p = info[j].hdr;
                while (*p == ' ') p++;
                if (strstr(token, p)) {
                    info[j].summary_bit = SPEC_BIT;
                    mod->spec = 1;
                }
            }
        }
    }
}

canonical_original_code:
void special_mod(char *spec_mod) {
    char mod_name[32] = {0};
    int i; int j;
    struct module *mod;
    sprintf(mod_name, "mod_%s", spec_mod + 5);
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        if (!strcmp(mod->name, mod_name)) {
            load_modules();
            char *token = strtok(((void *)0), " \t\r\n");
            struct mod_info *info = mod->info;
            for (j = 0; j < mod->n_col; j++) {
                char *p = info[j].hdr;
                while (*p == ' ') p++;
                if (strstr(token, p)) {
                    info[j].summary_bit = SPEC_BIT;
                    mod->spec = 1;
                }
            }
        }
    }
}

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

variable_types:
p
char *


decompiled_code:
char *__fastcall set_special_field(const char *a1)
{
char *result; // rax
__int64 v2; // r15
__int64 v3; // r12
const char *v4; // rsi
int v5; // ebp
__int64 v6; // rbx

result = (char *)statis;
if ( statis > 0 )
{
result = (char *)statis;
v2 = 4832LL * statis;
v3 = 0LL;
do
{
v6 = *(_QWORD *)&mods[v3 + 4800];
if ( *(int *)&mods[v3 + 4720] > 0 )
{
v5 = 0;
do
{
if ( *(_BYTE *)v6 == 32 )
{
v4 = (const char *)v6;
do
++v4;
while ( *v4 == 32 );
}
else
{
v4 = (const char *)v6;
}
result = strstr(a1, v4);
if ( result )
{
*(_DWORD *)(v6 + 128) = 3;
*(_DWORD *)&mods[v3 + 4716] = 1;
}
++v5;
v6 += 140LL;
}
while ( *(_DWORD *)&mods[v3 + 4720] > v5 );
}
v3 += 4832LL;
}
while ( v3 != v2 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1)
{
char *result; // rax
__int64 v2; // r15
__int64 v3; // r12
const char *v4; // rsi
int v5; // ebp
__int64 v6; // rbx

result = (char *)statis;
if ( statis > 0 )
{
result = (char *)statis;
v2 = 4832LL * statis;
v3 = 0LL;
do
{
v6 = *(_QWORD *)&mods[v3 + 4800];
if ( *(int *)&mods[v3 + 4720] > 0 )
{
v5 = 0;
do
{
if ( *(_BYTE *)v6 == 32 )
{
v4 = (const char *)v6;
do
++v4;
while ( *v4 == 32 );
}
else
{
v4 = (const char *)v6;
}
result = strstr(a1, v4);
if ( result )
{
*(_DWORD *)(v6 + 128) = 3;
*(_DWORD *)&mods[v3 + 4716] = 1;
}
++v5;
v6 += 140LL;
}
while ( *(_DWORD *)&mods[v3 + 4720] > v5 );
}
v3 += 4832LL;
}
while ( v3 != v2 );
}
return result;
}

original_code:
void set_special_field(const char *s) {
    int i, j;
    struct module *mod = ((void *)0);
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        struct mod_info *info = mod->info;
        for (j = 0; j < mod->n_col; j++) {
            char *p = info[j].hdr;
            while (*p == ' ') p++;
            if (strstr(s, p)) {
                info[j].summary_bit = SPEC_BIT;
                mod->spec = 1;
            }
        }
    }
}

canonical_original_code:
void set_special_field(char *s) {
    int i; int j;
    struct module *mod = ((void *)0);
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        struct mod_info *info = mod->info;
        for (j = 0; j < mod->n_col; j++) {
            char *p = info[j].hdr;
            while (*p == ' ') p++;
            if (strstr(s, p)) {
                info[j].summary_bit = SPEC_BIT;
                mod->spec = 1;
            }
        }
    }
}

variable_types:
s
char *

variable_types: j int


decompiled_code:
char *__fastcall set_special_item(char *src)
{
char *result; // rax
char *v2; // rbx
char *v3; // rbp

result = (char *)statis;
if ( statis > 0 )
{
v2 = (char *)(unsigned int)((_DWORD)mods + 576);
v3 = &mods[4832 * (statis - 1) + 5408];
do
{
result = strcpy(v2, src);
v2 += 4832;
}
while ( v2 != v3 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *src)
{
char *result; // rax
char *v2; // rbx
char *v3; // rbp

result = (char *)statis;
if ( statis > 0 )
{
v2 = (char *)(unsigned int)((_DWORD)mods + 576);
v3 = &mods[4832 * (statis - 1) + 5408];
do
{
result = strcpy(v2, src);
v2 += 4832;
}
while ( v2 != v3 );
}
return result;
}

original_code:
void set_special_item(const char *s) {
    int i;
    struct module *mod = ((void *)0);
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        strcpy(mod->print_item, s);
    }
}

canonical_original_code:
void set_special_item(char *s) {
    int i;
    struct module *mod = ((void *)0);
    for (i = 0; i < statis.total_mod_num; i++) {
        mod = &mods[i];
        strcpy(mod->print_item, s);
    }
}


decompiled_code:
char *__fastcall parse_string(char *dest)
{
char *result; // rax
const char *v2; // rbx
size_t v3; // rax

result = strtok(0LL, " \t\r\n");
if ( result )
{
v2 = result;
v3 = strlen(result);
result = strncpy(dest, v2, v3);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *dest)
{
char *result; // rax
const char *v2; // rbx
size_t v3; // rax

result = strtok(0LL, " \t\r\n");
if ( result )
{
v2 = result;
v3 = strlen(result);
result = strncpy(dest, v2, v3);
}
return result;
}

original_code:
void parse_string(char *var) {
    char *token = strtok(((void *)0), " \t\r\n");
    if (token)
        strncpy(var, token, strlen(token));
}

variable_types:
var
char *


decompiled_code:
char *__fastcall parse_add_string(char *src)
{
char *result; // rax
char *v2; // rbx
size_t v3; // rax
size_t v4; // rax

result = strtok(0LL, " \t\r\n");
if ( result )
{
v2 = result;
*(_WORD *)&result[strlen(result)] = 44;
v3 = strlen(src);
strncat(v2, src, v3);
v4 = strlen(v2);
result = strncpy(src, v2, v4);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(char *src)
{
char *result; // rax
char *v2; // rbx
size_t v3; // rax
size_t v4; // rax

result = strtok(0LL, " \t\r\n");
if ( result )
{
v2 = result;
*(_WORD *)&result[strlen(result)] = 44;
v3 = strlen(src);
strncat(v2, src, v3);
v4 = strlen(v2);
result = strncpy(src, v2, v4);
}
return result;
}

original_code:
void parse_add_string(char *var) {
    char *token = strtok(((void *)0), " \t\r\n");
    if (token) {
        strcat(token, ",");
        strncat(token, var, strlen(var));
    }
    if (token)
        strncpy(var, token, strlen(token));
}


decompiled_code:
char *set_debug_level()
{
char *result; // rax
bool v1; // zf

result = strtok(0LL, " \t\r\n");
if ( result )
{
if ( !strcmp(result, "INFO") )
{
*(_DWORD *)&conf = 0;
}
else if ( !strcmp(result, "WARN") )
{
*(_DWORD *)&conf = 2;
}
else if ( !strcmp(result, "DEBUG") )
{
*(_DWORD *)&conf = 1;
}
else if ( !strcmp(result, "ERROR") )
{
*(_DWORD *)&conf = 3;
}
else
{
v1 = strcmp(result, "FATAL") == 0;
result = (char *)((unsigned int)v1 + 3);
*(_DWORD *)&conf = v1 + 3;
}
}
return result;
}

canonical_decompiled_code:
char *func6()
{
char *result; // rax
bool v1; // zf

result = strtok(0LL, " \t\r\n");
if ( result )
{
if ( !strcmp(result, "INFO") )
{
*(_DWORD *)&conf = 0;
}
else if ( !strcmp(result, "WARN") )
{
*(_DWORD *)&conf = 2;
}
else if ( !strcmp(result, "DEBUG") )
{
*(_DWORD *)&conf = 1;
}
else if ( !strcmp(result, "ERROR") )
{
*(_DWORD *)&conf = 3;
}
else
{
v1 = strcmp(result, "FATAL") == 0;
result = (char *)((unsigned int)v1 + 3);
*(_DWORD *)&conf = v1 + 3;
}
}
return result;
}

original_code:
void set_debug_level(void) {
    char *token = strtok(((void *)0), " \t\r\n");
    if (token) {
        if (!strcmp(token, "INFO"))
            conf.debug_level = LOG_INFO;
        else if (!strcmp(token, "WARN"))
            conf.debug_level = LOG_WARN;
        else if (!strcmp(token, "DEBUG"))
            conf.debug_level = LOG_DEBUG;
        else if (!strcmp(token, "ERROR"))
            conf.debug_level = LOG_ERR;
        else if (!strcmp(token, "FATAL"))
            conf.debug_level = LOG_FATAL;
        else
            conf.debug_level = LOG_ERR;
    }
}

canonical_original_code:
void set_debug_level() {
    char *token = strtok(((void *)0), " \t\r\n");
    if (token) {
        if (!strcmp(token, "INFO"))
            conf.debug_level = LOG_INFO;
        else if (!strcmp(token, "WARN"))
            conf.debug_level = LOG_WARN;
        else if (!strcmp(token, "DEBUG"))
            conf.debug_level = LOG_DEBUG;
        else if (!strcmp(token, "ERROR"))
            conf.debug_level = LOG_ERR;
        else if (!strcmp(token, "FATAL"))
            conf.debug_level = LOG_FATAL;
        else
            conf.debug_level = LOG_ERR;
    }
}


original_code:
void get_threshold(void) {
    char *token = strtok(((void *)0), " \t\r\n");
    char tmp[4][32];
    if (conf.mod_num >= 64)
        do_debug(LOG_FATAL, "Too many mod threshold\n");
    sscanf(token, "%[^;];%[.N0-9];%[.N0-9];%[.N0-9];%[.N0-9];", conf.check_name[conf.mod_num], tmp[0], tmp[1], tmp[2], tmp[3]);
    if (!strcmp(tmp[0], "N"))
        conf.wmin[conf.mod_num] = 0;
    else
        conf.wmin[conf.mod_num] = atof(tmp[0]);
    if (!strcmp(tmp[1], "N"))
        conf.wmax[conf.mod_num] = 0;
    else
        conf.wmax[conf.mod_num] = atof(tmp[1]);
    if (!strcmp(tmp[2], "N"))
        conf.cmin[conf.mod_num] = 0;
    else
        conf.cmin[conf.mod_num] = atof(tmp[2]);
    if (!strcmp(tmp[3], "N"))
        conf.cmax[conf.mod_num] = 0;
    else
        conf.cmax[conf.mod_num] = atof(tmp[3]);
    conf.mod_num++;
}

canonical_original_code:
void get_threshold() {
    char *token = strtok(((void *)0), " \t\r\n");
    char tmp[4][32];
    if (conf.mod_num >= 64)
        do_debug(LOG_FATAL, "Too many mod threshold\n");
    sscanf(token, "%[^;];%[.N0-9];%[.N0-9];%[.N0-9];%[.N0-9];", conf.check_name[conf.mod_num], tmp[0], tmp[1], tmp[2], tmp[3]);
    if (!strcmp(tmp[0], "N"))
        conf.wmin[conf.mod_num] = 0;
    else
        conf.wmin[conf.mod_num] = atof(tmp[0]);
    if (!strcmp(tmp[1], "N"))
        conf.wmax[conf.mod_num] = 0;
    else
        conf.wmax[conf.mod_num] = atof(tmp[1]);
    if (!strcmp(tmp[2], "N"))
        conf.cmin[conf.mod_num] = 0;
    else
        conf.cmin[conf.mod_num] = atof(tmp[2]);
    if (!strcmp(tmp[3], "N"))
        conf.cmax[conf.mod_num] = 0;
    else
        conf.cmax[conf.mod_num] = atof(tmp[3]);
    conf.mod_num++;
}

variable_types:
tmp
char [4][32]


decompiled_code:
struct ifaddrs *get_host()
{
struct ifaddrs *result; // rax
struct sockaddr *v1; // rsi
struct ifaddrs *ifap; // [rsp+8h] [rbp-10h] BYREF

if ( gethostname((char *)(unsigned int)((_DWORD)&conf + 6252), 0x20uLL) )
do_debug(4LL, "get host name error!\n");
if ( getifaddrs(&ifap) == -1 )
do_debug(4LL, "get interface address struct error!\n");
for ( result = ifap; result; ifap = result )
{
if ( !strcmp(result->ifa_name, "eth0") )
{
v1 = result->ifa_addr;
if ( v1->sa_family == 2 && !inet_ntop(2, &v1->sa_data[2], (char *)(unsigned int)((_DWORD)&conf + 6284), 0x20u) )
do_debug(4LL, "get host ip error!\n");
}
result = ifap->ifa_next;
}
return result;
}

canonical_decompiled_code:
struct ifaddrs *func9()
{
struct ifaddrs *result; // rax
struct sockaddr *v1; // rsi
struct ifaddrs *ifap; // [rsp+8h] [rbp-10h] BYREF

if ( gethostname((char *)(unsigned int)((_DWORD)&conf + 6252), 0x20uLL) )
do_debug(4LL, "get host name error!\n");
if ( getifaddrs(&ifap) == -1 )
do_debug(4LL, "get interface address struct error!\n");
for ( result = ifap; result; ifap = result )
{
if ( !strcmp(result->ifa_name, "eth0") )
{
v1 = result->ifa_addr;
if ( v1->sa_family == 2 && !inet_ntop(2, &v1->sa_data[2], (char *)(unsigned int)((_DWORD)&conf + 6284), 0x20u) )
do_debug(4LL, "get host ip error!\n");
}
result = ifap->ifa_next;
}
return result;
}

original_code:
void get_host(void) {
    struct ifaddrs *if_addr_struct;
    void *tmp = ((void *)0);
    if (gethostname(conf.host_name, sizeof(conf.host_name)) != 0)
        do_debug(LOG_FATAL, "get host name error!\n");
    if (getifaddrs(&if_addr_struct) == -1)
        do_debug(LOG_FATAL, "get interface address struct error!\n");
    while (if_addr_struct != ((void *)0)) {
        if (!strcmp(if_addr_struct->ifa_name, "eth0") && (if_addr_struct->ifa_addr->sa_family == 2)) {
            tmp = &((struct sockaddr_in *)if_addr_struct->ifa_addr)->sin_addr;
            if (!inet_ntop(if_addr_struct->ifa_addr->sa_family, tmp, conf.host_ip, sizeof(conf.host_ip)))
                do_debug(LOG_FATAL, "get host ip error!\n");
        }
        if_addr_struct = if_addr_struct->ifa_next;
    }
}

canonical_original_code:
void get_host() {
    struct ifaddrs *if_addr_struct;
    void *tmp = ((void *)0);
    if (gethostname(conf.host_name, sizeof(conf.host_name)) != 0)
        do_debug(LOG_FATAL, "get host name error!\n");
    if (getifaddrs(&if_addr_struct) == -1)
        do_debug(LOG_FATAL, "get interface address struct error!\n");
    while (if_addr_struct != ((void *)0)) {
        if (!strcmp(if_addr_struct->ifa_name, "eth0") && (if_addr_struct->ifa_addr->sa_family == 2)) {
            tmp = &((struct sockaddr_in *)if_addr_struct->ifa_addr)->sin_addr;
            if (!inet_ntop(if_addr_struct->ifa_addr->sa_family, tmp, conf.host_ip, sizeof(conf.host_ip)))
                do_debug(LOG_FATAL, "get host ip error!\n");
        }
        if_addr_struct = if_addr_struct->ifa_next;
    }
}

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types:
tmp
void *

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }

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


decompiled_code:
__int64 __fastcall parse_line(char *haystack)
{
char *v1; // rbx
__int64 result; // rax

v1 = strtok(haystack, " \t\r\n");
result = 1LL;
if ( v1 )
{
if ( strstr(haystack, "mod_") )
{
parse_mod(v1);
result = 1LL;
}
else if ( !strcmp(v1, "module_path") )
{
parse_string((char *)(unsigned int)((_DWORD)&conf + 132));
result = 1LL;
}
else if ( strstr(haystack, "spec_") )
{
special_mod((__int64)v1);
result = 1LL;
}
else if ( !strcmp(v1, "output_interface") )
{
parse_string((char *)(unsigned int)((_DWORD)&conf + 260));
result = 1LL;
}
else if ( !strcmp(v1, "output_file_path") )
{
parse_string((char *)(unsigned int)((_DWORD)&conf + 388));
result = 1LL;
}
else if ( !strcmp(v1, "output_db_addr") )
{
parse_string((char *)(unsigned int)((_DWORD)&conf + 516));
result = 1LL;
}
else if ( !strcmp(v1, "output_db_pawd") )
{
parse_string((char *)(unsigned int)((_DWORD)&conf + 1028));
result = 1LL;
}
else if ( !strcmp(v1, "output_db_mod") )
{
parse_add_string((char *)(unsigned int)((_DWORD)&conf + 1060));
result = 1LL;
}
else if ( !strcmp(v1, "output_nagios_mod") )
{
parse_add_string((char *)(unsigned int)((_DWORD)&conf + 1572));
result = 1LL;
}
else if ( !strcmp(v1, "output_stdio_mod") )
{
parse_add_string((char *)(unsigned int)((_DWORD)&conf + 2084));
result = 1LL;
}
else if ( !strcmp(v1, "debug_leve") )
{
set_debug_level();
result = 1LL;
}
else if ( !strcmp(v1, "include") )
{
get_include_conf();
result = 1LL;
}
else if ( !strcmp(v1, "server_addr") )
{
parse_string((char *)(unsigned int)((_DWORD)&conf + 3108));
result = 1LL;
}
else if ( !strcmp(v1, "server_port") )
{
parse_int(*((_DWORD **)&conf + 453));
result = 1LL;
}
else if ( !strcmp(v1, "cycle_time") )
{
parse_int(*((_DWORD **)&conf + 454));
result = 1LL;
}
else if ( !strcmp(v1, "send_nsca_cmd") )
{
parse_string((char *)(unsigned int)((_DWORD)&conf + 3640));
result = 1LL;
}
else if ( !strcmp(v1, "send_nsca_conf") )
{
parse_string((char *)(unsigned int)((_DWORD)&conf + 4152));
result = 1LL;
}
else if ( !strcmp(v1, "threshold") )
{
get_threshold();
result = 1LL;
}
else
{
result = 0LL;
if ( !((unsigned __int8)*(&conf + 6284) | (unsigned __int8)*(&conf + 6252)) )
{
get_host();
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *haystack)
{
char *v1; // rbx
__int64 result; // rax

v1 = strtok(haystack, " \t\r\n");
result = 1LL;
if ( v1 )
{
if ( strstr(haystack, "mod_") )
{
func0(v1);
result = 1LL;
}
else if ( !strcmp(v1, "module_path") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 132));
result = 1LL;
}
else if ( strstr(haystack, "spec_") )
{
func1((__int64)v1);
result = 1LL;
}
else if ( !strcmp(v1, "output_interface") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 260));
result = 1LL;
}
else if ( !strcmp(v1, "output_file_path") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 388));
result = 1LL;
}
else if ( !strcmp(v1, "output_db_addr") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 516));
result = 1LL;
}
else if ( !strcmp(v1, "output_db_pawd") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 1028));
result = 1LL;
}
else if ( !strcmp(v1, "output_db_mod") )
{
func5((char *)(unsigned int)((_DWORD)&conf + 1060));
result = 1LL;
}
else if ( !strcmp(v1, "output_nagios_mod") )
{
func5((char *)(unsigned int)((_DWORD)&conf + 1572));
result = 1LL;
}
else if ( !strcmp(v1, "output_stdio_mod") )
{
func5((char *)(unsigned int)((_DWORD)&conf + 2084));
result = 1LL;
}
else if ( !strcmp(v1, "debug_leve") )
{
func6();
result = 1LL;
}
else if ( !strcmp(v1, "include") )
{
func10();
result = 1LL;
}
else if ( !strcmp(v1, "server_addr") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 3108));
result = 1LL;
}
else if ( !strcmp(v1, "server_port") )
{
func7(*((_DWORD **)&conf + 453));
result = 1LL;
}
else if ( !strcmp(v1, "cycle_time") )
{
func7(*((_DWORD **)&conf + 454));
result = 1LL;
}
else if ( !strcmp(v1, "send_nsca_cmd") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 3640));
result = 1LL;
}
else if ( !strcmp(v1, "send_nsca_conf") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 4152));
result = 1LL;
}
else if ( !strcmp(v1, "threshold") )
{
func8();
result = 1LL;
}
else
{
result = 0LL;
if ( !((unsigned __int8)*(&conf + 6284) | (unsigned __int8)*(&conf + 6252)) )
{
func9();
result = 1LL;
}
}
}
return result;
}

original_code:
static int parse_line(char *buff) {
    char *token;
    if (!(token = strtok(buff, " \t\r\n")))
        (void) 0;
    else if (strstr(buff, "mod_"))
        parse_mod(token);
    else if (!strcmp(token, "module_path"))
        parse_string(conf.module_path);
    else if (strstr(buff, "spec_"))
        special_mod(token);
    else if (!strcmp(token, "output_interface"))
        parse_string(conf.output_interface);
    else if (!strcmp(token, "output_file_path"))
        parse_string(conf.output_file_path);
    else if (!strcmp(token, "output_db_addr"))
        parse_string(conf.output_db_addr);
    else if (!strcmp(token, "output_db_pawd"))
        parse_string(conf.output_db_pawd);
    else if (!strcmp(token, "output_db_mod"))
        parse_add_string(conf.output_db_mod);
    else if (!strcmp(token, "output_nagios_mod"))
        parse_add_string(conf.output_nagios_mod);
    else if (!strcmp(token, "output_stdio_mod"))
        parse_add_string(conf.output_stdio_mod);
    else if (!strcmp(token, "debug_leve"))
        set_debug_level();
    else if (!strcmp(token, "include"))
        get_include_conf();
    else if (!strcmp(token, "server_addr"))
        parse_string(conf.server_addr);
    else if (!strcmp(token, "server_port"))
        parse_int(conf.server_port);
    else if (!strcmp(token, "cycle_time"))
        parse_int(conf.cycle_time);
    else if (!strcmp(token, "send_nsca_cmd"))
        parse_string(conf.send_nsca_cmd);
    else if (!strcmp(token, "send_nsca_conf"))
        parse_string(conf.send_nsca_conf);
    else if (!strcmp(token, "threshold"))
        get_threshold();
    else if (!strlen(conf.host_name) && !strlen(conf.host_ip))
        get_host();
    else
        return 0;
    return 1;
}

variable_types:
buff
char *


decompiled_code:
__int64 __fastcall get_strtok_num(char *s, char *delim)
{
unsigned int v2; // ebx
size_t v4; // rax
__int64 v5[2]; // [rsp+0h] [rbp-1018h] BYREF
char v6[4080]; // [rsp+10h] [rbp-1008h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
if ( !s )
return 0;
v2 = 0;
if ( *s )
{
v4 = strlen(s);
memcpy(v5, s, v4);
if ( strtok((char *)v5, delim) )
{
do
++v2;
while ( strtok(0LL, delim) );
}
else
{
v2 = 0;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, char *delim)
{
unsigned int v2; // ebx
size_t v4; // rax
__int64 v5[2]; // [rsp+0h] [rbp-1018h] BYREF
char v6[4080]; // [rsp+10h] [rbp-1008h] BYREF

v5[0] = 0LL;
v5[1] = 0LL;
memset(v6, 0, sizeof(v6));
if ( !s )
return 0;
v2 = 0;
if ( *s )
{
v4 = strlen(s);
memcpy(v5, s, v4);
if ( strtok((char *)v5, delim) )
{
do
++v2;
while ( strtok(0LL, delim) );
}
else
{
v2 = 0;
}
}
return v2;
}

original_code:
int get_strtok_num(const char *str, const char *split) {
    int num = 0;
    char *token, n_str[4096] = {0};
    if (!str || !strlen(str))
        return 0;
    memcpy(n_str, str, strlen(str));
    token = strtok(n_str, split);
    while (token) {
        num++;
        token = strtok(((void *)0), split);
    }
    return num;
}

canonical_original_code:
int get_strtok_num(char *str, char *split) {
    int num = 0;
    char *token; char n_str[4096] = {0};
    if (!str || !strlen(str))
        return 0;
    memcpy(n_str, str, strlen(str));
    token = strtok(n_str, split);
    while (token) {
        num++;
        token = strtok(((void *)0), split);
    }
    return num;
}

variable_types:
str
char *

variable_types:
split
char *

variable_types: num int


decompiled_code:
__int64 __fastcall is_digit(char *a1)
{
char v2; // bl

while ( 1 )
{
v2 = *a1;
if ( !*a1 )
break;
++a1;
if ( ((*_ctype_b_loc())[v2] & 0x800) == 0 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char v2; // bl

while ( 1 )
{
v2 = *a1;
if ( !*a1 )
break;
++a1;
if ( ((*_ctype_b_loc())[v2] & 0x800) == 0 )
return 0LL;
}
return 1LL;
}

original_code:
int is_digit(char *str) {
    while (*str) {
        if (!((*__ctype_b_loc ())[(int) ((*str++))] & (unsigned short int) _ISdigit))
            return 0;
    }
    return 1;
}

canonical_original_code:
int is_digit(char *str) {
    while (*str) {
        if (!((*__ctype_b_loc ())[(int) ((*str++))] & (unsigned short) _ISdigit))
            return 0;
    }
    return 1;
}


decompiled_code:
__int64 __fastcall convert_record_to_array(unsigned __int64 *a1, int a2, const char *a3)
{
unsigned int v5; // er12
size_t v7; // rax
char *v8; // rbx
int v9; // eax
__int64 v10[2]; // [rsp+0h] [rbp-1028h] BYREF
char v11[4080]; // [rsp+10h] [rbp-1018h] BYREF

v10[0] = 0LL;
v10[1] = 0LL;
memset(v11, 0, sizeof(v11));
if ( !a3 )
return 0;
v5 = 0;
if ( *a3 )
{
v7 = strlen(a3);
memcpy(v10, a3, v7);
v8 = strtok((char *)v10, ",");
if ( v8 )
{
do
{
v9 = is_digit(v8);
if ( a2 <= (int)v5 )
break;
if ( !v9 )
break;
++v5;
*a1 = strtoull(v8, 0LL, 10);
v8 = strtok(0LL, ",");
++a1;
}
while ( v8 );
}
else
{
v5 = 0;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 *a1, int a2, const char *a3)
{
unsigned int v5; // er12
size_t v7; // rax
char *v8; // rbx
int v9; // eax
__int64 v10[2]; // [rsp+0h] [rbp-1028h] BYREF
char v11[4080]; // [rsp+10h] [rbp-1018h] BYREF

v10[0] = 0LL;
v10[1] = 0LL;
memset(v11, 0, sizeof(v11));
if ( !a3 )
return 0;
v5 = 0;
if ( *a3 )
{
v7 = strlen(a3);
memcpy(v10, a3, v7);
v8 = strtok((char *)v10, ",");
if ( v8 )
{
do
{
v9 = func2(v8);
if ( a2 <= (int)v5 )
break;
if ( !v9 )
break;
++v5;
*a1 = strtoull(v8, 0LL, 10);
v8 = strtok(0LL, ",");
++a1;
}
while ( v8 );
}
else
{
v5 = 0;
}
}
return v5;
}

original_code:
int convert_record_to_array(unsigned long long *array, int l_array, const char *record) {
    int i = 0;
    char *token;
    char n_str[4096] = {0};
    if (!record || !strlen(record))
        return 0;
    memcpy(n_str, record, strlen(record));
    token = strtok(n_str, ",");
    while (token) {
        if (is_digit(token) && i < l_array)
            array[i++] = strtoull(token, ((void *)0), 10);
        else
            return i;
        token = strtok(((void *)0), ",");
    }
    return i;
}

canonical_original_code:
int convert_record_to_array(unsigned long long *array, int l_array, char *record) {
    int i = 0;
    char *token;
    char n_str[4096] = {0};
    if (!record || !strlen(record))
        return 0;
    memcpy(n_str, record, strlen(record));
    token = strtok(n_str, ",");
    while (token) {
        if (is_digit(token) && i < l_array)
            array[i++] = strtoull(token, ((void *)0), 10);
        else
            return i;
        token = strtok(((void *)0), ",");
    }
    return i;
}

variable_types:
array
unsigned long long *

variable_types:
record
char *


decompiled_code:
__int64 __fastcall strtok_next_item(void *dest, char *s, int *a3)
{
int v3; // ebx
__int64 result; // rax
size_t v6; // rcx
size_t v7; // rdx
const char *v8; // r14
char *v9; // r13
char *v10; // rsi

if ( !s )
return 0LL;
v3 = (int)s;
result = 0LL;
if ( *s )
{
v6 = strlen(s);
v7 = *a3;
result = 0LL;
if ( v6 > v7 )
{
v8 = &s[v7];
v9 = strchr(&s[v7], 59);
if ( v9 )
{
v10 = strchr(v8, 61);
result = 0LL;
if ( v10 )
{
memcpy(dest, v10 + 1, v9 - v10 - 1);
*a3 = (_DWORD)v9 - v3 + 2;
result = 1LL;
}
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *dest, char *s, int *a3)
{
int v3; // ebx
__int64 result; // rax
size_t v6; // rcx
size_t v7; // rdx
const char *v8; // r14
char *v9; // r13
char *v10; // rsi

if ( !s )
return 0LL;
v3 = (int)s;
result = 0LL;
if ( *s )
{
v6 = strlen(s);
v7 = *a3;
result = 0LL;
if ( v6 > v7 )
{
v8 = &s[v7];
v9 = strchr(&s[v7], 59);
if ( v9 )
{
v10 = strchr(v8, 61);
result = 0LL;
if ( v10 )
{
memcpy(dest, v10 + 1, v9 - v10 - 1);
*a3 = (_DWORD)v9 - v3 + 2;
result = 1LL;
}
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
int strtok_next_item(char item[], char *record, int *start) {
    char *s_token, *e_token, *n_record;
    if (!record || !strlen(record) || strlen(record) <= *start)
        return 0;
    n_record = record + *start;
    if (!(e_token = strstr(n_record, ";")))
        return 0;
    if (!(s_token = strstr(n_record, "=")))
        return 0;
    memcpy(item, s_token + sizeof("=") - 1, e_token - s_token - 1);
    *start = e_token - record + sizeof(";");
    return 1;
}

canonical_original_code:
int strtok_next_item(char item[], char *record, int *start) {
    char *s_token; char *e_token; char *n_record;
    if (!record || !strlen(record) || strlen(record) <= *start)
        return 0;
    n_record = record + *start;
    if (!(e_token = strstr(n_record, ";")))
        return 0;
    if (!(s_token = strstr(n_record, "=")))
        return 0;
    memcpy(item, s_token + sizeof("=") - 1, e_token - s_token - 1);
    *start = e_token - record + sizeof(";");
    return 1;
}

variable_types:
item
char []

variable_types:
start
int *


decompiled_code:
__int64 __fastcall merge_one_string(unsigned __int64 *a1, int a2, const char *a3, __int64 a4, int a5)
{
unsigned __int64 *v5; // r12
__int64 v7; // rbx
__int64 result; // rax
_DWORD *v9; // rsi
unsigned __int64 *v10; // rcx
unsigned __int64 *v11; // rdi
unsigned __int64 v12[35]; // [rsp+0h] [rbp-118h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 *a1, int a2, const char *a3, __int64 a4, int a5)
{
unsigned __int64 *v5; // r12
__int64 v7; // rbx
__int64 result; // rax
_DWORD *v9; // rsi
unsigned __int64 *v10; // rcx
unsigned __int64 *v11; // rdi
unsigned __int64 v12[35]; // [rsp+0h] [rbp-118h] BYREF

v5 = a1;
memset(v12, 0, 0x100uLL);
v7 = *(_QWORD *)(a4 + 4800);
result = func3(v12, a2, a3);
if ( (_DWORD)result )
{
if ( (int)result <= 0 )
{
result = 1LL;
}
else
{
v9 = (_DWORD *)(v7 + 132);
v10 = a1;
v11 = v12;
do
{
if ( *v9 == 1 )
{
*v10 += *v11;
}
else if ( *v9 == 2 )
{
*v10 = (*v11 + *v10 * (a5 - 1)) / a5;
}
v9 += 35;
++v10;
++v11;
}
while ( v10 != &v5[(unsigned int)(result - 1) + 1] );
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


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: pos int

variable_types:
item
char [128]


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 *


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

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; // rdi
double v6; // xmm0_8
__int64 v7; // rdx
__int64 v8; // rax
double v9; // xmm0_8
__int64 result; // rax
double v11; // xmm0_8
__int64 v12; // rdx
unsigned __int64 v13; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 i; // rax
__int64 v5; // rdi
double v6; // xmm0_8
__int64 v7; // rdx
__int64 v8; // rax
double v9; // xmm0_8
__int64 result; // rax
double v11; // xmm0_8
__int64 v12; // rdx
unsigned __int64 v13; // rdx

for ( i = 0LL; i != 24; i += 8LL )
{
v7 = *(_QWORD *)(a4 + i);
if ( v7 < 0 )
{
v5 = *(_QWORD *)(a4 + i) & 1LL | ((unsigned __int64)v7 >> 1);
v6 = (double)(int)v5 + (double)(int)v5;
}
else
{
v6 = (double)(int)v7;
}
*(double *)(a2 + i) = v6 / 100.0;
}
v8 = *(_QWORD *)(a4 + 24);
if ( v8 < 0 )
{
v12 = *(_QWORD *)(a4 + 24) & 1LL | ((unsigned __int64)v8 >> 1);
v9 = (double)(int)v12 + (double)(int)v12;
}
else
{
v9 = (double)(int)v8;
}
*(double *)(a2 + 24) = v9;
result = *(_QWORD *)(a4 + 32);
if ( result < 0 )
{
v13 = (unsigned __int64)result >> 1;
result = *(_QWORD *)(a4 + 32) & 1LL;
v11 = (double)(int)(result | v13) + (double)(int)(result | v13);
}
else
{
v11 = (double)(int)result;
}
*(double *)(a2 + 32) = v11;
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


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

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; // rbx

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

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

if ( a2 )
{
v2 = a1;
do
printf("%02X\n", *v2++);
while ( v2 != &a1[a2] );
}
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:
__int64 __fastcall fcgi_header_set_request_id(__int64 a1, __int16 a2)
{
__int64 result; // rax

*(_BYTE *)(a1 + 3) = a2;
result = HIBYTE(a2);
*(_BYTE *)(a1 + 2) = HIBYTE(a2);
return result;
}

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

*(_BYTE *)(a1 + 3) = a2;
result = HIBYTE(a2);
*(_BYTE *)(a1 + 2) = HIBYTE(a2);
return result;
}

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:
__int64 __fastcall fcgi_header_set_content_len(__int64 a1, __int16 a2)
{
__int64 result; // rax

*(_BYTE *)(a1 + 5) = a2;
result = HIBYTE(a2);
*(_BYTE *)(a1 + 4) = HIBYTE(a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int16 a2)
{
__int64 result; // rax

*(_BYTE *)(a1 + 5) = a2;
result = HIBYTE(a2);
*(_BYTE *)(a1 + 4) = HIBYTE(a2);
return result;
}

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; // rbx

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

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *v0; // rbx

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

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