decompiled_code:
void __fastcall do_thread(void *a1)
{
execute_command(*(_DWORD **)a1, 0);
}

canonical_decompiled_code:
void __fastcall func13(void *a1)
{
func12(*(_DWORD **)a1, 0);
}

original_code:
void
do_thread (void* c)
{
 struct arg_struct * args = (struct arg_struct *)c;
 execute_command(args->cmd,0);
}

canonical_original_code:
void do_thread(void *c)
{
 struct arg_struct *args = (struct arg_struct *)c;
 execute_command(args->cmd,0);
}

variable_types:
c
void *

variable_types: struct arg_struct { struct command { enum command_type { AND_COMMAND=0, SEQUENCE_COMMAND=1, OR_COMMAND=2, PIPE_COMMAND=3, SIMPLE_COMMAND=4, START_SUBSHELL_COMMAND=5, END_SUBSHELL_COMMAND=6, SUBSHELL_COMMAND=7, NEWLINE_COMMAND=8, REDIRECT_FROM_COMMAND=9, REDIRECT_TO_COMMAND=10 } type; int status; char *input; char *output; union { struct command *command[2]; char **word; struct command *subshell_command; } u; } *cmd; int thread_index; } *

user_defined_types: struct arg_struct { struct command *cmd; int thread_index; }


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

do_command(*(_DWORD **)(a1 + 24));
result = *(unsigned int *)(*(_QWORD *)(a1 + 24) + 4LL);
if ( !(_DWORD)result )
{
do_command(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
}
*(_DWORD *)(a1 + 4) = result;
return result;
}

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

func11(*(_DWORD **)(a1 + 24));
result = *(unsigned int *)(*(_QWORD *)(a1 + 24) + 4LL);
if ( !(_DWORD)result )
{
func11(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
}
*(_DWORD *)(a1 + 4) = result;
return result;
}

original_code:
void
execute_and_operator (command_t c)
{
 do_command(c->u.command[0]);
 if(c->u.command[0]->status == 0)
 {
  do_command(c->u.command[1]);
  c->status = c->u.command[1]->status;
 }
 else
 {
  c->status = c->u.command[0]->status;
 }
}

canonical_original_code:
void execute_and_operator(struct command *c)
{
 do_command(c->u.command[0]);
 if(c->u.command[0]->status == 0)
 {
  do_command(c->u.command[1]);
  c->status = c->u.command[1]->status;
 }
 else
 {
  c->status = c->u.command[0]->status;
 }
}

variable_types: struct command { enum command_type { AND_COMMAND=0, SEQUENCE_COMMAND=1, OR_COMMAND=2, PIPE_COMMAND=3, SIMPLE_COMMAND=4, START_SUBSHELL_COMMAND=5, END_SUBSHELL_COMMAND=6, SUBSHELL_COMMAND=7, NEWLINE_COMMAND=8, REDIRECT_FROM_COMMAND=9, REDIRECT_TO_COMMAND=10 } type; int status; char *input; char *output; union { struct command *command[2]; char **word; struct command *subshell_command; } u; } *

return_type: void

user_defined_types: struct command { enum command_type type; int status; char *input; char *output; union { struct command *command[2]; char **word; struct command *subshell_command; } u; }


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

do_command(*(_DWORD **)(a1 + 24));
result = *(unsigned int *)(*(_QWORD *)(a1 + 24) + 4LL);
if ( (_DWORD)result )
{
do_command(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
*(_DWORD *)(a1 + 4) = result;
}
else
{
*(_DWORD *)(a1 + 4) = 0;
}
return result;
}

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

func11(*(_DWORD **)(a1 + 24));
result = *(unsigned int *)(*(_QWORD *)(a1 + 24) + 4LL);
if ( (_DWORD)result )
{
func11(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
*(_DWORD *)(a1 + 4) = result;
}
else
{
*(_DWORD *)(a1 + 4) = 0;
}
return result;
}

original_code:
void
execute_or_operator (command_t c)
{
 do_command(c->u.command[0]);
 if(!(c->u.command[0]->status))
 {
  c->status = c->u.command[0]->status;
 }
 else
 {
  do_command(c->u.command[1]);
  c->status = c->u.command[1]->status;
 }
}

canonical_original_code:
void execute_or_operator(struct command *c)
{
 do_command(c->u.command[0]);
 if(!(c->u.command[0]->status))
 {
  c->status = c->u.command[0]->status;
 }
 else
 {
  do_command(c->u.command[1]);
  c->status = c->u.command[1]->status;
 }
}

user_defined_types: enum command_type { AND_COMMAND=0, SEQUENCE_COMMAND=1, OR_COMMAND=2, PIPE_COMMAND=3, SIMPLE_COMMAND=4, START_SUBSHELL_COMMAND=5, END_SUBSHELL_COMMAND=6, SUBSHELL_COMMAND=7, NEWLINE_COMMAND=8, REDIRECT_FROM_COMMAND=9, REDIRECT_TO_COMMAND=10 }


decompiled_code:
__int64 __fastcall execute_pipe_operator(__int64 a1)
{
__pid_t v1; // eax
__pid_t v2; // ebp
__pid_t v3; // eax
__pid_t v4; // er12
__int64 result; // rax
int v6; // [rsp+0h] [rbp-28h] BYREF
int stat_loc; // [rsp+4h] [rbp-24h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

pipe(pipedes);
v1 = fork();
if ( v1 == -1 )
goto LABEL_6;
v2 = v1;
if ( !v1 )
{
close(1);
dup2(pipedes[1], 1);
close(pipedes[0]);
close(pipedes[1]);
do_command(*(_DWORD **)(a1 + 24));
exit(*(_DWORD *)(*(_QWORD *)(a1 + 24) + 4LL));
}
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
LABEL_6:
error(1, 0, "You forked up the pipeline man");
LABEL_7:
close(0);
dup2(pipedes[0], 0);
close(pipedes[0]);
close(pipedes[1]);
do_command(*(_DWORD **)(a1 + 32));
exit(*(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL));
}
if ( !v3 )
goto LABEL_7;
close(pipedes[0]);
close(pipedes[1]);
waitpid(v2, &v6, 0);
waitpid(v4, &stat_loc, 0);
result = (unsigned int)stat_loc;
*(_DWORD *)(a1 + 4) = stat_loc;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
__pid_t v1; // eax
__pid_t v2; // ebp
__pid_t v3; // eax
__pid_t v4; // er12
__int64 result; // rax
int v6; // [rsp+0h] [rbp-28h] BYREF
int stat_loc; // [rsp+4h] [rbp-24h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

pipe(pipedes);
v1 = fork();
if ( v1 == -1 )
goto LABEL_6;
v2 = v1;
if ( !v1 )
{
close(1);
dup2(pipedes[1], 1);
close(pipedes[0]);
close(pipedes[1]);
func11(*(_DWORD **)(a1 + 24));
exit(*(_DWORD *)(*(_QWORD *)(a1 + 24) + 4LL));
}
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
LABEL_6:
error(1, 0, "You forked up the pipeline man");
LABEL_7:
close(0);
dup2(pipedes[0], 0);
close(pipedes[0]);
close(pipedes[1]);
func11(*(_DWORD **)(a1 + 32));
exit(*(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL));
}
if ( !v3 )
goto LABEL_7;
close(pipedes[0]);
close(pipedes[1]);
waitpid(v2, &v6, 0);
waitpid(v4, &stat_loc, 0);
result = (unsigned int)stat_loc;
*(_DWORD *)(a1 + 4) = stat_loc;
return result;
}

original_code:
void
execute_pipe_operator (command_t c)
{
 int fd[2];
 pipe(fd);
 pid_t l_pid;
 l_pid = fork();
 if(l_pid == -1)
 {
  error(1,0,"You forked up the pipeline man");
 }
 else if(l_pid == 0)
 {
  close(1);
  dup2(fd[1],1);
  close(fd[0]);
  close(fd[1]);
  do_command(c->u.command[0]);
  exit(c->u.command[0]->status);
 }
 pid_t r_pid;
 r_pid = fork();
 if(r_pid == -1)
 {
  error(1,0,"You forked up the pipeline man");
 }
 else if(r_pid == 0)
 {
  close(0);
  dup2(fd[0],0);
  close(fd[0]);
  close(fd[1]);
  do_command(c->u.command[1]);
  exit(c->u.command[1]->status);
 }
 close(fd[0]);
 close(fd[1]);
 int status_left_child,status_right_child;
 waitpid(l_pid,&status_left_child,0);
 waitpid(r_pid,&status_right_child,0);
 c->status = status_right_child;
}

canonical_original_code:
void execute_pipe_operator(struct command *c)
{
 int fd[2];
 pipe(fd);
 int l_pid;
 l_pid = fork();
 if(l_pid == -1)
 {
  error(1,0,"You forked up the pipeline man");
 }
 else if(l_pid == 0)
 {
  close(1);
  dup2(fd[1],1);
  close(fd[0]);
  close(fd[1]);
  do_command(c->u.command[0]);
  exit(c->u.command[0]->status);
 }
 int r_pid;
 r_pid = fork();
 if(r_pid == -1)
 {
  error(1,0,"You forked up the pipeline man");
 }
 else if(r_pid == 0)
 {
  close(0);
  dup2(fd[0],0);
  close(fd[0]);
  close(fd[1]);
  do_command(c->u.command[1]);
  exit(c->u.command[1]->status);
 }
 close(fd[0]);
 close(fd[1]);
 int status_left_child; int status_right_child;
 waitpid(l_pid,&status_left_child,0);
 waitpid(r_pid,&status_right_child,0);
 c->status = status_right_child;
}

variable_types:
fd
int [2]


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

do_command(*(_DWORD **)(a1 + 24));
do_command(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
*(_DWORD *)(a1 + 4) = result;
return result;
}

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

func11(*(_DWORD **)(a1 + 24));
func11(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
*(_DWORD *)(a1 + 4) = result;
return result;
}

original_code:
void
execute_sequence_operator (command_t c)
{
 do_command(c->u.command[0]);
 do_command(c->u.command[1]);
 c->status = c->u.command[1]->status;
}

canonical_original_code:
void execute_sequence_operator(struct command *c)
{
 do_command(c->u.command[0]);
 do_command(c->u.command[1]);
 c->status = c->u.command[1]->status;
}


cleanup

decompiled_code:
void cleanup()
{
;
}

canonical_decompiled_code:
void func18()
{
;
}

original_code:
void
cleanup()
{
}

canonical_original_code:
void cleanup()
{
}


decompiled_code:
__int64 __fastcall memory_exhausted(int errnum)
{
error(1, errnum, "memory exhausted");
return check_nonnull();
}

canonical_decompiled_code:
__int64 __fastcall func0(int errnum)
{
error(1, errnum, "memory exhausted");
return func1();
}

original_code:
static void
memory_exhausted (int errnum)
{
  error (1, errnum, "memory exhausted");
}

canonical_original_code:
static void memory_exhausted(int errnum)
{
  error (1, errnum, "memory exhausted");
}

variable_types: errnum int


decompiled_code:
__int64 __fastcall check_nonnull(__int64 a1)
{
int *v2; // rax

if ( a1 )
return a1;
v2 = _errno_location();
memory_exhausted(*v2);
return checked_malloc();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int *v2; // rax

if ( a1 )
return a1;
v2 = _errno_location();
func0(*v2);
return func2();
}

original_code:
static void *
check_nonnull (void *p)
{
  if (! p)
    memory_exhausted ((*__errno_location ()));
  return p;
}

canonical_original_code:
static void *check_nonnull(void *p)
{
  if (! p)
    memory_exhausted ((*__errno_location ()));
  return p;
}

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 __fastcall checked_malloc(size_t a1)
{
void *v1; // rax

if ( !a1 )
a1 = 1LL;
v1 = malloc(a1);
return check_nonnull((__int64)v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(size_t a1)
{
void *v1; // rax

if ( !a1 )
a1 = 1LL;
v1 = malloc(a1);
return func1((__int64)v1);
}

original_code:
void *
checked_malloc (size_t size)
{
  return check_nonnull (malloc (size ? size : 1));
}

canonical_original_code:
void *checked_malloc(unsigned long size)
{
  return check_nonnull (malloc (size ? size : 1));
}

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall checked_realloc(void *a1, size_t a2)
{
void *v2; // rax

if ( !a2 )
a2 = 1LL;
v2 = realloc(a1, a2);
return check_nonnull((__int64)v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(void *a1, size_t a2)
{
void *v2; // rax

if ( !a2 )
a2 = 1LL;
v2 = realloc(a1, a2);
return func1((__int64)v2);
}

original_code:
void *
checked_realloc (void *ptr, size_t size)
{
  return check_nonnull (realloc (ptr, size ? size : 1));
}

canonical_original_code:
void *checked_realloc(void *ptr, unsigned long size)
{
  return check_nonnull (realloc (ptr, size ? size : 1));
}

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall checked_grow_alloc(void *a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // rax
size_t v3; // r8

v2 = *a2;
if ( *a2 == -1LL )
{
memory_exhausted(0);
JUMPOUT(0xB5LL);
}
v3 = 2 * v2;
if ( v2 > 0x7FFFFFFFFFFFFFFELL )
v3 = -1LL;
*a2 = v3;
return checked_realloc(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func4(void *a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // rax
size_t v3; // r8

v2 = *a2;
if ( *a2 == -1LL )
{
func0(0);
JUMPOUT(0xB5LL);
}
v3 = 2 * v2;
if ( v2 > 0x7FFFFFFFFFFFFFFELL )
v3 = -1LL;
*a2 = v3;
return func3(a1, v3);
}

original_code:
void *
checked_grow_alloc (void *ptr, size_t *size)
{
  size_t max = -1;
  if (*size == max)
    memory_exhausted (0);
  *size = *size < max / 2 ? 2 * *size : max;
  return checked_realloc (ptr, *size);
}

canonical_original_code:
void *checked_grow_alloc(void *ptr, unsigned long *size)
{
  unsigned long max = -1;
  if (*size == max)
    memory_exhausted (0);
  *size = *size < max / 2 ? 2 * *size : max;
  return checked_realloc (ptr, *size);
}

variable_types:
size
unsigned long *

variable_types:
max
unsigned long


decompiled_code:
int __fastcall command_indented_print(__int64 a1, unsigned int *a2)
{
unsigned int v2; // er12
unsigned int v4; // eax
int result; // eax
const char *v6; // rsi
const char *v7; // rsi
unsigned int v8; // ebx
const char **v9; // r13
const char **v10; // rbx
const char *v11; // rsi

v2 = a1;
v4 = *a2;
if ( *a2 == 4 )
{
v9 = (const char **)*((_QWORD *)a2 + 3);
v10 = v9 + 1;
result = printf("%*s%s", a1, (const char *)&unk_171, *v9);
v11 = v9[1];
if ( v11 )
{
do
{
++v10;
result = printf(" %s", v11);
v11 = *v10;
}
while ( *v10 );
}
}
else if ( v4 <= 4 )
{
v8 = a1 + 2;
if ( v4 != **((_DWORD **)a2 + 3) )
a1 = v8;
command_indented_print(a1);
printf(" \\\n%*s%s\n", v2, (const char *)&unk_171, &command_label_0[3 * *a2]);
if ( **((_DWORD **)a2 + 4) != *a2 )
v2 = v8;
result = command_indented_print(v2);
}
else
{
if ( v4 != 7 )
command_indented_print_cold();
printf("%*s(\n", a1, (const char *)&unk_171);
command_indented_print((unsigned int)(a1 + 1));
result = printf("\n%*s)", a1, (const char *)&unk_171);
}
v6 = (const char *)*((_QWORD *)a2 + 1);
if ( v6 )
result = printf("<%s", v6);
v7 = (const char *)*((_QWORD *)a2 + 2);
if ( v7 )
result = printf(">%s", v7);
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned int *a2)
{
unsigned int v2; // er12
unsigned int v4; // eax
int result; // eax
const char *v6; // rsi
const char *v7; // rsi
unsigned int v8; // ebx
const char **v9; // r13
const char **v10; // rbx
const char *v11; // rsi

v2 = a1;
v4 = *a2;
if ( *a2 == 4 )
{
v9 = (const char **)*((_QWORD *)a2 + 3);
v10 = v9 + 1;
result = printf("%*s%s", a1, (const char *)&unk_171, *v9);
v11 = v9[1];
if ( v11 )
{
do
{
++v10;
result = printf(" %s", v11);
v11 = *v10;
}
while ( *v10 );
}
}
else if ( v4 <= 4 )
{
v8 = a1 + 2;
if ( v4 != **((_DWORD **)a2 + 3) )
a1 = v8;
func0(a1);
printf(" \\\n%*s%s\n", v2, (const char *)&unk_171, &command_label_0[3 * *a2]);
if ( **((_DWORD **)a2 + 4) != *a2 )
v2 = v8;
result = func0(v2);
}
else
{
if ( v4 != 7 )
func2();
printf("%*s(\n", a1, (const char *)&unk_171);
func0((unsigned int)(a1 + 1));
result = printf("\n%*s)", a1, (const char *)&unk_171);
}
v6 = (const char *)*((_QWORD *)a2 + 1);
if ( v6 )
result = printf("<%s", v6);
v7 = (const char *)*((_QWORD *)a2 + 2);
if ( v7 )
result = printf(">%s", v7);
return result;
}

original_code:
static void
command_indented_print (int indent, command_t c)
{
  switch (c->type)
    {
    case AND_COMMAND:
    case SEQUENCE_COMMAND:
    case OR_COMMAND:
    case PIPE_COMMAND:
      {
 command_indented_print (indent + 2 * (c->u.command[0]->type != c->type),
    c->u.command[0]);
 static char const command_label[][3] = { "&&", ";", "||", "|" };
 printf (" \\\n%*s%s\n", indent, "", command_label[c->type]);
 command_indented_print (indent + 2 * (c->u.command[1]->type != c->type),
    c->u.command[1]);
 break;
      }
    case SIMPLE_COMMAND:
      {
 char **w = c->u.word;
 printf ("%*s%s", indent, "", *w);
 while (*++w)
   printf (" %s", *w);
 break;
      }
    case SUBSHELL_COMMAND:
      printf ("%*s(\n", indent, "");
      command_indented_print (indent + 1, c->u.subshell_command);
      printf ("\n%*s)", indent, "");
      break;
    default:
      abort ();
    }
  if (c->input)
    printf ("<%s", c->input);
  if (c->output)
    printf (">%s", c->output);
}

canonical_original_code:
static void command_indented_print(int indent, struct command *c)
{
  switch (c->type)
    {
    case AND_COMMAND:
    case SEQUENCE_COMMAND:
    case OR_COMMAND:
    case PIPE_COMMAND:
      {
 command_indented_print (indent + 2 * (c->u.command[0]->type != c->type),
    c->u.command[0]);
 static char command_label[][3] = { "&&", ";", "||", "|" };
 printf (" \\\n%*s%s\n", indent, "", command_label[c->type]);
 command_indented_print (indent + 2 * (c->u.command[1]->type != c->type),
    c->u.command[1]);
 break;
      }
    case SIMPLE_COMMAND:
      {
 char **w = c->u.word;
 printf ("%*s%s", indent, "", *w);
 while (*++w)
   printf (" %s", *w);
 break;
      }
    case SUBSHELL_COMMAND:
      printf ("%*s(\n", indent, "");
      command_indented_print (indent + 1, c->u.subshell_command);
      printf ("\n%*s)", indent, "");
      break;
    default:
      abort ();
    }
  if (c->input)
    printf ("<%s", c->input);
  if (c->output)
    printf (">%s", c->output);
}

variable_types: indent int

variable_types:
w
char **


decompiled_code:
int __fastcall print_command(unsigned int *a1)
{
command_indented_print(2LL, a1);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int *a1)
{
func0(2LL, a1);
return putchar(10);
}

original_code:
void
print_command (command_t c)
{
  command_indented_print (2, c);
  putchar ('\n');
}

canonical_original_code:
void print_command(struct command *c)
{
  command_indented_print (2, c);
  putchar ('\n');
}


decompiled_code:
// attributes: thunk
int get_next_byte(FILE *stream)
{
return getc(stream);
}

canonical_decompiled_code:
int func0(FILE *stream)
{
return getc(stream);
}

original_code:
static int
get_next_byte (void *stream)
{
  return getc (stream);
}

canonical_original_code:
static int get_next_byte(void *stream)
{
  return getc (stream);
}

variable_types:
stream
void *

return_type: int


usage

decompiled_code:
void usage()
{
error(1, 0, "usage: %s [-pt] SCRIPT-FILE", (const char *)program_name);
JUMPOUT(0x2ELL);
}

canonical_decompiled_code:
void func1()
{
error(1, 0, "usage: %s [-pt] SCRIPT-FILE", (const char *)program_name);
JUMPOUT(0x2ELL);
}

original_code:
static void
usage (void)
{
  error (1, 0, "usage: %s [-pt] SCRIPT-FILE", program_name);
}

canonical_original_code:
static void usage()
{
  error (1, 0, "usage: %s [-pt] SCRIPT-FILE", program_name);
}


repo: abellong/httptest

decompiled_code:
__int64 __fastcall l_remove(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 40);
result = *(_QWORD *)(a1 + 48);
if ( v1 )
*(_QWORD *)(v1 + 48) = result;
else
timers[*(int *)(a1 + 56)] = result;
if ( result )
*(_QWORD *)(result + 40) = v1;
return result;
}

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

v1 = *(_QWORD *)(a1 + 40);
result = *(_QWORD *)(a1 + 48);
if ( v1 )
*(_QWORD *)(v1 + 48) = result;
else
timers[*(int *)(a1 + 56)] = result;
if ( result )
*(_QWORD *)(result + 40) = v1;
return result;
}

original_code:
static void
l_remove( Timer* t )
    {
    int h = t->hash;
    if ( t->prev == (Timer*) 0 )
 timers[h] = t->next;
    else
 t->prev->next = t->next;
    if ( t->next != (Timer*) 0 )
 t->next->prev = t->prev;
    }

canonical_original_code:
static void l_remove(struct TimerStruct *t)
    {
    int h = t->hash;
    if ( t->prev == (struct TimerStruct *) 0 )
 timers[h] = t->next;
    else
 t->prev->next = t->next;
    if ( t->next != (struct TimerStruct *) 0 )
 t->next->prev = t->prev;
    }

variable_types: struct TimerStruct { void (*timer_proc)(struct timeval { long tv_sec; long tv_usec; } *nowP); long msecs; int periodic; struct timeval time; struct TimerStruct *prev; struct TimerStruct *next; int hash; } *

variable_types: h int

user_defined_types: struct TimerStruct { void (*timer_proc)(struct timeval *nowP); long msecs; int periodic; struct timeval time; struct TimerStruct *prev; struct TimerStruct *next; int hash; }


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

result = 0LL;
memset(timers, 0, sizeof(timers));
return result;
}

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

result = 0LL;
memset(timers, 0, sizeof(timers));
return result;
}

original_code:
void
tmr_init( void )
    {
    int h;
    for ( h = 0; h < 67; ++h )
 timers[h] = (Timer*) 0;
    }

canonical_original_code:
void tmr_init()
    {
    int h;
    for ( h = 0; h < 67; ++h )
 timers[h] = (struct TimerStruct *) 0;
    }

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


original_code:
Timer*
tmr_create(
    struct timeval* nowP, TimerProc* timer_proc, long msecs, int periodic )
    {
    Timer* t;
    if ( free_timers != (Timer*) 0 )
 {
 t = free_timers;
 free_timers = t->next;
 }
    else
 {
 t = (Timer*) malloc( sizeof(Timer) );
 if ( t == (Timer*) 0 )
     return (Timer*) 0;
 }
    t->timer_proc = timer_proc;
    t->msecs = msecs;
    t->periodic = periodic;
    if ( nowP != (struct timeval*) 0 )
 t->time = *nowP;
    else
 (void) gettimeofday( &t->time, (struct timezone*) 0 );
    t->time.tv_sec += msecs / 1000000L;
    t->time.tv_usec += msecs % 1000000L;
    if ( t->time.tv_usec >= 1000000L )
 {
 t->time.tv_sec += t->time.tv_usec / 1000000L;
 t->time.tv_usec %= 1000000L;
 }
    t->hash = hash( t );
    l_add( t );
    return t;
    }

canonical_original_code:
struct TimerStruct *tmr_create(struct timeval *nowP, void (*timer_proc)(struct timeval *nowP), long msecs, int periodic)
    {
    struct TimerStruct *t;
    if ( free_timers != (struct TimerStruct *) 0 )
 {
 t = free_timers;
 free_timers = t->next;
 }
    else
 {
 t = (struct TimerStruct *) malloc( sizeof(Timer) );
 if ( t == (struct TimerStruct *) 0 )
     return (struct TimerStruct *) 0;
 }
    t->timer_proc = timer_proc;
    t->msecs = msecs;
    t->periodic = periodic;
    if ( nowP != (struct timeval *) 0 )
 t->time = *nowP;
    else
 (void) gettimeofday( &t->time, (struct timezone *) 0 );
    t->time.tv_sec += msecs / 1000000L;
    t->time.tv_usec += msecs % 1000000L;
    if ( t->time.tv_usec >= 1000000L )
 {
 t->time.tv_sec += t->time.tv_usec / 1000000L;
 t->time.tv_usec %= 1000000L;
 }
    t->hash = hash( t );
    l_add( t );
    return t;
    }

variable_types:
nowP
struct timeval *

variable_types: msecs long

variable_types: periodic int

return_type: struct TimerStruct { void (*timer_proc)(struct timeval { long tv_sec; long tv_usec; } *nowP); long msecs; int periodic; struct timeval time; struct TimerStruct *prev; struct TimerStruct *next; int hash; } *

user_defined_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


original_code:
long
tmr_mstimeout( struct timeval* nowP )
    {
    int h;
    int gotone;
    long msecs, m;
    register Timer* t;
    gotone = 0;
    msecs = 0;
    for ( h = 0; h < 67; ++h )
 {
 t = timers[h];
 if ( t != (Timer*) 0 )
     {
     m = ( t->time.tv_sec - nowP->tv_sec ) * 1000L +
  ( t->time.tv_usec - nowP->tv_usec ) / 1000L;
     if ( ! gotone )
  {
  msecs = m;
  gotone = 1;
  }
     else if ( m < msecs )
  msecs = m;
     }
 }
    if ( ! gotone )
 return -1;
    if ( msecs <= 0 )
 msecs = 0;
    return msecs;
    }

canonical_original_code:
long tmr_mstimeout(struct timeval *nowP)
    {
    int h;
    int gotone;
    long msecs; long m;
    register struct TimerStruct *t;
    gotone = 0;
    msecs = 0;
    for ( h = 0; h < 67; ++h )
 {
 t = timers[h];
 if ( t != (struct TimerStruct *) 0 )
     {
     m = ( t->time.tv_sec - nowP->tv_sec ) * 1000L +
  ( t->time.tv_usec - nowP->tv_usec ) / 1000L;
     if ( ! gotone )
  {
  msecs = m;
  gotone = 1;
  }
     else if ( m < msecs )
  msecs = m;
     }
 }
    if ( ! gotone )
 return -1;
    if ( msecs <= 0 )
 msecs = 0;
    return msecs;
    }

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

variable_types: gotone int

variable_types: m long

return_type: long


decompiled_code:
void *__fastcall tmr_cancel(_QWORD *a1)
{
void *result; // rax

l_remove((__int64)a1);
result = free_timers;
a1[5] = 0LL;
free_timers = a1;
a1[6] = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func5(_QWORD *a1)
{
void *result; // rax

func0((__int64)a1);
result = free_timers;
a1[5] = 0LL;
free_timers = a1;
a1[6] = result;
return result;
}

original_code:
void
tmr_cancel( Timer* t )
    {
    l_remove( t );
    t->next = free_timers;
    free_timers = t;
    t->prev = (Timer*) 0;
    }

canonical_original_code:
void tmr_cancel(struct TimerStruct *t)
    {
    l_remove( t );
    t->next = free_timers;
    free_timers = t;
    t->prev = (struct TimerStruct *) 0;
    }


original_code:
void
tmr_run( struct timeval* nowP )
    {
    int h;
    Timer* t;
    Timer* next;
    for ( h = 0; h < 67; ++h )
 for ( t = timers[h]; t != (Timer*) 0; t = next )
     {
     next = t->next;
     if ( t->time.tv_sec > nowP->tv_sec ||
   ( t->time.tv_sec == nowP->tv_sec &&
     t->time.tv_usec > nowP->tv_usec ) )
  break;
     (t->timer_proc)(nowP );
     if ( t->periodic )
  {
  t->time.tv_sec += t->msecs / 1000000L;
  t->time.tv_usec += t->msecs % 1000000L;
  if ( t->time.tv_usec >= 1000000L )
      {
      t->time.tv_sec += t->time.tv_usec / 1000000L;
      t->time.tv_usec %= 1000000L;
      }
  l_resort( t );
  }
     else
  tmr_cancel( t );
     }
    }

canonical_original_code:
void tmr_run(struct timeval *nowP)
    {
    int h;
    struct TimerStruct *t;
    struct TimerStruct *next;
    for ( h = 0; h < 67; ++h )
 for ( t = timers[h]; t != (struct TimerStruct *) 0; t = next )
     {
     next = t->next;
     if ( t->time.tv_sec > nowP->tv_sec ||
   ( t->time.tv_sec == nowP->tv_sec &&
     t->time.tv_usec > nowP->tv_usec ) )
  break;
     (t->timer_proc)(nowP );
     if ( t->periodic )
  {
  t->time.tv_sec += t->msecs / 1000000L;
  t->time.tv_usec += t->msecs % 1000000L;
  if ( t->time.tv_usec >= 1000000L )
      {
      t->time.tv_sec += t->time.tv_usec / 1000000L;
      t->time.tv_usec %= 1000000L;
      }
  l_resort( t );
  }
     else
  tmr_cancel( t );
     }
    }


decompiled_code:
void tmr_cleanup()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = free_timers;
if ( free_timers )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[6];
free_timers = v0;
free(v1);
}
while ( v0 );
}
}

canonical_decompiled_code:
void func7()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = free_timers;
if ( free_timers )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[6];
free_timers = v0;
free(v1);
}
while ( v0 );
}
}

original_code:
void
tmr_cleanup( void )
    {
    Timer* t;
    while ( free_timers != (Timer*) 0 )
 {
 t = free_timers;
 free_timers = t->next;
 free( (void*) t );
 }
    }

canonical_original_code:
void tmr_cleanup()
    {
    struct TimerStruct *t;
    while ( free_timers != (struct TimerStruct *) 0 )
 {
 t = free_timers;
 free_timers = t->next;
 free( (void *) t );
 }
    }


decompiled_code:
void tmr_destroy()
{
__int64 *v0; // rsi
_QWORD *v1; // rdi

v0 = timers;
do
{
v1 = (_QWORD *)*v0;
if ( *v0 )
{
while ( 1 )
{
tmr_cancel(v1);
while ( 1 )
{
v1 = (_QWORD *)*v0;
if ( *v0 )
break;
if ( ++v0 == (__int64 *)&unk_818 )
goto LABEL_6;
}
}
}
++v0;
}
while ( v0 != (__int64 *)&unk_818 );
LABEL_6:
tmr_cleanup();
}

original_code:
void
tmr_destroy( void )
    {
    int h;
    for ( h = 0; h < 67; ++h )
 while ( timers[h] != (Timer*) 0 )
     tmr_cancel( timers[h] );
    tmr_cleanup();
    }

canonical_original_code:
void tmr_destroy()
    {
    int h;
    for ( h = 0; h < 67; ++h )
 while ( timers[h] != (struct TimerStruct *) 0 )
     tmr_cancel( timers[h] );
    tmr_cleanup();
    }


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)
{
__int64 v4; // rbx

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)
{
__int64 v4; // rbx

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


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

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


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

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
{
v2 = v0;
++v1;
v0 += 4832;
fputs(v2, stderr);
fputc(10, stderr);
}
while ( (int)statis > v1 );
}
exit(0);
}

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

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
{
v2 = v0;
++v1;
v0 += 4832;
fputs(v2, stderr);
fputc(10, stderr);
}
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 v3; // ebx
int v4; // eax
int v5; // er13
char *v6; // rdi
char *v7; // rdi
char *v8; // rdi
char *v9; // rdi
const char *v10; // r14
size_t v11; // rax
int v12; // eax
int result; // eax

v3 = 0;
while ( 1 )
{
v4 = getopt_long(argc, argv, ":cCi:Llf:n:d:s:I:e:j:a:x:mhD", &longopts, 0LL);
if ( v4 == -1 )
break;
v5 = v3 + 1;
switch ( v4 )
{
case ':':
puts("must have parameter");
goto LABEL_36;
case '?':
v10 = argv[v5];
if ( !v10 || !strstr(argv[v5], "--") )
goto LABEL_36;
++v3;
v11 = strlen((const char *)(unsigned int)((_DWORD)conf + 2596));
*(_WORD *)stpcpy(&conf[v11 + 2596], v10) = 44;
continue;
case 'C':
*(_DWORD *)&conf[6212] = 3;
++v3;
continue;
case 'D':
*(_DWORD *)&conf[6224] = 1;
++v3;
continue;
case 'I':
++v3;
set_special_item(optarg);
continue;
case 'L':
*(_DWORD *)&conf[6212] = 1;
++v3;
continue;
case 'a':
v9 = optarg;
++v3;
*(_DWORD *)&conf[6212] = 6;
aes_enc(v9);
continue;
case 'c':
*(_DWORD *)&conf[6212] = 2;
++v3;
continue;
case 'd':
v3 += 2;
*(_DWORD *)&conf[6204] = atoi(optarg);
continue;
case 'e':
v8 = optarg;
++v3;
*(_DWORD *)&conf[6212] = 6;
enc_code(v8);
continue;
case 'f':
++v3;
strcpy((char *)(unsigned int)((_DWORD)conf + 388), optarg);
continue;
case 'h':
LABEL_36:
usage();
return result;
case 'i':
v3 += 2;
*(_DWORD *)&conf[6216] = atoi(optarg);
continue;
case 'j':
v7 = optarg;
++v3;
*(_DWORD *)&conf[6212] = 6;
dec_code(v7, 1LL);
continue;
case 'l':
*(_DWORD *)&conf[6212] = 5;
++v3;
continue;
case 'm':
*(_DWORD *)&conf[6220] = 1;
++v3;
continue;
case 'n':
v3 += 2;
*(_DWORD *)&conf[6208] = atoi(optarg);
continue;
case 's':
++v3;
set_special_field(optarg);
continue;
case 'x':
v6 = optarg;
*(_DWORD *)&conf[6212] = 6;
aes_dec(v6, 1LL);
goto LABEL_5;
default:
LABEL_5:
++v3;
break;
}
}
if ( !*(_DWORD *)&conf[6208] )
*(_DWORD *)&conf[6208] = 1;
if ( !*(_DWORD *)&conf[6216] )
*(_DWORD *)&conf[6216] = 5;
v12 = *(_DWORD *)&conf[6212];
if ( v12 )
{
if ( v12 == 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 v3; // ebx
int v4; // eax
int v5; // er13
char *v6; // rdi
char *v7; // rdi
char *v8; // rdi
char *v9; // rdi
const char *v10; // r14
size_t v11; // rax
int v12; // eax
int result; // eax

v3 = 0;
while ( 1 )
{
v4 = getopt_long(argc, argv, ":cCi:Llf:n:d:s:I:e:j:a:x:mhD", &longopts, 0LL);
if ( v4 == -1 )
break;
v5 = v3 + 1;
switch ( v4 )
{
case ':':
puts("must have parameter");
goto LABEL_36;
case '?':
v10 = argv[v5];
if ( !v10 || !strstr(argv[v5], "--") )
goto LABEL_36;
++v3;
v11 = strlen((const char *)(unsigned int)((_DWORD)conf + 2596));
*(_WORD *)stpcpy(&conf[v11 + 2596], v10) = 44;
continue;
case 'C':
*(_DWORD *)&conf[6212] = 3;
++v3;
continue;
case 'D':
*(_DWORD *)&conf[6224] = 1;
++v3;
continue;
case 'I':
++v3;
set_special_item(optarg);
continue;
case 'L':
*(_DWORD *)&conf[6212] = 1;
++v3;
continue;
case 'a':
v9 = optarg;
++v3;
*(_DWORD *)&conf[6212] = 6;
aes_enc(v9);
continue;
case 'c':
*(_DWORD *)&conf[6212] = 2;
++v3;
continue;
case 'd':
v3 += 2;
*(_DWORD *)&conf[6204] = atoi(optarg);
continue;
case 'e':
v8 = optarg;
++v3;
*(_DWORD *)&conf[6212] = 6;
enc_code(v8);
continue;
case 'f':
++v3;
strcpy((char *)(unsigned int)((_DWORD)conf + 388), optarg);
continue;
case 'h':
LABEL_36:
func0();
return result;
case 'i':
v3 += 2;
*(_DWORD *)&conf[6216] = atoi(optarg);
continue;
case 'j':
v7 = optarg;
++v3;
*(_DWORD *)&conf[6212] = 6;
dec_code(v7, 1LL);
continue;
case 'l':
*(_DWORD *)&conf[6212] = 5;
++v3;
continue;
case 'm':
*(_DWORD *)&conf[6220] = 1;
++v3;
continue;
case 'n':
v3 += 2;
*(_DWORD *)&conf[6208] = atoi(optarg);
continue;
case 's':
++v3;
set_special_field(optarg);
continue;
case 'x':
v6 = optarg;
*(_DWORD *)&conf[6212] = 6;
aes_dec(v6, 1LL);
goto LABEL_5;
default:
LABEL_5:
++v3;
break;
}
}
if ( !*(_DWORD *)&conf[6208] )
*(_DWORD *)&conf[6208] = 1;
if ( !*(_DWORD *)&conf[6216] )
*(_DWORD *)&conf[6216] = 5;
v12 = *(_DWORD *)&conf[6212];
if ( v12 )
{
if ( v12 == 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

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

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

puts("tsar enable follow modules:");
result = statis;
if ( (int)statis > 0 )
{
v1 = (unsigned int)((_DWORD)mods + 4);
v2 = 0;
do
{
++v2;
result = printf("\t%s\n", (const char *)v1);
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, sizeof(conf));
result = memset(mods, 0, (size_t)&unk_25C00);
statis = 0LL;
return result;
}

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

free_modules();
memset(conf, 0, sizeof(conf));
result = memset(mods, 0, (size_t)&unk_25C00);
statis = 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)
{
time_t v3; // rax

parse_config_file("tsar.conf", argv, envp);
load_modules();
v3 = time(0LL);
*(_DWORD *)&conf[6204] = -1;
*((_QWORD *)&statis + 1) = v3;
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)
{
time_t v3; // rax

parse_config_file("tsar.conf", argv, envp);
load_modules();
v3 = time(0LL);
*(_DWORD *)&conf[6204] = -1;
*((_QWORD *)&statis + 1) = v3;
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; // er12
void *v3; // r14
const char *v4; // rbp
__int128 v6; // [rsp+0h] [rbp-138h] BYREF
char v7[296]; // [rsp+10h] [rbp-128h] BYREF

v6 = 0LL;
if ( (int)AES_set_encrypt_key("yunwei@love7road", 128LL, v7) < 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, v7, &v6, 1LL);
byte2hexstr((__int64)v4, (__int64)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; // er12
void *v3; // r14
const char *v4; // rbp
__int128 v6; // [rsp+0h] [rbp-138h] BYREF
char v7[296]; // [rsp+10h] [rbp-128h] BYREF

v6 = 0LL;
if ( (int)AES_set_encrypt_key("yunwei@love7road", 128LL, v7) < 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, v7, &v6, 1LL);
func0((__int64)v4, (__int64)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; // eax
size_t v3; // r15
int v4; // er14
void *v5; // rbp
const char *v6; // r12
__int128 v8; // [rsp+0h] [rbp-148h] BYREF
char v9[312]; // [rsp+10h] [rbp-138h] BYREF

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

canonical_decompiled_code:
const char *__fastcall func3(char *s, int a2)
{
int v2; // eax
size_t v3; // r15
int v4; // er14
void *v5; // rbp
const char *v6; // r12
__int128 v8; // [rsp+0h] [rbp-148h] BYREF
char v9[312]; // [rsp+10h] [rbp-138h] BYREF

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

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)
{
__int64 v1; // r13
const char *v2; // rbx
char *v3; // rax
int v4; // eax
__int64 v5; // r13
char *v6; // rax
const char *v7; // rbp
size_t v8; // rax
const char *v9; // rbp
size_t v10; // rax

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

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

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

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 *


decompiled_code:
int __fastcall special_mod(__int64 a1)
{
char *v1; // rax
char *v2; // rbp
int v3; // er12
__int64 v4; // rbx
const char *v5; // r13
__int64 v6; // r14
const char *i; // rsi
__int128 v9[4]; // [rsp+0h] [rbp-48h] BYREF

v9[0] = 0LL;
v9[1] = 0LL;
sprintf((char *)v9, "mod_%s", (const char *)(a1 + 5));
LODWORD(v1) = statis;
if ( statis > 0 )
{
v2 = mods;
v3 = 0;
do
{
LODWORD(v1) = strcmp(v2, (const char *)v9);
if ( !(_DWORD)v1 )
{
load_modules();
v1 = strtok(0LL, " \t\r\n");
v4 = *((_QWORD *)v2 + 600);
v5 = v1;
LODWORD(v1) = *((_DWORD *)v2 + 1180);
if ( (int)v1 > 0 )
{
v6 = v4 + 140LL * (unsigned int)((_DWORD)v1 - 1) + 140;
do
{
for ( i = (const char *)v4; *i == 32; ++i )
;
v1 = strstr(v5, i);
if ( v1 )
{
*(_DWORD *)(v4 + 128) = 3;
*((_DWORD *)v2 + 1179) = 1;
}
v4 += 140LL;
}
while ( v4 != v6 );
}
}
++v3;
v2 += 4832;
}
while ( statis > v3 );
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
char *v1; // rax
char *v2; // rbp
int v3; // er12
__int64 v4; // rbx
const char *v5; // r13
__int64 v6; // r14
const char *i; // rsi
__int128 v9[4]; // [rsp+0h] [rbp-48h] BYREF

v9[0] = 0LL;
v9[1] = 0LL;
sprintf((char *)v9, "mod_%s", (const char *)(a1 + 5));
LODWORD(v1) = statis;
if ( statis > 0 )
{
v2 = mods;
v3 = 0;
do
{
LODWORD(v1) = strcmp(v2, (const char *)v9);
if ( !(_DWORD)v1 )
{
load_modules();
v1 = strtok(0LL, " \t\r\n");
v4 = *((_QWORD *)v2 + 600);
v5 = v1;
LODWORD(v1) = *((_DWORD *)v2 + 1180);
if ( (int)v1 > 0 )
{
v6 = v4 + 140LL * (unsigned int)((_DWORD)v1 - 1) + 140;
do
{
for ( i = (const char *)v4; *i == 32; ++i )
;
v1 = strstr(v5, i);
if ( v1 )
{
*(_DWORD *)(v4 + 128) = 3;
*((_DWORD *)v2 + 1179) = 1;
}
v4 += 140LL;
}
while ( v4 != v6 );
}
}
++v3;
v2 += 4832;
}
while ( statis > v3 );
}
return (int)v1;
}

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(char *haystack)
{
char *result; // rax
__int64 v2; // r13
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // r14
const char *i; // rsi

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

canonical_decompiled_code:
char *__fastcall func2(char *haystack)
{
char *result; // rax
__int64 v2; // r13
__int64 v3; // rbp
__int64 v4; // rbx
__int64 v5; // r14
const char *i; // rsi

result = (char *)statis;
if ( statis > 0 )
{
v2 = 4832LL * statis;
v3 = 0LL;
do
{
result = (char *)*(unsigned int *)&mods[v3 + 4720];
v4 = *(_QWORD *)&mods[v3 + 4800];
if ( (int)result > 0 )
{
v5 = v4 + 140LL * (unsigned int)((_DWORD)result - 1) + 140;
do
{
for ( i = (const char *)v4; *i == 32; ++i )
;
result = strstr(haystack, i);
if ( result )
{
*(_DWORD *)(v4 + 128) = 3;
*(_DWORD *)&mods[v3 + 4716] = 1;
}
v4 += 140LL;
}
while ( v5 != v4 );
}
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; // rdx
char *v3; // rbx

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 = result + 4832;
}
while ( result + 4832 != v3 );
}
return result;
}

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

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 = result + 4832;
}
while ( result + 4832 != 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; // rbp
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; // rbp
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; // rbp
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; // rbp
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 *v0; // rax
bool v1; // zf

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

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

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

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
const char *v2; // r8
struct ifaddrs *ifap[2]; // [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 )
goto LABEL_3;
}
else if ( getifaddrs(ifap) != -1 )
{
goto LABEL_3;
}
do_debug(4LL, "get interface address struct error!\n");
LABEL_3:
for ( result = ifap[0]; result; ifap[0] = result )
{
if ( !strcmp(result->ifa_name, "eth0") )
{
v1 = result->ifa_addr;
if ( v1->sa_family == 2 )
{
v2 = inet_ntop(2, &v1->sa_data[2], (char *)(unsigned int)((_DWORD)&conf + 6284), 0x20u);
result = ifap[0];
if ( !v2 )
{
do_debug(4LL, "get host ip error!\n");
result = ifap[0];
}
}
}
result = result->ifa_next;
}
return result;
}

canonical_decompiled_code:
struct ifaddrs *func9()
{
struct ifaddrs *result; // rax
struct sockaddr *v1; // rsi
const char *v2; // r8
struct ifaddrs *ifap[2]; // [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 )
goto LABEL_3;
}
else if ( getifaddrs(ifap) != -1 )
{
goto LABEL_3;
}
do_debug(4LL, "get interface address struct error!\n");
LABEL_3:
for ( result = ifap[0]; result; ifap[0] = result )
{
if ( !strcmp(result->ifa_name, "eth0") )
{
v1 = result->ifa_addr;
if ( v1->sa_family == 2 )
{
v2 = inet_ntop(2, &v1->sa_data[2], (char *)(unsigned int)((_DWORD)&conf + 6284), 0x20u);
result = ifap[0];
if ( !v2 )
{
do_debug(4LL, "get host ip error!\n");
result = ifap[0];
}
}
}
result = result->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)
{
unsigned int v1; // er13
char *v2; // rax
char *v3; // rbp
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func11(char *haystack)
{
unsigned int v1; // er13
char *v2; // rax
char *v3; // rbp
__int64 result; // rax

v1 = 1;
v2 = strtok(haystack, " \t\r\n");
if ( !v2 )
return v1;
v3 = v2;
if ( strstr(haystack, "mod_") )
{
func0(v3);
return v1;
}
if ( !strcmp(v3, "module_path") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 132));
result = 1LL;
}
else
{
if ( !strstr(haystack, "spec_") )
{
if ( !strcmp(v3, "output_interface") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 260));
}
else if ( !strcmp(v3, "output_file_path") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 388));
}
else if ( !strcmp(v3, "output_db_addr") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 516));
}
else if ( !strcmp(v3, "output_db_pawd") )
{
func4((char *)(unsigned int)((_DWORD)&conf + 1028));
}
else if ( !strcmp(v3, "output_db_mod") )
{
func5((char *)(unsigned int)((_DWORD)&conf + 1060));
}
else if ( !strcmp(v3, "output_nagios_mod") )
{
v1 = 1;
func5((char *)(unsigned int)((_DWORD)&conf + 1572));
}
else if ( !strcmp(v3, "output_stdio_mod") )
{
v1 = 1;
func5((char *)(unsigned int)((_DWORD)&conf + 2084));
}
else if ( !strcmp(v3, "debug_leve") )
{
func6();
v1 = 1;
}
else if ( !strcmp(v3, "include") )
{
func10();
v1 = 1;
}
else if ( !strcmp(v3, "server_addr") )
{
v1 = 1;
func4((char *)(unsigned int)((_DWORD)&conf + 3108));
}
else if ( !strcmp(v3, "server_port") )
{
v1 = 1;
func7(*((_DWORD **)&conf + 453));
}
else if ( !strcmp(v3, "cycle_time") )
{
v1 = 1;
func7(*((_DWORD **)&conf + 454));
}
else if ( !strcmp(v3, "send_nsca_cmd") )
{
v1 = 1;
func4((char *)(unsigned int)((_DWORD)&conf + 3640));
}
else if ( !strcmp(v3, "send_nsca_conf") )
{
v1 = 1;
func4((char *)(unsigned int)((_DWORD)&conf + 4152));
}
else if ( !strcmp(v3, "threshold") )
{
func8();
v1 = 1;
}
else
{
v1 = 0;
if ( !((unsigned __int8)*(&conf + 6284) | (unsigned __int8)*(&conf + 6252)) )
{
func9();
v1 = 1;
}
}
return v1;
}
func1((__int64)v3);
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)
{
size_t v3; // rax
unsigned int v4; // er12
__int128 v5; // [rsp+0h] [rbp-1018h] BYREF
char v6[4080]; // [rsp+10h] [rbp-1008h] BYREF

v5 = 0LL;
memset(v6, 0, sizeof(v6));
if ( !s )
return 0LL;
if ( !*s )
return 0LL;
v3 = strlen(s);
memcpy(&v5, s, v3);
if ( !strtok((char *)&v5, delim) )
return 0LL;
v4 = 0;
do
++v4;
while ( strtok(0LL, delim) );
return v4;
}

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

v5 = 0LL;
memset(v6, 0, sizeof(v6));
if ( !s )
return 0LL;
if ( !*s )
return 0LL;
v3 = strlen(s);
memcpy(&v5, s, v3);
if ( !strtok((char *)&v5, delim) )
return 0LL;
v4 = 0;
do
++v4;
while ( strtok(0LL, delim) );
return v4;
}

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)
{
__int64 v2; // rbx

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

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

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

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(__int64 a1, int a2, const char *a3)
{
unsigned int v5; // er13
size_t v7; // rax
char *v8; // rbp
int v9; // eax
__int128 v10; // [rsp+0h] [rbp-1028h] BYREF
char v11[4080]; // [rsp+10h] [rbp-1018h] BYREF

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

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

v10 = 0LL;
memset(v11, 0, sizeof(v11));
if ( !a3 )
return 0;
if ( !*a3 )
return 0;
v7 = strlen(a3);
memcpy(&v10, a3, v7);
if ( (v8 = strtok((char *)&v10, ",")) == 0LL )
return 0;
v5 = 0;
do
{
v9 = func2(v8);
if ( a2 <= (int)v5 )
break;
if ( !v9 )
break;
++v5;
a1 += 8LL;
*(_QWORD *)(a1 - 8) = strtoull(v8, 0LL, 10);
v8 = strtok(0LL, ",");
}
while ( v8 );
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)
{
unsigned int v3; // er15
size_t v6; // rax
size_t v7; // rdi
char *v8; // r13
char *v9; // rax

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

canonical_decompiled_code:
__int64 __fastcall func4(void *dest, char *s, int *a3)
{
unsigned int v3; // er15
size_t v6; // rax
size_t v7; // rdi
char *v8; // r13
char *v9; // rax

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

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 *