UnixConnectTCPSocket

decompiled_code:
__int64 __fastcall UnixConnectTCPSocket(char *name, char *service)
{
__int64 v2; // r12
struct addrinfo *v3; // rbp
int v4; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v2 = off_4040F8();
*(_QWORD *)&req.ai_flags = 0LL;
pai = 0LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(name, service, &req, &pai) )
{
fwrite("getaddrinfo() failed\n", 1uLL, 0x15uLL, stderr);
exit(-1);
}
v3 = pai;
if ( pai )
{
do
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
*(_DWORD *)(v2 + 56) = v4;
if ( v4 != -1 )
{
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) != -1 )
break;
close(*(_DWORD *)(v2 + 56));
*(_DWORD *)(v2 + 56) = -1;
}
v3 = v3->ai_next;
}
while ( v3 );
v3 = pai;
}
freeaddrinfo(v3);
if ( *(_DWORD *)(v2 + 56) == -1 )
{
fwrite("Error: Unable to connect to server.\n", 1uLL, 0x24uLL, stderr);
exit(-1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *name, char *service)
{
__int64 v2; // r12
struct addrinfo *v3; // rbp
int v4; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

v2 = off_4040F8();
*(_QWORD *)&req.ai_flags = 0LL;
pai = 0LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
if ( getaddrinfo(name, service, &req, &pai) )
{
fwrite("getaddrinfo() failed\n", 1uLL, 0x15uLL, stderr);
exit(-1);
}
v3 = pai;
if ( pai )
{
do
{
v4 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
*(_DWORD *)(v2 + 56) = v4;
if ( v4 != -1 )
{
if ( connect(v4, v3->ai_addr, v3->ai_addrlen) != -1 )
break;
close(*(_DWORD *)(v2 + 56));
*(_DWORD *)(v2 + 56) = -1;
}
v3 = v3->ai_next;
}
while ( v3 );
v3 = pai;
}
freeaddrinfo(v3);
if ( *(_DWORD *)(v2 + 56) == -1 )
{
fwrite("Error: Unable to connect to server.\n", 1uLL, 0x24uLL, stderr);
exit(-1);
}
return v2;
}


Unixaccept

repo: cohenadair/assignments

decompiled_code:
__int64 __fastcall Unixaccept(__int64 a1)
{
__int64 v1; // r12
int v2; // ebx
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
v1 = off_4040F8();
v2 = accept(*(_DWORD *)(a1 + 56), (struct sockaddr *)(v1 + 40), addr_len);
if ( v2 < 0 )
{
free((void *)v1);
(*(void (__fastcall **)(__int64, const char *))(a1 + 32))(a1, "ERROR on accept");
}
*(_DWORD *)(v1 + 56) = v2;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // r12
int v2; // ebx
socklen_t addr_len[7]; // [rsp+Ch] [rbp-1Ch] BYREF

addr_len[0] = 16;
v1 = off_4040F8();
v2 = accept(*(_DWORD *)(a1 + 56), (struct sockaddr *)(v1 + 40), addr_len);
if ( v2 < 0 )
{
free((void *)v1);
(*(void (__fastcall **)(__int64, const char *))(a1 + 32))(a1, "ERROR on accept");
}
*(_DWORD *)(v1 + 56) = v2;
return v1;
}

original_code:
nmu_socket_t Unixaccept(nmu_socket_t pSocket)
{
 socklen_t sockAddrLength = sizeof(SocketAddress);
 nmu_socket_t pClientSocket = socketFactory.new();
 int newsockfd =
  accept(pSocket->sockfd, (struct sockaddr *)&(pClientSocket->sockAddr), &sockAddrLength);
 if (newsockfd < 0){
  free(pClientSocket);
  pSocket->error(pSocket, "ERROR on accept");
 }
 pClientSocket->sockfd = newsockfd;
 return pClientSocket;
}

canonical_original_code:
struct NMUSocket *Unixaccept(struct NMUSocket *pSocket)
{
 unsigned int sockAddrLength = sizeof(SocketAddress);
 struct NMUSocket *pClientSocket = socketFactory.new();
 int newsockfd = accept(pSocket->sockfd, (struct sockaddr *)&(pClientSocket->sockAddr), &sockAddrLength);
 if (newsockfd < 0){
  free(pClientSocket);
  pSocket->error(pSocket, "ERROR on accept");
 }
 pClientSocket->sockfd = newsockfd;
 return pClientSocket;
}

variable_types:
pSocket
struct NMUSocket *

variable_types:
sockAddrLength
unsigned int

variable_types: struct NMUSocket { struct NMUSocket *(*accept)(struct NMUSocket *); int (*read)(struct NMUSocket *, void *, int); int (*write)(struct NMUSocket *, void *, int); void (*close)(struct NMUSocket *); void (*error)(struct NMUSocket *, char *); void (*acceptAndForkService)(struct NMUSocket *, void (*)(struct NMUSocket *)); struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sockAddr; int sockfd; } *

variable_types: newsockfd int

user_defined_types: struct NMUSocket { struct NMUSocket *(*accept)(struct NMUSocket *); int (*read)(struct NMUSocket *, void *, int); int (*write)(struct NMUSocket *, void *, int); void (*close)(struct NMUSocket *); void (*error)(struct NMUSocket *, char *); void (*acceptAndForkService)(struct NMUSocket *, void (*)(struct NMUSocket *)); struct sockaddr_in sockAddr; int sockfd; }

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


Unixclose

decompiled_code:
void __fastcall Unixclose(void *ptr)
{
close(*((_DWORD *)ptr + 14));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
close(*((_DWORD *)ptr + 14));
free(ptr);
}

original_code:
void Unixclose(nmu_socket_t pSocket)
{
 close(pSocket->sockfd);
 free(pSocket);
}

canonical_original_code:
void Unixclose(struct NMUSocket *pSocket)
{
 close(pSocket->sockfd);
 free(pSocket);
}

return_type: void


Unixerror

decompiled_code:
void __fastcall __noreturn Unixerror(__int64 a1, const char *a2)
{
perror(a2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func16(__int64 a1, const char *a2)
{
perror(a2);
exit(1);
}

original_code:
void Unixerror(nmu_socket_t pSocket, char *msg)
{
    perror(msg);
    exit(1);
}

canonical_original_code:
void Unixerror(struct NMUSocket *pSocket, char *msg)
{
    perror(msg);
    exit(1);
}

variable_types:
msg
char *


Unixconnect

decompiled_code:
bool __fastcall Unixconnect(__int64 a1)
{
return connect(*(_DWORD *)(a1 + 56), (const struct sockaddr *)(a1 + 40), 0x10u) == 0;
}

canonical_decompiled_code:
bool __fastcall func17(__int64 a1)
{
return connect(*(_DWORD *)(a1 + 56), (const struct sockaddr *)(a1 + 40), 0x10u) == 0;
}

original_code:
_Bool Unixconnect(nmu_socket_t pSocket)
{
    return connect(
  pSocket->sockfd,
  (struct sockaddr *)&pSocket->sockAddr,
  sizeof(SocketAddress)) == 0;
}

canonical_original_code:
_Bool Unixconnect(struct NMUSocket *pSocket)
{
    return connect(
  pSocket->sockfd,
  (struct sockaddr *)&pSocket->sockAddr,
  sizeof(SocketAddress)) == 0;
}

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


shouldQuit

decompiled_code:
bool shouldQuit()
{
bool v0; // zf
bool v1; // sf
bool v2; // of

v2 = __OFSUB__(fortuneCount_0, 8);
v0 = fortuneCount_0 == 8;
v1 = fortuneCount_0 - 8 < 0;
++fortuneCount_0;
return !(v1 ^ v2 | v0);
}

canonical_decompiled_code:
bool func19()
{
bool v0; // zf
bool v1; // sf
bool v2; // of

v2 = __OFSUB__(fortuneCount_0, 8);
v0 = fortuneCount_0 == 8;
v1 = fortuneCount_0 - 8 < 0;
++fortuneCount_0;
return !(v1 ^ v2 | v0);
}

original_code:
_Bool shouldQuit(void)
{
 static int fortuneCount = 0;
 return (fortuneCount++ >= 9);
}

canonical_original_code:
_Bool shouldQuit()
{
 static int fortuneCount = 0;
 return (fortuneCount++ >= 9);
}

variable_types: fortuneCount int


main

canonical_name: main

repo: colding/argopt

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v5; // [rsp+4h] [rbp-174h] BYREF
void *ptr; // [rsp+8h] [rbp-170h]
__int64 v7[40]; // [rsp+10h] [rbp-168h] BYREF

v5 = 0;
while ( 1 )
{
memset(v7, 0, sizeof(v7));
v7[0] = (__int64)&unk_402004;
v7[1] = (__int64)"-rb will help you rb-fy your source";
LODWORD(v7[4]) = 114;
v7[5] = (__int64)&unk_402007;
v7[6] = (__int64)"-rw is great to foobalooze the bazee";
v7[8] = (__int64)&v5;
LODWORD(v7[9]) = 1;
v7[10] = (__int64)"abc123";
v7[11] = (__int64)"-abc123 alphabetizes a lower set";
v7[15] = (__int64)"abc456";
v7[16] = (__int64)"-abc456 alphabetizes a higher set";
v7[20] = (__int64)"abc";
v7[25] = (__int64)"count";
v7[26] = (__int64)"-count <PARAMETER> enumerates the parameter";
LODWORD(v7[27]) = 1;
LODWORD(v7[29]) = 99;
v7[30] = (__int64)"offset";
v7[31] = (__int64)"-offset [PARAMETER] set the offset for the optional paramater";
LODWORD(v7[32]) = 2;
LODWORD(v7[34]) = 111;
v3 = argopt();
if ( v3 > 0 )
{
if ( v3 != 111 )
{
if ( v3 == 114 )
{
fprintf(_bss_start, "%d - Option found:\t\t%s\n", 103LL, *argv);
goto LABEL_6;
}
if ( v3 == 99 )
{
strtol((const char *)ptr, 0LL, 10);
fprintf(_bss_start, "%d - Count option found:\t%s\n", 90LL, *(argv - 1));
fprintf(_bss_start, "%d - Count parameter is:\t\"%s\"\n", 91LL, (const char *)ptr);
goto LABEL_6;
}
LABEL_23:
printf("?? get_option() returned character code 0%o ??\n", (unsigned int)v3);
goto LABEL_6;
}
if ( ptr )
{
fprintf(_bss_start, "%d - Offset option found:\t%s\n", 95LL, *(argv - 1));
fprintf(_bss_start, "%d - Offset parameter is:\t\"%s\"\n", 96LL, (const char *)ptr);
strtol((const char *)ptr, 0LL, 16);
}
else
{
fprintf(_bss_start, "%d - Offset option found:\t%s\n", 99LL, *argv);
}
}
else
{
if ( v3 < -6 )
goto LABEL_23;
switch ( v3 )
{
case -5:
fprintf(_bss_start, "%d - Bad or malformed option found:\t%s\n", 69LL, *argv);
argopt_help();
break;
case -4:
fprintf(_bss_start, "%d - Option missing parameter:\t%s\n", 76LL, *argv);
argopt_help();
break;
case -3:
fprintf(_bss_start, "%d - Unknown option found:\t%s\n", 62LL, *argv);
argopt_help();
break;
case -2:
++*argv;
argopt_completions();
break;
case -1:
fprintf(_bss_start, "%d - Option found:\t\t%s (*flag is not NULL)\n", 53LL, *argv);
break;
case 0:
fprintf(_bss_start, "%d - Option found:\t\t%s\n", 86LL, *argv);
break;
default:
fwrite("\nargv[] parsed.\n", 1uLL, 0x10uLL, _bss_start);
exit(0);
}
}
LABEL_6:
if ( ptr )
free(ptr);
if ( v5 )
{
fprintf(_bss_start, "-rw option found:\t%s\n", *argv);
v5 = 0;
}
}
}

original_code:
int
main(int argc, char **argv)
{
 int index = 0;
 int count;
 int offset;
 int opt_rw = 0;
 int opt_rb = 0;
 while (1) {
  int c;
  char *parameter;
  struct option_t options[] = {
   {"rb", "-rb will help you rb-fy your source", NO_PARAM, ((void *)0), 'r'},
   {"rw", "-rw is great to foobalooze the bazee", NO_PARAM, &opt_rw, 1},
   {"abc123", "-abc123 alphabetizes a lower set", NO_PARAM, ((void *)0), 0},
   {"abc456", "-abc456 alphabetizes a higher set", NO_PARAM, ((void *)0), 0},
   {"abc", ((void *)0), NO_PARAM, ((void *)0), 0},
   {"count", "-count <PARAMETER> enumerates the parameter", NEED_PARAM, ((void *)0), 'c'},
   {"offset", "-offset [PARAMETER] set the offset for the optional paramater", OPTIONAL_PARAM, ((void *)0), 'o'},
   {0, 0, 0, 0}
  };
  c = argopt(argc,
      argv,
      options,
      &index,
      &parameter);
  switch (c) {
  case (-1) :
   fprintf(stdout, "%d - Option found:\t\t%s (*flag is not NULL)\n", 53, argv[index]);
   break;
  case (-2) :
   argopt_completions(stdout,
        "Ambigious option found. Possible completions:",
        ++argv[index],
        options);
   break;
  case (-3) :
   fprintf(stdout, "%d - Unknown option found:\t%s\n", 62, argv[index]);
   argopt_help(stdout,
        "Unknown option found",
        argv[0],
        options);
   break;
  case (-5) :
   fprintf(stdout, "%d - Bad or malformed option found:\t%s\n", 69, argv[index]);
   argopt_help(stdout,
        "Bad or malformed option found",
        argv[0],
        options);
   break;
  case (-4) :
   fprintf(stdout, "%d - Option missing parameter:\t%s\n", 76, argv[index]);
   argopt_help(stdout,
        "Option missing parameter",
        argv[0],
        options);
   break;
  case (-6) :
   fprintf(stdout, "\nargv[] parsed.\n");
   goto opt_done;
  case 0 :
   fprintf(stdout, "%d - Option found:\t\t%s\n", 86, argv[index]);
   break;
  case 'c' :
   count = strtol(parameter, ((void *)0), 10);
   fprintf(stdout, "%d - Count option found:\t%s\n", 90, argv[index-1]);
   fprintf(stdout, "%d - Count parameter is:\t\"%s\"\n", 91, parameter);
   break;
  case 'o' :
   if (parameter) {
    fprintf(stdout, "%d - Offset option found:\t%s\n", 95, argv[index-1]);
    fprintf(stdout, "%d - Offset parameter is:\t\"%s\"\n", 96, parameter);
    offset = strtol(parameter, ((void *)0), 16);
   } else {
    fprintf(stdout, "%d - Offset option found:\t%s\n", 99, argv[index]);
   }
   break;
  case 'r' :
   fprintf(stdout, "%d - Option found:\t\t%s\n", 103, argv[index]);
   opt_rb = 1;
   break;
  default:
   printf ("?? get_option() returned character code 0%o ??\n", c);
  }
  if (parameter)
   free(parameter);
  if (opt_rw) {
   fprintf(stdout, "-rw option found:\t%s\n", argv[index]);
   opt_rw = 0;
  }
 }
opt_done:
 if ((index) && (index < argc)) {
  printf ("non-option ARGV-elements: ");
  while (index < argc)
   printf("%s ", argv[index++]);
  printf ("\n");
  exit(1);
 }
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: index int

variable_types: count int

variable_types: offset int

variable_types: c int

variable_types:
parameter
char *

variable_types: struct option_t { char *name; char *help; enum need_param_t { NO_PARAM=0, NEED_PARAM=1, OPTIONAL_PARAM=2 } param; int *flag; int val; } []

return_type: int

user_defined_types: struct option_t { char *name; char *help; enum need_param_t param; int *flag; int val; }


decompiled_code:
_BOOL8 __fastcall is_option(_BYTE *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == 45 )
result = a1[1] != 0;
return result;
}

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

result = 0LL;
if ( *a1 == 45 )
result = a1[1] != 0;
return result;
}

original_code:
static int
is_option(const char * const str)
{
        return ((str[0] == '-') && str[1]) ? 1 : 0;
}

canonical_original_code:
static int is_option(char *str)
{
        return ((str[0] == '-') && str[1]) ? 1 : 0;
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall match_meassure(char *a1, char *a2)
{
char v2; // dl
char v3; // cl
__int64 v4; // rax
unsigned int v5; // er8

if ( !a1 || !a2 )
return 0LL;
v2 = *a1;
v3 = *a2;
v4 = 1LL;
do
{
v5 = v4 - 1;
if ( v3 != v2 )
break;
v2 = a1[v4];
v5 = v4;
if ( !v2 )
break;
v3 = a2[v4++];
}
while ( v3 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, char *a2)
{
char v2; // dl
char v3; // cl
__int64 v4; // rax
unsigned int v5; // er8

if ( !a1 || !a2 )
return 0LL;
v2 = *a1;
v3 = *a2;
v4 = 1LL;
do
{
v5 = v4 - 1;
if ( v3 != v2 )
break;
v2 = a1[v4];
v5 = v4;
if ( !v2 )
break;
v3 = a2[v4++];
}
while ( v3 );
return v5;
}

original_code:
static int
match_meassure(const char *str1,
               const char *str2)
{
        int retv = 0;
        if (!str1 || !str2)
                return 0;
        do {
                if (*str1 != *str2)
                        return retv;
                retv++;
        } while (*(++str1) && *(++str2));
        return retv;
}

canonical_original_code:
static int match_meassure(char *str1, char *str2)
{
        int retv = 0;
        if (!str1 || !str2)
                return 0;
        do {
                if (*str1 != *str2)
                        return retv;
                retv++;
        } while (*(++str1) && *(++str2));
        return retv;
}

variable_types: retv int


decompiled_code:
__int64 __fastcall find_option(__int64 a1, char **a2)
{
char *v2; // rbp
size_t v3; // rax
char *v4; // r15
size_t v5; // r13
char **v6; // rbx
unsigned int v7; // er14
unsigned int v8; // er12
unsigned __int64 v9; // rax
bool v10; // cf
char v11; // cl
unsigned __int64 v13; // [rsp+0h] [rbp-48h]
char v14; // [rsp+Eh] [rbp-3Ah]
char v15; // [rsp+Fh] [rbp-39h]

v2 = (char *)(a1 + 1);
v3 = strlen((const char *)(a1 + 1));
v4 = *a2;
if ( !*a2 )
return (unsigned int)-3;
v15 = 0;
v5 = v3;
v6 = a2 + 5;
v7 = 0;
v14 = 1;
v8 = 0;
v13 = 0LL;
do
{
if ( !strcmp(v2, v4) )
return v8;
v9 = (int)match_meassure(v4, v2);
if ( v5 == (int)v9 && (_DWORD)v9 )
{
v15 = 1;
v10 = v13 < (int)v9;
if ( v13 == (int)v9 )
{
v14 = 1;
}
else
{
if ( v13 >= v9 )
v9 = v13;
v11 = v14;
if ( v10 )
v7 = v8;
v13 = v9;
if ( v10 )
v11 = 0;
v14 = v11;
}
}
v4 = *v6;
v6 += 5;
++v8;
}
while ( v4 );
if ( !v15 )
return (unsigned int)-3;
if ( v14 )
v7 = -2;
return v7;
}

original_code:
static int
find_option(const char *opt,
            const struct option_t * const options)
{
        int i = 0;
        size_t best = 0;
        size_t match = 0;
        int best_idx = 0;
        size_t min_match = strlen(++opt);
        char amb = 1;
        char found = 0;
        while (options[i].name) {
                if (!strcmp(opt, options[i].name))
                        return i;
                match = match_meassure(options[i].name, opt);
                if (match) {
                        if (match != min_match)
                                goto next;
                        found = 1;
                        if (match == best)
                                amb = 1;
                        else if (match > best) {
                                best_idx = i;
                                best = match;
                                amb = 0;
                        }
                }
        next:
                i++;
        }
        if (!found)
                return (-3);
        if (amb)
                return (-2);
        return best_idx;
}

canonical_original_code:
static int find_option(char *opt, struct option_t *options)
{
        int i = 0;
        unsigned long best = 0;
        unsigned long match = 0;
        int best_idx = 0;
        unsigned long min_match = strlen(++opt);
        char amb = 1;
        char found = 0;
        while (options[i].name) {
                if (!strcmp(opt, options[i].name))
                        return i;
                match = match_meassure(options[i].name, opt);
                if (match) {
                        if (match != min_match)
                                goto next;
                        found = 1;
                        if (match == best)
                                amb = 1;
                        else if (match > best) {
                                best_idx = i;
                                best = match;
                                amb = 0;
                        }
                }
        next:
                i++;
        }
        if (!found)
                return (-3);
        if (amb)
                return (-2);
        return best_idx;
}

variable_types:
opt
char *

variable_types: struct option_t { char *name; char *help; enum need_param_t { NO_PARAM=0, NEED_PARAM=1, OPTIONAL_PARAM=2 } param; int *flag; int val; } *

variable_types: i int

variable_types:
best
unsigned long

variable_types:
match
unsigned long

variable_types: amb char

variable_types: found char


decompiled_code:
char *__fastcall is_param(__int64 a1)
{
if ( *(_BYTE *)a1 == 45 )
return 0LL;
if ( *(_BYTE *)a1 == 92 )
a1 += *(_BYTE *)(a1 + 1) == 45;
return strdup((const char *)a1);
}

canonical_decompiled_code:
char *__fastcall func10(__int64 a1)
{
if ( *(_BYTE *)a1 == 45 )
return 0LL;
if ( *(_BYTE *)a1 == 92 )
a1 += *(_BYTE *)(a1 + 1) == 45;
return strdup((const char *)a1);
}

original_code:
static char*
is_param(const char *param)
{
        if (param[0] == '-')
                return ((void *)0);
        if ((param[0] == '\\') && (param[1] == '-'))
                param++;
        return strdup(param);
}

canonical_original_code:
static char *is_param(char *param)
{
        if (param[0] == '-')
                return ((void *)0);
        if ((param[0] == '\\') && (param[1] == '-'))
                param++;
        return strdup(param);
}

variable_types:
param
char *

return_type: char *


argopt

original_code:
int
argopt(int argc,
       char *argv[],
       const struct option_t * const options,
       int *index,
       char **parameter)
{
        static int argv_idx = 0;
        static int push_count = 0;
        int opt_index = 0;
        if (!options)
                return (-6);
        if (*index == -1) {
                argv_idx = 0;
                push_count = 0;
        }
        *parameter = ((void *)0);
        if (++argv_idx < argc) {
                if (push_count + argv_idx >= argc) {
                        *index = argc - push_count;
                        return (-6);
                }
                *index = argv_idx;
                if (!is_option(argv[argv_idx])) {
                        if (push_count + argv_idx == argc)
                                return (-6);
                        push_to_end(argc, argv, argv_idx);
                        push_count++;
                        argv_idx--;
                        *index = argc - 1;
                        return (-5);
                }
                opt_index = find_option(argv[argv_idx], options);
                if (opt_index < 0) {
                        push_to_end(argc, argv, argv_idx);
                        push_count++;
                        *index = argc - 1;
                        if (push_count + argv_idx == argc) {
                                argv_idx--;
                                return opt_index;
                        }
                        if (!is_option(argv[argv_idx])) {
                                push_to_end(argc, argv, argv_idx);
                                *index = argc - 2;
                                push_count++;
                        }
                        argv_idx--;
                        return opt_index;
                }
                *index = argv_idx;
                switch (options[opt_index].param) {
                case NO_PARAM :
                        break;
                case NEED_PARAM :
                        if (push_count + argv_idx + 1 == argc)
                                return (-4);
                        *parameter = is_param(argv[argv_idx+1]);
                        if (!*parameter)
                                return (-4);
                        *index = ++argv_idx;
                        break;
                case OPTIONAL_PARAM :
                        if (push_count + argv_idx + 1 == argc)
                                break;
                        *parameter = is_param(argv[argv_idx+1]);
                        if (*parameter)
                                *index = ++argv_idx;
                        break;
                }
                if (options[opt_index].flag == ((void *)0))
                        return options[opt_index].val;
                else {
                        *(options[opt_index].flag) = options[opt_index].val;
                        return (-1);
                }
        }
        *index = argc - push_count;
        return (-6);
}

canonical_original_code:
int argopt(int argc, char *argv[], struct option_t *options, int *index, char **parameter)
{
        static int argv_idx = 0;
        static int push_count = 0;
        int opt_index = 0;
        if (!options)
                return (-6);
        if (*index == -1) {
                argv_idx = 0;
                push_count = 0;
        }
        *parameter = ((void *)0);
        if (++argv_idx < argc) {
                if (push_count + argv_idx >= argc) {
                        *index = argc - push_count;
                        return (-6);
                }
                *index = argv_idx;
                if (!is_option(argv[argv_idx])) {
                        if (push_count + argv_idx == argc)
                                return (-6);
                        push_to_end(argc, argv, argv_idx);
                        push_count++;
                        argv_idx--;
                        *index = argc - 1;
                        return (-5);
                }
                opt_index = find_option(argv[argv_idx], options);
                if (opt_index < 0) {
                        push_to_end(argc, argv, argv_idx);
                        push_count++;
                        *index = argc - 1;
                        if (push_count + argv_idx == argc) {
                                argv_idx--;
                                return opt_index;
                        }
                        if (!is_option(argv[argv_idx])) {
                                push_to_end(argc, argv, argv_idx);
                                *index = argc - 2;
                                push_count++;
                        }
                        argv_idx--;
                        return opt_index;
                }
                *index = argv_idx;
                switch (options[opt_index].param) {
                case NO_PARAM :
                        break;
                case NEED_PARAM :
                        if (push_count + argv_idx + 1 == argc)
                                return (-4);
                        *parameter = is_param(argv[argv_idx+1]);
                        if (!*parameter)
                                return (-4);
                        *index = ++argv_idx;
                        break;
                case OPTIONAL_PARAM :
                        if (push_count + argv_idx + 1 == argc)
                                break;
                        *parameter = is_param(argv[argv_idx+1]);
                        if (*parameter)
                                *index = ++argv_idx;
                        break;
                }
                if (options[opt_index].flag == ((void *)0))
                        return options[opt_index].val;
                else {
                        *(options[opt_index].flag) = options[opt_index].val;
                        return (-1);
                }
        }
        *index = argc - push_count;
        return (-6);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
index
int *

variable_types:
parameter
char **

user_defined_types: enum need_param_t { NO_PARAM=0, NEED_PARAM=1, OPTIONAL_PARAM=2 }


repo: collindoyle/ExPED

decompiled_code:
char *__fastcall init_font(char *dest, const char *a2, int a3, __m128i a4)
{
char *v4; // r8
int v5; // er14
char *result; // rax

v4 = dest;
v5 = _mm_cvtsi128_si32(a4);
if ( !dest )
v4 = (char *)malloc(0x28uLL);
result = strcpy(v4, a2);
*((_DWORD *)result + 8) = v5;
*((_DWORD *)result + 9) = a3;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *dest, const char *a2, int a3, __m128i a4)
{
char *v4; // r8
int v5; // er14
char *result; // rax

v4 = dest;
v5 = _mm_cvtsi128_si32(a4);
if ( !dest )
v4 = (char *)malloc(0x28uLL);
result = strcpy(v4, a2);
*((_DWORD *)result + 8) = v5;
*((_DWORD *)result + 9) = a3;
return result;
}

original_code:
pedfont * init_font (pedfont * pfont, char * name, float size, pedfontstyle style) {
 pedfont * newfont;
 if (pfont == ((void *)0)) {
  newfont = (pedfont *)malloc(sizeof(pedfont));
 }
 else {
  newfont = pfont;
 }
 strcpy(newfont->name,name);
 newfont->size = size;
 newfont->style = style;
 return newfont;
}

canonical_original_code:
struct _pedfont *init_font(struct _pedfont *pfont, char *name, float size, enum _pedfontstyle style) {
 struct _pedfont *newfont;
 if (pfont == ((void *)0)) {
  newfont = (struct _pedfont *)malloc(sizeof(pedfont));
 }
 else {
  newfont = pfont;
 }
 strcpy(newfont->name,name);
 newfont->size = size;
 newfont->style = style;
 return newfont;
}

variable_types:
pfont
struct _pedfont *

variable_types:
name
char *

variable_types: size float

variable_types: struct _pedfont { char name[32]; float size; enum _pedfontstyle { PEDFONT_NONE=0, PEDFONT_BOLD=1, PEDFONT_ITALIC=2, PEDFONT_BOLD_ITALIC=3 } style; } *

user_defined_types: struct _pedfont { char name[32]; float size; enum _pedfontstyle style; }


decompiled_code:
_BOOL8 __fastcall is_equal(__int64 a1, __int64 a2)
{
int v2; // er8
_BOOL8 result; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = strcmp((const char *)a1, (const char *)a2);
result = 0LL;
if ( v2 )
return result;
if ( *(float *)(a1 + 32) != *(float *)(a2 + 32) )
return 0LL;
return *(_DWORD *)(a1 + 36) == *(_DWORD *)(a2 + 36);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // er8
_BOOL8 result; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = strcmp((const char *)a1, (const char *)a2);
result = 0LL;
if ( v2 )
return result;
if ( *(float *)(a1 + 32) != *(float *)(a2 + 32) )
return 0LL;
return *(_DWORD *)(a1 + 36) == *(_DWORD *)(a2 + 36);
}

original_code:
PED_BOOL is_equal (pedfont *fonta, pedfont *fontb) {
 if ( fonta == ((void *)0) || fontb == ((void *)0) )
  return 0;
 if ( strcmp(fonta->name, fontb->name) != 0)
  return 0;
 if ( fonta->size != fontb->size)
  return 0;
 if ( fonta->style != fontb->style)
  return 0;
 return 1;
}

canonical_original_code:
unsigned int is_equal(struct _pedfont *fonta, struct _pedfont *fontb) {
 if ( fonta == ((void *)0) || fontb == ((void *)0) )
  return 0;
 if ( strcmp(fonta->name, fontb->name) != 0)
  return 0;
 if ( fonta->size != fontb->size)
  return 0;
 if ( fonta->style != fontb->style)
  return 0;
 return 1;
}

variable_types:
fontb
struct _pedfont *

return_type: unsigned int

user_defined_types: enum _pedfontstyle { PEDFONT_NONE=0, PEDFONT_BOLD=1, PEDFONT_ITALIC=2, PEDFONT_BOLD_ITALIC=3 }


decompiled_code:
_BOOL8 __fastcall is_bold(__int64 a1)
{
return (*(_DWORD *)(a1 + 36) & 0xFFFFFFFD) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return (*(_DWORD *)(a1 + 36) & 0xFFFFFFFD) == 1;
}

original_code:
PED_BOOL is_bold (pedfont *font) {
 if (font->style == PEDFONT_BOLD ||
     font->style == PEDFONT_BOLD_ITALIC)
  return 1;
 else
  return 0;
}

canonical_original_code:
unsigned int is_bold(struct _pedfont *font) {
 if (font->style == PEDFONT_BOLD ||
     font->style == PEDFONT_BOLD_ITALIC)
  return 1;
 else
  return 0;
}


decompiled_code:
_BOOL8 __fastcall is_italic(__int64 a1)
{
return (unsigned int)(*(_DWORD *)(a1 + 36) - 2) <= 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
return (unsigned int)(*(_DWORD *)(a1 + 36) - 2) <= 1;
}

original_code:
PED_BOOL is_italic (pedfont *font) {
 if (font->style == PEDFONT_ITALIC ||
     font->style == PEDFONT_BOLD_ITALIC )
  return 1;
 else
  return 0;
}

canonical_original_code:
unsigned int is_italic(struct _pedfont *font) {
 if (font->style == PEDFONT_ITALIC ||
     font->style == PEDFONT_BOLD_ITALIC )
  return 1;
 else
  return 0;
}


decompiled_code:
// attributes: thunk
void finalize_node(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func0(void *ptr)
{
free(ptr);
}

original_code:
void finalize_node(pedlistnode *node) {
 if (node->content != ((void *)0)) {
  node->content = ((void *)0);
 }
 free(node);
}

canonical_original_code:
void finalize_node(struct _pedlistnode *node) {
 if (node->content != ((void *)0)) {
  node->content = ((void *)0);
 }
 free(node);
}

variable_types: struct _pedlistnode { void *content; struct _pedlistnode *next; } *


generatefilename

decompiled_code:
char *__fastcall generatefilename(char *src)
{
int v1; // eax
char *v2; // r12
char *v3; // r13
size_t v4; // rax

v1 = strlen(src);
v2 = (char *)calloc(v1 + 5, 1uLL);
v3 = strrchr(src, 46);
strncpy(v2, src, v3 - src);
v4 = strlen(v2);
*(_DWORD *)&v2[v4] = 2003136046;
strcpy(&v2[v4 + 4], v3);
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
int v1; // eax
char *v2; // r12
char *v3; // r13
size_t v4; // rax

v1 = strlen(src);
v2 = (char *)calloc(v1 + 5, 1uLL);
v3 = strrchr(src, 46);
strncpy(v2, src, v3 - src);
v4 = strlen(v2);
*(_DWORD *)&v2[v4] = 2003136046;
strcpy(&v2[v4 + 4], v3);
return v2;
}

original_code:
char * generatefilename (char * sourcefilename) {
 char * result = ((void *)0);
 char * exten;
 int len = strlen(sourcefilename);
 result = (char *)malloc(len+4+1);
 memset(result, 0, len+4+1);
 exten = strrchr(sourcefilename,'.');
 strncpy(result, sourcefilename, exten-sourcefilename);
 strcat(result, ".new");
 strcat(result, exten);
 return result;
}

canonical_original_code:
char *generatefilename(char *sourcefilename) {
 char *result = ((void *)0);
 char *exten;
 int len = strlen(sourcefilename);
 result = (char *)malloc(len+4+1);
 memset(result, 0, len+4+1);
 exten = strrchr(sourcefilename,'.');
 strncpy(result, sourcefilename, exten-sourcefilename);
 strcat(result, ".new");
 strcat(result, exten);
 return result;
}

variable_types:
sourcefilename
char *

variable_types:
result
char *

variable_types:
exten
char *

variable_types: len int


decompiled_code:
void __fastcall finalize_font_cache(void *ptr)
{
__int64 *v2; // rdi
__int64 v3; // rbx

if ( ptr )
{
v2 = *(__int64 **)ptr;
v3 = *v2;
if ( *v2 )
{
do
{
free(*(void **)v3);
*(_QWORD *)v3 = 0LL;
v3 = *(_QWORD *)(v3 + 8);
}
while ( v3 );
v2 = *(__int64 **)ptr;
}
finalize_list(v2);
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 *v2; // rdi
__int64 v3; // rbx

if ( ptr )
{
v2 = *(__int64 **)ptr;
v3 = *v2;
if ( *v2 )
{
do
{
free(*(void **)v3);
*(_QWORD *)v3 = 0LL;
v3 = *(_QWORD *)(v3 + 8);
}
while ( v3 );
v2 = *(__int64 **)ptr;
}
finalize_list(v2);
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void finalize_font_cache (pedfontcache * cache) {
 pedlistnode * pnode;
 if (cache == ((void *)0))
  return;
 pnode = cache->font_list->head;
 while (pnode != ((void *)0)) {
  free(pnode->content);
  pnode->content = ((void *)0);
  pnode = pnode->next;
 }
 finalize_list(cache->font_list);
 free(cache->font_list);
 cache->font_list = ((void *)0);
 free(cache);
}

canonical_original_code:
void finalize_font_cache(struct _pedfontcache *cache) {
 struct _pedlistnode *pnode;
 if (cache == ((void *)0))
  return;
 pnode = cache->font_list->head;
 while (pnode != ((void *)0)) {
  free(pnode->content);
  pnode->content = ((void *)0);
  pnode = pnode->next;
 }
 finalize_list(cache->font_list);
 free(cache->font_list);
 cache->font_list = ((void *)0);
 free(cache);
}

variable_types: struct _pedfontcache { struct _pedlist { struct _pedlistnode { void *content; struct _pedlistnode *next; } *head; struct _pedlistnode *tail; } *font_list; } *

user_defined_types: struct _pedfontcache { struct _pedlist *font_list; }

user_defined_types: struct _pedlist { struct _pedlistnode *head; struct _pedlistnode *tail; }


doPersonB

repo: collinglass/talkagent

decompiled_code:
__int64 doPersonB()
{
__pid_t v0; // eax
char **v1; // rbx
unsigned int v2; // eax
const char *v4; // rsi
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

if ( pipe(pipedes) == -1 )
{
v4 = "Person B: Failed to create pipe.";
LABEL_10:
printf((const char *)stderr, v4);
exit(-1);
}
v0 = fork();
if ( v0 < 0 )
{
v4 = "Person B: Failed to fork.";
goto LABEL_10;
}
if ( !v0 )
{
close(pipedes[0]);
dup2(pipedes[1], 1);
close(pipedes[1]);
sleep(2u);
if ( persBdialog[0] )
{
v1 = persBdialog;
do
{
++v1;
v2 = getpid();
printf("%s (%d)\n", *(v1 - 1), v2);
fflush(stdout);
sleep(2u);
}
while ( *v1 );
}
exit(0);
}
close(pipedes[1]);
return (unsigned int)pipedes[0];
}

canonical_decompiled_code:
__int64 func7()
{
__pid_t v0; // eax
char **v1; // rbx
unsigned int v2; // eax
const char *v4; // rsi
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

if ( pipe(pipedes) == -1 )
{
v4 = "Person B: Failed to create pipe.";
LABEL_10:
printf((const char *)stderr, v4);
exit(-1);
}
v0 = fork();
if ( v0 < 0 )
{
v4 = "Person B: Failed to fork.";
goto LABEL_10;
}
if ( !v0 )
{
close(pipedes[0]);
dup2(pipedes[1], 1);
close(pipedes[1]);
sleep(2u);
if ( persBdialog[0] )
{
v1 = persBdialog;
do
{
++v1;
v2 = getpid();
printf("%s (%d)\n", *(v1 - 1), v2);
fflush(stdout);
sleep(2u);
}
while ( *v1 );
}
exit(0);
}
close(pipedes[1]);
return (unsigned int)pipedes[0];
}

original_code:
int doPersonB(void)
{
    int pipefd[2];
    if (pipe(pipefd) == -1) {
        printf(stderr, "Person B: Failed to create pipe.");
        exit(-1);
    }
    int pid;
    pid = fork();
    if (pid < 0) {
        printf(stderr, "Person B: Failed to fork.");
        exit(-1);
    } else if (pid == 0) {
        close(pipefd[0]);
        dup2(pipefd[1], 1);
        close(pipefd[1]);
        int i;
        sleep(2);
        for(i=0 ; persBdialog[i] != ((void *)0) ; i++)
        {
            printf("%s (%d)\n",persBdialog[i], getpid());
            fflush(stdout);
            sleep(2);
        }
        exit(0);
    } else {
        close(pipefd[1]);
        return(pipefd[0]);
    }
}

canonical_original_code:
int doPersonB()
{
    int pipefd[2];
    if (pipe(pipefd) == -1) {
        printf(stderr, "Person B: Failed to create pipe.");
        exit(-1);
    }
    int pid;
    pid = fork();
    if (pid < 0) {
        printf(stderr, "Person B: Failed to fork.");
        exit(-1);
    } else if (pid == 0) {
        close(pipefd[0]);
        dup2(pipefd[1], 1);
        close(pipefd[1]);
        int i;
        sleep(2);
        for(i=0 ; persBdialog[i] != ((void *)0) ; i++)
        {
            printf("%s (%d)\n",persBdialog[i], getpid());
            fflush(stdout);
            sleep(2);
        }
        exit(0);
    } else {
        close(pipefd[1]);
        return(pipefd[0]);
    }
}

variable_types:
pipefd
int [2]

variable_types: pid int

variable_types: i int


setupTalkAgentB

decompiled_code:
int __fastcall setupTalkAgentB(int fd, int *a2, int *a3)
{
__pid_t v4; // eax
char s[2]; // [rsp+Ch] [rbp-1Ch] BYREF
char v7[26]; // [rsp+Eh] [rbp-1Ah] BYREF

v4 = fork();
if ( v4 < 0 )
{
printf((const char *)stderr, "Talk Agent B: Failed to fork.");
exit(-1);
}
if ( !v4 )
{
dup2(fd, 0);
close(fd);
sprintf(s, "%d", (unsigned int)a2[1]);
sprintf(v7, "%d", (unsigned int)*a3);
close(*a2);
close(a3[1]);
execlp("./talkagent", "./talkagent", v7, s, 0LL);
exit(-1);
}
close(fd);
close(*a3);
return close(a2[1]);
}

canonical_decompiled_code:
int __fastcall func8(int fd, int *a2, int *a3)
{
__pid_t v4; // eax
char s[2]; // [rsp+Ch] [rbp-1Ch] BYREF
char v7[26]; // [rsp+Eh] [rbp-1Ah] BYREF

v4 = fork();
if ( v4 < 0 )
{
printf((const char *)stderr, "Talk Agent B: Failed to fork.");
exit(-1);
}
if ( !v4 )
{
dup2(fd, 0);
close(fd);
sprintf(s, "%d", (unsigned int)a2[1]);
sprintf(v7, "%d", (unsigned int)*a3);
close(*a2);
close(a3[1]);
execlp("./talkagent", "./talkagent", v7, s, 0LL);
exit(-1);
}
close(fd);
close(*a3);
return close(a2[1]);
}

original_code:
void setupTalkAgentB(int persBrfd, int pipefd1[], int pipefd2[])
{
    int pid;
    pid = fork();
    if (pid < 0) {
        printf(stderr, "Talk Agent B: Failed to fork.");
        exit(-1);
    } else if (pid == 0) {
        dup2(persBrfd, 0);
        close(persBrfd);
        char pipeFeed1[2];
        char pipeFeed2[2];
        sprintf(pipeFeed1, "%d", pipefd1[1]);
        sprintf(pipeFeed2, "%d", pipefd2[0]);
        close(pipefd1[0]);
        close(pipefd2[1]);
        execlp("./talkagent", "./talkagent", pipeFeed2, pipeFeed1, ((void *)0));
        exit(-1);
    } else {
        close(persBrfd);
        close(pipefd2[0]);
        close(pipefd1[1]);
    }
}

variable_types: persBrfd int


setupTalkAgentA

decompiled_code:
__int64 __fastcall setupTalkAgentA(int *a1, int *a2)
{
__pid_t v2; // eax
const char *v4; // rsi
char s[2]; // [rsp+4h] [rbp-24h] BYREF
char v6[2]; // [rsp+6h] [rbp-22h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(pipedes) == -1 )
{
v4 = "Talk Agent A: Failed to create pipe.";
goto LABEL_6;
}
v2 = fork();
if ( v2 < 0 )
{
v4 = "Talk Agent A: Failed to fork.";
LABEL_6:
printf((const char *)stderr, v4);
exit(-1);
}
if ( !v2 )
{
dup2(pipedes[0], 0);
close(pipedes[0]);
close(pipedes[1]);
sprintf(s, "%d", (unsigned int)*a1);
sprintf(v6, "%d", (unsigned int)a2[1]);
close(a1[1]);
close(*a2);
execlp("./talkagent", "./talkagent", s, v6, 0LL);
exit(-1);
}
close(pipedes[0]);
close(*a1);
close(a2[1]);
return (unsigned int)pipedes[1];
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, int *a2)
{
__pid_t v2; // eax
const char *v4; // rsi
char s[2]; // [rsp+4h] [rbp-24h] BYREF
char v6[2]; // [rsp+6h] [rbp-22h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(pipedes) == -1 )
{
v4 = "Talk Agent A: Failed to create pipe.";
goto LABEL_6;
}
v2 = fork();
if ( v2 < 0 )
{
v4 = "Talk Agent A: Failed to fork.";
LABEL_6:
printf((const char *)stderr, v4);
exit(-1);
}
if ( !v2 )
{
dup2(pipedes[0], 0);
close(pipedes[0]);
close(pipedes[1]);
sprintf(s, "%d", (unsigned int)*a1);
sprintf(v6, "%d", (unsigned int)a2[1]);
close(a1[1]);
close(*a2);
execlp("./talkagent", "./talkagent", s, v6, 0LL);
exit(-1);
}
close(pipedes[0]);
close(*a1);
close(a2[1]);
return (unsigned int)pipedes[1];
}

original_code:
int setupTalkAgentA(int pipefd1[], int pipefd2[])
{
    int pipefd[2];
    if (pipe(pipefd) == -1) {
        printf(stderr, "Talk Agent A: Failed to create pipe.");
        exit(-1);
    }
    int pid;
    pid = fork();
    if (pid < 0) {
        printf(stderr, "Talk Agent A: Failed to fork.");
        exit(-1);
    } else if (pid == 0) {
        dup2(pipefd[0], 0);
        close(pipefd[0]);
        close(pipefd[1]);
        char pipeFeed1[2];
        char pipeFeed2[2];
        sprintf(pipeFeed1, "%d", pipefd1[0]);
        sprintf(pipeFeed2, "%d", pipefd2[1]);
        close(pipefd1[1]);
        close(pipefd2[0]);
        execlp("./talkagent", "./talkagent", pipeFeed1, pipeFeed2, ((void *)0));
        exit(-1);
    } else {
        close(pipefd[0]);
        close(pipefd1[0]);
        close(pipefd2[1]);
        return(pipefd[1]);
    }
}


doPersonA

decompiled_code:
unsigned int __fastcall doPersonA(int fd)
{
unsigned int result; // eax
char **v2; // rbx
unsigned int v3; // eax

dup2(fd, 1);
close(fd);
result = sleep(1u);
if ( persAdialog[0] )
{
v2 = persAdialog;
do
{
++v2;
v3 = getpid();
printf("%s (%d)\n", *(v2 - 1), v3);
fflush(stdout);
result = sleep(2u);
}
while ( *v2 );
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func10(int fd)
{
unsigned int result; // eax
char **v2; // rbx
unsigned int v3; // eax

dup2(fd, 1);
close(fd);
result = sleep(1u);
if ( persAdialog[0] )
{
v2 = persAdialog;
do
{
++v2;
v3 = getpid();
printf("%s (%d)\n", *(v2 - 1), v3);
fflush(stdout);
result = sleep(2u);
}
while ( *v2 );
}
return result;
}

original_code:
void doPersonA(int persAwfd)
{
    dup2(persAwfd, 1);
    close(persAwfd);
    int i;
    sleep(1);
    for(i=0 ; persAdialog[i] != ((void *)0) ; i++)
    {
        printf("%s (%d)\n",persAdialog[i], getpid());
        fflush(stdout);
        sleep(2);
    }
}

variable_types: persAwfd int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax
const char *v6; // rsi
int v7; // [rsp+0h] [rbp-18h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

puts("Simulation starting");
v3 = doPersonB("Simulation starting", argv);
if ( pipe(&v7) == -1 )
{
v6 = "Talk Agent: Failed to create pipe 1.";
goto LABEL_5;
}
if ( pipe(pipedes) == -1 )
{
v6 = "Talk Agent: Failed to create pipe 2.";
LABEL_5:
printf((const char *)stderr, v6);
exit(-1);
}
setupTalkAgentB(v3);
v4 = setupTalkAgentA(&v7, pipedes);
doPersonA(v4);
fwrite("Simulation all done\n", 1uLL, 0x14uLL, stderr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax
const char *v6; // rsi
int v7; // [rsp+0h] [rbp-18h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

puts("Simulation starting");
v3 = func7("Simulation starting", argv);
if ( pipe(&v7) == -1 )
{
v6 = "Talk Agent: Failed to create pipe 1.";
goto LABEL_5;
}
if ( pipe(pipedes) == -1 )
{
v6 = "Talk Agent: Failed to create pipe 2.";
LABEL_5:
printf((const char *)stderr, v6);
exit(-1);
}
func8(v3);
v4 = func9(&v7, pipedes);
func10(v4);
fwrite("Simulation all done\n", 1uLL, 0x14uLL, stderr);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int persBrfd;
    int persAwfd;
    printf("Simulation starting\n");
    persBrfd = doPersonB();
    int pipefd1[2];
    int pipefd2[2];
    if (pipe(pipefd1) == -1) {
        printf(stderr, "Talk Agent: Failed to create pipe 1.");
        exit(-1);
    }
    if (pipe(pipefd2) == -1) {
        printf(stderr, "Talk Agent: Failed to create pipe 2.");
        exit(-1);
    }
    setupTalkAgentB(persBrfd, pipefd1, pipefd2);
    persAwfd = setupTalkAgentA(pipefd1, pipefd2);
    doPersonA(persAwfd);
    fprintf(stderr,"Simulation all done\n");
}

variable_types: argc int

variable_types:
argv
char *[]


talk

decompiled_code:
void __fastcall __noreturn talk(void *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
size_t v3; // rax
unsigned int v4; // eax
size_t v5; // rax
int v6[2050]; // [rsp+0h] [rbp-2008h] BYREF

while ( 1 )
{
v1 = read(*(_DWORD *)a1, v6, 0x2000uLL);
if ( v1 == -1 )
break;
if ( !v1 )
{
v4 = getpid();
sprintf((char *)v6, "Link severed (%d)\n", v4);
v5 = strlen((const char *)v6);
write(*((_DWORD *)a1 + 1), v6, v5);
LABEL_6:
close(*(_DWORD *)a1);
close(*((_DWORD *)a1 + 1));
pthread_exit(0LL);
}
if ( v6[0] == 1953069157 )
goto LABEL_6;
write(*((_DWORD *)a1 + 1), v6, v1);
}
v2 = getpid();
sprintf((char *)v6, "Fatal read error on %d (%d)\n", *(unsigned int *)a1, v2);
v3 = strlen((const char *)v6);
write(*((_DWORD *)a1 + 1), v6, v3);
perror((const char *)v6);
goto LABEL_6;
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
size_t v3; // rax
unsigned int v4; // eax
size_t v5; // rax
int v6[2050]; // [rsp+0h] [rbp-2008h] BYREF

while ( 1 )
{
v1 = read(*(_DWORD *)a1, v6, 0x2000uLL);
if ( v1 == -1 )
break;
if ( !v1 )
{
v4 = getpid();
sprintf((char *)v6, "Link severed (%d)\n", v4);
v5 = strlen((const char *)v6);
write(*((_DWORD *)a1 + 1), v6, v5);
LABEL_6:
close(*(_DWORD *)a1);
close(*((_DWORD *)a1 + 1));
pthread_exit(0LL);
}
if ( v6[0] == 1953069157 )
goto LABEL_6;
write(*((_DWORD *)a1 + 1), v6, v1);
}
v2 = getpid();
sprintf((char *)v6, "Fatal read error on %d (%d)\n", *(unsigned int *)a1, v2);
v3 = strlen((const char *)v6);
write(*((_DWORD *)a1 + 1), v6, v3);
perror((const char *)v6);
goto LABEL_6;
}

original_code:
void *talk(void *fdPtr)
{
    int *fds = (int *) fdPtr;
    int num;
    char buffer[8192];
    while(1)
    {
        num = read(fds[0],buffer,8192);
        if(num == -1)
        {
            sprintf(buffer,"Fatal read error on %d (%d)\n",fds[0],getpid());
            write(fds[1],buffer,strlen(buffer));
            perror(buffer);
            break;
        }
        else if(num == 0)
        {
            sprintf(buffer,"Link severed (%d)\n",getpid());
            write(fds[1],buffer,strlen(buffer));
            break;
        }
        else if(strncmp("exit",buffer,strlen("exit")) == 0)
        {
            break;
        }
        else write(fds[1],buffer,num);
    }
    close(fds[0]);
    close(fds[1]);
    pthread_exit(0);
}

variable_types:
fdPtr
void *

variable_types:
fds
int *

variable_types: num int

variable_types:
buffer
char [8192]

return_type: void *


createThreads

decompiled_code:
__int64 __fastcall createThreads(int *a1, const char *a2)
{
unsigned int v2; // eax
int v3; // eax
int v4; // eax
int v6[2]; // [rsp+0h] [rbp-28h] BYREF
int arg[2]; // [rsp+8h] [rbp-20h] BYREF
pthread_t newthread; // [rsp+10h] [rbp-18h] BYREF
pthread_t th[2]; // [rsp+18h] [rbp-10h] BYREF

v2 = getpid();
printf("Welcome to talk agent (%d)\n", v2);
v3 = a1[1];
v6[0] = 0;
v6[1] = v3;
v4 = *a1;
arg[1] = 1;
arg[0] = v4;
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))talk, v6)
|| pthread_create(th, 0LL, (void *(*)(void *))talk, arg) )
{
printf(stderr, "Failed to create thread.");
exit(-1);
}
if ( pthread_join(newthread, 0LL) )
{
printf(stderr, "pthread_join failed on thread ");
if ( !pthread_join(th[0], 0LL) )
return 0LL;
}
else if ( !pthread_join(th[0], 0LL) )
{
return 0LL;
}
printf(stderr, 4202665LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1, const char *a2)
{
unsigned int v2; // eax
int v3; // eax
int v4; // eax
int v6[2]; // [rsp+0h] [rbp-28h] BYREF
int arg[2]; // [rsp+8h] [rbp-20h] BYREF
pthread_t newthread; // [rsp+10h] [rbp-18h] BYREF
pthread_t th[2]; // [rsp+18h] [rbp-10h] BYREF

v2 = getpid();
printf("Welcome to talk agent (%d)\n", v2);
v3 = a1[1];
v6[0] = 0;
v6[1] = v3;
v4 = *a1;
arg[1] = 1;
arg[0] = v4;
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))talk, v6)
|| pthread_create(th, 0LL, (void *(*)(void *))talk, arg) )
{
printf(stderr, "Failed to create thread.");
exit(-1);
}
if ( pthread_join(newthread, 0LL) )
{
printf(stderr, "pthread_join failed on thread ");
if ( !pthread_join(th[0], 0LL) )
return 0LL;
}
else if ( !pthread_join(th[0], 0LL) )
{
return 0LL;
}
printf(stderr, 4202665LL);
return 0LL;
}

original_code:
int createThreads(int fds[])
{
    int retcd = 0;
    printf("Welcome to talk agent (%d)\n", getpid());
    pthread_t tid[2];
    int i;
    int fd1[2];
    int fd2[2];
    fd1[0] = 0;
    fd1[1] = fds[1];
    fd2[0] = fds[0];
    fd2[1] = 1;
    int thread1 = pthread_create(&tid[0], ((void *)0), talk, &fd1);
    if (thread1 != 0) {
        printf(stderr, "Failed to create thread.");
        exit(-1);
    }
    int thread2 = pthread_create(&tid[1], ((void *)0), talk, &fd2);
    if (thread2 != 0) {
        printf(stderr, "Failed to create thread.");
        exit(-1);
    }
    for (i = 0; i<2; i++) {
        if (pthread_join(tid[i], ((void *)0)) !=0) {
            printf(stderr, "pthread_join failed on thread " + i);
        }
    }
    return(retcd);
}

canonical_original_code:
int createThreads(int fds[])
{
    int retcd = 0;
    printf("Welcome to talk agent (%d)\n", getpid());
    unsigned long tid[2];
    int i;
    int fd1[2];
    int fd2[2];
    fd1[0] = 0;
    fd1[1] = fds[1];
    fd2[0] = fds[0];
    fd2[1] = 1;
    int thread1 = pthread_create(&tid[0], ((void *)0), talk, &fd1);
    if (thread1 != 0) {
        printf(stderr, "Failed to create thread.");
        exit(-1);
    }
    int thread2 = pthread_create(&tid[1], ((void *)0), talk, &fd2);
    if (thread2 != 0) {
        printf(stderr, "Failed to create thread.");
        exit(-1);
    }
    for (i = 0; i<2; i++) {
        if (pthread_join(tid[i], ((void *)0)) !=0) {
            printf(stderr, "pthread_join failed on thread " + i);
        }
    }
    return(retcd);
}

variable_types:
fds
int []

variable_types: retcd int

variable_types:
tid
unsigned long [2]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
unsigned int v4; // eax
__int64 v6; // rdx
char v7[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc == 3 )
{
LODWORD(v3) = __isoc99_sscanf();
if ( (_DWORD)v3 == 1 )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
v3 = (unsigned int)createThreads(v7, "%d", v6) != 0;
else
printf("Invalid <outfd> %s\n", argv[2]);
}
else
{
LODWORD(v3) = 1;
printf("Invalid <infd> %s\n", argv[1]);
}
}
else
{
LODWORD(v3) = 1;
puts("Usage: talkagent <infd> <outfd>");
}
v4 = getpid();
printf("All done! (%s)\n", (const char *)v4);
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
unsigned int v4; // eax
__int64 v6; // rdx
char v7[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc == 3 )
{
LODWORD(v3) = __isoc99_sscanf();
if ( (_DWORD)v3 == 1 )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
v3 = (unsigned int)func8(v7, "%d", v6) != 0;
else
printf("Invalid <outfd> %s\n", argv[2]);
}
else
{
LODWORD(v3) = 1;
printf("Invalid <infd> %s\n", argv[1]);
}
}
else
{
LODWORD(v3) = 1;
puts("Usage: talkagent <infd> <outfd>");
}
v4 = getpid();
printf("All done! (%s)\n", (const char *)v4);
return v3;
}

original_code:
int main(int argc, char *argv[])
{
    int fds[2];
    int retcd;
    if(argc != 3)
    {
        printf("Usage: talkagent <infd> <outfd>\n");
        retcd = 1;
    }
    else if(sscanf(argv[1],"%d",&fds[0]) != 1)
    {
        printf("Invalid <infd> %s\n",argv[1]);
        retcd = 1;
    }
    else if(sscanf(argv[2],"%d",&fds[1]) != 1)
    {
        printf("Invalid <outfd> %s\n",argv[2]);
        retcd = 1;
    }
    else
    {
        if(createThreads(fds) == 0) retcd = 0;
        else retcd = 1;
    }
    printf("All done! (%s)\n", getpid());
    return(retcd);
}

variable_types:
fds
int [2]


repo: colmmacc/nutrient

decompiled_code:
__int64 __fastcall ffa_get_size(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
uint64_t ffa_get_size(struct ffa *handle)
{
    return handle->size;
}

canonical_original_code:
unsigned long ffa_get_size(struct ffa *handle)
{
    return handle->size;
}

variable_types: struct ffa { int fd; unsigned long size; void *base; } *

return_type: unsigned long


decompiled_code:
int __fastcall ffa_truncate(__int64 a1, __off_t a2)
{
int result; // eax

result = ftruncate(*(_DWORD *)a1, a2);
if ( result >= 0 )
{
*(_QWORD *)(a1 + 8) = a2;
result = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __off_t a2)
{
int result; // eax

result = ftruncate(*(_DWORD *)a1, a2);
if ( result >= 0 )
{
*(_QWORD *)(a1 + 8) = a2;
result = 0;
}
return result;
}

original_code:
int ffa_truncate(struct ffa *handle, uint64_t size)
{
    int r = ftruncate(handle->fd, size);
    if (r < 0) {
        return r;
    }
    handle->size = size;
    return 0;
}

canonical_original_code:
int ffa_truncate(struct ffa *handle, unsigned long size)
{
    int r = ftruncate(handle->fd, size);
    if (r < 0) {
        return r;
    }
    handle->size = size;
    return 0;
}

variable_types:
size
unsigned long

variable_types: r int

user_defined_types: struct ffa { int fd; unsigned long size; void *base; }


decompiled_code:
__int64 __fastcall ffa_get_memory(__int64 a1, __int64 a2)
{
return a2 + *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return a2 + *(_QWORD *)(a1 + 16);
}

original_code:
void *ffa_get_memory(struct ffa *handle, uint64_t offset)
{
    return (void *) (((intptr_t) handle->base) + offset);
}

canonical_original_code:
void *ffa_get_memory(struct ffa *handle, unsigned long offset)
{
    return (void *) (((long) handle->base) + offset);
}

variable_types:
offset
unsigned long


decompiled_code:
__int64 ffa_free()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 0LL;
}

original_code:
uint64_t ffa_free(struct ffa * handle, uint64_t offset, size_t size)
{
    return 0;
}

canonical_original_code:
unsigned long ffa_free(struct ffa *handle, unsigned long offset, unsigned long size)
{
    return 0;
}


decompiled_code:
__int64 __fastcall ffa_alloc(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbx
int v4; // edi
size_t v5; // rsi
size_t v6; // rsi
void *v7; // rdi
int v8; // er8
void *v9; // rax

if ( a2 )
{
v2 = a2;
v4 = *(_DWORD *)a1;
if ( (a2 & 7) != 0 )
v2 = (a2 & 0xFFFFFFFFFFFFFFF8LL) + 8;
if ( lseek(v4, v2 - 1, 2) >= 0 && write(*(_DWORD *)a1, &unk_2A4, 1uLL) == 1 )
{
v5 = *(_QWORD *)(a1 + 8);
if ( !v5 )
goto LABEL_9;
if ( munmap(*(void **)(a1 + 16), v5) >= 0 )
{
v5 = *(_QWORD *)(a1 + 8);
LABEL_9:
v6 = v2 + v5;
v7 = *(void **)(a1 + 16);
v8 = *(_DWORD *)a1;
*(_QWORD *)(a1 + 8) = v6;
v9 = mmap(v7, v6, 3, 1, v8, 0LL);
*(_QWORD *)(a1 + 16) = v9;
if ( v9 != (void *)-1LL )
return *(_QWORD *)(a1 + 8) - v2;
return 0xFFFFFFFFLL;
}
}
return 0xFFFFFFFFLL;
}
*_errno_location() = 22;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbx
int v4; // edi
size_t v5; // rsi
size_t v6; // rsi
void *v7; // rdi
int v8; // er8
void *v9; // rax

if ( a2 )
{
v2 = a2;
v4 = *(_DWORD *)a1;
if ( (a2 & 7) != 0 )
v2 = (a2 & 0xFFFFFFFFFFFFFFF8LL) + 8;
if ( lseek(v4, v2 - 1, 2) >= 0 && write(*(_DWORD *)a1, &unk_2A4, 1uLL) == 1 )
{
v5 = *(_QWORD *)(a1 + 8);
if ( !v5 )
goto LABEL_9;
if ( munmap(*(void **)(a1 + 16), v5) >= 0 )
{
v5 = *(_QWORD *)(a1 + 8);
LABEL_9:
v6 = v2 + v5;
v7 = *(void **)(a1 + 16);
v8 = *(_DWORD *)a1;
*(_QWORD *)(a1 + 8) = v6;
v9 = mmap(v7, v6, 3, 1, v8, 0LL);
*(_QWORD *)(a1 + 16) = v9;
if ( v9 != (void *)-1LL )
return *(_QWORD *)(a1 + 8) - v2;
return 0xFFFFFFFFLL;
}
}
return 0xFFFFFFFFLL;
}
*_errno_location() = 22;
return 0xFFFFFFFFLL;
}

original_code:
uint64_t ffa_alloc(struct ffa * handle, size_t size)
{
    if (size <= 0) {
        (*__errno_location ()) = 22;
        return 0xFFFFFFFF;
    }
    if (size % (sizeof(void *))) {
        size += sizeof(void *) - (size % (sizeof(void *)));
    }
    if (lseek(handle->fd, size - 1, 2) < 0) {
        return 0xFFFFFFFF;
    }
    if (write(handle->fd, "\0", 1) != 1) {
        return 0xFFFFFFFF;
    }
    if (handle->size > 0 && munmap(handle->base, handle->size) < 0) {
        return 0xFFFFFFFF;
    }
    handle->size += size;
    handle->base =
        mmap(handle->base, handle->size, 0x1 | 0x2, 0x01,
             handle->fd, 0);
    if (handle->base == ((void *) -1)) {
        return 0xFFFFFFFF;
    }
    return handle->size - size;
}

canonical_original_code:
unsigned long ffa_alloc(struct ffa *handle, unsigned long size)
{
    if (size <= 0) {
        (*__errno_location ()) = 22;
        return 0xFFFFFFFF;
    }
    if (size % (sizeof(void *))) {
        size += sizeof(void *) - (size % (sizeof(void *)));
    }
    if (lseek(handle->fd, size - 1, 2) < 0) {
        return 0xFFFFFFFF;
    }
    if (write(handle->fd, "\0", 1) != 1) {
        return 0xFFFFFFFF;
    }
    if (handle->size > 0 && munmap(handle->base, handle->size) < 0) {
        return 0xFFFFFFFF;
    }
    handle->size += size;
    handle->base =
        mmap(handle->base, handle->size, 0x1 | 0x2, 0x01,
             handle->fd, 0);
    if (handle->base == ((void *) -1)) {
        return 0xFFFFFFFF;
    }
    return handle->size - size;
}


decompiled_code:
int __fastcall ffa_sync(__int64 a1)
{
return msync(*(void **)(a1 + 16), *(_QWORD *)(a1 + 8), 4);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
return msync(*(void **)(a1 + 16), *(_QWORD *)(a1 + 8), 4);
}

original_code:
int ffa_sync(struct ffa *handle)
{
    return msync(handle->base, handle->size, 4);
}


decompiled_code:
int __fastcall ffa_close(void *ptr)
{
int result; // eax

result = munmap(*((void **)ptr + 2), *((_QWORD *)ptr + 1));
if ( !result )
{
result = close(*(_DWORD *)ptr);
if ( !result )
{
free(ptr);
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(void *ptr)
{
int result; // eax

result = munmap(*((void **)ptr + 2), *((_QWORD *)ptr + 1));
if ( !result )
{
result = close(*(_DWORD *)ptr);
if ( !result )
{
free(ptr);
result = 0;
}
}
return result;
}

original_code:
int ffa_close(struct ffa *handle)
{
    int r;
    r = munmap(handle->base, handle->size);
    if (r != 0) {
        return r;
    }
    r = close(handle->fd);
    if (r != 0) {
        return r;
    }
    free(handle);
    return 0;
}


original_code:
static int cidr_pack(const uint8_t * ip, uint8_t bits, uint8_t * packed)
{
    int bit;
    for (bit = 0; bit < bits; bit++) {
         packed[bit] = !!(ip[bit / 8] & (1 << (7 - (bit % 8)))) + '0';
    }
    packed[bit] = 0;
    return 0;
}

canonical_original_code:
static int cidr_pack(unsigned char *ip, unsigned char bits, unsigned char *packed)
{
    int bit;
    for (bit = 0; bit < bits; bit++) {
         packed[bit] = !!(ip[bit / 8] & (1 << (7 - (bit % 8)))) + '0';
    }
    packed[bit] = 0;
    return 0;
}

variable_types:
ip
unsigned char *

variable_types:
bits
unsigned char

variable_types:
packed
unsigned char *

variable_types: bit int


original_code:
static int cidr_unpack(uint8_t * packed, uint8_t bits, uint8_t * ip, uint8_t size)
{
    int bit;
    memset(ip, 0, size);
    for (bit = 0; bit < bits; bit++) {
         if (packed[bit] == '1') {
             ip[bit / 8] |= (1 << (7 - bit % 8));
         }
    }
    return 0;
}

canonical_original_code:
static int cidr_unpack(unsigned char *packed, unsigned char bits, unsigned char *ip, unsigned char size)
{
    int bit;
    memset(ip, 0, size);
    for (bit = 0; bit < bits; bit++) {
         if (packed[bit] == '1') {
             ip[bit / 8] |= (1 << (7 - bit % 8));
         }
    }
    return 0;
}

variable_types:
size
unsigned char


decompiled_code:
__int64 __fastcall ipv4_cidr_pack(__int64 a1, unsigned __int8 a2, _BYTE *a3)
{
__int64 result; // rax

if ( a2 > 0x20u )
result = 0xFFFFFFFFLL;
else
result = cidr_pack(a1, a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int8 a2, _BYTE *a3)
{
__int64 result; // rax

if ( a2 > 0x20u )
result = 0xFFFFFFFFLL;
else
result = func0(a1, a2, a3);
return result;
}

original_code:
int ipv4_cidr_pack(uint8_t * ip, uint8_t bits, uint8_t * packed)
{
    if (bits > 32) {
         return -1;
    }
    return cidr_pack(ip, bits, packed);
}

canonical_original_code:
int ipv4_cidr_pack(unsigned char *ip, unsigned char bits, unsigned char *packed)
{
    if (bits > 32) {
         return -1;
    }
    return cidr_pack(ip, bits, packed);
}


decompiled_code:
__int64 __fastcall ipv6_cidr_pack(__int64 a1, unsigned __int8 a2, _BYTE *a3)
{
__int64 result; // rax

if ( a2 > 0x80u )
result = 0xFFFFFFFFLL;
else
result = cidr_pack(a1, a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int8 a2, _BYTE *a3)
{
__int64 result; // rax

if ( a2 > 0x80u )
result = 0xFFFFFFFFLL;
else
result = func0(a1, a2, a3);
return result;
}

original_code:
int ipv6_cidr_pack(uint8_t * ip, uint8_t bits, uint8_t * packed)
{
    if (bits > 128) {
         return -1;
    }
    return cidr_pack(ip, bits, packed);
}

canonical_original_code:
int ipv6_cidr_pack(unsigned char *ip, unsigned char bits, unsigned char *packed)
{
    if (bits > 128) {
         return -1;
    }
    return cidr_pack(ip, bits, packed);
}


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

if ( a2 > 0x20u )
result = 0xFFFFFFFFLL;
else
result = cidr_unpack(a1, a2, a3, 4LL);
return result;
}

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

if ( a2 > 0x20u )
result = 0xFFFFFFFFLL;
else
result = func1(a1, a2, a3, 4LL);
return result;
}

original_code:
int ipv4_cidr_unpack(uint8_t * packed, uint8_t bits, uint8_t * ip)
{
    if (bits > 32) {
             return -1;
    }
    return cidr_unpack(packed, bits, ip, 4);
}

canonical_original_code:
int ipv4_cidr_unpack(unsigned char *packed, unsigned char bits, unsigned char *ip)
{
    if (bits > 32) {
             return -1;
    }
    return cidr_unpack(packed, bits, ip, 4);
}


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

if ( a2 > 0x80u )
result = 0xFFFFFFFFLL;
else
result = cidr_unpack(a1, a2, a3, 16LL);
return result;
}

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

if ( a2 > 0x80u )
result = 0xFFFFFFFFLL;
else
result = func1(a1, a2, a3, 16LL);
return result;
}

original_code:
int ipv6_cidr_unpack(uint8_t * packed, uint8_t bits, uint8_t * ip)
{
    if (bits > 128) {
         return -1;
    }
    return cidr_unpack(packed, bits, ip, 16);
}

canonical_original_code:
int ipv6_cidr_unpack(unsigned char *packed, unsigned char bits, unsigned char *ip)
{
    if (bits > 128) {
         return -1;
    }
    return cidr_unpack(packed, bits, ip, 16);
}


decompiled_code:
__int64 __fastcall code_word_op(char a1)
{
return a1 & 0x1F;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return a1 & 0x1F;
}

original_code:
unsigned short code_word_op(unsigned short word){
  return word & 0x1f;
}

variable_types:
word
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall code_word_special_op(unsigned __int16 a1)
{
return (a1 >> 5) & 0x1F;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1)
{
return (a1 >> 5) & 0x1F;
}

original_code:
unsigned short code_word_special_op(unsigned short word){
 return (word >> 5) & 0x1f;
}


decompiled_code:
__int64 __fastcall mem_get(unsigned __int16 a1)
{
return (unsigned __int16)ram[a1];
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 a1)
{
return (unsigned __int16)ram[a1];
}

original_code:
unsigned short mem_get(unsigned short loc){
  return ram[loc];
}

variable_types:
loc
unsigned short


decompiled_code:
__int64 peek_next_word()
{
return mem_get(PC);
}

canonical_decompiled_code:
__int64 func3()
{
return func2(PC);
}

original_code:
unsigned short peek_next_word(){
 return mem_get(PC);
}


decompiled_code:
__int64 get_next_word()
{
unsigned __int16 v0; // di

v0 = PC++;
return mem_get(v0);
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int16 v0; // di

v0 = PC++;
return func2(v0);
}

original_code:
unsigned short get_next_word(){
  return mem_get(PC++);
}


decompiled_code:
__int64 __fastcall code_word_value(__int64 a1, __int64 a2, __int64 a3, __int16 a4)
{
__int16 v4; // dx
int v5; // eax
__int64 v7; // [rsp+14h] [rbp-14h]

v4 = a1;
v5 = 0;
if ( (unsigned __int16)a1 > 7u )
{
if ( (unsigned __int16)a1 > 0xFu )
{
if ( (unsigned __int16)a1 <= 0x17u )
{
a4 = get_next_word(a1, a2, a1 & 7);
v5 = 3;
}
else
{
switch ( (__int16)a1 )
{
case 24:
v5 = 4;
break;
case 25:
v5 = 5;
break;
case 26:
a4 = get_next_word(a1, a2, (unsigned int)a1);
v5 = 6;
break;
case 27:
v5 = 8;
break;
case 28:
v5 = 9;
break;
case 29:
v5 = 10;
break;
case 30:
a4 = get_next_word(a1, a2, (unsigned int)a1);
v5 = 1;
break;
case 31:
get_next_word(a1, a2, (unsigned int)a1);
v5 = 7;
break;
default:
if ( (_WORD)a2 || (unsigned __int16)a1 <= 0x1Fu )
v5 = 0;
else
v5 = 7;
break;
}
}
}
else
{
v4 = a1 & 7;
v5 = 2;
}
}
HIWORD(v7) = v4;
LODWORD(v7) = v5;
WORD2(v7) = a4;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int16 a4)
{
__int16 v4; // dx
int v5; // eax
__int64 v7; // [rsp+14h] [rbp-14h]

v4 = a1;
v5 = 0;
if ( (unsigned __int16)a1 > 7u )
{
if ( (unsigned __int16)a1 > 0xFu )
{
if ( (unsigned __int16)a1 <= 0x17u )
{
a4 = func4(a1, a2, a1 & 7);
v5 = 3;
}
else
{
switch ( (__int16)a1 )
{
case 24:
v5 = 4;
break;
case 25:
v5 = 5;
break;
case 26:
a4 = func4(a1, a2, (unsigned int)a1);
v5 = 6;
break;
case 27:
v5 = 8;
break;
case 28:
v5 = 9;
break;
case 29:
v5 = 10;
break;
case 30:
a4 = func4(a1, a2, (unsigned int)a1);
v5 = 1;
break;
case 31:
func4(a1, a2, (unsigned int)a1);
v5 = 7;
break;
default:
if ( (_WORD)a2 || (unsigned __int16)a1 <= 0x1Fu )
v5 = 0;
else
v5 = 7;
break;
}
}
}
else
{
v4 = a1 & 7;
v5 = 2;
}
}
HIWORD(v7) = v4;
LODWORD(v7) = v5;
WORD2(v7) = a4;
return v7;
}

original_code:
vm_loc code_word_value(unsigned short raw_val, const short b_val){
 vm_loc ret;
 if(raw_val <= 0x07){
  ret.type = LOC_REGISTER;
  ret.reg = raw_val;
 }else if(raw_val <= 0x0f){
  ret.type = LOC_REGISTER_MEMORY;
  ret.reg = raw_val % 0x08;
 } else if(raw_val <= 0x17){
  ret.type = LOC_REGISTER_MEMORY_OFFSET;
  ret.reg = raw_val % 0x08;
  ret.loc = get_next_word();
 }
 switch(raw_val){
 case 0x18:
  ret.type = LOC_PUSHPOP;
  break;
 case 0x19:
  ret.type = LOC_PEEK;
  break;
 case 0x1a:
  ret.type = LOC_PICK;
  ret.loc = get_next_word();
  break;
 case 0x1b:
  ret.type = LOC_SP;
  break;
 case 0x1c:
  ret.type = LOC_PC;
  break;
 case 0x1d:
  ret.type = LOC_EX;
  break;
 case 0x1e:
  ret.type = LOC_MEMORY;
  ret.loc = get_next_word();
  break;
 case 0x1f:
  ret.type = LOC_LITERAL;
  ret.val = get_next_word();
 }
 if(!b_val && raw_val >= 0x20){
  ret.type = LOC_LITERAL;
  ret.val = raw_val - 0x20;
 }
 return ret;
}

canonical_original_code:
struct vm_loc_t code_word_value(unsigned short raw_val, short b_val){
 struct vm_loc_t ret;
 if(raw_val <= 0x07){
  ret.type = LOC_REGISTER;
  ret.reg = raw_val;
 }else if(raw_val <= 0x0f){
  ret.type = LOC_REGISTER_MEMORY;
  ret.reg = raw_val % 0x08;
 } else if(raw_val <= 0x17){
  ret.type = LOC_REGISTER_MEMORY_OFFSET;
  ret.reg = raw_val % 0x08;
  ret.loc = get_next_word();
 }
 switch(raw_val){
 case 0x18:
  ret.type = LOC_PUSHPOP;
  break;
 case 0x19:
  ret.type = LOC_PEEK;
  break;
 case 0x1a:
  ret.type = LOC_PICK;
  ret.loc = get_next_word();
  break;
 case 0x1b:
  ret.type = LOC_SP;
  break;
 case 0x1c:
  ret.type = LOC_PC;
  break;
 case 0x1d:
  ret.type = LOC_EX;
  break;
 case 0x1e:
  ret.type = LOC_MEMORY;
  ret.loc = get_next_word();
  break;
 case 0x1f:
  ret.type = LOC_LITERAL;
  ret.val = get_next_word();
 }
 if(!b_val && raw_val >= 0x20){
  ret.type = LOC_LITERAL;
  ret.val = raw_val - 0x20;
 }
 return ret;
}

variable_types: struct vm_loc_t { enum vm_loc_type { LOC_REGISTER=0, LOC_MEMORY=1, LOC_REGISTER_MEMORY=2, LOC_REGISTER_MEMORY_OFFSET=3, LOC_PUSHPOP=4, LOC_PEEK=5, LOC_PICK=6, LOC_LITERAL=7, LOC_SP=8, LOC_PC=9, LOC_EX=10, LOC_LABEL=11, LOC_LABEL_MEM=12, LOC_IA=13 } type; unsigned short loc; unsigned short reg; unsigned short val; }

user_defined_types: struct vm_loc_t { enum vm_loc_type type; unsigned short loc; unsigned short reg; unsigned short val; }


decompiled_code:
__int64 __fastcall code_word_a(unsigned __int16 a1, __int64 a2, __int64 a3, __int16 a4)
{
return code_word_value(a1 >> 10, 0LL, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int16 a1, __int64 a2, __int64 a3, __int16 a4)
{
return func5(a1 >> 10, 0LL, a3, a4);
}

original_code:
vm_loc code_word_a(unsigned short word){
  short raw_a = word >> 10;
  return code_word_value(raw_a, 0);
}

canonical_original_code:
struct vm_loc_t code_word_a(unsigned short word){
  short raw_a = word >> 10;
  return code_word_value(raw_a, 0);
}

return_type: struct vm_loc_t { enum vm_loc_type { LOC_REGISTER=0, LOC_MEMORY=1, LOC_REGISTER_MEMORY=2, LOC_REGISTER_MEMORY_OFFSET=3, LOC_PUSHPOP=4, LOC_PEEK=5, LOC_PICK=6, LOC_LITERAL=7, LOC_SP=8, LOC_PC=9, LOC_EX=10, LOC_LABEL=11, LOC_LABEL_MEM=12, LOC_IA=13 } type; unsigned short loc; unsigned short reg; unsigned short val; }


decompiled_code:
__int64 __fastcall code_word_b(unsigned __int16 a1, __int64 a2, __int64 a3, __int16 a4)
{
return code_word_value((a1 >> 5) & 0x1F, 1LL, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int16 a1, __int64 a2, __int64 a3, __int16 a4)
{
return func5((a1 >> 5) & 0x1F, 1LL, a3, a4);
}

original_code:
vm_loc code_word_b(unsigned short word){
  short raw_b = (word >> 5) & 0x1f;
  return code_word_value(raw_b, 1);
}

canonical_original_code:
struct vm_loc_t code_word_b(unsigned short word){
  short raw_b = (word >> 5) & 0x1f;
  return code_word_value(raw_b, 1);
}

user_defined_types: enum vm_loc_type { LOC_REGISTER=0, LOC_MEMORY=1, LOC_REGISTER_MEMORY=2, LOC_REGISTER_MEMORY_OFFSET=3, LOC_PUSHPOP=4, LOC_PEEK=5, LOC_PICK=6, LOC_LITERAL=7, LOC_SP=8, LOC_PC=9, LOC_EX=10, LOC_LABEL=11, LOC_LABEL_MEM=12, LOC_IA=13 }


decompiled_code:
__int64 __fastcall get_value(__int64 a1)
{
__int64 result; // rax
unsigned __int16 v2; // di

if ( !a1 )
return 0LL;
switch ( *(_DWORD *)a1 )
{
case 0:
result = (unsigned __int16)registers[*(unsigned __int16 *)(a1 + 6)];
break;
case 1:
result = mem_get(*(_WORD *)(a1 + 4));
break;
case 2:
result = mem_get(registers[*(unsigned __int16 *)(a1 + 6)]);
break;
case 3:
result = mem_get(registers[*(unsigned __int16 *)(a1 + 6)] + *(_WORD *)(a1 + 4));
break;
case 4:
v2 = word_6C6++;
result = mem_get(v2);
break;
case 5:
result = mem_get(word_6C6);
break;
case 6:
result = mem_get(*(_WORD *)(a1 + 6) + word_6C6);
break;
case 7:
result = *(unsigned __int16 *)(a1 + 8);
break;
case 8:
result = (unsigned __int16)word_6C6;
break;
case 9:
result = (unsigned __int16)PC;
break;
case 0xA:
result = (unsigned __int16)EX;
break;
case 0xD:
result = (unsigned __int16)IA;
break;
default:
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
unsigned __int16 v2; // di

if ( !a1 )
return 0LL;
switch ( *(_DWORD *)a1 )
{
case 0:
result = (unsigned __int16)registers[*(unsigned __int16 *)(a1 + 6)];
break;
case 1:
result = func2(*(_WORD *)(a1 + 4));
break;
case 2:
result = func2(registers[*(unsigned __int16 *)(a1 + 6)]);
break;
case 3:
result = func2(registers[*(unsigned __int16 *)(a1 + 6)] + *(_WORD *)(a1 + 4));
break;
case 4:
v2 = word_6C6++;
result = func2(v2);
break;
case 5:
result = func2(word_6C6);
break;
case 6:
result = func2(*(_WORD *)(a1 + 6) + word_6C6);
break;
case 7:
result = *(unsigned __int16 *)(a1 + 8);
break;
case 8:
result = (unsigned __int16)word_6C6;
break;
case 9:
result = (unsigned __int16)PC;
break;
case 0xA:
result = (unsigned __int16)EX;
break;
case 0xD:
result = (unsigned __int16)IA;
break;
default:
return 0LL;
}
return result;
}

original_code:
unsigned short get_value(const vm_loc *loc){
 if(loc == 0){
  return 0;
 }
 switch(loc->type){
 case LOC_REGISTER:
  return registers[loc->reg];
  break;
 case LOC_MEMORY:
  return mem_get(loc->loc);
  break;
 case LOC_REGISTER_MEMORY:
  return mem_get(registers[loc->reg]);
  break;
 case LOC_REGISTER_MEMORY_OFFSET:
  return mem_get(registers[loc->reg] + loc->loc);
  break;
 case LOC_LITERAL:
  return loc->val;
  break;
 case LOC_SP:
  return SP;
  break;
 case LOC_PC:
  return PC;
  break;
 case LOC_EX:
  return EX;
  break;
 case LOC_IA:
  return IA;
  break;
 case LOC_PUSHPOP:
  return mem_get(SP++);
  break;
 case LOC_PICK:
  return mem_get(loc->reg + SP);
  break;
 case LOC_PEEK:
  return mem_get(SP);
  break;
 case LOC_LABEL:
 case LOC_LABEL_MEM:
  break;
 }
 return 0;
}

canonical_original_code:
unsigned short get_value(struct vm_loc_t *loc){
 if(loc == 0){
  return 0;
 }
 switch(loc->type){
 case LOC_REGISTER:
  return registers[loc->reg];
  break;
 case LOC_MEMORY:
  return mem_get(loc->loc);
  break;
 case LOC_REGISTER_MEMORY:
  return mem_get(registers[loc->reg]);
  break;
 case LOC_REGISTER_MEMORY_OFFSET:
  return mem_get(registers[loc->reg] + loc->loc);
  break;
 case LOC_LITERAL:
  return loc->val;
  break;
 case LOC_SP:
  return SP;
  break;
 case LOC_PC:
  return PC;
  break;
 case LOC_EX:
  return EX;
  break;
 case LOC_IA:
  return IA;
  break;
 case LOC_PUSHPOP:
  return mem_get(SP++);
  break;
 case LOC_PICK:
  return mem_get(loc->reg + SP);
  break;
 case LOC_PEEK:
  return mem_get(SP);
  break;
 case LOC_LABEL:
 case LOC_LABEL_MEM:
  break;
 }
 return 0;
}

variable_types: struct vm_loc_t { enum vm_loc_type { LOC_REGISTER=0, LOC_MEMORY=1, LOC_REGISTER_MEMORY=2, LOC_REGISTER_MEMORY_OFFSET=3, LOC_PUSHPOP=4, LOC_PEEK=5, LOC_PICK=6, LOC_LITERAL=7, LOC_SP=8, LOC_PC=9, LOC_EX=10, LOC_LABEL=11, LOC_LABEL_MEM=12, LOC_IA=13 } type; unsigned short loc; unsigned short reg; unsigned short val; } *


decompiled_code:
void __fastcall mem_set(unsigned __int16 a1, __int16 a2)
{
ram[a1] = a2;
}

canonical_decompiled_code:
void __fastcall func9(unsigned __int16 a1, __int16 a2)
{
ram[a1] = a2;
}

original_code:
void mem_set(unsigned short loc, unsigned short val){
  ram[loc] = val;
}

variable_types:
val
unsigned short


decompiled_code:
void __fastcall set_value(__int64 a1, __int16 a2)
{
if ( a1 )
{
switch ( *(_DWORD *)a1 )
{
case 0:
registers[*(unsigned __int16 *)(a1 + 6)] = a2;
break;
case 1:
mem_set(*(_WORD *)(a1 + 4), a2);
break;
case 2:
mem_set(registers[*(unsigned __int16 *)(a1 + 6)], a2);
break;
case 3:
mem_set(registers[*(unsigned __int16 *)(a1 + 6)] + *(_WORD *)(a1 + 4), a2);
break;
case 4:
mem_set(--word_6C6, a2);
break;
case 5:
mem_set(word_6C6, a2);
break;
case 6:
mem_set(*(_WORD *)(a1 + 4) + word_6C6, a2);
break;
case 8:
word_6C6 = a2;
break;
case 9:
PC = a2;
break;
case 0xA:
EX = a2;
break;
case 0xD:
IA = a2;
break;
default:
return;
}
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, __int16 a2)
{
if ( a1 )
{
switch ( *(_DWORD *)a1 )
{
case 0:
registers[*(unsigned __int16 *)(a1 + 6)] = a2;
break;
case 1:
func9(*(_WORD *)(a1 + 4), a2);
break;
case 2:
func9(registers[*(unsigned __int16 *)(a1 + 6)], a2);
break;
case 3:
func9(registers[*(unsigned __int16 *)(a1 + 6)] + *(_WORD *)(a1 + 4), a2);
break;
case 4:
func9(--word_6C6, a2);
break;
case 5:
func9(word_6C6, a2);
break;
case 6:
func9(*(_WORD *)(a1 + 4) + word_6C6, a2);
break;
case 8:
word_6C6 = a2;
break;
case 9:
PC = a2;
break;
case 0xA:
EX = a2;
break;
case 0xD:
IA = a2;
break;
default:
return;
}
}
}

original_code:
void set_value(const vm_loc *loc, const unsigned short val){
 if(loc == 0){
  return;
 }
 switch(loc->type){
 case LOC_REGISTER:
  registers[loc->reg] = val;
  break;
 case LOC_MEMORY:
  mem_set(loc->loc, val);
  break;
 case LOC_REGISTER_MEMORY:
  mem_set(registers[loc->reg], val);
  break;
 case LOC_REGISTER_MEMORY_OFFSET:
  mem_set(registers[loc->reg] + loc->loc, val);
  break;
 case LOC_SP:
  SP = val;
  break;
 case LOC_EX:
  EX = val;
  break;
 case LOC_PC:
  PC = val;
  break;
 case LOC_IA:
  IA = val;
  break;
 case LOC_PUSHPOP:
  mem_set(--SP, val);
  break;
 case LOC_PEEK:
  mem_set(SP, val);
  break;
 case LOC_PICK:
  mem_set(SP + loc->loc, val);
  break;
 case LOC_LITERAL:
 case LOC_LABEL:
 case LOC_LABEL_MEM:
  break;
 }
}

canonical_original_code:
void set_value(struct vm_loc_t *loc, unsigned short val){
 if(loc == 0){
  return;
 }
 switch(loc->type){
 case LOC_REGISTER:
  registers[loc->reg] = val;
  break;
 case LOC_MEMORY:
  mem_set(loc->loc, val);
  break;
 case LOC_REGISTER_MEMORY:
  mem_set(registers[loc->reg], val);
  break;
 case LOC_REGISTER_MEMORY_OFFSET:
  mem_set(registers[loc->reg] + loc->loc, val);
  break;
 case LOC_SP:
  SP = val;
  break;
 case LOC_EX:
  EX = val;
  break;
 case LOC_PC:
  PC = val;
  break;
 case LOC_IA:
  IA = val;
  break;
 case LOC_PUSHPOP:
  mem_set(--SP, val);
  break;
 case LOC_PEEK:
  mem_set(SP, val);
  break;
 case LOC_PICK:
  mem_set(SP + loc->loc, val);
  break;
 case LOC_LITERAL:
 case LOC_LABEL:
 case LOC_LABEL_MEM:
  break;
 }
}


decompiled_code:
__int64 __fastcall write_code(unsigned __int16 a1, __int64 a2, unsigned __int16 a3)
{
__int64 result; // rax
__int64 v4; // rdi

result = 0LL;
v4 = a1;
if ( a3 )
{
do
{
ram[result + v4] = *(_WORD *)(a2 + 2 * result);
++result;
}
while ( a3 > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int16 a1, __int64 a2, unsigned __int16 a3)
{
__int64 result; // rax
__int64 v4; // rdi

result = 0LL;
v4 = a1;
if ( a3 )
{
do
{
ram[result + v4] = *(_WORD *)(a2 + 2 * result);
++result;
}
while ( a3 > (int)result );
}
return result;
}

original_code:
void write_code(const unsigned short loc, const unsigned short *code, const unsigned short len){
 for(int i = 0; i < len; i++){
  ram[loc + i] = code[i];
 }
}

canonical_original_code:
void write_code(unsigned short loc, unsigned short *code, unsigned short len){
 for(int i = 0; i < len; i++){
  ram[loc + i] = code[i];
 }
}

variable_types:
code
unsigned short *

variable_types:
len
unsigned short

variable_types: i int


original_code:
void init_vm(){
  memset(ram, 0, sizeof(short) * 0x10000);
  PC = 0;
  SP = 0xFFFF;
  EX = 0;
  IA = 0;
  unsigned short test_code[] = {
        0x7c01, 0x0030,
    0x7fc1, 0x0020, 0x1000,
    0x7803, 0x1000,
    0xc013,
    0x7f80, 0x0020
  };
 write_code(0, test_code, sizeof(test_code));
}


decompiled_code:
__int64 __fastcall vm_skip(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int16 v3; // di
__int64 v4; // rdx
__int16 v5; // cx
__int64 v7; // rdx
__int16 v8; // cx
unsigned __int16 v9; // r9

puts("SKIP");
v3 = get_next_word("SKIP", a2, v2);
if ( !(unsigned __int16)code_word_op(v3) )
return code_word_a(v3, a2, v4, v5);
code_word_a(v3, a2, v4, v5);
return code_word_b(v9, a2, v7, v8);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int16 v3; // di
__int64 v4; // rdx
__int16 v5; // cx
__int64 v7; // rdx
__int16 v8; // cx
unsigned __int16 v9; // r9

puts("SKIP");
v3 = func4("SKIP", a2, v2);
if ( !(unsigned __int16)func0(v3) )
return func6(v3, a2, v4, v5);
func6(v3, a2, v4, v5);
return func7(v9, a2, v7, v8);
}

original_code:
void vm_skip(){
 printf("SKIP\n");
 unsigned short word = get_next_word();
 unsigned short op = code_word_op(word);
 if(op == 0x00){
    code_word_a(word);
 }else{
  code_word_a(word);
  code_word_b(word);
 }
}

variable_types:
op
unsigned short


decompiled_code:
int __fastcall run_special_op(unsigned __int16 a1)
{
int result; // eax

result = code_word_special_op(a1);
if ( (_WORD)result != 1 )
result = puts("Unsupported special op");
return result;
}

canonical_decompiled_code:
int __fastcall func14(unsigned __int16 a1)
{
int result; // eax

result = func1(a1);
if ( (_WORD)result != 1 )
result = puts("Unsupported special op");
return result;
}

original_code:
void run_special_op(const unsigned short word){
 switch(code_word_special_op(word)){
 case 0x01:
  break;
 default:
  printf("Unsupported special op\n");
 }
}

canonical_original_code:
void run_special_op(unsigned short word){
 switch(code_word_special_op(word)){
 case 0x01:
  break;
 default:
  printf("Unsupported special op\n");
 }
}


original_code:
void run_op(const unsigned short word){
 unsigned short op = code_word_op(word);
 if(op == 0x00){
  run_special_op(word);
 }
 vm_loc a = code_word_a(word);
 vm_loc b = code_word_b(word);
 switch(op){
 case 0x01:
  printf("OP_SET\n");
  set_value(&b, get_value(&a));
  break;
 case 0x02:
  printf("OP_ADD\n");
  set_value(&b, get_value(&b) + get_value(&a));
  break;
 case 0x03:
  printf("OP_SUB\n");
  set_value(&b, get_value(&b) - get_value(&a));
  break;
 case 0x13:
  printf("OP_IFN\n");
  printf("A: 0x%04X -- B: 0x%04X\n", get_value(&a), get_value(&b));
  if(get_value(&a) == get_value(&b)){
   vm_skip();
  }
  break;
 }
}

canonical_original_code:
void run_op(unsigned short word){
 unsigned short op = code_word_op(word);
 if(op == 0x00){
  run_special_op(word);
 }
 struct vm_loc_t a = code_word_a(word);
 struct vm_loc_t b = code_word_b(word);
 switch(op){
 case 0x01:
  printf("OP_SET\n");
  set_value(&b, get_value(&a));
  break;
 case 0x02:
  printf("OP_ADD\n");
  set_value(&b, get_value(&b) + get_value(&a));
  break;
 case 0x03:
  printf("OP_SUB\n");
  set_value(&b, get_value(&b) - get_value(&a));
  break;
 case 0x13:
  printf("OP_IFN\n");
  printf("A: 0x%04X -- B: 0x%04X\n", get_value(&a), get_value(&b));
  if(get_value(&a) == get_value(&b)){
   vm_skip();
  }
  break;
 }
}


decompiled_code:
void __fastcall vm_step(__int64 a1, __int64 a2, __int64 a3)
{
__int16 v3; // ax

v3 = get_next_word(a1, a2, a3);
run_op(v3, a2);
}

original_code:
void vm_step(){
 unsigned short word = get_next_word();
 run_op(word);
}


original_code:
void init_encoder(){
 op_convert_table = calloc(sizeof(op_convert_entry), 0x20);
 special_op_convert_table = calloc(sizeof(op_convert_entry), 0x20);
 int len = 0;
 char *buf = 0;
 op_convert_entry *cur_op = op_convert_table;
 len = strlen(("SET")); buf = calloc(sizeof(char), len); strncpy(buf, (("SET")), len); cur_op->name = buf; cur_op->code = (0x01); cur_op++;
 len = strlen(("ADD")); buf = calloc(sizeof(char), len); strncpy(buf, (("ADD")), len); cur_op->name = buf; cur_op->code = (0x02); cur_op++;
 len = strlen(("SUB")); buf = calloc(sizeof(char), len); strncpy(buf, (("SUB")), len); cur_op->name = buf; cur_op->code = (0x03); cur_op++;
 len = strlen(("MUL")); buf = calloc(sizeof(char), len); strncpy(buf, (("MUL")), len); cur_op->name = buf; cur_op->code = (0x04); cur_op++;
 len = strlen(("MLI")); buf = calloc(sizeof(char), len); strncpy(buf, (("MLI")), len); cur_op->name = buf; cur_op->code = (0x05); cur_op++;
 len = strlen(("DIV")); buf = calloc(sizeof(char), len); strncpy(buf, (("DIV")), len); cur_op->name = buf; cur_op->code = (0x06); cur_op++;
 len = strlen(("DVI")); buf = calloc(sizeof(char), len); strncpy(buf, (("DVI")), len); cur_op->name = buf; cur_op->code = (0x07); cur_op++;
  len = strlen(("MOD")); buf = calloc(sizeof(char), len); strncpy(buf, (("MOD")), len); cur_op->name = buf; cur_op->code = (0x08); cur_op++;
  len = strlen(("MDI")); buf = calloc(sizeof(char), len); strncpy(buf, (("MDI")), len); cur_op->name = buf; cur_op->code = (0x09); cur_op++;
  len = strlen(("AND")); buf = calloc(sizeof(char), len); strncpy(buf, (("AND")), len); cur_op->name = buf; cur_op->code = (0x0a); cur_op++;
  len = strlen(("BOR")); buf = calloc(sizeof(char), len); strncpy(buf, (("BOR")), len); cur_op->name = buf; cur_op->code = (0x0b); cur_op++;
  len = strlen(("XOR")); buf = calloc(sizeof(char), len); strncpy(buf, (("XOR")), len); cur_op->name = buf; cur_op->code = (0x0c); cur_op++;
  len = strlen(("SHR")); buf = calloc(sizeof(char), len); strncpy(buf, (("SHR")), len); cur_op->name = buf; cur_op->code = (0x0d); cur_op++;
  len = strlen(("ASR")); buf = calloc(sizeof(char), len); strncpy(buf, (("ASR")), len); cur_op->name = buf; cur_op->code = (0x0e); cur_op++;
  len = strlen(("SHL")); buf = calloc(sizeof(char), len); strncpy(buf, (("SHL")), len); cur_op->name = buf; cur_op->code = (0x0f); cur_op++;
  len = strlen(("IFB")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFB")), len); cur_op->name = buf; cur_op->code = (0x10); cur_op++;
  len = strlen(("IFC")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFC")), len); cur_op->name = buf; cur_op->code = (0x11); cur_op++;
  len = strlen(("IFE")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFE")), len); cur_op->name = buf; cur_op->code = (0x12); cur_op++;
  len = strlen(("IFN")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFN")), len); cur_op->name = buf; cur_op->code = (0x13); cur_op++;
  len = strlen(("IFG")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFG")), len); cur_op->name = buf; cur_op->code = (0x14); cur_op++;
  len = strlen(("IFA")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFA")), len); cur_op->name = buf; cur_op->code = (0x15); cur_op++;
  len = strlen(("IFL")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFL")), len); cur_op->name = buf; cur_op->code = (0x16); cur_op++;
  len = strlen(("IFU")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFU")), len); cur_op->name = buf; cur_op->code = (0x17); cur_op++;
  len = strlen(("ADX")); buf = calloc(sizeof(char), len); strncpy(buf, (("ADX")), len); cur_op->name = buf; cur_op->code = (0x1a); cur_op++;
  len = strlen(("SBX")); buf = calloc(sizeof(char), len); strncpy(buf, (("SBX")), len); cur_op->name = buf; cur_op->code = (0x1b); cur_op++;
  len = strlen(("STI")); buf = calloc(sizeof(char), len); strncpy(buf, (("STI")), len); cur_op->name = buf; cur_op->code = (0x1e); cur_op++;
  len = strlen(("STD")); buf = calloc(sizeof(char), len); strncpy(buf, (("STD")), len); cur_op->name = buf; cur_op->code = (0x1f); cur_op++;
 cur_op = special_op_convert_table;
  len = strlen(("JSR")); buf = calloc(sizeof(char), len); strncpy(buf, (("JSR")), len); cur_op->name = buf; cur_op->code = (0x01); cur_op++;
  len = strlen(("INT")); buf = calloc(sizeof(char), len); strncpy(buf, (("INT")), len); cur_op->name = buf; cur_op->code = (0x08); cur_op++;
  len = strlen(("IAG")); buf = calloc(sizeof(char), len); strncpy(buf, (("IAG")), len); cur_op->name = buf; cur_op->code = (0x09); cur_op++;
  len = strlen(("IAS")); buf = calloc(sizeof(char), len); strncpy(buf, (("IAS")), len); cur_op->name = buf; cur_op->code = (0x0a); cur_op++;
  len = strlen(("RFI")); buf = calloc(sizeof(char), len); strncpy(buf, (("RFI")), len); cur_op->name = buf; cur_op->code = (0x0b); cur_op++;
  len = strlen(("IAQ")); buf = calloc(sizeof(char), len); strncpy(buf, (("IAQ")), len); cur_op->name = buf; cur_op->code = (0x0c); cur_op++;
  len = strlen(("HWN")); buf = calloc(sizeof(char), len); strncpy(buf, (("HWN")), len); cur_op->name = buf; cur_op->code = (0x10); cur_op++;
  len = strlen(("HWQ")); buf = calloc(sizeof(char), len); strncpy(buf, (("HWQ")), len); cur_op->name = buf; cur_op->code = (0x11); cur_op++;
  len = strlen(("HWI")); buf = calloc(sizeof(char), len); strncpy(buf, (("HWI")), len); cur_op->name = buf; cur_op->code = (0x12); cur_op++;
}

canonical_original_code:
void init_encoder(){
 op_convert_table = calloc(sizeof(op_convert_entry), 0x20);
 special_op_convert_table = calloc(sizeof(op_convert_entry), 0x20);
 int len = 0;
 char *buf = 0;
 struct op_convert_entry_t *cur_op = op_convert_table;
 len = strlen(("SET")); buf = calloc(sizeof(char), len); strncpy(buf, (("SET")), len); cur_op->name = buf; cur_op->code = (0x01); cur_op++;
 len = strlen(("ADD")); buf = calloc(sizeof(char), len); strncpy(buf, (("ADD")), len); cur_op->name = buf; cur_op->code = (0x02); cur_op++;
 len = strlen(("SUB")); buf = calloc(sizeof(char), len); strncpy(buf, (("SUB")), len); cur_op->name = buf; cur_op->code = (0x03); cur_op++;
 len = strlen(("MUL")); buf = calloc(sizeof(char), len); strncpy(buf, (("MUL")), len); cur_op->name = buf; cur_op->code = (0x04); cur_op++;
 len = strlen(("MLI")); buf = calloc(sizeof(char), len); strncpy(buf, (("MLI")), len); cur_op->name = buf; cur_op->code = (0x05); cur_op++;
 len = strlen(("DIV")); buf = calloc(sizeof(char), len); strncpy(buf, (("DIV")), len); cur_op->name = buf; cur_op->code = (0x06); cur_op++;
 len = strlen(("DVI")); buf = calloc(sizeof(char), len); strncpy(buf, (("DVI")), len); cur_op->name = buf; cur_op->code = (0x07); cur_op++;
  len = strlen(("MOD")); buf = calloc(sizeof(char), len); strncpy(buf, (("MOD")), len); cur_op->name = buf; cur_op->code = (0x08); cur_op++;
  len = strlen(("MDI")); buf = calloc(sizeof(char), len); strncpy(buf, (("MDI")), len); cur_op->name = buf; cur_op->code = (0x09); cur_op++;
  len = strlen(("AND")); buf = calloc(sizeof(char), len); strncpy(buf, (("AND")), len); cur_op->name = buf; cur_op->code = (0x0a); cur_op++;
  len = strlen(("BOR")); buf = calloc(sizeof(char), len); strncpy(buf, (("BOR")), len); cur_op->name = buf; cur_op->code = (0x0b); cur_op++;
  len = strlen(("XOR")); buf = calloc(sizeof(char), len); strncpy(buf, (("XOR")), len); cur_op->name = buf; cur_op->code = (0x0c); cur_op++;
  len = strlen(("SHR")); buf = calloc(sizeof(char), len); strncpy(buf, (("SHR")), len); cur_op->name = buf; cur_op->code = (0x0d); cur_op++;
  len = strlen(("ASR")); buf = calloc(sizeof(char), len); strncpy(buf, (("ASR")), len); cur_op->name = buf; cur_op->code = (0x0e); cur_op++;
  len = strlen(("SHL")); buf = calloc(sizeof(char), len); strncpy(buf, (("SHL")), len); cur_op->name = buf; cur_op->code = (0x0f); cur_op++;
  len = strlen(("IFB")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFB")), len); cur_op->name = buf; cur_op->code = (0x10); cur_op++;
  len = strlen(("IFC")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFC")), len); cur_op->name = buf; cur_op->code = (0x11); cur_op++;
  len = strlen(("IFE")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFE")), len); cur_op->name = buf; cur_op->code = (0x12); cur_op++;
  len = strlen(("IFN")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFN")), len); cur_op->name = buf; cur_op->code = (0x13); cur_op++;
  len = strlen(("IFG")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFG")), len); cur_op->name = buf; cur_op->code = (0x14); cur_op++;
  len = strlen(("IFA")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFA")), len); cur_op->name = buf; cur_op->code = (0x15); cur_op++;
  len = strlen(("IFL")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFL")), len); cur_op->name = buf; cur_op->code = (0x16); cur_op++;
  len = strlen(("IFU")); buf = calloc(sizeof(char), len); strncpy(buf, (("IFU")), len); cur_op->name = buf; cur_op->code = (0x17); cur_op++;
  len = strlen(("ADX")); buf = calloc(sizeof(char), len); strncpy(buf, (("ADX")), len); cur_op->name = buf; cur_op->code = (0x1a); cur_op++;
  len = strlen(("SBX")); buf = calloc(sizeof(char), len); strncpy(buf, (("SBX")), len); cur_op->name = buf; cur_op->code = (0x1b); cur_op++;
  len = strlen(("STI")); buf = calloc(sizeof(char), len); strncpy(buf, (("STI")), len); cur_op->name = buf; cur_op->code = (0x1e); cur_op++;
  len = strlen(("STD")); buf = calloc(sizeof(char), len); strncpy(buf, (("STD")), len); cur_op->name = buf; cur_op->code = (0x1f); cur_op++;
 cur_op = special_op_convert_table;
  len = strlen(("JSR")); buf = calloc(sizeof(char), len); strncpy(buf, (("JSR")), len); cur_op->name = buf; cur_op->code = (0x01); cur_op++;
  len = strlen(("INT")); buf = calloc(sizeof(char), len); strncpy(buf, (("INT")), len); cur_op->name = buf; cur_op->code = (0x08); cur_op++;
  len = strlen(("IAG")); buf = calloc(sizeof(char), len); strncpy(buf, (("IAG")), len); cur_op->name = buf; cur_op->code = (0x09); cur_op++;
  len = strlen(("IAS")); buf = calloc(sizeof(char), len); strncpy(buf, (("IAS")), len); cur_op->name = buf; cur_op->code = (0x0a); cur_op++;
  len = strlen(("RFI")); buf = calloc(sizeof(char), len); strncpy(buf, (("RFI")), len); cur_op->name = buf; cur_op->code = (0x0b); cur_op++;
  len = strlen(("IAQ")); buf = calloc(sizeof(char), len); strncpy(buf, (("IAQ")), len); cur_op->name = buf; cur_op->code = (0x0c); cur_op++;
  len = strlen(("HWN")); buf = calloc(sizeof(char), len); strncpy(buf, (("HWN")), len); cur_op->name = buf; cur_op->code = (0x10); cur_op++;
  len = strlen(("HWQ")); buf = calloc(sizeof(char), len); strncpy(buf, (("HWQ")), len); cur_op->name = buf; cur_op->code = (0x11); cur_op++;
  len = strlen(("HWI")); buf = calloc(sizeof(char), len); strncpy(buf, (("HWI")), len); cur_op->name = buf; cur_op->code = (0x12); cur_op++;
}

variable_types: len int

variable_types:
buf
char *

variable_types: struct op_convert_entry_t { char *name; unsigned short code; } *


decompiled_code:
__int64 encode_op()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
unsigned short encode_op(const char *str){
 return 0;
}

canonical_original_code:
unsigned short encode_op(char *str){
 return 0;
}

variable_types:
str
char *


decompiled_code:
__int64 encode_val()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0LL;
}

original_code:
unsigned short encode_val(const char *str, _Bool aval){
 return 0;
}

canonical_original_code:
unsigned short encode_val(char *str, _Bool aval){
 return 0;
}


decompiled_code:
void compile_cleanup()
{
_QWORD *v0; // rbp
void *v1; // rdi
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
_QWORD *v5; // rbx

v0 = codelist;
if ( codelist )
{
while ( 1 )
{
v1 = (void *)v0[1];
if ( v1 )
free(v1);
v2 = (void *)v0[2];
if ( v2 )
free(v2);
v3 = (void *)v0[3];
if ( v3 )
free(v3);
v4 = (void *)v0[4];
if ( v4 )
free(v4);
v5 = (_QWORD *)v0[6];
free(v0);
if ( !v5 )
break;
v0 = v5;
}
}
codelist = 0LL;
codelist_end = 0LL;
labels = 0LL;
}

canonical_decompiled_code:
void func0()
{
_QWORD *v0; // rbp
void *v1; // rdi
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
_QWORD *v5; // rbx

v0 = codelist;
if ( codelist )
{
while ( 1 )
{
v1 = (void *)v0[1];
if ( v1 )
free(v1);
v2 = (void *)v0[2];
if ( v2 )
free(v2);
v3 = (void *)v0[3];
if ( v3 )
free(v3);
v4 = (void *)v0[4];
if ( v4 )
free(v4);
v5 = (_QWORD *)v0[6];
free(v0);
if ( !v5 )
break;
v0 = v5;
}
}
codelist = 0LL;
codelist_end = 0LL;
labels = 0LL;
}

original_code:
void compile_cleanup(){
 codelist_entry *cl = codelist;
 codelist_entry *old = 0;
 while(cl){
  if(cl->aval){
   free(cl->aval);
  }
  if(cl->bval){
   free(cl->bval);
  }
  if(cl->label){
   free(cl->label);
  }
  if(cl->data){
   free(cl->data);
  }
  old = cl;
  cl = cl->next;
  free(old);
 }
 codelist = 0;
 codelist_end = 0;
 labels = 0;
}

canonical_original_code:
void compile_cleanup(){
 struct codelist_entry_t *cl = codelist;
 struct codelist_entry_t *old = 0;
 while(cl){
  if(cl->aval){
   free(cl->aval);
  }
  if(cl->bval){
   free(cl->bval);
  }
  if(cl->label){
   free(cl->label);
  }
  if(cl->data){
   free(cl->data);
  }
  old = cl;
  cl = cl->next;
  free(old);
 }
 codelist = 0;
 codelist_end = 0;
 labels = 0;
}

variable_types: struct codelist_entry_t { enum codelist_entry_type { CODELIST_ENTRY_TYPE_OP=0, CODELIST_ENTRY_TYPE_SPECIAL_OP=1, CODELIST_ENTRY_TYPE_LABEL=2, CODELIST_ENTRY_TYPE_DATA=3 } type; unsigned short op; struct token_val_t { enum vm_loc_type { LOC_REGISTER=0, LOC_MEMORY=1, LOC_REGISTER_MEMORY=2, LOC_REGISTER_MEMORY_OFFSET=3, LOC_PUSHPOP=4, LOC_PEEK=5, LOC_PICK=6, LOC_LITERAL=7, LOC_SP=8, LOC_PC=9, LOC_EX=10, LOC_LABEL=11, LOC_LABEL_MEM=12, LOC_IA=13 } type; unsigned short reg; unsigned short loc; unsigned short val; char *label_name; } *aval; struct token_val_t *bval; struct code_label_t { char *label_name; unsigned short loc; struct code_label_t *next; } *label; int *data; unsigned short data_size; unsigned short codeloc; struct codelist_entry_t *next; } *

user_defined_types: struct codelist_entry_t { enum codelist_entry_type type; unsigned short op; struct token_val_t *aval; struct token_val_t *bval; struct code_label_t *label; int *data; unsigned short data_size; unsigned short codeloc; struct codelist_entry_t *next; }

user_defined_types: struct token_val_t { enum vm_loc_type type; unsigned short reg; unsigned short loc; unsigned short val; char *label_name; }


decompiled_code:
void compile_init()
{
compile_cleanup();
}

canonical_decompiled_code:
void func1()
{
func0();
}

original_code:
void compile_init(){
 compile_cleanup();
}


decompiled_code:
__int64 __fastcall add_codelist_entry(void *a1)
{
__int64 result; // rax

if ( codelist )
{
result = codelist_end;
codelist_end = (__int64)a1;
*(_QWORD *)(result + 48) = a1;
}
else
{
codelist_end = (__int64)a1;
codelist = a1;
}
return result;
}

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

if ( codelist )
{
result = codelist_end;
codelist_end = (__int64)a1;
*(_QWORD *)(result + 48) = a1;
}
else
{
codelist_end = (__int64)a1;
codelist = a1;
}
return result;
}

original_code:
void add_codelist_entry(codelist_entry *new_entry){
 if(codelist == 0){
  codelist = codelist_end = new_entry;
 }else{
  codelist_end->next = new_entry;
  codelist_end = new_entry;
 }
}

canonical_original_code:
void add_codelist_entry(struct codelist_entry_t *new_entry){
 if(codelist == 0){
  codelist = codelist_end = new_entry;
 }else{
  codelist_end->next = new_entry;
  codelist_end = new_entry;
 }
}

user_defined_types: enum codelist_entry_type { CODELIST_ENTRY_TYPE_OP=0, CODELIST_ENTRY_TYPE_SPECIAL_OP=1, CODELIST_ENTRY_TYPE_LABEL=2, CODELIST_ENTRY_TYPE_DATA=3 }

user_defined_types: struct code_label_t { char *label_name; unsigned short loc; struct code_label_t *next; }