original_code:
int lib_Fmap_add(field_map* f_map, char* field_name, int id)
{
 size_t hash, emp, sh, hash_full;
 do{if((f_map)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((field_name)==(((void *)0))) return ((LP_FAIL));}while(0);
 hash_full =calc_hash(field_name);
 hash = hash_full % f_map->size;
 sh = hash;
 if(f_map->slot[hash].field_name == ((void *)0))
 {
  f_map->slot[hash].field_name = field_name;
  f_map->slot[hash].id = id;
  f_map->slot[hash].hash = hash_full;
 }
 else
 {
  for( ;; )
  {
   if(f_map->slot[sh].hash== hash_full && strcmp(f_map->slot[sh].field_name, field_name)==0)
    return LP_EXIST;
   if(f_map->slot[sh].next==0)
    break;
   sh = f_map->slot[sh].next -1;
  }
  emp = hash;
  for(;f_map->slot[emp].field_name!=((void *)0);)
   emp = (emp + 1)%f_map->size;
  f_map->slot[emp].next = f_map->slot[hash].next;
  f_map->slot[hash].next = emp + 1;
  f_map->slot[emp].field_name = field_name;
  f_map->slot[emp].id = id;
  f_map->slot[emp].hash = hash_full;
 }
 return LP_TRUE;
}

canonical_original_code:
int lib_Fmap_add(struct _field_map *f_map, char *field_name, int id)
{
 unsigned long hash; unsigned long emp; unsigned long sh; unsigned long hash_full;
 do{if((f_map)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((field_name)==(((void *)0))) return ((LP_FAIL));}while(0);
 hash_full =calc_hash(field_name);
 hash = hash_full % f_map->size;
 sh = hash;
 if(f_map->slot[hash].field_name == ((void *)0))
 {
  f_map->slot[hash].field_name = field_name;
  f_map->slot[hash].id = id;
  f_map->slot[hash].hash = hash_full;
 }
 else
 {
  for( ;; )
  {
   if(f_map->slot[sh].hash== hash_full && strcmp(f_map->slot[sh].field_name, field_name)==0)
    return LP_EXIST;
   if(f_map->slot[sh].next==0)
    break;
   sh = f_map->slot[sh].next -1;
  }
  emp = hash;
  for(;f_map->slot[emp].field_name!=((void *)0);)
   emp = (emp + 1)%f_map->size;
  f_map->slot[emp].next = f_map->slot[hash].next;
  f_map->slot[hash].next = emp + 1;
  f_map->slot[emp].field_name = field_name;
  f_map->slot[emp].id = id;
  f_map->slot[emp].hash = hash_full;
 }
 return LP_TRUE;
}

variable_types: id int


repo: lvzixun/lite-proto

decompiled_code:
const char *__fastcall lib_Fmap_find(unsigned __int64 *a1, const char *a2)
{
unsigned __int64 v2; // r14
const char *v4; // rsi
size_t v5; // rax
unsigned __int64 v6; // r12
size_t v7; // rbp
unsigned __int64 v8; // rbx
__int64 v9; // rbx

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v2 = *a1;
v4 = 0LL;
if ( *a1 )
{
v5 = calc_hash(a2);
v6 = a1[1];
v7 = v5;
v8 = v6 + 32 * (v5 % v2);
v4 = *(const char **)v8;
if ( *(_QWORD *)v8 )
{
while ( *(_QWORD *)(v8 + 16) != v7 || strcmp(a2, v4) )
{
v9 = *(_QWORD *)(v8 + 24);
if ( !v9 )
return 0LL;
v8 = v6 + 32 * (v9 - 1);
v4 = *(const char **)v8;
if ( !*(_QWORD *)v8 )
return v4;
}
v4 = (const char *)(v8 + 8);
}
}
return v4;
}

canonical_decompiled_code:
const char *__fastcall func11(unsigned __int64 *a1, const char *a2)
{
unsigned __int64 v2; // r14
const char *v4; // rsi
size_t v5; // rax
unsigned __int64 v6; // r12
size_t v7; // rbp
unsigned __int64 v8; // rbx
__int64 v9; // rbx

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v2 = *a1;
v4 = 0LL;
if ( *a1 )
{
v5 = func1(a2);
v6 = a1[1];
v7 = v5;
v8 = v6 + 32 * (v5 % v2);
v4 = *(const char **)v8;
if ( *(_QWORD *)v8 )
{
while ( *(_QWORD *)(v8 + 16) != v7 || strcmp(a2, v4) )
{
v9 = *(_QWORD *)(v8 + 24);
if ( !v9 )
return 0LL;
v8 = v6 + 32 * (v9 - 1);
v4 = *(const char **)v8;
if ( !*(_QWORD *)v8 )
return v4;
}
v4 = (const char *)(v8 + 8);
}
}
return v4;
}

original_code:
int* lib_Fmap_find(field_map* f_map, char* field_name)
{
 size_t hash, hash_full;
 do{if((f_map)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((field_name)==(((void *)0))) return ((((void *)0)));}while(0);
 if(!(f_map->size)) return ((void *)0);
 hash_full = calc_hash(field_name);
 hash = hash_full % f_map->size;
 for(;f_map->slot[hash].field_name!= ((void *)0);)
 {
  if(f_map->slot[hash].hash==hash_full && strcmp(field_name, f_map->slot[hash].field_name)==0)
   return &f_map->slot[hash].id;
  if(f_map->slot[hash].next==0)
   return ((void *)0);
  hash = f_map->slot[hash].next -1;
 }
 return ((void *)0);
}

canonical_original_code:
int *lib_Fmap_find(struct _field_map *f_map, char *field_name)
{
 unsigned long hash; unsigned long hash_full;
 do{if((f_map)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((field_name)==(((void *)0))) return ((((void *)0)));}while(0);
 if(!(f_map->size)) return ((void *)0);
 hash_full = calc_hash(field_name);
 hash = hash_full % f_map->size;
 for(;f_map->slot[hash].field_name!= ((void *)0);)
 {
  if(f_map->slot[hash].hash==hash_full && strcmp(field_name, f_map->slot[hash].field_name)==0)
   return &f_map->slot[hash].id;
  if(f_map->slot[hash].next==0)
   return ((void *)0);
  hash = f_map->slot[hash].next -1;
 }
 return ((void *)0);
}

variable_types: struct _field_map { unsigned long size; struct _field_slot { char *field_name; int id; unsigned long hash; unsigned long next; } *slot; } *

variable_types:
hash
unsigned long

return_type: int *

user_defined_types: struct _field_map { unsigned long size; struct _field_slot *slot; }


decompiled_code:
__int64 __fastcall lp_lex_token_free(__int64 a1)
{
if ( !a1 )
return 0LL;
lp_list_free(a1 + 8);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
return 0LL;
lp_list_free(a1 + 8);
return 1LL;
}

original_code:
int lp_lex_token_free(lp_token* tp)
{
 do{if((tp)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_list_free(&tp->name.str);
 return LP_TRUE;
}

canonical_original_code:
int lp_lex_token_free(struct _lp_token *tp)
{
 do{if((tp)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_list_free(&tp->name.str);
 return LP_TRUE;
}

variable_types: struct _lp_token { unsigned int line; enum _e_t { t_error=0, t_num=1, t_lb=2, t_rb=3, t_ass=4, t_ll=5, t_rl=6, t_ide=7, t_end=8, t_clo=9, t_ca=10, t_Kextern=11, t_Kinteger=12, t_Kreal=13, t_kstring=14, t_Kbytes=15, t_Kmessage=16, t_count=17 } type; struct _lp_string { struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; } str; } name; } *

return_type: int

user_defined_types: struct _lp_token { unsigned int line; enum _e_t type; struct _lp_string name; }

user_defined_types: struct _lp_string { struct _lp_list str; }


decompiled_code:
__int64 __fastcall lp_look_key(__int64 a1, const char *a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
__int64 result; // rax

if ( a2
&& a1
&& (v2 = 16LL * (int)BKDRHash(a2, 32LL) + a1, v3 = *(unsigned __int8 *)(v2 + 8), (_BYTE)v3)
&& !strcmp(*(const char **)v2, a2) )
{
result = v3;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
__int64 result; // rax

if ( a2
&& a1
&& (v2 = 16LL * (int)BKDRHash(a2, 32LL) + a1, v3 = *(unsigned __int8 *)(v2 + 8), (_BYTE)v3)
&& !strcmp(*(const char **)v2, a2) )
{
result = v3;
}
else
{
result = 0LL;
}
return result;
}

original_code:
static byte lp_look_key(lp_lex_env* env_p, char* str)
{
 int inx = 0;
 do{if((env_p)==(((void *)0))) return ((t_error));}while(0);
 do{if((str)==(((void *)0))) return ((t_error));}while(0);
 inx = _BKDRHash(str, 32);
 return (env_p->lp_k[inx].s_tt==t_error || strcmp(env_p->lp_k[inx].s_key, str))?(t_error):(env_p->lp_k[inx].s_tt);
}

canonical_original_code:
static unsigned char lp_look_key(struct _lp_lex_env *env_p, char *str)
{
 int inx = 0;
 do{if((env_p)==(((void *)0))) return ((t_error));}while(0);
 do{if((str)==(((void *)0))) return ((t_error));}while(0);
 inx = _BKDRHash(str, 32);
 return (env_p->lp_k[inx].s_tt==t_error || strcmp(env_p->lp_k[inx].s_key, str))?(t_error):(env_p->lp_k[inx].s_tt);
}

variable_types: struct _lp_lex_env { struct _lp_key { char *s_key; unsigned char s_tt; } lp_k[32]; unsigned char char_enum[128]; struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; } lex_list; unsigned int line; } *

variable_types:
str
char *

variable_types: inx int

return_type: unsigned char

user_defined_types: struct _lp_lex_env { struct _lp_key lp_k[32]; unsigned char char_enum[128]; struct _lp_list lex_list; unsigned int line; }


decompiled_code:
__int64 __fastcall lp_add_token(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return lp_list_add(a1 + 640, &a7);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
return lp_list_add(a1 + 640, &a7);
}

original_code:
static void lp_add_token(lp_lex_env* env_p, lp_token lp_t)
{
 lp_list_add( &((env_p)->lex_list), (byte*)(&(lp_t)) );
}

canonical_original_code:
static void lp_add_token(struct _lp_lex_env *env_p, struct _lp_token lp_t)
{
 lp_list_add( &((env_p)->lex_list), (unsigned char *)(&(lp_t)) );
}

variable_types: struct _lp_token { unsigned int line; enum _e_t { t_error=0, t_num=1, t_lb=2, t_rb=3, t_ass=4, t_ll=5, t_rl=6, t_ide=7, t_end=8, t_clo=9, t_ca=10, t_Kextern=11, t_Kinteger=12, t_Kreal=13, t_kstring=14, t_Kbytes=15, t_Kmessage=16, t_count=17 } type; struct _lp_string { struct _lp_list str; } name; }

return_type: void

user_defined_types: struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; }

user_defined_types: struct _lp_key { char *s_key; unsigned char s_tt; }


decompiled_code:
__int64 __fastcall next_char(_BYTE **a1)
{
unsigned int v1; // er8
_BYTE *v2; // rax

v1 = 0;
if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
if ( *v2 )
{
v1 = (unsigned __int8)*v2;
*a1 = v2 + 1;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE **a1)
{
unsigned int v1; // er8
_BYTE *v2; // rax

v1 = 0;
if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
if ( *v2 )
{
v1 = (unsigned __int8)*v2;
*a1 = v2 + 1;
}
}
}
return v1;
}

original_code:
char next_char(slice* p)
{
 char ret = 0;
 if(p&&p->sp&&*(p->sp))
 {
  ret = *((char*)(p->sp));
  (p->sp)++;
 }
 return ret;
}

canonical_original_code:
char next_char(struct _slice *p)
{
 char ret = 0;
 if(p&&p->sp&&*(p->sp))
 {
  ret = *((char *)(p->sp));
  (p->sp)++;
 }
 return ret;
}

variable_types: struct _slice { unsigned char *sp; unsigned char *b_sp; unsigned int sp_size; } *

variable_types: ret char

return_type: char


decompiled_code:
__int64 __fastcall free_lex_env(_QWORD *a1)
{
__int64 result; // rax

lp_list_free(a1 + 80);
*a1 = 0LL;
result = 0LL;
a1[87] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 704) >> 3));
return result;
}

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

lp_list_free(a1 + 80);
*a1 = 0LL;
result = 0LL;
a1[87] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 704) >> 3));
return result;
}

original_code:
void free_lex_env(lp_lex_env* le)
{
 if(le==((void *)0))
  return;
 lp_list_free(&le->lex_list);
 memset(le, 0, sizeof(*le));
}

canonical_original_code:
void free_lex_env(struct _lp_lex_env *le)
{
 if(le==((void *)0))
  return;
 lp_list_free(&le->lex_list);
 memset(le, 0, sizeof(*le));
}


decompiled_code:
_BOOL8 __fastcall cls_lex_env(__int64 a1)
{
if ( !a1 )
return 0LL;
lp_list_free(a1 + 640);
*(_DWORD *)(a1 + 696) = 1;
return (unsigned int)lp_list_new(a1 + 640, 64LL, 128LL, 0LL, lp_lex_token_free) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1)
{
if ( !a1 )
return 0LL;
lp_list_free(a1 + 640);
*(_DWORD *)(a1 + 696) = 1;
return (unsigned int)lp_list_new(a1 + 640, 64LL, 128LL, 0LL, lp_lex_token_free) != 0;
}

original_code:
int cls_lex_env(lp_lex_env* le)
{
 do{if((le)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_list_free(&le->lex_list);
 le->line = 1;
 do{if((_lp_list_new(&le->lex_list, sizeof(lp_token), 128, ((void *)0), (list_Ffree)lp_lex_token_free))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

canonical_original_code:
int cls_lex_env(struct _lp_lex_env *le)
{
 do{if((le)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_list_free(&le->lex_list);
 le->line = 1;
 do{if((_lp_list_new(&le->lex_list, sizeof(lp_token), 128, ((void *)0), (int (*)(void *))lp_lex_token_free))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}


original_code:
int get_lex_env(lp_lex_env* le)
{
 int i=0;
 do{if((le)==(((void *)0))) return ((LP_FAIL));}while(0);
 for(i=0; lp_sk[i].s_key; i++)
 {
  int inx = _BKDRHash(lp_sk[i].s_key, 32);
  if(le->lp_k[inx].s_key)
  {
   printf("[init error]lp_key is not null! key=\"%s\" \n", le->lp_k[inx].s_key);
   return LP_FAIL;
  }
  else
   le->lp_k[inx] = lp_sk[i];
 }
 memset(le->char_enum, 0, sizeof(le->char_enum));
 le->char_enum['\t']= l_skip;
 le->char_enum[' ']= l_skip;
 le->char_enum['\r'] = l_skip;
 le->char_enum['\n']= l_n;
 le->char_enum['_']= l_char;
 le->char_enum['{']= l_lb;
 le->char_enum['}']= l_rb;
 le->char_enum['=']= l_ass;
 le->char_enum['[']= l_ll;
 le->char_enum[']']= l_rl;
 le->char_enum[',']= l_ca;
 le->char_enum['#']= l_text;
 le->char_enum[';']= l_end;
 le->char_enum['.']= l_clo;
 for(i='a'; i<='z'; i++)
  le->char_enum[i] = l_char;
 for(i='A'; i<='Z'; i++)
  le->char_enum[i] = l_char;
 for(i='0'; i<='9'; i++)
  le->char_enum[i] = l_num;
 le->line = 1;
 do{if((_lp_list_new(&le->lex_list, sizeof(lp_token), 128, ((void *)0), (list_Ffree)lp_lex_token_free))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

canonical_original_code:
int get_lex_env(struct _lp_lex_env *le)
{
 int i = 0;
 do{if((le)==(((void *)0))) return ((LP_FAIL));}while(0);
 for(i=0; lp_sk[i].s_key; i++)
 {
  int inx = _BKDRHash(lp_sk[i].s_key, 32);
  if(le->lp_k[inx].s_key)
  {
   printf("[init error]lp_key is not null! key=\"%s\" \n", le->lp_k[inx].s_key);
   return LP_FAIL;
  }
  else
   le->lp_k[inx] = lp_sk[i];
 }
 memset(le->char_enum, 0, sizeof(le->char_enum));
 le->char_enum['\t']= l_skip;
 le->char_enum[' ']= l_skip;
 le->char_enum['\r'] = l_skip;
 le->char_enum['\n']= l_n;
 le->char_enum['_']= l_char;
 le->char_enum['{']= l_lb;
 le->char_enum['}']= l_rb;
 le->char_enum['=']= l_ass;
 le->char_enum['[']= l_ll;
 le->char_enum[']']= l_rl;
 le->char_enum[',']= l_ca;
 le->char_enum['#']= l_text;
 le->char_enum[';']= l_end;
 le->char_enum['.']= l_clo;
 for(i='a'; i<='z'; i++)
  le->char_enum[i] = l_char;
 for(i='A'; i<='Z'; i++)
  le->char_enum[i] = l_char;
 for(i='0'; i<='9'; i++)
  le->char_enum[i] = l_num;
 le->line = 1;
 do{if((_lp_list_new(&le->lex_list, sizeof(lp_token), 128, ((void *)0), (int (*)(void *))lp_lex_token_free))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

variable_types: i int


original_code:
int lp_lex(lp_lex_env* env_p, slice* buff)
{
 char at_char = 0;
 do{if((env_p)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((buff)==(((void *)0))) return ((LP_FAIL));}while(0);
 for(; (at_char=( (buff)&&((buff)->sp)&&(*((buff)->sp)) )?( *((char*)((buff)->sp)) ):(0))!=0 ; )
 {
  switch(( (env_p)->char_enum[(int)(at_char)] ))
  {
  case l_char:
   lp_lex_char(env_p, buff);
   break;
  case l_num:
   lp_lex_number(env_p, buff);
   break;
  case l_end:
   lp_add_token(env_p, lp_new_token(env_p, t_end, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_clo:
   {
    lp_add_token(env_p, lp_new_token(env_p, t_clo, lp_string_new(((void *)0))));
    next_char(buff);
    at_char=( (buff)&&((buff)->sp)&&(*((buff)->sp)) )?( *((char*)((buff)->sp)) ):(0);
    if(( (env_p)->char_enum[(int)(at_char)] ) != l_char)
    {
     printf("lex[error line: %d] token \".\" must be followed identifier!\n", env_p->line);
     return LP_FAIL;
    }
   }
   break;
  case l_ass:
   lp_add_token(env_p, lp_new_token(env_p, t_ass, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_lb:
   lp_add_token(env_p, lp_new_token(env_p, t_lb, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_ll:
   lp_add_token(env_p, lp_new_token(env_p, t_ll, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_rb:
   lp_add_token(env_p, lp_new_token(env_p, t_rb, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_ca:
   lp_add_token(env_p, lp_new_token(env_p, t_ca, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_rl:
   lp_add_token(env_p, lp_new_token(env_p, t_rl, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_text:
   {
    char lc = ( (buff)&&((buff)->sp)&&(*((buff)->sp)) )?( *((char*)((buff)->sp)) ):(0);
    for(; lc && lc!='\n'; )
    {
     next_char(buff);
     lc = ( (buff)&&((buff)->sp)&&(*((buff)->sp)) )?( *((char*)((buff)->sp)) ):(0);
    }
   }
   break;
  case l_n:
   (env_p->line)++;
  case l_skip:
   next_char(buff);
   break;
  default:
   printf("lex[error line: %d] find can not lex char!\n", env_p->line);
   return LP_FAIL;
  }
 }
 return LP_TRUE;
}

canonical_original_code:
int lp_lex(struct _lp_lex_env *env_p, struct _slice *buff)
{
 char at_char = 0;
 do{if((env_p)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((buff)==(((void *)0))) return ((LP_FAIL));}while(0);
 for(; (at_char=( (buff)&&((buff)->sp)&&(*((buff)->sp)) )?( *((char *)((buff)->sp)) ):(0))!=0 ; )
 {
  switch(( (env_p)->char_enum[(int)(at_char)] ))
  {
  case l_char:
   lp_lex_char(env_p, buff);
   break;
  case l_num:
   lp_lex_number(env_p, buff);
   break;
  case l_end:
   lp_add_token(env_p, lp_new_token(env_p, t_end, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_clo:
   {
    lp_add_token(env_p, lp_new_token(env_p, t_clo, lp_string_new(((void *)0))));
    next_char(buff);
    at_char=( (buff)&&((buff)->sp)&&(*((buff)->sp)) )?( *((char *)((buff)->sp)) ):(0);
    if(( (env_p)->char_enum[(int)(at_char)] ) != l_char)
    {
     printf("lex[error line: %d] token \".\" must be followed identifier!\n", env_p->line);
     return LP_FAIL;
    }
   }
   break;
  case l_ass:
   lp_add_token(env_p, lp_new_token(env_p, t_ass, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_lb:
   lp_add_token(env_p, lp_new_token(env_p, t_lb, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_ll:
   lp_add_token(env_p, lp_new_token(env_p, t_ll, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_rb:
   lp_add_token(env_p, lp_new_token(env_p, t_rb, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_ca:
   lp_add_token(env_p, lp_new_token(env_p, t_ca, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_rl:
   lp_add_token(env_p, lp_new_token(env_p, t_rl, lp_string_new(((void *)0))));
   next_char(buff);
   break;
  case l_text:
   {
    char lc = ( (buff)&&((buff)->sp)&&(*((buff)->sp)) )?( *((char*)((buff)->sp)) ):(0);
    for(; lc && lc!='\n'; )
    {
     next_char(buff);
     lc = ( (buff)&&((buff)->sp)&&(*((buff)->sp)) )?( *((char *)((buff)->sp)) ):(0);
    }
   }
   break;
  case l_n:
   (env_p->line)++;
  case l_skip:
   next_char(buff);
   break;
  default:
   printf("lex[error line: %d] find can not lex char!\n", env_p->line);
   return LP_FAIL;
  }
 }
 return LP_TRUE;
}

variable_types: lc char

user_defined_types: struct _slice { unsigned char *sp; unsigned char *b_sp; unsigned int sp_size; }


decompiled_code:
__int64 __fastcall llp_read_field(_QWORD *a1, __int64 a2, __int64 a3)
{
void *v6; // rax
__int64 v7; // rax
unsigned int v8; // er12
__int64 v9; // rbp
__int64 v10; // rax
__int64 v11; // rdi
__int64 v12; // rsi
__int64 v13; // rbp
__int64 v14; // rax
__int64 v16; // rax
char v17; // [rsp+1Fh] [rbp-49h] BYREF
__int64 v18; // [rsp+20h] [rbp-48h] BYREF
__int64 v19[8]; // [rsp+28h] [rbp-40h] BYREF

v6 = (void *)lp_malloc(24LL * *(unsigned int *)(a2 + 32));
*(_QWORD *)(a2 + 24) = v6;
memset(v6, 0, 24LL * *(unsigned int *)(a2 + 32));
v7 = lib_Fmap_new(*(unsigned int *)(a2 + 32));
*(_QWORD *)(a2 + 16) = v7;
if ( !v7 )
return 0LL;
if ( *(_DWORD *)(a2 + 32) )
{
v8 = 0;
while ( 1 )
{
v12 = *(_QWORD *)(a2 + 24);
v18 = 0LL;
v13 = 24LL * v8;
if ( !(unsigned int)sl_Rbyte(a3, v13 + v12) )
break;
if ( *(_BYTE *)(*(_QWORD *)(a2 + 24) + 24LL * v8) >> 3 == 4 )
{
v17 = 0;
v19[0] = 0LL;
if ( !(unsigned int)sl_Rbyte(a3, &v17) )
return 0LL;
if ( !(unsigned int)sl_Rstr(a3, v19) )
return 0LL;
v14 = lib_Mmap_find(*a1, v19[0]);
if ( !v14 )
{
if ( v17 )
return 0LL;
v16 = lib_stringpool_add(a1[1], v19[0]);
v14 = lib_Mmap_add(*a1, v16);
if ( !v14 )
return 0LL;
}
*(_QWORD *)(*(_QWORD *)(a2 + 24) + v13 + 16) = v14;
}
if ( !(unsigned int)sl_Rstr(a3, &v18) )
return 0LL;
v9 = *(_QWORD *)(a2 + 24) + v13;
v10 = lib_stringpool_add(a1[1], v18);
v11 = *(_QWORD *)(a2 + 16);
*(_QWORD *)(v9 + 8) = v10;
if ( !(unsigned int)lib_Fmap_add(v11, v10, v8) )
return 0LL;
if ( *(_DWORD *)(a2 + 32) <= ++v8 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, __int64 a3)
{
void *v6; // rax
__int64 v7; // rax
unsigned int v8; // er12
__int64 v9; // rbp
__int64 v10; // rax
__int64 v11; // rdi
__int64 v12; // rsi
__int64 v13; // rbp
__int64 v14; // rax
__int64 v16; // rax
char v17; // [rsp+1Fh] [rbp-49h] BYREF
__int64 v18; // [rsp+20h] [rbp-48h] BYREF
__int64 v19[8]; // [rsp+28h] [rbp-40h] BYREF

v6 = (void *)lp_malloc(24LL * *(unsigned int *)(a2 + 32));
*(_QWORD *)(a2 + 24) = v6;
memset(v6, 0, 24LL * *(unsigned int *)(a2 + 32));
v7 = lib_Fmap_new(*(unsigned int *)(a2 + 32));
*(_QWORD *)(a2 + 16) = v7;
if ( !v7 )
return 0LL;
if ( *(_DWORD *)(a2 + 32) )
{
v8 = 0;
while ( 1 )
{
v12 = *(_QWORD *)(a2 + 24);
v18 = 0LL;
v13 = 24LL * v8;
if ( !(unsigned int)sl_Rbyte(a3, v13 + v12) )
break;
if ( *(_BYTE *)(*(_QWORD *)(a2 + 24) + 24LL * v8) >> 3 == 4 )
{
v17 = 0;
v19[0] = 0LL;
if ( !(unsigned int)sl_Rbyte(a3, &v17) )
return 0LL;
if ( !(unsigned int)sl_Rstr(a3, v19) )
return 0LL;
v14 = lib_Mmap_find(*a1, v19[0]);
if ( !v14 )
{
if ( v17 )
return 0LL;
v16 = lib_stringpool_add(a1[1], v19[0]);
v14 = lib_Mmap_add(*a1, v16);
if ( !v14 )
return 0LL;
}
*(_QWORD *)(*(_QWORD *)(a2 + 24) + v13 + 16) = v14;
}
if ( !(unsigned int)sl_Rstr(a3, &v18) )
return 0LL;
v9 = *(_QWORD *)(a2 + 24) + v13;
v10 = lib_stringpool_add(a1[1], v18);
v11 = *(_QWORD *)(a2 + 16);
*(_QWORD *)(v9 + 8) = v10;
if ( !(unsigned int)lib_Fmap_add(v11, v10, v8) )
return 0LL;
if ( *(_DWORD *)(a2 + 32) <= ++v8 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

original_code:
static int llp_read_field(llp_env* env, t_def_mes* des_mes, slice* sl)
{
 llp_uint32 i=0;
 des_mes->message_tfl = (t_Mfield*)lp_malloc(sizeof(t_Mfield)*des_mes->message_count);
 memset(des_mes->message_tfl, 0, sizeof(t_Mfield)*des_mes->message_count);
 do{if((des_mes->message_field = lib_Fmap_new(des_mes->message_count))==(((void *)0))) return ((LP_FAIL));}while(0);
 for(i=0; i<des_mes->message_count; i++)
 {
  char* f_name = ((void *)0);
  do{if((sl_Rbyte(sl, &des_mes->message_tfl[i].tag))==(LP_FAIL)) return ((LP_FAIL));}while(0);
  if(( ((byte)des_mes->message_tfl[i].tag)>>3 ) == 4)
  {
   byte ei = 0;
   char* fms = ((void *)0);
   t_def_mes* mes_p = ((void *)0);
   do{if((sl_Rbyte(sl, &ei))==(LP_FAIL)) return ((LP_FAIL));}while(0);
   do{if((sl_Rstr(sl, &fms))==(LP_FAIL)) return ((LP_FAIL));}while(0);
   mes_p = lib_Mmap_find(env->dmes, fms);
   if(mes_p == ((void *)0) && !ei)
   {
    mes_p = lib_Mmap_add(env->dmes, lib_stringpool_add(env->mesN, fms));
    do{if((mes_p)==(((void *)0))) return ((LP_FAIL));}while(0);
   }else if(mes_p == ((void *)0) && ei)
   {
    return LP_FAIL;
   }
   des_mes->message_tfl[i].tms = mes_p;
  }
  do{if((sl_Rstr(sl, &f_name))==(LP_FAIL)) return ((LP_FAIL));}while(0);
  do{if((lib_Fmap_add(des_mes->message_field, des_mes->message_tfl[i].field_name = lib_stringpool_add(env->mesN, f_name), i))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 }
 return LP_TRUE;
}

canonical_original_code:
static int llp_read_field(struct llp_env *env, struct _t_def_mes *des_mes, struct _slice *sl)
{
 unsigned int i = 0;
 des_mes->message_tfl = (struct _t_Mfield *)lp_malloc(sizeof(t_Mfield)*des_mes->message_count);
 memset(des_mes->message_tfl, 0, sizeof(t_Mfield)*des_mes->message_count);
 do{if((des_mes->message_field = lib_Fmap_new(des_mes->message_count))==(((void *)0))) return ((LP_FAIL));}while(0);
 for(i=0; i<des_mes->message_count; i++)
 {
  char *f_name = ((void *)0);
  do{if((sl_Rbyte(sl, &des_mes->message_tfl[i].tag))==(LP_FAIL)) return ((LP_FAIL));}while(0);
  if(( ((unsigned char)des_mes->message_tfl[i].tag)>>3 ) == 4)
  {
   unsigned char ei = 0;
   char *fms = ((void *)0);
   struct _t_def_mes *mes_p = ((void *)0);
   do{if((sl_Rbyte(sl, &ei))==(LP_FAIL)) return ((LP_FAIL));}while(0);
   do{if((sl_Rstr(sl, &fms))==(LP_FAIL)) return ((LP_FAIL));}while(0);
   mes_p = lib_Mmap_find(env->dmes, fms);
   if(mes_p == ((void *)0) && !ei)
   {
    mes_p = lib_Mmap_add(env->dmes, lib_stringpool_add(env->mesN, fms));
    do{if((mes_p)==(((void *)0))) return ((LP_FAIL));}while(0);
   }else if(mes_p == ((void *)0) && ei)
   {
    return LP_FAIL;
   }
   des_mes->message_tfl[i].tms = mes_p;
  }
  do{if((sl_Rstr(sl, &f_name))==(LP_FAIL)) return ((LP_FAIL));}while(0);
  do{if((lib_Fmap_add(des_mes->message_field, des_mes->message_tfl[i].field_name = lib_stringpool_add(env->mesN, f_name), i))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 }
 return LP_TRUE;
}

variable_types: struct llp_env { struct _llp_map { unsigned long size; unsigned long cap; struct _llp_slot { unsigned long hash; char *key; void *vp; unsigned long next; } *table; } *dmes; struct _string_pool { struct _string_pool_slot { char *str; unsigned long len; struct _string_pool_slot *next; } *pool; struct _llp_map *string_table; } *mesN; } *

variable_types: struct _t_def_mes { unsigned int message_id; char *message_name; struct _field_map { unsigned long size; struct _field_slot { char *field_name; int id; unsigned long hash; unsigned long next; } *slot; } *message_field; struct _t_Mfield { unsigned char tag; char *field_name; struct _t_def_mes *tms; } *message_tfl; unsigned int message_count; } *

variable_types:
i
unsigned int

variable_types:
ei
unsigned char

variable_types:
fms
char *

user_defined_types: struct llp_env { struct _llp_map *dmes; struct _string_pool *mesN; }

user_defined_types: struct _t_def_mes { unsigned int message_id; char *message_name; struct _field_map *message_field; struct _t_Mfield *message_tfl; unsigned int message_count; }

user_defined_types: struct _llp_map { unsigned long size; unsigned long cap; struct _llp_slot *table; }

user_defined_types: struct _string_pool { struct _string_pool_slot *pool; struct _llp_map *string_table; }


decompiled_code:
__int64 __fastcall llp_read_message(__int64 *a1, __int64 *a2, __int64 a3)
{
__int64 v4; // rax
bool v5; // zf
__int64 result; // rax
__int64 v8; // rax
__int64 v9; // rdi
__int64 v10; // r13

if ( !a3 )
return 0LL;
if ( *(_QWORD *)a3 )
{
v4 = *(_QWORD *)a3 - *(_QWORD *)(a3 + 8);
v5 = (_DWORD)v4 == *(_DWORD *)(a3 + 16);
if ( (unsigned int)v4 <= *(_DWORD *)(a3 + 16) )
{
result = 4LL;
if ( v5 )
return result;
if ( (unsigned int)sl_Rstr(a3, a2) )
{
v8 = lib_stringpool_add(a1[1], *a2);
v9 = *a1;
*a2 = v8;
v10 = lib_Mmap_add(v9, v8);
if ( v10 )
{
*(_QWORD *)(v10 + 8) = *a2;
if ( (unsigned int)sl_Ruint(a3, v10) )
{
if ( (unsigned int)sl_Ruint(a3, v10 + 32) )
return (unsigned int)llp_read_field(a1, v10, a3) != 0;
}
}
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 *a2, __int64 a3)
{
__int64 v4; // rax
bool v5; // zf
__int64 result; // rax
__int64 v8; // rax
__int64 v9; // rdi
__int64 v10; // r13

if ( !a3 )
return 0LL;
if ( *(_QWORD *)a3 )
{
v4 = *(_QWORD *)a3 - *(_QWORD *)(a3 + 8);
v5 = (_DWORD)v4 == *(_DWORD *)(a3 + 16);
if ( (unsigned int)v4 <= *(_DWORD *)(a3 + 16) )
{
result = 4LL;
if ( v5 )
return result;
if ( (unsigned int)sl_Rstr(a3, a2) )
{
v8 = lib_stringpool_add(a1[1], *a2);
v9 = *a1;
*a2 = v8;
v10 = lib_Mmap_add(v9, v8);
if ( v10 )
{
*(_QWORD *)(v10 + 8) = *a2;
if ( (unsigned int)sl_Ruint(a3, v10) )
{
if ( (unsigned int)sl_Ruint(a3, v10 + 32) )
return (unsigned int)func0(a1, v10, a3) != 0;
}
}
}
}
}
return 0LL;
}

original_code:
static int llp_read_message(llp_env* env, char** out_name, slice* sl)
{
 t_def_mes* mes_p = ((void *)0);
 do{ if( (sl)==((void *)0) || (sl)->sp==((void *)0) || ((unsigned int)((sl)->sp-(sl)->b_sp))>(sl)->sp_size ) return LP_FAIL; else if( ((unsigned int)((sl)->sp-(sl)->b_sp))==(sl)->sp_size ) return LP_END; }while(0);
 do{if((sl_Rstr(sl, out_name))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 *out_name = lib_stringpool_add(env->mesN, *out_name);
 do{if((mes_p=lib_Mmap_add(env->dmes, *out_name))==(((void *)0))) return ((LP_FAIL));}while(0);
 mes_p->message_name = *out_name;
 do{if((sl_Ruint(sl, &(mes_p->message_id)))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 do{if((sl_Ruint(sl, &(mes_p->message_count)))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 do{if((llp_read_field(env, mes_p, sl))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

canonical_original_code:
static int llp_read_message(struct llp_env *env, char **out_name, struct _slice *sl)
{
 struct _t_def_mes *mes_p = ((void *)0);
 do{ if( (sl)==((void *)0) || (sl)->sp==((void *)0) || ((unsigned int)((sl)->sp-(sl)->b_sp))>(sl)->sp_size ) return LP_FAIL; else if( ((unsigned int)((sl)->sp-(sl)->b_sp))==(sl)->sp_size ) return LP_END; }while(0);
 do{if((sl_Rstr(sl, out_name))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 *out_name = lib_stringpool_add(env->mesN, *out_name);
 do{if((mes_p=lib_Mmap_add(env->dmes, *out_name))==(((void *)0))) return ((LP_FAIL));}while(0);
 mes_p->message_name = *out_name;
 do{if((sl_Ruint(sl, &(mes_p->message_id)))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 do{if((sl_Ruint(sl, &(mes_p->message_count)))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 do{if((llp_read_field(env, mes_p, sl))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

user_defined_types: struct _t_Mfield { unsigned char tag; char *field_name; struct _t_def_mes *tms; }

user_defined_types: struct _llp_slot { unsigned long hash; char *key; void *vp; unsigned long next; }

user_defined_types: struct _string_pool_slot { char *str; unsigned long len; struct _string_pool_slot *next; }

user_defined_types: struct _field_slot { char *field_name; int id; unsigned long hash; unsigned long next; }


decompiled_code:
__int64 __fastcall llp_reg_mes_value(__int64 *a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

v3[0] = 0LL;
if ( !a2 || !*a2 )
return 0LL;
while ( 1 )
{
result = llp_read_message(a1, v3, (__int64)a2);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 4 )
return 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3[4]; // [rsp+8h] [rbp-20h] BYREF

v3[0] = 0LL;
if ( !a2 || !*a2 )
return 0LL;
while ( 1 )
{
result = func1(a1, v3, (__int64)a2);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 4 )
return 1LL;
}
return result;
}

original_code:
static int llp_reg_mes_value(llp_env* env, slice* sl)
{
 char* out_name = ((void *)0);
 do{if((sl)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((sl->sp)==(((void *)0))) return ((LP_FAIL));}while(0);
 for(;;)
 {
  switch(llp_read_message(env, &out_name, sl))
  {
  case LP_FAIL:
   return LP_FAIL;
  case LP_END:
   return LP_TRUE;
  }
 }
}

canonical_original_code:
static int llp_reg_mes_value(struct llp_env *env, struct _slice *sl)
{
 char *out_name = ((void *)0);
 do{if((sl)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((sl->sp)==(((void *)0))) return ((LP_FAIL));}while(0);
 for(;;)
 {
  switch(llp_read_message(env, &out_name, sl))
  {
  case LP_FAIL:
   return LP_FAIL;
  case LP_END:
   return LP_TRUE;
  }
 }
}


decompiled_code:
_QWORD *llp_new_env()
{
_QWORD *v0; // r12

v0 = (_QWORD *)lp_malloc(16LL);
*v0 = lib_map_new();
v0[1] = lib_stringpool_new();
return v0;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *v0; // r12

v0 = (_QWORD *)lp_malloc(16LL);
*v0 = lib_map_new();
v0[1] = lib_stringpool_new();
return v0;
}

original_code:
extern llp_env* llp_new_env()
{
 llp_env* ret = ((void *)0);
 ret=(llp_env*)lp_malloc(sizeof(llp_env));
 ret->dmes = lib_map_new();
 ret->mesN = lib_stringpool_new();
 return ret;
}

canonical_original_code:
extern struct llp_env *llp_new_env()
{
 struct llp_env *ret = ((void *)0);
 ret=(struct llp_env *)lp_malloc(sizeof(llp_env));
 ret->dmes = lib_map_new();
 ret->mesN = lib_stringpool_new();
 return ret;
}

return_type: struct llp_env { struct _llp_map { unsigned long size; unsigned long cap; struct _llp_slot { unsigned long hash; char *key; void *vp; unsigned long next; } *table; } *dmes; struct _string_pool { struct _string_pool_slot { char *str; unsigned long len; struct _string_pool_slot *next; } *pool; struct _llp_map *string_table; } *mesN; } *


decompiled_code:
__int64 __fastcall llp_free_env(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
lib_Mmap_free(*a1);
lib_stringpool_free(a1[1]);
result = lp_free(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
lib_Mmap_free(*a1);
lib_stringpool_free(a1[1]);
result = lp_free(a1);
}
return result;
}

original_code:
extern void llp_free_env(llp_env* p)
{
 if(p)
 {
  lib_Mmap_free(p->dmes);
  lib_stringpool_free(p->mesN);
  lp_free(p);
 }
}

canonical_original_code:
extern void llp_free_env(struct llp_env *p)
{
 if(p)
 {
  lib_Mmap_free(p->dmes);
  lib_stringpool_free(p->mesN);
  lp_free(p);
 }
}


decompiled_code:
_BOOL8 __fastcall llp_reg_Smes(__int64 *a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 && a2 && *(_QWORD *)(a2 + 8) )
{
if ( *(_DWORD *)(a2 + 16) )
result = (unsigned int)llp_reg_mes_value(a1, (_QWORD *)a2) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 *a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 && a2 && *(_QWORD *)(a2 + 8) )
{
if ( *(_DWORD *)(a2 + 16) )
result = (unsigned int)func2(a1, (_QWORD *)a2) != 0;
}
return result;
}

original_code:
extern int llp_reg_Smes(llp_env* env, slice* buff)
{
 do{if((env)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((buff)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((buff->b_sp)==(((void *)0))) return ((LP_FAIL));}while(0);
 if(buff->sp_size == 0) return LP_FAIL;
 do{if((llp_reg_mes_value(env, buff))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

canonical_original_code:
extern int llp_reg_Smes(struct llp_env *env, struct _slice *buff)
{
 do{if((env)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((buff)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((buff->b_sp)==(((void *)0))) return ((LP_FAIL));}while(0);
 if(buff->sp_size == 0) return LP_FAIL;
 do{if((llp_reg_mes_value(env, buff))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}


decompiled_code:
__int64 __fastcall lp_table_new(_QWORD *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
{
a1[128] = 0LL;
result = 1LL;
*a1 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
{
a1[128] = 0LL;
result = 1LL;
*a1 = 0LL;
}
return result;
}

original_code:
int lp_table_new(lp_table* lp_t)
{
 do{if((lp_t)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_t->table_len = 0;
 memset(lp_t->table_list, 0, sizeof(lp_table_one*));
 return LP_TRUE;
}

canonical_original_code:
int lp_table_new(struct _lp_table *lp_t)
{
 do{if((lp_t)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_t->table_len = 0;
 memset(lp_t->table_list, 0, sizeof(struct _lp_table_one *));
 return LP_TRUE;
}

variable_types: struct _lp_table { struct _lp_table_one { int value; struct _lp_string { struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; } str; } name; struct _lp_table_one *next; } *table_list[128]; unsigned long table_len; } *

user_defined_types: struct _lp_table { struct _lp_table_one *table_list[128]; unsigned long table_len; }

user_defined_types: struct _lp_table_one { int value; struct _lp_string name; struct _lp_table_one *next; }


decompiled_code:
__int64 __fastcall lp_table_query(__int64 a1, char *a2)
{
__int64 v2; // rbx

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8LL * (int)BKDRHash(a2, 0x80u));
if ( !v2 )
return 0LL;
while ( strcmp(*(const char **)(v2 + 32), a2) )
{
v2 = *(_QWORD *)(v2 + 64);
if ( !v2 )
return 0LL;
}
return v2;
}

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

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8LL * (int)func0(a2, 0x80u));
if ( !v2 )
return 0LL;
while ( strcmp(*(const char **)(v2 + 32), a2) )
{
v2 = *(_QWORD *)(v2 + 64);
if ( !v2 )
return 0LL;
}
return v2;
}

original_code:
int* lp_table_query(lp_table* lp_t, char* name)
{
 lp_table_one* lt_o = ((void *)0);
 int inx =0;
 do{if((lp_t)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((name)==(((void *)0))) return ((((void *)0)));}while(0);
 inx = _BKDRHash(name, 128);
 lt_o = lp_t->table_list[inx];
 while(lt_o)
 {
  if(strcmp((char*)lt_o->name.str.list_p, name)==0)
   return &(lt_o->value);
  lt_o = lt_o->next;
 }
 return ((void *)0);
}

canonical_original_code:
int *lp_table_query(struct _lp_table *lp_t, char *name)
{
 struct _lp_table_one *lt_o = ((void *)0);
 int inx = 0;
 do{if((lp_t)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((name)==(((void *)0))) return ((((void *)0)));}while(0);
 inx = _BKDRHash(name, 128);
 lt_o = lp_t->table_list[inx];
 while(lt_o)
 {
  if(strcmp((char *)lt_o->name.str.list_p, name)==0)
   return &(lt_o->value);
  lt_o = lt_o->next;
 }
 return ((void *)0);
}

variable_types:
name
char *

variable_types: struct _lp_table_one { int value; struct _lp_string { struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; } str; } name; struct _lp_table_one *next; } *


original_code:
int lp_table_add(lp_table* lp_t, char* name, int value)
{
 lp_table_one* head = ((void *)0);
 int inx = 0;
 do{if((lp_t)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((name)==(((void *)0))) return ((LP_FAIL));}while(0);
 inx = _BKDRHash(name, 128);
 head = lp_t->table_list[inx];
 if(head==((void *)0))
 {
  lp_t->table_list[inx] = (lp_table_one*)lp_malloc(sizeof(lp_table_one));
  memset(lp_t->table_list[inx], 0, sizeof(lp_table_one));
  lp_t->table_list[inx]->name = lp_string_new(name);
  lp_t->table_list[inx]->value = value;
 }
 else
 {
  lp_table_one* back = ((void *)0);
  while(head)
  {
   if(strcmp((char*)head->name.str.list_p, name)==0)
    return LP_EXIST;
   back = head;
   head = head->next;
  }
  back->next = (lp_table_one*)lp_malloc(sizeof(lp_table_one));
  memset(back->next, 0, sizeof(lp_table_one));
  back->next->name = lp_string_new(name);
  back->next->value = value;
 }
 return LP_TRUE;
}

canonical_original_code:
int lp_table_add(struct _lp_table *lp_t, char *name, int value)
{
 struct _lp_table_one *head = ((void *)0);
 int inx = 0;
 do{if((lp_t)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((name)==(((void *)0))) return ((LP_FAIL));}while(0);
 inx = _BKDRHash(name, 128);
 head = lp_t->table_list[inx];
 if(head==((void *)0))
 {
  lp_t->table_list[inx] = (struct _lp_table_one *)lp_malloc(sizeof(lp_table_one));
  memset(lp_t->table_list[inx], 0, sizeof(lp_table_one));
  lp_t->table_list[inx]->name = lp_string_new(name);
  lp_t->table_list[inx]->value = value;
 }
 else
 {
  struct _lp_table_one *back = ((void *)0);
  while(head)
  {
   if(strcmp((char *)head->name.str.list_p, name)==0)
    return LP_EXIST;
   back = head;
   head = head->next;
  }
  back->next = (struct _lp_table_one *)lp_malloc(sizeof(lp_table_one));
  memset(back->next, 0, sizeof(lp_table_one));
  back->next->name = lp_string_new(name);
  back->next->value = value;
 }
 return LP_TRUE;
}

variable_types: value int


decompiled_code:
__int64 __fastcall lp_string_cats(__int64 a1, const char *a2)
{
size_t v3; // rbx
const char *v4; // rsi

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v3 = 0LL;
do
{
v4 = &a2[v3++];
lp_list_add(a1, v4);
}
while ( strlen(a2) + 1 > v3 );
--*(_QWORD *)(a1 + 8);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
size_t v3; // rbx
const char *v4; // rsi

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v3 = 0LL;
do
{
v4 = &a2[v3++];
lp_list_add(a1, v4);
}
while ( strlen(a2) + 1 > v3 );
--*(_QWORD *)(a1 + 8);
return a1;
}

original_code:
lp_string* lp_string_cats(lp_string* lp_s, char* str)
{
 size_t i=0;
 do{if((lp_s)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((str)==(((void *)0))) return ((((void *)0)));}while(0);
 for(i=0; i<strlen(str)+1; i++)
  lp_list_add(&lp_s->str, (byte*)(str+i));
 lp_s->str.list_len--;
 return lp_s;
}

canonical_original_code:
struct _lp_string *lp_string_cats(struct _lp_string *lp_s, char *str)
{
 unsigned long i = 0;
 do{if((lp_s)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((str)==(((void *)0))) return ((((void *)0)));}while(0);
 for(i=0; i<strlen(str)+1; i++)
  lp_list_add(&lp_s->str, (unsigned char *)(str+i));
 lp_s->str.list_len--;
 return lp_s;
}

variable_types:
i
unsigned long

return_type: struct _lp_string { struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; } str; } *


decompiled_code:
__int64 __fastcall lp_string_cat(__int64 a1, char a2)
{
char v3[19]; // [rsp+Ch] [rbp-1Ch] BYREF
char v4[9]; // [rsp+1Fh] [rbp-9h] BYREF

v3[0] = a2;
v4[0] = 0;
if ( a1 )
{
lp_list_add(a1, v3);
lp_list_add(a1, v4);
--*(_QWORD *)(a1 + 8);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
char v3[19]; // [rsp+Ch] [rbp-1Ch] BYREF
char v4[9]; // [rsp+1Fh] [rbp-9h] BYREF

v3[0] = a2;
v4[0] = 0;
if ( a1 )
{
lp_list_add(a1, v3);
lp_list_add(a1, v4);
--*(_QWORD *)(a1 + 8);
}
return a1;
}

original_code:
lp_string* lp_string_cat(lp_string* lp_s, char at_char)
{
 char a = 0;
 do{if((lp_s)==(((void *)0))) return ((((void *)0)));}while(0);
 lp_list_add(&lp_s->str, (byte*)(&at_char));
 lp_list_add(&lp_s->str, (byte*)(&a));
 lp_s->str.list_len--;
 return lp_s;
}

canonical_original_code:
struct _lp_string *lp_string_cat(struct _lp_string *lp_s, char at_char)
{
 char a = 0;
 do{if((lp_s)==(((void *)0))) return ((((void *)0)));}while(0);
 lp_list_add(&lp_s->str, (unsigned char *)(&at_char));
 lp_list_add(&lp_s->str, (unsigned char *)(&a));
 lp_s->str.list_len--;
 return lp_s;
}

variable_types: a char


decompiled_code:
void __fastcall lp_string_clear(__int64 a1)
{
if ( a1 )
*(_QWORD *)(a1 + 8) = 0LL;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
if ( a1 )
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void lp_string_clear(lp_string* lp_s)
{
 if(lp_s==((void *)0))
  return;
 lp_s->str.list_len = 0;
}

canonical_original_code:
void lp_string_clear(struct _lp_string *lp_s)
{
 if(lp_s==((void *)0))
  return;
 lp_s->str.list_len = 0;
}

variable_types: struct _lp_string { struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; } str; } *


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

if ( a1 )
result = lp_list_free();
return result;
}

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

if ( a1 )
result = lp_list_free();
return result;
}

original_code:
void lp_string_free(lp_string* lp_s)
{
 if(lp_s==((void *)0))
  return;
 lp_list_free(&lp_s->str);
}

canonical_original_code:
void lp_string_free(struct _lp_string *lp_s)
{
 if(lp_s==((void *)0))
  return;
 lp_list_free(&lp_s->str);
}


decompiled_code:
__int64 __fastcall lp_table_one_free(__int64 a1)
{
if ( !a1 )
return 0LL;
lp_string_free(a1 + 8);
lp_free(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( !a1 )
return 0LL;
func7(a1 + 8);
lp_free(a1);
return 1LL;
}

original_code:
int lp_table_one_free(lp_table_one* lt_o)
{
 do{if((lt_o)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_string_free(&lt_o->name);
 lp_free(lt_o);
 return LP_TRUE;
}

canonical_original_code:
int lp_table_one_free(struct _lp_table_one *lt_o)
{
 do{if((lt_o)==(((void *)0))) return ((LP_FAIL));}while(0);
 lp_string_free(&lt_o->name);
 lp_free(lt_o);
 return LP_TRUE;
}


decompiled_code:
__int64 __fastcall lp_table_free(__int64 *a1)
{
__int64 *v1; // r12
__int64 *v2; // rbp
__int64 v3; // rbx
__int64 v4; // rdi

if ( !a1 )
return 0LL;
v1 = a1 + 128;
v2 = a1;
do
{
while ( 1 )
{
v3 = *v2;
if ( *v2 )
break;
if ( v1 == ++v2 )
return 1LL;
}
do
{
v4 = v3;
v3 = *(_QWORD *)(v3 + 64);
lp_table_one_free(v4);
}
while ( v3 );
*v2++ = 0LL;
}
while ( v1 != v2 );
return 1LL;
}

original_code:
int lp_table_free(lp_table* lp_t)
{
 int i=0;
 do{if((lp_t)==(((void *)0))) return ((LP_FAIL));}while(0);
 for(i=0; i<128; i++)
 {
  if(lp_t->table_list[i])
  {
   lp_table_one* lt_o = lp_t->table_list[i];
   while(lt_o)
   {
    lp_table_one* nt = lt_o->next;
    lp_table_one_free(lt_o);
    lt_o = nt;
   }
   lp_t->table_list[i] = ((void *)0);
  }
 }
 return LP_TRUE;
}

canonical_original_code:
int lp_table_free(struct _lp_table *lp_t)
{
 int i = 0;
 do{if((lp_t)==(((void *)0))) return ((LP_FAIL));}while(0);
 for(i=0; i<128; i++)
 {
  if(lp_t->table_list[i])
  {
   struct _lp_table_one *lt_o = lp_t->table_list[i];
   while(lt_o)
   {
    struct _lp_table_one *nt = lt_o->next;
    lp_table_one_free(lt_o);
    lt_o = nt;
   }
   lp_t->table_list[i] = ((void *)0);
  }
 }
 return LP_TRUE;
}


decompiled_code:
__int64 __fastcall lp_list_relloc(_QWORD *a1)
{
void *v2; // rdi
unsigned __int64 v3; // rsi
__int64 result; // rax
unsigned __int64 v5; // rsi
void *v6; // rax

if ( !a1 )
return 0LL;
v2 = (void *)a1[3];
if ( !v2 )
return 0LL;
v3 = a1[2];
result = 2LL;
if ( a1[1] >= v3 )
{
v5 = *a1 + v3;
a1[2] = v5;
v6 = realloc(v2, a1[6] * v5);
a1[3] = v6;
result = v6 != 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
void *v2; // rdi
unsigned __int64 v3; // rsi
__int64 result; // rax
unsigned __int64 v5; // rsi
void *v6; // rax

if ( !a1 )
return 0LL;
v2 = (void *)a1[3];
if ( !v2 )
return 0LL;
v3 = a1[2];
result = 2LL;
if ( a1[1] >= v3 )
{
v5 = *a1 + v3;
a1[2] = v5;
v6 = realloc(v2, a1[6] * v5);
a1[3] = v6;
result = v6 != 0LL;
}
return result;
}

original_code:
int lp_list_relloc(lp_list* lp_l)
{
 do{if((lp_l)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((lp_l->list_p)==(((void *)0))) return ((LP_FAIL));}while(0);
 if(lp_l->list_len < lp_l->list_size)
  return LP_NIL;
 do{if((lp_l->list_p=realloc(lp_l->list_p, (lp_l->list_size+=lp_l->list_def_size)*lp_l->one_size))==(((void *)0))) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

canonical_original_code:
int lp_list_relloc(struct _lp_list *lp_l)
{
 do{if((lp_l)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((lp_l->list_p)==(((void *)0))) return ((LP_FAIL));}while(0);
 if(lp_l->list_len < lp_l->list_size)
  return LP_NIL;
 do{if((lp_l->list_p=realloc(lp_l->list_p, (lp_l->list_size+=lp_l->list_def_size)*lp_l->one_size))==(((void *)0))) return ((LP_FAIL));}while(0);
 return LP_TRUE;
}

variable_types: struct _lp_list { unsigned long list_def_size; unsigned long list_len; unsigned long list_size; unsigned char *list_p; int (*new_func)(void *); int (*free_func)(void *); unsigned long one_size; } *


decompiled_code:
__int64 __fastcall lp_list_add(_QWORD *a1, const void *a2)
{
void (__fastcall *v2)(const void *); // rax

if ( !a1 )
return 0LL;
if ( !a1[3] || !a2 || !(unsigned int)lp_list_relloc(a1) )
return 0LL;
v2 = (void (__fastcall *)(const void *))a1[4];
if ( v2 )
v2(a2);
memcpy((void *)(a1[3] + a1[6] * a1[1]++), a2, a1[6]);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, const void *a2)
{
void (__fastcall *v2)(const void *); // rax

if ( !a1 )
return 0LL;
if ( !a1[3] || !a2 || !(unsigned int)func1(a1) )
return 0LL;
v2 = (void (__fastcall *)(const void *))a1[4];
if ( v2 )
v2(a2);
memcpy((void *)(a1[3] + a1[6] * a1[1]++), a2, a1[6]);
return 1LL;
}

original_code:
int lp_list_add(lp_list* lp_l, byte* data_p)
{
 do{if((lp_l)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((lp_l->list_p)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((data_p)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((lp_list_relloc(lp_l))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 if(lp_l->new_func)
  lp_l->new_func(data_p);
 memcpy((lp_l->list_p + lp_l->one_size*lp_l->list_len), data_p, lp_l->one_size);
 (lp_l->list_len)++;
 return LP_TRUE;
}

canonical_original_code:
int lp_list_add(struct _lp_list *lp_l, unsigned char *data_p)
{
 do{if((lp_l)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((lp_l->list_p)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((data_p)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((lp_list_relloc(lp_l))==(LP_FAIL)) return ((LP_FAIL));}while(0);
 if(lp_l->new_func)
  lp_l->new_func(data_p);
 memcpy((lp_l->list_p + lp_l->one_size*lp_l->list_len), data_p, lp_l->one_size);
 (lp_l->list_len)++;
 return LP_TRUE;
}


decompiled_code:
__int64 __fastcall lp_list_inx(_QWORD *a1, unsigned __int64 a2)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = a1[3];
if ( !result )
return result;
if ( a1[1] <= a2 )
return 0LL;
result += a1[6] * a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, unsigned __int64 a2)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = a1[3];
if ( !result )
return result;
if ( a1[1] <= a2 )
return 0LL;
result += a1[6] * a2;
return result;
}

original_code:
void* lp_list_inx(lp_list* lp_l, size_t inx)
{
 do{if((lp_l)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((lp_l->list_p)==(((void *)0))) return ((((void *)0)));}while(0);
 return (inx>=lp_l->list_len)?(((void *)0)):( (void*)(&lp_l->list_p[lp_l->one_size*inx]) );
}

canonical_original_code:
void *lp_list_inx(struct _lp_list *lp_l, unsigned long inx)
{
 do{if((lp_l)==(((void *)0))) return ((((void *)0)));}while(0);
 do{if((lp_l->list_p)==(((void *)0))) return ((((void *)0)));}while(0);
 return (inx>=lp_l->list_len)?(((void *)0)):( (void *)(&lp_l->list_p[lp_l->one_size*inx]) );
}

variable_types:
inx
unsigned long

return_type: void *


original_code:
int lp_list_free(lp_list* lp_l)
{
 size_t i=0;
 do{if((lp_l)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((lp_l->list_p)==(((void *)0))) return ((LP_NIL));}while(0);
 for(i=0; i<lp_l->list_len; i++)
 {
  if(lp_l->free_func)
   lp_l->free_func(lp_list_inx(lp_l, i));
 }
 lp_free(lp_l->list_p);
 memset(lp_l, 0, sizeof(lp_list));
 return LP_TRUE;
}

canonical_original_code:
int lp_list_free(struct _lp_list *lp_l)
{
 unsigned long i = 0;
 do{if((lp_l)==(((void *)0))) return ((LP_FAIL));}while(0);
 do{if((lp_l->list_p)==(((void *)0))) return ((LP_NIL));}while(0);
 for(i=0; i<lp_l->list_len; i++)
 {
  if(lp_l->free_func)
   lp_l->free_func(lp_list_inx(lp_l, i));
 }
 lp_free(lp_l->list_p);
 memset(lp_l, 0, sizeof(lp_list));
 return LP_TRUE;
}


decompiled_code:
void *__fastcall lp_malloc(size_t size)
{
++mem_lens;
return malloc(size);
}

canonical_decompiled_code:
void *__fastcall func1(size_t size)
{
++mem_lens;
return malloc(size);
}

original_code:
void* lp_malloc(size_t len)
{
 mem_lens++;
 return malloc(len);
}

canonical_original_code:
void *lp_malloc(unsigned long len)
{
 mem_lens++;
 return malloc(len);
}

variable_types:
len
unsigned long


decompiled_code:
void __fastcall lp_free(void *a1)
{
if ( a1 )
{
--mem_lens;
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
if ( a1 )
{
--mem_lens;
free(a1);
}
}

original_code:
void lp_free(void* p)
{
 if(p==((void *)0))
  return;
 mem_lens--;
 free(p);
}

canonical_original_code:
void lp_free(void *p)
{
 if(p==((void *)0))
  return;
 mem_lens--;
 free(p);
}

variable_types:
p
void *


decompiled_code:
int print_mem()
{
return printf("mem = %lu\n", mem_lens);
}

canonical_decompiled_code:
int func3()
{
return printf("mem = %lu\n", mem_lens);
}

original_code:
void print_mem()
{
 printf("mem = %lu\n", mem_lens);
}


trieInit

repo: lxc-xx/SimpleLZW

decompiled_code:
__int64 trieInit()
{
_QWORD *v0; // rax
_QWORD *v1; // rdx
__int64 result; // rax

v0 = malloc(0x808uLL);
TRIE_TREE = (__int64)v0;
if ( v0 )
{
v1 = v0;
memset(v0, 0, 0x800uLL);
result = 1LL;
v1[256] = 0LL;
}
else
{
fwrite(" error: cannot initiate a trie \n", 1uLL, 0x20uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
_QWORD *v0; // rax
_QWORD *v1; // rdx
__int64 result; // rax

v0 = malloc(0x808uLL);
TRIE_TREE = (__int64)v0;
if ( v0 )
{
v1 = v0;
memset(v0, 0, 0x800uLL);
result = 1LL;
v1[256] = 0LL;
}
else
{
fwrite(" error: cannot initiate a trie \n", 1uLL, 0x20uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int trieInit()
{
 TRIE_TREE = ( Trie )malloc ( sizeof( TrieRoot ) );
 if( TRIE_TREE == ((void *)0) )
 {
  fprintf( stderr , " error: cannot initiate a trie \n" );
  return 0;
 }
 else
 {
  int i;
  for( i = 0 ; i < 256 ; ++i )
  {
   TRIE_TREE->child[ i ] = ((void *)0);
  }
  TRIE_TREE->size = 0;
  return 1;
 }
}

canonical_original_code:
int trieInit()
{
 TRIE_TREE = ( struct RootType * )malloc ( sizeof( TrieRoot ) );
 if( TRIE_TREE == ((void *)0) )
 {
  fprintf( stderr , " error: cannot initiate a trie \n" );
  return 0;
 }
 else
 {
  int i;
  for( i = 0 ; i < 256 ; ++i )
  {
   TRIE_TREE->child[ i ] = ((void *)0);
  }
  TRIE_TREE->size = 0;
  return 1;
 }
}

variable_types: i int

user_defined_types: struct RootType { struct NodeType *child[256]; unsigned long size; }

user_defined_types: struct NodeType { struct NodeType *child[256]; int key; unsigned char character; }


nodeDestruct

decompiled_code:
void **__fastcall nodeDestruct(void *ptr)
{
void **result; // rax

if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(&Dic, 0, 0xFDE8uLL);
trieInit();
}
result = (void **)ptr;
while ( !*result )
{
if ( ++result == (void **)((char *)ptr + 2048) )
return result;
}
if ( (unsigned int)nodeDestruct(*result) == 1 )
{
free(ptr);
result = (void **)(trieInit + 1);
}
else
{
fwrite("error: cannot destruct node \n ", 1uLL, 0x1EuLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void **__fastcall func1(void *ptr)
{
void **result; // rax

if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(&Dic, 0, 0xFDE8uLL);
func0();
}
result = (void **)ptr;
while ( !*result )
{
if ( ++result == (void **)((char *)ptr + 2048) )
return result;
}
if ( (unsigned int)func1(*result) == 1 )
{
free(ptr);
result = (void **)(trieInit + 1);
}
else
{
fwrite("error: cannot destruct node \n ", 1uLL, 0x1EuLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int nodeDestruct( TrieNode *node )
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void*)Dic , 0 , (65000) );
  trieInit();
 }
 int i;
 for( i = 0 ; i < 256 ; ++i )
 {
  if( node->child[ i ] != ((void *)0) )
  {
   if( nodeDestruct( node->child[ i ] ) != 1 )
   {
    fprintf( stderr , "error: cannot destruct node \n " );
    return 0;
   }
   else
   {
    free( node );
    return 1;
   }
  }
 }
}

canonical_original_code:
int nodeDestruct(struct NodeType *node)
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void *)Dic , 0 , (65000) );
  trieInit();
 }
 int i;
 for( i = 0 ; i < 256 ; ++i )
 {
  if( node->child[ i ] != ((void *)0) )
  {
   if( nodeDestruct( node->child[ i ] ) != 1 )
   {
    fprintf( stderr , "error: cannot destruct node \n " );
    return 0;
   }
   else
   {
    free( node );
    return 1;
   }
  }
 }
}

variable_types: struct NodeType { struct NodeType *child[256]; int key; unsigned char character; } *


trieDestruct

decompiled_code:
__int64 __fastcall trieDestruct(void **a1)
{
void **v1; // rbx

v1 = a1;
if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(&Dic, 0, 0xFDE8uLL);
trieInit();
}
do
{
if ( *v1 && (unsigned int)nodeDestruct(*v1) != 1 )
{
fwrite("error: cannot destruct node \n ", 1uLL, 0x1EuLL, stderr);
return 0LL;
}
++v1;
}
while ( v1 != a1 + 256 );
return 1LL;
}

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

v1 = a1;
if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(&Dic, 0, 0xFDE8uLL);
func0();
}
do
{
if ( *v1 && (unsigned int)func1(*v1) != 1 )
{
fwrite("error: cannot destruct node \n ", 1uLL, 0x1EuLL, stderr);
return 0LL;
}
++v1;
}
while ( v1 != a1 + 256 );
return 1LL;
}

original_code:
int trieDestruct( Trie root )
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void*)Dic , 0 , (65000) );
  trieInit();
 }
 int i;
 for( i = 0 ; i < 256 ; ++i )
 {
  if( root->child[ i ] != ((void *)0) )
  {
   if( nodeDestruct( root->child[ i ] ) != 1 )
   {
    fprintf( stderr , "error: cannot destruct node \n " );
    return 0;
   }
  }
 }
 return 1;
}

canonical_original_code:
int trieDestruct(struct RootType *root)
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void *)Dic , 0 , (65000) );
  trieInit();
 }
 int i;
 for( i = 0 ; i < 256 ; ++i )
 {
  if( root->child[ i ] != ((void *)0) )
  {
   if( nodeDestruct( root->child[ i ] ) != 1 )
   {
    fprintf( stderr , "error: cannot destruct node \n " );
    return 0;
   }
  }
 }
 return 1;
}

variable_types: struct RootType { struct NodeType { struct NodeType *child[256]; int key; unsigned char character; } *child[256]; unsigned long size; } *


trieSearch

decompiled_code:
__int64 __fastcall trieSearch(char *s)
{
__int64 v1; // r12
__int64 v2; // rbp
size_t v3; // rcx
__int64 v4; // rax
__int64 v5; // rdx

if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(&Dic, 0, 0xFDE8uLL);
trieInit();
v2 = TRIE_TREE;
if ( TRIE_TREE )
goto LABEL_3;
}
else
{
v2 = TRIE_TREE;
if ( TRIE_TREE )
goto LABEL_3;
}
trieInit();
v2 = TRIE_TREE;
LABEL_3:
v3 = strlen(s);
if ( v3 - 1 <= 0x31 )
{
v4 = 0LL;
while ( 1 )
{
v5 = (unsigned __int8)s[v4];
if ( v4 )
{
v1 = *(_QWORD *)(v1 + 8 * v5);
if ( !v1 )
return v1;
}
else
{
v1 = *(_QWORD *)(v2 + 8 * v5);
if ( !v1 )
return v1;
}
if ( v3 == ++v4 )
return v1;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s)
{
__int64 v1; // r12
__int64 v2; // rbp
size_t v3; // rcx
__int64 v4; // rax
__int64 v5; // rdx

if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(&Dic, 0, 0xFDE8uLL);
func0();
v2 = TRIE_TREE;
if ( TRIE_TREE )
goto LABEL_3;
}
else
{
v2 = TRIE_TREE;
if ( TRIE_TREE )
goto LABEL_3;
}
func0();
v2 = TRIE_TREE;
LABEL_3:
v3 = strlen(s);
if ( v3 - 1 <= 0x31 )
{
v4 = 0LL;
while ( 1 )
{
v5 = (unsigned __int8)s[v4];
if ( v4 )
{
v1 = *(_QWORD *)(v1 + 8 * v5);
if ( !v1 )
return v1;
}
else
{
v1 = *(_QWORD *)(v2 + 8 * v5);
if ( !v1 )
return v1;
}
if ( v3 == ++v4 )
return v1;
}
}
return 0LL;
}

original_code:
TrieNode *trieSearch( const unsigned char *name )
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void*)Dic , 0 , (65000) );
  trieInit();
 }
 if( TRIE_TREE == ((void *)0) )
 {
  trieInit();
 }
 Trie root = TRIE_TREE;
 TrieNode * node;
 unsigned char target;
 size_t size = strlen( name );
 if( size == 0 || size > (50) )
 {
  return ((void *)0);
 }
 int i;
 int key;
 for( i = 0 ; i < size ; ++i )
 {
  target = (unsigned char) ( name[ i ] );
  if( (size_t)target >= 256 || (size_t)target < 0 )
  {
   printf( "bad target: %c\n" , target );
   printf( "name: %s i: %d\n" , name , i );
   exit( 1 );
  }
  if( i == 0 )
  {
   node = root->child[ (size_t)target ];
  }
  else
  {
   node = node->child[ (size_t)target ];
  }
  if( node == ((void *)0) )
  {
   return ((void *)0);
  }
 }
 return node;
}

canonical_original_code:
struct NodeType *trieSearch(unsigned char *name)
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void *)Dic , 0 , (65000) );
  trieInit();
 }
 if( TRIE_TREE == ((void *)0) )
 {
  trieInit();
 }
 struct RootType *root = TRIE_TREE;
 struct NodeType *node;
 unsigned char target;
 unsigned long size = strlen( name );
 if( size == 0 || size > (50) )
 {
  return ((void *)0);
 }
 int i;
 int key;
 for( i = 0 ; i < size ; ++i )
 {
  target = (unsigned char) ( name[ i ] );
  if( (unsigned long)target >= 256 || (unsigned long)target < 0 )
  {
   printf( "bad target: %c\n" , target );
   printf( "name: %s i: %d\n" , name , i );
   exit( 1 );
  }
  if( i == 0 )
  {
   node = root->child[ (unsigned long)target ];
  }
  else
  {
   node = node->child[ (unsigned long)target ];
  }
  if( node == ((void *)0) )
  {
   return ((void *)0);
  }
 }
 return node;
}

variable_types:
name
unsigned char *

variable_types:
target
unsigned char

variable_types:
size
unsigned long

variable_types: key int

return_type: struct NodeType { struct NodeType *child[256]; int key; unsigned char character; } *


dicSearchString

decompiled_code:
__int64 __fastcall dicSearchString(char *s)
{
__int64 v1; // rax
__int64 result; // rax

if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(&Dic, 0, 0xFDE8uLL);
trieInit();
}
v1 = trieSearch(s);
if ( v1 )
result = *(unsigned int *)(v1 + 2048);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s)
{
__int64 v1; // rax
__int64 result; // rax

if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(&Dic, 0, 0xFDE8uLL);
func0();
}
v1 = func3(s);
if ( v1 )
result = *(unsigned int *)(v1 + 2048);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int dicSearchString( const unsigned char *name )
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void*)Dic , 0 , (65000) );
  trieInit();
 }
 TrieNode *node = trieSearch( name );
 if( node == ((void *)0) )
 {
  return -1;
 }
 else
 {
  return node->key;
 }
}

canonical_original_code:
int dicSearchString(unsigned char *name)
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void *)Dic , 0 , (65000) );
  trieInit();
 }
 struct NodeType *node = trieSearch( name );
 if( node == ((void *)0) )
 {
  return -1;
 }
 else
 {
  return node->key;
 }
}


dicInsert

decompiled_code:
__int64 __fastcall dicInsert(char *s)
{
_QWORD *v1; // rbx
size_t v2; // rax
__int64 v3; // r12
char *v4; // rax

if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(Dic, 0, 0xFDE8uLL);
trieInit();
}
if ( (unsigned __int64)Dic_Size <= 0xFDE7 )
{
v1 = trieInsert(s);
if ( v1 )
{
v2 = strlen(s);
v3 = Dic_Size;
v4 = (char *)malloc(v2 + 1);
Dic[v3] = (__int64)v4;
if ( v4 )
{
strcpy(v4, s);
Dic_Size = v3 + 1;
return *((unsigned int *)v1 + 512);
}
fwrite("error: cannot insert to dictionary\n", 1uLL, 0x23uLL, stderr);
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s)
{
_QWORD *v1; // rbx
size_t v2; // rax
__int64 v3; // r12
char *v4; // rax

if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(Dic, 0, 0xFDE8uLL);
func0();
}
if ( (unsigned __int64)Dic_Size <= 0xFDE7 )
{
v1 = trieInsert(s);
if ( v1 )
{
v2 = strlen(s);
v3 = Dic_Size;
v4 = (char *)malloc(v2 + 1);
Dic[v3] = (__int64)v4;
if ( v4 )
{
strcpy(v4, s);
Dic_Size = v3 + 1;
return *((unsigned int *)v1 + 512);
}
fwrite("error: cannot insert to dictionary\n", 1uLL, 0x23uLL, stderr);
}
}
return 0xFFFFFFFFLL;
}

original_code:
int dicInsert( const unsigned char *name )
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset((void*)Dic , 0 , (65000) );
  trieInit();
 }
 if( Dic_Size < (65000) )
 {
  TrieNode *node = trieInsert( name );
  if( node == ((void *)0) )
  {
   return -1;
  }
  else
  {
   Dic[ Dic_Size ] = ( unsigned char* )malloc( strlen( name ) + 1 );
   if ( Dic[ Dic_Size ] == ((void *)0) )
   {
    fprintf( stderr , "error: cannot insert to dictionary\n" );
    return -1;
   }
   strcpy( Dic[ Dic_Size ] , name );
   Dic_Size++;
   return node->key;
  }
 }
 else
 {
  return -1;
 }
}

canonical_original_code:
int dicInsert(unsigned char *name)
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset((void *)Dic , 0 , (65000) );
  trieInit();
 }
 if( Dic_Size < (65000) )
 {
  struct NodeType *node = trieInsert( name );
  if( node == ((void *)0) )
  {
   return -1;
  }
  else
  {
   Dic[ Dic_Size ] = ( unsigned char * )malloc( strlen( name ) + 1 );
   if ( Dic[ Dic_Size ] == ((void *)0) )
   {
    fprintf( stderr , "error: cannot insert to dictionary\n" );
    return -1;
   }
   strcpy( Dic[ Dic_Size ] , name );
   Dic_Size++;
   return node->key;
  }
 }
 else
 {
  return -1;
 }
}


dicSearchCode

decompiled_code:
__int64 __fastcall dicSearchCode(unsigned __int16 a1)
{
__int64 result; // rax

if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(Dic, 0, 0xFDE8uLL);
trieInit();
}
result = 0LL;
if ( (unsigned __int16)(a1 - 256) <= 0xFDE7u )
result = Dic[a1 - 256];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int16 a1)
{
__int64 result; // rax

if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(Dic, 0, 0xFDE8uLL);
func0();
}
result = 0LL;
if ( (unsigned __int16)(a1 - 256) <= 0xFDE7u )
result = Dic[a1 - 256];
return result;
}

original_code:
unsigned char* dicSearchCode( const unsigned short i )
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void*)Dic , 0 , (65000) );
  trieInit();
 }
 if( i-256 >= 0 && i-256 < (65000) )
 {
  return Dic[ i - 256 ];
 }
 else
 {
  return ((void *)0);
 }
}

canonical_original_code:
unsigned char *dicSearchCode(unsigned short i)
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void *)Dic , 0 , (65000) );
  trieInit();
 }
 if( i-256 >= 0 && i-256 < (65000) )
 {
  return Dic[ i - 256 ];
 }
 else
 {
  return ((void *)0);
 }
}

variable_types:
i
unsigned short

return_type: unsigned char *


dicSize

decompiled_code:
__int64 dicSize()
{
if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(Dic, 0, 0xFDE8uLL);
trieInit();
}
return *(_QWORD *)(TRIE_TREE + 2048);
}

canonical_decompiled_code:
__int64 func10()
{
if ( FIRST_FLAG )
{
FIRST_FLAG = 0;
memset(Dic, 0, 0xFDE8uLL);
func0();
}
return *(_QWORD *)(TRIE_TREE + 2048);
}

original_code:
size_t dicSize()
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void*)Dic , 0 , (65000) );
  trieInit();
 }
 return TRIE_TREE->size;
}

canonical_original_code:
unsigned long dicSize()
{
 if( FIRST_FLAG )
 {
  FIRST_FLAG =0;
  memset( (void *)Dic , 0 , (65000) );
  trieInit();
 }
 return TRIE_TREE->size;
}

return_type: unsigned long


writeInt

decompiled_code:
size_t __fastcall writeInt(__int16 a1)
{
size_t result; // rax
size_t v2; // rdx

result = POS_OUT;
v2 = POS_OUT + 1;
if ( POS_OUT > 0xFFF )
{
fwrite(BUF_OUT, 2uLL, 0x1000uLL, OUT);
v2 = 1LL;
result = 0LL;
}
BUF_OUT[result] = a1;
POS_OUT = v2;
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(__int16 a1)
{
size_t result; // rax
size_t v2; // rdx

result = POS_OUT;
v2 = POS_OUT + 1;
if ( POS_OUT > 0xFFF )
{
fwrite(BUF_OUT, 2uLL, 0x1000uLL, OUT);
v2 = 1LL;
result = 0LL;
}
BUF_OUT[result] = a1;
POS_OUT = v2;
return result;
}

original_code:
void writeInt( unsigned short i )
{
 if( POS_OUT >= (4096) )
 {
  fwrite( BUF_OUT , sizeof( unsigned short int ) , (4096) , OUT );
  POS_OUT = 0;
 }
 BUF_OUT[ POS_OUT++ ] = i;
}

canonical_original_code:
void writeInt(unsigned short i)
{
 if( POS_OUT >= (4096) )
 {
  fwrite( BUF_OUT , sizeof( unsigned short ) , (4096) , OUT );
  POS_OUT = 0;
 }
 BUF_OUT[ POS_OUT++ ] = i;
}


readInt

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

if ( (unsigned __int64)POS_IN >= SIZE_NOW_0 )
{
SIZE_NOW_0 = fread(BUF_IN, 2uLL, 0x1000uLL, IN);
if ( !SIZE_NOW_0 )
EMPTY_FLAG = 1;
result = BUF_IN[0];
POS_IN = writeInt + 1;
}
else
{
result = BUF_IN[(_QWORD)POS_IN];
POS_IN = (char *)POS_IN + 1;
}
return result;
}

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

if ( (unsigned __int64)POS_IN >= SIZE_NOW_0 )
{
SIZE_NOW_0 = fread(BUF_IN, 2uLL, 0x1000uLL, IN);
if ( !SIZE_NOW_0 )
EMPTY_FLAG = 1;
result = BUF_IN[0];
POS_IN = writeInt + 1;
}
else
{
result = BUF_IN[(_QWORD)POS_IN];
POS_IN = (char *)POS_IN + 1;
}
return result;
}

original_code:
unsigned short readInt()
{
 static size_t SIZE_NOW = 0;
 if( POS_IN >= SIZE_NOW )
 {
  SIZE_NOW = fread( BUF_IN , sizeof( unsigned short int ) , (4096) , IN );
  POS_IN = 0;
  if( SIZE_NOW == 0 )
  {
   EMPTY_FLAG = 1;
  }
 }
 return BUF_IN[ POS_IN++ ];
}

canonical_original_code:
unsigned short readInt()
{
 static unsigned long SIZE_NOW = 0;
 if( POS_IN >= SIZE_NOW )
 {
  SIZE_NOW = fread( BUF_IN , sizeof( unsigned short ) , (4096) , IN );
  POS_IN = 0;
  if( SIZE_NOW == 0 )
  {
   EMPTY_FLAG = 1;
  }
 }
 return BUF_IN[ POS_IN++ ];
}

return_type: unsigned short


synFile

decompiled_code:
size_t synFile()
{
return fwrite(BUF_OUT, 2uLL, POS_OUT, OUT);
}

canonical_decompiled_code:
size_t func2()
{
return fwrite(BUF_OUT, 2uLL, POS_OUT, OUT);
}

original_code:
void synFile()
{
 fwrite( BUF_OUT , sizeof( unsigned short int ) , POS_OUT, OUT );
}

canonical_original_code:
void synFile()
{
 fwrite( BUF_OUT , sizeof( unsigned short ) , POS_OUT, OUT );
}


lzw

decompiled_code:
__int64 lzw()
{
int v0; // eax
char v1; // bp
size_t v2; // rax
size_t v3; // rbx
__int16 v4; // r12
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

v6[0] = 0;
while ( 1 )
{
v0 = getc(IN);
v1 = v0;
if ( v0 == -1 )
return 1LL;
v2 = strlen(v6);
v3 = v2;
if ( !v2 )
goto LABEL_12;
if ( v2 == 1 )
{
v4 = (unsigned __int8)v6[0];
goto LABEL_6;
}
v4 = dicSearchString(v6);
if ( v3 == 50 )
{
LABEL_11:
writeInt(v4);
LABEL_12:
v6[0] = v1;
v6[1] = 0;
}
else
{
LABEL_6:
v6[(int)v3] = v1;
v6[(int)v3 + 1] = 0;
if ( (unsigned int)dicSearchString(v6) == -1 && (unsigned __int64)dicSize() <= 0xFDE7 )
{
if ( (unsigned int)dicInsert(v6) == -1 )
{
fwrite("error: cannot insert to dictionary\n", 1uLL, 0x23uLL, stderr);
return 0LL;
}
goto LABEL_11;
}
}
}
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
char v1; // bp
size_t v2; // rax
size_t v3; // rbx
__int16 v4; // r12
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

v6[0] = 0;
while ( 1 )
{
v0 = getc(IN);
v1 = v0;
if ( v0 == -1 )
return 1LL;
v2 = strlen(v6);
v3 = v2;
if ( !v2 )
goto LABEL_12;
if ( v2 == 1 )
{
v4 = (unsigned __int8)v6[0];
goto LABEL_6;
}
v4 = dicSearchString(v6);
if ( v3 == 50 )
{
LABEL_11:
func0(v4);
LABEL_12:
v6[0] = v1;
v6[1] = 0;
}
else
{
LABEL_6:
v6[(int)v3] = v1;
v6[(int)v3 + 1] = 0;
if ( (unsigned int)dicSearchString(v6) == -1 && (unsigned __int64)dicSize() <= 0xFDE7 )
{
if ( (unsigned int)dicInsert(v6) == -1 )
{
fwrite("error: cannot insert to dictionary\n", 1uLL, 0x23uLL, stderr);
return 0LL;
}
goto LABEL_11;
}
}
}
}

original_code:
int lzw()
{
 unsigned char str[(50) + 1];
 unsigned char ch;
 int ich = 0;
 str[ 0 ] = '\0';
 while( ( ich = getc( IN ) ) != (-1) )
 {
  ch = ( unsigned char ) ich;
  int length = strlen( str );
  int insert_code;
  int out_code;
  if( length == 0 )
  {
   str[ 0 ] = ch;
   str[ 1 ] = '\0';
   continue;
  }
  if( length == 1 )
  {
   out_code = (int)( str[ 0 ] );
  }
  else
  {
   out_code = dicSearchString( str );
  }
  if( length < (50) && length > 0 )
  {
   str[ length ] = ch;
   str[ length + 1 ] = '\0';
   if( dicSearchString( str ) == -1 && ( length != 0 ) )
   {
    if( dicSize() < (65000))
    {
     if ( ( insert_code = dicInsert( str ) ) != -1 )
     {
      writeInt( out_code );
      str[ 0 ] = ch;
      str[ 1 ] = '\0';
     }
     else
     {
      fprintf( stderr , "error: cannot insert to dictionary\n" );
      return 0;
     }
    }
   }
  }
  else
  {
   writeInt( out_code );
   str[ 0 ] = ch;
   str[ 1 ] = '\0';
  }
 }
 return 1;
}

canonical_original_code:
int lzw()
{
 unsigned char str[-1];
 unsigned char ch;
 int ich = 0;
 str[ 0 ] = '\0';
 while( ( ich = getc( IN ) ) != (-1) )
 {
  ch = ( unsigned char ) ich;
  int length = strlen( str );
  int insert_code;
  int out_code;
  if( length == 0 )
  {
   str[ 0 ] = ch;
   str[ 1 ] = '\0';
   continue;
  }
  if( length == 1 )
  {
   out_code = (int)( str[ 0 ] );
  }
  else
  {
   out_code = dicSearchString( str );
  }
  if( length < (50) && length > 0 )
  {
   str[ length ] = ch;
   str[ length + 1 ] = '\0';
   if( dicSearchString( str ) == -1 && ( length != 0 ) )
   {
    if( dicSize() < (65000))
    {
     if ( ( insert_code = dicInsert( str ) ) != -1 )
     {
      writeInt( out_code );
      str[ 0 ] = ch;
      str[ 1 ] = '\0';
     }
     else
     {
      fprintf( stderr , "error: cannot insert to dictionary\n" );
      return 0;
     }
    }
   }
  }
  else
  {
   writeInt( out_code );
   str[ 0 ] = ch;
   str[ 1 ] = '\0';
  }
 }
 return 1;
}

variable_types:
str
unsigned char [-1]

variable_types:
ch
unsigned char

variable_types: ich int

variable_types: length int


dlzw

decompiled_code:
__int64 dlzw()
{
size_t v0; // rbx
unsigned __int16 v1; // ax
const char *v2; // rsi
char v3; // al
signed __int64 v5; // rax
char v6[64]; // [rsp+0h] [rbp-98h] BYREF
char s[88]; // [rsp+40h] [rbp-58h] BYREF

v6[0] = 0;
s[0] = 0;
while ( 1 )
{
v1 = readInt();
if ( EMPTY_FLAG )
break;
if ( v1 <= 0xFFu )
{
v6[0] = v1;
v6[1] = 0;
}
else
{
v2 = (const char *)dicSearchCode(v1);
if ( v2 )
{
strcpy(v6, v2);
}
else
{
v5 = stpcpy(v6, s) - v6;
if ( v5 != 50 )
*(_WORD *)&v6[v5] = (unsigned __int8)s[0];
}
}
fputs(v6, OUT);
v0 = strlen(s);
if ( v0 - 1 <= 0x30 && (unsigned __int64)dicSize() <= 0xFDE7 )
{
v3 = v6[0];
s[v0 + 1] = 0;
s[v0] = v3;
if ( (unsigned int)dicInsert(s) == -1 )
{
fwrite("error: cannot insert to dictionary\n", 1uLL, 0x23uLL, stderr);
return 0LL;
}
}
strcpy(s, v6);
}
fputc(10, OUT);
return 1LL;
}

canonical_decompiled_code:
__int64 func4()
{
size_t v0; // rbx
unsigned __int16 v1; // ax
const char *v2; // rsi
char v3; // al
signed __int64 v5; // rax
char v6[64]; // [rsp+0h] [rbp-98h] BYREF
char s[88]; // [rsp+40h] [rbp-58h] BYREF

v6[0] = 0;
s[0] = 0;
while ( 1 )
{
v1 = func1();
if ( EMPTY_FLAG )
break;
if ( v1 <= 0xFFu )
{
v6[0] = v1;
v6[1] = 0;
}
else
{
v2 = (const char *)dicSearchCode(v1);
if ( v2 )
{
strcpy(v6, v2);
}
else
{
v5 = stpcpy(v6, s) - v6;
if ( v5 != 50 )
*(_WORD *)&v6[v5] = (unsigned __int8)s[0];
}
}
fputs(v6, OUT);
v0 = strlen(s);
if ( v0 - 1 <= 0x30 && (unsigned __int64)dicSize() <= 0xFDE7 )
{
v3 = v6[0];
s[v0 + 1] = 0;
s[v0] = v3;
if ( (unsigned int)dicInsert(s) == -1 )
{
fwrite("error: cannot insert to dictionary\n", 1uLL, 0x23uLL, stderr);
return 0LL;
}
}
strcpy(s, v6);
}
fputc(10, OUT);
return 1LL;
}

original_code:
int dlzw()
{
 unsigned short k;
 unsigned char entry[(50) + 1];
 unsigned char s[(50) + 1];
 entry [ 0 ] = '\0';
 s [ 0 ] = '\0';
 unsigned char *search_rel = ((void *)0);
 while( 1 )
 {
  k = readInt();
  if( EMPTY_FLAG )
  {
   break;
  }
  if( k < 256 )
  {
   entry[ 0 ] = (unsigned char)k;
   entry[ 1 ] = '\0';
  }
  else
  {
   search_rel = dicSearchCode( k );
   if( search_rel != ((void *)0) )
   {
    strcpy( entry , search_rel );
   }
   else
   {
    strcpy( entry , s );
    size_t entry_l = strlen( entry );
    if( entry_l < (50) )
    {
     entry[ entry_l ] = s[ 0 ];
     entry[ entry_l + 1 ] = '\0';
    }
   }
  }
  fputs( entry , OUT );
  size_t s_l = strlen( s );
  if( s_l < (50) && s_l > 0 && dicSize() < (65000) )
  {
   s[ s_l ] = entry[ 0 ];
   s[ s_l + 1 ] = '\0';
   int insert_rel = dicInsert( s );
   if ( insert_rel == -1 )
   {
    fprintf( stderr , "error: cannot insert to dictionary\n" );
    return 0;
   }
   else
   {
   }
  }
  strcpy( s , entry );
 }
 fputs( "\n" , OUT );
 return 1;
}

canonical_original_code:
int dlzw()
{
 unsigned short k;
 unsigned char entry[-1];
 unsigned char s[-1];
 entry [ 0 ] = '\0';
 s [ 0 ] = '\0';
 unsigned char *search_rel = ((void *)0);
 while( 1 )
 {
  k = readInt();
  if( EMPTY_FLAG )
  {
   break;
  }
  if( k < 256 )
  {
   entry[ 0 ] = (unsigned char)k;
   entry[ 1 ] = '\0';
  }
  else
  {
   search_rel = dicSearchCode( k );
   if( search_rel != ((void *)0) )
   {
    strcpy( entry , search_rel );
   }
   else
   {
    strcpy( entry , s );
    unsigned long entry_l = strlen( entry );
    if( entry_l < (50) )
    {
     entry[ entry_l ] = s[ 0 ];
     entry[ entry_l + 1 ] = '\0';
    }
   }
  }
  fputs( entry , OUT );
  unsigned long s_l = strlen( s );
  if( s_l < (50) && s_l > 0 && dicSize() < (65000) )
  {
   s[ s_l ] = entry[ 0 ];
   s[ s_l + 1 ] = '\0';
   int insert_rel = dicInsert( s );
   if ( insert_rel == -1 )
   {
    fprintf( stderr , "error: cannot insert to dictionary\n" );
    return 0;
   }
   else
   {
   }
  }
  strcpy( s , entry );
 }
 fputs( "\n" , OUT );
 return 1;
}

variable_types:
k
unsigned short

variable_types:
entry
unsigned char [-1]

variable_types:
s
unsigned char [-1]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
int v4; // er12
char *v5; // r13
int v6; // eax
const char *v7; // rsi
size_t v9; // rbx
char *v10; // rax
size_t v11; // rdx
char *v12; // rbx

if ( argc <= 1 )
{
LABEL_14:
v7 = help;
LABEL_12:
printf("%s", v7);
exit(1);
}
v3 = argv[1];
if ( !v3 )
fwrite("error: cannot get the input file\n", 1uLL, 0x21uLL, stderr);
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "o:hvd");
if ( v6 == -1 )
break;
if ( v6 == 111 )
{
v5 = optarg;
}
else if ( v6 > 111 )
{
if ( v6 == 118 )
{
v7 = version[0];
goto LABEL_12;
}
}
else if ( v6 == 100 )
{
v4 = 1;
}
else if ( v6 == 104 )
{
goto LABEL_14;
}
}
if ( !v5 )
{
v9 = strlen(v3);
v10 = (char *)malloc(v9 + 5);
v5 = v10;
if ( !v10 )
{
fwrite("error: memory error\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
v11 = v9;
v12 = &v10[v9];
memcpy(v10, v3, v11);
strcpy(v12, ".lzw");
}
IN = fopen(v3, "r");
OUT = fopen(v5, "w");
if ( v4 )
{
dlzw();
}
else
{
lzw();
synFile();
}
fclose(IN);
fclose(OUT);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
int v4; // er12
char *v5; // r13
int v6; // eax
const char *v7; // rsi
size_t v9; // rbx
char *v10; // rax
size_t v11; // rdx
char *v12; // rbx

if ( argc <= 1 )
{
LABEL_14:
v7 = help;
LABEL_12:
printf("%s", v7);
exit(1);
}
v3 = argv[1];
if ( !v3 )
fwrite("error: cannot get the input file\n", 1uLL, 0x21uLL, stderr);
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "o:hvd");
if ( v6 == -1 )
break;
if ( v6 == 111 )
{
v5 = optarg;
}
else if ( v6 > 111 )
{
if ( v6 == 118 )
{
v7 = version[0];
goto LABEL_12;
}
}
else if ( v6 == 100 )
{
v4 = 1;
}
else if ( v6 == 104 )
{
goto LABEL_14;
}
}
if ( !v5 )
{
v9 = strlen(v3);
v10 = (char *)malloc(v9 + 5);
v5 = v10;
if ( !v10 )
{
fwrite("error: memory error\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
v11 = v9;
v12 = &v10[v9];
memcpy(v10, v3, v11);
strcpy(v12, ".lzw");
}
IN = fopen(v3, "r");
OUT = fopen(v5, "w");
if ( v4 )
{
func4();
}
else
{
func3();
func2();
}
fclose(IN);
fclose(OUT);
return 1;
}

original_code:
int main( int argc , char **argv )
{
 unsigned char *in_file_name = ((void *)0);
 unsigned char *out_file_name = ((void *)0);
 int result = 0;
 int decom_flag = 0;
 if( argc >= 2 )
 {
  in_file_name = argv[ 1 ];
 }
 else
 {
  printf( "%s" , help );
  exit( 1 );
 }
 if( in_file_name == ((void *)0) )
 {
  fprintf( stderr , "error: cannot get the input file\n" );
 }
 while ( (result = getopt( argc , argv , "o:hvd" ) ) != -1 )
 {
  switch ( result )
  {
   case 'h':
    printf( "%s" , help );
    exit( 1 );
   case 'v':
    printf( "%s" , version );
    exit( 1 );
   case 'o':
    out_file_name = optarg;
    break;
   case 'd':
    decom_flag = 1;
    break;
  }
 }
 if( out_file_name == ((void *)0) )
 {
  out_file_name = (unsigned char *)malloc( strlen( in_file_name ) + 1 + 4 );
  if( out_file_name == ((void *)0) )
  {
   fprintf( stderr , "error: memory error\n" );
   exit(1);
  }
  strcpy( out_file_name , in_file_name );
  strcat( out_file_name , ".lzw" );
 }
 IN = fopen( in_file_name , "r" );
 OUT = fopen( out_file_name , "w" );
 if( decom_flag )
 {
  dlzw();
 }
 else
 {
  lzw();
  synFile();
 }
 fclose( IN );
 fclose( OUT );
 return 1;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned char *in_file_name = ((void *)0);
 unsigned char *out_file_name = ((void *)0);
 int result = 0;
 int decom_flag = 0;
 if( argc >= 2 )
 {
  in_file_name = argv[ 1 ];
 }
 else
 {
  printf( "%s" , help );
  exit( 1 );
 }
 if( in_file_name == ((void *)0) )
 {
  fprintf( stderr , "error: cannot get the input file\n" );
 }
 while ( (result = getopt( argc , argv , "o:hvd" ) ) != -1 )
 {
  switch ( result )
  {
   case 'h':
    printf( "%s" , help );
    exit( 1 );
   case 'v':
    printf( "%s" , version );
    exit( 1 );
   case 'o':
    out_file_name = optarg;
    break;
   case 'd':
    decom_flag = 1;
    break;
  }
 }
 if( out_file_name == ((void *)0) )
 {
  out_file_name = (unsigned char *)malloc( strlen( in_file_name ) + 1 + 4 );
  if( out_file_name == ((void *)0) )
  {
   fprintf( stderr , "error: memory error\n" );
   exit(1);
  }
  strcpy( out_file_name , in_file_name );
  strcat( out_file_name , ".lzw" );
 }
 IN = fopen( in_file_name , "r" );
 OUT = fopen( out_file_name , "w" );
 if( decom_flag )
 {
  dlzw();
 }
 else
 {
  lzw();
  synFile();
 }
 fclose( IN );
 fclose( OUT );
 return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: result int


doUndo

repo: lxdfigo/shedit

decompiled_code:
void doUndo()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void doUndo(){
}

canonical_original_code:
void doUndo(){
}


doCut

decompiled_code:
__int64 doCut()
{
__int64 result; // rax
__int64 v1; // rdx
bool v2; // zf
__int64 v3; // rcx
__int64 v4; // rsi

result = textInput[136];
if ( result )
{
v1 = *(_QWORD *)(result + 16);
v2 = result == textInput[135];
textInput[134] = v1;
if ( v2 )
textInput[135] = *(_QWORD *)(result + 8);
v3 = textInput[137];
if ( v1 )
*(_QWORD *)(v1 + 8) = *(_QWORD *)(v3 + 8);
v4 = *(_QWORD *)(v3 + 8);
if ( v4 )
*(_QWORD *)(v4 + 16) = v1;
textInput[139] = result;
textInput[140] = v3;
result = resetState();
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
__int64 v1; // rdx
bool v2; // zf
__int64 v3; // rcx
__int64 v4; // rsi

result = textInput[136];
if ( result )
{
v1 = *(_QWORD *)(result + 16);
v2 = result == textInput[135];
textInput[134] = v1;
if ( v2 )
textInput[135] = *(_QWORD *)(result + 8);
v3 = textInput[137];
if ( v1 )
*(_QWORD *)(v1 + 8) = *(_QWORD *)(v3 + 8);
v4 = *(_QWORD *)(v3 + 8);
if ( v4 )
*(_QWORD *)(v4 + 16) = v1;
textInput[139] = result;
textInput[140] = v3;
result = resetState();
}
return result;
}

original_code:
void doCut(){
 if (textInput.selected_begin == ((void *)0)) return;
 textInput.curElement = textInput.selected_begin->previous;
 if (textInput.selected_begin == textInput.beginElement){
  textInput.beginElement = textInput.selected_begin->next;
 }
 if (textInput.selected_begin->previous != ((void *)0)){
  textInput.selected_begin->previous->next = textInput.selected_end->next;
 }
 if (textInput.selected_end->next != ((void *)0)){
  textInput.selected_end->next->previous = textInput.selected_begin->previous;
 }
 textInput.copy_begin = textInput.selected_begin;
 textInput.copy_end = textInput.selected_end;
 resetState();
}


doCopy

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

result = textInput[136];
if ( result )
{
textInput[139] = result;
textInput[140] = textInput[137];
copyElements((char **)(unsigned int)((_DWORD)textInput + 1112), (__int64 *)(unsigned int)((_DWORD)textInput + 1120));
result = resetState();
}
return result;
}

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

result = textInput[136];
if ( result )
{
textInput[139] = result;
textInput[140] = textInput[137];
func3((char **)(unsigned int)((_DWORD)textInput + 1112), (__int64 *)(unsigned int)((_DWORD)textInput + 1120));
result = resetState();
}
return result;
}

original_code:
void doCopy(){
 if (textInput.selected_begin == ((void *)0)) return;
 textInput.copy_begin = textInput.selected_begin;
 textInput.copy_end = textInput.selected_end;
 copyElements(&textInput.copy_begin,&textInput.copy_end);
 resetState();
}


doPaste

decompiled_code:
__int64 doPaste()
{
__int64 result; // rax
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // rsi
__int64 v4; // rdx

result = textInput[139];
if ( result )
{
v1 = textInput[134];
v2 = textInput[140];
if ( v1 )
{
v3 = *(_QWORD *)(v1 + 8);
if ( v3 )
*(_QWORD *)(v3 + 16) = v2;
*(_QWORD *)(v2 + 8) = v3;
*(_QWORD *)(v1 + 8) = result;
*(_QWORD *)(result + 16) = v1;
}
else
{
v4 = textInput[135];
if ( v4 )
*(_QWORD *)(v4 + 16) = v2;
*(_QWORD *)(v2 + 8) = v4;
textInput[135] = result;
}
textInput[134] = v2;
textInput[139] = 0LL;
textInput[140] = 0LL;
result = resetState();
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // rsi
__int64 v4; // rdx

result = textInput[139];
if ( result )
{
v1 = textInput[134];
v2 = textInput[140];
if ( v1 )
{
v3 = *(_QWORD *)(v1 + 8);
if ( v3 )
*(_QWORD *)(v3 + 16) = v2;
*(_QWORD *)(v2 + 8) = v3;
*(_QWORD *)(v1 + 8) = result;
*(_QWORD *)(result + 16) = v1;
}
else
{
v4 = textInput[135];
if ( v4 )
*(_QWORD *)(v4 + 16) = v2;
*(_QWORD *)(v2 + 8) = v4;
textInput[135] = result;
}
textInput[134] = v2;
textInput[139] = 0LL;
textInput[140] = 0LL;
result = resetState();
}
return result;
}

original_code:
void doPaste(){
 if (textInput.copy_begin == ((void *)0)) return;
 Element *el = textInput.curElement;
 if (el == ((void *)0)){
  el = textInput.beginElement;
  if (el != ((void *)0))
   el->previous = textInput.copy_end;
  textInput.copy_end->next = el;
  textInput.beginElement = textInput.copy_begin;
 }else{
  if (el->next != ((void *)0))
   el->next->previous = textInput.copy_end;
  textInput.copy_end->next = el->next;
  el->next = textInput.copy_begin;
  textInput.copy_begin->previous = el;
 }
 textInput.curElement = textInput.copy_end;
 textInput.copy_begin = ((void *)0);
 textInput.copy_end = ((void *)0);
 resetState();
}

canonical_original_code:
void doPaste(){
 if (textInput.copy_begin == ((void *)0)) return;
 struct _Element *el = textInput.curElement;
 if (el == ((void *)0)){
  el = textInput.beginElement;
  if (el != ((void *)0))
   el->previous = textInput.copy_end;
  textInput.copy_end->next = el;
  textInput.beginElement = textInput.copy_begin;
 }else{
  if (el->next != ((void *)0))
   el->next->previous = textInput.copy_end;
  textInput.copy_end->next = el->next;
  el->next = textInput.copy_begin;
  textInput.copy_begin->previous = el;
 }
 textInput.curElement = textInput.copy_end;
 textInput.copy_begin = ((void *)0);
 textInput.copy_end = ((void *)0);
 resetState();
}

variable_types: struct _Element { char c; char isSelected; struct _Element *next; struct _Element *previous; struct _Word { int type; struct _Element *begin; struct _Element *end; int count; struct _Word *next; struct _Word *previous; } *father; } *

user_defined_types: struct _Element { char c; char isSelected; struct _Element *next; struct _Element *previous; struct _Word *father; }


doSearch

decompiled_code:
int doSearch()
{
return printw("do Search\n");
}

canonical_decompiled_code:
int func6()
{
return printw("do Search\n");
}

original_code:
void doSearch(){
 printw("do Search\n");
}


doEdit

decompiled_code:
int doEdit()
{
int result; // eax

result = *((_DWORD *)&shSystem + 1);
if ( result == 2 )
return doPaste();
if ( result > 2 )
{
if ( result == 3 )
result = doSearch();
}
else if ( result )
{
if ( result == 1 )
result = doCopy();
}
else
{
result = doCut();
}
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax

result = *((_DWORD *)&shSystem + 1);
if ( result == 2 )
return func5();
if ( result > 2 )
{
if ( result == 3 )
result = func6();
}
else if ( result )
{
if ( result == 1 )
result = func4();
}
else
{
result = func2();
}
return result;
}

original_code:
void doEdit(){
 switch(shSystem.menuSection){
  case 0:
   doCut();
   break;
  case 1:
   doCopy();
   break;
  case 2:
   doPaste();
   break;
  case 3:
   doSearch();
   break;
 }
}


getCurCommand

decompiled_code:
char *__fastcall getCurCommand(_BYTE *a1, char *a2)
{
char v2; // dl
_BYTE *v3; // rcx
char *result; // rax

if ( a2 || (a2 = (char *)textInput[135]) != 0LL )
{
while ( 1 )
{
v2 = *a2;
if ( *a2 != 10 )
break;
a2 = (char *)*((_QWORD *)a2 + 1);
if ( !a2 )
goto LABEL_10;
}
v3 = a1 + 1;
result = a2;
while ( 1 )
{
*(v3 - 1) = v2;
result = (char *)*((_QWORD *)result + 1);
a1 = v3;
if ( !result )
break;
v2 = *result;
++v3;
if ( *result == 10 )
{
*a1 = 10;
return result;
}
}
}
else
{
LABEL_10:
result = 0LL;
}
*a1 = 10;
return result;
}

canonical_decompiled_code:
char *__fastcall func8(_BYTE *a1, char *a2)
{
char v2; // dl
_BYTE *v3; // rcx
char *result; // rax

if ( a2 || (a2 = (char *)textInput[135]) != 0LL )
{
while ( 1 )
{
v2 = *a2;
if ( *a2 != 10 )
break;
a2 = (char *)*((_QWORD *)a2 + 1);
if ( !a2 )
goto LABEL_10;
}
v3 = a1 + 1;
result = a2;
while ( 1 )
{
*(v3 - 1) = v2;
result = (char *)*((_QWORD *)result + 1);
a1 = v3;
if ( !result )
break;
v2 = *result;
++v3;
if ( *result == 10 )
{
*a1 = 10;
return result;
}
}
}
else
{
LABEL_10:
result = 0LL;
}
*a1 = 10;
return result;
}

original_code:
Element* getCurCommand(char *command,Element *begin){
 int i = 0;
 Element *el = begin;
 if (el == ((void *)0)) el = textInput.beginElement;
 while(el != ((void *)0) && el->c == '\n')
  el = el->next;
 while(el != ((void *)0) && el->c != '\n'){
  command[i] = el->c;
  el = el->next;
  i++;
 }
 command[i] = '\n';
 return el;
}

canonical_original_code:
struct _Element *getCurCommand(char *command, struct _Element *begin){
 int i = 0;
 struct _Element *el = begin;
 if (el == ((void *)0)) el = textInput.beginElement;
 while(el != ((void *)0) && el->c == '\n')
  el = el->next;
 while(el != ((void *)0) && el->c != '\n'){
  command[i] = el->c;
  el = el->next;
  i++;
 }
 command[i] = '\n';
 return el;
}

variable_types:
command
char *

variable_types:
begin
struct _Element *

variable_types: i int

return_type: struct _Element { char c; char isSelected; struct _Element *next; struct _Element *previous; struct _Word { int type; struct _Element *begin; struct _Element *end; int count; struct _Word *next; struct _Word *previous; } *father; } *


doStep

decompiled_code:
int doStep()
{
char v1[1032]; // [rsp+0h] [rbp-408h] BYREF

setSystemState(3LL);
textInput[131] = getCurCommand(v1, (char *)textInput[131]);
return runCommand(v1, (unsigned int)((_DWORD)&shSystem + 1033));
}

canonical_decompiled_code:
int func9()
{
char v1[1032]; // [rsp+0h] [rbp-408h] BYREF

setSystemState(3LL);
textInput[131] = func8(v1, (char *)textInput[131]);
return func0(v1, (unsigned int)((_DWORD)&shSystem + 1033));
}

original_code:
void doStep(){
 setSystemState(InDebug);
 char command[1024];
 textInput.curCommand = getCurCommand(command,textInput.curCommand);
 runCommand(command,shSystem.status);
}

variable_types:
command
char [1024]


doRun

decompiled_code:
int doRun()
{
int v0; // ecx
__int64 v1; // rax
int v2; // ebx
int v3; // ebp

v0 = getElementLine(textInput[131]);
v1 = textInput[130];
if ( v1 )
{
while ( *(_DWORD *)v1 <= v0 )
{
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
goto LABEL_10;
}
v2 = *(_DWORD *)v1 - v0;
}
else
{
LABEL_10:
v2 = -1;
}
v3 = 0;
do
{
if ( !textInput[131] )
break;
++v3;
LODWORD(v1) = doStep();
}
while ( v3 != v2 );
return v1;
}

canonical_decompiled_code:
int func10()
{
int v0; // ecx
__int64 v1; // rax
int v2; // ebx
int v3; // ebp

v0 = getElementLine(textInput[131]);
v1 = textInput[130];
if ( v1 )
{
while ( *(_DWORD *)v1 <= v0 )
{
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
goto LABEL_10;
}
v2 = *(_DWORD *)v1 - v0;
}
else
{
LABEL_10:
v2 = -1;
}
v3 = 0;
do
{
if ( !textInput[131] )
break;
++v3;
LODWORD(v1) = func9();
}
while ( v3 != v2 );
return v1;
}

original_code:
void doRun(){
 int i = 0;
 int ln = getElementLine(textInput.curCommand);
 Point *p = textInput.breakpoints;
 unsigned int count = -1;
 while (p != ((void *)0)){
  if (p->ln > ln){
   count = p->ln - ln;
   break;
  }
  p = p->next;
 }
 for(i = 0; i < count && textInput.curCommand != ((void *)0); ++i){
  doStep();
 }
}

canonical_original_code:
void doRun(){
 int i = 0;
 int ln = getElementLine(textInput.curCommand);
 struct _Point *p = textInput.breakpoints;
 unsigned int count = -1;
 while (p != ((void *)0)){
  if (p->ln > ln){
   count = p->ln - ln;
   break;
  }
  p = p->next;
 }
 for(i = 0; i < count && textInput.curCommand != ((void *)0); ++i){
  doStep();
 }
}

variable_types: ln int

variable_types: struct _Point { int ln; int col; struct _Point *next; struct _Point *previous; } *

variable_types:
count
unsigned int


doSetBreakpoint

original_code:
void doSetBreakpoint(){
 Point * p = textInput.breakpoints;
 while (p != ((void *)0) && p->ln < textInput.curLn) p = p->next;
 if (p != ((void *)0) && p->ln == textInput.curLn){
  if (p->next != ((void *)0)) p->next->previous = p->previous;
  if (p->previous != ((void *)0)) p->previous->next = p->next;
  if (textInput.breakpoints == p)
   textInput.breakpoints = p->next;
  free(p);
 }else{
  Point *ins = (Point *)malloc(sizeof(Point));
  ins->ln = textInput.curLn;
  ins->col = textInput.curCol;
  ins->next = ((void *)0);
  ins->previous = ((void *)0);
  if (p != ((void *)0)){
   if (p->previous != ((void *)0)) p->previous->next = ins;
   p->previous = ins;
   ins->previous = p->previous;
   ins->next = p;
  }
  if (p == textInput.breakpoints)
   textInput.breakpoints = ins;
 }
}

canonical_original_code:
void doSetBreakpoint(){
 struct _Point *p = textInput.breakpoints;
 while (p != ((void *)0) && p->ln < textInput.curLn) p = p->next;
 if (p != ((void *)0) && p->ln == textInput.curLn){
  if (p->next != ((void *)0)) p->next->previous = p->previous;
  if (p->previous != ((void *)0)) p->previous->next = p->next;
  if (textInput.breakpoints == p)
   textInput.breakpoints = p->next;
  free(p);
 }else{
  struct _Point *ins = (Point *)malloc(sizeof(Point));
  ins->ln = textInput.curLn;
  ins->col = textInput.curCol;
  ins->next = ((void *)0);
  ins->previous = ((void *)0);
  if (p != ((void *)0)){
   if (p->previous != ((void *)0)) p->previous->next = ins;
   p->previous = ins;
   ins->previous = p->previous;
   ins->next = p;
  }
  if (p == textInput.breakpoints)
   textInput.breakpoints = ins;
 }
}

user_defined_types: struct _Point { int ln; int col; struct _Point *next; struct _Point *previous; }


doDebug

decompiled_code:
__int64 doDebug()
{
int v0; // eax
__int64 result; // rax

v0 = *((_DWORD *)&shSystem + 1);
if ( v0 == 1 )
{
doStep();
result = resetState();
}
else if ( v0 == 2 )
{
doSetBreakpoint();
result = resetState();
}
else
{
if ( !v0 )
doRun();
result = resetState();
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // eax
__int64 result; // rax

v0 = *((_DWORD *)&shSystem + 1);
if ( v0 == 1 )
{
func9();
result = resetState();
}
else if ( v0 == 2 )
{
func11();
result = resetState();
}
else
{
if ( !v0 )
func10();
result = resetState();
}
return result;
}

original_code:
void doDebug(){
 switch(shSystem.menuSection){
  case 0:
   doRun();
   break;
  case 1:
   doStep();
   break;
  case 2:
   doSetBreakpoint();
   break;
 }
 resetState();
}


doAbout

decompiled_code:
__int64 doAbout()
{
return setSubState(2LL);
}

canonical_decompiled_code:
__int64 func13()
{
return setSubState(2LL);
}

original_code:
void doAbout(){
 setSubState(InAbout);
}

canonical_original_code:
void doAbout(){
 setSubState(InAbout);
}


doManual

decompiled_code:
__int64 doManual()
{
return setSubState(3LL);
}

canonical_decompiled_code:
__int64 func14()
{
return setSubState(3LL);
}

original_code:
void doManual(){
 setSubState(InManual);
}


doHelp

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

result = *((unsigned int *)&shSystem + 1);
if ( !(_DWORD)result )
return doManual();
if ( (_DWORD)result == 1 )
result = doAbout();
return result;
}

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

result = *((unsigned int *)&shSystem + 1);
if ( !(_DWORD)result )
return func14();
if ( (_DWORD)result == 1 )
result = func13();
return result;
}

original_code:
void doHelp(){
 switch(shSystem.menuSection){
  case 0:
   doManual();
   break;
  case 1:
   doAbout();
   break;
 }
}


doNewFile

decompiled_code:
__int64 doNewFile()
{
clearText();
return resetState();
}

canonical_decompiled_code:
__int64 func16()
{
clearText();
return resetState();
}

original_code:
void doNewFile(){
 clearText();
 resetState();
}


doSave

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

setSubState(1LL);
result = 0LL;
LOWORD(textInput[128]) = 0;
qmemcpy(textInput, (const void *)(unsigned int)((_DWORD)&shSystem + 9), 0x400uLL);
return result;
}

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

setSubState(1LL);
result = 0LL;
LOWORD(textInput[128]) = 0;
qmemcpy(textInput, (const void *)(unsigned int)((_DWORD)&shSystem + 9), 0x400uLL);
return result;
}

original_code:
void doSave(){
 setSubState(InSave);
 memset(textInput.tmpStr,0,sizeof(textInput.tmpStr));
 memcpy(textInput.tmpStr,shSystem.fileName,sizeof(textInput.tmpStr));
 textInput.tmpCur = 0;
}


doLoad

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

setSubState(0LL);
memset(textInput, 0, 0x400uLL);
result = 0LL;
LOWORD(textInput[128]) = 0;
return result;
}

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

setSubState(0LL);
memset(textInput, 0, 0x400uLL);
result = 0LL;
LOWORD(textInput[128]) = 0;
return result;
}

original_code:
void doLoad(){
 setSubState(InLoad);
 memset(textInput.tmpStr,0,sizeof(textInput.tmpStr));
 textInput.tmpCur = 0;
}


doExit

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

result = setSystemState(0LL);
shSystem[8] = 1;
return result;
}

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

result = setSystemState(0LL);
shSystem[8] = 1;
return result;
}

original_code:
void doExit(){
 setSystemState(InQuit);
 shSystem.isQuit = 1;
}


doFile

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

result = *(unsigned int *)&shSystem[4];
if ( (_DWORD)result == 2 )
return doSave();
if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
result = doExit();
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
result = doLoad();
}
else
{
result = doNewFile();
}
return result;
}

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

result = *(unsigned int *)&shSystem[4];
if ( (_DWORD)result == 2 )
return func17();
if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
result = func19();
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
result = func18();
}
else
{
result = func16();
}
return result;
}

original_code:
void doFile(){
 switch(shSystem.menuSection){
  case 0:
   doNewFile();
   break;
  case 1:
   doLoad();
   break;
  case 2:
   doSave();
   break;
  case 3:
   doExit();
   break;
 }
}


doMenu

decompiled_code:
int doMenu()
{
int result; // eax

result = *(_DWORD *)shSystem;
if ( *(_DWORD *)shSystem == 2 )
return doDebug();
if ( *(int *)shSystem > 2 )
{
if ( *(_DWORD *)shSystem == 3 )
result = doHelp();
}
else if ( *(_DWORD *)shSystem )
{
if ( *(_DWORD *)shSystem == 1 )
result = doEdit();
}
else
{
result = doFile();
}
return result;
}

canonical_decompiled_code:
int func21()
{
int result; // eax

result = *(_DWORD *)shSystem;
if ( *(_DWORD *)shSystem == 2 )
return func12();
if ( *(int *)shSystem > 2 )
{
if ( *(_DWORD *)shSystem == 3 )
result = func15();
}
else if ( *(_DWORD *)shSystem )
{
if ( *(_DWORD *)shSystem == 1 )
result = func7();
}
else
{
result = func20();
}
return result;
}

original_code:
void doMenu(){
 switch (shSystem.menuIndex){
  case 0:
   doFile();
   break;
  case 1:
   doEdit();
   break;
  case 2:
   doDebug();
   break;
  case 3:
   doHelp();
   break;
 }
}