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, char *src, int a3, __m128i a4)
{
char *v4; // rbx
int v5; // er12
char *result; // rax

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

canonical_decompiled_code:
char *__fastcall func0(char *dest, char *src, int a3, __m128i a4)
{
char *v4; // rbx
int v5; // er12
char *result; // rax

v4 = dest;
v5 = _mm_cvtsi128_si32(a4);
if ( !dest )
v4 = (char *)malloc(0x28uLL);
result = strcpy(v4, src);
*((_DWORD *)v4 + 8) = v5;
*((_DWORD *)v4 + 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; // edx
_BOOL8 result; // rax

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

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

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

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:
void __fastcall finalize_node(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
free(a1);
}

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

return_type: void


generatefilename

decompiled_code:
char *__fastcall generatefilename(char *src)
{
size_t v1; // r12
void *v2; // rbx
char *v3; // r12

v1 = (int)(strlen(src) + 5);
v2 = malloc(v1);
memset(v2, 0, v1);
v3 = strrchr(src, 46);
strncpy((char *)v2, src, v3 - src);
strcat((char *)v2, ".new");
return strcat((char *)v2, v3);
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
size_t v1; // r12
void *v2; // rbx
char *v3; // r12

v1 = (int)(strlen(src) + 5);
v2 = malloc(v1);
memset(v2, 0, v1);
v3 = strrchr(src, 46);
strncpy((char *)v2, src, v3 - src);
strcat((char *)v2, ".new");
return strcat((char *)v2, v3);
}

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

return_type: char *


decompiled_code:
void __fastcall finalize_font_cache(void *ptr)
{
__int64 i; // rbx

if ( ptr )
{
for ( i = **(_QWORD **)ptr; i; i = *(_QWORD *)(i + 8) )
{
free(*(void **)i);
*(_QWORD *)i = 0LL;
}
finalize_list(*(_QWORD *)ptr);
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 i; // rbx

if ( ptr )
{
for ( i = **(_QWORD **)ptr; i; i = *(_QWORD *)(i + 8) )
{
free(*(void **)i);
*(_QWORD *)i = 0LL;
}
finalize_list(*(_QWORD *)ptr);
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
const char **v1; // rbx
unsigned int v2; // eax
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

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

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

if ( pipe(pipedes) == -1 )
{
printf((const char *)stderr, "Person B: Failed to create pipe.");
exit(-1);
}
v0 = fork();
if ( v0 < 0 )
{
printf((const char *)stderr, "Person B: Failed to fork.");
exit(-1);
}
if ( !v0 )
{
close(pipedes[0]);
dup2(pipedes[1], 1);
close(pipedes[1]);
sleep(2u);
if ( persBdialog[0] )
{
v1 = (const char **)persBdialog;
do
{
v2 = getpid();
printf("%s (%d)\n", *v1, v2);
fflush(stdout);
sleep(2u);
++v1;
}
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

return_type: 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
char s[2]; // [rsp+4h] [rbp-24h] BYREF
char v5[2]; // [rsp+6h] [rbp-22h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(pipedes) == -1 )
{
printf((const char *)stderr, "Talk Agent A: Failed to create pipe.");
exit(-1);
}
v2 = fork();
if ( v2 < 0 )
{
printf((const char *)stderr, "Talk Agent A: Failed to fork.");
exit(-1);
}
if ( !v2 )
{
dup2(pipedes[0], 0);
close(pipedes[0]);
close(pipedes[1]);
sprintf(s, "%d", (unsigned int)*a1);
sprintf(v5, "%d", (unsigned int)a2[1]);
close(a1[1]);
close(*a2);
execlp("./talkagent", "./talkagent", s, v5, 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
char s[2]; // [rsp+4h] [rbp-24h] BYREF
char v5[2]; // [rsp+6h] [rbp-22h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

if ( pipe(pipedes) == -1 )
{
printf((const char *)stderr, "Talk Agent A: Failed to create pipe.");
exit(-1);
}
v2 = fork();
if ( v2 < 0 )
{
printf((const char *)stderr, "Talk Agent A: Failed to fork.");
exit(-1);
}
if ( !v2 )
{
dup2(pipedes[0], 0);
close(pipedes[0]);
close(pipedes[1]);
sprintf(s, "%d", (unsigned int)*a1);
sprintf(v5, "%d", (unsigned int)a2[1]);
close(a1[1]);
close(*a2);
execlp("./talkagent", "./talkagent", s, v5, 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
const char **v2; // rbx
unsigned int v3; // eax

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

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

dup2(fd, 1);
close(fd);
result = sleep(1u);
if ( persAdialog[0] )
{
v2 = (const char **)persAdialog;
do
{
v3 = getpid();
printf("%s (%d)\n", *v2, v3);
fflush(stdout);
result = sleep(2u);
++v2;
}
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

canonical_name: main

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

puts("Simulation starting");
v3 = doPersonB("Simulation starting", argv);
if ( pipe(pipedes) == -1 )
{
printf((const char *)stderr, "Talk Agent: Failed to create pipe 1.");
exit(-1);
}
if ( pipe(&v6) == -1 )
{
printf((const char *)stderr, "Talk Agent: Failed to create pipe 2.");
exit(-1);
}
setupTalkAgentB(v3, pipedes, &v6);
v4 = setupTalkAgentA(pipedes, &v6);
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; // ebx
int v4; // eax
int v6; // [rsp+0h] [rbp-18h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

puts("Simulation starting");
v3 = func7("Simulation starting", argv);
if ( pipe(pipedes) == -1 )
{
printf((const char *)stderr, "Talk Agent: Failed to create pipe 1.");
exit(-1);
}
if ( pipe(&v6) == -1 )
{
printf((const char *)stderr, "Talk Agent: Failed to create pipe 2.");
exit(-1);
}
func8(v3, pipedes, &v6);
v4 = func9(pipedes, &v6);
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 v2; // eax
size_t v3; // rax
unsigned int v4; // eax
size_t v5; // rax
unsigned int v6; // eax
char v7[8216]; // [rsp+0h] [rbp-2018h] BYREF

while ( 1 )
{
v6 = read(*(_DWORD *)a1, v7, 0x2000uLL);
if ( v6 == -1 )
break;
if ( !v6 )
{
v4 = getpid();
sprintf(v7, "Link severed (%d)\n", v4);
v5 = strlen(v7);
write(*((_DWORD *)a1 + 1), v7, v5);
LABEL_3:
close(*(_DWORD *)a1);
close(*((_DWORD *)a1 + 1));
pthread_exit(0LL);
}
if ( !memcmp("exit", v7, 4uLL) )
goto LABEL_3;
write(*((_DWORD *)a1 + 1), v7, v6);
}
v2 = getpid();
sprintf(v7, "Fatal read error on %d (%d)\n", *(unsigned int *)a1, v2);
v3 = strlen(v7);
write(*((_DWORD *)a1 + 1), v7, v3);
perror(v7);
goto LABEL_3;
}

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

while ( 1 )
{
v6 = read(*(_DWORD *)a1, v7, 0x2000uLL);
if ( v6 == -1 )
break;
if ( !v6 )
{
v4 = getpid();
sprintf(v7, "Link severed (%d)\n", v4);
v5 = strlen(v7);
write(*((_DWORD *)a1 + 1), v7, v5);
LABEL_3:
close(*(_DWORD *)a1);
close(*((_DWORD *)a1 + 1));
pthread_exit(0LL);
}
if ( !memcmp("exit", v7, 4uLL) )
goto LABEL_3;
write(*((_DWORD *)a1 + 1), v7, v6);
}
v2 = getpid();
sprintf(v7, "Fatal read error on %d (%d)\n", *(unsigned int *)a1, v2);
v3 = strlen(v7);
write(*((_DWORD *)a1 + 1), v7, v3);
perror(v7);
goto LABEL_3;
}

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)
{
unsigned int v1; // eax
int v3[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

v1 = getpid();
printf("Welcome to talk agent (%d)\n", v1);
arg[0] = 0;
arg[1] = a1[1];
v3[0] = *a1;
v3[1] = 1;
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))talk, arg) )
{
printf(stderr, "Failed to create thread.");
exit(-1);
}
if ( pthread_create(th, 0LL, (void *(*)(void *))talk, v3) )
{
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) )
printf(stderr, 4202665LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1)
{
unsigned int v1; // eax
int v3[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

v1 = getpid();
printf("Welcome to talk agent (%d)\n", v1);
arg[0] = 0;
arg[1] = a1[1];
v3[0] = *a1;
v3[1] = 1;
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))talk, arg) )
{
printf(stderr, "Failed to create thread.");
exit(-1);
}
if ( pthread_create(th, 0LL, (void *(*)(void *))talk, v3) )
{
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) )
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)
{
int v3; // ebp
unsigned int v4; // eax
int v6; // [rsp+8h] [rbp-20h] BYREF

if ( argc == 3 )
{
v3 = __isoc99_sscanf();
if ( v3 == 1 )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
v3 = createThreads(&v6) != 0;
else
printf("Invalid <outfd> %s\n", argv[2]);
}
else
{
printf("Invalid <infd> %s\n", argv[1]);
v3 = 1;
}
}
else
{
puts("Usage: talkagent <infd> <outfd>");
v3 = 1;
}
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)
{
int v3; // ebp
unsigned int v4; // eax
int v6; // [rsp+8h] [rbp-20h] BYREF

if ( argc == 3 )
{
v3 = __isoc99_sscanf();
if ( v3 == 1 )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
v3 = func8(&v6) != 0;
else
printf("Invalid <outfd> %s\n", argv[2]);
}
else
{
printf("Invalid <infd> %s\n", argv[1]);
v3 = 1;
}
}
else
{
puts("Usage: talkagent <infd> <outfd>");
v3 = 1;
}
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 *(_QWORD *)(a1 + 16) + a2;
}

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

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 func4()
{
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
__off_t v3; // rdx
__int64 result; // rax
ssize_t v5; // rdx
size_t v6; // rsi
int v7; // edx
size_t v8; // rsi
void *v9; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbx
__off_t v3; // rdx
__int64 result; // rax
ssize_t v5; // rdx
size_t v6; // rsi
int v7; // edx
size_t v8; // rsi
void *v9; // rdx

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

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 func6(__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:
__int64 __fastcall ffa_close(void *ptr)
{
unsigned int v1; // ebx

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

canonical_decompiled_code:
__int64 __fastcall func7(void *ptr)
{
unsigned int v1; // ebx

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

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, __int64 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, __int64 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, __int64 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, __int64 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, 4u);
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, 4u);
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, 0x10u);
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, 0x10u);
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(unsigned __int16 a1, __int16 a2)
{
__int16 v2; // bx
__int16 v3; // r12
int v4; // eax
__int64 v6; // [rsp+14h] [rbp-24h]

if ( a1 <= 7u )
{
v3 = a1;
}
else
{
if ( a1 <= 0xFu )
{
v3 = a1 & 7;
v4 = 2;
goto LABEL_17;
}
if ( a1 <= 0x17u )
{
v3 = a1 & 7;
v2 = get_next_word();
v4 = 3;
goto LABEL_17;
}
}
switch ( a1 )
{
case 0x18u:
v4 = 4;
break;
case 0x19u:
v4 = 5;
break;
case 0x1Au:
v2 = get_next_word();
v4 = 6;
break;
case 0x1Bu:
v4 = 8;
break;
case 0x1Cu:
v4 = 9;
break;
case 0x1Du:
v4 = 10;
break;
case 0x1Eu:
v2 = get_next_word();
v4 = 1;
break;
case 0x1Fu:
get_next_word();
v4 = 7;
break;
default:
if ( a2 || a1 <= 0x1Fu )
v4 = 0;
else
v4 = 7;
break;
}
LABEL_17:
LODWORD(v6) = v4;
WORD2(v6) = v2;
HIWORD(v6) = v3;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int16 a1, __int16 a2)
{
__int16 v2; // bx
__int16 v3; // r12
int v4; // eax
__int64 v6; // [rsp+14h] [rbp-24h]

if ( a1 <= 7u )
{
v3 = a1;
}
else
{
if ( a1 <= 0xFu )
{
v3 = a1 & 7;
v4 = 2;
goto LABEL_17;
}
if ( a1 <= 0x17u )
{
v3 = a1 & 7;
v2 = func4();
v4 = 3;
goto LABEL_17;
}
}
switch ( a1 )
{
case 0x18u:
v4 = 4;
break;
case 0x19u:
v4 = 5;
break;
case 0x1Au:
v2 = func4();
v4 = 6;
break;
case 0x1Bu:
v4 = 8;
break;
case 0x1Cu:
v4 = 9;
break;
case 0x1Du:
v4 = 10;
break;
case 0x1Eu:
v2 = func4();
v4 = 1;
break;
case 0x1Fu:
func4();
v4 = 7;
break;
default:
if ( a2 || a1 <= 0x1Fu )
v4 = 0;
else
v4 = 7;
break;
}
LABEL_17:
LODWORD(v6) = v4;
WORD2(v6) = v2;
HIWORD(v6) = v3;
return v6;
}

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)
{
return code_word_value(a1 >> 10, 0);
}

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

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)
{
return code_word_value((a1 >> 5) & 0x1F, 1);
}

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

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_5C6++;
result = mem_get(v2);
break;
case 5:
result = mem_get(word_5C6);
break;
case 6:
result = mem_get(*(_WORD *)(a1 + 6) + word_5C6);
break;
case 7:
result = *(unsigned __int16 *)(a1 + 8);
break;
case 8:
result = (unsigned __int16)word_5C6;
break;
case 9:
result = (unsigned __int16)PC;
break;
case 0xA:
result = (unsigned __int16)EX;
break;
case 0xD:
result = (unsigned __int16)IA;
break;
default:
result = 0LL;
break;
}
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_5C6++;
result = func2(v2);
break;
case 5:
result = func2(word_5C6);
break;
case 6:
result = func2(*(_WORD *)(a1 + 6) + word_5C6);
break;
case 7:
result = *(unsigned __int16 *)(a1 + 8);
break;
case 8:
result = (unsigned __int16)word_5C6;
break;
case 9:
result = (unsigned __int16)PC;
break;
case 0xA:
result = (unsigned __int16)EX;
break;
case 0xD:
result = (unsigned __int16)IA;
break;
default:
result = 0LL;
break;
}
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_5C6, a2);
break;
case 5:
mem_set(word_5C6, a2);
break;
case 6:
mem_set(*(_WORD *)(a1 + 4) + word_5C6, a2);
break;
case 8:
word_5C6 = 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_5C6, a2);
break;
case 5:
func9(word_5C6, a2);
break;
case 6:
func9(*(_WORD *)(a1 + 4) + word_5C6, a2);
break;
case 8:
word_5C6 = 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:
void __fastcall write_code(unsigned __int16 a1, __int64 a2, unsigned __int16 a3)
{
__int64 v3; // rax

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

canonical_decompiled_code:
void __fastcall func11(unsigned __int16 a1, __int64 a2, unsigned __int16 a3)
{
__int64 v3; // rax

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

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 vm_skip()
{
__int16 v0; // bx

puts("SKIP");
v0 = get_next_word();
if ( !(unsigned __int16)code_word_op(v0) )
return code_word_a(v0);
code_word_a(v0);
return code_word_b(v0);
}

canonical_decompiled_code:
__int64 func13()
{
__int16 v0; // bx

puts("SKIP");
v0 = func4();
if ( !(unsigned __int16)func0(v0) )
return func6(v0);
func6(v0);
return func7(v0);
}

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");
 }
}


decompiled_code:
void __fastcall run_op(__int16 a1)
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // bx
int v3; // edx
int v4; // edx
unsigned __int16 v5; // bx
unsigned __int16 v6; // ax
__int16 v7; // bx
int v8; // edx
__int16 v9; // ax
__int16 v10; // bx
__int16 v11; // ax
__int16 v12; // bx
__int16 v13; // ax
__int64 v14; // [rsp+8h] [rbp-30h] BYREF
int v15; // [rsp+10h] [rbp-28h]
__int64 v16; // [rsp+14h] [rbp-24h] BYREF
int v17; // [rsp+1Ch] [rbp-1Ch]

v1 = code_word_op(a1);
if ( v1 )
{
v2 = v1;
v16 = code_word_a(a1);
v17 = v3;
v14 = code_word_b(a1);
v15 = v4;
if ( v2 == 2 )
{
puts("OP_ADD");
v10 = get_value((__int64)&v14);
v11 = get_value((__int64)&v16);
set_value((__int64)&v14, v10 + v11);
}
else if ( v2 <= 2u )
{
puts("OP_SET");
v9 = get_value((__int64)&v16);
set_value((__int64)&v14, v9);
}
else if ( v2 == 3 )
{
puts("OP_SUB");
v12 = get_value((__int64)&v14);
v13 = get_value((__int64)&v16);
set_value((__int64)&v14, v12 - v13);
}
else if ( v2 == 19 )
{
puts("OP_IFN");
v5 = get_value((__int64)&v14);
v6 = get_value((__int64)&v16);
printf("A: 0x%04X -- B: 0x%04X\n", v6, v5);
v7 = get_value((__int64)&v16);
if ( v7 == (unsigned __int16)get_value((__int64)&v14) )
vm_skip();
}
}
else
{
run_special_op(a1);
v16 = code_word_a(a1);
v17 = v8;
code_word_b(a1);
}
}

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 vm_step()
{
__int16 v0; // ax

v0 = get_next_word();
run_op(v0);
}

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; // rbx
_QWORD *v1; // rbp
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi

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

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

v0 = codelist;
if ( codelist )
{
while ( 1 )
{
v2 = (void *)v0[1];
if ( v2 )
free(v2);
v3 = (void *)v0[2];
if ( v3 )
free(v3);
v4 = (void *)v0[3];
if ( v4 )
free(v4);
v5 = (void *)v0[4];
if ( v5 )
free(v5);
v1 = (_QWORD *)v0[6];
free(v0);
if ( !v1 )
break;
v0 = v1;
}
}
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;
*(_QWORD *)(codelist_end + 48) = a1;
codelist_end = (__int64)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;
*(_QWORD *)(codelist_end + 48) = a1;
codelist_end = (__int64)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; }


decompiled_code:
_QWORD *process_label()
{
char *v0; // r12
int v1; // ebx
char *v2; // rbp
size_t v3; // rax
_QWORD *v4; // rbx
_QWORD *result; // rax

v0 = (char *)get_next_token();
v1 = strlen(v0);
v2 = (char *)calloc(v1, 1uLL);
strncpy(v2, v0 + 1, v1 - 1);
v3 = strlen(v2);
printf("Raw label: %s -- Label name: %s -- last char: %d\n", v0, v2, (unsigned int)v2[v3 - 1]);
free(v0);
v4 = calloc(0x18uLL, 1uLL);
*v4 = v2;
result = calloc(0x38uLL, 1uLL);
*(_DWORD *)result = 2;
result[3] = v4;
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
char *v0; // r12
int v1; // ebx
char *v2; // rbp
size_t v3; // rax
_QWORD *v4; // rbx
_QWORD *result; // rax

v0 = (char *)get_next_token();
v1 = strlen(v0);
v2 = (char *)calloc(v1, 1uLL);
strncpy(v2, v0 + 1, v1 - 1);
v3 = strlen(v2);
printf("Raw label: %s -- Label name: %s -- last char: %d\n", v0, v2, (unsigned int)v2[v3 - 1]);
free(v0);
v4 = calloc(0x18uLL, 1uLL);
*v4 = v2;
result = calloc(0x38uLL, 1uLL);
*(_DWORD *)result = 2;
result[3] = v4;
return result;
}

original_code:
codelist_entry *process_label(){
 char *label_raw = get_next_token();
 int raw_size = strlen(label_raw);
 char *label_name = calloc(raw_size, sizeof(char));
 strncpy(label_name, label_raw + 1, raw_size - 1);
 printf("Raw label: %s -- Label name: %s -- last char: %d\n", label_raw, label_name, (int)label_name[strlen(label_name) - 1]);
 free(label_raw);
 code_label *label = calloc(sizeof(code_label), 1);
 label->label_name = label_name;
 codelist_entry *cl = calloc(sizeof(codelist_entry), 1);
 cl->type = CODELIST_ENTRY_TYPE_LABEL;
 cl->label = label;
 return cl;
}

canonical_original_code:
struct codelist_entry_t *process_label(){
 char *label_raw = get_next_token();
 int raw_size = strlen(label_raw);
 char *label_name = calloc(raw_size, sizeof(char));
 strncpy(label_name, label_raw + 1, raw_size - 1);
 printf("Raw label: %s -- Label name: %s -- last char: %d\n", label_raw, label_name, (int)label_name[strlen(label_name) - 1]);
 free(label_raw);
 struct code_label_t *label = calloc(sizeof(code_label), 1);
 label->label_name = label_name;
 struct codelist_entry_t *cl = calloc(sizeof(codelist_entry), 1);
 cl->type = CODELIST_ENTRY_TYPE_LABEL;
 cl->label = label;
 return cl;
}

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


decompiled_code:
int __fastcall get_data_from_nums(char *s, __int64 a2)
{
char *v2; // rbx
char *v3; // rax
__int16 v4; // bp

v2 = (char *)calloc(4uLL, 8uLL);
LODWORD(v3) = sscanf(s, "%i %i %i %i %i %i %i %i", v2, v2 + 4, v2 + 8, v2 + 12, v2 + 16, v2 + 20, v2 + 24, v2 + 28);
v4 = (__int16)v3;
if ( ((unsigned int)v3 & 0xFFFFFFF7) != 0 )
{
v3 = (char *)realloc(v2, 2LL * (int)v3);
v2 = v3;
}
else if ( !(_DWORD)v3 )
{
LODWORD(v3) = puts("Error when parsing numbers from DAT field");
}
*(_QWORD *)(a2 + 32) = v2;
*(_WORD *)(a2 + 40) = v4;
return (int)v3;
}

canonical_decompiled_code:
int __fastcall func4(char *s, __int64 a2)
{
char *v2; // rbx
char *v3; // rax
__int16 v4; // bp

v2 = (char *)calloc(4uLL, 8uLL);
LODWORD(v3) = sscanf(s, "%i %i %i %i %i %i %i %i", v2, v2 + 4, v2 + 8, v2 + 12, v2 + 16, v2 + 20, v2 + 24, v2 + 28);
v4 = (__int16)v3;
if ( ((unsigned int)v3 & 0xFFFFFFF7) != 0 )
{
v3 = (char *)realloc(v2, 2LL * (int)v3);
v2 = v3;
}
else if ( !(_DWORD)v3 )
{
LODWORD(v3) = puts("Error when parsing numbers from DAT field");
}
*(_QWORD *)(a2 + 32) = v2;
*(_WORD *)(a2 + 40) = v4;
return (int)v3;
}

original_code:
void get_data_from_nums(const char *str, codelist_entry *entry){
 int *data = calloc(sizeof(int), 8);
 int size = sscanf(str, "%i %i %i %i %i %i %i %i",
          data, data + 1, data + 2, data + 3,
          data + 4, data + 5, data + 6, data + 7);
 if(size != 8 && size != 0){
  data = realloc(data, sizeof(short) * size);
 }
 if(size == 0){
  printf("Error when parsing numbers from DAT field\n");
 }
 entry->data = data;
 entry->data_size = size;
}

canonical_original_code:
void get_data_from_nums(char *str, struct codelist_entry_t *entry){
 int *data = calloc(sizeof(int), 8);
 int size = sscanf(str, "%i %i %i %i %i %i %i %i",
          data, data + 1, data + 2, data + 3,
          data + 4, data + 5, data + 6, data + 7);
 if(size != 8 && size != 0){
  data = realloc(data, sizeof(short) * size);
 }
 if(size == 0){
  printf("Error when parsing numbers from DAT field\n");
 }
 entry->data = data;
 entry->data_size = size;
}

variable_types:
data
int *

variable_types: size int


original_code:
void get_data_from_quoted_string(char *str, codelist_entry *entry){
 remove_string_ends(str);
 int len = strlen(str);
 int size = ceil(len / 2.0f);
 int *data = calloc(sizeof(int), size);
 int tmp;
 for(int i = 0; i < size; i++){
  tmp = str[i * 2];
  tmp += str[(i * 2) + 1] << 8;
  data[i] = (tmp & 0xFFFF);
 }
 entry->data = data;
 entry->data_size = size;
}

canonical_original_code:
void get_data_from_quoted_string(char *str, struct codelist_entry_t *entry){
 remove_string_ends(str);
 int len = strlen(str);
 int size = ceil(len / 2.0f);
 int *data = calloc(sizeof(int), size);
 int tmp;
 for(int i = 0; i < size; i++){
  tmp = str[i * 2];
  tmp += str[(i * 2) + 1] << 8;
  data[i] = (tmp & 0xFFFF);
 }
 entry->data = data;
 entry->data_size = size;
}

variable_types: tmp int


decompiled_code:
_QWORD *process_dat()
{
const char *v0; // rbx
size_t v1; // r12
char *v2; // rbp
_QWORD *v3; // rbx
__int64 v4; // rbp
__int64 v5; // rbp
int v6; // eax

v0 = (const char *)get_rest_of_orig_line();
v1 = (int)(strlen(v0) - 3);
v2 = (char *)calloc(v1, 1uLL);
strncpy(v2, v0 + 4, v1);
trim(v2);
printf("Dat: %s\n", v2);
v3 = calloc(0x38uLL, 1uLL);
if ( (unsigned __int8)is_quoted_string(v2) )
get_data_from_quoted_string(v2, (__int64)v3);
else
get_data_from_nums(v2, (__int64)v3);
printf("Data: ");
if ( *((_WORD *)v3 + 20) )
{
v4 = 0LL;
do
printf("0x%04x ", *(unsigned int *)(v3[4] + 4 * v4++));
while ( *((unsigned __int16 *)v3 + 20) > (int)v4 );
}
putchar(10);
if ( *((_WORD *)v3 + 20) )
{
v5 = 0LL;
do
{
v6 = *(_DWORD *)(v3[4] + 4 * v5);
printf("%c%c", BYTE1(v6), (unsigned __int8)v6);
++v5;
}
while ( *((unsigned __int16 *)v3 + 20) > (int)v5 );
}
putchar(10);
return v3;
}

canonical_decompiled_code:
_QWORD *func6()
{
const char *v0; // rbx
size_t v1; // r12
char *v2; // rbp
_QWORD *v3; // rbx
__int64 v4; // rbp
__int64 v5; // rbp
int v6; // eax

v0 = (const char *)get_rest_of_orig_line();
v1 = (int)(strlen(v0) - 3);
v2 = (char *)calloc(v1, 1uLL);
strncpy(v2, v0 + 4, v1);
trim(v2);
printf("Dat: %s\n", v2);
v3 = calloc(0x38uLL, 1uLL);
if ( (unsigned __int8)is_quoted_string(v2) )
func5(v2, (__int64)v3);
else
func4(v2, (__int64)v3);
printf("Data: ");
if ( *((_WORD *)v3 + 20) )
{
v4 = 0LL;
do
printf("0x%04x ", *(unsigned int *)(v3[4] + 4 * v4++));
while ( *((unsigned __int16 *)v3 + 20) > (int)v4 );
}
putchar(10);
if ( *((_WORD *)v3 + 20) )
{
v5 = 0LL;
do
{
v6 = *(_DWORD *)(v3[4] + 4 * v5);
printf("%c%c", BYTE1(v6), (unsigned __int8)v6);
++v5;
}
while ( *((unsigned __int16 *)v3 + 20) > (int)v5 );
}
putchar(10);
return v3;
}

original_code:
codelist_entry *process_dat(){
 char *orig_line = get_rest_of_orig_line();
 int len = strlen(orig_line);
 char *buf = calloc(len - 3, sizeof(char));
 strncpy(buf, orig_line + 4, len - 3);
 trim(buf);
 printf("Dat: %s\n", buf);
 codelist_entry *entry = calloc(sizeof(codelist_entry), 1);
 if(is_quoted_string(buf)){
  get_data_from_quoted_string(buf, entry);
 }else{
  get_data_from_nums(buf, entry);
 }
 printf("Data: ");
 for(int i = 0; i < entry->data_size; i++){
  printf("0x%04x ", entry->data[i]);
 }
 printf("\n");
 for(int i = 0; i < entry->data_size; i++){
  unsigned short cur = entry->data[i];
  printf("%c%c", (cur >> 8), (cur & 0xFF));
 }
 printf("\n");
 return entry;
}

canonical_original_code:
struct codelist_entry_t *process_dat(){
 char *orig_line = get_rest_of_orig_line();
 int len = strlen(orig_line);
 char *buf = calloc(len - 3, sizeof(char));
 strncpy(buf, orig_line + 4, len - 3);
 trim(buf);
 printf("Dat: %s\n", buf);
 struct codelist_entry_t *entry = calloc(sizeof(codelist_entry), 1);
 if(is_quoted_string(buf)){
  get_data_from_quoted_string(buf, entry);
 }else{
  get_data_from_nums(buf, entry);
 }
 printf("Data: ");
 for(int i = 0; i < entry->data_size; i++){
  printf("0x%04x ", entry->data[i]);
 }
 printf("\n");
 for(int i = 0; i < entry->data_size; i++){
  unsigned short cur = entry->data[i];
  printf("%c%c", (cur >> 8), (cur & 0xFF));
 }
 printf("\n");
 return entry;
}

variable_types:
cur
unsigned short


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

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

original_code:
codelist_entry *process_op(){
 return ((void *)0);
}

canonical_original_code:
struct codelist_entry_t *process_op(){
 return ((void *)0);
}


decompiled_code:
_QWORD *process_line()
{
const char *v0; // rbx
size_t v1; // rax
_QWORD *result; // rax
__int64 v3; // rax

eat_whitespace();
v0 = (const char *)*input_file_stack;
v1 = strlen((const char *)*input_file_stack);
printf("Processing line: %s -- len: %d\n", v0, v1);
if ( (unsigned __int8)is_line_blank() || (unsigned __int8)is_line_comment() )
{
puts("Line comment/empty/blank");
result = 0LL;
}
else if ( (unsigned __int8)is_line_label() )
{
puts("Line is label");
result = process_label();
}
else if ( (unsigned __int8)is_line_dat() )
{
puts("Line is data");
result = process_dat();
}
else if ( (unsigned __int8)is_line_include() )
{
puts("Line is include");
v3 = get_include_filename();
open_input_m4(v3);
result = 0LL;
}
else
{
puts("Processing code line");
result = (_QWORD *)process_op();
}
return result;
}

canonical_decompiled_code:
_QWORD *func8()
{
const char *v0; // rbx
size_t v1; // rax
_QWORD *result; // rax
__int64 v3; // rax

eat_whitespace();
v0 = (const char *)*input_file_stack;
v1 = strlen((const char *)*input_file_stack);
printf("Processing line: %s -- len: %d\n", v0, v1);
if ( (unsigned __int8)is_line_blank() || (unsigned __int8)is_line_comment() )
{
puts("Line comment/empty/blank");
result = 0LL;
}
else if ( (unsigned __int8)is_line_label() )
{
puts("Line is label");
result = func3();
}
else if ( (unsigned __int8)is_line_dat() )
{
puts("Line is data");
result = func6();
}
else if ( (unsigned __int8)is_line_include() )
{
puts("Line is include");
v3 = get_include_filename();
open_input_m4(v3);
result = 0LL;
}
else
{
puts("Processing code line");
result = (_QWORD *)func7();
}
return result;
}

original_code:
codelist_entry *process_line(){
 eat_whitespace();
 codelist_entry *ret = ((void *)0);
 printf("Processing line: %s -- len: %d\n", input_file_stack->line_buffer, (int)strlen(input_file_stack->line_buffer));
 if(!is_line_blank() && !is_line_comment()){
  if(is_line_label()){
   printf("Line is label\n");
   return process_label();
  }else if(is_line_dat()){
   printf("Line is data\n");
   return process_dat();
  }else if(is_line_include()){
   printf("Line is include\n");
   open_input_m4(get_include_filename());
   return ((void *)0);
  }else{
   printf("Processing code line\n");
   return process_op();
  }
 }else{
  printf("Line comment/empty/blank\n");
 }
 return ret;
}

canonical_original_code:
struct codelist_entry_t *process_line(){
 eat_whitespace();
 struct codelist_entry_t *ret = ((void *)0);
 printf("Processing line: %s -- len: %d\n", input_file_stack->line_buffer, (int)strlen(input_file_stack->line_buffer));
 if(!is_line_blank() && !is_line_comment()){
  if(is_line_label()){
   printf("Line is label\n");
   return process_label();
  }else if(is_line_dat()){
   printf("Line is data\n");
   return process_dat();
  }else if(is_line_include()){
   printf("Line is include\n");
   open_input_m4(get_include_filename());
   return ((void *)0);
  }else{
   printf("Processing code line\n");
   return process_op();
  }
 }else{
  printf("Line comment/empty/blank\n");
 }
 return ret;
}


decompiled_code:
void __fastcall compile_file(const char *a1, const char *a2)
{
_QWORD *v2; // rbx

printf("Compiling file: %s into %s\n", a1, a2);
puts("Initializing compiler...");
compile_init();
open_input_m4(a1);
while ( (unsigned __int8)is_input_open() )
{
while ( (unsigned __int8)read_input_line() )
{
v2 = process_line();
if ( v2 )
{
puts("Adding codelist entry...");
add_codelist_entry(v2);
}
}
close_input();
}
close_input();
compile_cleanup();
}

canonical_decompiled_code:
void __fastcall func9(const char *a1, const char *a2)
{
_QWORD *v2; // rbx

printf("Compiling file: %s into %s\n", a1, a2);
puts("Initializing compiler...");
func1();
open_input_m4(a1);
while ( (unsigned __int8)is_input_open() )
{
while ( (unsigned __int8)read_input_line() )
{
v2 = func8();
if ( v2 )
{
puts("Adding codelist entry...");
func2(v2);
}
}
close_input();
}
close_input();
func0();
}

original_code:
void compile_file(const char *src, const char *dest){
 printf("Compiling file: %s into %s\n", src, dest);
 printf("Initializing compiler...\n");
 compile_init();
 open_input_m4(src);
 codelist_entry *entry;
 while(is_input_open()){
  while(read_input_line()){
   entry = process_line();
   if(entry != ((void *)0)){
    printf("Adding codelist entry...\n");
    add_codelist_entry(entry);
   }
  }
  close_input();
 }
 close_input();
 compile_cleanup();
}

canonical_original_code:
void compile_file(char *src, char *dest){
 printf("Compiling file: %s into %s\n", src, dest);
 printf("Initializing compiler...\n");
 compile_init();
 open_input_m4(src);
 struct codelist_entry_t *entry;
 while(is_input_open()){
  while(read_input_line()){
   entry = process_line();
   if(entry != ((void *)0)){
    printf("Adding codelist entry...\n");
    add_codelist_entry(entry);
   }
  }
  close_input();
 }
 close_input();
 compile_cleanup();
}

variable_types:
src
char *

variable_types:
dest
char *


decompiled_code:
bool __fastcall is_whitespace(char a1)
{
bool result; // al

result = 1;
if ( (unsigned __int8)(a1 - 9) > 4u )
result = (a1 & 0xDF) == 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func0(char a1)
{
bool result; // al

result = 1;
if ( (unsigned __int8)(a1 - 9) > 4u )
result = (a1 & 0xDF) == 0;
return result;
}

variable_types: c char


decompiled_code:
__int64 eat_whitespace()
{
_DWORD *v0; // rbx
__int64 v1; // rbp
char *i; // rax
unsigned int v3; // eax
__int64 result; // rax

v0 = input_file_stack;
v1 = *(_QWORD *)input_file_stack;
for ( i = (char *)(*(_QWORD *)input_file_stack + *((unsigned int *)input_file_stack + 5));
is_whitespace(*i);
i = (char *)(v1 + v3) )
{
v3 = v0[5];
v0[5] = v3 + 1;
}
result = (unsigned int)v0[5];
if ( (_DWORD)result )
{
result = (unsigned int)(result - 1);
v0[5] = result;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
_DWORD *v0; // rbx
__int64 v1; // rbp
char *i; // rax
unsigned int v3; // eax
__int64 result; // rax

v0 = input_file_stack;
v1 = *(_QWORD *)input_file_stack;
for ( i = (char *)(*(_QWORD *)input_file_stack + *((unsigned int *)input_file_stack + 5));
func0(*i);
i = (char *)(v1 + v3) )
{
v3 = v0[5];
v0[5] = v3 + 1;
}
result = (unsigned int)v0[5];
if ( (_DWORD)result )
{
result = (unsigned int)(result - 1);
v0[5] = result;
}
return result;
}

original_code:
void eat_whitespace(){
 char *cur = input_file_stack->line_buffer +
              input_file_stack->line_buffer_pos;
 while(is_whitespace(*cur)){
  cur = input_file_stack->line_buffer +
   input_file_stack->line_buffer_pos++;
 }
 if(input_file_stack->line_buffer_pos != 0){
  input_file_stack->line_buffer_pos--;
 }
}

variable_types:
cur
char *


decompiled_code:
__int64 parser_get_orig_line()
{
return *((_QWORD *)input_file_stack + 1);
}

canonical_decompiled_code:
__int64 func2()
{
return *((_QWORD *)input_file_stack + 1);
}

original_code:
char *parser_get_orig_line(){
 return input_file_stack->orig_line_buffer;
}


decompiled_code:
bool is_input_open()
{
return input_file_stack != 0LL;
}

canonical_decompiled_code:
bool func3()
{
return input_file_stack != 0LL;
}

original_code:
_Bool is_input_open(){
 return input_file_stack ? 1 : 0;
}


decompiled_code:
__int64 __fastcall open_input(char *filename)
{
printf("Opening file: %s\n", filename);
return push_input_file(filename);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *filename)
{
printf("Opening file: %s\n", filename);
return func4(filename);
}

original_code:
_Bool open_input(const char* filename){
 printf("Opening file: %s\n", filename);
 return push_input_file(filename);
}

canonical_original_code:
_Bool open_input(char *filename){
 printf("Opening file: %s\n", filename);
 return push_input_file(filename);
}

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall open_input_m4(char *src)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // rax
int v5[64]; // [rsp+0h] [rbp-208h] BYREF
char dest[8]; // [rsp+100h] [rbp-108h] BYREF
__int16 v7; // [rsp+108h] [rbp-100h]

*(_QWORD *)dest = 0x2F706D742FLL;
v7 = 0;
v1 = strlen(src);
strncat(dest, src, v1);
*(_DWORD *)&dest[strlen(dest)] = 3435822;
v5[0] = 2110573;
v2 = strlen(src);
strncat((char *)v5, src, v2);
*(int *)((char *)v5 + strlen((const char *)v5)) = 2113056;
v3 = strlen(dest);
strncat((char *)v5, dest, v3);
system((const char *)v5);
return open_input(dest);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src)
{
size_t v1; // rax
size_t v2; // rax
size_t v3; // rax
int v5[64]; // [rsp+0h] [rbp-208h] BYREF
char dest[8]; // [rsp+100h] [rbp-108h] BYREF
__int16 v7; // [rsp+108h] [rbp-100h]

*(_QWORD *)dest = 0x2F706D742FLL;
v7 = 0;
v1 = strlen(src);
strncat(dest, src, v1);
*(_DWORD *)&dest[strlen(dest)] = 3435822;
v5[0] = 2110573;
v2 = strlen(src);
strncat((char *)v5, src, v2);
*(int *)((char *)v5 + strlen((const char *)v5)) = 2113056;
v3 = strlen(dest);
strncat((char *)v5, dest, v3);
system((const char *)v5);
return func5(dest);
}

original_code:
_Bool open_input_m4(const char* filename){
 char m4_filename[256];
 strncpy(m4_filename, "/tmp/", 10);
 strncat(m4_filename, filename, strlen(filename));
 strncat(m4_filename, ".m4", 10);
 char m4_command[256];
 strncpy(m4_command, "m4 ", 4);
 strncat(m4_command, filename, strlen(filename));
 strncat(m4_command, " > ", 10);
 strncat(m4_command, m4_filename, strlen(m4_filename));
 system(m4_command);
 return open_input(m4_filename);
}

canonical_original_code:
_Bool open_input_m4(char *filename){
 char m4_filename[256];
 strncpy(m4_filename, "/tmp/", 10);
 strncat(m4_filename, filename, strlen(filename));
 strncat(m4_filename, ".m4", 10);
 char m4_command[256];
 strncpy(m4_command, "m4 ", 4);
 strncat(m4_command, filename, strlen(filename));
 strncat(m4_command, " > ", 10);
 strncat(m4_command, m4_filename, strlen(m4_filename));
 system(m4_command);
 return open_input(m4_filename);
}


decompiled_code:
void close_input()
{
puts("Closing ");
pop_input_file();
}

canonical_decompiled_code:
void func8()
{
puts("Closing ");
func7();
}

original_code:
void close_input(){
 printf("Closing \n");
 pop_input_file();
}


decompiled_code:
char *get_next_token()
{
const char *v0; // r12
size_t v1; // rbx
unsigned int v2; // er13
bool v3; // al
size_t v4; // rbp
char *v5; // rbx
char *result; // rax

eat_whitespace();
v0 = (const char *)(*(_QWORD *)input_file_stack + *((unsigned int *)input_file_stack + 5));
v1 = 0LL;
do
{
v2 = v1;
v3 = is_whitespace(v0[v1]);
v4 = v1++;
}
while ( !v3 );
printf("Token size: %d\n", v2);
*((_DWORD *)input_file_stack + 5) += v2;
v5 = (char *)calloc(v4, 1uLL);
result = strncpy(v5, v0, v4);
v5[v4] = 0;
return result;
}

canonical_decompiled_code:
char *func9()
{
const char *v0; // r12
size_t v1; // rbx
unsigned int v2; // er13
bool v3; // al
size_t v4; // rbp
char *v5; // rbx
char *result; // rax

func1();
v0 = (const char *)(*(_QWORD *)input_file_stack + *((unsigned int *)input_file_stack + 5));
v1 = 0LL;
do
{
v2 = v1;
v3 = func0(v0[v1]);
v4 = v1++;
}
while ( !v3 );
printf("Token size: %d\n", v2);
*((_DWORD *)input_file_stack + 5) += v2;
v5 = (char *)calloc(v4, 1uLL);
result = strncpy(v5, v0, v4);
v5[v4] = 0;
return result;
}

original_code:
char *get_next_token(){
 eat_whitespace();
 char *start = input_file_stack->line_buffer + input_file_stack->line_buffer_pos;
 int size = 0;
 while(!is_whitespace(start[size])){
  size++;
 }
 printf("Token size: %d\n", size);
 input_file_stack->line_buffer_pos += size;
 char *token = calloc(size, sizeof(char));
 strncpy(token, start, size);
 token[size] = '\0';
 return token;
}

variable_types:
start
char *

variable_types:
token
char *