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 ***v6; // rax
const char *v7; // rbx
__int64 result; // rax

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

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 ***v6; // rax
const char *v7; // rbx
__int64 result; // rax

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

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

return_type: int


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

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

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

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

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

return_type: void

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

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char **v4; // rbx
const char **v5; // r13
const char **v6; // r12
const char **v7; // r14
__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_322);
v6 = (const char **)graph_add_vertex(v9, (__int64)&unk_329);
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; // rbp
const char **v4; // rbx
const char **v5; // r13
const char **v6; // r12
const char **v7; // r14
__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_322);
v6 = (const char **)graph_add_vertex(v9, (__int64)&unk_329);
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;
}

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

user_defined_types: struct GRAPH { struct VERTEX *vertex; struct GRAPH *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

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");
if ( (*(_BYTE *)(a1 + 13) & 2) != 0 )
printf("SYN ");
if ( (*(_BYTE *)(a1 + 13) & 0x10) != 0 )
printf("ACK ");
if ( (*(_BYTE *)(a1 + 13) & 1) != 0 )
printf("FIN ");
if ( (*(_BYTE *)(a1 + 13) & 4) != 0 )
printf("RST ");
if ( (*(_BYTE *)(a1 + 13) & 8) != 0 )
printf("PSH ");
if ( (*(_BYTE *)(a1 + 12) & 0xF) != 0 )
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

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");
if ( (*(_BYTE *)(a1 + 13) & 2) != 0 )
printf("SYN ");
if ( (*(_BYTE *)(a1 + 13) & 0x10) != 0 )
printf("ACK ");
if ( (*(_BYTE *)(a1 + 13) & 1) != 0 )
printf("FIN ");
if ( (*(_BYTE *)(a1 + 13) & 4) != 0 )
printf("RST ");
if ( (*(_BYTE *)(a1 + 13) & 8) != 0 )
printf("PSH ");
if ( (*(_BYTE *)(a1 + 12) & 0xF) != 0 )
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)
{
_QWORD *v1; // rbp
__int64 result; // rax
__int64 v3; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
_QWORD *v1; // rbp
__int64 result; // rax
__int64 v3; // rdx

if ( first_gum )
*(_QWORD *)(last_gum + 16) = a1;
else
first_gum = a1;
last_gum = a1;
*(_QWORD *)(a1 + 16) = 0LL;
v1 = malloc(0x10uLL);
*v1 = a1;
v1[1] = 0LL;
result = func0(*(_DWORD *)a1);
v3 = gum_map[(int)result];
if ( v3 )
{
*(_QWORD *)(v3 + 8) = v1;
}
else
{
result = (int)result;
gum_map[(int)result] = (__int64)v1;
}
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()
{
__int64 *v0; // rax

v0 = gum_map;
do
*v0++ = 0LL;
while ( v0 != (__int64 *)(unsigned int)((_DWORD)gum_map + 800) );
first_gum = 0LL;
last_gum = 0LL;
return init_gum_management();
}

canonical_decompiled_code:
void *func6()
{
__int64 *v0; // rax

v0 = gum_map;
do
*v0++ = 0LL;
while ( v0 != (__int64 *)(unsigned int)((_DWORD)gum_map + 800) );
first_gum = 0LL;
last_gum = 0LL;
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

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

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

if ( !next )
next = func1();
result = next;
gumtable[2 * a1] = next;
next = *(_QWORD *)(result + 16);
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)
{
unsigned int v1; // edi
__int64 v2; // rbx

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

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

v1 = a1 % 0x186A0;
if ( !gumtable[2 * v1] )
func7(v1);
v2 = 2LL * 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, unsigned int *a2)
{
void *v2; // rbp

if ( *a2 <= 0xD )
*a2 = 14;
v2 = malloc((int)*a2);
memset(v2, 0, (int)*a2);
if ( a1 )
*a1 = v2;
return v2;
}

canonical_decompiled_code:
void *__fastcall func1(_QWORD *a1, unsigned int *a2)
{
void *v2; // rbp

if ( *a2 <= 0xD )
*a2 = 14;
v2 = malloc((int)*a2);
memset(v2, 0, (int)*a2);
if ( a1 )
*a1 = v2;
return v2;
}

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 *


decompiled_code:
void *__fastcall create_eth_ip(__int64 *a1, unsigned int *a2)
{
void *v2; // rbp
__int64 v3; // r12
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = create_eth(v5, a2);
v3 = v5[0];
*(_WORD *)(v3 + 12) = _bswap_16(2048);
if ( a1 )
*a1 = v3;
return v2;
}

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)
{
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
int v4; // [rsp+8h] [rbp-20h]
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

v3 = a1;
v4 = a2;
pthread_create(newthread, 0LL, (void *(*)(void *))start_thread_i, &v3);
return newthread[0];
}

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

v3 = a1;
v4 = a2;
pthread_create(newthread, 0LL, (void *(*)(void *))start_thread_i, &v3);
return newthread[0];
}

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)
{
if ( !a1 )
return 0LL;
while ( *((_DWORD *)a1 + 4) != a2 )
{
a1 = (__int64 *)*a1;
if ( !a1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, int a2)
{
if ( !a1 )
return 0LL;
while ( *((_DWORD *)a1 + 4) != a2 )
{
a1 = (__int64 *)*a1;
if ( !a1 )
return 0LL;
}
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)
{
*a1 = byte_AE0[3 * a2];
a1[1] = byte_AE0[3 * a2 + 1];
a1[2] = byte_AE0[3 * a2 + 2];
return 3LL;
}

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)
{
*a1 = byte_C68[3 * a2];
a1[1] = byte_C68[3 * a2 + 1];
a1[2] = byte_C68[3 * a2 + 2];
return 3LL;
}

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)
{
*a1 = byte_DF0[3 * a2];
a1[1] = byte_DF0[3 * a2 + 1];
a1[2] = byte_DF0[3 * a2 + 2];
return 3LL;
}

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)
{
*a1 = byte_F78[3 * a2];
a1[1] = byte_F78[3 * a2 + 1];
a1[2] = byte_F78[3 * a2 + 2];
return 3LL;
}

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:
int *__fastcall LockingShiftGL(char a1)
{
int *result; // rax

result = &m_CodeG[a1];
m_pLockingGL = (__int64)result;
return result;
}

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

result = &m_CodeG[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:
int *__fastcall LockingShiftGR(char a1)
{
int *result; // rax

result = &m_CodeG[a1];
m_pLockingGR = (__int64)result;
return result;
}

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

result = &m_CodeG[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:
int *__fastcall SingleShiftGL(char a1)
{
int *result; // rax

result = &m_CodeG[a1];
m_pSingleGL = (__int64)result;
return result;
}

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

result = &m_CodeG[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':
m_CodeG[a1] = 3;
result = 1LL;
break;
case '1':
m_CodeG[a1] = 4;
result = 1LL;
break;
case '2':
m_CodeG[a1] = 5;
result = 1LL;
break;
case '3':
m_CodeG[a1] = 6;
result = 1LL;
break;
case '4':
m_CodeG[a1] = 7;
result = 1LL;
break;
case '5':
m_CodeG[a1] = 8;
result = 1LL;
break;
case '6':
m_CodeG[a1] = 9;
result = 1LL;
break;
case '7':
m_CodeG[a1] = 10;
result = 1LL;
break;
case '8':
m_CodeG[a1] = 11;
result = 1LL;
break;
case '9':
m_CodeG[a1] = 13;
result = 1LL;
break;
case ':':
m_CodeG[a1] = 14;
result = 1LL;
break;
case ';':
m_CodeG[a1] = 15;
result = 1LL;
break;
case 'B':
m_CodeG[a1] = 1;
result = 1LL;
break;
case 'I':
m_CodeG[a1] = 12;
result = 1LL;
break;
case 'J':
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':
m_CodeG[a1] = 3;
result = 1LL;
break;
case '1':
m_CodeG[a1] = 4;
result = 1LL;
break;
case '2':
m_CodeG[a1] = 5;
result = 1LL;
break;
case '3':
m_CodeG[a1] = 6;
result = 1LL;
break;
case '4':
m_CodeG[a1] = 7;
result = 1LL;
break;
case '5':
m_CodeG[a1] = 8;
result = 1LL;
break;
case '6':
m_CodeG[a1] = 9;
result = 1LL;
break;
case '7':
m_CodeG[a1] = 10;
result = 1LL;
break;
case '8':
m_CodeG[a1] = 11;
result = 1LL;
break;
case '9':
m_CodeG[a1] = 13;
result = 1LL;
break;
case ':':
m_CodeG[a1] = 14;
result = 1LL;
break;
case ';':
m_CodeG[a1] = 15;
result = 1LL;
break;
case 'B':
m_CodeG[a1] = 1;
result = 1LL;
break;
case 'I':
m_CodeG[a1] = 12;
result = 1LL;
break;
case 'J':
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)
{
__int64 result; // rax

switch ( a2 )
{
case '@':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'A':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'B':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'C':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'D':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'E':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'F':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'G':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'H':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'I':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'J':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'K':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'L':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'M':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'N':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'O':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'p':
m_CodeG[a1] = 0;
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a2 )
{
case '@':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'A':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'B':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'C':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'D':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'E':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'F':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'G':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'H':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'I':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'J':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'K':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'L':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'M':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'N':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'O':
m_CodeG[a1] = 0;
result = 1LL;
break;
case 'p':
m_CodeG[a1] = 0;
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

v1 = m_byEscSeqCount;
if ( m_byEscSeqCount == 3 )
{
if ( m_bIsEscSeqDrcs )
{
if ( (unsigned int)DesignationDRCS(m_byEscSeqIndex, a1) )
{
m_byEscSeqCount = 0;
return;
}
}
else if ( (unsigned int)DesignationGSET(m_byEscSeqIndex, a1) )
{
m_byEscSeqCount = 0;
return;
}
if ( a1 != 32 )
{
m_byEscSeqCount = 0;
return;
}
m_bIsEscSeqDrcs = 1;
goto LABEL_35;
}
if ( m_byEscSeqCount > 3 )
{
if ( m_byEscSeqCount == 4 )
{
DesignationDRCS(m_byEscSeqIndex, a1);
m_byEscSeqCount = 0;
return;
}
goto LABEL_35;
}
if ( m_byEscSeqCount != 1 )
{
if ( m_byEscSeqCount == 2 )
{
if ( (unsigned int)DesignationGSET(m_byEscSeqIndex, a1) )
{
m_byEscSeqCount = 0;
}
else
{
switch ( a1 )
{
case ' ':
m_bIsEscSeqDrcs = 1;
goto LABEL_35;
case '(':
m_bIsEscSeqDrcs = 1;
m_byEscSeqIndex = 0;
goto LABEL_35;
case ')':
m_bIsEscSeqDrcs = 0;
m_byEscSeqIndex = 1;
goto LABEL_35;
case '*':
m_bIsEscSeqDrcs = 0;
m_byEscSeqIndex = 2;
goto LABEL_35;
case '+':
m_bIsEscSeqDrcs = 0;
m_byEscSeqIndex = 3;
goto LABEL_35;
default:
m_byEscSeqCount = 0;
break;
}
}
return;
}
LABEL_35:
m_byEscSeqCount = v1 + 1;
return;
}
if ( a1 <= 43 )
{
if ( a1 > 35 )
{
switch ( a1 )
{
case '$':
case '(':
m_byEscSeqIndex = 0;
goto LABEL_35;
case ')':
m_byEscSeqIndex = 1;
goto LABEL_35;
case '*':
m_byEscSeqIndex = 2;
goto LABEL_35;
case '+':
m_byEscSeqIndex = 3;
goto LABEL_35;
default:
goto LABEL_13;
}
}
goto LABEL_13;
}
if ( (unsigned __int8)(a1 - 110) > 0x10u )
{
LABEL_13:
m_byEscSeqCount = 0;
return;
}
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_13;
}
}

canonical_decompiled_code:
void __fastcall func9(char a1)
{
char v1; // bp

v1 = m_byEscSeqCount;
if ( m_byEscSeqCount == 3 )
{
if ( m_bIsEscSeqDrcs )
{
if ( (unsigned int)func8(m_byEscSeqIndex, a1) )
{
m_byEscSeqCount = 0;
return;
}
}
else if ( (unsigned int)func7(m_byEscSeqIndex, a1) )
{
m_byEscSeqCount = 0;
return;
}
if ( a1 != 32 )
{
m_byEscSeqCount = 0;
return;
}
m_bIsEscSeqDrcs = 1;
goto LABEL_35;
}
if ( m_byEscSeqCount > 3 )
{
if ( m_byEscSeqCount == 4 )
{
func8(m_byEscSeqIndex, a1);
m_byEscSeqCount = 0;
return;
}
goto LABEL_35;
}
if ( m_byEscSeqCount != 1 )
{
if ( m_byEscSeqCount == 2 )
{
if ( (unsigned int)func7(m_byEscSeqIndex, a1) )
{
m_byEscSeqCount = 0;
}
else
{
switch ( a1 )
{
case ' ':
m_bIsEscSeqDrcs = 1;
goto LABEL_35;
case '(':
m_bIsEscSeqDrcs = 1;
m_byEscSeqIndex = 0;
goto LABEL_35;
case ')':
m_bIsEscSeqDrcs = 0;
m_byEscSeqIndex = 1;
goto LABEL_35;
case '*':
m_bIsEscSeqDrcs = 0;
m_byEscSeqIndex = 2;
goto LABEL_35;
case '+':
m_bIsEscSeqDrcs = 0;
m_byEscSeqIndex = 3;
goto LABEL_35;
default:
m_byEscSeqCount = 0;
break;
}
}
return;
}
LABEL_35:
m_byEscSeqCount = v1 + 1;
return;
}
if ( a1 <= 43 )
{
if ( a1 > 35 )
{
switch ( a1 )
{
case '$':
case '(':
m_byEscSeqIndex = 0;
goto LABEL_35;
case ')':
m_byEscSeqIndex = 1;
goto LABEL_35;
case '*':
m_byEscSeqIndex = 2;
goto LABEL_35;
case '+':
m_byEscSeqIndex = 3;
goto LABEL_35;
default:
goto LABEL_13;
}
}
goto LABEL_13;
}
if ( (unsigned __int8)(a1 - 110) > 0x10u )
{
LABEL_13:
m_byEscSeqCount = 0;
return;
}
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_13;
}
}

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; // rbp
size_t v3; // rax
char *v5; // [rsp+0h] [rbp-48h] BYREF
char *inbuf; // [rsp+8h] [rbp-40h] BYREF
size_t outbytesleft; // [rsp+10h] [rbp-38h] BYREF
size_t inbytesleft; // [rsp+18h] [rbp-30h] BYREF
char s[4]; // [rsp+22h] [rbp-26h] BYREF
char v10; // [rsp+26h] [rbp-22h]
char v11[5]; // [rsp+27h] [rbp-21h] BYREF
char v12[8]; // [rsp+2Ch] [rbp-1Ch] BYREF

inbytesleft = 8LL;
outbytesleft = 5LL;
*(_DWORD *)s = 0;
v10 = 0;
v11[0] = 27;
v11[1] = 36;
v11[2] = 64;
v11[3] = HIBYTE(a2);
v11[4] = a2;
strcpy(v12, "\x1B(J");
v2 = iconv_open("UTF-8", "ISO-2022-JP");
inbuf = v11;
v5 = s;
iconv(v2, &inbuf, &inbytesleft, &v5, &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; // rbp
size_t v3; // rax
char *v5; // [rsp+0h] [rbp-48h] BYREF
char *inbuf; // [rsp+8h] [rbp-40h] BYREF
size_t outbytesleft; // [rsp+10h] [rbp-38h] BYREF
size_t inbytesleft; // [rsp+18h] [rbp-30h] BYREF
char s[4]; // [rsp+22h] [rbp-26h] BYREF
char v10; // [rsp+26h] [rbp-22h]
char v11[5]; // [rsp+27h] [rbp-21h] BYREF
char v12[8]; // [rsp+2Ch] [rbp-1Ch] BYREF

inbytesleft = 8LL;
outbytesleft = 5LL;
*(_DWORD *)s = 0;
v10 = 0;
v11[0] = 27;
v11[1] = 36;
v11[2] = 64;
v11[3] = HIBYTE(a2);
v11[4] = a2;
strcpy(v12, "\x1B(J");
v2 = iconv_open("UTF-8", "ISO-2022-JP");
inbuf = v11;
v5 = s;
iconv(v2, &inbuf, &inbytesleft, &v5, &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 *dest, int a2)
{
unsigned int v2; // esi

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

canonical_decompiled_code:
size_t __fastcall func11(char *dest, int a2)
{
unsigned int v2; // esi

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


IsSmallCharMode

decompiled_code:
_BOOL8 IsSmallCharMode()
{
_BOOL8 result; // rax

result = 1LL;
if ( (unsigned int)m_emStrSize > 1 )
result = m_emStrSize == 3;
return result;
}

canonical_decompiled_code:
_BOOL8 func12()
{
_BOOL8 result; // rax

result = 1LL;
if ( (unsigned int)m_emStrSize > 1 )
result = m_emStrSize == 3;
return result;
}

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:
__int64 __fastcall ProcessCharCode(char *dest, __int16 a2, int a3)
{
__int64 result; // rax

switch ( a3 )
{
case 0:
case 5:
case 6:
case 7:
case 8:
result = 0LL;
break;
case 1:
case 13:
case 14:
result = PutKanjiChar(dest, a2);
break;
case 2:
case 9:
if ( IsSmallCharMode() )
{
*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:
__int64 __fastcall func13(char *dest, __int16 a2, int a3)
{
__int64 result; // rax

switch ( a3 )
{
case 0:
case 5:
case 6:
case 7:
case 8:
result = 0LL;
break;
case 1:
case 13:
case 14:
result = func10(dest, a2);
break;
case 2:
case 9:
if ( func12() )
{
*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(__int64 a1, __int64 a2, int a3)
{
unsigned int v4; // ebp
int v5; // ebx
int v6; // edx
int v7; // edx
unsigned __int8 v8; // al

if ( a1 == 0 || a3 == 0 || !a2 )
return 0;
m_byEscSeqCount = 0;
m_pSingleGL = 0LL;
m_CodeG[0] = 1;
dword_AD4 = 2;
dword_AD8 = 3;
dword_ADC = 4;
m_pLockingGL = (__int64)m_CodeG;
m_pLockingGR = (__int64)&dword_AD8;
m_emStrSize = 2;
if ( a3 > 0 )
{
v4 = 0;
v5 = 0;
while ( 1 )
{
v8 = *(_BYTE *)(a2 + v5);
if ( m_byEscSeqCount )
{
ProcessEscapeSeq(*(_BYTE *)(a2 + v5));
}
else if ( (unsigned int)v8 - 33 > 0x5D )
{
if ( (unsigned int)v8 - 161 > 0x5D )
{
if ( v8 > 0x20u )
{
switch ( v8 )
{
case 0x8Au:
m_emStrSize = 2;
break;
case 0xA0u:
LABEL_17:
if ( IsSmallCharMode() )
{
*(_BYTE *)(a1 + (int)v4++) = 32;
}
else
{
*(_DWORD *)(a1 + (int)v4) = 8421603;
v4 += 3;
}
break;
case 0x89u:
m_emStrSize = 1;
break;
}
}
else if ( v8 > 0xDu )
{
switch ( v8 )
{
case 0xEu:
LockingShiftGL(1);
break;
case 0xFu:
LockingShiftGL(0);
break;
case 0x19u:
SingleShiftGL(2);
break;
case 0x1Bu:
m_byEscSeqCount = 1;
break;
case 0x1Du:
SingleShiftGL(3);
break;
case 0x20u:
goto LABEL_17;
default:
break;
}
}
}
else
{
v7 = *(_DWORD *)m_pLockingGR;
if ( abCharSizeTable[*(int *)m_pLockingGR] )
{
if ( (unsigned int)(a3 - v5) <= 1 )
goto LABEL_38;
v4 += ProcessCharCode(
(char *)(a1 + (int)v4),
((char)v8 << 8) & 0x7F00 | *(_BYTE *)(a2 + v5++ + 1) & 0x7Fu,
v7);
}
else
{
v4 += ProcessCharCode((char *)(a1 + (int)v4), v8 & 0x7F, v7);
}
}
}
else
{
if ( m_pSingleGL )
v6 = *(_DWORD *)m_pSingleGL;
else
v6 = *(_DWORD *)m_pLockingGL;
m_pSingleGL = 0LL;
if ( abCharSizeTable[v6] )
{
if ( (unsigned int)(a3 - v5) <= 1 )
goto LABEL_38;
v4 += ProcessCharCode(
(char *)(a1 + (int)v4),
(unsigned __int16)((char)v8 << 8) | *(char *)(a2 + v5++ + 1),
v6);
}
else
{
v4 += ProcessCharCode((char *)(a1 + (int)v4), v8, v6);
}
}
if ( a3 <= ++v5 )
goto LABEL_38;
}
}
v4 = 0;
LABEL_38:
*(_BYTE *)(a1 + (int)v4) = 0;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, int a3)
{
unsigned int v4; // ebp
int v5; // ebx
int v6; // edx
int v7; // edx
unsigned __int8 v8; // al

if ( a1 == 0 || a3 == 0 || !a2 )
return 0;
m_byEscSeqCount = 0;
m_pSingleGL = 0LL;
m_CodeG[0] = 1;
dword_AD4 = 2;
dword_AD8 = 3;
dword_ADC = 4;
m_pLockingGL = (__int64)m_CodeG;
m_pLockingGR = (__int64)&dword_AD8;
m_emStrSize = 2;
if ( a3 > 0 )
{
v4 = 0;
v5 = 0;
while ( 1 )
{
v8 = *(_BYTE *)(a2 + v5);
if ( m_byEscSeqCount )
{
func9(*(_BYTE *)(a2 + v5));
}
else if ( (unsigned int)v8 - 33 > 0x5D )
{
if ( (unsigned int)v8 - 161 > 0x5D )
{
if ( v8 > 0x20u )
{
switch ( v8 )
{
case 0x8Au:
m_emStrSize = 2;
break;
case 0xA0u:
LABEL_17:
if ( func12() )
{
*(_BYTE *)(a1 + (int)v4++) = 32;
}
else
{
*(_DWORD *)(a1 + (int)v4) = 8421603;
v4 += 3;
}
break;
case 0x89u:
m_emStrSize = 1;
break;
}
}
else if ( v8 > 0xDu )
{
switch ( v8 )
{
case 0xEu:
func4(1);
break;
case 0xFu:
func4(0);
break;
case 0x19u:
func6(2);
break;
case 0x1Bu:
m_byEscSeqCount = 1;
break;
case 0x1Du:
func6(3);
break;
case 0x20u:
goto LABEL_17;
default:
break;
}
}
}
else
{
v7 = *(_DWORD *)m_pLockingGR;
if ( abCharSizeTable[*(int *)m_pLockingGR] )
{
if ( (unsigned int)(a3 - v5) <= 1 )
goto LABEL_38;
v4 += func13(
(char *)(a1 + (int)v4),
((char)v8 << 8) & 0x7F00 | *(_BYTE *)(a2 + v5++ + 1) & 0x7Fu,
v7);
}
else
{
v4 += func13((char *)(a1 + (int)v4), v8 & 0x7F, v7);
}
}
}
else
{
if ( m_pSingleGL )
v6 = *(_DWORD *)m_pSingleGL;
else
v6 = *(_DWORD *)m_pLockingGL;
m_pSingleGL = 0LL;
if ( abCharSizeTable[v6] )
{
if ( (unsigned int)(a3 - v5) <= 1 )
goto LABEL_38;
v4 += func13(
(char *)(a1 + (int)v4),
(unsigned __int16)((char)v8 << 8) | *(char *)(a2 + v5++ + 1),
v6);
}
else
{
v4 += func13((char *)(a1 + (int)v4), v8, v6);
}
}
if ( a3 <= ++v5 )
goto LABEL_38;
}
}
v4 = 0;
LABEL_38:
*(_BYTE *)(a1 + (int)v4) = 0;
return v4;
}

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:
__int64 __fastcall AribToString(__int64 a1, __int64 a2, int a3)
{
return AribToStringInternal(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 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);
}


strrep

decompiled_code:
__int64 __fastcall strrep(char *haystack, char *needle, void *src)
{
size_t v4; // r15
__int64 result; // rax
char *v6; // rbx
size_t v7; // rbp
int v8; // er13
size_t v9; // rax
size_t v10; // rax

v4 = strlen(needle);
result = 0LL;
if ( v4 )
{
v6 = strstr(haystack, needle);
if ( v6 )
{
v7 = strlen((const char *)src);
v8 = v7 - v4;
do
{
if ( v8 > 0 )
{
v9 = strlen(v6);
memmove(&v6[v8], v6, v9 + 1);
}
else if ( v8 < 0 )
{
v10 = strlen(v6);
memmove(v6, &v6[-v8], v8 + v10 + 1);
}
memmove(v6, src, v7);
v6 = strstr(&v6[v7], needle);
}
while ( v6 );
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *haystack, char *needle, void *src)
{
size_t v4; // r15
__int64 result; // rax
char *v6; // rbx
size_t v7; // rbp
int v8; // er13
size_t v9; // rax
size_t v10; // rax

v4 = strlen(needle);
result = 0LL;
if ( v4 )
{
v6 = strstr(haystack, needle);
if ( v6 )
{
v7 = strlen((const char *)src);
v8 = v7 - v4;
do
{
if ( v8 > 0 )
{
v9 = strlen(v6);
memmove(&v6[v8], v6, v9 + 1);
}
else if ( v8 < 0 )
{
v10 = strlen(v6);
memmove(v6, &v6[-v8], v8 + v10 + 1);
}
memmove(v6, src, v7);
v6 = strstr(&v6[v7], needle);
}
while ( v6 );
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int strrep(char *buf, char *mae, char *ato)
{
    char *mitsuke, *findpos;
 size_t maelen, atolen;
 int shift;
 findpos = buf;
 maelen = strlen(mae);
 atolen = strlen(ato);
 shift = (int)(strlen(ato)-strlen(mae));
 if (maelen == 0 || strstr(findpos, mae) == ((void *)0)) return 0;
 while ((mitsuke = strstr(findpos, mae)) != ((void *)0)) {
  if (shift > 0) {
   memmove(mitsuke + shift, mitsuke, strlen(mitsuke) + 1);
  } else if (shift < 0) {
   memmove(mitsuke, mitsuke - shift, strlen(mitsuke) + shift + 1);
  }
  memmove(mitsuke, ato, atolen);
  findpos = mitsuke + atolen;
 }
 return 1;
}

canonical_original_code:
int strrep(char *buf, char *mae, char *ato)
{
    char *mitsuke; char *findpos;
 unsigned long maelen; unsigned long atolen;
 int shift;
 findpos = buf;
 maelen = strlen(mae);
 atolen = strlen(ato);
 shift = (int)(strlen(ato)-strlen(mae));
 if (maelen == 0 || strstr(findpos, mae) == ((void *)0)) return 0;
 while ((mitsuke = strstr(findpos, mae)) != ((void *)0)) {
  if (shift > 0) {
   memmove(mitsuke + shift, mitsuke, strlen(mitsuke) + 1);
  } else if (shift < 0) {
   memmove(mitsuke, mitsuke - shift, strlen(mitsuke) + shift + 1);
  }
  memmove(mitsuke, ato, atolen);
  findpos = mitsuke + atolen;
 }
 return 1;
}

variable_types:
buf
char *

variable_types:
mae
char *

variable_types:
ato
char *

variable_types:
mitsuke
char *

variable_types:
findpos
char *

variable_types:
maelen
unsigned long

variable_types:
atolen
unsigned long

variable_types: shift int


getBit

original_code:
int getBit(unsigned char *byte, int *pbit, int gbit) {
 int pbyte = *pbit / 8;
 unsigned char *fbyte = byte + pbyte;
 int cutbit = *pbit - (pbyte * 8);
 int lcutbit = 32 - (cutbit + gbit);
 unsigned char tbuf[4];
 unsigned int tnum;
 memcpy(tbuf, fbyte, sizeof(unsigned char) * 4);
 tbuf[0] = tbuf[0] << cutbit;
 tbuf[0] = tbuf[0] >> cutbit;
 tnum = tbuf[0] << 24 | tbuf[1] << 16 | tbuf[2] << 8 | tbuf[3];
 tnum = tnum >> lcutbit;
 *pbit += gbit;
 return tnum;
}

variable_types:
byte
unsigned char *

variable_types:
pbit
int *

variable_types: gbit int

variable_types: pbyte int

variable_types:
fbyte
unsigned char *

variable_types: cutbit int

variable_types: lcutbit int

variable_types:
tbuf
unsigned char [4]

variable_types:
tnum
unsigned int


getStr

decompiled_code:
__int64 __fastcall getStr(__int64 a1, __int64 a2, int *a3, unsigned int a4)
{
int v6; // er13
_BYTE savedregs[4136]; // [rsp+0h] [rbp+0h] BYREF

v6 = *a3;
memset(savedregs, 0, 0x1000uLL);
memcpy(savedregs, (const void *)(a2 + v6 / 8), (int)a4);
*a3 = v6 + 8 * a4;
return AribToString(a1, savedregs, a4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int *a3, unsigned int a4)
{
int v6; // er13
_BYTE savedregs[4136]; // [rsp+0h] [rbp+0h] BYREF

v6 = *a3;
memset(savedregs, 0, 0x1000uLL);
memcpy(savedregs, (const void *)(a2 + v6 / 8), (int)a4);
*a3 = v6 + 8 * a4;
return AribToString(a1, savedregs, a4);
}

original_code:
void getStr(char *tostr, unsigned char *byte, int *pbit, int len) {
 char str[4096];
 int pbyte = *pbit / 8;
 unsigned char *fbyte = byte + pbyte;
 memset(str, 0, sizeof(char) * 4096);
 memcpy(str, fbyte, len);
 *pbit += (len * 8);
 AribToString(tostr, str, len);
 return;
}

variable_types:
tostr
char *

variable_types: len int

variable_types:
str
char [4096]


parseOTHERdesc

decompiled_code:
__int64 __fastcall parseOTHERdesc(__int64 a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
getBit(a1, v2, 8);
return (unsigned int)getBit(a1, v2, 8) + 2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
func1(a1, v2, 8);
return (unsigned int)func1(a1, v2, 8) + 2;
}

original_code:
int parseOTHERdesc(unsigned char *data) {
 int boff = 0;
 int descriptor_tag;
 int descriptor_length;
 descriptor_tag = getBit(data, &boff, 8);
 descriptor_length = getBit(data, &boff, 8);
 return descriptor_length + 2;
}

variable_types:
data
unsigned char *

variable_types: boff int


xmlspecialchars

original_code:
void xmlspecialchars(char *str)
{
 strrep(str, "&", "&");
 strrep(str, "'", "'");
 strrep(str, "\"", """);
 strrep(str, "<", "<");
 strrep(str, ">", ">");
}

variable_types:
str
char *


main

repo: hachreak/scheduler-clockdriven

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
executive_init(argc, argv, envp);
return 0;
}

original_code:
int main(){
  executive_init();
  return 0;
}


decompiled_code:
void __fastcall __noreturn sp_task_handler(void *a1)
{
while ( 1 )
{
if ( (unsigned int)excstate_get_state((unsigned int)((_DWORD)&executive_sp_frame_desc + 8)) == 1 )
excstate_set_state((unsigned int)((_DWORD)&executive_sp_frame_desc + 8), 4LL);
excstate_wait_running((unsigned int)((_DWORD)&executive_sp_frame_desc + 8));
excstate_set_state((unsigned int)((_DWORD)&executive_sp_frame_desc + 8), 1LL);
puts("[SP] [WAKE UP] SP frame");
puts("[SP] [EXEC SP TASK]");
SP_TASK();
puts("[SP] [END]");
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
while ( 1 )
{
if ( (unsigned int)excstate_get_state((unsigned int)((_DWORD)&executive_sp_frame_desc + 8)) == 1 )
excstate_set_state((unsigned int)((_DWORD)&executive_sp_frame_desc + 8), 4LL);
excstate_wait_running((unsigned int)((_DWORD)&executive_sp_frame_desc + 8));
excstate_set_state((unsigned int)((_DWORD)&executive_sp_frame_desc + 8), 1LL);
puts("[SP] [WAKE UP] SP frame");
puts("[SP] [EXEC SP TASK]");
SP_TASK();
puts("[SP] [END]");
}
}

original_code:
void *sp_task_handler(){
  while(1){
    if(excstate_get_state(&executive_sp_frame_desc.excstate) == WORKING){
      excstate_set_state(&executive_sp_frame_desc.excstate, COMPLETED);
    }
    excstate_wait_running(&executive_sp_frame_desc.excstate);
    excstate_set_state(&executive_sp_frame_desc.excstate, WORKING);
    printf("[SP] [WAKE UP] SP frame\n");
    printf("[SP] [EXEC SP TASK]\n");
    SP_TASK();
    printf("[SP] [END]\n");
  }
  return ((void *)0);
}


decompiled_code:
void __fastcall __noreturn frame_handler(void *a1)
{
unsigned int v1; // er12
__int64 v2; // rbp
unsigned int v3; // ebx
__int64 v4; // r14

v1 = *(_DWORD *)a1;
v2 = 208LL * *(int *)a1;
while ( 1 )
{
do
{
excstate_set_state(frame_descs + v2 + 8, 0LL);
printf("[FRAME %d] [WAIT WAKE UP]\n", v1);
excstate_wait_running(frame_descs + v2 + 8);
excstate_set_state(frame_descs + v2 + 8, 1LL);
printf("[FRAME %d] [WAKE UP]\n", v1);
v3 = **((_DWORD **)&SCHEDULE + (int)v1);
}
while ( v3 == -1 );
v4 = 4LL;
do
{
printf("[FRAME %d] [EXECUTE %d] [INIT]\n", v1, v3);
excstate_set_state(frame_descs + v2 + 112, v3);
(*(&P_TASKS + (int)v3))();
printf("[FRAME %d] [EXECUTE %d] [END]\n", v1, v3);
v3 = *(_DWORD *)(*((_QWORD *)&SCHEDULE + (int)v1) + v4);
v4 += 4LL;
}
while ( v3 != -1 );
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
unsigned int v1; // er12
__int64 v2; // rbp
unsigned int v3; // ebx
__int64 v4; // r14

v1 = *(_DWORD *)a1;
v2 = 208LL * *(int *)a1;
while ( 1 )
{
do
{
excstate_set_state(frame_descs + v2 + 8, 0LL);
printf("[FRAME %d] [WAIT WAKE UP]\n", v1);
excstate_wait_running(frame_descs + v2 + 8);
excstate_set_state(frame_descs + v2 + 8, 1LL);
printf("[FRAME %d] [WAKE UP]\n", v1);
v3 = **((_DWORD **)&SCHEDULE + (int)v1);
}
while ( v3 == -1 );
v4 = 4LL;
do
{
printf("[FRAME %d] [EXECUTE %d] [INIT]\n", v1, v3);
excstate_set_state(frame_descs + v2 + 112, v3);
(*(&P_TASKS + (int)v3))();
printf("[FRAME %d] [EXECUTE %d] [END]\n", v1, v3);
v3 = *(_DWORD *)(*((_QWORD *)&SCHEDULE + (int)v1) + v4);
v4 += 4LL;
}
while ( v3 != -1 );
}
}

original_code:
void *frame_handler(void *arg){
  int index = * (int *) arg;
  while(1){
    excstate_set_state(&frame_descs[index].excstate, IDLE);
    printf("[FRAME %d] [WAIT WAKE UP]\n", index);
    excstate_wait_running(&frame_descs[index].excstate);
    excstate_set_state(&frame_descs[index].excstate, WORKING);
    printf("[FRAME %d] [WAKE UP]\n", index);
    int task_index = 0, i = 0;
    while((task_index = SCHEDULE[index][i]) != -1){
      printf("[FRAME %d] [EXECUTE %d] [INIT]\n", index, task_index);
      excstate_set_state(&frame_descs[index].task_in_execution, task_index);
      P_TASKS[task_index]();
      printf("[FRAME %d] [EXECUTE %d] [END]\n", index, task_index);
      i++;
    }
  }
  return ((void *)0);
}

canonical_original_code:
void *frame_handler(void *arg){
  int index = * (int *) arg;
  while(1){
    excstate_set_state(&frame_descs[index].excstate, IDLE);
    printf("[FRAME %d] [WAIT WAKE UP]\n", index);
    excstate_wait_running(&frame_descs[index].excstate);
    excstate_set_state(&frame_descs[index].excstate, WORKING);
    printf("[FRAME %d] [WAKE UP]\n", index);
    int task_index = 0; int i = 0;
    while((task_index = SCHEDULE[index][i]) != -1){
      printf("[FRAME %d] [EXECUTE %d] [INIT]\n", index, task_index);
      excstate_set_state(&frame_descs[index].task_in_execution, task_index);
      P_TASKS[task_index]();
      printf("[FRAME %d] [EXECUTE %d] [END]\n", index, task_index);
      i++;
    }
  }
  return ((void *)0);
}

variable_types:
arg
void *

variable_types: index int

variable_types: i int


decompiled_code:
__int64 __fastcall executive_check_deadline_frame(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // eax

printf("[FRAME %d] [DEADLINE CHECK]\n", a1);
result = (unsigned int)excstate_get_state(frame_descs + 208LL * (int)a1 + 8) - 1;
if ( (unsigned int)result <= 1 )
{
v2 = excstate_get_state(frame_descs + 208LL * (int)a1 + 112);
printf("[FRAME %d] [DEADLINE MISS] [TASK %d]!\n", a1, v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 result; // rax
unsigned int v2; // eax

printf("[FRAME %d] [DEADLINE CHECK]\n", a1);
result = (unsigned int)excstate_get_state(frame_descs + 208LL * (int)a1 + 8) - 1;
if ( (unsigned int)result <= 1 )
{
v2 = excstate_get_state(frame_descs + 208LL * (int)a1 + 112);
printf("[FRAME %d] [DEADLINE MISS] [TASK %d]!\n", a1, v2);
exit(1);
}
return result;
}

original_code:
void executive_check_deadline_frame(int index){
  printf("[FRAME %d] [DEADLINE CHECK]\n", index);
  int state = excstate_get_state(&frame_descs[index].excstate);
  if(state == WORKING || state == PENDING){
    int task = excstate_get_state(&frame_descs[index].task_in_execution);
    printf("[FRAME %d] [DEADLINE MISS] [TASK %d]!\n", index, task);
    exit(1);
  }
}

variable_types: state int

variable_types: task int


decompiled_code:
bool __fastcall executive_sp_check_static_deadline(int a1)
{
unsigned int v1; // er13
int v2; // er12
unsigned int v3; // ebp
__int64 v4; // r8
int v5; // er14
int v6; // ebx
__int64 v7; // rdx
unsigned int v8; // ebx
int v10; // [rsp+Ch] [rbp-3Ch]

v1 = NUM_FRAMES;
v2 = H_PERIOD / NUM_FRAMES * (a1 + 1);
v3 = H_PERIOD / NUM_FRAMES + v2;
v4 = (unsigned int)(v2 + SP_DLINE);
if ( H_PERIOD / NUM_FRAMES > SP_DLINE )
{
v5 = 0;
v6 = 1;
}
else
{
v10 = H_PERIOD / NUM_FRAMES;
v5 = 0;
v6 = 1;
do
{
v7 = *((unsigned int *)&SLACK + (v6 + a1) % v1);
v5 += v7;
printf("SLACK[%d] = %d; CURMAX[%d] DEADLINE[%d]\n", (v6 + a1) % v1, v7, v3, v4);
++v6;
v3 += v10;
v4 = (unsigned int)(SP_DLINE + v2);
}
while ( SP_DLINE >= (int)(v3 - v2) );
}
v8 = v6 - 1;
printf("[SP] [WAIT] %d frame\n", v8);
excstate_set_state(&executive_sp_count_frame, v8);
return SP_WCET <= v5;
}

canonical_decompiled_code:
bool __fastcall func3(int a1)
{
unsigned int v1; // er13
int v2; // er12
unsigned int v3; // ebp
__int64 v4; // r8
int v5; // er14
int v6; // ebx
__int64 v7; // rdx
unsigned int v8; // ebx
int v10; // [rsp+Ch] [rbp-3Ch]

v1 = NUM_FRAMES;
v2 = H_PERIOD / NUM_FRAMES * (a1 + 1);
v3 = H_PERIOD / NUM_FRAMES + v2;
v4 = (unsigned int)(v2 + SP_DLINE);
if ( H_PERIOD / NUM_FRAMES > SP_DLINE )
{
v5 = 0;
v6 = 1;
}
else
{
v10 = H_PERIOD / NUM_FRAMES;
v5 = 0;
v6 = 1;
do
{
v7 = *((unsigned int *)&SLACK + (v6 + a1) % v1);
v5 += v7;
printf("SLACK[%d] = %d; CURMAX[%d] DEADLINE[%d]\n", (v6 + a1) % v1, v7, v3, v4);
++v6;
v3 += v10;
v4 = (unsigned int)(SP_DLINE + v2);
}
while ( SP_DLINE >= (int)(v3 - v2) );
}
v8 = v6 - 1;
printf("[SP] [WAIT] %d frame\n", v8);
excstate_set_state(&executive_sp_count_frame, v8);
return SP_WCET <= v5;
}

original_code:
_Bool executive_sp_check_static_deadline(int frame_index){
  int index = frame_index;
  index++;
  int quant = H_PERIOD / NUM_FRAMES;
  int qi = index * quant;
  int y = 1;
  int i = 0;
  int count_slack = 0;
  while((i = qi + (y*quant)) <= (qi + SP_DLINE)){
    int slack = SLACK[(index+y-1)%NUM_FRAMES];
    count_slack += slack;
    printf("SLACK[%d] = %d; CURMAX[%d] DEADLINE[%d]\n", (index+y-1)%NUM_FRAMES, slack, i, (qi + SP_DLINE));
    y++;
  }
  printf("[SP] [WAIT] %d frame\n", --y);
  excstate_set_state(&executive_sp_count_frame, y);
  return (count_slack >= SP_WCET ? 1 : 0);
}

variable_types: quant int

variable_types: qi int

variable_types: y int

variable_types: slack int