decompiled_code:
int __fastcall add_second_dic(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
_QWORD *v3; // rax
int v4; // edx

v2 = 16LL * Marcov3Used + 4477184;
LODWORD(v3) = Marcov3Used + 1;
qword_445108[2 * Marcov3Used] = a2;
Marcov3Used = (int)v3;
if ( (int)v3 > 490 )
LODWORD(v3) = puts("louise_love : MarkovList3 memory leaked.");
if ( *(_DWORD *)a1 )
{
v3 = getWordList(*(_QWORD **)(a1 + 8), *(_DWORD *)a1 - 1);
*v3 = v2;
*(_DWORD *)a1 = v4;
}
else
{
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = 1;
}
return (int)v3;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
_QWORD *v3; // rax
int v4; // edx

v2 = 16LL * Marcov3Used + 4477184;
LODWORD(v3) = Marcov3Used + 1;
qword_445108[2 * Marcov3Used] = a2;
Marcov3Used = (int)v3;
if ( (int)v3 > 490 )
LODWORD(v3) = puts("louise_love : MarkovList3 memory leaked.");
if ( *(_DWORD *)a1 )
{
v3 = getWordList(*(_QWORD **)(a1 + 8), *(_DWORD *)a1 - 1);
*v3 = v2;
*(_DWORD *)a1 = v4;
}
else
{
*(_QWORD *)(a1 + 8) = v2;
*(_DWORD *)a1 = 1;
}
return (int)v3;
}

original_code:
void add_second_dic(struct SecondStageDic* dic,const struct Word* word){
 struct WordList* insert = &MarcovList3[Marcov3Used];
 insert->word = word;
 Marcov3Used++;
 if(Marcov3Used > ((491)-1)){
  printf("" "louise_love : MarkovList3 memory leaked.\n");
 }
 if(dic->list_size == 0){
  dic->list = insert;
  dic->list_size=1;
 }else{
  struct WordList* last = getWordList(dic->list,dic->list_size-1);
  last->next = insert;
  dic->list_size++;
 }
}

canonical_original_code:
void add_second_dic(struct SecondStageDic *dic, struct Word *word){
 struct WordList *insert = &MarcovList3[Marcov3Used];
 insert->word = word;
 Marcov3Used++;
 if(Marcov3Used > ((491)-1)){
  printf("" "louise_love : MarkovList3 memory leaked.\n");
 }
 if(dic->list_size == 0){
  dic->list = insert;
  dic->list_size=1;
 }else{
  struct WordList *last = getWordList(dic->list,dic->list_size-1);
  last->next = insert;
  dic->list_size++;
 }
}

variable_types: struct SecondStageDic { int list_size; struct WordList { struct WordList *next; struct Word { short id; short surface; short reading; short pos; } *word; } *list; } *

variable_types:
word
struct Word *

user_defined_types: struct SecondStageDic { int list_size; struct WordList *list; }

user_defined_types: struct WordList { struct WordList *next; struct Word *word; }


decompiled_code:
int __fastcall add_first_dic(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
_QWORD *v3; // rax
int v4; // edx
int v5; // edx

v2 = 16LL * Marcov2Used + 4485056;
LODWORD(v3) = Marcov2Used + 1;
qword_446FC8[2 * Marcov2Used] = a2;
Marcov2Used = (int)v3;
if ( (int)v3 > 491 )
LODWORD(v3) = puts("louise_love : MarkovList3 memory leaked.");
v4 = *(_DWORD *)(a1 + 2032);
if ( v4 )
{
v3 = getWordList(*(_QWORD **)(a1 + 2040), v4 - 1);
*v3 = v2;
*(_DWORD *)(a1 + 2032) = v5;
}
else
{
*(_QWORD *)(a1 + 2040) = v2;
*(_DWORD *)(a1 + 2032) = 1;
}
return (int)v3;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
_QWORD *v3; // rax
int v4; // edx
int v5; // edx

v2 = 16LL * Marcov2Used + 4485056;
LODWORD(v3) = Marcov2Used + 1;
qword_446FC8[2 * Marcov2Used] = a2;
Marcov2Used = (int)v3;
if ( (int)v3 > 491 )
LODWORD(v3) = puts("louise_love : MarkovList3 memory leaked.");
v4 = *(_DWORD *)(a1 + 2032);
if ( v4 )
{
v3 = getWordList(*(_QWORD **)(a1 + 2040), v4 - 1);
*v3 = v2;
*(_DWORD *)(a1 + 2032) = v5;
}
else
{
*(_QWORD *)(a1 + 2040) = v2;
*(_DWORD *)(a1 + 2032) = 1;
}
return (int)v3;
}

original_code:
void add_first_dic(struct FirstStageDic* dic,const struct Word* word){
 struct WordList* insert = &MarcovList2[Marcov2Used];
 insert->word = word;
 Marcov2Used++;
 if(Marcov2Used > (491)){
  printf("" "louise_love : MarkovList3 memory leaked.\n");
 }
 if(dic->list_size == 0){
  dic->list = insert;
  dic->list_size=1;
 }else{
  struct WordList* last = getWordList(dic->list,dic->list_size-1);
  last->next = insert;
  dic->list_size++;
 }
}

canonical_original_code:
void add_first_dic(struct FirstStageDic *dic, struct Word *word){
 struct WordList *insert = &MarcovList2[Marcov2Used];
 insert->word = word;
 Marcov2Used++;
 if(Marcov2Used > (491)){
  printf("" "louise_love : MarkovList3 memory leaked.\n");
 }
 if(dic->list_size == 0){
  dic->list = insert;
  dic->list_size=1;
 }else{
  struct WordList *last = getWordList(dic->list,dic->list_size-1);
  last->next = insert;
  dic->list_size++;
 }
}

variable_types: struct FirstStageDic { struct SecondStageDic { int list_size; struct WordList { struct WordList *next; struct Word { short id; short surface; short reading; short pos; } *word; } *list; } next[-1]; int list_size; struct WordList *list; } *

return_type: void

user_defined_types: struct FirstStageDic { struct SecondStageDic next[-1]; int list_size; struct WordList *list; }


buildDictionary

decompiled_code:
__int64 buildDictionary()
{
__int16 v0; // r12
__int16 v1; // bp
unsigned __int16 *v2; // rbx
__int64 result; // rax

v0 = -1;
v1 = 0;
v2 = (unsigned __int16 *)&unk_402568;
memset(&Dic, 0, 0x3F800uLL);
result = 0LL;
memset(&MarcovList2, 0, 0x1EB0uLL);
memset(&MarcovList3, 0, 0x1EA0uLL);
while ( v2 != (unsigned __int16 *)&_GNU_EH_FRAME_HDR )
{
if ( v1 >= 0 )
{
add_first_dic(((__int64)v1 << 11) + 4217088, (__int64)v2);
if ( v0 >= 0 )
add_second_dic(16 * (v1 + ((__int64)v0 << 7)) + 4217088, (__int64)v2);
}
result = v2[2];
v0 = v1;
v2 += 4;
v1 = result;
}
return result;
}

original_code:
void buildDictionary(void){
 short i;
 short beforebefore = -1;
 short before = -1;
 memset(Dic,0,sizeof(Dic));
 memset(MarcovList2,0,sizeof(MarcovList2));
 memset(MarcovList3,0,sizeof(MarcovList3));
 for(i=0;i<(491);i++){
  const struct Word* copipe = &Copipe[i];
  if(before >= 0){
   struct FirstStageDic* dic = &Dic[before];
   add_first_dic(dic,copipe);
   if(beforebefore >= 0){
    struct SecondStageDic* second_dic = &(Dic[beforebefore].next[before]);
    add_second_dic(second_dic,copipe);
   }
  }
  beforebefore = before;
  before = copipe->reading;
 }
}

canonical_original_code:
void buildDictionary(){
 short i;
 short beforebefore = -1;
 short before = -1;
 memset(Dic,0,sizeof(Dic));
 memset(MarcovList2,0,sizeof(MarcovList2));
 memset(MarcovList3,0,sizeof(MarcovList3));
 for(i=0;i<(491);i++){
  struct Word *copipe = &Copipe[i];
  if(before >= 0){
   struct FirstStageDic *dic = &Dic[before];
   add_first_dic(dic,copipe);
   if(beforebefore >= 0){
    struct SecondStageDic *second_dic = &(Dic[beforebefore].next[before]);
    add_second_dic(second_dic,copipe);
   }
  }
  beforebefore = before;
  before = copipe->reading;
 }
}

variable_types: i short

variable_types: beforebefore short

variable_types: before short

variable_types: struct Word { short id; short surface; short reading; short pos; } *


nextRand

decompiled_code:
__int64 __fastcall nextRand(__int64 a1)
{
unsigned int v1; // eax

v1 = 214013 * *(_DWORD *)(a1 + 12) + 2531011;
*(_DWORD *)(a1 + 12) = v1;
return HIWORD(v1) & 0x7FFF;
}

original_code:
unsigned int nextRand(struct CopipeStatus* status){
 unsigned int result;
 status->seed *= 214013;
 status->seed += 2531011;
 result = status->seed;
 result = result >> 0x10;
 result &= 0x7fff;
 return result;
}

canonical_original_code:
unsigned int nextRand(struct CopipeStatus *status){
 unsigned int result;
 status->seed *= 214013;
 status->seed += 2531011;
 result = status->seed;
 result = result >> 0x10;
 result &= 0x7fff;
 return result;
}

variable_types: struct CopipeStatus { short beforebefore; short before; short now; short now_str; short now_str_size; short now_str_ptr; unsigned int seed; } *

variable_types:
result
unsigned int

return_type: unsigned int


initCopipeStatus

decompiled_code:
__int64 __fastcall initCopipeStatus(__int64 a1)
{
__int16 v1; // ax
__int64 result; // rax

*(_QWORD *)a1 = 0xFFFFFFFFLL;
v1 = strlen(Surface);
*(_DWORD *)(a1 + 12) = 0;
*(_WORD *)(a1 + 8) = v1;
result = 0LL;
*(_WORD *)(a1 + 10) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int16 v1; // ax
__int64 result; // rax

*(_QWORD *)a1 = 0xFFFFFFFFLL;
v1 = strlen(Surface);
*(_DWORD *)(a1 + 12) = 0;
*(_WORD *)(a1 + 8) = v1;
result = 0LL;
*(_WORD *)(a1 + 10) = 0;
return result;
}

original_code:
void initCopipeStatus(struct CopipeStatus* status){
 status->beforebefore=-1;
 status->before=-1;
 status->now=0;
 status->now_str = 0;
 status->now_str_size = strlen(Surface[status->now_str]);
 status->now_str_ptr = 0;
 status->seed = 0;
}

canonical_original_code:
void initCopipeStatus(struct CopipeStatus *status){
 status->beforebefore=-1;
 status->before=-1;
 status->now=0;
 status->now_str = 0;
 status->now_str_size = strlen(Surface[status->now_str]);
 status->now_str_ptr = 0;
 status->seed = 0;
}

user_defined_types: struct CopipeStatus { short beforebefore; short before; short now; short now_str; short now_str_size; short now_str_ptr; unsigned int seed; }


main

canonical_name: main

repo: leecbaker/colorbase

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

while ( 2 )
{
v3 = getchar();
if ( v3 != -1 )
{
LABEL_2:
switch ( v3 )
{
case 'A':
case 'a':
printf("\x1B[32m%c", v3);
continue;
case 'C':
case 'c':
printf("\x1B[34m%c", v3);
continue;
case 'G':
case 'g':
printf("\x1B[33m%c", v3);
continue;
case 'T':
case 't':
printf("\x1B[31m%c", v3);
continue;
default:
printf("\x1B[30m%c", v3);
v3 = getchar();
if ( v3 != -1 )
goto LABEL_2;
break;
}
}
break;
}
printf("\x1B[30m%c", 0xFFFFFFFFLL);
return 0;
}

original_code:
int main() {
 while(1) {
  int ch = getchar();
  switch(ch) {
   case (-1):
    printf("\e[30m%c",ch);
    return 0;
   case 'A':
   case 'a':
    printf("\e[32m%c", ch);
    break;
   case 'C':
   case 'c':
    printf("\e[34m%c", ch);
    break;
   case 'G':
   case 'g':
    printf("\e[33m%c", ch);
    break;
   case 'T':
   case 't':
    printf("\e[31m%c", ch);
    break;
   default:
    printf("\e[30m%c",ch);
    break;
  }
 }
}

variable_types: ch int

return_type: int


repo: leevon/rhizel

decompiled_code:
__int64 __fastcall find_section(__int64 a1, const char *a2)
{
__int64 i; // r12

for ( i = a1; i; i = *(_QWORD *)(i + 16) )
{
if ( *(_QWORD *)i && !strcmp(*(const char **)i, a2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
__int64 i; // r12

for ( i = a1; i; i = *(_QWORD *)(i + 16) )
{
if ( *(_QWORD *)i && !strcmp(*(const char **)i, a2) )
break;
}
return i;
}

original_code:
static struct cfg_section *find_section(struct cfg_section *sec_head, char *name)
{
    struct cfg_section *sec_curr = sec_head;
    while (sec_curr)
    {
        if (sec_curr->name && strcmp(sec_curr->name, name) == 0)
            return sec_curr;
        sec_curr = sec_curr->next;
    }
    return ((void *)0);
}

variable_types:
name
char *

variable_types: struct cfg_section { char *name; struct cfg_obj { char *name; char *value; struct cfg_obj *next; } *obj; struct cfg_section *next; } *

user_defined_types: struct cfg_section { char *name; struct cfg_obj *obj; struct cfg_section *next; }


decompiled_code:
void __fastcall cfg_free(void *ptr)
{
void **v1; // r12
void **v2; // r13
void **v3; // rbx
void **v4; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[2];
v3 = (void **)v2[1];
while ( v3 )
{
v4 = v3;
v3 = (void **)v3[2];
free(*v4);
free(v4[1]);
free(v4);
}
free(*v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void **v1; // r12
void **v2; // r13
void **v3; // rbx
void **v4; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[2];
v3 = (void **)v2[1];
while ( v3 )
{
v4 = v3;
v3 = (void **)v3[2];
free(*v4);
free(v4[1]);
free(v4);
}
free(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void cfg_free(cfg_st *handler)
{
    struct cfg_section *sec_curr = handler;
    struct cfg_section *next = ((void *)0);
    while (sec_curr)
    {
        next = sec_curr->next;
        struct cfg_obj *obj_curr = sec_curr->obj;
        struct cfg_obj *arg_next = ((void *)0);
        while (obj_curr)
        {
            arg_next = obj_curr->next;
            free(obj_curr->name);
            free(obj_curr->value);
            free(obj_curr);
            obj_curr = arg_next;
        }
        free(sec_curr->name);
        free(sec_curr);
        sec_curr = next;
    }
    return;
}

canonical_original_code:
void cfg_free(struct cfg_section *handler)
{
    struct cfg_section *sec_curr = handler;
    struct cfg_section *next = ((void *)0);
    while (sec_curr)
    {
        next = sec_curr->next;
        struct cfg_obj *obj_curr = sec_curr->obj;
        struct cfg_obj *arg_next = ((void *)0);
        while (obj_curr)
        {
            arg_next = obj_curr->next;
            free(obj_curr->name);
            free(obj_curr->value);
            free(obj_curr);
            obj_curr = arg_next;
        }
        free(sec_curr->name);
        free(sec_curr);
        sec_curr = next;
    }
    return;
}

variable_types: struct cfg_obj { char *name; char *value; struct cfg_obj *next; } *


decompiled_code:
__int64 __fastcall cfg_read_str(__int64 a1, const char *a2, const char *a3, char **a4, const char *a5)
{
__int64 v6; // rbx
const char *v7; // r14
char *v10; // rax
__int64 v12; // rbx
const char *v13; // r14
char *v14; // rax

if ( a4 == 0LL || a3 == 0LL )
return 0xFFFFFFFFLL;
v6 = a1;
if ( !a1 )
return 0xFFFFFFFFLL;
v7 = a2;
if ( a2 )
{
if ( !*a2 )
v7 = "global";
}
else
{
v7 = "global";
}
while ( !*(_QWORD *)v6 || strcmp(v7, *(const char **)v6) )
{
v6 = *(_QWORD *)(v6 + 16);
if ( !v6 )
goto LABEL_9;
}
v12 = *(_QWORD *)(v6 + 8);
if ( v12 )
{
do
{
if ( *(_QWORD *)v12 )
{
v13 = *(const char **)(v12 + 8);
if ( v13 )
{
if ( !strcmp(*(const char **)v12, a3) )
{
v14 = strdup(v13);
*a4 = v14;
return (unsigned int)-(v14 == 0LL);
}
}
}
v12 = *(_QWORD *)(v12 + 16);
}
while ( v12 );
if ( a5 )
goto LABEL_10;
goto LABEL_19;
}
LABEL_9:
if ( !a5 )
{
LABEL_19:
*a4 = 0LL;
return 1LL;
}
LABEL_10:
v10 = strdup(a5);
*a4 = v10;
if ( !v10 )
return 0xFFFFFFFFLL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2, const char *a3, char **a4, const char *a5)
{
__int64 v6; // rbx
const char *v7; // r14
char *v10; // rax
__int64 v12; // rbx
const char *v13; // r14
char *v14; // rax

if ( a4 == 0LL || a3 == 0LL )
return 0xFFFFFFFFLL;
v6 = a1;
if ( !a1 )
return 0xFFFFFFFFLL;
v7 = a2;
if ( a2 )
{
if ( !*a2 )
v7 = "global";
}
else
{
v7 = "global";
}
while ( !*(_QWORD *)v6 || strcmp(v7, *(const char **)v6) )
{
v6 = *(_QWORD *)(v6 + 16);
if ( !v6 )
goto LABEL_9;
}
v12 = *(_QWORD *)(v6 + 8);
if ( v12 )
{
do
{
if ( *(_QWORD *)v12 )
{
v13 = *(const char **)(v12 + 8);
if ( v13 )
{
if ( !strcmp(*(const char **)v12, a3) )
{
v14 = strdup(v13);
*a4 = v14;
return (unsigned int)-(v14 == 0LL);
}
}
}
v12 = *(_QWORD *)(v12 + 16);
}
while ( v12 );
if ( a5 )
goto LABEL_10;
goto LABEL_19;
}
LABEL_9:
if ( !a5 )
{
LABEL_19:
*a4 = 0LL;
return 1LL;
}
LABEL_10:
v10 = strdup(a5);
*a4 = v10;
if ( !v10 )
return 0xFFFFFFFFLL;
return 1LL;
}

original_code:
int cfg_read_str(cfg_st *handler,
        char *section, char *name, char **value, char *default_value)
{
    if (!handler || !name || !value)
        return -1;
    if (section == ((void *)0) || *section == 0)
        section = "global";
    struct cfg_section *sec_curr = handler;
    while (sec_curr)
    {
        if (sec_curr->name && strcmp(section, sec_curr->name) == 0)
            break;
        sec_curr = sec_curr->next;
    }
    if (sec_curr)
    {
        struct cfg_obj *obj = sec_curr->obj;
        while (obj)
        {
            if (obj->name && obj->value && strcmp(obj->name, name) == 0)
            {
                *value = strdup(obj->value);
                if (*value == ((void *)0))
                    return -1;
                return 0;
            }
            obj = obj->next;
        }
    }
    if (default_value)
    {
        *value = strdup(default_value);
        if (*value == ((void *)0))
            return -1;
    }
    else
    {
        *value = ((void *)0);
    }
    return 1;
}

canonical_original_code:
int cfg_read_str(struct cfg_section *handler, char *section, char *name, char **value, char *default_value)
{
    if (!handler || !name || !value)
        return -1;
    if (section == ((void *)0) || *section == 0)
        section = "global";
    struct cfg_section *sec_curr = handler;
    while (sec_curr)
    {
        if (sec_curr->name && strcmp(section, sec_curr->name) == 0)
            break;
        sec_curr = sec_curr->next;
    }
    if (sec_curr)
    {
        struct cfg_obj *obj = sec_curr->obj;
        while (obj)
        {
            if (obj->name && obj->value && strcmp(obj->name, name) == 0)
            {
                *value = strdup(obj->value);
                if (*value == ((void *)0))
                    return -1;
                return 0;
            }
            obj = obj->next;
        }
    }
    if (default_value)
    {
        *value = strdup(default_value);
        if (*value == ((void *)0))
            return -1;
    }
    else
    {
        *value = ((void *)0);
    }
    return 1;
}

variable_types:
section
char *

variable_types:
value
char **

user_defined_types: struct cfg_obj { char *name; char *value; struct cfg_obj *next; }


decompiled_code:
__int64 __fastcall cfg_read_strn(__int64 a1, const char *a2, const char *a3, void *a4, size_t a5, const char *a6)
{
int v8; // er12
char *v9; // r14
char *src; // [rsp+8h] [rbp-30h] BYREF

src = 0LL;
v8 = cfg_read_str(a1, a2, a3, &src, a6);
if ( v8 >= 0 )
{
memset(a4, 0, a5);
v9 = src;
if ( src )
{
strncpy((char *)a4, src, a5);
free(v9);
}
}
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2, const char *a3, void *a4, size_t a5, const char *a6)
{
int v8; // er12
char *v9; // r14
char *src; // [rsp+8h] [rbp-30h] BYREF

src = 0LL;
v8 = func10(a1, a2, a3, &src, a6);
if ( v8 >= 0 )
{
memset(a4, 0, a5);
v9 = src;
if ( src )
{
strncpy((char *)a4, src, a5);
free(v9);
}
}
return (unsigned int)v8;
}

original_code:
int cfg_read_strn(cfg_st *handler,
        char *section, char *name, char *value, size_t n, char *default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, default_value);
    if (ret < 0)
        return ret;
    memset(value, 0, n);
    if (s)
    {
        strncpy(value, s, n);
        free(s);
    }
    return ret;
}

canonical_original_code:
int cfg_read_strn(struct cfg_section *handler, char *section, char *name, char *value, unsigned long n, char *default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, default_value);
    if (ret < 0)
        return ret;
    memset(value, 0, n);
    if (s)
    {
        strncpy(value, s, n);
        free(s);
    }
    return ret;
}

variable_types:
value
char *

variable_types:
n
unsigned long

variable_types:
s
char *

variable_types: ret int


decompiled_code:
__int64 __fastcall cfg_read_int(__int64 a1, const char *a2, const char *a3, _DWORD *a4, int a5)
{
__int64 result; // rax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

result = ini_read_num_constprop_0(a1, a2, a3, v8);
if ( (_DWORD)result )
{
if ( (int)result > 0 )
*a4 = a5;
}
else
{
*a4 = v8[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, const char *a2, const char *a3, _DWORD *a4, int a5)
{
__int64 result; // rax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

result = func11(a1, a2, a3, v8);
if ( (_DWORD)result )
{
if ( (int)result > 0 )
*a4 = a5;
}
else
{
*a4 = v8[0];
}
return result;
}

original_code:
int cfg_read_int(cfg_st *handler,
        char *section, char *name, int *value, int default_value)
{
    do { long long int v; int ret = ini_read_num(handler, section, name, &v, 0); if (ret == 0) { *value = (int)v; } else if (ret > 0) { *value = default_value; } return ret; } while (0);
}

canonical_original_code:
int cfg_read_int(struct cfg_section *handler, char *section, char *name, int *value, int default_value)
{
    do { long long v; int ret = ini_read_num(handler, section, name, &v, 0); if (ret == 0) { *value = (int)v; } else if (ret > 0) { *value = default_value; } return ret; } while (0);
}

variable_types:
value
int *

variable_types:
v
long long


decompiled_code:
__int64 __fastcall cfg_read_float(__int64 a1, const char *a2, const char *a3, int *a4, __m128i a5)
{
int v5; // er14
__int64 result; // rax
float v8; // xmm0_4
char *v9; // rdi
char *nptr; // [rsp+Ch] [rbp-20h] BYREF

v5 = _mm_cvtsi128_si32(a5);
nptr = 0LL;
result = cfg_read_str(a1, a2, a3, &nptr, 0LL);
if ( (_DWORD)result )
{
if ( (int)result > 0 )
*a4 = v5;
}
else
{
v8 = strtof(nptr, 0LL);
v9 = nptr;
*(float *)a4 = v8;
free(v9);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, const char *a2, const char *a3, int *a4, __m128i a5)
{
int v5; // er14
__int64 result; // rax
float v8; // xmm0_4
char *v9; // rdi
char *nptr; // [rsp+Ch] [rbp-20h] BYREF

v5 = _mm_cvtsi128_si32(a5);
nptr = 0LL;
result = func10(a1, a2, a3, &nptr, 0LL);
if ( (_DWORD)result )
{
if ( (int)result > 0 )
*a4 = v5;
}
else
{
v8 = strtof(nptr, 0LL);
v9 = nptr;
*(float *)a4 = v8;
free(v9);
result = 0LL;
}
return result;
}

original_code:
int cfg_read_float(cfg_st *handler,
        char *section, char *name, float *value, float default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        *value = strtof(s, ((void *)0));
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

canonical_original_code:
int cfg_read_float(struct cfg_section *handler, char *section, char *name, float *value, float default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        *value = strtof(s, ((void *)0));
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

variable_types:
value
float *


decompiled_code:
__int64 __fastcall cfg_read_double(__int64 a1, const char *a2, const char *a3, double *a4, double a5)
{
__int64 result; // rax
double v7; // xmm0_8
char *v8; // rdi
char *nptr; // [rsp+Ch] [rbp-20h] BYREF

nptr = 0LL;
result = cfg_read_str(a1, a2, a3, &nptr, 0LL);
if ( (_DWORD)result )
{
if ( (int)result > 0 )
*a4 = a5;
}
else
{
v7 = strtod(nptr, 0LL);
v8 = nptr;
*a4 = v7;
free(v8);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, const char *a2, const char *a3, double *a4, double a5)
{
__int64 result; // rax
double v7; // xmm0_8
char *v8; // rdi
char *nptr; // [rsp+Ch] [rbp-20h] BYREF

nptr = 0LL;
result = func10(a1, a2, a3, &nptr, 0LL);
if ( (_DWORD)result )
{
if ( (int)result > 0 )
*a4 = a5;
}
else
{
v7 = strtod(nptr, 0LL);
v8 = nptr;
*a4 = v7;
free(v8);
result = 0LL;
}
return result;
}

original_code:
int cfg_read_double(cfg_st *handler,
        char *section, char *name, double *value, double default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        *value = strtod(s, ((void *)0));
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

canonical_original_code:
int cfg_read_double(struct cfg_section *handler, char *section, char *name, double *value, double default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        *value = strtod(s, ((void *)0));
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

variable_types:
value
double *


decompiled_code:
__int64 __fastcall cfg_read_ipv4_addr(__int64 a1, const char *a2, const char *a3, __int64 a4, const char *a5)
{
int v6; // er12
char *v7; // rdi
char *v8; // rbp
char *v9; // r13
__int16 v10; // ax
__int16 v11; // ax
char *v12; // rdi
char *s; // [rsp+8h] [rbp-30h] BYREF

s = 0LL;
v6 = cfg_read_str(a1, a2, a3, &s, a5);
if ( v6 >= 0 )
{
v7 = s;
*(_OWORD *)a4 = 0LL;
if ( v7 )
{
v8 = strtok(v7, ": \t");
if ( v8 && (v9 = strtok(0LL, ": \t")) != 0LL && (*(_WORD *)a4 = 2, inet_aton(v8, (struct in_addr *)(a4 + 4))) )
{
v10 = atoi(v9);
v11 = _bswap_16(v10);
v12 = s;
*(_WORD *)(a4 + 2) = v11;
free(v12);
}
else
{
v6 = -1;
free(s);
}
}
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, const char *a2, const char *a3, __int64 a4, const char *a5)
{
int v6; // er12
char *v7; // rdi
char *v8; // rbp
char *v9; // r13
__int16 v10; // ax
__int16 v11; // ax
char *v12; // rdi
char *s; // [rsp+8h] [rbp-30h] BYREF

s = 0LL;
v6 = func10(a1, a2, a3, &s, a5);
if ( v6 >= 0 )
{
v7 = s;
*(_OWORD *)a4 = 0LL;
if ( v7 )
{
v8 = strtok(v7, ": \t");
if ( v8 && (v9 = strtok(0LL, ": \t")) != 0LL && (*(_WORD *)a4 = 2, inet_aton(v8, (struct in_addr *)(a4 + 4))) )
{
v10 = atoi(v9);
v11 = func1(v10);
v12 = s;
*(_WORD *)(a4 + 2) = v11;
free(v12);
}
else
{
v6 = -1;
free(s);
}
}
}
return (unsigned int)v6;
}

original_code:
int cfg_read_ipv4_addr(cfg_st *handler,
        char *section, char *name, struct sockaddr_in *addr, char *default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, default_value);
    if (ret < 0)
        return ret;
    memset(addr, 0, sizeof(struct sockaddr_in));
    if (s)
    {
        char *ip = strtok(s, ": \t");
        if (ip == ((void *)0))
        {
            free(s);
            return -1;
        }
        char *port = strtok(((void *)0), ": \t");
        if (port == ((void *)0))
        {
            free(s);
            return -1;
        }
        addr->sin_family = 2;
        if (inet_aton(ip, &addr->sin_addr) == 0)
        {
            free(s);
            return -1;
        }
        addr->sin_port = htons((uint16_t)atoi(port));
        free(s);
    }
    return ret;
}

canonical_original_code:
int cfg_read_ipv4_addr(struct cfg_section *handler, char *section, char *name, struct sockaddr_in *addr, char *default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, default_value);
    if (ret < 0)
        return ret;
    memset(addr, 0, sizeof(struct sockaddr_in));
    if (s)
    {
        char *ip = strtok(s, ": \t");
        if (ip == ((void *)0))
        {
            free(s);
            return -1;
        }
        char *port = strtok(((void *)0), ": \t");
        if (port == ((void *)0))
        {
            free(s);
            return -1;
        }
        addr->sin_family = 2;
        if (inet_aton(ip, &addr->sin_addr) == 0)
        {
            free(s);
            return -1;
        }
        addr->sin_port = htons((unsigned short)atoi(port));
        free(s);
    }
    return ret;
}

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

variable_types:
ip
char *

variable_types:
port
char *

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 cfg_read_bool(__int64 a1, const char *a2, const char *a3, _BYTE *a4, char a5)
{
__int64 result; // rax
unsigned int v8; // er14
_BYTE *v9; // rbp
__int64 v10; // rbx
const __int32_t **v11; // rcx
__int64 v12; // rax
char *v13; // r8
void *ptr; // [rsp+8h] [rbp-30h] BYREF

ptr = 0LL;
LODWORD(result) = cfg_read_str(a1, a2, a3, (char **)&ptr, 0LL);
v8 = result;
if ( !(_DWORD)result )
{
v9 = ptr;
v10 = *(char *)ptr;
if ( (_BYTE)v10 )
{
v11 = _ctype_tolower_loc();
v12 = 1LL;
do
{
*v9 = (*v11)[v10];
v13 = (char *)ptr;
v9 = (char *)ptr + v12++;
v10 = (char)*v9;
}
while ( (_BYTE)v10 );
}
else
{
v13 = (char *)ptr;
}
if ( !strcmp(v13, "true") )
{
*a4 = 1;
}
else
{
if ( !strcmp(v13, "false") )
a5 = 0;
*a4 = a5;
}
free(v13);
return v8;
}
if ( (int)result <= 0 )
return v8;
*a4 = a5;
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, const char *a2, const char *a3, _BYTE *a4, char a5)
{
__int64 result; // rax
unsigned int v8; // er14
_BYTE *v9; // rbp
__int64 v10; // rbx
const __int32_t **v11; // rcx
__int64 v12; // rax
char *v13; // r8
void *ptr; // [rsp+8h] [rbp-30h] BYREF

ptr = 0LL;
LODWORD(result) = func10(a1, a2, a3, (char **)&ptr, 0LL);
v8 = result;
if ( !(_DWORD)result )
{
v9 = ptr;
v10 = *(char *)ptr;
if ( (_BYTE)v10 )
{
v11 = _ctype_tolower_loc();
v12 = 1LL;
do
{
*v9 = (*v11)[v10];
v13 = (char *)ptr;
v9 = (char *)ptr + v12++;
v10 = (char)*v9;
}
while ( (_BYTE)v10 );
}
else
{
v13 = (char *)ptr;
}
if ( !strcmp(v13, "true") )
{
*a4 = 1;
}
else
{
if ( !strcmp(v13, "false") )
a5 = 0;
*a4 = a5;
}
free(v13);
return v8;
}
if ( (int)result <= 0 )
return v8;
*a4 = a5;
return (unsigned int)result;
}

original_code:
int cfg_read_bool(cfg_st *handler,
        char *section, char *name, _Bool *value, _Bool default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        int i;
        for (i = 0; s[i]; ++i)
            s[i] = tolower(s[i]);
        if (strcmp(s, "true") == 0)
            *value = 1;
        else if (strcmp(s, "false") == 0)
            *value = 0;
        else
            *value = default_value;
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

canonical_original_code:
int cfg_read_bool(struct cfg_section *handler, char *section, char *name, _Bool *value, _Bool default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        int i;
        for (i = 0; s[i]; ++i)
            s[i] = tolower(s[i]);
        if (strcmp(s, "true") == 0)
            *value = 1;
        else if (strcmp(s, "false") == 0)
            *value = 0;
        else
            *value = default_value;
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

variable_types:
value
_Bool *

variable_types: i int


decompiled_code:
void __fastcall __noreturn thread_routine(void *a1)
{
pthread_mutex_t *v1; // r12
void *v2; // rbp
__int64 v3; // rax

v1 = (pthread_mutex_t *)((char *)a1 + 32);
while ( 1 )
{
pthread_mutex_lock(v1);
v2 = (void *)*((_QWORD *)a1 + 3);
if ( !v2 )
break;
LABEL_7:
if ( *(_DWORD *)a1 )
goto LABEL_6;
v3 = *((_QWORD *)v2 + 2);
*((_QWORD *)a1 + 3) = v3;
if ( !v3 )
pthread_cond_signal((pthread_cond_t *)((char *)a1 + 120));
pthread_mutex_unlock(v1);
(*(void (__fastcall **)(_QWORD))v2)(*((_QWORD *)v2 + 1));
free(*((void **)v2 + 1));
free(v2);
}
while ( !*(_DWORD *)a1 )
{
pthread_cond_wait((pthread_cond_t *)((char *)a1 + 72), v1);
v2 = (void *)*((_QWORD *)a1 + 3);
if ( v2 )
goto LABEL_7;
}
LABEL_6:
pthread_mutex_unlock(v1);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
pthread_mutex_t *v1; // r12
void *v2; // rbp
__int64 v3; // rax

v1 = (pthread_mutex_t *)((char *)a1 + 32);
while ( 1 )
{
pthread_mutex_lock(v1);
v2 = (void *)*((_QWORD *)a1 + 3);
if ( !v2 )
break;
LABEL_7:
if ( *(_DWORD *)a1 )
goto LABEL_6;
v3 = *((_QWORD *)v2 + 2);
*((_QWORD *)a1 + 3) = v3;
if ( !v3 )
pthread_cond_signal((pthread_cond_t *)((char *)a1 + 120));
pthread_mutex_unlock(v1);
(*(void (__fastcall **)(_QWORD))v2)(*((_QWORD *)v2 + 1));
free(*((void **)v2 + 1));
free(v2);
}
while ( !*(_DWORD *)a1 )
{
pthread_cond_wait((pthread_cond_t *)((char *)a1 + 72), v1);
v2 = (void *)*((_QWORD *)a1 + 3);
if ( v2 )
goto LABEL_7;
}
LABEL_6:
pthread_mutex_unlock(v1);
pthread_exit(0LL);
}

original_code:
static void*
thread_routine(void *arg)
{
    tpool_t *tpool = (tpool_t *)arg;
    tpool_work_t *work;
    while(1) {
        pthread_mutex_lock(&tpool->queue_lock);
        while(!tpool->queue_head && !tpool->shutdown)
        {
            pthread_cond_wait(&tpool->queue_ready, &tpool->queue_lock);
        }
        if (tpool->shutdown) {
            pthread_mutex_unlock(&tpool->queue_lock);
            pthread_exit(((void *)0));
        }
        work = tpool->queue_head;
        tpool->queue_head = tpool->queue_head->next;
        if (!tpool->queue_head)
        {
          pthread_cond_signal(&tpool->queue_empty);
        }
        pthread_mutex_unlock(&tpool->queue_lock);
        work->routine(work->arg);
        free(work->arg);
        free(work);
    }
    return ((void *)0);
}

canonical_original_code:
static void *thread_routine(void *arg)
{
    struct tpool *tpool = (tpool_t *)arg;
    struct tpool_work *work;
    while(1) {
        pthread_mutex_lock(&tpool->queue_lock);
        while(!tpool->queue_head && !tpool->shutdown)
        {
            pthread_cond_wait(&tpool->queue_ready, &tpool->queue_lock);
        }
        if (tpool->shutdown) {
            pthread_mutex_unlock(&tpool->queue_lock);
            pthread_exit(((void *)0));
        }
        work = tpool->queue_head;
        tpool->queue_head = tpool->queue_head->next;
        if (!tpool->queue_head)
        {
          pthread_cond_signal(&tpool->queue_empty);
        }
        pthread_mutex_unlock(&tpool->queue_lock);
        work->routine(work->arg);
        free(work->arg);
        free(work);
    }
    return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct tpool { int shutdown; int list_close; int max_thr_num; unsigned long *thr_id; struct tpool_work { void *(*routine)(void *); void *arg; struct tpool_work *next; } *queue_head; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } queue_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } queue_ready; union pthread_cond_t queue_empty; } *

return_type: void *

user_defined_types: struct tpool { int shutdown; int list_close; int max_thr_num; unsigned long *thr_id; struct tpool_work *queue_head; union pthread_mutex_t queue_lock; union pthread_cond_t queue_ready; union pthread_cond_t queue_empty; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall tpool_create(_QWORD *a1, int a2)
{
char *v3; // rax
char *v4; // rbp
char *v5; // rax
char *v6; // rdi
__int64 i; // rbx
int *v9; // rbx
char *v10; // rax
int *v11; // rbx
char *v12; // rax
int *v13; // rbx
char *v14; // rax
int *v15; // rbx
char *v16; // rax

v3 = (char *)calloc(1uLL, 0xA8uLL);
if ( !v3 )
goto LABEL_16;
*((_DWORD *)v3 + 2) = a2;
v4 = v3;
*(_QWORD *)v3 = 0LL;
*((_QWORD *)v3 + 3) = 0LL;
if ( pthread_mutex_init((pthread_mutex_t *)(v3 + 32), 0LL) )
{
v15 = _errno_location();
v16 = strerror(*v15);
printf("%s: pthread_mutex_init failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v15, v16);
exit(1);
}
if ( pthread_cond_init((pthread_cond_t *)(v4 + 72), 0LL) )
{
v13 = _errno_location();
v14 = strerror(*v13);
printf("%s: pthread_cond_init failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v13, v14);
exit(1);
}
if ( pthread_cond_init((pthread_cond_t *)(v4 + 120), 0LL) )
{
v11 = _errno_location();
v12 = strerror(*v11);
printf("%s: pthread_cond_init2 failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v11, v12);
exit(1);
}
v5 = (char *)calloc(a2, 8uLL);
*((_QWORD *)v4 + 2) = v5;
v6 = v5;
if ( !v5 )
{
LABEL_16:
printf("%s: calloc failed\n", "tpool_create");
exit(1);
}
if ( a2 > 0 )
{
for ( i = 0LL; ; i += 8LL )
{
if ( pthread_create((pthread_t *)&v6[i], 0LL, (void *(*)(void *))thread_routine, v4) )
{
v9 = _errno_location();
v10 = strerror(*v9);
printf("%s:pthread_create failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v9, v10);
exit(1);
}
if ( 8LL * (unsigned int)(a2 - 1) == i )
break;
v6 = (char *)*((_QWORD *)v4 + 2);
}
}
*a1 = v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2)
{
char *v3; // rax
char *v4; // rbp
char *v5; // rax
char *v6; // rdi
__int64 i; // rbx
int *v9; // rbx
char *v10; // rax
int *v11; // rbx
char *v12; // rax
int *v13; // rbx
char *v14; // rax
int *v15; // rbx
char *v16; // rax

v3 = (char *)calloc(1uLL, 0xA8uLL);
if ( !v3 )
goto LABEL_16;
*((_DWORD *)v3 + 2) = a2;
v4 = v3;
*(_QWORD *)v3 = 0LL;
*((_QWORD *)v3 + 3) = 0LL;
if ( pthread_mutex_init((pthread_mutex_t *)(v3 + 32), 0LL) )
{
v15 = _errno_location();
v16 = strerror(*v15);
printf("%s: pthread_mutex_init failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v15, v16);
exit(1);
}
if ( pthread_cond_init((pthread_cond_t *)(v4 + 72), 0LL) )
{
v13 = _errno_location();
v14 = strerror(*v13);
printf("%s: pthread_cond_init failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v13, v14);
exit(1);
}
if ( pthread_cond_init((pthread_cond_t *)(v4 + 120), 0LL) )
{
v11 = _errno_location();
v12 = strerror(*v11);
printf("%s: pthread_cond_init2 failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v11, v12);
exit(1);
}
v5 = (char *)calloc(a2, 8uLL);
*((_QWORD *)v4 + 2) = v5;
v6 = v5;
if ( !v5 )
{
LABEL_16:
printf("%s: calloc failed\n", "tpool_create");
exit(1);
}
if ( a2 > 0 )
{
for ( i = 0LL; ; i += 8LL )
{
if ( pthread_create((pthread_t *)&v6[i], 0LL, (void *(*)(void *))thread_routine, v4) )
{
v9 = _errno_location();
v10 = strerror(*v9);
printf("%s:pthread_create failed, errno:%d, error:%s\n", "tpool_create", (unsigned int)*v9, v10);
exit(1);
}
if ( 8LL * (unsigned int)(a2 - 1) == i )
break;
v6 = (char *)*((_QWORD *)v4 + 2);
}
}
*a1 = v4;
return 0LL;
}

original_code:
int
tpool_create(tpool_t **ppTpool, int max_thr_num)
{
    int i;
    tpool_t *tpool = ((void *)0);
    tpool = calloc(1, sizeof(tpool_t));
    if (!tpool) {
        printf("%s: calloc failed\n", __FUNCTION__);
        exit(1);
    }
    tpool->max_thr_num = max_thr_num;
    tpool->shutdown = 0;
    tpool->list_close = 0;
    tpool->queue_head = ((void *)0);
    if (pthread_mutex_init(&tpool->queue_lock, ((void *)0)) !=0) {
        printf("%s: pthread_mutex_init failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    if (pthread_cond_init(&tpool->queue_ready, ((void *)0)) !=0 ) {
        printf("%s: pthread_cond_init failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    if (pthread_cond_init(&tpool->queue_empty, ((void *)0)) !=0 ) {
        printf("%s: pthread_cond_init2 failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    tpool->thr_id = calloc(max_thr_num, sizeof(pthread_t));
    if (!tpool->thr_id) {
        printf("%s: calloc failed\n", __FUNCTION__);
        exit(1);
    }
    for (i = 0; i < max_thr_num; ++i) {
        if (pthread_create(&tpool->thr_id[i], ((void *)0), thread_routine, (void*)tpool) != 0){
            printf("%s:pthread_create failed, errno:%d, error:%s\n", __FUNCTION__,
                (*__errno_location ()), strerror((*__errno_location ())));
            exit(1);
        }
    }
    *ppTpool = tpool;
    return 0;
}

canonical_original_code:
int tpool_create(struct tpool **ppTpool, int max_thr_num)
{
    int i;
    struct tpool *tpool = ((void *)0);
    tpool = calloc(1, sizeof(tpool_t));
    if (!tpool) {
        printf("%s: calloc failed\n", __FUNCTION__);
        exit(1);
    }
    tpool->max_thr_num = max_thr_num;
    tpool->shutdown = 0;
    tpool->list_close = 0;
    tpool->queue_head = ((void *)0);
    if (pthread_mutex_init(&tpool->queue_lock, ((void *)0)) !=0) {
        printf("%s: pthread_mutex_init failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    if (pthread_cond_init(&tpool->queue_ready, ((void *)0)) !=0 ) {
        printf("%s: pthread_cond_init failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    if (pthread_cond_init(&tpool->queue_empty, ((void *)0)) !=0 ) {
        printf("%s: pthread_cond_init2 failed, errno:%d, error:%s\n",
            __FUNCTION__, (*__errno_location ()), strerror((*__errno_location ())));
        exit(1);
    }
    tpool->thr_id = calloc(max_thr_num, sizeof(pthread_t));
    if (!tpool->thr_id) {
        printf("%s: calloc failed\n", __FUNCTION__);
        exit(1);
    }
    for (i = 0; i < max_thr_num; ++i) {
        if (pthread_create(&tpool->thr_id[i], ((void *)0), thread_routine, (void *)tpool) != 0){
            printf("%s:pthread_create failed, errno:%d, error:%s\n", __FUNCTION__,
                (*__errno_location ()), strerror((*__errno_location ())));
            exit(1);
        }
    }
    *ppTpool = tpool;
    return 0;
}

variable_types: struct tpool { int shutdown; int list_close; int max_thr_num; unsigned long *thr_id; struct tpool_work { void *(*routine)(void *); void *arg; struct tpool_work *next; } *queue_head; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } queue_lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } queue_ready; union pthread_cond_t queue_empty; } **


decompiled_code:
void __fastcall tpool_destroy(void *ptr, int a2)
{
pthread_mutex_t *v2; // r13
__int64 v4; // r12
pthread_t v5; // rdi
_QWORD *i; // r12
void *v7; // rdi

if ( !*((_DWORD *)ptr + 1) )
{
v2 = (pthread_mutex_t *)((char *)ptr + 32);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 32));
*((_DWORD *)ptr + 1) = 1;
if ( a2 && *((_QWORD *)ptr + 3) )
pthread_cond_wait((pthread_cond_t *)((char *)ptr + 120), v2);
*(_DWORD *)ptr = 1;
pthread_cond_broadcast((pthread_cond_t *)((char *)ptr + 72));
pthread_mutex_unlock(v2);
if ( *((int *)ptr + 2) > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)ptr + 2) + 8 * v4++);
pthread_join(v5, 0LL);
}
while ( *((_DWORD *)ptr + 2) > (int)v4 );
}
free(*((void **)ptr + 2));
for ( i = (_QWORD *)*((_QWORD *)ptr + 3); i; i = (_QWORD *)*((_QWORD *)ptr + 3) )
{
v7 = (void *)i[1];
*((_QWORD *)ptr + 3) = i[2];
free(v7);
free(i);
}
pthread_mutex_destroy(v2);
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 72));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr, int a2)
{
pthread_mutex_t *v2; // r13
__int64 v4; // r12
pthread_t v5; // rdi
_QWORD *i; // r12
void *v7; // rdi

if ( !*((_DWORD *)ptr + 1) )
{
v2 = (pthread_mutex_t *)((char *)ptr + 32);
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 32));
*((_DWORD *)ptr + 1) = 1;
if ( a2 && *((_QWORD *)ptr + 3) )
pthread_cond_wait((pthread_cond_t *)((char *)ptr + 120), v2);
*(_DWORD *)ptr = 1;
pthread_cond_broadcast((pthread_cond_t *)((char *)ptr + 72));
pthread_mutex_unlock(v2);
if ( *((int *)ptr + 2) > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)ptr + 2) + 8 * v4++);
pthread_join(v5, 0LL);
}
while ( *((_DWORD *)ptr + 2) > (int)v4 );
}
free(*((void **)ptr + 2));
for ( i = (_QWORD *)*((_QWORD *)ptr + 3); i; i = (_QWORD *)*((_QWORD *)ptr + 3) )
{
v7 = (void *)i[1];
*((_QWORD *)ptr + 3) = i[2];
free(v7);
free(i);
}
pthread_mutex_destroy(v2);
pthread_cond_destroy((pthread_cond_t *)((char *)ptr + 72));
free(ptr);
}
}

original_code:
void
tpool_destroy(tpool_t *tpool,int flag)
{
    int i;
    tpool_work_t *member;
    if (tpool->list_close) {
        return;
    }
    pthread_mutex_lock(&tpool->queue_lock);
    tpool->list_close =1;
    if (flag)
    {
      if (tpool->queue_head)
      {
        pthread_cond_wait(&tpool->queue_empty, &tpool->queue_lock);
      }
    }
    tpool->shutdown = 1;
    pthread_cond_broadcast(&tpool->queue_ready);
    pthread_mutex_unlock(&tpool->queue_lock);
    for (i = 0; i < tpool->max_thr_num; ++i) {
        pthread_join(tpool->thr_id[i], ((void *)0));
    }
    free(tpool->thr_id);
    while(tpool->queue_head) {
        member = tpool->queue_head;
        tpool->queue_head = tpool->queue_head->next;
        free(member->arg);
        free(member);
    }
    pthread_mutex_destroy(&tpool->queue_lock);
    pthread_cond_destroy(&tpool->queue_ready);
    free(tpool);
}

canonical_original_code:
void tpool_destroy(struct tpool *tpool, int flag)
{
    int i;
    struct tpool_work *member;
    if (tpool->list_close) {
        return;
    }
    pthread_mutex_lock(&tpool->queue_lock);
    tpool->list_close =1;
    if (flag)
    {
      if (tpool->queue_head)
      {
        pthread_cond_wait(&tpool->queue_empty, &tpool->queue_lock);
      }
    }
    tpool->shutdown = 1;
    pthread_cond_broadcast(&tpool->queue_ready);
    pthread_mutex_unlock(&tpool->queue_lock);
    for (i = 0; i < tpool->max_thr_num; ++i) {
        pthread_join(tpool->thr_id[i], ((void *)0));
    }
    free(tpool->thr_id);
    while(tpool->queue_head) {
        member = tpool->queue_head;
        tpool->queue_head = tpool->queue_head->next;
        free(member->arg);
        free(member);
    }
    pthread_mutex_destroy(&tpool->queue_lock);
    pthread_cond_destroy(&tpool->queue_ready);
    free(tpool);
}

variable_types: flag int

variable_types: struct tpool_work { void *(*routine)(void *); void *arg; struct tpool_work *next; } *

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall tpool_add_work(__int64 a1, __int64 a2, const void *a3, int a4)
{
size_t v5; // r12
_QWORD *v6; // rax
_QWORD *v7; // rbp
void *v8; // rax
unsigned int v9; // er12
__int64 v10; // rax
__int64 v11; // rdx

if ( !a2 )
{
v9 = -1;
printf("%s:Invalid argument\n", "tpool_add_work");
return v9;
}
v5 = a4;
v6 = malloc(0x18uLL);
v7 = v6;
if ( !v6 )
{
v9 = -1;
printf("%s:malloc failed\n", "tpool_add_work");
return v9;
}
*v6 = a2;
v8 = malloc(v5);
v7[1] = v8;
if ( !v8 )
return 0;
memcpy(v8, a3, v5);
v7[2] = 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v9 = *(_DWORD *)(a1 + 4);
if ( !v9 )
{
v10 = *(_QWORD *)(a1 + 24);
if ( v10 )
{
do
{
v11 = v10;
v10 = *(_QWORD *)(v10 + 16);
}
while ( v10 );
*(_QWORD *)(v11 + 16) = v7;
}
else
{
*(_QWORD *)(a1 + 24) = v7;
}
pthread_cond_signal((pthread_cond_t *)(a1 + 72));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v9;
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, const void *a3, int a4)
{
size_t v5; // r12
_QWORD *v6; // rax
_QWORD *v7; // rbp
void *v8; // rax
unsigned int v9; // er12
__int64 v10; // rax
__int64 v11; // rdx

if ( !a2 )
{
v9 = -1;
printf("%s:Invalid argument\n", "tpool_add_work");
return v9;
}
v5 = a4;
v6 = malloc(0x18uLL);
v7 = v6;
if ( !v6 )
{
v9 = -1;
printf("%s:malloc failed\n", "tpool_add_work");
return v9;
}
*v6 = a2;
v8 = malloc(v5);
v7[1] = v8;
if ( !v8 )
return 0;
memcpy(v8, a3, v5);
v7[2] = 0LL;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 32));
v9 = *(_DWORD *)(a1 + 4);
if ( !v9 )
{
v10 = *(_QWORD *)(a1 + 24);
if ( v10 )
{
do
{
v11 = v10;
v10 = *(_QWORD *)(v10 + 16);
}
while ( v10 );
*(_QWORD *)(v11 + 16) = v7;
}
else
{
*(_QWORD *)(a1 + 24) = v7;
}
pthread_cond_signal((pthread_cond_t *)(a1 + 72));
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return v9;
}
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 32));
return 0LL;
}

original_code:
int
tpool_add_work(tpool_t *tpool, void*(*routine)(void*), void *arg, int len)
{
    tpool_work_t *work, *member;
    if (!routine){
        printf("%s:Invalid argument\n", __FUNCTION__);
        return -1;
    }
    work = malloc(sizeof(tpool_work_t));
    if (!work) {
        printf("%s:malloc failed\n", __FUNCTION__);
        return -1;
    }
    work->routine = routine;
    work->arg = (void*)malloc(len);
    if (!work->arg) return 0;
    memcpy(work->arg, arg, len);
    work->next = ((void *)0);
    pthread_mutex_lock(&tpool->queue_lock);
    if (tpool->list_close)
    {
      pthread_mutex_unlock(&tpool->queue_lock);
      return 0;
    }
    member = tpool->queue_head;
    if (!member) {
        tpool->queue_head = work;
    } else {
        while(member->next) {
            member = member->next;
        }
        member->next = work;
    }
    pthread_cond_signal(&tpool->queue_ready);
    pthread_mutex_unlock(&tpool->queue_lock);
    return 0;
}

canonical_original_code:
int tpool_add_work(struct tpool *tpool, void *(*routine)(void *), void *arg, int len)
{
    struct tpool_work *work; struct tpool_work *member;
    if (!routine){
        printf("%s:Invalid argument\n", __FUNCTION__);
        return -1;
    }
    work = malloc(sizeof(tpool_work_t));
    if (!work) {
        printf("%s:malloc failed\n", __FUNCTION__);
        return -1;
    }
    work->routine = routine;
    work->arg = (void *)malloc(len);
    if (!work->arg) return 0;
    memcpy(work->arg, arg, len);
    work->next = ((void *)0);
    pthread_mutex_lock(&tpool->queue_lock);
    if (tpool->list_close)
    {
      pthread_mutex_unlock(&tpool->queue_lock);
      return 0;
    }
    member = tpool->queue_head;
    if (!member) {
        tpool->queue_head = work;
    } else {
        while(member->next) {
            member = member->next;
        }
        member->next = work;
    }
    pthread_cond_signal(&tpool->queue_ready);
    pthread_mutex_unlock(&tpool->queue_lock);
    return 0;
}

variable_types:
routine
void *(*)(void *)

variable_types: len int

user_defined_types: struct tpool_work { void *(*routine)(void *); void *arg; struct tpool_work *next; }


getTcpConSoc

decompiled_code:
__int64 __fastcall getTcpConSoc(__int64 a1, __int16 a2)
{
const char *v2; // r8
int v3; // eax
unsigned int v4; // er12
__int64 result; // rax
int v6; // edi
struct sockaddr v7; // [rsp+0h] [rbp-18h] BYREF

v7 = 0LL;
v7.sa_family = 2;
*(_WORD *)v7.sa_data = _bswap_16(a2);
*(_DWORD *)&v7.sa_data[2] = inet_addr(v2);
v3 = socket(2, 1, 0);
v4 = v3;
if ( v3 < 0 )
{
perror("create\n");
result = v4;
}
else
{
if ( connect(v3, &v7, 0x10u) < 0 )
{
perror("connect\n");
v6 = v4;
v4 = -1;
close(v6);
}
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int16 a2)
{
const char *v2; // r8
int v3; // eax
unsigned int v4; // er12
__int64 result; // rax
int v6; // edi
struct sockaddr v7; // [rsp+0h] [rbp-18h] BYREF

v7 = 0LL;
v7.sa_family = 2;
*(_WORD *)v7.sa_data = func0(a2);
*(_DWORD *)&v7.sa_data[2] = inet_addr(v2);
v3 = socket(2, 1, 0);
v4 = v3;
if ( v3 < 0 )
{
perror("create\n");
result = v4;
}
else
{
if ( connect(v3, &v7, 0x10u) < 0 )
{
perror("connect\n");
v6 = v4;
v4 = -1;
close(v6);
}
result = v4;
}
return result;
}

original_code:
int getTcpConSoc(char *serverIp, int port)
{
  struct sockaddr_in client_addr;
  bzero(&client_addr, sizeof(client_addr));
  client_addr.sin_family = 2;
  client_addr.sin_port = htons(port);
  client_addr.sin_addr.s_addr = inet_addr(serverIp);
  int soc = -1;
  if((soc = socket(2,SOCK_STREAM,0)) < 0)
  {
    perror("create\n");
    return soc;
  }
  if(connect(soc,(struct sockaddr *)&client_addr,sizeof(client_addr)) < 0)
  {
    perror("connect\n");
    close(soc);
    return -1;
  }
  return soc;
}

variable_types:
serverIp
char *

variable_types: port int

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

variable_types: soc int

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


clsSoc

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

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

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

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

original_code:
void clsSoc(int soc)
{
  if (soc > 0)
  {
    close(soc);
  }
}


sendCmdStr

decompiled_code:
__int64 __fastcall sendCmdStr(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
if ( send(fd, buf, v2 + 1, 0) >= 0 )
return 0LL;
perror("send");
return 4294967197LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
if ( send(fd, buf, v2 + 1, 0) >= 0 )
return 0LL;
perror("send");
return 4294967197LL;
}

original_code:
int sendCmdStr(int soc, char *sdCmd)
{
  if(send(soc,sdCmd,strlen(sdCmd)+1,0) < 0)
  {
    perror("send");
    return -99;
  }
  return 0;
}

variable_types:
sdCmd
char *


recvInfoStr

decompiled_code:
__int64 __fastcall recvInfoStr(int fd, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // r15
int v5; // ebx
int v6; // eax
int v7; // eax
unsigned int v9; // [rsp+0h] [rbp-8D8h]
int v10; // [rsp+4h] [rbp-8D4h]
struct timeval timeout; // [rsp+10h] [rbp-8C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-8B8h] BYREF
__int128 buf; // [rsp+A0h] [rbp-838h] BYREF
char v14[1008]; // [rsp+B0h] [rbp-828h] BYREF
char src[16]; // [rsp+4A0h] [rbp-438h] BYREF
char v16[1008]; // [rsp+4B0h] [rbp-428h] BYREF

timeout.tv_sec = 80LL;
timeout.tv_usec = 50LL;
memset(&readfds, 0, sizeof(readfds));
v3 = fd / 64;
v4 = 1LL << (fd % 64);
readfds.fds_bits[v3] |= v4;
if ( !a3 )
return 0;
v9 = 0;
v5 = a3;
while ( 1 )
{
while ( 1 )
{
v6 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( v6 == -1 )
{
perror("select.");
return (unsigned int)-1;
}
if ( !v6 )
{
sendCmdStr(fd, "LT");
goto LABEL_3;
}
if ( (readfds.fds_bits[v3] & v4) != 0 )
break;
LABEL_3:
if ( !--v5 )
return v9;
}
memset(v14, 0, sizeof(v14));
buf = 0LL;
v7 = recv(fd, &buf, 0x400uLL, 0);
if ( v7 < 0 )
{
perror("recv.");
return (unsigned int)-1;
}
if ( !v7 )
break;
*(_OWORD *)src = 0LL;
memset(v16, 0, sizeof(v16));
v10 = v7 - 6;
strncpy((char *)(a2 + (int)v9), src, v7 - 6);
v9 += v10;
timeout.tv_sec /= 2LL;
if ( !--v5 )
return v9;
}
perror("recv connect err");
return (unsigned int)-99;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 a2, int a3)
{
__int64 v3; // rbp
__int64 v4; // r15
int v5; // ebx
int v6; // eax
int v7; // eax
unsigned int v9; // [rsp+0h] [rbp-8D8h]
int v10; // [rsp+4h] [rbp-8D4h]
struct timeval timeout; // [rsp+10h] [rbp-8C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-8B8h] BYREF
__int128 buf; // [rsp+A0h] [rbp-838h] BYREF
char v14[1008]; // [rsp+B0h] [rbp-828h] BYREF
char src[16]; // [rsp+4A0h] [rbp-438h] BYREF
char v16[1008]; // [rsp+4B0h] [rbp-428h] BYREF

timeout.tv_sec = 80LL;
timeout.tv_usec = 50LL;
memset(&readfds, 0, sizeof(readfds));
v3 = fd / 64;
v4 = 1LL << (fd % 64);
readfds.fds_bits[v3] |= v4;
if ( !a3 )
return 0;
v9 = 0;
v5 = a3;
while ( 1 )
{
while ( 1 )
{
v6 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
if ( v6 == -1 )
{
perror("select.");
return (unsigned int)-1;
}
if ( !v6 )
{
func3(fd, "LT");
goto LABEL_3;
}
if ( (readfds.fds_bits[v3] & v4) != 0 )
break;
LABEL_3:
if ( !--v5 )
return v9;
}
memset(v14, 0, sizeof(v14));
buf = 0LL;
v7 = recv(fd, &buf, 0x400uLL, 0);
if ( v7 < 0 )
{
perror("recv.");
return (unsigned int)-1;
}
if ( !v7 )
break;
*(_OWORD *)src = 0LL;
memset(v16, 0, sizeof(v16));
v10 = v7 - 6;
strncpy((char *)(a2 + (int)v9), src, v7 - 6);
v9 += v10;
timeout.tv_sec /= 2LL;
if ( !--v5 )
return v9;
}
perror("recv connect err");
return (unsigned int)-99;
}

original_code:
int recvInfoStr(int soc, char *recBuf, int iDftRdCt)
{
  struct timeval timeout;
  timeout.tv_sec = 80;
  timeout.tv_usec = 50;
  fd_set read_fds;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&read_fds)->__fds_bits)[((soc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((soc) % (8 * (int) sizeof (__fd_mask)))))));
  int iLen = 0;
  while(iDftRdCt--)
  {
    int iSelRet = select(soc+1,&read_fds,((void *)0),((void *)0),&timeout);
    if (-1 == iSelRet)
    {
      perror("select.");
      return -1;
    }
    else if (0 == iSelRet)
    {
      sendCmdStr(soc, "LT");
      continue;
    }
    else
    {
      if (((((&read_fds)->__fds_bits)[((soc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((soc) % (8 * (int) sizeof (__fd_mask)))))) != 0))
      {
        char strRecvInfo[1024] = {0};
        int iRecRet = recv(soc,strRecvInfo,sizeof(strRecvInfo),0);
        if(iRecRet < 0)
        {
          perror("recv.");
          return -1;
        }
        if (iRecRet == 0)
        {
          perror("recv connect err");
          return -99;
        }
        char strJmInfo[1024] = {0};
        iRecRet -= 6;
        if (0 == strncmp("LT",strJmInfo, 2))
        {
          sendCmdStr(soc, "LT");
          continue;
        }
        strncpy(recBuf+iLen, strJmInfo, iRecRet);
        iLen += iRecRet;
        timeout.tv_sec /= 2;
      }
    }
  }
  return iLen;
}

canonical_original_code:
int recvInfoStr(int soc, char *recBuf, int iDftRdCt)
{
  struct timeval timeout;
  timeout.tv_sec = 80;
  timeout.tv_usec = 50;
  struct fd_set read_fds;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&read_fds)->__fds_bits)[((soc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((soc) % (8 * (int) sizeof (__fd_mask)))))));
  int iLen = 0;
  while(iDftRdCt--)
  {
    int iSelRet = select(soc+1,&read_fds,((void *)0),((void *)0),&timeout);
    if (-1 == iSelRet)
    {
      perror("select.");
      return -1;
    }
    else if (0 == iSelRet)
    {
      sendCmdStr(soc, "LT");
      continue;
    }
    else
    {
      if (((((&read_fds)->__fds_bits)[((soc) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((soc) % (8 * (int) sizeof (__fd_mask)))))) != 0))
      {
        char strRecvInfo[1024] = {0};
        int iRecRet = recv(soc,strRecvInfo,sizeof(strRecvInfo),0);
        if(iRecRet < 0)
        {
          perror("recv.");
          return -1;
        }
        if (iRecRet == 0)
        {
          perror("recv connect err");
          return -99;
        }
        char strJmInfo[1024] = {0};
        iRecRet -= 6;
        if (0 == strncmp("LT",strJmInfo, 2))
        {
          sendCmdStr(soc, "LT");
          continue;
        }
        strncpy(recBuf+iLen, strJmInfo, iRecRet);
        iLen += iRecRet;
        timeout.tv_sec /= 2;
      }
    }
  }
  return iLen;
}

variable_types:
recBuf
char *

variable_types: iDftRdCt int

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

variable_types: iLen int

variable_types: iSelRet int

variable_types:
strRecvInfo
char [1024]

variable_types: iRecRet int

variable_types:
strJmInfo
char [1024]


pstrchr

decompiled_code:
void __fastcall pstrchr(const char *a1, char a2, int a3, char *a4)
{
char *v6; // rax
int v7; // er13

if ( a1 )
{
v6 = strchr(a1, a2);
if ( v6 )
{
if ( a3 <= 1 )
{
LABEL_8:
strcpy(a4, v6);
}
else
{
v7 = 1;
while ( 1 )
{
v6 = strchr(v6 + 1, a2);
if ( !v6 )
break;
if ( a3 == ++v7 )
goto LABEL_8;
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(const char *a1, char a2, int a3, char *a4)
{
char *v6; // rax
int v7; // er13

if ( a1 )
{
v6 = strchr(a1, a2);
if ( v6 )
{
if ( a3 <= 1 )
{
LABEL_8:
strcpy(a4, v6);
}
else
{
v7 = 1;
while ( 1 )
{
v6 = strchr(v6 + 1, a2);
if ( !v6 )
break;
if ( a3 == ++v7 )
goto LABEL_8;
}
}
}
}
}

original_code:
static void pstrchr( char * str, char ch, int n, char * p )
{
  char * tmp = ((void *)0);
  int i = 0;
  int k = 0;
  if(!str) return;
  tmp = strchr(str, ch);
  if( !tmp ) return;
  i++;
  for(k=i; k<n; k++)
  {
    tmp = strchr(tmp+1, ch);
    if(!tmp)
    {
      return;
    }
  }
  strcpy(p, tmp);
}

canonical_original_code:
static void pstrchr(char *str, char ch, int n, char *p)
{
  char *tmp = ((void *)0);
  int i = 0;
  int k = 0;
  if(!str) return;
  tmp = strchr(str, ch);
  if( !tmp ) return;
  i++;
  for(k=i; k<n; k++)
  {
    tmp = strchr(tmp+1, ch);
    if(!tmp)
    {
      return;
    }
  }
  strcpy(p, tmp);
}

variable_types:
str
char *

variable_types: ch char

variable_types: n int

variable_types:
p
char *

variable_types:
tmp
char *

variable_types: i int

variable_types: k int


daemonInit

decompiled_code:
int daemonInit()
{
if ( fork() > 0 || (sleep(1u), setsid(), signal(1, (__sighandler_t)((char *)pstrchr + 1)), fork() > 0) )
exit(0);
sleep(1u);
close(0);
close(1);
return close(2);
}

canonical_decompiled_code:
int func1()
{
if ( fork() > 0 || (sleep(1u), setsid(), signal(1, (__sighandler_t)((char *)pstrchr + 1)), fork() > 0) )
exit(0);
sleep(1u);
close(0);
close(1);
return close(2);
}

original_code:
void daemonInit(void)
{
  int i;
  if(fork() > 0) exit(0);
  sleep(1);
  setsid();
  signal(1,((__sighandler_t) 1));
  if(fork() > 0) exit(0);
  sleep(1);
  for(i = 0; i < 3; i++)
  {
    close(i);
  }
}

canonical_original_code:
void daemonInit()
{
  int i;
  if(fork() > 0) exit(0);
  sleep(1);
  setsid();
  signal(1,((void (*)(int)) 1));
  if(fork() > 0) exit(0);
  sleep(1);
  for(i = 0; i < 3; i++)
  {
    close(i);
  }
}


isNumber

decompiled_code:
__int64 __fastcall isNumber(const char *a1)
{
const char *v1; // rbx
char *v2; // rbp
const unsigned __int16 **v3; // rax
__int64 v4; // rdx

if ( !a1 )
return 0LL;
v1 = a1;
v2 = (char *)&a1[strlen(a1)];
do
{
if ( v1 == v2 )
return 1LL;
v3 = _ctype_b_loc();
v4 = *v1++;
}
while ( ((*v3)[v4] & 0x800) != 0 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
const char *v1; // rbx
char *v2; // rbp
const unsigned __int16 **v3; // rax
__int64 v4; // rdx

if ( !a1 )
return 0LL;
v1 = a1;
v2 = (char *)&a1[strlen(a1)];
do
{
if ( v1 == v2 )
return 1LL;
v3 = _ctype_b_loc();
v4 = *v1++;
}
while ( ((*v3)[v4] & 0x800) != 0 );
return 0LL;
}

original_code:
int isNumber(char * sNumber)
{
  if (!sNumber) return 0;
  int i;
  for(i=0; i<strlen(sNumber); ++i)
  {
    if(0 == ((*__ctype_b_loc ())[(int) ((sNumber[i]))] & (unsigned short int) _ISdigit))
    {
      return 0;
    }
  }
  return 1;
}

canonical_original_code:
int isNumber(char *sNumber)
{
  if (!sNumber) return 0;
  int i;
  for(i=0; i<strlen(sNumber); ++i)
  {
    if(0 == ((*__ctype_b_loc ())[(int) ((sNumber[i]))] & (unsigned short) _ISdigit))
    {
      return 0;
    }
  }
  return 1;
}

variable_types:
sNumber
char *


ltrim

decompiled_code:
void *__fastcall ltrim(void *src)
{
const char *v1; // rbp
int v2; // ebx
const unsigned __int16 *v3; // rdx
size_t v4; // rax

if ( !src )
return src;
v1 = (const char *)src;
v2 = strlen((const char *)src);
v3 = *_ctype_b_loc();
while ( (v3[*v1] & 0x2000) != 0 )
++v1;
v4 = strlen(v1);
if ( v2 <= v4 )
return src;
memcpy(src, v1, v4 + 1);
return src;
}

canonical_decompiled_code:
void *__fastcall func3(void *src)
{
const char *v1; // rbp
int v2; // ebx
const unsigned __int16 *v3; // rdx
size_t v4; // rax

if ( !src )
return src;
v1 = (const char *)src;
v2 = strlen((const char *)src);
v3 = *_ctype_b_loc();
while ( (v3[*v1] & 0x2000) != 0 )
++v1;
v4 = strlen(v1);
if ( v2 <= v4 )
return src;
memcpy(src, v1, v4 + 1);
return src;
}

original_code:
char* ltrim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int tmpLen = strlen(s);
  while(((*__ctype_b_loc ())[(int) ((*ptmp))] & (unsigned short int) _ISspace))
  {
    ++ptmp;
  }
  if (tmpLen > strlen(ptmp))
  {
    memcpy(s, ptmp, strlen(ptmp)+1);
  }
  return s;
}

canonical_original_code:
char *ltrim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int tmpLen = strlen(s);
  while(((*__ctype_b_loc ())[(int) ((*ptmp))] & (unsigned short) _ISspace))
  {
    ++ptmp;
  }
  if (tmpLen > strlen(ptmp))
  {
    memcpy(s, ptmp, strlen(ptmp)+1);
  }
  return s;
}

variable_types:
s
char *

variable_types:
ptmp
char *

variable_types: tmpLen int

return_type: char *


rtrim

decompiled_code:
const char *__fastcall rtrim(const char *a1)
{
int v2; // ebx
const unsigned __int16 **v3; // rsi
char *v4; // rax
__int64 v5; // rdi

if ( a1 )
{
v2 = strlen(a1);
if ( v2 )
{
v3 = _ctype_b_loc();
v4 = (char *)&a1[v2 - 1];
v5 = (__int64)&a1[v2 - 2 - (v2 - 1)];
do
{
if ( ((*v3)[*v4] & 0x2000) == 0 )
break;
*v4-- = 0;
}
while ( (char *)v5 != v4 );
}
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1)
{
int v2; // ebx
const unsigned __int16 **v3; // rsi
char *v4; // rax
__int64 v5; // rdi

if ( a1 )
{
v2 = strlen(a1);
if ( v2 )
{
v3 = _ctype_b_loc();
v4 = (char *)&a1[v2 - 1];
v5 = (__int64)&a1[v2 - 2 - (v2 - 1)];
do
{
if ( ((*v3)[*v4] & 0x2000) == 0 )
break;
*v4-- = 0;
}
while ( (char *)v5 != v4 );
}
}
return a1;
}

original_code:
char* rtrim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int len = strlen(s);
  while (len)
  {
    if (((*__ctype_b_loc ())[(int) ((*(ptmp+len-1)))] & (unsigned short int) _ISspace))
    {
      *(ptmp+len-1) = '\0';
      --len;
    }
    else
    {
      break;
    }
  }
  return s;
}

canonical_original_code:
char *rtrim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int len = strlen(s);
  while (len)
  {
    if (((*__ctype_b_loc ())[(int) ((*(ptmp+len-1)))] & (unsigned short) _ISspace))
    {
      *(ptmp+len-1) = '\0';
      --len;
    }
    else
    {
      break;
    }
  }
  return s;
}

variable_types: len int


getSysDate

decompiled_code:
char *__fastcall getSysDate(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( s )
{
timer = time(0LL);
v1 = localtime(&timer);
sprintf(
s,
"%04d%02d%02d%02d%02d%02d",
(unsigned int)(v1->tm_year + 1900),
(unsigned int)(v1->tm_mon + 1),
(unsigned int)v1->tm_mday,
(unsigned int)v1->tm_hour,
(unsigned int)v1->tm_min,
(unsigned int)v1->tm_sec);
s[14] = 0;
}
return s;
}

canonical_decompiled_code:
char *__fastcall func6(char *s)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( s )
{
timer = time(0LL);
v1 = localtime(&timer);
sprintf(
s,
"%04d%02d%02d%02d%02d%02d",
(unsigned int)(v1->tm_year + 1900),
(unsigned int)(v1->tm_mon + 1),
(unsigned int)v1->tm_mday,
(unsigned int)v1->tm_hour,
(unsigned int)v1->tm_min,
(unsigned int)v1->tm_sec);
s[14] = 0;
}
return s;
}

original_code:
char* getSysDate(char * sysDate)
{
  if (!sysDate) return ((void *)0);
  time_t sec;
  struct tm *t;
  sec = time(((void *)0));
  t = localtime(&sec);
  sprintf(sysDate,"%04d%02d%02d%02d%02d%02d", t->tm_year+1900,t->tm_mon+1, t->tm_mday, t->tm_hour,t->tm_min,t->tm_sec);
  sysDate[14]='\0';
  return sysDate;
}

canonical_original_code:
char *getSysDate(char *sysDate)
{
  if (!sysDate) return ((void *)0);
  long sec;
  struct tm *t;
  sec = time(((void *)0));
  t = localtime(&sec);
  sprintf(sysDate,"%04d%02d%02d%02d%02d%02d", t->tm_year+1900,t->tm_mon+1, t->tm_mday, t->tm_hour,t->tm_min,t->tm_sec);
  sysDate[14]='\0';
  return sysDate;
}

variable_types:
sysDate
char *

variable_types: sec long

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


isDate

decompiled_code:
_BOOL8 __fastcall isDate(const char *a1)
{
_BOOL8 result; // rax
int v2; // eax
int v3; // eax
int v4; // er12
int v5; // ebp
int v6; // eax
int v7; // edx
char nptr[4]; // [rsp+1h] [rbp-1Dh] BYREF
char v9; // [rsp+5h] [rbp-19h]

if ( !a1 )
return 0LL;
if ( strlen(a1) != 8 )
return 0LL;
if ( !(unsigned int)isNumber(a1) )
return 0LL;
v2 = *(_DWORD *)a1;
v9 = 0;
*(_DWORD *)nptr = v2;
v3 = atoi(nptr);
nptr[2] = 0;
v4 = v3;
*(_WORD *)nptr = *((_WORD *)a1 + 2);
v5 = atoi(nptr);
*(_WORD *)nptr = *((_WORD *)a1 + 3);
if ( v4 <= 1990 )
return 0LL;
v6 = atoi(nptr);
v7 = v6;
if ( v5 > 12 || v6 > 31 || !v5 || !v6 )
return 0LL;
if ( ((v5 & 0xFFFFFFFD) == 4 || (v5 & 0xFFFFFFFD) == 9) && v6 == 31 )
return 0LL;
result = 1LL;
if ( v5 == 2 )
{
if ( __ROR4__(-1030792151 * v4 + 85899344, 2) <= 0x28F5C28u && __ROR4__(-1030792151 * v4 + 85899344, 4) > 0xA3D70Au
|| (v4 & 3) != 0 )
{
result = v7 <= 28;
}
else
{
result = v7 <= 29;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const char *a1)
{
_BOOL8 result; // rax
int v2; // eax
int v3; // eax
int v4; // er12
int v5; // ebp
int v6; // eax
int v7; // edx
char nptr[4]; // [rsp+1h] [rbp-1Dh] BYREF
char v9; // [rsp+5h] [rbp-19h]

if ( !a1 )
return 0LL;
if ( strlen(a1) != 8 )
return 0LL;
if ( !(unsigned int)func2(a1) )
return 0LL;
v2 = *(_DWORD *)a1;
v9 = 0;
*(_DWORD *)nptr = v2;
v3 = atoi(nptr);
nptr[2] = 0;
v4 = v3;
*(_WORD *)nptr = *((_WORD *)a1 + 2);
v5 = atoi(nptr);
*(_WORD *)nptr = *((_WORD *)a1 + 3);
if ( v4 <= 1990 )
return 0LL;
v6 = atoi(nptr);
v7 = v6;
if ( v5 > 12 || v6 > 31 || !v5 || !v6 )
return 0LL;
if ( ((v5 & 0xFFFFFFFD) == 4 || (v5 & 0xFFFFFFFD) == 9) && v6 == 31 )
return 0LL;
result = 1LL;
if ( v5 == 2 )
{
if ( __ROR4__(-1030792151 * v4 + 85899344, 2) <= 0x28F5C28u && __ROR4__(-1030792151 * v4 + 85899344, 4) > 0xA3D70Au
|| (v4 & 3) != 0 )
{
result = v7 <= 28;
}
else
{
result = v7 <= 29;
}
}
return result;
}

original_code:
int isDate(char * sDate)
{
  if (!sDate || strlen(sDate)!=8) return 0;
  int iYear,iMonth,iDay;
  char sBuffer[5];
  if (!isNumber(sDate)) return 0;
  memcpy(sBuffer,sDate,4);
  sBuffer[4] = 0;
  iYear = atoi(sBuffer);
  memcpy(sBuffer,sDate+4,2);
  sBuffer[2] = 0;
  iMonth = atoi(sBuffer);
  memcpy(sBuffer,sDate+6,2);
  sBuffer[2] = 0;
  iDay = atoi(sBuffer);
  if (iYear <= 1990)
  {
    return 0;
  }
  if (iMonth>12 || iDay>31 || iMonth==0 || iDay==0)
  {
    return 0;
  }
  if ((iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11) && iDay>30)
  {
    return 0;
  }
  if (iMonth==2)
  {
    if ((iYear%100!=0 && iYear%4==0) || (iYear%400==0 && iYear%4==0))
    {
      if (iDay > 29) return 0;
    }
    else
    {
      if (iDay > 28) return 0;
    }
  }
  return 1;
}

canonical_original_code:
int isDate(char *sDate)
{
  if (!sDate || strlen(sDate)!=8) return 0;
  int iYear; int iMonth; int iDay;
  char sBuffer[5];
  if (!isNumber(sDate)) return 0;
  memcpy(sBuffer,sDate,4);
  sBuffer[4] = 0;
  iYear = atoi(sBuffer);
  memcpy(sBuffer,sDate+4,2);
  sBuffer[2] = 0;
  iMonth = atoi(sBuffer);
  memcpy(sBuffer,sDate+6,2);
  sBuffer[2] = 0;
  iDay = atoi(sBuffer);
  if (iYear <= 1990)
  {
    return 0;
  }
  if (iMonth>12 || iDay>31 || iMonth==0 || iDay==0)
  {
    return 0;
  }
  if ((iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11) && iDay>30)
  {
    return 0;
  }
  if (iMonth==2)
  {
    if ((iYear%100!=0 && iYear%4==0) || (iYear%400==0 && iYear%4==0))
    {
      if (iDay > 29) return 0;
    }
    else
    {
      if (iDay > 28) return 0;
    }
  }
  return 1;
}

variable_types:
sDate
char *

variable_types: iYear int

variable_types: iMonth int

variable_types: iDay int

variable_types:
sBuffer
char [5]


isTime

decompiled_code:
_BOOL8 __fastcall isTime(const char *a1)
{
__int16 v2; // ax
char nptr[2]; // [rsp+1h] [rbp-Dh] BYREF
char v4; // [rsp+3h] [rbp-Bh]

if ( !a1 )
return 0LL;
if ( strlen(a1) != 6 )
return 0LL;
if ( !(unsigned int)isNumber(a1) )
return 0LL;
v2 = *(_WORD *)a1;
v4 = 0;
*(_WORD *)nptr = v2;
if ( (unsigned int)atoi(nptr) > 0x17 )
return 0LL;
*(_WORD *)nptr = *((_WORD *)a1 + 1);
if ( (unsigned int)atoi(nptr) > 0x3B )
return 0LL;
*(_WORD *)nptr = *((_WORD *)a1 + 2);
return (unsigned int)atoi(nptr) <= 0x3B;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1)
{
__int16 v2; // ax
char nptr[2]; // [rsp+1h] [rbp-Dh] BYREF
char v4; // [rsp+3h] [rbp-Bh]

if ( !a1 )
return 0LL;
if ( strlen(a1) != 6 )
return 0LL;
if ( !(unsigned int)func2(a1) )
return 0LL;
v2 = *(_WORD *)a1;
v4 = 0;
*(_WORD *)nptr = v2;
if ( (unsigned int)atoi(nptr) > 0x17 )
return 0LL;
*(_WORD *)nptr = *((_WORD *)a1 + 1);
if ( (unsigned int)atoi(nptr) > 0x3B )
return 0LL;
*(_WORD *)nptr = *((_WORD *)a1 + 2);
return (unsigned int)atoi(nptr) <= 0x3B;
}

original_code:
int isTime(char * sTime)
{
  if (!sTime || strlen(sTime)!=6) return 0;
  char sBuffer[5];
  int iValue;
  if (!isNumber(sTime)) return 0;
  memcpy(sBuffer,sTime,2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=23)) return 0;
  memcpy(sBuffer,&sTime[2],2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=59)) return 0;
  memcpy(sBuffer,&sTime[4],2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=59)) return 0;
  return 1;
}

canonical_original_code:
int isTime(char *sTime)
{
  if (!sTime || strlen(sTime)!=6) return 0;
  char sBuffer[5];
  int iValue;
  if (!isNumber(sTime)) return 0;
  memcpy(sBuffer,sTime,2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=23)) return 0;
  memcpy(sBuffer,&sTime[2],2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=59)) return 0;
  memcpy(sBuffer,&sTime[4],2);
  sBuffer[2] = 0;
  iValue = atoi(sBuffer);
  if (!(iValue>=0 && iValue <=59)) return 0;
  return 1;
}

variable_types:
sTime
char *

variable_types: iValue int


isDatetime

decompiled_code:
_BOOL8 __fastcall isDatetime(__int64 a1)
{
__int64 v2; // rax
int v3; // eax
int v4; // [rsp+0h] [rbp-18h] BYREF
__int16 v5; // [rsp+4h] [rbp-14h]
char v6; // [rsp+6h] [rbp-12h]
__int64 v7; // [rsp+7h] [rbp-11h] BYREF
char v8; // [rsp+Fh] [rbp-9h]

if ( !a1 )
return 0LL;
if ( strlen((const char *)a1) != 14 )
return 0LL;
v2 = *(_QWORD *)a1;
v8 = 0;
v7 = v2;
if ( !isDate((const char *)&v7) )
return 0LL;
v3 = *(_DWORD *)(a1 + 8);
v6 = 0;
v4 = v3;
v5 = *(_WORD *)(a1 + 12);
return isTime((const char *)&v4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1)
{
__int64 v2; // rax
int v3; // eax
int v4; // [rsp+0h] [rbp-18h] BYREF
__int16 v5; // [rsp+4h] [rbp-14h]
char v6; // [rsp+6h] [rbp-12h]
__int64 v7; // [rsp+7h] [rbp-11h] BYREF
char v8; // [rsp+Fh] [rbp-9h]

if ( !a1 )
return 0LL;
if ( strlen((const char *)a1) != 14 )
return 0LL;
v2 = *(_QWORD *)a1;
v8 = 0;
v7 = v2;
if ( !func7((const char *)&v7) )
return 0LL;
v3 = *(_DWORD *)(a1 + 8);
v6 = 0;
v4 = v3;
v5 = *(_WORD *)(a1 + 12);
return func8((const char *)&v4);
}

original_code:
int isDatetime(const char * sDatetime)
{
  if (!sDatetime || strlen(sDatetime)!=14) return 0;
  char sDate[8+1];
  char sTime[6+1];
  if( strlen(sDatetime) != 14 ) return 0;
  memcpy(sDate,sDatetime,8);
  sDate[8] = 0;
  if (!isDate(sDate)) return 0;
  memcpy(sTime,&sDatetime[8],6);
  sTime[6] = 0;
  if (!isTime(sTime)) return 0;
  return 1;
}

canonical_original_code:
int isDatetime(char *sDatetime)
{
  if (!sDatetime || strlen(sDatetime)!=14) return 0;
  char sDate[-1];
  char sTime[-1];
  if( strlen(sDatetime) != 14 ) return 0;
  memcpy(sDate,sDatetime,8);
  sDate[8] = 0;
  if (!isDate(sDate)) return 0;
  memcpy(sTime,&sDatetime[8],6);
  sTime[6] = 0;
  if (!isTime(sTime)) return 0;
  return 1;
}

variable_types:
sDatetime
char *

variable_types:
sDate
char [-1]

variable_types:
sTime
char [-1]


decompiled_code:
time_t __fastcall time2sec(__int64 a1)
{
struct tm tp; // [rsp+0h] [rbp-48h] BYREF

if ( !a1 )
return 0LL;
if ( !isDatetime(a1) )
return 0LL;
tp.tm_zone = 0LL;
*(_OWORD *)&tp.tm_sec = 0LL;
*(_OWORD *)&tp.tm_mon = 0LL;
*(_OWORD *)&tp.tm_isdst = 0LL;
_isoc99_sscanf(a1, "%4d%2d%2d%2d%2d%2d", &tp.tm_year, &tp.tm_mon, &tp.tm_mday, &tp.tm_hour, &tp.tm_min, &tp);
--tp.tm_mon;
tp.tm_year -= 1900;
return mktime(&tp);
}

canonical_decompiled_code:
time_t __fastcall func10(__int64 a1)
{
struct tm tp; // [rsp+0h] [rbp-48h] BYREF

if ( !a1 )
return 0LL;
if ( !func9(a1) )
return 0LL;
tp.tm_zone = 0LL;
*(_OWORD *)&tp.tm_sec = 0LL;
*(_OWORD *)&tp.tm_mon = 0LL;
*(_OWORD *)&tp.tm_isdst = 0LL;
_isoc99_sscanf(a1, "%4d%2d%2d%2d%2d%2d", &tp.tm_year, &tp.tm_mon, &tp.tm_mday, &tp.tm_hour, &tp.tm_min, &tp);
--tp.tm_mon;
tp.tm_year -= 1900;
return mktime(&tp);
}

original_code:
long time2sec(const char *src)
{
  if (!src || !isDatetime(src)) return 0L;
  struct tm tmpTm;
  memset(&tmpTm,0x00,sizeof(struct tm));
  sscanf(src,"%4d%2d%2d%2d%2d%2d",&tmpTm.tm_year, &tmpTm.tm_mon, &tmpTm.tm_mday, &tmpTm.tm_hour, &tmpTm.tm_min, &tmpTm.tm_sec);
  tmpTm.tm_year -= 1900;
  tmpTm.tm_mon -= 1;
  return mktime(&tmpTm);
}

canonical_original_code:
long time2sec(char *src)
{
  if (!src || !isDatetime(src)) return 0L;
  struct tm tmpTm;
  memset(&tmpTm,0x00,sizeof(struct tm));
  sscanf(src,"%4d%2d%2d%2d%2d%2d",&tmpTm.tm_year, &tmpTm.tm_mon, &tmpTm.tm_mday, &tmpTm.tm_hour, &tmpTm.tm_min, &tmpTm.tm_sec);
  tmpTm.tm_year -= 1900;
  tmpTm.tm_mon -= 1;
  return mktime(&tmpTm);
}

variable_types:
src
char *

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

return_type: long


diffsec

decompiled_code:
time_t __fastcall diffsec(__int64 a1, __int64 a2)
{
time_t v2; // rbx

v2 = time2sec(a1);
return v2 - time2sec(a2);
}

canonical_decompiled_code:
time_t __fastcall func11(__int64 a1, __int64 a2)
{
time_t v2; // rbx

v2 = func10(a1);
return v2 - func10(a2);
}

original_code:
long diffsec(const char *src1, const char *src2)
{
  return time2sec(src1) - time2sec(src2);
}

canonical_original_code:
long diffsec(char *src1, char *src2)
{
  return time2sec(src1) - time2sec(src2);
}


cryptStr

original_code:
char* cryptStr(char * oStr,char * sStr)
{
  char key[5 +1]="\001\002\003\004\005";
  int p = (int)5;
  int k;
  for (k=0; k<strlen(sStr); ++k)
  {
   oStr[k]=sStr[k]^key[k%p--];
   if (!p) p = (int)5;
  }
  oStr[strlen(sStr)] = '\0';
  return oStr;
}

canonical_original_code:
char *cryptStr(char *oStr, char *sStr)
{
  char key[-1] = "\001\002\003\004\005";
  int p = (int)5;
  int k;
  for (k=0; k<strlen(sStr); ++k)
  {
   oStr[k]=sStr[k]^key[k%p--];
   if (!p) p = (int)5;
  }
  oStr[strlen(sStr)] = '\0';
  return oStr;
}

variable_types:
oStr
char *

variable_types:
sStr
char *

variable_types:
key
char [-1]

variable_types: p int

variable_types: k int


getExePathAndName

decompiled_code:
__int64 __fastcall getExePathAndName(char *src, char *dest, char *a3)
{
char *v4; // rax
const char *v5; // r13
const char *v6; // r15
size_t v7; // rax
size_t v8; // rbx
size_t v9; // rax
__int64 result; // rax
size_t v11; // rax

if ( src )
{
v4 = strrchr(src, 47);
v5 = v4;
if ( v4 )
{
v6 = v4 + 1;
v7 = strlen(v4 + 1);
strncpy(dest, v6, v7);
v8 = strlen(src);
v9 = strlen(v5);
strncpy(a3, src, v8 + 1 - v9);
}
else
{
v11 = strlen(src);
strncpy(dest, src, v11);
*(_WORD *)a3 = 12078;
}
result = 0LL;
}
else
{
puts("SearchExeFileNameAndPath_<Input_Parameter_Error");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *src, char *dest, char *a3)
{
char *v4; // rax
const char *v5; // r13
const char *v6; // r15
size_t v7; // rax
size_t v8; // rbx
size_t v9; // rax
__int64 result; // rax
size_t v11; // rax

if ( src )
{
v4 = strrchr(src, 47);
v5 = v4;
if ( v4 )
{
v6 = v4 + 1;
v7 = strlen(v4 + 1);
strncpy(dest, v6, v7);
v8 = strlen(src);
v9 = strlen(v5);
strncpy(a3, src, v8 + 1 - v9);
}
else
{
v11 = strlen(src);
strncpy(dest, src, v11);
*(_WORD *)a3 = 12078;
}
result = 0LL;
}
else
{
puts("SearchExeFileNameAndPath_<Input_Parameter_Error");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int getExePathAndName( const char *in_ptrArgv0,char *out_exename, char *out_exepath)
{
  const char *ptrChar;
  if( in_ptrArgv0 == ((void *)0) )
  {
    printf( "SearchExeFileNameAndPath_<Input_Parameter_Error\n" );
    return -1;
  }
  ptrChar = strrchr( in_ptrArgv0, '/' );
  if( ptrChar != ((void *)0) )
  {
    strncpy(out_exename, ptrChar+1, strlen(ptrChar+1));
    strncpy(out_exepath, in_ptrArgv0, strlen(in_ptrArgv0)-strlen(ptrChar)+1);
  }
  else
  {
    strncpy( out_exename, in_ptrArgv0, strlen( in_ptrArgv0 ) );
    strncpy( out_exepath, "./", 2);
  }
  return 0;
}

canonical_original_code:
int getExePathAndName(char *in_ptrArgv0, char *out_exename, char *out_exepath)
{
  char *ptrChar;
  if( in_ptrArgv0 == ((void *)0) )
  {
    printf( "SearchExeFileNameAndPath_<Input_Parameter_Error\n" );
    return -1;
  }
  ptrChar = strrchr( in_ptrArgv0, '/' );
  if( ptrChar != ((void *)0) )
  {
    strncpy(out_exename, ptrChar+1, strlen(ptrChar+1));
    strncpy(out_exepath, in_ptrArgv0, strlen(in_ptrArgv0)-strlen(ptrChar)+1);
  }
  else
  {
    strncpy( out_exename, in_ptrArgv0, strlen( in_ptrArgv0 ) );
    strncpy( out_exepath, "./", 2);
  }
  return 0;
}

variable_types:
ptrChar
char *


getsubstr

decompiled_code:
char *__fastcall getsubstr(char *src, char a2, int a3, char *a4)
{
char *result; // rax
size_t v7; // rbp
size_t v8; // rax
size_t v9; // rbp
size_t v10; // rax
char v11[1024]; // [rsp+0h] [rbp-838h] BYREF
char v12[1080]; // [rsp+400h] [rbp-438h] BYREF

result = 0LL;
memset(v11, 0, sizeof(v11));
memset(v12, 0, 0x400uLL);
if ( src && a3 > 0 )
{
if ( a3 == 1 )
{
strcpy(v11, src);
pstrchr(src, a2, 1, v12);
v9 = strlen(v11);
v10 = strlen(v12);
result = strncpy(a4, v11, v9 - v10);
}
else
{
pstrchr(src, a2, a3 - 1, v11);
pstrchr(src, a2, a3, v12);
v7 = strlen(&v11[1]);
v8 = strlen(v12);
result = strncpy(a4, &v11[1], v7 - v8);
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func14(char *src, char a2, int a3, char *a4)
{
char *result; // rax
size_t v7; // rbp
size_t v8; // rax
size_t v9; // rbp
size_t v10; // rax
char v11[1024]; // [rsp+0h] [rbp-838h] BYREF
char v12[1080]; // [rsp+400h] [rbp-438h] BYREF

result = 0LL;
memset(v11, 0, sizeof(v11));
memset(v12, 0, 0x400uLL);
if ( src && a3 > 0 )
{
if ( a3 == 1 )
{
strcpy(v11, src);
func0(src, a2, 1, v12);
v9 = strlen(v11);
v10 = strlen(v12);
result = strncpy(a4, v11, v9 - v10);
}
else
{
func0(src, a2, a3 - 1, v11);
func0(src, a2, a3, v12);
v7 = strlen(&v11[1]);
v8 = strlen(v12);
result = strncpy(a4, &v11[1], v7 - v8);
}
}
return result;
}

original_code:
void getsubstr(char *str, char sp, int n, char *substr)
{
  char p0[1024];
  char p1[1024];
  memset(p0, 0, sizeof(p0));
  memset(p1, 0, sizeof(p1));
  if(!str || n<=0) return;
  if(n == 1)
  {
    strcpy(p0, str);
  }
  else
  {
    pstrchr( str, sp, n-1, p0 );
  }
  pstrchr( str, sp, n, p1 );
    if( n == 1 )
    {
      strncpy( substr, p0, strlen( p0 ) - strlen( p1 ) );
    }
    else
    {
      strncpy( substr, p0+1, strlen( p0+1 ) - strlen( p1 ) );
    }
}

variable_types:
str
char *

variable_types: sp char

variable_types: n int

variable_types:
substr
char *


getstrnum

decompiled_code:
__int64 __fastcall getstrnum(const char *a1, const char *a2)
{
char *v2; // rax
char *v3; // rbx
unsigned int v4; // er12
size_t v5; // r13

v2 = strstr(a1, a2);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = 0;
v5 = strlen(a2);
do
{
++v4;
v3 = strstr(&v3[v5], a2);
}
while ( v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func15(const char *a1, const char *a2)
{
char *v2; // rax
char *v3; // rbx
unsigned int v4; // er12
size_t v5; // r13

v2 = strstr(a1, a2);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = 0;
v5 = strlen(a2);
do
{
++v4;
v3 = strstr(&v3[v5], a2);
}
while ( v3 );
return v4;
}

original_code:
int getstrnum(char *dest ,char *searchstr)
{
  char *strtmp,*strtmp2;
  int i=0;
  if (strstr(dest,searchstr)==((void *)0))
  {
    return 0;
  }
  strtmp=dest;
  while ((strtmp2=strstr((char *)strtmp,searchstr))!=((void *)0))
  {
    strtmp=strtmp2+strlen(searchstr);
    i++;
  }
  return i;
}

canonical_original_code:
int getstrnum(char *dest, char *searchstr)
{
  char *strtmp; char *strtmp2;
  int i = 0;
  if (strstr(dest,searchstr)==((void *)0))
  {
    return 0;
  }
  strtmp=dest;
  while ((strtmp2=strstr((char *)strtmp,searchstr))!=((void *)0))
  {
    strtmp=strtmp2+strlen(searchstr);
    i++;
  }
  return i;
}

variable_types:
dest
char *

variable_types:
searchstr
char *

variable_types:
strtmp
char *

variable_types: i int


strreplace

decompiled_code:
__int64 __fastcall strreplace(char *haystack, char *needle, char *src)
{
char *v4; // r8
__int64 result; // rax
int v6; // er12
size_t v7; // r15
int v8; // eax
void *v9; // r12
unsigned int v10; // eax
int i; // er8
const char *v12; // r14
char *v13; // rax
size_t v14; // rax
int v15; // [rsp+8h] [rbp-40h]

v4 = strstr(haystack, needle);
result = 0LL;
if ( v4 )
{
v6 = getstrnum(haystack, needle);
v15 = strlen(needle);
v7 = strlen(src);
v8 = strlen(haystack);
v9 = calloc(v6 * ((int)v7 - v15) + v8 + 1, 1uLL);
if ( v9 )
{
v10 = (unsigned int)strstr(haystack, needle);
memcpy(v9, haystack, (int)(v10 - (_DWORD)haystack));
strncat((char *)v9, src, v7);
for ( i = (unsigned int)strstr(haystack, needle) - (_DWORD)haystack + v15;
;
i = (unsigned int)strstr(v12, needle) - (_DWORD)haystack + v15 )
{
v12 = &haystack[i];
v13 = strstr(v12, needle);
if ( !v13 )
break;
strncat((char *)v9, v12, v13 - v12);
strncat((char *)v9, src, v7);
}
v14 = strlen(v12);
strncat((char *)v9, v12, v14);
strcpy(haystack, (const char *)v9);
free(v9);
result = 0LL;
}
else
{
perror("replace malloc error");
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *haystack, char *needle, char *src)
{
char *v4; // r8
__int64 result; // rax
int v6; // er12
size_t v7; // r15
int v8; // eax
void *v9; // r12
unsigned int v10; // eax
int i; // er8
const char *v12; // r14
char *v13; // rax
size_t v14; // rax
int v15; // [rsp+8h] [rbp-40h]

v4 = strstr(haystack, needle);
result = 0LL;
if ( v4 )
{
v6 = func15(haystack, needle);
v15 = strlen(needle);
v7 = strlen(src);
v8 = strlen(haystack);
v9 = calloc(v6 * ((int)v7 - v15) + v8 + 1, 1uLL);
if ( v9 )
{
v10 = (unsigned int)strstr(haystack, needle);
memcpy(v9, haystack, (int)(v10 - (_DWORD)haystack));
strncat((char *)v9, src, v7);
for ( i = (unsigned int)strstr(haystack, needle) - (_DWORD)haystack + v15;
;
i = (unsigned int)strstr(v12, needle) - (_DWORD)haystack + v15 )
{
v12 = &haystack[i];
v13 = strstr(v12, needle);
if ( !v13 )
break;
strncat((char *)v9, v12, v13 - v12);
strncat((char *)v9, src, v7);
}
v14 = strlen(v12);
strncat((char *)v9, v12, v14);
strcpy(haystack, (const char *)v9);
free(v9);
result = 0LL;
}
else
{
perror("replace malloc error");
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int strreplace(char *dest,char *searchstr,char *replacestr)
{
  char *sTmphead, *sTmptail;
  int ilen = 0, ipos = 0;
  int iserlen, ireplen, inum;
  if (strstr(dest,searchstr) == ((void *)0))
  {
    return 0;
  }
  inum = getstrnum(dest,searchstr);
  iserlen = strlen(searchstr);
  ireplen = strlen(replacestr);
  ilen = strlen(dest) + (ireplen-iserlen)*inum + 1;
  if ((sTmphead=(char *)malloc(ilen)) == ((void *)0))
  {
    perror("replace malloc error");
    return -1;
  }
  memset(sTmphead, 0, ilen);
  ilen = strstr(dest, searchstr) - dest;
  memcpy(sTmphead,dest,ilen);
  strncat(sTmphead,replacestr,strlen(replacestr));
  ipos=strstr(dest,searchstr)-dest+strlen(searchstr);
  while ((sTmptail=strstr(dest+ipos,searchstr)) != ((void *)0))
  {
    strncat(sTmphead,dest+ipos,sTmptail-(dest+ipos));
    strncat(sTmphead,replacestr,strlen(replacestr));
    ipos=strstr(dest+ipos,searchstr)-dest+strlen(searchstr);
  }
  strncat(sTmphead,dest+ipos,strlen(dest+ipos));
  strcpy(dest,sTmphead);
  free(sTmphead);
  return 0;
}

canonical_original_code:
int strreplace(char *dest, char *searchstr, char *replacestr)
{
  char *sTmphead; char *sTmptail;
  int ilen = 0; int ipos = 0;
  int iserlen; int ireplen; int inum;
  if (strstr(dest,searchstr) == ((void *)0))
  {
    return 0;
  }
  inum = getstrnum(dest,searchstr);
  iserlen = strlen(searchstr);
  ireplen = strlen(replacestr);
  ilen = strlen(dest) + (ireplen-iserlen)*inum + 1;
  if ((sTmphead=(char *)malloc(ilen)) == ((void *)0))
  {
    perror("replace malloc error");
    return -1;
  }
  memset(sTmphead, 0, ilen);
  ilen = strstr(dest, searchstr) - dest;
  memcpy(sTmphead,dest,ilen);
  strncat(sTmphead,replacestr,strlen(replacestr));
  ipos=strstr(dest,searchstr)-dest+strlen(searchstr);
  while ((sTmptail=strstr(dest+ipos,searchstr)) != ((void *)0))
  {
    strncat(sTmphead,dest+ipos,sTmptail-(dest+ipos));
    strncat(sTmphead,replacestr,strlen(replacestr));
    ipos=strstr(dest+ipos,searchstr)-dest+strlen(searchstr);
  }
  strncat(sTmphead,dest+ipos,strlen(dest+ipos));
  strcpy(dest,sTmphead);
  free(sTmphead);
  return 0;
}

variable_types:
replacestr
char *

variable_types:
sTmphead
char *

variable_types:
sTmptail
char *

variable_types: ilen int

variable_types: ipos int

variable_types: iserlen int

variable_types: ireplen int

variable_types: inum int


trim

decompiled_code:
void *__fastcall trim(void *src)
{
int v2; // ebp
const unsigned __int16 **v3; // rax
const unsigned __int16 **v4; // rsi
size_t v5; // rbx
char *v6; // rax
char *v7; // rdi
const unsigned __int16 *v8; // rdx
const char *i; // rbp
size_t v10; // rax

if ( !src )
return src;
v2 = strlen((const char *)src);
v3 = _ctype_b_loc();
v4 = v3;
if ( v2 )
{
v5 = v2;
v6 = (char *)src + v2 - 1;
v7 = (char *)src + v2 - (unsigned int)(v2 - 1) - 2;
while ( 1 )
{
v8 = *v4;
if ( ((*v4)[*v6] & 0x2000) == 0 )
break;
*v6-- = 0;
if ( v7 == v6 )
{
v8 = *v4;
break;
}
}
}
else
{
v8 = *v3;
v5 = 0LL;
}
for ( i = (const char *)src; (v8[*i] & 0x2000) != 0; ++i )
;
v10 = strlen(i);
if ( v5 <= v10 )
return src;
memcpy(src, i, v10 + 1);
return src;
}

canonical_decompiled_code:
void *__fastcall func5(void *src)
{
int v2; // ebp
const unsigned __int16 **v3; // rax
const unsigned __int16 **v4; // rsi
size_t v5; // rbx
char *v6; // rax
char *v7; // rdi
const unsigned __int16 *v8; // rdx
const char *i; // rbp
size_t v10; // rax

if ( !src )
return src;
v2 = strlen((const char *)src);
v3 = _ctype_b_loc();
v4 = v3;
if ( v2 )
{
v5 = v2;
v6 = (char *)src + v2 - 1;
v7 = (char *)src + v2 - (unsigned int)(v2 - 1) - 2;
while ( 1 )
{
v8 = *v4;
if ( ((*v4)[*v6] & 0x2000) == 0 )
break;
*v6-- = 0;
if ( v7 == v6 )
{
v8 = *v4;
break;
}
}
}
else
{
v8 = *v3;
v5 = 0LL;
}
for ( i = (const char *)src; (v8[*i] & 0x2000) != 0; ++i )
;
v10 = strlen(i);
if ( v5 <= v10 )
return src;
memcpy(src, i, v10 + 1);
return src;
}

original_code:
char* trim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int len = strlen(s);
  int tmpLen = len;
  while (len)
  {
    if (((*__ctype_b_loc ())[(int) ((*(ptmp+len-1)))] & (unsigned short int) _ISspace))
    {
      *(ptmp+len-1) = '\0';
      --len;
    }
    else
    {
      break;
    }
  }
  while(((*__ctype_b_loc ())[(int) ((*ptmp))] & (unsigned short int) _ISspace))
  {
    ++ptmp;
  }
  if (tmpLen > strlen(ptmp))
  {
    memcpy(s, ptmp, strlen(ptmp)+1);
  }
  return s;
}

canonical_original_code:
char *trim(char *s)
{
  if (!s) return ((void *)0);
  char *ptmp = s;
  int len = strlen(s);
  int tmpLen = len;
  while (len)
  {
    if (((*__ctype_b_loc ())[(int) ((*(ptmp+len-1)))] & (unsigned short) _ISspace))
    {
      *(ptmp+len-1) = '\0';
      --len;
    }
    else
    {
      break;
    }
  }
  while(((*__ctype_b_loc ())[(int) ((*ptmp))] & (unsigned short) _ISspace))
  {
    ++ptmp;
  }
  if (tmpLen > strlen(ptmp))
  {
    memcpy(s, ptmp, strlen(ptmp)+1);
  }
  return s;
}

variable_types:
s
char *

variable_types:
ptmp
char *

variable_types: len int

variable_types: tmpLen int


mkFlNm

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

strcpy(a1, a2);
v4 = strlen(a2);
if ( a2[v4 - 1] == 47 )
{
strcpy(&a1[v4], a3);
}
else
{
a2[v4] = 47;
strcpy(&a1[v4 + 1], a3);
}
return a1;
}

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

strcpy(a1, a2);
v4 = strlen(a2);
if ( a2[v4 - 1] == 47 )
{
strcpy(&a1[v4], a3);
}
else
{
a2[v4] = 47;
strcpy(&a1[v4 + 1], a3);
}
return a1;
}

original_code:
char *mkFlNm(char *fullFileName, char *dirName, char *fileName)
{
  int dirLen;
  strcpy(fullFileName, dirName);
  dirLen = strlen(dirName);
  if(dirName[dirLen-1]=='/')
  {
    strcpy(fullFileName+dirLen, fileName);
  }
  else
  {
    dirName[dirLen]='/';
    strcpy(fullFileName+dirLen+1, fileName);
  }
  return fullFileName;
}

variable_types:
fullFileName
char *

variable_types:
dirName
char *

variable_types:
fileName
char *

variable_types: dirLen int


getFlLth

decompiled_code:
__off_t __fastcall getFlLth(const char *a1, const char *a2)
{
struct stat v3; // [rsp+0h] [rbp-498h] BYREF
char file[16]; // [rsp+90h] [rbp-408h] BYREF
char v5[1008]; // [rsp+A0h] [rbp-3F8h] BYREF

memset(v5, 0, sizeof(v5));
*(_OWORD *)file = 0LL;
mkFlNm(file, a1, a2);
stat(file, &v3);
return v3.st_size;
}

canonical_decompiled_code:
__off_t __fastcall func8(const char *a1, const char *a2)
{
struct stat v3; // [rsp+0h] [rbp-498h] BYREF
char file[16]; // [rsp+90h] [rbp-408h] BYREF
char v5[1008]; // [rsp+A0h] [rbp-3F8h] BYREF

memset(v5, 0, sizeof(v5));
*(_OWORD *)file = 0LL;
func0(file, a1, a2);
stat(file, &v3);
return v3.st_size;
}

original_code:
long getFlLth(char *dirName, char *fileName)
{
  char fullName[1024] = {0};
  mkFlNm(fullName, dirName, fileName);
  struct stat buf;
  stat(fullName, &buf);
  return buf.st_size;
}

variable_types:
fullName
char [1024]

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


reNm

decompiled_code:
int __fastcall reNm(const char *a1, const char *a2, const char *a3)
{
char v5[1024]; // [rsp+0h] [rbp-818h] BYREF
char newa[1048]; // [rsp+400h] [rbp-418h] BYREF

mkFlNm(v5, a3, a1);
mkFlNm(newa, a3, a2);
return rename(v5, newa);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1, const char *a2, const char *a3)
{
char v5[1024]; // [rsp+0h] [rbp-818h] BYREF
char newa[1048]; // [rsp+400h] [rbp-418h] BYREF

func0(v5, a3, a1);
func0(newa, a3, a2);
return rename(v5, newa);
}

original_code:
int reNm(char *oldFileName, char *newFileName, char *dirName)
{
  char oldFullFile[1024];
  char newFullFile[1024];
  mkFlNm(oldFullFile, dirName, oldFileName);
  mkFlNm(newFullFile, dirName, newFileName);
  return rename(oldFullFile, newFullFile);
}

variable_types:
oldFileName
char *

variable_types:
newFileName
char *

variable_types:
oldFullFile
char [1024]

variable_types:
newFullFile
char [1024]


isHaveFile

decompiled_code:
_BOOL8 __fastcall isHaveFile(const char *a1)
{
return access(a1, 0) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(const char *a1)
{
return access(a1, 0) >= 0;
}

original_code:
int isHaveFile(char *file)
{
  if (access(file, 0) < 0)
  {
    return 0;
  }
  else
  {
    return 1;
  }
}

variable_types:
file
char *


getLogLevel

decompiled_code:
__int64 __fastcall getLogLevel(char *a1, int a2)
{
if ( a2 == 3 )
{
strcpy(a1, "WARN");
return 0LL;
}
if ( a2 > 3 )
{
if ( a2 == 4 )
{
strcpy(a1, "ERROR");
return 0LL;
}
LABEL_8:
perror("error log level!");
return 0LL;
}
if ( a2 == 1 )
{
strcpy(a1, "DEBUG");
return 0LL;
}
if ( a2 != 2 )
goto LABEL_8;
strcpy(a1, "INFO");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2)
{
if ( a2 == 3 )
{
strcpy(a1, "WARN");
return 0LL;
}
if ( a2 > 3 )
{
if ( a2 == 4 )
{
strcpy(a1, "ERROR");
return 0LL;
}
LABEL_8:
perror("error log level!");
return 0LL;
}
if ( a2 == 1 )
{
strcpy(a1, "DEBUG");
return 0LL;
}
if ( a2 != 2 )
goto LABEL_8;
strcpy(a1, "INFO");
return 0LL;
}

original_code:
static int getLogLevel(char *levelInfo, int logLevel)
{
  switch(logLevel)
  {
    case 1:
      strcpy(levelInfo, "DEBUG");
      break;
    case 2:
      strcpy(levelInfo, "INFO");
      break;
    case 3:
      strcpy(levelInfo, "WARN");
      break;
    case 4:
      strcpy(levelInfo, "ERROR");
      break;
    default:
      perror("error log level!");
  }
  return 0;
}

variable_types:
levelInfo
char *

variable_types: logLevel int


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

result = 1LL;
if ( a1 >= 0 )
result = (unsigned int)((a1 & 0x40) != 0) + 2;
return result;
}

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

result = 1LL;
if ( a1 >= 0 )
result = (unsigned int)((a1 & 0x40) != 0) + 2;
return result;
}

original_code:
int adc_chunk_type(char _byte)
{
 if (_byte & 0x80)
  return 0x01;
 if (_byte & 0x40)
  return 0x03;
 return 0x02;
}


decompiled_code:
__int64 __fastcall adc_chunk_size(char a1)
{
int v1; // eax
char v2; // dl
int v3; // ecx
unsigned int v4; // edx
bool v5; // zf
__int64 result; // rax

v1 = adc_chunk_type(a1);
if ( v1 == 2 )
return ((v3 >> 2) & 0xFu) + 3;
if ( v1 == 3 )
return (v2 & 0x3Fu) + 4;
v4 = (v2 & 0x7F) + 1;
v5 = v1 == 1;
result = 0xFFFFFFFFLL;
if ( v5 )
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
int v1; // eax
char v2; // dl
int v3; // ecx
unsigned int v4; // edx
bool v5; // zf
__int64 result; // rax

v1 = func0(a1);
if ( v1 == 2 )
return ((v3 >> 2) & 0xFu) + 3;
if ( v1 == 3 )
return (v2 & 0x3Fu) + 4;
v4 = (v2 & 0x7F) + 1;
v5 = v1 == 1;
result = 0xFFFFFFFFLL;
if ( v5 )
result = v4;
return result;
}

original_code:
int adc_chunk_size(char _byte)
{
 switch (adc_chunk_type(_byte)) {
  case 0x01:
  return (_byte & 0x7F) + 1;
 case 0x02:
  return ((_byte & 0x3F) >> 2) + 3;
 case 0x03:
  return (_byte & 0x3F) + 4;
 }
 return -1;
}