decompiled_code:
int __fastcall graph_print_shortest_path(const char **a1, const char **a2)
{
const char **v2; // r14
char **v3; // rax
char **v4; // r15
int v5; // er12
_QWORD *i; // rbp
const char *j; // rbx
__int64 v8; // rsi
_QWORD *v9; // rax
__int64 v10; // r13
_QWORD *v11; // rax
const char ***v12; // rbx
const char **k; // rax
int v16; // [rsp+10h] [rbp-58h] BYREF
const char **v17; // [rsp+18h] [rbp-50h]
__int64 v18; // [rsp+20h] [rbp-48h]

v2 = a1;
v3 = (char **)priority_queue_create();
if ( a1 != a2 )
{
v4 = v3;
v5 = 0;
for ( i = 0LL; ; i = v11 )
{
for ( j = v2[1]; j; j = (const char *)*((_QWORD *)j + 2) )
{
while ( 1 )
{
v8 = *((_QWORD *)j + 1);
v9 = i;
if ( i )
break;
LABEL_12:
priority_queue_add(v4, v8, (__int64)v2, v5 + *(_DWORD *)j);
j = (const char *)*((_QWORD *)j + 2);
if ( !j )
goto LABEL_9;
}
while ( *v9 != v8 )
{
v9 = (_QWORD *)v9[2];
if ( !v9 )
goto LABEL_12;
}
}
LABEL_9:
if ( !*((_DWORD *)v4 + 2) )
return puts("no path found");
priority_queue_pop((__int64)&v16, (int **)v4);
v2 = v17;
v10 = v18;
v5 = v16;
v11 = malloc(0x18uLL);
*v11 = v2;
v12 = (const char ***)v11;
v11[2] = i;
v11[1] = v10;
if ( a2 == v2 )
break;
}
for ( k = v2; ; k = *v12 )
{
if ( k == v2 )
{
printf(format, *v2);
v2 = v12[1];
}
v12 = (const char ***)v12[2];
if ( !v12 )
break;
}
}
return puts(*v2);
}

canonical_decompiled_code:
int __fastcall func4(const char **a1, const char **a2)
{
const char **v2; // r14
char **v3; // rax
char **v4; // r15
int v5; // er12
_QWORD *i; // rbp
const char *j; // rbx
__int64 v8; // rsi
_QWORD *v9; // rax
__int64 v10; // r13
_QWORD *v11; // rax
const char ***v12; // rbx
const char **k; // rax
int v16; // [rsp+10h] [rbp-58h] BYREF
const char **v17; // [rsp+18h] [rbp-50h]
__int64 v18; // [rsp+20h] [rbp-48h]

v2 = a1;
v3 = (char **)func3();
if ( a1 != a2 )
{
v4 = v3;
v5 = 0;
for ( i = 0LL; ; i = v11 )
{
for ( j = v2[1]; j; j = (const char *)*((_QWORD *)j + 2) )
{
while ( 1 )
{
v8 = *((_QWORD *)j + 1);
v9 = i;
if ( i )
break;
LABEL_12:
func1(v4, v8, (__int64)v2, v5 + *(_DWORD *)j);
j = (const char *)*((_QWORD *)j + 2);
if ( !j )
goto LABEL_9;
}
while ( *v9 != v8 )
{
v9 = (_QWORD *)v9[2];
if ( !v9 )
goto LABEL_12;
}
}
LABEL_9:
if ( !*((_DWORD *)v4 + 2) )
return puts("no path found");
func2((__int64)&v16, (int **)v4);
v2 = v17;
v10 = v18;
v5 = v16;
v11 = malloc(0x18uLL);
*v11 = v2;
v12 = (const char ***)v11;
v11[2] = i;
v11[1] = v10;
if ( a2 == v2 )
break;
}
for ( k = v2; ; k = *v12 )
{
if ( k == v2 )
{
printf(format, *v2);
v2 = v12[1];
}
v12 = (const char ***)v12[2];
if ( !v12 )
break;
}
}
return puts(*v2);
}

original_code:
void graph_print_shortest_path(struct VERTEX *v1, struct VERTEX *v2) {
 struct EDGE *e;
 struct PRIORITY_QUEUE_ELEMENT element={0};
 struct PRIORITY_QUEUE *queue=priority_queue_create();
 struct VISITED *visited=((void *)0), *l;
 for(;;) {
  if(v1==v2) {
   for(l=visited; l; l=l->next) {
    if(l->vertex==v1) {
     printf("%s←", l->vertex->name);
     v1=l->prev;
    }
   }
   printf("%s\n", v1->name);
   return;
  }
  for(e=v1->neighbour; e; e=e->next) {
   for(l=visited; l; l=l->next)
    if(l->vertex==e->vertex)
     break;
   if(!l)
    priority_queue_add(queue, e->vertex, v1, e->weight+element.priority);
  }
  if(!queue->elements)
   break;
  element=priority_queue_pop(queue);
  v1=element.item;
  l=visited;
  visited=malloc(sizeof(struct VISITED));
  visited->vertex=v1;
  visited->next=l;
  visited->prev=element.prev;
 }
 printf("no path found\n");
}

canonical_original_code:
void graph_print_shortest_path(struct VERTEX *v1, struct VERTEX *v2) {
 struct EDGE *e;
 struct PRIORITY_QUEUE_ELEMENT element = {0};
 struct PRIORITY_QUEUE *queue = priority_queue_create();
 struct VISITED *visited = ((void *)0); struct VISITED *l;
 for(;;) {
  if(v1==v2) {
   for(l=visited; l; l=l->next) {
    if(l->vertex==v1) {
     printf("%s←", l->vertex->name);
     v1=l->prev;
    }
   }
   printf("%s\n", v1->name);
   return;
  }
  for(e=v1->neighbour; e; e=e->next) {
   for(l=visited; l; l=l->next)
    if(l->vertex==e->vertex)
     break;
   if(!l)
    priority_queue_add(queue, e->vertex, v1, e->weight+element.priority);
  }
  if(!queue->elements)
   break;
  element=priority_queue_pop(queue);
  v1=element.item;
  l=visited;
  visited=malloc(sizeof(struct VISITED));
  visited->vertex=v1;
  visited->next=l;
  visited->prev=element.prev;
 }
 printf("no path found\n");
}

variable_types: struct EDGE { int weight; struct VERTEX { char *name; struct EDGE *neighbour; } *vertex; struct EDGE *next; } *

variable_types: struct PRIORITY_QUEUE_ELEMENT { int priority; void *item; void *prev; }

variable_types: struct VISITED { struct VERTEX { char *name; struct EDGE { int weight; struct VERTEX *vertex; struct EDGE *next; } *neighbour; } *vertex; struct VERTEX *prev; struct VISITED *next; } *

user_defined_types: struct VISITED { struct VERTEX *vertex; struct VERTEX *prev; struct VISITED *next; }


original_code:
void graph_add_edge(struct VERTEX *v1, struct VERTEX *v2, int weight, enum DIRECTION direction) {
 struct EDGE *e;
 for(e=v1->neighbour; e; e=e->next)
  if(e->vertex==v2) {
   printf("Warning: %s already linked to %s\n", v1->name, v2->name);
   return;
  }
 e=v1->neighbour;
 v1->neighbour=malloc(sizeof(struct EDGE));
 v1->neighbour->next=e;
 v1->neighbour->vertex=v2;
 v1->neighbour->weight=weight;
 if(direction!=DIRECTION_DOUBLE)
  return;
 e=v2->neighbour;
 v2->neighbour=malloc(sizeof(struct EDGE));
 v2->neighbour->next=e;
 v2->neighbour->vertex=v1;
 v2->neighbour->weight=weight;
}

variable_types: struct VERTEX { char *name; struct EDGE { int weight; struct VERTEX *vertex; struct EDGE *next; } *neighbour; } *

variable_types: weight int

variable_types: enum DIRECTION { DIRECTION_SINGLE=0, DIRECTION_DOUBLE=1 }

return_type: void

user_defined_types: struct VERTEX { char *name; struct EDGE *neighbour; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // r15
const char **v5; // r14
const char **v6; // r12
const char **v7; // rbp
const char *v8; // rsi
int v9; // eax
char *v10; // [rsp+8h] [rbp-50h]
char *s1; // [rsp+10h] [rbp-48h] BYREF
void *ptr; // [rsp+18h] [rbp-40h] BYREF

db_load();
puts("\nEurope roadmap, Axel Isaksson 2013\n");
while ( 1 )
{
printf("city 1>");
_isoc99_scanf("%m[^\n]", &s1);
getchar();
printf("city 2>");
_isoc99_scanf("%m[^\n]", &ptr);
getchar();
v3 = graph;
if ( graph )
{
v4 = s1;
v5 = 0LL;
v6 = 0LL;
v10 = (char *)ptr;
do
{
v7 = *(const char ***)v3;
v8 = **(const char ***)v3;
if ( !strcasecmp(v4, v8) )
v6 = v7;
v9 = strcasecmp(v10, v8);
v3 = *(_QWORD *)(v3 + 8);
if ( !v9 )
v5 = v7;
if ( !v3 )
goto LABEL_13;
}
while ( !v6 || !v5 );
graph_print_shortest_path(v6, v5);
}
else
{
LABEL_13:
puts("city not found");
}
free(s1);
free(ptr);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v4; // r15
const char **v5; // r14
const char **v6; // r12
const char **v7; // rbp
const char *v8; // rsi
int v9; // eax
char *v10; // [rsp+8h] [rbp-50h]
char *s1; // [rsp+10h] [rbp-48h] BYREF
void *ptr; // [rsp+18h] [rbp-40h] BYREF

func5();
puts("\nEurope roadmap, Axel Isaksson 2013\n");
while ( 1 )
{
printf("city 1>");
_isoc99_scanf("%m[^\n]", &s1);
getchar();
printf("city 2>");
_isoc99_scanf("%m[^\n]", &ptr);
getchar();
v3 = graph;
if ( graph )
{
v4 = s1;
v5 = 0LL;
v6 = 0LL;
v10 = (char *)ptr;
do
{
v7 = *(const char ***)v3;
v8 = **(const char ***)v3;
if ( !strcasecmp(v4, v8) )
v6 = v7;
v9 = strcasecmp(v10, v8);
v3 = *(_QWORD *)(v3 + 8);
if ( !v9 )
v5 = v7;
if ( !v3 )
goto LABEL_13;
}
while ( !v6 || !v5 );
func4(v6, v5);
}
else
{
LABEL_13:
puts("city not found");
}
free(s1);
free(ptr);
}
}

original_code:
int main(int argc, char **argv) {
 char *city1, *city2;
 struct VERTEX *v1, *v2;
 struct GRAPH *g;
 db_load();
 printf("\nEurope roadmap, Axel Isaksson 2013\n\n");
 for(;;) {
  printf("city 1>");
  scanf("%m[^\n]", &city1);
  getchar();
  printf("city 2>");
  scanf("%m[^\n]", &city2);
  getchar();
  v1=v2=((void *)0);
  for(g=graph; g&&!(v1&&v2); g=g->next) {
   if(!strcasecmp(city1, g->vertex->name)) {
    v1=g->vertex;
   }
   if(!strcasecmp(city2, g->vertex->name)) {
    v2=g->vertex;
   }
  }
  if(g) {
   graph_print_shortest_path(v1, v2);
  } else {
   printf("city not found\n");
  }
  free(city1);
  free(city2);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 char *city1; char *city2;
 struct VERTEX *v1; struct VERTEX *v2;
 struct GRAPH *g;
 db_load();
 printf("\nEurope roadmap, Axel Isaksson 2013\n\n");
 for(;;) {
  printf("city 1>");
  scanf("%m[^\n]", &city1);
  getchar();
  printf("city 2>");
  scanf("%m[^\n]", &city2);
  getchar();
  v1=v2=((void *)0);
  for(g=graph; g&&!(v1&&v2); g=g->next) {
   if(!strcasecmp(city1, g->vertex->name)) {
    v1=g->vertex;
   }
   if(!strcasecmp(city2, g->vertex->name)) {
    v2=g->vertex;
   }
  }
  if(g) {
   graph_print_shortest_path(v1, v2);
  } else {
   printf("city not found\n");
  }
  free(city1);
  free(city2);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct GRAPH { struct VERTEX { char *name; struct EDGE { int weight; struct VERTEX *vertex; struct EDGE *next; } *neighbour; } *vertex; struct GRAPH *next; } *

return_type: int

user_defined_types: struct GRAPH { struct VERTEX *vertex; struct GRAPH *next; }


decompiled_code:
int __fastcall count_word(char *s)
{
int v1; // er12
__int64 v2; // rbx
char *v3; // rax
_DWORD *v4; // r13
__int64 *v5; // rbx

v1 = hash_string(s);
v2 = wordtable[(unsigned __int16)v1];
if ( v2 )
{
while ( 1 )
{
LODWORD(v3) = strcmp(s, *(const char **)v2);
if ( !(_DWORD)v3 )
{
++*(_DWORD *)(v2 + 8);
return (int)v3;
}
if ( !*(_QWORD *)(v2 + 16) )
break;
v2 = *(_QWORD *)(v2 + 16);
}
v5 = (__int64 *)(v2 + 16);
}
else
{
v5 = &wordtable[(unsigned __int16)v1];
}
v4 = malloc(0x18uLL);
v3 = strdup(s);
v4[3] = v1;
*(_QWORD *)v4 = v3;
v4[2] = 1;
*((_QWORD *)v4 + 2) = 0LL;
*v5 = (__int64)v4;
return (int)v3;
}

canonical_decompiled_code:
int __fastcall func1(char *s)
{
int v1; // er12
__int64 v2; // rbx
char *v3; // rax
_DWORD *v4; // r13
__int64 *v5; // rbx

v1 = func0(s);
v2 = wordtable[(unsigned __int16)v1];
if ( v2 )
{
while ( 1 )
{
LODWORD(v3) = strcmp(s, *(const char **)v2);
if ( !(_DWORD)v3 )
{
++*(_DWORD *)(v2 + 8);
return (int)v3;
}
if ( !*(_QWORD *)(v2 + 16) )
break;
v2 = *(_QWORD *)(v2 + 16);
}
v5 = (__int64 *)(v2 + 16);
}
else
{
v5 = &wordtable[(unsigned __int16)v1];
}
v4 = malloc(0x18uLL);
v3 = strdup(s);
v4[3] = v1;
*(_QWORD *)v4 = v3;
v4[2] = 1;
*((_QWORD *)v4 + 2) = 0LL;
*v5 = (__int64)v4;
return (int)v3;
}

original_code:
void count_word(const char *s) {
 unsigned int hash=hash_string(s);
 struct WORD **word, *newword;
 for(word=&wordtable[hash%65536]; *word; word=&(*word)->next) {
  if(!strcmp(s, (*word)->word)) {
   (*word)->count++;
   return;
  }
 }
 newword=malloc(sizeof(struct WORD));
 *((char **) &(newword->word))=strdup(s);
 *((int *) &(newword->hash))=hash;
 newword->count=1;
 newword->next=*word;
 *word=newword;
}

canonical_original_code:
void count_word(char *s) {
 unsigned int hash = hash_string(s);
 struct WORD **word; struct WORD *newword;
 for(word=&wordtable[hash%65536]; *word; word=&(*word)->next) {
  if(!strcmp(s, (*word)->word)) {
   (*word)->count++;
   return;
  }
 }
 newword=malloc(sizeof(struct WORD));
 *((char **) &(newword->word))=strdup(s);
 *((int *) &(newword->hash))=hash;
 newword->count=1;
 newword->next=*word;
 *word=newword;
}

variable_types:
s
char *

variable_types:
hash
unsigned int

variable_types: struct WORD { char *word; unsigned int count; unsigned int hash; struct WORD *next; } **


decompiled_code:
__int64 __fastcall hash_string(_BYTE *a1)
{
int v1; // eax
unsigned int v2; // er8
int v3; // esi

if ( !*a1 )
return 0LL;
v1 = 1;
v2 = 0;
do
{
v3 = (char)*++a1;
v2 += v3 * (unsigned __int16)v1;
v1 *= 31;
}
while ( (_BYTE)v3 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax
unsigned int v2; // er8
int v3; // esi

if ( !*a1 )
return 0LL;
v1 = 1;
v2 = 0;
do
{
v3 = (char)*++a1;
v2 += v3 * (unsigned __int16)v1;
v1 *= 31;
}
while ( (_BYTE)v3 );
return v2;
}

original_code:
unsigned int hash_string(const char *string) {
 unsigned int hash=0;
 unsigned short i;
 for(i=1; *string; string++, hash+=i*(*string), i*=31);
 return hash;
}

canonical_original_code:
unsigned int hash_string(char *string) {
 unsigned int hash = 0;
 unsigned short i;
 for(i=1; *string; string++, hash+=i*(*string), i*=31);
 return hash;
}

variable_types:
string
char *

variable_types:
i
unsigned short

return_type: unsigned int


original_code:
int main(int argc, char **argv) {
 char w[256];
 char c, *s=w;
 int i;
 struct WORD *word, *sorted=((void *)0), *next, **tmp;
 while(!feof(stdin)) {
  c=getchar();
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISpunct)||((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)||((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
   if(s>w) {
    if(c=='\'')
     goto inword;
    *s=0;
    count_word(w);
    s=w;
   }
   continue;
  }
  inword:
  *s=tolower(c);
  s++;
 }
 for(i=0; i<65536; i++)
  for(word=wordtable[i]; word; word=word->next) {
   for(tmp=&sorted; *tmp; tmp=&((*tmp)->next)) {
    if(word->count>=(*tmp)->count)
     break;
   }
   next=*tmp;
   *tmp=malloc(sizeof(struct WORD));
   memcpy(*tmp, word, sizeof(struct WORD));
   (*tmp)->next=next;
  }
 for(i=0, word=sorted; word; word=sorted) {
  if(i++<100)
   printf("%s: %u\n", word->word, word->count);
  sorted=word->next;
  free(word);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 char w[256];
 char c; char *s = w;
 int i;
 struct WORD *word; struct WORD *sorted = ((void *)0); struct WORD *next; struct WORD **tmp;
 while(!feof(stdin)) {
  c=getchar();
  if(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISpunct)||((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)||((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
   if(s>w) {
    if(c=='\'')
     goto inword;
    *s=0;
    count_word(w);
    s=w;
   }
   continue;
  }
  inword:
  *s=tolower(c);
  s++;
 }
 for(i=0; i<65536; i++)
  for(word=wordtable[i]; word; word=word->next) {
   for(tmp=&sorted; *tmp; tmp=&((*tmp)->next)) {
    if(word->count>=(*tmp)->count)
     break;
   }
   next=*tmp;
   *tmp=malloc(sizeof(struct WORD));
   memcpy(*tmp, word, sizeof(struct WORD));
   (*tmp)->next=next;
  }
 for(i=0, word=sorted; word; word=sorted) {
  if(i++<100)
   printf("%s: %u\n", word->word, word->count);
  sorted=word->next;
  free(word);
 }
 return 0;
}

variable_types:
w
char [256]

variable_types: c char

variable_types: i int

variable_types: struct WORD { char *word; unsigned int count; unsigned int hash; struct WORD *next; } *


decompiled_code:
__int64 __fastcall graph_exists_path(const char **a1, const char **a2, const char ****a3)
{
const char ***v4; // r13
const char ***v5; // rax
const char ***v7; // rax
const char *v8; // rbx

printf("\tVisit %s\n", *a1);
if ( a1 == a2 )
return 1LL;
v4 = *a3;
if ( !*a3 )
{
LABEL_7:
v7 = (const char ***)malloc(0x10uLL);
*v7 = a1;
v8 = a1[1];
v7[1] = (const char **)v4;
*a3 = v7;
if ( !v8 )
return 0LL;
while ( !(unsigned int)graph_exists_path(*((_QWORD *)v8 + 1), a2, a3) )
{
v8 = (const char *)*((_QWORD *)v8 + 2);
if ( !v8 )
return 0LL;
}
return 1LL;
}
v5 = *a3;
while ( *v5 != a1 )
{
v5 = (const char ***)v5[1];
if ( !v5 )
goto LABEL_7;
}
printf("\t\t%s already visited\n", *a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1, const char **a2, const char ****a3)
{
const char ***v4; // r13
const char ***v5; // rax
const char ***v7; // rax
const char *v8; // rbx

printf("\tVisit %s\n", *a1);
if ( a1 == a2 )
return 1LL;
v4 = *a3;
if ( !*a3 )
{
LABEL_7:
v7 = (const char ***)malloc(0x10uLL);
*v7 = a1;
v8 = a1[1];
v7[1] = (const char **)v4;
*a3 = v7;
if ( !v8 )
return 0LL;
while ( !(unsigned int)func0(*((_QWORD *)v8 + 1), a2, a3) )
{
v8 = (const char *)*((_QWORD *)v8 + 2);
if ( !v8 )
return 0LL;
}
return 1LL;
}
v5 = *a3;
while ( *v5 != a1 )
{
v5 = (const char ***)v5[1];
if ( !v5 )
goto LABEL_7;
}
printf("\t\t%s already visited\n", *a1);
return 0LL;
}

original_code:
int graph_exists_path(struct VERTEX *v1, struct VERTEX *v2, struct VISITED **visited) {
 struct EDGE *e;
 struct VISITED *v;
 printf("	Visit %s\n", v1->name);
 if(v1==v2)
  return 1;
 for(v=*visited; v; v=v->next)
  if(v1==v->vertex) {
   printf("		%s already visited\n", v1->name);
   return 0;
  }
 v=malloc(sizeof(struct VISITED));
 v->next=*visited;
 v->vertex=v1;
 *visited=v;
 for(e=v1->neighbour; e; e=e->next) {
  if(graph_exists_path(e->vertex, v2, visited))
   return 1;
 }
 return 0;
}

variable_types: struct VISITED { struct VERTEX *vertex; struct VISITED *next; } **

variable_types: struct EDGE { int weight; struct VERTEX { char *name; struct EDGE *neighbour; } *vertex; struct EDGE *next; } *

variable_types: struct VISITED { struct VERTEX { char *name; struct EDGE { int weight; struct VERTEX *vertex; struct EDGE *next; } *neighbour; } *vertex; struct VISITED *next; } *


decompiled_code:
void __fastcall exists_path(const char **a1, const char **a2)
{
const char *v3; // rdx
const char *v4; // rsi
const char *v5; // r14
const char *v6; // r13
const char *v7; // rsi
_QWORD *v8; // rbx
void *v9; // rdi
void *ptr; // [rsp+8h] [rbp-30h] BYREF

v3 = *a2;
v4 = *a1;
ptr = 0LL;
printf("Looking for path between %s and %s\n", v4, v3);
v5 = *a2;
v6 = *a1;
v7 = "a";
if ( !(unsigned int)graph_exists_path(a1, a2, (const char ****)&ptr) )
v7 = "no";
printf("\t* There is %s path between %s and %s\n", v7, v6, v5);
v8 = ptr;
if ( ptr )
{
do
{
v9 = v8;
v8 = (_QWORD *)v8[1];
free(v9);
ptr = v8;
}
while ( v8 );
}
}

canonical_decompiled_code:
void __fastcall func1(const char **a1, const char **a2)
{
const char *v3; // rdx
const char *v4; // rsi
const char *v5; // r14
const char *v6; // r13
const char *v7; // rsi
_QWORD *v8; // rbx
void *v9; // rdi
void *ptr; // [rsp+8h] [rbp-30h] BYREF

v3 = *a2;
v4 = *a1;
ptr = 0LL;
printf("Looking for path between %s and %s\n", v4, v3);
v5 = *a2;
v6 = *a1;
v7 = "a";
if ( !(unsigned int)func0(a1, a2, (const char ****)&ptr) )
v7 = "no";
printf("\t* There is %s path between %s and %s\n", v7, v6, v5);
v8 = ptr;
if ( ptr )
{
do
{
v9 = v8;
v8 = (_QWORD *)v8[1];
free(v9);
ptr = v8;
}
while ( v8 );
}
}

original_code:
void exists_path(struct VERTEX *v1, struct VERTEX *v2) {
 struct VISITED *visited=((void *)0), *next;
 printf("Looking for path between %s and %s\n", v1->name, v2->name);
 printf("	* There is %s path between %s and %s\n", graph_exists_path(v1, v2, &visited)?"a":"no", v1->name, v2->name);
 for(; visited; visited=next) {
  next=visited->next;
  free(visited);
 }
}

canonical_original_code:
void exists_path(struct VERTEX *v1, struct VERTEX *v2) {
 struct VISITED *visited = ((void *)0); struct VISITED *next;
 printf("Looking for path between %s and %s\n", v1->name, v2->name);
 printf("	* There is %s path between %s and %s\n", graph_exists_path(v1, v2, &visited)?"a":"no", v1->name, v2->name);
 for(; visited; visited=next) {
  next=visited->next;
  free(visited);
 }
}

variable_types: struct VERTEX { char *name; struct EDGE { int weight; struct VERTEX *vertex; struct EDGE *next; } *neighbour; } *

user_defined_types: struct VISITED { struct VERTEX *vertex; struct VISITED *next; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r12
const char **v4; // rbp
const char **v5; // r14
const char **v6; // r13
const char **v7; // r15
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

v9[0] = 0LL;
v3 = (const char **)graph_add_vertex(v9, (__int64)"stockholm");
v4 = (const char **)graph_add_vertex(v9, (__int64)"uppsala");
v5 = (const char **)graph_add_vertex(v9, (__int64)&unk_285);
v6 = (const char **)graph_add_vertex(v9, (__int64)&unk_28C);
v7 = (const char **)graph_add_vertex(v9, (__int64)"visby");
graph_add_edge((__int64)v3, (__int64)v4, 71);
graph_add_edge((__int64)v5, (__int64)v4, 105);
graph_add_edge((__int64)v4, (__int64)v6, 79);
graph_add_edge((__int64)v3, (__int64)v6, 110);
exists_path(v3, v6);
exists_path(v3, v5);
exists_path(v4, v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r12
const char **v4; // rbp
const char **v5; // r14
const char **v6; // r13
const char **v7; // r15
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

v9[0] = 0LL;
v3 = (const char **)graph_add_vertex(v9, (__int64)"stockholm");
v4 = (const char **)graph_add_vertex(v9, (__int64)"uppsala");
v5 = (const char **)graph_add_vertex(v9, (__int64)&unk_285);
v6 = (const char **)graph_add_vertex(v9, (__int64)&unk_28C);
v7 = (const char **)graph_add_vertex(v9, (__int64)"visby");
graph_add_edge((__int64)v3, (__int64)v4, 71);
graph_add_edge((__int64)v5, (__int64)v4, 105);
graph_add_edge((__int64)v4, (__int64)v6, 79);
graph_add_edge((__int64)v3, (__int64)v6, 110);
func1(v3, v6);
func1(v3, v5);
func1(v4, v7);
return 0;
}

original_code:
int main(int argc, char **argv) {
 struct GRAPH *g=((void *)0);
 struct VERTEX *stockholm, *uppsala, *gavle, *vasteras, *visby;
 stockholm=graph_add_vertex(&g, "stockholm");
 uppsala=graph_add_vertex(&g, "uppsala");
 gavle=graph_add_vertex(&g, "gävle");
 vasteras=graph_add_vertex(&g, "västerås");
 visby=graph_add_vertex(&g, "visby");
 graph_add_edge(stockholm, uppsala, 71);
 graph_add_edge(gavle, uppsala, 105);
 graph_add_edge(uppsala, vasteras, 79);
 graph_add_edge(stockholm, vasteras, 110);
 exists_path(stockholm, vasteras);
 exists_path(stockholm, gavle);
 exists_path(uppsala, visby);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 struct GRAPH *g = ((void *)0);
 struct VERTEX *stockholm; struct VERTEX *uppsala; struct VERTEX *gavle; struct VERTEX *vasteras; struct VERTEX *visby;
 stockholm=graph_add_vertex(&g, "stockholm");
 uppsala=graph_add_vertex(&g, "uppsala");
 gavle=graph_add_vertex(&g, "gävle");
 vasteras=graph_add_vertex(&g, "västerås");
 visby=graph_add_vertex(&g, "visby");
 graph_add_edge(stockholm, uppsala, 71);
 graph_add_edge(gavle, uppsala, 105);
 graph_add_edge(uppsala, vasteras, 79);
 graph_add_edge(stockholm, vasteras, 110);
 exists_path(stockholm, vasteras);
 exists_path(stockholm, gavle);
 exists_path(uppsala, visby);
 return 0;
}

user_defined_types: struct EDGE { int weight; struct VERTEX *vertex; struct EDGE *next; }


repo: ha-D/NetSplit

canonical_original_code:
void print_bytes(char *buff, int len){
    unsigned char *buf = (uint8_t*)buff;
 int i;
 printf("Bytes:\n");
 for(i = 0; i < len; i ++){
  printf("%02x ", buf[i]);
 }
 printf("\n------------------------------------------\n");
}

variable_types:
buff
char *

variable_types: len int

variable_types:
buf
unsigned char *


decompiled_code:
int __fastcall print_tcp(__int64 a1)
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // ax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned __int16 v5; // ax
char v6; // al

puts("TCP: ");
v1 = _bswap_16(*(_WORD *)a1);
printf("\tSource Port: %d\n", v1);
v2 = _bswap_16(*(_WORD *)(a1 + 2));
printf("\tDestination Port: %d\n", v2);
v3 = _bswap_32(*(_DWORD *)(a1 + 4));
printf("\tSequence: %d\n", v3);
v4 = _bswap_32(*(_DWORD *)(a1 + 8));
printf("\tAck Sequence: %d\n", v4);
v5 = _bswap_16(*(_WORD *)(a1 + 14));
printf("\tWindow Size: %d\n", v5);
printf("\tFlags: \n\t\t");
v6 = *(_BYTE *)(a1 + 13);
if ( (v6 & 2) != 0 )
{
printf("SYN ");
v6 = *(_BYTE *)(a1 + 13);
if ( (v6 & 0x10) == 0 )
{
LABEL_3:
if ( (v6 & 1) == 0 )
goto LABEL_4;
goto LABEL_10;
}
}
else if ( (v6 & 0x10) == 0 )
{
goto LABEL_3;
}
printf("ACK ");
v6 = *(_BYTE *)(a1 + 13);
if ( (v6 & 1) == 0 )
{
LABEL_4:
if ( (v6 & 4) == 0 )
goto LABEL_5;
goto LABEL_11;
}
LABEL_10:
printf("FIN ");
v6 = *(_BYTE *)(a1 + 13);
if ( (v6 & 4) == 0 )
{
LABEL_5:
if ( (v6 & 8) == 0 )
goto LABEL_6;
LABEL_12:
printf("PSH ");
if ( (*(_BYTE *)(a1 + 12) & 0xF) == 0 )
return putchar(10);
goto LABEL_13;
}
LABEL_11:
printf("RST ");
if ( (*(_BYTE *)(a1 + 13) & 8) != 0 )
goto LABEL_12;
LABEL_6:
if ( (*(_BYTE *)(a1 + 12) & 0xF) == 0 )
return putchar(10);
LABEL_13:
printf("RESL ");
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // ax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned __int16 v5; // ax
char v6; // al

puts("TCP: ");
v1 = func1(*(_WORD *)a1);
printf("\tSource Port: %d\n", v1);
v2 = func1(*(_WORD *)(a1 + 2));
printf("\tDestination Port: %d\n", v2);
v3 = func0(*(_DWORD *)(a1 + 4));
printf("\tSequence: %d\n", v3);
v4 = func0(*(_DWORD *)(a1 + 8));
printf("\tAck Sequence: %d\n", v4);
v5 = func1(*(_WORD *)(a1 + 14));
printf("\tWindow Size: %d\n", v5);
printf("\tFlags: \n\t\t");
v6 = *(_BYTE *)(a1 + 13);
if ( (v6 & 2) != 0 )
{
printf("SYN ");
v6 = *(_BYTE *)(a1 + 13);
if ( (v6 & 0x10) == 0 )
{
LABEL_3:
if ( (v6 & 1) == 0 )
goto LABEL_4;
goto LABEL_10;
}
}
else if ( (v6 & 0x10) == 0 )
{
goto LABEL_3;
}
printf("ACK ");
v6 = *(_BYTE *)(a1 + 13);
if ( (v6 & 1) == 0 )
{
LABEL_4:
if ( (v6 & 4) == 0 )
goto LABEL_5;
goto LABEL_11;
}
LABEL_10:
printf("FIN ");
v6 = *(_BYTE *)(a1 + 13);
if ( (v6 & 4) == 0 )
{
LABEL_5:
if ( (v6 & 8) == 0 )
goto LABEL_6;
LABEL_12:
printf("PSH ");
if ( (*(_BYTE *)(a1 + 12) & 0xF) == 0 )
return putchar(10);
goto LABEL_13;
}
LABEL_11:
printf("RST ");
if ( (*(_BYTE *)(a1 + 13) & 8) != 0 )
goto LABEL_12;
LABEL_6:
if ( (*(_BYTE *)(a1 + 12) & 0xF) == 0 )
return putchar(10);
LABEL_13:
printf("RESL ");
return putchar(10);
}

original_code:
void print_tcp(char* buf, int print_rest){
    struct tcphdr* tcp;
    tcp = (struct tcphdr*)buf;
    printf("TCP: \n");
    printf("\tSource Port:      %d\n", ntohs(tcp->source));
    printf("\tDestination Port: %d\n", ntohs(tcp->dest));
    printf("\tSequence:         %d\n", ntohl(tcp->seq));
    printf("\tAck Sequence:     %d\n", ntohl(tcp->ack_seq));
    printf("\tWindow Size:      %d\n", ntohs(tcp->window));
    printf("\tFlags:              \n\t\t");
    if(tcp->syn)
        printf("SYN ");
    if(tcp->ack)
        printf("ACK ");
    if(tcp->fin)
        printf("FIN ");
    if(tcp->rst)
        printf("RST ");
    if(tcp->psh)
        printf("PSH ");
    if(tcp->res1)
        printf("RESL ");
    printf("\n");
}

canonical_original_code:
void print_tcp(char *buf, int print_rest){
    struct tcphdr *tcp;
    tcp = (struct tcphdr *)buf;
    printf("TCP: \n");
    printf("\tSource Port:      %d\n", ntohs(tcp->source));
    printf("\tDestination Port: %d\n", ntohs(tcp->dest));
    printf("\tSequence:         %d\n", ntohl(tcp->seq));
    printf("\tAck Sequence:     %d\n", ntohl(tcp->ack_seq));
    printf("\tWindow Size:      %d\n", ntohs(tcp->window));
    printf("\tFlags:              \n\t\t");
    if(tcp->syn)
        printf("SYN ");
    if(tcp->ack)
        printf("ACK ");
    if(tcp->fin)
        printf("FIN ");
    if(tcp->rst)
        printf("RST ");
    if(tcp->psh)
        printf("PSH ");
    if(tcp->res1)
        printf("RESL ");
    printf("\n");
}

variable_types:
buf
char *

variable_types: struct tcphdr { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short window; unsigned short check; unsigned short urg_ptr; } *


original_code:
void print_ip(char* buf, int print_payload){
    struct iphdr* ip;
    struct in_addr src, dst;
    ip = (struct iphdr*)buf;
    src.s_addr = ip->saddr;
    dst.s_addr = ip->daddr;
    printf("------------------------------------------\n");
    printf("IP: \n");
    printf("\tSource Addr:      %s\n", inet_ntoa(src));
    printf("\tDestination Addr: %s\n", inet_ntoa(dst));
    printf("\tHeader Length:    %d\n", ip->ihl);
    printf("\tTotal Length:     %d\n", ntohs(ip->tot_len));
    printf("\tProtocol:         %d\n", ip->protocol);
    if(print_payload){
        printf("\n");
        if(ip->protocol == IPPROTO_TCP){
            print_tcp(buf + sizeof(struct iphdr), print_payload);
        }
    }
    printf("------------------------------------------\n");
}

canonical_original_code:
void print_ip(char *buf, int print_payload){
    struct iphdr *ip;
    struct in_addr src; struct in_addr dst;
    ip = (struct iphdr *)buf;
    src.s_addr = ip->saddr;
    dst.s_addr = ip->daddr;
    printf("------------------------------------------\n");
    printf("IP: \n");
    printf("\tSource Addr:      %s\n", inet_ntoa(src));
    printf("\tDestination Addr: %s\n", inet_ntoa(dst));
    printf("\tHeader Length:    %d\n", ip->ihl);
    printf("\tTotal Length:     %d\n", ntohs(ip->tot_len));
    printf("\tProtocol:         %d\n", ip->protocol);
    if(print_payload){
        printf("\n");
        if(ip->protocol == IPPROTO_TCP){
            print_tcp(buf + sizeof(struct iphdr), print_payload);
        }
    }
    printf("------------------------------------------\n");
}

variable_types: struct iphdr { unsigned char ihl; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *

variable_types:
src
struct in_addr { unsigned int s_addr; }

variable_types:
dst
struct in_addr { unsigned int s_addr; }


original_code:
void print_arp(char* buf, int print_payload){
    struct arp_hdr* arp;
    struct in_addr src, dst;
    unsigned char* m;
    arp = (struct arp_hdr*)buf;
    src.s_addr = (in_addr_t)arp->sender_ip;
    dst.s_addr = (in_addr_t)arp->target_ip;
    printf("------------------------------------------\n");
    printf("ARP: \n");
    printf("\tSender  IP:      %s\n", inet_ntoa(src));
    m = arp->sender_mac;
    printf("\tSender Mac:      %02x:%02x:%02x:%02x:%02x:%02x\n", m[0], m[1], m[2], m[3], m[4], m[5]);
    printf("\tTarget  IP:      %s\n", inet_ntoa(dst));
    m = arp->target_mac;
    printf("\tTarget Mac:      %02x:%02x:%02x:%02x:%02x:%02x\n", m[0], m[1], m[2], m[3], m[4], m[5]);
    if(arp->opcode == 0){
  printf("\tOP:              Reply\n");
    }else{
     printf("\tOP:              Request\n");
    }
    printf("------------------------------------------\n");
}

canonical_original_code:
void print_arp(char *buf, int print_payload){
    struct arp_hdr *arp;
    struct in_addr src; struct in_addr dst;
    unsigned char *m;
    arp = (struct arp_hdr *)buf;
    src.s_addr = (unsigned int)arp->sender_ip;
    dst.s_addr = (unsigned int)arp->target_ip;
    printf("------------------------------------------\n");
    printf("ARP: \n");
    printf("\tSender  IP:      %s\n", inet_ntoa(src));
    m = arp->sender_mac;
    printf("\tSender Mac:      %02x:%02x:%02x:%02x:%02x:%02x\n", m[0], m[1], m[2], m[3], m[4], m[5]);
    printf("\tTarget  IP:      %s\n", inet_ntoa(dst));
    m = arp->target_mac;
    printf("\tTarget Mac:      %02x:%02x:%02x:%02x:%02x:%02x\n", m[0], m[1], m[2], m[3], m[4], m[5]);
    if(arp->opcode == 0){
  printf("\tOP:              Reply\n");
    }else{
     printf("\tOP:              Request\n");
    }
    printf("------------------------------------------\n");
}

variable_types: struct arp_hdr { unsigned short htype; unsigned short ptype; unsigned char hlen; unsigned char plen; unsigned short opcode; unsigned char sender_mac[6]; unsigned int sender_ip; unsigned char target_mac[6]; unsigned int target_ip; } *

variable_types:
m
unsigned char *


original_code:
void print_eth(char* buf, int print_payload){
    struct ethhdr* eth;
 unsigned char* m;
    eth = (struct ethhdr*)buf;
    printf("Eth: \n");
    m = eth->h_source;
    printf("\tSource Addr:      %02x:%02x:%02x:%02x:%02x:%02x\n", m[0], m[1], m[2], m[3], m[4], m[5]);
    m = eth->h_dest;
    printf("\tDestination Addr: %02x:%02x:%02x:%02x:%02x:%02x\n", m[0], m[1], m[2], m[3], m[4], m[5]);
    if(ntohs(eth->h_proto) == 0x0800)
     printf("\tProtocol:         IP\n");
    else if(ntohs(eth->h_proto) == 0x0806)
     printf("\tProtocol:         ARP\n");
    else
     printf("\tProtocol:         %d\n", eth->h_proto);
    if(print_payload){
        printf("\n");
        if(eth->h_proto == htons(0x0800)){
            print_ip(buf + sizeof(struct ethhdr), print_payload);
        }else if(eth->h_proto == htons(0x0806)){
         print_arp(buf + sizeof(struct ethhdr), print_payload);
        }
    }
    printf("------------------------------------------\n");
}

canonical_original_code:
void print_eth(char *buf, int print_payload){
    struct ethhdr *eth;
 unsigned char *m;
    eth = (struct ethhdr *)buf;
    printf("Eth: \n");
    m = eth->h_source;
    printf("\tSource Addr:      %02x:%02x:%02x:%02x:%02x:%02x\n", m[0], m[1], m[2], m[3], m[4], m[5]);
    m = eth->h_dest;
    printf("\tDestination Addr: %02x:%02x:%02x:%02x:%02x:%02x\n", m[0], m[1], m[2], m[3], m[4], m[5]);
    if(ntohs(eth->h_proto) == 0x0800)
     printf("\tProtocol:         IP\n");
    else if(ntohs(eth->h_proto) == 0x0806)
     printf("\tProtocol:         ARP\n");
    else
     printf("\tProtocol:         %d\n", eth->h_proto);
    if(print_payload){
        printf("\n");
        if(eth->h_proto == htons(0x0800)){
            print_ip(buf + sizeof(struct ethhdr), print_payload);
        }else if(eth->h_proto == htons(0x0806)){
         print_arp(buf + sizeof(struct ethhdr), print_payload);
        }
    }
    printf("------------------------------------------\n");
}

variable_types: struct ethhdr { unsigned char h_dest[6]; unsigned char h_source[6]; unsigned short h_proto; } *


hash

decompiled_code:
__int64 __fastcall hash(unsigned int a1)
{
return a1 % 0x64;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return a1 % 0x64;
}

original_code:
int hash(uint32_t val){
 return val % 100;
}

canonical_original_code:
int hash(unsigned int val){
 return val % 100;
}

variable_types:
val
unsigned int


decompiled_code:
__int64 gum_list()
{
return first_gum;
}

canonical_decompiled_code:
__int64 func1()
{
return first_gum;
}

original_code:
struct gumpck* gum_list(){
 return first_gum;
}

canonical_original_code:
struct gumpck *gum_list(){
 return first_gum;
}

return_type: struct gumpck { unsigned int ip; unsigned char mac[6]; struct gumpck *next; } *


decompiled_code:
__int64 __fastcall gum_lookup(unsigned int a1, __m128i *a2)
{
__int64 v2; // rax
const __m128i *v3; // rdx

v2 = gum_map[(int)hash(a1)];
if ( !v2 )
return 0xFFFFFFFFLL;
while ( 1 )
{
v3 = *(const __m128i **)v2;
if ( **(_DWORD **)v2 == a1 )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0xFFFFFFFFLL;
}
*a2 = _mm_loadu_si128(v3);
a2[1].m128i_i64[0] = v3[1].m128i_i64[0];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __m128i *a2)
{
__int64 v2; // rax
const __m128i *v3; // rdx

v2 = gum_map[(int)func0(a1)];
if ( !v2 )
return 0xFFFFFFFFLL;
while ( 1 )
{
v3 = *(const __m128i **)v2;
if ( **(_DWORD **)v2 == a1 )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0xFFFFFFFFLL;
}
*a2 = _mm_loadu_si128(v3);
a2[1].m128i_i64[0] = v3[1].m128i_i64[0];
return 0LL;
}

original_code:
int gum_lookup(uint32_t ip, struct gumpck* gum){
 struct mapgum* mgum;
 mgum = gum_map[hash(ip)];
 while(mgum != 0){
  if(mgum->gumpck->ip == ip){
   memcpy(gum, mgum->gumpck, sizeof(struct gumpck));
   return 0;
  }
  mgum = mgum->next_mapgum;
 }
 return -1;
}

canonical_original_code:
int gum_lookup(unsigned int ip, struct gumpck *gum){
 struct mapgum *mgum;
 mgum = gum_map[hash(ip)];
 while(mgum != 0){
  if(mgum->gumpck->ip == ip){
   memcpy(gum, mgum->gumpck, sizeof(struct gumpck));
   return 0;
  }
  mgum = mgum->next_mapgum;
 }
 return -1;
}

variable_types:
ip
unsigned int

variable_types: struct mapgum { struct gumpck { unsigned int ip; unsigned char mac[6]; struct gumpck *next; } *gumpck; struct mapgum *next_mapgum; } *

user_defined_types: struct mapgum { struct gumpck *gumpck; struct mapgum *next_mapgum; }


decompiled_code:
__int64 __fastcall gum_add(__int64 a1)
{
__int64 v2; // rax
_QWORD *v3; // rax
unsigned int v4; // edi
__int64 result; // rax
__int64 v6; // rcx
__int64 v7; // rdx

if ( first_gum )
{
v2 = last_gum;
last_gum = a1;
*(_QWORD *)(v2 + 16) = a1;
}
else
{
first_gum = a1;
last_gum = a1;
}
*(_QWORD *)(a1 + 16) = 0LL;
v3 = malloc(0x10uLL);
v4 = *(_DWORD *)a1;
*v3 = a1;
v3[1] = 0LL;
result = (int)hash(v4);
v7 = gum_map[(int)result];
if ( v7 )
*(_QWORD *)(v7 + 8) = v6;
else
gum_map[(int)result] = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v2; // rax
_QWORD *v3; // rax
unsigned int v4; // edi
__int64 result; // rax
__int64 v6; // rcx
__int64 v7; // rdx

if ( first_gum )
{
v2 = last_gum;
last_gum = a1;
*(_QWORD *)(v2 + 16) = a1;
}
else
{
first_gum = a1;
last_gum = a1;
}
*(_QWORD *)(a1 + 16) = 0LL;
v3 = malloc(0x10uLL);
v4 = *(_DWORD *)a1;
*v3 = a1;
v3[1] = 0LL;
result = (int)func0(v4);
v7 = gum_map[(int)result];
if ( v7 )
*(_QWORD *)(v7 + 8) = v6;
else
gum_map[(int)result] = v6;
return result;
}

original_code:
void gum_add(struct gumpck* gum){
 struct mapgum *mgum, *newmgum;
 if(first_gum == 0){
  first_gum = gum;
  last_gum = gum;
 }else{
  last_gum->next = gum;
  last_gum = gum;
 }
 gum->next = 0;
 newmgum = (struct mapgum*)malloc(sizeof(struct mapgum));
 newmgum->gumpck = gum;
 newmgum->next_mapgum = 0;
 mgum = gum_map[hash(gum->ip)];
 if(mgum == 0)
  gum_map[hash(gum->ip)] = newmgum;
 else
  mgum->next_mapgum = newmgum;
}

canonical_original_code:
void gum_add(struct gumpck *gum){
 struct mapgum *mgum; struct mapgum *newmgum;
 if(first_gum == 0){
  first_gum = gum;
  last_gum = gum;
 }else{
  last_gum->next = gum;
  last_gum = gum;
 }
 gum->next = 0;
 newmgum = (struct mapgum *)malloc(sizeof(struct mapgum));
 newmgum->gumpck = gum;
 newmgum->next_mapgum = 0;
 mgum = gum_map[hash(gum->ip)];
 if(mgum == 0)
  gum_map[hash(gum->ip)] = newmgum;
 else
  mgum->next_mapgum = newmgum;
}

variable_types: struct gumpck { unsigned int ip; unsigned char mac[6]; struct gumpck *next; } *


decompiled_code:
void gum_remove()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void gum_remove(struct gumpck* gum){
}

canonical_original_code:
void gum_remove(struct gumpck *gum){
}

user_defined_types: struct gumpck { unsigned int ip; unsigned char mac[6]; struct gumpck *next; }


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

result = memset(&gumtable, 0, (size_t)&unk_186A00);
next = 0LL;
return result;
}

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

result = memset(&gumtable, 0, (size_t)&unk_186A00);
next = 0LL;
return result;
}

original_code:
void init_gum_management(){
 memset(gumtable, 0, 100000 * sizeof(struct gumhash));
 next = 0;
}

user_defined_types: struct gumhash { struct gumpck *gum; long access_time; }


decompiled_code:
void *init_gums()
{
first_gum = 0LL;
last_gum = 0LL;
memset(gum_map, 0, sizeof(gum_map));
return init_gum_management();
}

canonical_decompiled_code:
void *func6()
{
first_gum = 0LL;
last_gum = 0LL;
memset(gum_map, 0, sizeof(gum_map));
return func5();
}

original_code:
void init_gums(){
 int i;
 for (i = 0; i < 100; i++){
  gum_map[i] = 0;
 }
 first_gum = 0;
 last_gum = 0;
 init_gum_management();
}

variable_types: i int


decompiled_code:
__int64 __fastcall set_assigned_gum(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = next;
if ( !next )
result = gum_list();
v2 = *(_QWORD *)(result + 16);
gumtable[2 * a1] = result;
next = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = next;
if ( !next )
result = func1();
v2 = *(_QWORD *)(result + 16);
gumtable[2 * a1] = result;
next = v2;
return result;
}

original_code:
struct gumpck* set_assigned_gum(uint32_t hash){
 if(next == 0)
  next = gum_list();
 gumtable[hash].gum = next;
 next = next->next;
 return gumtable[hash].gum;
}

canonical_original_code:
struct gumpck *set_assigned_gum(unsigned int hash){
 if(next == 0)
  next = gum_list();
 gumtable[hash].gum = next;
 next = next->next;
 return gumtable[hash].gum;
}

variable_types:
hash
unsigned int


decompiled_code:
__int64 __fastcall get_assigned_gum(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rbx

v1 = a1 % 0x186A0;
if ( !gumtable[2 * v1] )
set_assigned_gum(v1);
v2 = 2 * v1;
gumtable[v2 + 1] = time(0LL);
return gumtable[v2];
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rbx

v1 = a1 % 0x186A0;
if ( !gumtable[2 * v1] )
func7(v1);
v2 = 2 * v1;
gumtable[v2 + 1] = time(0LL);
return gumtable[v2];
}

original_code:
struct gumpck* get_assigned_gum(uint32_t hash){
 hash = hash % 100000;
 if(gumtable[hash].gum == 0)
  set_assigned_gum(hash);
 gumtable[hash].access_time = time(0);
 return gumtable[hash].gum;
}

canonical_original_code:
struct gumpck *get_assigned_gum(unsigned int hash){
 hash = hash % 100000;
 if(gumtable[hash].gum == 0)
  set_assigned_gum(hash);
 gumtable[hash].access_time = time(0);
 return gumtable[hash].gum;
}


decompiled_code:
void *__fastcall create_eth(_QWORD *a1, int *a2)
{
size_t v3; // rdi
void *v4; // rax
void *result; // rax

v3 = *a2;
if ( (unsigned int)v3 <= 0xD )
{
*a2 = 14;
v3 = 14LL;
}
v4 = malloc(v3);
result = memset(v4, 0, *a2);
if ( a1 )
*a1 = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func1(_QWORD *a1, int *a2)
{
size_t v3; // rdi
void *v4; // rax
void *result; // rax

v3 = *a2;
if ( (unsigned int)v3 <= 0xD )
{
*a2 = 14;
v3 = 14LL;
}
v4 = malloc(v3);
result = memset(v4, 0, *a2);
if ( a1 )
*a1 = result;
return result;
}

original_code:
char* create_eth(struct ethhdr** eth, int* len){
 char* buf;
 if(*len < sizeof(struct ethhdr))
  *len = sizeof(struct ethhdr);
 buf = (char*) malloc(*len);
 memset(buf, 0, *len);
 if(eth != 0)
  *eth = (struct ethhdr*)buf;
 return buf;
}

canonical_original_code:
char *create_eth(struct ethhdr **eth, int *len){
 char *buf;
 if(*len < sizeof(struct ethhdr))
  *len = sizeof(struct ethhdr);
 buf = (char *) malloc(*len);
 memset(buf, 0, *len);
 if(eth != 0)
  *eth = (struct ethhdr *)buf;
 return buf;
}

variable_types: struct ethhdr { unsigned char h_dest[6]; unsigned char h_source[6]; unsigned short h_proto; } **

variable_types:
len
int *

return_type: char *


original_code:
char* create_eth_ip(struct ethhdr** eth, int* len){
 char* buf;
 struct ethhdr* buf_eth;
 buf = create_eth(&buf_eth, len);
 buf_eth->h_proto = htons(0x0800);
 if(eth != 0)
  (*eth) = buf_eth;
 return buf;
}

canonical_original_code:
char *create_eth_ip(struct ethhdr **eth, int *len){
 char *buf;
 struct ethhdr *buf_eth;
 buf = create_eth(&buf_eth, len);
 buf_eth->h_proto = htons(0x0800);
 if(eth != 0)
  (*eth) = buf_eth;
 return buf;
}

user_defined_types: struct ethhdr { unsigned char h_dest[6]; unsigned char h_source[6]; unsigned short h_proto; }


original_code:
unsigned short checksum_ip(unsigned short *addr, int len){
    register int sum = 0;
    u_short answer = 0;
    register u_short *w = addr;
    register int nleft = len;
    while (nleft > 1){
      sum += *w++;
      nleft -= 2;
    }
    if (nleft == 1){
      *(u_char *) (&answer) = *(u_char *) w;
      sum += answer;
    }
    sum = (sum >> 16) + (sum & 0xffff);
    sum += (sum >> 16);
    answer = ~sum;
    return (answer);
}

canonical_original_code:
unsigned short checksum_ip(unsigned short *addr, int len){
    register int sum = 0;
    unsigned short answer = 0;
    register unsigned short *w = addr;
    register int nleft = len;
    while (nleft > 1){
      sum += *w++;
      nleft -= 2;
    }
    if (nleft == 1){
      *(unsigned char *) (&answer) = *(unsigned char *) w;
      sum += answer;
    }
    sum = (sum >> 16) + (sum & 0xffff);
    sum += (sum >> 16);
    answer = ~sum;
    return (answer);
}

variable_types:
addr
unsigned short *

variable_types: len int

variable_types: sum int

variable_types:
answer
unsigned short

variable_types:
w
unsigned short *

variable_types: nleft int

return_type: unsigned short


original_code:
char* create_ip(struct iphdr** ip, int* len){
 char* buf;
 struct iphdr* buf_ip;
 struct ethhdr* buf_eth;
 if(*len < sizeof(struct ethhdr) + sizeof(struct iphdr)){
  *len = sizeof(struct ethhdr) + sizeof(struct iphdr);
 }
 buf = create_eth(&buf_eth, len);
 buf_eth->h_proto = htons(0x0800);
 buf_ip = (struct iphdr*)(buf + sizeof(struct iphdr));
 buf_ip->ihl = 5;
 buf_ip->tot_len = htons(*len);
 buf_ip->ttl = 255;
 buf_ip->version = 4;
 if(ip != 0)
  (*ip) = buf_ip;
 return buf;
}

canonical_original_code:
char *create_ip(struct iphdr **ip, int *len){
 char *buf;
 struct iphdr *buf_ip;
 struct ethhdr *buf_eth;
 if(*len < sizeof(struct ethhdr) + sizeof(struct iphdr)){
  *len = sizeof(struct ethhdr) + sizeof(struct iphdr);
 }
 buf = create_eth(&buf_eth, len);
 buf_eth->h_proto = htons(0x0800);
 buf_ip = (struct iphdr *)(buf + sizeof(struct iphdr));
 buf_ip->ihl = 5;
 buf_ip->tot_len = htons(*len);
 buf_ip->ttl = 255;
 buf_ip->version = 4;
 if(ip != 0)
  (*ip) = buf_ip;
 return buf;
}

variable_types: struct iphdr { unsigned char ihl; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } **

variable_types:
buf
char *


decompiled_code:
void __fastcall __noreturn start_thread_noarg(void *a1)
{
(*(void (__fastcall **)(_QWORD))a1)(0LL);
free(a1);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
(*(void (__fastcall **)(_QWORD))a1)(0LL);
free(a1);
pthread_exit(0LL);
}

original_code:
void* start_thread_noarg(void* args){
 struct thread_arg_noarg* t_arg = (struct thread_arg_noarg*)args;
 t_arg->fun(((void *)0));
 free(t_arg);
 pthread_exit(((void *)0));
}

canonical_original_code:
void *start_thread_noarg(void *args){
 struct thread_arg_noarg *t_arg = (struct thread_arg_noarg*)args;
 t_arg->fun(((void *)0));
 free(t_arg);
 pthread_exit(((void *)0));
}

variable_types:
args
void *

variable_types: struct thread_arg_noarg { void (*fun)(); } *

return_type: void *


decompiled_code:
void __fastcall __noreturn start_thread_i(void *a1)
{
(*(void (__fastcall **)(_QWORD))a1)(*((unsigned int *)a1 + 2));
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
(*(void (__fastcall **)(_QWORD))a1)(*((unsigned int *)a1 + 2));
pthread_exit(0LL);
}

original_code:
void* start_thread_i(void* args){
 struct thread_arg_int* t_arg = (struct thread_arg_int*)args;
 t_arg->fun(t_arg->arg);
 pthread_exit(((void *)0));
}

canonical_original_code:
void *start_thread_i(void *args){
 struct thread_arg_int *t_arg = (struct thread_arg_int*)args;
 t_arg->fun(t_arg->arg);
 pthread_exit(((void *)0));
}

variable_types: struct thread_arg_int { void (*fun)(int); int arg; } *


decompiled_code:
pthread_t __fastcall thread_init_i(__int64 a1, int a2)
{
pthread_t newthread; // [rsp+8h] [rbp-20h] BYREF
__int64 arg; // [rsp+10h] [rbp-18h] BYREF
int v5; // [rsp+18h] [rbp-10h]

arg = a1;
v5 = a2;
pthread_create(&newthread, 0LL, (void *(*)(void *))start_thread_i, &arg);
return newthread;
}

canonical_decompiled_code:
pthread_t __fastcall func2(__int64 a1, int a2)
{
pthread_t newthread; // [rsp+8h] [rbp-20h] BYREF
__int64 arg; // [rsp+10h] [rbp-18h] BYREF
int v5; // [rsp+18h] [rbp-10h]

arg = a1;
v5 = a2;
pthread_create(&newthread, 0LL, (void *(*)(void *))start_thread_i, &arg);
return newthread;
}

original_code:
thread_t thread_init_i(void (*fun)(int), int arg){
 pthread_t th;
 struct thread_arg_int t_arg;
 t_arg.fun = fun;
 t_arg.arg = arg;
 pthread_create(&th, ((void *)0), start_thread_i, (void*)&t_arg);
 return th;
}

canonical_original_code:
unsigned long thread_init_i(void (*fun)(int), int arg){
 unsigned long th;
 struct thread_arg_int t_arg;
 t_arg.fun = fun;
 t_arg.arg = arg;
 pthread_create(&th, ((void *)0), start_thread_i, (void *)&t_arg);
 return th;
}

variable_types:
fun
void (*)(int)

variable_types: arg int

variable_types:
th
unsigned long

variable_types: struct thread_arg_int { void (*fun)(int); int arg; }

return_type: unsigned long


decompiled_code:
pthread_t __fastcall thread_init(__int64 a1)
{
_QWORD *v1; // rax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = malloc(8uLL);
*v1 = a1;
pthread_create(newthread, 0LL, (void *(*)(void *))start_thread_noarg, v1);
return newthread[0];
}

canonical_decompiled_code:
pthread_t __fastcall func3(__int64 a1)
{
_QWORD *v1; // rax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = malloc(8uLL);
*v1 = a1;
pthread_create(newthread, 0LL, (void *(*)(void *))start_thread_noarg, v1);
return newthread[0];
}

original_code:
thread_t thread_init(void (*fun)()){
 pthread_t th;
 struct thread_arg_noarg* t_arg = (struct thread_arg_noarg*) malloc(sizeof(struct thread_arg_noarg));
 t_arg->fun = fun;
 pthread_create(&th, ((void *)0), start_thread_noarg, (void*)t_arg);
 return th;
}

canonical_original_code:
unsigned long thread_init(void (*fun)()){
 unsigned long th;
 struct thread_arg_noarg *t_arg = (struct thread_arg_noarg*) malloc(sizeof(struct thread_arg_noarg));
 t_arg->fun = fun;
 pthread_create(&th, ((void *)0), start_thread_noarg, (void *)t_arg);
 return th;
}

variable_types:
fun
void (*)()

user_defined_types: struct thread_arg_noarg { void (*fun)(); }


parseSDThead

original_code:
int parseSDThead(unsigned char *data, SDThead *h) {
 int boff = 0;
 memset(h, 0, sizeof(SDThead));
 boff = 0;
 h->table_id = getBit(data, &boff, 8);
 h->section_syntax_indicator = getBit(data, &boff, 1);
 h->reserved_future_use1 = getBit(data, &boff, 1);
 h->reserved1 = getBit(data, &boff, 2);
 h->section_length = getBit(data, &boff, 12);
 h->transport_stream_id = getBit(data, &boff, 16);
 h->reserved2 = getBit(data, &boff, 2);
 h->version_number = getBit(data, &boff, 5);
 h->current_next_indicator = getBit(data, &boff, 1);
 h->section_number = getBit(data, &boff, 8);
 h->last_section_number = getBit(data, &boff, 8);
 h->original_network_id = getBit(data, &boff, 16);
 h->reserved_future_use2 = getBit(data, &boff, 8);
 return 11;
}

canonical_original_code:
int parseSDThead(unsigned char *data, struct _SDThead *h) {
 int boff = 0;
 memset(h, 0, sizeof(SDThead));
 boff = 0;
 h->table_id = getBit(data, &boff, 8);
 h->section_syntax_indicator = getBit(data, &boff, 1);
 h->reserved_future_use1 = getBit(data, &boff, 1);
 h->reserved1 = getBit(data, &boff, 2);
 h->section_length = getBit(data, &boff, 12);
 h->transport_stream_id = getBit(data, &boff, 16);
 h->reserved2 = getBit(data, &boff, 2);
 h->version_number = getBit(data, &boff, 5);
 h->current_next_indicator = getBit(data, &boff, 1);
 h->section_number = getBit(data, &boff, 8);
 h->last_section_number = getBit(data, &boff, 8);
 h->original_network_id = getBit(data, &boff, 16);
 h->reserved_future_use2 = getBit(data, &boff, 8);
 return 11;
}

variable_types:
data
unsigned char *

variable_types: struct _SDThead { char table_id; int section_syntax_indicator; int reserved_future_use1; int reserved1; int section_length; int transport_stream_id; int reserved2; int version_number; int current_next_indicator; int section_number; int last_section_number; int original_network_id; int reserved_future_use2; } *

variable_types: boff int


parseSDTbody

original_code:
int parseSDTbody(unsigned char *data, SDTbody *b) {
 int boff = 0;
 memset(b, 0, sizeof(SDTbody));
 b->service_id = getBit(data, &boff, 16);
 b->reserved_future_use1 = getBit(data, &boff, 3);
 b->EIT_user_defined_flags = getBit(data, &boff, 3);
 b->EIT_schedule_flag = getBit(data, &boff, 1);
 b->EIT_present_following_flag = getBit(data, &boff, 1);
 b->running_status = getBit(data, &boff, 3);
 b->free_CA_mode = getBit(data, &boff, 1);
 b->descriptors_loop_length = getBit(data, &boff, 12);
 return 5;
}

canonical_original_code:
int parseSDTbody(unsigned char *data, struct _SDTbody *b) {
 int boff = 0;
 memset(b, 0, sizeof(SDTbody));
 b->service_id = getBit(data, &boff, 16);
 b->reserved_future_use1 = getBit(data, &boff, 3);
 b->EIT_user_defined_flags = getBit(data, &boff, 3);
 b->EIT_schedule_flag = getBit(data, &boff, 1);
 b->EIT_present_following_flag = getBit(data, &boff, 1);
 b->running_status = getBit(data, &boff, 3);
 b->free_CA_mode = getBit(data, &boff, 1);
 b->descriptors_loop_length = getBit(data, &boff, 12);
 return 5;
}

variable_types: struct _SDTbody { int service_id; int reserved_future_use1; int EIT_user_defined_flags; int EIT_schedule_flag; int EIT_present_following_flag; int running_status; int free_CA_mode; int descriptors_loop_length; } *


parseSVCdesc

decompiled_code:
__int64 __fastcall parseSVCdesc(__int64 a1, _DWORD *a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 0;
memset(a2, 0, 0x2014uLL);
*a2 = getBit(a1, v5, 8LL);
a2[1] = getBit(a1, v5, 8LL);
a2[2] = getBit(a1, v5, 8LL);
v2 = getBit(a1, v5, 8LL);
a2[3] = v2;
getStr(a2 + 4, a1, v5, v2);
v3 = getBit(a1, v5, 8LL);
a2[1028] = v3;
getStr(a2 + 1029, a1, v5, v3);
return (unsigned int)(a2[1] + 2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _DWORD *a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 0;
memset(a2, 0, 0x2014uLL);
*a2 = getBit(a1, v5, 8LL);
a2[1] = getBit(a1, v5, 8LL);
a2[2] = getBit(a1, v5, 8LL);
v2 = getBit(a1, v5, 8LL);
a2[3] = v2;
getStr(a2 + 4, a1, v5, v2);
v3 = getBit(a1, v5, 8LL);
a2[1028] = v3;
getStr(a2 + 1029, a1, v5, v3);
return (unsigned int)(a2[1] + 2);
}

original_code:
int parseSVCdesc(unsigned char *data, SVCdesc *desc) {
 int boff = 0;
 memset(desc, 0, sizeof(SVCdesc));
 desc->descriptor_tag = getBit(data, &boff, 8);
 desc->descriptor_length = getBit(data, &boff, 8);
 desc->service_type = getBit(data, &boff, 8);
 desc->service_provider_name_length = getBit(data, &boff, 8);
 getStr(desc->service_provider_name, data, &boff, desc->service_provider_name_length);
 desc->service_name_length = getBit(data, &boff, 8);
 getStr(desc->service_name, data, &boff, desc->service_name_length);
 return desc->descriptor_length + 2;
}

canonical_original_code:
int parseSVCdesc(unsigned char *data, struct _SVCdesc *desc) {
 int boff = 0;
 memset(desc, 0, sizeof(SVCdesc));
 desc->descriptor_tag = getBit(data, &boff, 8);
 desc->descriptor_length = getBit(data, &boff, 8);
 desc->service_type = getBit(data, &boff, 8);
 desc->service_provider_name_length = getBit(data, &boff, 8);
 getStr(desc->service_provider_name, data, &boff, desc->service_provider_name_length);
 desc->service_name_length = getBit(data, &boff, 8);
 getStr(desc->service_name, data, &boff, desc->service_name_length);
 return desc->descriptor_length + 2;
}

variable_types: struct _SVCdesc { int descriptor_tag; int descriptor_length; int service_type; int service_provider_name_length; char service_provider_name[4096]; int service_name_length; char service_name[4096]; } *


serachid

decompiled_code:
__int64 __fastcall serachid(__int64 *a1, int a2)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *((_DWORD *)a1 + 4) == a2 )
break;
a1 = (__int64 *)*a1;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, int a2)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *((_DWORD *)a1 + 4) == a2 )
break;
a1 = (__int64 *)*a1;
}
return 1LL;
}

original_code:
int serachid(SVT_CONTROL *top, int service_id)
{
 SVT_CONTROL *cur = top ;
 while(cur != ((void *)0)){
  if(cur->event_id == service_id){
   return 1 ;
  }
  cur = cur->next ;
 }
 return 0 ;
}

canonical_original_code:
int serachid(struct _SVT_CONTROL *top, int service_id)
{
 struct _SVT_CONTROL *cur = top;
 while(cur != ((void *)0)){
  if(cur->event_id == service_id){
   return 1 ;
  }
  cur = cur->next ;
 }
 return 0 ;
}

variable_types: struct _SVT_CONTROL { struct _SVT_CONTROL *next; struct _SVT_CONTROL *prev; int event_id; int original_network_id; int transport_stream_id; char servicename[4096]; } *


dumpSDT

original_code:
void dumpSDT(unsigned char *ptr, SVT_CONTROL *top)
{
 SDThead sdth;
 SDTbody sdtb;
 SVCdesc desc;
 SVT_CONTROL *svtptr ;
 int rc ;
 int len = 0;
 int loop_len = 0;
 len = parseSDThead(ptr, &sdth);
 ptr += len;
 loop_len = sdth.section_length - (len - 3 + 4);
 while(loop_len > 0) {
  len = parseSDTbody(ptr, &sdtb);
  ptr += len;
  loop_len -= len;
  parseSVCdesc(ptr, &desc);
  rc = serachid(top, sdtb.service_id);
  if(rc == 0){
   svtptr = calloc(1, sizeof(SVT_CONTROL));
   svtptr->event_id = sdtb.service_id;
   svtptr->original_network_id = sdth.original_network_id;
   svtptr->transport_stream_id = sdth.transport_stream_id;
   svtptr->event_id = sdtb.service_id;
   memcpy(svtptr->servicename, desc.service_name, strlen(desc.service_name));
   enqueue_sdt(top, svtptr);
  }
  ptr += sdtb.descriptors_loop_length;
  loop_len -= sdtb.descriptors_loop_length;
 }
 return;
}

canonical_original_code:
void dumpSDT(unsigned char *ptr, struct _SVT_CONTROL *top)
{
 struct _SDThead sdth;
 struct _SDTbody sdtb;
 struct _SVCdesc desc;
 struct _SVT_CONTROL *svtptr;
 int rc;
 int len = 0;
 int loop_len = 0;
 len = parseSDThead(ptr, &sdth);
 ptr += len;
 loop_len = sdth.section_length - (len - 3 + 4);
 while(loop_len > 0) {
  len = parseSDTbody(ptr, &sdtb);
  ptr += len;
  loop_len -= len;
  parseSVCdesc(ptr, &desc);
  rc = serachid(top, sdtb.service_id);
  if(rc == 0){
   svtptr = calloc(1, sizeof(SVT_CONTROL));
   svtptr->event_id = sdtb.service_id;
   svtptr->original_network_id = sdth.original_network_id;
   svtptr->transport_stream_id = sdth.transport_stream_id;
   svtptr->event_id = sdtb.service_id;
   memcpy(svtptr->servicename, desc.service_name, strlen(desc.service_name));
   enqueue_sdt(top, svtptr);
  }
  ptr += sdtb.descriptors_loop_length;
  loop_len -= sdtb.descriptors_loop_length;
 }
 return;
}

variable_types:
ptr
unsigned char *

variable_types: struct _SDThead { char table_id; int section_syntax_indicator; int reserved_future_use1; int reserved1; int section_length; int transport_stream_id; int reserved2; int version_number; int current_next_indicator; int section_number; int last_section_number; int original_network_id; int reserved_future_use2; }

variable_types: struct _SDTbody { int service_id; int reserved_future_use1; int EIT_user_defined_flags; int EIT_schedule_flag; int EIT_present_following_flag; int running_status; int free_CA_mode; int descriptors_loop_length; }

variable_types: struct _SVCdesc { int descriptor_tag; int descriptor_length; int service_type; int service_provider_name_length; char service_provider_name[4096]; int service_name_length; char service_name[4096]; }

variable_types: rc int

variable_types: len int

user_defined_types: struct _SVT_CONTROL { struct _SVT_CONTROL *next; struct _SVT_CONTROL *prev; int event_id; int original_network_id; int transport_stream_id; char servicename[4096]; }


PutAlphanumericChar

decompiled_code:
__int64 __fastcall PutAlphanumericChar(_BYTE *a1, int a2)
{
char v2; // dl
__int64 result; // rax

*a1 = byte_A50[3 * a2];
v2 = byte_A50[3 * a2 + 1];
a1[2] = byte_A50[3 * a2 + 2];
result = 3LL;
a1[1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, int a2)
{
char v2; // dl
__int64 result; // rax

*a1 = byte_A50[3 * a2];
v2 = byte_A50[3 * a2 + 1];
a1[2] = byte_A50[3 * a2 + 2];
result = 3LL;
a1[1] = v2;
return result;
}

original_code:
const int PutAlphanumericChar(char *lpszDst, const int wCode)
{
 static const char *acAlphanumericTable =
  "　　　　　　　　　　　　　　　　"
  "　　　　　　　　　　　　　　　　"
  "　！”＃＄％＆’（）＊＋，－．／"
  "０１２３４５６７８９：；＜＝＞？"
  "＠ＡＢＣＤＥＦＧＨＩＪＫＬＭＮＯ"
  "ＰＱＲＳＴＵＶＷＸＹＺ［￥］＾＿"
  "　ａｂｃｄｅｆｇｈｉｊｋｌｍｎｏ"
  "ｐｑｒｓｔｕｖｗｘｙｚ｛｜｝￣　";
 lpszDst[0] = acAlphanumericTable[wCode * 3U + 0U];
 lpszDst[1] = acAlphanumericTable[wCode * 3U + 1U];
 lpszDst[2] = acAlphanumericTable[wCode * 3U + 2U];
 return 3UL;
}

canonical_original_code:
int PutAlphanumericChar(char *lpszDst, int wCode)
{
 static char *acAlphanumericTable = "　　　　　　　　　　　　　　　　"
  "　　　　　　　　　　　　　　　　"
  "　！”＃＄％＆’（）＊＋，－．／"
  "０１２３４５６７８９：；＜＝＞？"
  "＠ＡＢＣＤＥＦＧＨＩＪＫＬＭＮＯ"
  "ＰＱＲＳＴＵＶＷＸＹＺ［￥］＾＿"
  "　ａｂｃｄｅｆｇｈｉｊｋｌｍｎｏ"
  "ｐｑｒｓｔｕｖｗｘｙｚ｛｜｝￣　";
 lpszDst[0] = acAlphanumericTable[wCode * 3U + 0U];
 lpszDst[1] = acAlphanumericTable[wCode * 3U + 1U];
 lpszDst[2] = acAlphanumericTable[wCode * 3U + 2U];
 return 3UL;
}

variable_types:
lpszDst
char *

variable_types: wCode int

variable_types:
acAlphanumericTable
char *


PutHiraganaChar

decompiled_code:
__int64 __fastcall PutHiraganaChar(_BYTE *a1, int a2)
{
char v2; // dl
__int64 result; // rax

*a1 = byte_BD8[3 * a2];
v2 = byte_BD8[3 * a2 + 1];
a1[2] = byte_BD8[3 * a2 + 2];
result = 3LL;
a1[1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, int a2)
{
char v2; // dl
__int64 result; // rax

*a1 = byte_BD8[3 * a2];
v2 = byte_BD8[3 * a2 + 1];
a1[2] = byte_BD8[3 * a2 + 2];
result = 3LL;
a1[1] = v2;
return result;
}

original_code:
const int PutHiraganaChar(char *lpszDst, const int wCode)
{
 static const char *acHiraganaTable =
  "　　　　　　　　　　　　　　　　"
  "　　　　　　　　　　　　　　　　"
  "　ぁあぃいぅうぇえぉおかがきぎく"
  "ぐけげこごさざしじすずせぜそぞた"
  "だちぢっつづてでとどなにぬねのは"
  "ばぱひびぴふぶぷへべぺほぼぽまみ"
  "むめもゃやゅゆょよらりるれろゎわ"
  "ゐゑをん　　　ゝゞー。「」、・　";
 lpszDst[0] = acHiraganaTable[wCode * 3U + 0U];
 lpszDst[1] = acHiraganaTable[wCode * 3U + 1U];
 lpszDst[2] = acHiraganaTable[wCode * 3U + 2U];
 return 3UL;
}

canonical_original_code:
int PutHiraganaChar(char *lpszDst, int wCode)
{
 static char *acHiraganaTable = "　　　　　　　　　　　　　　　　"
  "　　　　　　　　　　　　　　　　"
  "　ぁあぃいぅうぇえぉおかがきぎく"
  "ぐけげこごさざしじすずせぜそぞた"
  "だちぢっつづてでとどなにぬねのは"
  "ばぱひびぴふぶぷへべぺほぼぽまみ"
  "むめもゃやゅゆょよらりるれろゎわ"
  "ゐゑをん　　　ゝゞー。「」、・　";
 lpszDst[0] = acHiraganaTable[wCode * 3U + 0U];
 lpszDst[1] = acHiraganaTable[wCode * 3U + 1U];
 lpszDst[2] = acHiraganaTable[wCode * 3U + 2U];
 return 3UL;
}

variable_types:
acHiraganaTable
char *


PutKatakanaChar

decompiled_code:
__int64 __fastcall PutKatakanaChar(_BYTE *a1, int a2)
{
char v2; // dl
__int64 result; // rax

*a1 = byte_D60[3 * a2];
v2 = byte_D60[3 * a2 + 1];
a1[2] = byte_D60[3 * a2 + 2];
result = 3LL;
a1[1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, int a2)
{
char v2; // dl
__int64 result; // rax

*a1 = byte_D60[3 * a2];
v2 = byte_D60[3 * a2 + 1];
a1[2] = byte_D60[3 * a2 + 2];
result = 3LL;
a1[1] = v2;
return result;
}

original_code:
const int PutKatakanaChar(char *lpszDst, const int wCode)
{
 static const char *acKatakanaTable =
  "　　　　　　　　　　　　　　　　"
  "　　　　　　　　　　　　　　　　"
  "　ァアィイゥウェエォオカガキギク"
  "グケゲコゴサザシジスズセゼソゾタ"
  "ダチヂッツヅテデトドナニヌネノハ"
  "バパヒビピフブプヘベペホボポマミ"
  "ムメモャヤュユョヨラリルレロヮワ"
  "ヰヱヲンヴヵヶヽヾー。「」、・　";
 lpszDst[0] = acKatakanaTable[wCode * 3U + 0U];
 lpszDst[1] = acKatakanaTable[wCode * 3U + 1U];
 lpszDst[2] = acKatakanaTable[wCode * 3U + 2U];
 return 3UL;
}

canonical_original_code:
int PutKatakanaChar(char *lpszDst, int wCode)
{
 static char *acKatakanaTable = "　　　　　　　　　　　　　　　　"
  "　　　　　　　　　　　　　　　　"
  "　ァアィイゥウェエォオカガキギク"
  "グケゲコゴサザシジスズセゼソゾタ"
  "ダチヂッツヅテデトドナニヌネノハ"
  "バパヒビピフブプヘベペホボポマミ"
  "ムメモャヤュユョヨラリルレロヮワ"
  "ヰヱヲンヴヵヶヽヾー。「」、・　";
 lpszDst[0] = acKatakanaTable[wCode * 3U + 0U];
 lpszDst[1] = acKatakanaTable[wCode * 3U + 1U];
 lpszDst[2] = acKatakanaTable[wCode * 3U + 2U];
 return 3UL;
}

variable_types:
acKatakanaTable
char *


PutJisKatakanaChar

decompiled_code:
__int64 __fastcall PutJisKatakanaChar(_BYTE *a1, int a2)
{
char v2; // dl
__int64 result; // rax

*a1 = byte_EE8[3 * a2];
v2 = byte_EE8[3 * a2 + 1];
a1[2] = byte_EE8[3 * a2 + 2];
result = 3LL;
a1[1] = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, int a2)
{
char v2; // dl
__int64 result; // rax

*a1 = byte_EE8[3 * a2];
v2 = byte_EE8[3 * a2 + 1];
a1[2] = byte_EE8[3 * a2 + 2];
result = 3LL;
a1[1] = v2;
return result;
}

original_code:
const int PutJisKatakanaChar(char *lpszDst, const int wCode)
{
 static const char *acJisKatakanaTable =
  "　　　　　　　　　　　　　　　　"
  "　　　　　　　　　　　　　　　　"
  "　。「」、・ヲァィゥェォャュョッ"
  "ーアイウエオカキクケコサシスセソ"
  "タチツテトナニヌネノハヒフヘホマ"
  "ミムメモヤユヨラリルレロワン゛゜"
  "　　　　　　　　　　　　　　　　"
  "　　　　　　　　　　　　　　　　";
 lpszDst[0] = acJisKatakanaTable[wCode * 3U + 0U];
 lpszDst[1] = acJisKatakanaTable[wCode * 3U + 1U];
 lpszDst[2] = acJisKatakanaTable[wCode * 3U + 2U];
 return 3UL;
}

canonical_original_code:
int PutJisKatakanaChar(char *lpszDst, int wCode)
{
 static char *acJisKatakanaTable = "　　　　　　　　　　　　　　　　"
  "　　　　　　　　　　　　　　　　"
  "　。「」、・ヲァィゥェォャュョッ"
  "ーアイウエオカキクケコサシスセソ"
  "タチツテトナニヌネノハヒフヘホマ"
  "ミムメモヤユヨラリルレロワン゛゜"
  "　　　　　　　　　　　　　　　　"
  "　　　　　　　　　　　　　　　　";
 lpszDst[0] = acJisKatakanaTable[wCode * 3U + 0U];
 lpszDst[1] = acJisKatakanaTable[wCode * 3U + 1U];
 lpszDst[2] = acJisKatakanaTable[wCode * 3U + 2U];
 return 3UL;
}

variable_types:
acJisKatakanaTable
char *


LockingShiftGL

decompiled_code:
char *__fastcall LockingShiftGL(char a1)
{
char *result; // rax

result = (char *)&m_CodeG + 4 * a1;
m_pLockingGL = (__int64)result;
return result;
}

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

result = (char *)&m_CodeG + 4 * a1;
m_pLockingGL = (__int64)result;
return result;
}

original_code:
void LockingShiftGL(const char byIndexG)
{
 m_pLockingGL = &m_CodeG[(int)byIndexG];
}

canonical_original_code:
void LockingShiftGL(char byIndexG)
{
 m_pLockingGL = &m_CodeG[(int)byIndexG];
}

variable_types: byIndexG char


LockingShiftGR

decompiled_code:
char *__fastcall LockingShiftGR(char a1)
{
char *result; // rax

result = (char *)&m_CodeG + 4 * a1;
m_pLockingGR = (__int64)result;
return result;
}

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

result = (char *)&m_CodeG + 4 * a1;
m_pLockingGR = (__int64)result;
return result;
}

original_code:
void LockingShiftGR(const char byIndexG)
{
 m_pLockingGR = &m_CodeG[(int)byIndexG];
}

canonical_original_code:
void LockingShiftGR(char byIndexG)
{
 m_pLockingGR = &m_CodeG[(int)byIndexG];
}


SingleShiftGL

decompiled_code:
char *__fastcall SingleShiftGL(char a1)
{
char *result; // rax

result = (char *)&m_CodeG + 4 * a1;
m_pSingleGL = (__int64)result;
return result;
}

canonical_decompiled_code:
char *__fastcall func6(char a1)
{
char *result; // rax

result = (char *)&m_CodeG + 4 * a1;
m_pSingleGL = (__int64)result;
return result;
}

original_code:
void SingleShiftGL(const char byIndexG)
{
 m_pSingleGL = &m_CodeG[(int)byIndexG];
}

canonical_original_code:
void SingleShiftGL(char byIndexG)
{
 m_pSingleGL = &m_CodeG[(int)byIndexG];
}


DesignationGSET

decompiled_code:
__int64 __fastcall DesignationGSET(char a1, char a2)
{
__int64 result; // rax

switch ( a2 )
{
case '0':
*((_DWORD *)&m_CodeG + a1) = 3;
result = 1LL;
break;
case '1':
*((_DWORD *)&m_CodeG + a1) = 4;
result = 1LL;
break;
case '2':
*((_DWORD *)&m_CodeG + a1) = 5;
result = 1LL;
break;
case '3':
*((_DWORD *)&m_CodeG + a1) = 6;
result = 1LL;
break;
case '4':
*((_DWORD *)&m_CodeG + a1) = 7;
result = 1LL;
break;
case '5':
*((_DWORD *)&m_CodeG + a1) = 8;
result = 1LL;
break;
case '6':
*((_DWORD *)&m_CodeG + a1) = 9;
result = 1LL;
break;
case '7':
*((_DWORD *)&m_CodeG + a1) = 10;
result = 1LL;
break;
case '8':
*((_DWORD *)&m_CodeG + a1) = 11;
result = 1LL;
break;
case '9':
*((_DWORD *)&m_CodeG + a1) = 13;
result = 1LL;
break;
case ':':
*((_DWORD *)&m_CodeG + a1) = 14;
result = 1LL;
break;
case ';':
*((_DWORD *)&m_CodeG + a1) = 15;
result = 1LL;
break;
case 'B':
*((_DWORD *)&m_CodeG + a1) = 1;
result = 1LL;
break;
case 'I':
*((_DWORD *)&m_CodeG + a1) = 12;
result = 1LL;
break;
case 'J':
*((_DWORD *)&m_CodeG + a1) = 2;
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a2 )
{
case '0':
*((_DWORD *)&m_CodeG + a1) = 3;
result = 1LL;
break;
case '1':
*((_DWORD *)&m_CodeG + a1) = 4;
result = 1LL;
break;
case '2':
*((_DWORD *)&m_CodeG + a1) = 5;
result = 1LL;
break;
case '3':
*((_DWORD *)&m_CodeG + a1) = 6;
result = 1LL;
break;
case '4':
*((_DWORD *)&m_CodeG + a1) = 7;
result = 1LL;
break;
case '5':
*((_DWORD *)&m_CodeG + a1) = 8;
result = 1LL;
break;
case '6':
*((_DWORD *)&m_CodeG + a1) = 9;
result = 1LL;
break;
case '7':
*((_DWORD *)&m_CodeG + a1) = 10;
result = 1LL;
break;
case '8':
*((_DWORD *)&m_CodeG + a1) = 11;
result = 1LL;
break;
case '9':
*((_DWORD *)&m_CodeG + a1) = 13;
result = 1LL;
break;
case ':':
*((_DWORD *)&m_CodeG + a1) = 14;
result = 1LL;
break;
case ';':
*((_DWORD *)&m_CodeG + a1) = 15;
result = 1LL;
break;
case 'B':
*((_DWORD *)&m_CodeG + a1) = 1;
result = 1LL;
break;
case 'I':
*((_DWORD *)&m_CodeG + a1) = 12;
result = 1LL;
break;
case 'J':
*((_DWORD *)&m_CodeG + a1) = 2;
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
const int DesignationGSET(const char byIndexG_arg, const char byCode)
{
 int byIndexG = (int)byIndexG_arg;
 switch(byCode){
 case 0x42U : m_CodeG[byIndexG] = 1; return 1;
 case 0x4AU : m_CodeG[byIndexG] = 2; return 1;
 case 0x30U : m_CodeG[byIndexG] = 3; return 1;
 case 0x31U : m_CodeG[byIndexG] = 4; return 1;
 case 0x32U : m_CodeG[byIndexG] = 5; return 1;
 case 0x33U : m_CodeG[byIndexG] = 6; return 1;
 case 0x34U : m_CodeG[byIndexG] = 7; return 1;
 case 0x35U : m_CodeG[byIndexG] = 8; return 1;
 case 0x36U : m_CodeG[byIndexG] = 9; return 1;
 case 0x37U : m_CodeG[byIndexG] = 10; return 1;
 case 0x38U : m_CodeG[byIndexG] = 11; return 1;
 case 0x49U : m_CodeG[byIndexG] = 12; return 1;
 case 0x39U : m_CodeG[byIndexG] = 13; return 1;
 case 0x3AU : m_CodeG[byIndexG] = 14; return 1;
 case 0x3BU : m_CodeG[byIndexG] = 15; return 1;
 default : return 0;
 }
}

canonical_original_code:
int DesignationGSET(char byIndexG_arg, char byCode)
{
 int byIndexG = (int)byIndexG_arg;
 switch(byCode){
 case 0x42U : m_CodeG[byIndexG] = 1; return 1;
 case 0x4AU : m_CodeG[byIndexG] = 2; return 1;
 case 0x30U : m_CodeG[byIndexG] = 3; return 1;
 case 0x31U : m_CodeG[byIndexG] = 4; return 1;
 case 0x32U : m_CodeG[byIndexG] = 5; return 1;
 case 0x33U : m_CodeG[byIndexG] = 6; return 1;
 case 0x34U : m_CodeG[byIndexG] = 7; return 1;
 case 0x35U : m_CodeG[byIndexG] = 8; return 1;
 case 0x36U : m_CodeG[byIndexG] = 9; return 1;
 case 0x37U : m_CodeG[byIndexG] = 10; return 1;
 case 0x38U : m_CodeG[byIndexG] = 11; return 1;
 case 0x49U : m_CodeG[byIndexG] = 12; return 1;
 case 0x39U : m_CodeG[byIndexG] = 13; return 1;
 case 0x3AU : m_CodeG[byIndexG] = 14; return 1;
 case 0x3BU : m_CodeG[byIndexG] = 15; return 1;
 default : return 0;
 }
}

variable_types: byCode char

variable_types: byIndexG int


DesignationDRCS

decompiled_code:
__int64 __fastcall DesignationDRCS(char a1, char a2)
{
if ( a2 > 79 )
{
if ( a2 != 112 )
return 0LL;
}
else if ( a2 <= 63 )
{
return 0LL;
}
*((_DWORD *)&m_CodeG + a1) = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1, char a2)
{
if ( a2 > 79 )
{
if ( a2 != 112 )
return 0LL;
}
else if ( a2 <= 63 )
{
return 0LL;
}
*((_DWORD *)&m_CodeG + a1) = 0;
return 1LL;
}

original_code:
const int DesignationDRCS(const char byIndexG_arg, const char byCode)
{
 int byIndexG = (int)byIndexG_arg;
 switch(byCode){
 case 0x40U : m_CodeG[byIndexG] = 0; return 1;
 case 0x41U : m_CodeG[byIndexG] = 0; return 1;
 case 0x42U : m_CodeG[byIndexG] = 0; return 1;
 case 0x43U : m_CodeG[byIndexG] = 0; return 1;
 case 0x44U : m_CodeG[byIndexG] = 0; return 1;
 case 0x45U : m_CodeG[byIndexG] = 0; return 1;
 case 0x46U : m_CodeG[byIndexG] = 0; return 1;
 case 0x47U : m_CodeG[byIndexG] = 0; return 1;
 case 0x48U : m_CodeG[byIndexG] = 0; return 1;
 case 0x49U : m_CodeG[byIndexG] = 0; return 1;
 case 0x4AU : m_CodeG[byIndexG] = 0; return 1;
 case 0x4BU : m_CodeG[byIndexG] = 0; return 1;
 case 0x4CU : m_CodeG[byIndexG] = 0; return 1;
 case 0x4DU : m_CodeG[byIndexG] = 0; return 1;
 case 0x4EU : m_CodeG[byIndexG] = 0; return 1;
 case 0x4FU : m_CodeG[byIndexG] = 0; return 1;
 case 0x70U : m_CodeG[byIndexG] = 0; return 1;
 default : return 0;
}
}

canonical_original_code:
int DesignationDRCS(char byIndexG_arg, char byCode)
{
 int byIndexG = (int)byIndexG_arg;
 switch(byCode){
 case 0x40U : m_CodeG[byIndexG] = 0; return 1;
 case 0x41U : m_CodeG[byIndexG] = 0; return 1;
 case 0x42U : m_CodeG[byIndexG] = 0; return 1;
 case 0x43U : m_CodeG[byIndexG] = 0; return 1;
 case 0x44U : m_CodeG[byIndexG] = 0; return 1;
 case 0x45U : m_CodeG[byIndexG] = 0; return 1;
 case 0x46U : m_CodeG[byIndexG] = 0; return 1;
 case 0x47U : m_CodeG[byIndexG] = 0; return 1;
 case 0x48U : m_CodeG[byIndexG] = 0; return 1;
 case 0x49U : m_CodeG[byIndexG] = 0; return 1;
 case 0x4AU : m_CodeG[byIndexG] = 0; return 1;
 case 0x4BU : m_CodeG[byIndexG] = 0; return 1;
 case 0x4CU : m_CodeG[byIndexG] = 0; return 1;
 case 0x4DU : m_CodeG[byIndexG] = 0; return 1;
 case 0x4EU : m_CodeG[byIndexG] = 0; return 1;
 case 0x4FU : m_CodeG[byIndexG] = 0; return 1;
 case 0x70U : m_CodeG[byIndexG] = 0; return 1;
 default : return 0;
}
}


ProcessEscapeSeq

decompiled_code:
void __fastcall ProcessEscapeSeq(char a1)
{
char v1; // cl
char v2; // dl
char v3; // dl

v1 = m_byEscSeqCount;
if ( m_byEscSeqCount == 3 )
{
if ( m_bIsEscSeqDrcs )
{
if ( (unsigned int)DesignationDRCS(m_byEscSeqIndex, a1) )
goto LABEL_9;
}
else if ( (unsigned int)DesignationGSET(m_byEscSeqIndex, a1) )
{
goto LABEL_9;
}
if ( v3 != 32 )
goto LABEL_9;
LABEL_13:
m_bIsEscSeqDrcs = 1;
LABEL_14:
m_byEscSeqCount = v1 + 1;
return;
}
if ( m_byEscSeqCount > 3 )
{
if ( m_byEscSeqCount == 4 )
{
DesignationDRCS(m_byEscSeqIndex, a1);
LABEL_9:
m_byEscSeqCount = 0;
return;
}
goto LABEL_14;
}
if ( m_byEscSeqCount != 1 )
{
if ( m_byEscSeqCount == 2 )
{
if ( !(unsigned int)DesignationGSET(m_byEscSeqIndex, a1) )
{
switch ( v2 )
{
case ' ':
goto LABEL_13;
case '(':
m_bIsEscSeqDrcs = 1;
goto LABEL_22;
case ')':
m_bIsEscSeqDrcs = 0;
goto LABEL_28;
case '*':
m_bIsEscSeqDrcs = 0;
goto LABEL_26;
case '+':
m_bIsEscSeqDrcs = 0;
goto LABEL_24;
default:
goto LABEL_9;
}
}
goto LABEL_9;
}
goto LABEL_14;
}
if ( a1 <= 43 )
{
if ( a1 > 35 )
{
switch ( a1 )
{
case '$':
case '(':
LABEL_22:
m_byEscSeqIndex = 0;
goto LABEL_14;
case ')':
LABEL_28:
m_byEscSeqIndex = 1;
goto LABEL_14;
case '*':
LABEL_26:
m_byEscSeqIndex = 2;
goto LABEL_14;
case '+':
LABEL_24:
m_byEscSeqIndex = 3;
goto LABEL_14;
default:
goto LABEL_9;
}
}
goto LABEL_9;
}
switch ( a1 )
{
case 'n':
LockingShiftGL(2);
m_byEscSeqCount = 0;
break;
case 'o':
LockingShiftGL(3);
m_byEscSeqCount = 0;
break;
case '|':
LockingShiftGR(3);
m_byEscSeqCount = 0;
break;
case '}':
LockingShiftGR(2);
m_byEscSeqCount = 0;
break;
case '~':
LockingShiftGR(1);
m_byEscSeqCount = 0;
break;
default:
goto LABEL_9;
}
}

canonical_decompiled_code:
void __fastcall func9(char a1)
{
char v1; // cl
char v2; // dl
char v3; // dl

v1 = m_byEscSeqCount;
if ( m_byEscSeqCount == 3 )
{
if ( m_bIsEscSeqDrcs )
{
if ( (unsigned int)func8(m_byEscSeqIndex, a1) )
goto LABEL_9;
}
else if ( (unsigned int)func7(m_byEscSeqIndex, a1) )
{
goto LABEL_9;
}
if ( v3 != 32 )
goto LABEL_9;
LABEL_13:
m_bIsEscSeqDrcs = 1;
LABEL_14:
m_byEscSeqCount = v1 + 1;
return;
}
if ( m_byEscSeqCount > 3 )
{
if ( m_byEscSeqCount == 4 )
{
func8(m_byEscSeqIndex, a1);
LABEL_9:
m_byEscSeqCount = 0;
return;
}
goto LABEL_14;
}
if ( m_byEscSeqCount != 1 )
{
if ( m_byEscSeqCount == 2 )
{
if ( !(unsigned int)func7(m_byEscSeqIndex, a1) )
{
switch ( v2 )
{
case ' ':
goto LABEL_13;
case '(':
m_bIsEscSeqDrcs = 1;
goto LABEL_22;
case ')':
m_bIsEscSeqDrcs = 0;
goto LABEL_28;
case '*':
m_bIsEscSeqDrcs = 0;
goto LABEL_26;
case '+':
m_bIsEscSeqDrcs = 0;
goto LABEL_24;
default:
goto LABEL_9;
}
}
goto LABEL_9;
}
goto LABEL_14;
}
if ( a1 <= 43 )
{
if ( a1 > 35 )
{
switch ( a1 )
{
case '$':
case '(':
LABEL_22:
m_byEscSeqIndex = 0;
goto LABEL_14;
case ')':
LABEL_28:
m_byEscSeqIndex = 1;
goto LABEL_14;
case '*':
LABEL_26:
m_byEscSeqIndex = 2;
goto LABEL_14;
case '+':
LABEL_24:
m_byEscSeqIndex = 3;
goto LABEL_14;
default:
goto LABEL_9;
}
}
goto LABEL_9;
}
switch ( a1 )
{
case 'n':
func4(2);
m_byEscSeqCount = 0;
break;
case 'o':
func4(3);
m_byEscSeqCount = 0;
break;
case '|':
func5(3);
m_byEscSeqCount = 0;
break;
case '}':
func5(2);
m_byEscSeqCount = 0;
break;
case '~':
func5(1);
m_byEscSeqCount = 0;
break;
default:
goto LABEL_9;
}
}

original_code:
void ProcessEscapeSeq(const char byCode)
{
 switch(m_byEscSeqCount){
 case 1U :
  switch(byCode){
  case 0x6EU : LockingShiftGL(2U); m_byEscSeqCount = 0U; return;
  case 0x6FU : LockingShiftGL(3U); m_byEscSeqCount = 0U; return;
  case 0x7EU : LockingShiftGR(1U); m_byEscSeqCount = 0U; return;
  case 0x7DU : LockingShiftGR(2U); m_byEscSeqCount = 0U; return;
  case 0x7CU : LockingShiftGR(3U); m_byEscSeqCount = 0U; return;
  case 0x24U :
  case 0x28U : m_byEscSeqIndex = 0U; break;
  case 0x29U : m_byEscSeqIndex = 1U; break;
  case 0x2AU : m_byEscSeqIndex = 2U; break;
  case 0x2BU : m_byEscSeqIndex = 3U; break;
  default : m_byEscSeqCount = 0U; return;
  }
  break;
 case 2U :
  if(DesignationGSET(m_byEscSeqIndex, byCode)){
   m_byEscSeqCount = 0U;
   return;
  }
  switch(byCode){
  case 0x20 : m_bIsEscSeqDrcs = 1; break;
  case 0x28 : m_bIsEscSeqDrcs = 1; m_byEscSeqIndex = 0U; break;
  case 0x29 : m_bIsEscSeqDrcs = 0; m_byEscSeqIndex = 1U; break;
  case 0x2A : m_bIsEscSeqDrcs = 0; m_byEscSeqIndex = 2U; break;
  case 0x2B : m_bIsEscSeqDrcs = 0; m_byEscSeqIndex = 3U; break;
  default : m_byEscSeqCount = 0U; return;
  }
  break;
 case 3U :
  if(!m_bIsEscSeqDrcs){
   if(DesignationGSET(m_byEscSeqIndex, byCode)){
    m_byEscSeqCount = 0U;
    return;
   }
  }
  else{
   if(DesignationDRCS(m_byEscSeqIndex, byCode)){
    m_byEscSeqCount = 0U;
    return;
   }
  }
  if(byCode == 0x20U){
   m_bIsEscSeqDrcs = 1;
  }
  else{
   m_byEscSeqCount = 0U;
   return;
  }
  break;
 case 4U :
  DesignationDRCS(m_byEscSeqIndex, byCode);
  m_byEscSeqCount = 0U;
  return;
 }
 m_byEscSeqCount++;
}

canonical_original_code:
void ProcessEscapeSeq(char byCode)
{
 switch(m_byEscSeqCount){
 case 1U :
  switch(byCode){
  case 0x6EU : LockingShiftGL(2U); m_byEscSeqCount = 0U; return;
  case 0x6FU : LockingShiftGL(3U); m_byEscSeqCount = 0U; return;
  case 0x7EU : LockingShiftGR(1U); m_byEscSeqCount = 0U; return;
  case 0x7DU : LockingShiftGR(2U); m_byEscSeqCount = 0U; return;
  case 0x7CU : LockingShiftGR(3U); m_byEscSeqCount = 0U; return;
  case 0x24U :
  case 0x28U : m_byEscSeqIndex = 0U; break;
  case 0x29U : m_byEscSeqIndex = 1U; break;
  case 0x2AU : m_byEscSeqIndex = 2U; break;
  case 0x2BU : m_byEscSeqIndex = 3U; break;
  default : m_byEscSeqCount = 0U; return;
  }
  break;
 case 2U :
  if(DesignationGSET(m_byEscSeqIndex, byCode)){
   m_byEscSeqCount = 0U;
   return;
  }
  switch(byCode){
  case 0x20 : m_bIsEscSeqDrcs = 1; break;
  case 0x28 : m_bIsEscSeqDrcs = 1; m_byEscSeqIndex = 0U; break;
  case 0x29 : m_bIsEscSeqDrcs = 0; m_byEscSeqIndex = 1U; break;
  case 0x2A : m_bIsEscSeqDrcs = 0; m_byEscSeqIndex = 2U; break;
  case 0x2B : m_bIsEscSeqDrcs = 0; m_byEscSeqIndex = 3U; break;
  default : m_byEscSeqCount = 0U; return;
  }
  break;
 case 3U :
  if(!m_bIsEscSeqDrcs){
   if(DesignationGSET(m_byEscSeqIndex, byCode)){
    m_byEscSeqCount = 0U;
    return;
   }
  }
  else{
   if(DesignationDRCS(m_byEscSeqIndex, byCode)){
    m_byEscSeqCount = 0U;
    return;
   }
  }
  if(byCode == 0x20U){
   m_bIsEscSeqDrcs = 1;
  }
  else{
   m_byEscSeqCount = 0U;
   return;
  }
  break;
 case 4U :
  DesignationDRCS(m_byEscSeqIndex, byCode);
  m_byEscSeqCount = 0U;
  return;
 }
 m_byEscSeqCount++;
}


PutKanjiChar

decompiled_code:
size_t __fastcall PutKanjiChar(char *dest, __int16 a2)
{
iconv_t v2; // r12
size_t v3; // rax
char s[4]; // [rsp+1h] [rbp-4Dh] BYREF
char v6; // [rsp+5h] [rbp-49h]
size_t inbytesleft; // [rsp+6h] [rbp-48h] BYREF
size_t outbytesleft; // [rsp+Eh] [rbp-40h] BYREF
char *inbuf; // [rsp+16h] [rbp-38h] BYREF
char *outbuf; // [rsp+1Eh] [rbp-30h] BYREF
__int16 v11; // [rsp+2Dh] [rbp-21h] BYREF
char v12; // [rsp+2Fh] [rbp-1Fh]
__int16 v13; // [rsp+30h] [rbp-1Eh]
int v14; // [rsp+32h] [rbp-1Ch]

v13 = __ROL2__(a2, 8);
inbytesleft = 8LL;
outbytesleft = 5LL;
*(_DWORD *)s = 0;
v6 = 0;
v11 = 9243;
v12 = 64;
v14 = 4859931;
outbuf = s;
v2 = iconv_open("UTF-8", "ISO-2022-JP");
inbuf = (char *)&v11;
iconv(v2, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
iconv_close(v2);
v3 = strlen(s);
strncpy(dest, s, v3);
return strlen(dest);
}

canonical_decompiled_code:
size_t __fastcall func10(char *dest, __int16 a2)
{
iconv_t v2; // r12
size_t v3; // rax
char s[4]; // [rsp+1h] [rbp-4Dh] BYREF
char v6; // [rsp+5h] [rbp-49h]
size_t inbytesleft; // [rsp+6h] [rbp-48h] BYREF
size_t outbytesleft; // [rsp+Eh] [rbp-40h] BYREF
char *inbuf; // [rsp+16h] [rbp-38h] BYREF
char *outbuf; // [rsp+1Eh] [rbp-30h] BYREF
__int16 v11; // [rsp+2Dh] [rbp-21h] BYREF
char v12; // [rsp+2Fh] [rbp-1Fh]
__int16 v13; // [rsp+30h] [rbp-1Eh]
int v14; // [rsp+32h] [rbp-1Ch]

v13 = __ROL2__(a2, 8);
inbytesleft = 8LL;
outbytesleft = 5LL;
*(_DWORD *)s = 0;
v6 = 0;
v11 = 9243;
v12 = 64;
v14 = 4859931;
outbuf = s;
v2 = iconv_open("UTF-8", "ISO-2022-JP");
inbuf = (char *)&v11;
iconv(v2, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
iconv_close(v2);
v3 = strlen(s);
strncpy(dest, s, v3);
return strlen(dest);
}

original_code:
const int PutKanjiChar(char *lpszDst, const int wCode)
{
 char code[9];
 char xcode[5];
 iconv_t cd;
 size_t inbyte = 8;
 size_t outbyte = sizeof(xcode);
 memset(xcode, '\0', sizeof(xcode));
 const char *fptr;
 char *tptr;
 code[0] = 0x1BU;
 code[1] = 0x24U;
 code[2] = 0x40U;
 code[3] = wCode >> 8;
 code[4] = wCode & 0xFF;
 code[5] = 0x1BU;
 code[6] = 0x28U;
 code[7] = 0x4AU;
 code[8] = '\0';
 cd = iconv_open("UTF-8","ISO-2022-JP");
 fptr = code;
 tptr = xcode;
 iconv(cd, (char **)&fptr, &inbyte, &tptr, &outbyte);
 iconv_close(cd);
 strncpy(lpszDst, xcode, strlen(xcode));
 return strlen(lpszDst);
}

canonical_original_code:
int PutKanjiChar(char *lpszDst, int wCode)
{
 char code[9];
 char xcode[5];
 void *cd;
 unsigned long inbyte = 8;
 unsigned long outbyte = sizeof(xcode);
 memset(xcode, '\0', sizeof(xcode));
 char *fptr;
 char *tptr;
 code[0] = 0x1BU;
 code[1] = 0x24U;
 code[2] = 0x40U;
 code[3] = wCode >> 8;
 code[4] = wCode & 0xFF;
 code[5] = 0x1BU;
 code[6] = 0x28U;
 code[7] = 0x4AU;
 code[8] = '\0';
 cd = iconv_open("UTF-8","ISO-2022-JP");
 fptr = code;
 tptr = xcode;
 iconv(cd, (char **)&fptr, &inbyte, &tptr, &outbyte);
 iconv_close(cd);
 strncpy(lpszDst, xcode, strlen(xcode));
 return strlen(lpszDst);
}

variable_types:
code
char [9]

variable_types:
xcode
char [5]

variable_types:
cd
void *

variable_types:
inbyte
unsigned long

variable_types:
outbyte
unsigned long

variable_types:
fptr
char *

variable_types:
tptr
char *


PutSymbolsChar

decompiled_code:
size_t __fastcall PutSymbolsChar(char *a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rsi
size_t result; // rax
char *v9; // rax
char *v10; // rax

v2 = (unsigned int)(a2 - 31312);
if ( (unsigned int)v2 <= 0x24 )
{
v9 = strcpy(a1, (&aszSymbolsTable1_5)[v2]);
result = strlen(v9);
}
else
{
v3 = (unsigned int)(a2 - 31777);
if ( (unsigned int)v3 <= 0x5A )
{
a1 = strcpy(a1, (&aszSymbolsTable2_4)[v3]);
return strlen(a1);
}
v4 = (unsigned int)(a2 - 32033);
if ( (unsigned int)v4 > 0x5A )
{
v5 = (unsigned int)(a2 - 32289);
if ( (unsigned int)v5 <= 0x5C )
{
a1 = strcpy(a1, (&aszSymbolsTable4_2)[v5]);
}
else
{
v6 = (unsigned int)(a2 - 29985);
if ( (unsigned int)v6 <= 0x5D )
{
a1 = strcpy(a1, (&aszSymbolsTable5_1)[v6]);
}
else
{
v7 = (unsigned int)(a2 - 30241);
if ( (unsigned int)v7 > 0x2A )
*(_DWORD *)a1 = 12288995;
else
a1 = strcpy(a1, (&aszSymbolsTable6_0)[v7]);
}
}
return strlen(a1);
}
v10 = strcpy(a1, (&aszSymbolsTable3_3)[v4]);
result = strlen(v10);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func11(char *a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rsi
size_t result; // rax
char *v9; // rax
char *v10; // rax

v2 = (unsigned int)(a2 - 31312);
if ( (unsigned int)v2 <= 0x24 )
{
v9 = strcpy(a1, (&aszSymbolsTable1_5)[v2]);
result = strlen(v9);
}
else
{
v3 = (unsigned int)(a2 - 31777);
if ( (unsigned int)v3 <= 0x5A )
{
a1 = strcpy(a1, (&aszSymbolsTable2_4)[v3]);
return strlen(a1);
}
v4 = (unsigned int)(a2 - 32033);
if ( (unsigned int)v4 > 0x5A )
{
v5 = (unsigned int)(a2 - 32289);
if ( (unsigned int)v5 <= 0x5C )
{
a1 = strcpy(a1, (&aszSymbolsTable4_2)[v5]);
}
else
{
v6 = (unsigned int)(a2 - 29985);
if ( (unsigned int)v6 <= 0x5D )
{
a1 = strcpy(a1, (&aszSymbolsTable5_1)[v6]);
}
else
{
v7 = (unsigned int)(a2 - 30241);
if ( (unsigned int)v7 > 0x2A )
*(_DWORD *)a1 = 12288995;
else
a1 = strcpy(a1, (&aszSymbolsTable6_0)[v7]);
}
}
return strlen(a1);
}
v10 = strcpy(a1, (&aszSymbolsTable3_3)[v4]);
result = strlen(v10);
}
return result;
}


IsSmallCharMode

decompiled_code:
__int64 IsSmallCharMode()
{
unsigned int v0; // er8

v0 = 0;
if ( (unsigned int)m_emStrSize <= 3 )
v0 = CSWTCH_69[m_emStrSize];
return v0;
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // er8

v0 = 0;
if ( (unsigned int)m_emStrSize <= 3 )
v0 = CSWTCH_69[m_emStrSize];
return v0;
}

original_code:
int IsSmallCharMode(void)
{
 int bRet = 0;
 switch(m_emStrSize){
  case STR_SMALL:
   bRet = 1;
   break;
  case STR_MEDIUM:
   bRet = 1;
   break;
  case STR_NORMAL:
   bRet = 0;
   break;
  case STR_MICRO:
   bRet = 1;
   break;
  case STR_HIGH_W:
   bRet = 0;
   break;
  case STR_WIDTH_W:
   bRet = 0;
   break;
  case STR_W:
   bRet = 0;
   break;
  case STR_SPECIAL_1:
   bRet = 0;
   break;
  case STR_SPECIAL_2:
   bRet = 0;
   break;
  default:
   break;
 }
 return bRet;
}

canonical_original_code:
int IsSmallCharMode()
{
 int bRet = 0;
 switch(m_emStrSize){
  case STR_SMALL:
   bRet = 1;
   break;
  case STR_MEDIUM:
   bRet = 1;
   break;
  case STR_NORMAL:
   bRet = 0;
   break;
  case STR_MICRO:
   bRet = 1;
   break;
  case STR_HIGH_W:
   bRet = 0;
   break;
  case STR_WIDTH_W:
   bRet = 0;
   break;
  case STR_W:
   bRet = 0;
   break;
  case STR_SPECIAL_1:
   bRet = 0;
   break;
  case STR_SPECIAL_2:
   bRet = 0;
   break;
  default:
   break;
 }
 return bRet;
}

variable_types: bRet int


ProcessCharCode

decompiled_code:
size_t __fastcall ProcessCharCode(char *dest, __int64 a2, int a3)
{
size_t result; // rax

switch ( a3 )
{
case 1:
case 13:
case 14:
result = PutKanjiChar(dest, a2);
break;
case 2:
case 9:
if ( (unsigned int)IsSmallCharMode(dest, a2) )
{
*dest = a2;
result = 1LL;
}
else
{
result = PutAlphanumericChar(dest, a2);
}
break;
case 3:
case 10:
result = PutHiraganaChar(dest, a2);
break;
case 4:
case 11:
result = PutKatakanaChar(dest, a2);
break;
case 12:
result = PutJisKatakanaChar(dest, a2);
break;
case 15:
result = PutSymbolsChar(dest, a2);
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func13(char *dest, __int64 a2, int a3)
{
size_t result; // rax

switch ( a3 )
{
case 1:
case 13:
case 14:
result = func10(dest, a2);
break;
case 2:
case 9:
if ( (unsigned int)func12(dest, a2) )
{
*dest = a2;
result = 1LL;
}
else
{
result = func0(dest, a2);
}
break;
case 3:
case 10:
result = func1(dest, a2);
break;
case 4:
case 11:
result = func2(dest, a2);
break;
case 12:
result = func3(dest, a2);
break;
case 15:
result = func11(dest, a2);
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
const int ProcessCharCode(char *lpszDst, const int wCode, const int CodeSet)
{
 switch(CodeSet){
 case 1 :
 case 13 :
 case 14 :
  return PutKanjiChar(lpszDst, wCode);
 case 2 :
 case 9 :
  if( IsSmallCharMode() == 0 ){
  return PutAlphanumericChar(lpszDst, wCode);
  } else {
   lpszDst[0] = wCode;
   return 1UL;
  }
 case 3 :
 case 10 :
  return PutHiraganaChar(lpszDst, wCode);
 case 11 :
 case 4 :
  return PutKatakanaChar(lpszDst, wCode);
 case 12 :
  return PutJisKatakanaChar(lpszDst, wCode);
 case 15 :
  return PutSymbolsChar(lpszDst, wCode);
 default :
  return 0UL;
 }
}

canonical_original_code:
int ProcessCharCode(char *lpszDst, int wCode, int CodeSet)
{
 switch(CodeSet){
 case 1 :
 case 13 :
 case 14 :
  return PutKanjiChar(lpszDst, wCode);
 case 2 :
 case 9 :
  if( IsSmallCharMode() == 0 ){
  return PutAlphanumericChar(lpszDst, wCode);
  } else {
   lpszDst[0] = wCode;
   return 1UL;
  }
 case 3 :
 case 10 :
  return PutHiraganaChar(lpszDst, wCode);
 case 11 :
 case 4 :
  return PutKatakanaChar(lpszDst, wCode);
 case 12 :
  return PutJisKatakanaChar(lpszDst, wCode);
 case 15 :
  return PutSymbolsChar(lpszDst, wCode);
 default :
  return 0UL;
 }
}

variable_types:
lpszDst
char *

variable_types: CodeSet int


AribToStringInternal

decompiled_code:
__int64 __fastcall AribToStringInternal(char *a1, char *a2, int a3)
{
int v6; // ebx
unsigned int v7; // er12
__int64 v8; // r8
__int64 v9; // rdi
__int64 v10; // rsi
char *v11; // r9
_DWORD *v12; // rax
__int64 v13; // rdx
int v14; // edi
int v15; // esi
_BYTE *v17; // r9

if ( a1 == 0LL || a3 == 0 || !a2 )
return 0LL;
m_byEscSeqCount = 0;
m_CodeG = 0x200000001LL;
m_pSingleGL = 0LL;
qword_A48 = 0x400000003LL;
m_pLockingGL = (__int64)&m_CodeG;
m_pLockingGR = (__int64)&qword_A48;
m_emStrSize = 2;
if ( a3 > 0 )
{
v6 = 0;
v7 = 0;
v8 = 0LL;
v9 = (unsigned int)*a2;
while ( 1 )
{
v10 = (unsigned __int8)v9;
v11 = &a1[v8];
if ( (unsigned int)(unsigned __int8)v9 - 33 <= 0x5D )
break;
if ( (unsigned int)(unsigned __int8)v9 - 161 > 0x5D )
{
if ( (unsigned __int8)v9 > 0x20u )
{
switch ( (unsigned __int8)v9 )
{
case 0x8Au:
m_emStrSize = 2;
break;
case 0xA0u:
LABEL_27:
if ( (unsigned int)IsSmallCharMode(v9, v10) )
{
++v7;
*v17 = 32;
}
else
{
v7 += 3;
*(_DWORD *)v17 = 8421603;
}
v8 = (int)v7;
break;
case 0x89u:
m_emStrSize = 1;
break;
}
}
else if ( (unsigned __int8)v9 > 0xDu )
{
v10 = (unsigned int)(unsigned __int8)v9 - 14;
switch ( (char)v9 )
{
case 14:
LockingShiftGL(1);
break;
case 15:
LockingShiftGL(0);
break;
case 25:
SingleShiftGL(2);
break;
case 27:
m_byEscSeqCount = 1;
break;
case 29:
SingleShiftGL(3);
break;
case 32:
goto LABEL_27;
default:
break;
}
}
}
else
{
v13 = *(int *)m_pLockingGR;
if ( abCharSizeTable[v13] )
{
if ( a3 - v6 == 1 )
goto LABEL_17;
++v6;
v14 = ((_WORD)v9 << 8) & 0x7F00;
v15 = a2[v6] & 0x7F;
LABEL_11:
v10 = v14 | (unsigned int)v15;
LABEL_12:
v7 += ProcessCharCode(v11, v10, v13);
v8 = (int)v7;
goto LABEL_13;
}
v7 += ProcessCharCode(&a1[v8], v9 & 0x7F, v13);
v8 = (int)v7;
}
LABEL_13:
if ( a3 <= ++v6 )
{
LABEL_16:
v11 = &a1[v8];
goto LABEL_17;
}
while ( 1 )
{
v9 = (unsigned int)a2[v6];
if ( !m_byEscSeqCount )
break;
ProcessEscapeSeq(a2[v6++]);
if ( a3 <= v6 )
goto LABEL_16;
}
}
v12 = (_DWORD *)m_pSingleGL;
if ( !m_pSingleGL )
v12 = (_DWORD *)m_pLockingGL;
LODWORD(v13) = *v12;
m_pSingleGL = 0LL;
if ( abCharSizeTable[(int)v13] )
{
if ( a3 - v6 == 1 )
goto LABEL_17;
++v6;
v14 = (_DWORD)v9 << 8;
v15 = a2[v6];
goto LABEL_11;
}
goto LABEL_12;
}
v11 = a1;
v7 = 0;
LABEL_17:
*v11 = 0;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *a1, char *a2, int a3)
{
int v6; // ebx
unsigned int v7; // er12
__int64 v8; // r8
__int64 v9; // rdi
__int64 v10; // rsi
char *v11; // r9
_DWORD *v12; // rax
__int64 v13; // rdx
int v14; // edi
int v15; // esi
_BYTE *v17; // r9

if ( a1 == 0LL || a3 == 0 || !a2 )
return 0LL;
m_byEscSeqCount = 0;
m_CodeG = 0x200000001LL;
m_pSingleGL = 0LL;
qword_A48 = 0x400000003LL;
m_pLockingGL = (__int64)&m_CodeG;
m_pLockingGR = (__int64)&qword_A48;
m_emStrSize = 2;
if ( a3 > 0 )
{
v6 = 0;
v7 = 0;
v8 = 0LL;
v9 = (unsigned int)*a2;
while ( 1 )
{
v10 = (unsigned __int8)v9;
v11 = &a1[v8];
if ( (unsigned int)(unsigned __int8)v9 - 33 <= 0x5D )
break;
if ( (unsigned int)(unsigned __int8)v9 - 161 > 0x5D )
{
if ( (unsigned __int8)v9 > 0x20u )
{
switch ( (unsigned __int8)v9 )
{
case 0x8Au:
m_emStrSize = 2;
break;
case 0xA0u:
LABEL_27:
if ( (unsigned int)func12(v9, v10) )
{
++v7;
*v17 = 32;
}
else
{
v7 += 3;
*(_DWORD *)v17 = 8421603;
}
v8 = (int)v7;
break;
case 0x89u:
m_emStrSize = 1;
break;
}
}
else if ( (unsigned __int8)v9 > 0xDu )
{
v10 = (unsigned int)(unsigned __int8)v9 - 14;
switch ( (char)v9 )
{
case 14:
func4(1);
break;
case 15:
func4(0);
break;
case 25:
func6(2);
break;
case 27:
m_byEscSeqCount = 1;
break;
case 29:
func6(3);
break;
case 32:
goto LABEL_27;
default:
break;
}
}
}
else
{
v13 = *(int *)m_pLockingGR;
if ( abCharSizeTable[v13] )
{
if ( a3 - v6 == 1 )
goto LABEL_17;
++v6;
v14 = ((_WORD)v9 << 8) & 0x7F00;
v15 = a2[v6] & 0x7F;
LABEL_11:
v10 = v14 | (unsigned int)v15;
LABEL_12:
v7 += func13(v11, v10, v13);
v8 = (int)v7;
goto LABEL_13;
}
v7 += func13(&a1[v8], v9 & 0x7F, v13);
v8 = (int)v7;
}
LABEL_13:
if ( a3 <= ++v6 )
{
LABEL_16:
v11 = &a1[v8];
goto LABEL_17;
}
while ( 1 )
{
v9 = (unsigned int)a2[v6];
if ( !m_byEscSeqCount )
break;
func9(a2[v6++]);
if ( a3 <= v6 )
goto LABEL_16;
}
}
v12 = (_DWORD *)m_pSingleGL;
if ( !m_pSingleGL )
v12 = (_DWORD *)m_pLockingGL;
LODWORD(v13) = *v12;
m_pSingleGL = 0LL;
if ( abCharSizeTable[(int)v13] )
{
if ( a3 - v6 == 1 )
goto LABEL_17;
++v6;
v14 = (_DWORD)v9 << 8;
v15 = a2[v6];
goto LABEL_11;
}
goto LABEL_12;
}
v11 = a1;
v7 = 0;
LABEL_17:
*v11 = 0;
return v7;
}

original_code:
const int AribToStringInternal(char *lpszDst,
         const char *pSrcData, const int dwSrcLen)
{
 if(!pSrcData || !dwSrcLen || !lpszDst)return 0UL;
 int dwSrcPos = 0UL;
 int dwDstLen = 0UL;
 int dwSrcData;
 m_byEscSeqCount = 0U;
 m_pSingleGL = ((void *)0);
 m_CodeG[0] = 1;
 m_CodeG[1] = 2;
 m_CodeG[2] = 3;
 m_CodeG[3] = 4;
 m_pLockingGL = &m_CodeG[0];
 m_pLockingGR = &m_CodeG[2];
 m_emStrSize = STR_NORMAL;
 while(dwSrcPos < dwSrcLen){
  dwSrcData = pSrcData[dwSrcPos] & 0xFF;
  if(!m_byEscSeqCount){
   if((dwSrcData >= 0x21U) && (dwSrcData <= 0x7EU)){
    const int CurCodeSet = (m_pSingleGL)? *m_pSingleGL : *m_pLockingGL;
    m_pSingleGL = ((void *)0);
    if(abCharSizeTable[CurCodeSet]){
     if((dwSrcLen - dwSrcPos) < 2UL)break;
     dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], ((int)pSrcData[dwSrcPos + 0] << 8) | (int)pSrcData[dwSrcPos + 1], CurCodeSet);
     dwSrcPos++;
    }
    else{
     dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], (int)dwSrcData, CurCodeSet);
    }
   }
   else if((dwSrcData >= 0xA1U) && (dwSrcData <= 0xFEU)){
    const int CurCodeSet = *m_pLockingGR;
    if(abCharSizeTable[CurCodeSet]){
     if((dwSrcLen - dwSrcPos) < 2UL)break;
     dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], ((int)(pSrcData[dwSrcPos + 0] & 0x7FU) << 8) | (int)(pSrcData[dwSrcPos + 1] & 0x7FU), CurCodeSet);
     dwSrcPos++;
    }
    else{
     dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], (int)(dwSrcData & 0x7FU), CurCodeSet);
    }
   }
   else{
    switch(dwSrcData){
    case 0x0FU : LockingShiftGL(0U); break;
    case 0x0EU : LockingShiftGL(1U); break;
    case 0x19U : SingleShiftGL(2U); break;
    case 0x1DU : SingleShiftGL(3U); break;
    case 0x1BU : m_byEscSeqCount = 1U; break;
    case 0x89U : m_emStrSize = STR_MEDIUM; break;
    case 0x8AU : m_emStrSize = STR_NORMAL; break;
    case 0x20U :
    case 0xA0U :
     if( IsSmallCharMode() == 0 ){
      strcpy(&lpszDst[dwDstLen], "　");
      dwDstLen += 3U;
     } else {
      lpszDst[dwDstLen++] = ' ';
     }
     break;
    default : break;
    }
   }
  }
  else{
   ProcessEscapeSeq(dwSrcData);
  }
  dwSrcPos++;
 }
 lpszDst[dwDstLen] = '\0';
 return dwDstLen;
}

canonical_original_code:
int AribToStringInternal(char *lpszDst, char *pSrcData, int dwSrcLen)
{
 if(!pSrcData || !dwSrcLen || !lpszDst)return 0UL;
 int dwSrcPos = 0UL;
 int dwDstLen = 0UL;
 int dwSrcData;
 m_byEscSeqCount = 0U;
 m_pSingleGL = ((void *)0);
 m_CodeG[0] = 1;
 m_CodeG[1] = 2;
 m_CodeG[2] = 3;
 m_CodeG[3] = 4;
 m_pLockingGL = &m_CodeG[0];
 m_pLockingGR = &m_CodeG[2];
 m_emStrSize = STR_NORMAL;
 while(dwSrcPos < dwSrcLen){
  dwSrcData = pSrcData[dwSrcPos] & 0xFF;
  if(!m_byEscSeqCount){
   if((dwSrcData >= 0x21U) && (dwSrcData <= 0x7EU)){
    int CurCodeSet = (m_pSingleGL)? *m_pSingleGL : *m_pLockingGL;
    m_pSingleGL = ((void *)0);
    if(abCharSizeTable[CurCodeSet]){
     if((dwSrcLen - dwSrcPos) < 2UL)break;
     dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], ((int)pSrcData[dwSrcPos + 0] << 8) | (int)pSrcData[dwSrcPos + 1], CurCodeSet);
     dwSrcPos++;
    }
    else{
     dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], (int)dwSrcData, CurCodeSet);
    }
   }
   else if((dwSrcData >= 0xA1U) && (dwSrcData <= 0xFEU)){
    int CurCodeSet = *m_pLockingGR;
    if(abCharSizeTable[CurCodeSet]){
     if((dwSrcLen - dwSrcPos) < 2UL)break;
     dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], ((int)(pSrcData[dwSrcPos + 0] & 0x7FU) << 8) | (int)(pSrcData[dwSrcPos + 1] & 0x7FU), CurCodeSet);
     dwSrcPos++;
    }
    else{
     dwDstLen += ProcessCharCode(&lpszDst[dwDstLen], (int)(dwSrcData & 0x7FU), CurCodeSet);
    }
   }
   else{
    switch(dwSrcData){
    case 0x0FU : LockingShiftGL(0U); break;
    case 0x0EU : LockingShiftGL(1U); break;
    case 0x19U : SingleShiftGL(2U); break;
    case 0x1DU : SingleShiftGL(3U); break;
    case 0x1BU : m_byEscSeqCount = 1U; break;
    case 0x89U : m_emStrSize = STR_MEDIUM; break;
    case 0x8AU : m_emStrSize = STR_NORMAL; break;
    case 0x20U :
    case 0xA0U :
     if( IsSmallCharMode() == 0 ){
      strcpy(&lpszDst[dwDstLen], "　");
      dwDstLen += 3U;
     } else {
      lpszDst[dwDstLen++] = ' ';
     }
     break;
    default : break;
    }
   }
  }
  else{
   ProcessEscapeSeq(dwSrcData);
  }
  dwSrcPos++;
 }
 lpszDst[dwDstLen] = '\0';
 return dwDstLen;
}

variable_types:
pSrcData
char *

variable_types: dwSrcLen int

variable_types: dwSrcPos int

variable_types: dwDstLen int

variable_types: dwSrcData int

variable_types: CurCodeSet int


AribToString

decompiled_code:
// attributes: thunk
__int64 __fastcall AribToString(char *a1, char *a2, int a3)
{
return AribToStringInternal(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func15(char *a1, char *a2, int a3)
{
return func14(a1, a2, a3);
}

original_code:
int AribToString(
 char *lpszDst,
 const char *pSrcData,
 const int dwSrcLen) {
 return AribToStringInternal(lpszDst, pSrcData, dwSrcLen);
}

canonical_original_code:
int AribToString(char *lpszDst, char *pSrcData, int dwSrcLen) {
 return AribToStringInternal(lpszDst, pSrcData, dwSrcLen);
}