StringCmp

decompiled_code:
__int64 __fastcall StringCmp(__int64 a1, __int64 a2)
{
__int64 i; // rax
char v3; // cl
char v4; // dl

for ( i = 0LL; ; ++i )
{
v4 = *(_BYTE *)(a1 + i);
if ( !v4 )
return (unsigned int)-(*(_BYTE *)(a2 + i) != 0);
v3 = *(_BYTE *)(a2 + i);
if ( v4 > v3 || !v3 )
break;
if ( v4 < v3 )
return 0xFFFFFFFFLL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 i; // rax
char v3; // cl
char v4; // dl

for ( i = 0LL; ; ++i )
{
v4 = *(_BYTE *)(a1 + i);
if ( !v4 )
return (unsigned int)-(*(_BYTE *)(a2 + i) != 0);
v3 = *(_BYTE *)(a2 + i);
if ( v4 > v3 || !v3 )
break;
if ( v4 < v3 )
return 0xFFFFFFFFLL;
}
return 1LL;
}

original_code:
int StringCmp(char * str1, char * str2)
{
  int i = 0;
  while (1) {
    if ( (str1[i] == '\0') && (str2[i] == '\0') ) return (0);
    if (str1[i] == '\0') return (-1);
    if (str2[i] == '\0') return ( 1);
    if (str1[i] > str2[i]) return ( 1);
    if (str1[i] < str2[i]) return (-1);
    i++;
  }
}

canonical_original_code:
int StringCmp(char *str1, char *str2)
{
  int i = 0;
  while (1) {
    if ( (str1[i] == '\0') && (str2[i] == '\0') ) return (0);
    if (str1[i] == '\0') return (-1);
    if (str2[i] == '\0') return ( 1);
    if (str1[i] > str2[i]) return ( 1);
    if (str1[i] < str2[i]) return (-1);
    i++;
  }
}


StringEqual

repo: yabuki/xfireworks

decompiled_code:
_BOOL8 __fastcall StringEqual(__int64 a1, __int64 a2)
{
return (unsigned int)StringCmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, __int64 a2)
{
return (unsigned int)func7(a1, a2) == 0;
}

original_code:
int StringEqual(char * str1, char * str2)
{
  return (!StringCmp(str1, str2));
}

canonical_original_code:
int StringEqual(char *str1, char *str2)
{
  return (!StringCmp(str1, str2));
}

return_type: int


decompiled_code:
__int64 __fastcall Calculator_Destroy(void *ptr)
{
void *v2; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
void *v2; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
return 0LL;
}

original_code:
Calculator Calculator_Destroy(Calculator cal)
{
  if (!cal) return (((void *)0));
  if (cal->sine) free(cal->sine);
  free(cal);
  return (((void *)0));
}

canonical_original_code:
struct _Calculator *Calculator_Destroy(struct _Calculator *cal)
{
  if (!cal) return (((void *)0));
  if (cal->sine) free(cal->sine);
  free(cal);
  return (((void *)0));
}

variable_types:
cal
struct _Calculator *

return_type: struct _Calculator { int degree_number; double *sine; } *


decompiled_code:
double __fastcall Calculator_GetSin(__int64 a1, int a2)
{
int i; // eax

for ( i = a2; i < 0; i += *(_DWORD *)a1 )
;
return *(double *)(*(_QWORD *)(a1 + 8) + 8LL * (i % *(_DWORD *)a1));
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1, int a2)
{
int i; // eax

for ( i = a2; i < 0; i += *(_DWORD *)a1 )
;
return *(double *)(*(_QWORD *)(a1 + 8) + 8LL * (i % *(_DWORD *)a1));
}

original_code:
double Calculator_GetSin(Calculator cal, int degree)
{
  while (degree < 0) degree += cal->degree_number;
  degree = degree % cal->degree_number;
  return (cal->sine[degree]);
}

canonical_original_code:
double Calculator_GetSin(struct _Calculator *cal, int degree)
{
  while (degree < 0) degree += cal->degree_number;
  degree = degree % cal->degree_number;
  return (cal->sine[degree]);
}

variable_types: struct _Calculator { int degree_number; double *sine; } *

variable_types: degree int

return_type: double


decompiled_code:
double __fastcall Calculator_GetCos(int *a1, int a2)
{
int v3; // esi

v3 = *a1 + 3;
if ( *a1 >= 0 )
v3 = *a1;
return Calculator_GetSin((__int64)a1, (v3 >> 2) - a2);
}

canonical_decompiled_code:
double __fastcall func2(int *a1, int a2)
{
int v3; // esi

v3 = *a1 + 3;
if ( *a1 >= 0 )
v3 = *a1;
return func1((__int64)a1, (v3 >> 2) - a2);
}

original_code:
double Calculator_GetCos(Calculator cal, int degree)
{
  return (Calculator_GetSin(cal, cal->degree_number / 4 - degree));
}

canonical_original_code:
double Calculator_GetCos(struct _Calculator *cal, int degree)
{
  return (Calculator_GetSin(cal, cal->degree_number / 4 - degree));
}

user_defined_types: struct _Calculator { int degree_number; double *sine; }


help

decompiled_code:
void __noreturn help()
{
printf("%s\n\n", "XFireworks-1.3");
puts("XFireworks Copyright (c) 2000 Sakai Hiroaki.");
puts("All Rights Reserved.\n");
puts("Usage:");
puts(" xfireworks [options]\n");
puts("Options:");
puts(" -h, -help");
puts(" -display [displayname]");
puts(" -bg, -background, -background-color [backgroundcolor]");
puts(" -f, -file [filename]");
puts(" -wait [micro seconds]");
puts(" -fine [number]");
puts(" -gradation [number]");
puts(" -direct-draw, -no-direct-draw");
puts(" -probability, -probability-magnification [number]");
puts(" -size, -size-magnification [number]");
puts(" -air, -air-magnification [number]");
puts(" -gravity, -gravity-magnification [number]");
puts(" -transmission, -transmission-magnification [number]");
puts(" -after-image, -after-image-magnification [number]");
puts(" -color-length, -color-length-magnification [number]");
puts(" -next-power, -next-power-magnification [number]");
puts(" -next-number, -next-number-magnification [number]");
putchar(10);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
printf("%s\n\n", "XFireworks-1.3");
puts("XFireworks Copyright (c) 2000 Sakai Hiroaki.");
puts("All Rights Reserved.\n");
puts("Usage:");
puts(" xfireworks [options]\n");
puts("Options:");
puts(" -h, -help");
puts(" -display [displayname]");
puts(" -bg, -background, -background-color [backgroundcolor]");
puts(" -f, -file [filename]");
puts(" -wait [micro seconds]");
puts(" -fine [number]");
puts(" -gradation [number]");
puts(" -direct-draw, -no-direct-draw");
puts(" -probability, -probability-magnification [number]");
puts(" -size, -size-magnification [number]");
puts(" -air, -air-magnification [number]");
puts(" -gravity, -gravity-magnification [number]");
puts(" -transmission, -transmission-magnification [number]");
puts(" -after-image, -after-image-magnification [number]");
puts(" -color-length, -color-length-magnification [number]");
puts(" -next-power, -next-power-magnification [number]");
puts(" -next-number, -next-number-magnification [number]");
putchar(10);
exit(0);
}

original_code:
void help()
{
  printf("%s\n\n", "XFireworks-1.3");
  printf("XFireworks Copyright (c) 2000 Sakai Hiroaki.\n");
  printf("All Rights Reserved.\n\n");
  printf("Usage:\n");
  printf("        xfireworks [options]\n\n");
  printf("Options:\n");
  printf("        -h, -help\n");
  printf("        -display [displayname]\n");
  printf("        -bg, -background, -background-color [backgroundcolor]\n");
  printf("        -f, -file [filename]\n");
  printf("        -wait [micro seconds]\n");
  printf("        -fine [number]\n");
  printf("        -gradation [number]\n");
  printf("        -direct-draw, -no-direct-draw\n");
  printf("        -probability, -probability-magnification [number]\n");
  printf("        -size, -size-magnification [number]\n");
  printf("        -air, -air-magnification [number]\n");
  printf("        -gravity, -gravity-magnification [number]\n");
  printf("        -transmission, -transmission-magnification [number]\n");
  printf("        -after-image, -after-image-magnification [number]\n");
  printf("        -color-length, -color-length-magnification [number]\n");
  printf("        -next-power, -next-power-magnification [number]\n");
  printf("        -next-number, -next-number-magnification [number]\n");
  printf("\n");
  exit (0);
}

return_type: void


usage

repo: yami/pacfind

decompiled_code:
int usage()
{
return puts(
"Usage: \n"
" Query a binary\n"
" pacfind [-c <config file>] -q <binary_name>\n"
" Update the database\n"
" pacfind [-c <config file>] -u\n"
"\n"
"Default config file is /etc/pacfind.conf");
}

canonical_decompiled_code:
int func0()
{
return puts(
"Usage: \n"
" Query a binary\n"
" pacfind [-c <config file>] -q <binary_name>\n"
" Update the database\n"
" pacfind [-c <config file>] -u\n"
"\n"
"Default config file is /etc/pacfind.conf");
}

original_code:
static void
usage()
{
    printf("Usage: \n"
           "  Query a binary\n"
           "    pacfind [-c <config file>] -q <binary_name>\n"
           "  Update the database\n"
           "    pacfind [-c <config file>] -u\n"
           "\n"
           "Default config file is /etc/pacfind.conf\n"
        );
}


decompiled_code:
_BOOL8 __fastcall are_options_valid(int a1)
{
_BOOL8 result; // rax

if ( (a1 & 0x10) == 0 || (result = 0LL, (a1 & 0xFFFFFFEF) == 0) )
result = (a1 & 5) != 5;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1)
{
_BOOL8 result; // rax

if ( (a1 & 0x10) == 0 || (result = 0LL, (a1 & 0xFFFFFFEF) == 0) )
result = (a1 & 5) != 5;
return result;
}

original_code:
int are_options_valid(int options, const char* argument)
{
    if ((options & (1<<4)) && (options & ~(1<<4))) {
        return 0;
    }
    if ((options & (1<<0)) && (options & (1<<2))) {
        return 0;
    }
    return 1;
}

canonical_original_code:
int are_options_valid(int options, char *argument)
{
    if ((options & (1<<4)) && (options & ~(1<<4))) {
        return 0;
    }
    if ((options & (1<<0)) && (options & (1<<2))) {
        return 0;
    }
    return 1;
}

variable_types: options int

variable_types:
argument
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // r13
__int64 v5; // r15
__int64 v6; // r14
int v7; // ebx
int v8; // eax
__int64 v9; // rdx
int v10; // ebp
__int64 v12; // rsi
__int64 v13; // rax
__int64 v14; // r12

v4 = xstrdup(Default_Config_Path, argv, envp);
v5 = 0LL;
v6 = 0LL;
v7 = 0;
while ( 2 )
{
v8 = getopt(argc, (char *const *)argv, "uc:q:l:h");
if ( v8 != -1 )
{
switch ( v8 )
{
case 'c':
v7 |= 2u;
v4 = xstrdup(optarg, argv, v9);
continue;
case 'h':
v7 |= 0x10u;
continue;
case 'l':
v7 |= 8u;
v5 = xstrdup(optarg, argv, v9);
continue;
case 'q':
v7 |= 4u;
v6 = xstrdup(optarg, argv, v9);
continue;
case 'u':
v7 |= 1u;
continue;
default:
goto LABEL_9;
}
}
break;
}
v12 = 0LL;
if ( optind < argc )
v12 = xstrdup(argv[optind], 0LL, v9);
if ( are_options_valid(v7) )
{
v13 = read_config_file(v4, v12);
v14 = v13;
v10 = v7 & 1;
if ( (v7 & 1) != 0 )
v10 = do_update(v13);
if ( (v7 & 4) != 0 )
v10 = do_query(v14, v6);
xfree(v4);
xfree(v6);
xfree(v5);
config_delete(v14);
}
else
{
LABEL_9:
usage();
v10 = 1;
}
return v10;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // r13
__int64 v5; // r15
__int64 v6; // r14
int v7; // ebx
int v8; // eax
__int64 v9; // rdx
int v10; // ebp
__int64 v12; // rsi
__int64 v13; // rax
__int64 v14; // r12

v4 = xstrdup(Default_Config_Path, argv, envp);
v5 = 0LL;
v6 = 0LL;
v7 = 0;
while ( 2 )
{
v8 = getopt(argc, (char *const *)argv, "uc:q:l:h");
if ( v8 != -1 )
{
switch ( v8 )
{
case 'c':
v7 |= 2u;
v4 = xstrdup(optarg, argv, v9);
continue;
case 'h':
v7 |= 0x10u;
continue;
case 'l':
v7 |= 8u;
v5 = xstrdup(optarg, argv, v9);
continue;
case 'q':
v7 |= 4u;
v6 = xstrdup(optarg, argv, v9);
continue;
case 'u':
v7 |= 1u;
continue;
default:
goto LABEL_9;
}
}
break;
}
v12 = 0LL;
if ( optind < argc )
v12 = xstrdup(argv[optind], 0LL, v9);
if ( func1(v7) )
{
v13 = read_config_file(v4, v12);
v14 = v13;
v10 = v7 & 1;
if ( (v7 & 1) != 0 )
v10 = do_update(v13);
if ( (v7 & 4) != 0 )
v10 = do_query(v14, v6);
xfree(v4);
xfree(v6);
xfree(v5);
config_delete(v14);
}
else
{
LABEL_9:
func0();
v10 = 1;
}
return v10;
}

original_code:
int main(int argc, char *argv[])
{
    int opt;
    int options = 0;
    char *config_file = xstrdup(Default_Config_Path);
    char *query_string = ((void *)0);
    char *logging_spec = ((void *)0);
    char *argument = ((void *)0);
    int ret = 0;
    while ( (opt = getopt(argc, argv, "uc:q:l:h")) != -1) {
        switch (opt) {
            case 'u':
                options |= (1<<0);
                break;
            case 'c':
                options |= (1<<1);
                config_file = xstrdup(optarg);
                break;
            case 'q':
                options |= (1<<2);
                query_string = xstrdup(optarg);
                break;
            case 'l':
                options |= (1<<3);
                logging_spec = xstrdup(optarg);
                break;
            case 'h':
                options |= (1<<4);
                break;
            default:
                usage();
                return 1;
        }
    }
    if (optind < argc) {
        argument = xstrdup(argv[optind]);
    }
    if (!are_options_valid(options, argument)) {
        usage();
        return 1;
    }
    struct config *config = read_config_file(config_file);
    if (options & (1<<3)) {
        logging_config(logging_spec);
    }
    if (options & (1<<0)) {
        ret = do_update(config);
    }
    if (options & (1<<2)) {
        ret = do_query(config, query_string);
    }
    xfree(config_file);
    xfree(query_string);
    xfree(logging_spec);
    config_delete(config);
    return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: ret int

variable_types: struct config { char *update_server; char **repositories; char *bindb_dir; char *bindb_file; } *


decompiled_code:
_BOOL8 __fastcall slist_empty(_QWORD *a1)
{
_BOOL8 result; // rax

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

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

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

original_code:
static inline int
slist_empty(struct slist *slist)
{
    return !slist->head && !slist->tail;
}

variable_types: struct slist { struct slist_entry { void *data; struct slist_entry *next; } *head; struct slist_entry *tail; } *

user_defined_types: struct slist { struct slist_entry *head; struct slist_entry *tail; }


decompiled_code:
_BOOL8 __fastcall do_query(__int64 a1, const char *a2)
{
_QWORD *v2; // rax
__int64 v3; // r12
_BOOL4 v4; // er13
__int64 i; // rbx
const char **v6; // rax

v2 = (_QWORD *)bindb_query(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), a2);
if ( v2 )
{
v3 = (__int64)v2;
v4 = slist_empty(v2);
if ( v4 )
{
fprintf(stderr, "do_query: %s not found\n", a2);
v4 = 0;
}
else
{
for ( i = slist_head(v3); i; i = slist_entry_next(i) )
{
v6 = (const char **)slist_entry_data(i);
printf("%s is found in repository %s as package %s\n", a2, *v6, v6[1]);
}
slist_delete(v3);
}
}
else
{
fprintf(stderr, "do_query: failed to query %s\n", a2);
v4 = 1;
}
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, const char *a2)
{
_QWORD *v2; // rax
__int64 v3; // r12
_BOOL4 v4; // er13
__int64 i; // rbx
const char **v6; // rax

v2 = (_QWORD *)bindb_query(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24), a2);
if ( v2 )
{
v3 = (__int64)v2;
v4 = func1(v2);
if ( v4 )
{
fprintf(stderr, "do_query: %s not found\n", a2);
v4 = 0;
}
else
{
for ( i = func0(v3); i; i = func2(i) )
{
v6 = (const char **)func3(i);
printf("%s is found in repository %s as package %s\n", a2, *v6, v6[1]);
}
slist_delete(v3);
}
}
else
{
fprintf(stderr, "do_query: failed to query %s\n", a2);
v4 = 1;
}
return v4;
}

original_code:
int do_query(struct config *config, const char *bin)
{
    struct slist *qlist = bindb_query(config->bindb_dir, config->bindb_file, bin);
    if (!qlist) {
        fprintf(stderr, "do_query: failed to query %s\n", bin);
        return 1;
    }
    if (slist_empty(qlist)) {
        fprintf(stderr, "do_query: %s not found\n", bin);
        return 0;
    }
    for (struct slist_entry *ent = slist_head(qlist);
         ent;
         ent = slist_entry_next(ent)) {
        struct bindb_qentry *qent = (struct bindb_qentry *) slist_entry_data(ent);
        printf("%s is found in repository %s as package %s\n",
               bin, qent->repository, qent->package);
    }
    slist_delete(qlist);
    return 0;
}

canonical_original_code:
int do_query(struct config *config, char *bin)
{
    struct slist *qlist = bindb_query(config->bindb_dir, config->bindb_file, bin);
    if (!qlist) {
        fprintf(stderr, "do_query: failed to query %s\n", bin);
        return 1;
    }
    if (slist_empty(qlist)) {
        fprintf(stderr, "do_query: %s not found\n", bin);
        return 0;
    }
    for (struct slist_entry *ent = slist_head(qlist);
         ent;
         ent = slist_entry_next(ent)) {
        struct bindb_qentry *qent = (struct bindb_qentry *) slist_entry_data(ent);
        printf("%s is found in repository %s as package %s\n",
               bin, qent->repository, qent->package);
    }
    slist_delete(qlist);
    return 0;
}

variable_types:
bin
char *

variable_types: struct slist_entry { void *data; struct slist_entry *next; } *

variable_types: struct bindb_qentry { char *repository; char *package; } *

user_defined_types: struct config { char *update_server; char **repositories; char *bindb_dir; char *bindb_file; }


original_code:
static char *
ttemp_parse_variable(const char *template, const char ** endp )
{
    const char *t = template;
    const char *vbeg = ((void *)0);
    const char *vend = ((void *)0);
    char *var = ((void *)0);
    int embraced = 0;
    ;
    *endp = ((void *)0);
    t++;
    if (*t == '{') {
        t++;
        embraced = 1;
    }
    for (vbeg = t; *t; t++) {
        if (!((*__ctype_b_loc ())[(int) ((*t))] & (unsigned short int) _ISalnum) && *t != '_') {
            if (embraced && *t != '}') {
                return ((void *)0);
            }
            break;
        }
    }
    vend = t;
    if (vend == vbeg) {
        return ((void *)0);
    }
    var = zmalloc(vend - vbeg + 1);
    memcpy(var, vbeg, vend - vbeg);
    *endp = vend;
    return var;
}

canonical_original_code:
static char *ttemp_parse_variable(char *template, char **endp)
{
    char *t = template;
    char *vbeg = ((void *)0);
    char *vend = ((void *)0);
    char *var = ((void *)0);
    int embraced = 0;
    ;
    *endp = ((void *)0);
    t++;
    if (*t == '{') {
        t++;
        embraced = 1;
    }
    for (vbeg = t; *t; t++) {
        if (!((*__ctype_b_loc ())[(int) ((*t))] & (unsigned short) _ISalnum) && *t != '_') {
            if (embraced && *t != '}') {
                return ((void *)0);
            }
            break;
        }
    }
    vend = t;
    if (vend == vbeg) {
        return ((void *)0);
    }
    var = zmalloc(vend - vbeg + 1);
    memcpy(var, vbeg, vend - vbeg);
    *endp = vend;
    return var;
}

variable_types:
template
char *

variable_types:
endp
char **

variable_types:
t
char *

variable_types:
vbeg
char *

variable_types:
vend
char *

variable_types:
var
char *

variable_types: embraced int

return_type: char *


decompiled_code:
__int64 __fastcall ttemp_nv_lookup(__int64 *a1, __int64 a2)
{
__int64 *v2; // rbx
__int64 v3; // rdi

v2 = a1;
v3 = *a1;
if ( v3 )
{
while ( !(unsigned int)string_eq(v3, a2) )
{
v2 += 2;
v3 = *v2;
if ( !*v2 )
return v3;
}
v3 = v2[1];
}
return v3;
}

original_code:
static const char *
ttemp_nv_lookup(struct ttemp_nv *nv, const char *name)
{
    while (nv->name) {
        ;
        if (string_eq(nv->name, name)) {
            return nv->value;
        }
        nv++;
    }
    return ((void *)0);
}

canonical_original_code:
static char *ttemp_nv_lookup(struct ttemp_nv *nv, char *name)
{
    while (nv->name) {
        ;
        if (string_eq(nv->name, name)) {
            return nv->value;
        }
        nv++;
    }
    return ((void *)0);
}

variable_types: struct ttemp_nv { char *name; char *value; } *

variable_types:
name
char *


decompiled_code:
__int64 __fastcall ttemp_fill(void *src, __int64 *a2)
{
_BYTE *v2; // r14
__int64 v3; // r12
char v4; // al
char *v5; // rbx
__int64 v6; // rbp
void *v7; // rsi
const char *v8; // rax
const char *v9; // r13
size_t v10; // rbx
size_t v11; // r15
__int64 v12; // rbp
size_t v13; // rbx
void *srca; // [rsp+18h] [rbp-40h] BYREF

v2 = src;
v3 = zmalloc(1LL);
v4 = *(_BYTE *)src;
if ( *(_BYTE *)src )
{
v5 = (char *)src;
v6 = 1LL;
do
{
if ( v4 == 36 )
{
v7 = ttemp_parse_variable((__int64)v5, &srca);
if ( !v7 || (v8 = (const char *)ttemp_nv_lookup(a2, (__int64)v7), (v9 = v8) == 0LL) )
{
xfree(v3, v7);
return 0LL;
}
v10 = v5 - v2;
v11 = strlen(v8) + v10 + v6;
v3 = xrealloc(v3, v11);
v12 = v6 - 1;
memcpy((void *)(v3 + v12), v2, v10);
strcpy((char *)(v3 + v10 + v12), v9);
v2 = srca;
v6 = v11;
v5 = (char *)srca;
}
else
{
++v5;
}
v4 = *v5;
}
while ( *v5 );
v13 = v5 - v2;
if ( v13 )
{
v3 = xrealloc(v3, v13 + v6);
memcpy((void *)(v3 + v6 - 1), v2, v13);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *src, __int64 *a2)
{
_BYTE *v2; // r14
__int64 v3; // r12
char v4; // al
char *v5; // rbx
__int64 v6; // rbp
void *v7; // rsi
const char *v8; // rax
const char *v9; // r13
size_t v10; // rbx
size_t v11; // r15
__int64 v12; // rbp
size_t v13; // rbx
void *srca; // [rsp+18h] [rbp-40h] BYREF

v2 = src;
v3 = zmalloc(1LL);
v4 = *(_BYTE *)src;
if ( *(_BYTE *)src )
{
v5 = (char *)src;
v6 = 1LL;
do
{
if ( v4 == 36 )
{
v7 = func0((__int64)v5, &srca);
if ( !v7 || (v8 = (const char *)func1(a2, (__int64)v7), (v9 = v8) == 0LL) )
{
xfree(v3, v7);
return 0LL;
}
v10 = v5 - v2;
v11 = strlen(v8) + v10 + v6;
v3 = xrealloc(v3, v11);
v12 = v6 - 1;
memcpy((void *)(v3 + v12), v2, v10);
strcpy((char *)(v3 + v10 + v12), v9);
v2 = srca;
v6 = v11;
v5 = (char *)srca;
}
else
{
++v5;
}
v4 = *v5;
}
while ( *v5 );
v13 = v5 - v2;
if ( v13 )
{
v3 = xrealloc(v3, v13 + v6);
memcpy((void *)(v3 + v6 - 1), v2, v13);
}
}
return v3;
}

original_code:
const char *
ttemp_fill(const char *template, struct ttemp_nv *nv)
{
    const char *start = template;
    const char *t = template;
    char *filled = zmalloc(1);
    size_t len = 1;
    size_t nadd = 0;
    size_t plen = 0;
    const char *variable;
    const char *value;
    const char *next;
    while (*t) {
        if (*t == '$') {
            variable = ttemp_parse_variable(t, &next);
            if (!variable) {
                goto error;
            }
            value = ttemp_nv_lookup(nv, variable);
            if (!value) {
                goto error;
            }
            plen = t - start;
            nadd = plen + strlen(value);
            filled = xrealloc(filled, nadd + len);
            memcpy(filled + len - 1, start, plen);
            strcpy(filled + len - 1 + plen, value);
            len += nadd;
            t = start = next;
        } else {
            t++;
        }
    }
    nadd = plen = t - start;
    if (nadd) {
        filled = xrealloc(filled, nadd + len);
        memcpy(filled + len - 1, start, plen);
    }
    return filled;
error:
    xfree(filled);
    return ((void *)0);
}

canonical_original_code:
char *ttemp_fill(char *template, struct ttemp_nv *nv)
{
    char *start = template;
    char *t = template;
    char *filled = zmalloc(1);
    unsigned long len = 1;
    unsigned long nadd = 0;
    unsigned long plen = 0;
    char *variable;
    char *value;
    char *next;
    while (*t) {
        if (*t == '$') {
            variable = ttemp_parse_variable(t, &next);
            if (!variable) {
                goto error;
            }
            value = ttemp_nv_lookup(nv, variable);
            if (!value) {
                goto error;
            }
            plen = t - start;
            nadd = plen + strlen(value);
            filled = xrealloc(filled, nadd + len);
            memcpy(filled + len - 1, start, plen);
            strcpy(filled + len - 1 + plen, value);
            len += nadd;
            t = start = next;
        } else {
            t++;
        }
    }
    nadd = plen = t - start;
    if (nadd) {
        filled = xrealloc(filled, nadd + len);
        memcpy(filled + len - 1, start, plen);
    }
    return filled;
error:
    xfree(filled);
    return ((void *)0);
}

variable_types:
start
char *

variable_types:
filled
char *

variable_types:
len
unsigned long

variable_types:
nadd
unsigned long

variable_types:
plen
unsigned long

variable_types:
variable
char *

variable_types:
value
char *

variable_types:
next
char *

user_defined_types: struct ttemp_nv { char *name; char *value; }


xfree

decompiled_code:
void __fastcall xfree(void *a1)
{
free(a1);
}

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

original_code:
void
xfree(void *p)
{
    free(p);
}

canonical_original_code:
void xfree(void *p)
{
    free(p);
}

variable_types:
p
void *


decompiled_code:
_BOOL8 __fastcall double_eq(double a1, double a2)
{
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a1 - a2) & LC6) < 2.220446049250313e-16;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(double a1, double a2)
{
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a1 - a2) & LC6) < 2.220446049250313e-16;
}

variable_types: x double

variable_types: y double


decompiled_code:
_BOOL8 __fastcall string_eq(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int string_eq(const char *x, const char *y)
{
    return strcmp(x, y) == 0;
}

canonical_original_code:
int string_eq(char *x, char *y)
{
    return strcmp(x, y) == 0;
}

variable_types:
x
char *

variable_types:
y
char *


decompiled_code:
char *__fastcall j_status_string(int a1)
{
return J_Status_String[a1];
}

canonical_decompiled_code:
char *__fastcall func0(int a1)
{
return J_Status_String[a1];
}

original_code:
static const char *
j_status_string(j_status_t s)
{
    ;
    return J_Status_String[s];
}

canonical_original_code:
static char *j_status_string(enum j_status s)
{
    ;
    return J_Status_String[s];
}

variable_types: enum j_status { J_OK=0, J_NotFound=1, J_BadType=2, J_EmptyArray=3, J_Max=4 }


decompiled_code:
__int64 config_new()
{
return zmalloc(32LL);
}

canonical_decompiled_code:
__int64 func3()
{
return zmalloc(32LL);
}

original_code:
struct config *
config_new()
{
    return zmalloc(sizeof(struct config));
}

canonical_original_code:
struct config *config_new()
{
    return zmalloc(sizeof(struct config));
}

return_type: struct config { char *update_server; char **repositories; char *bindb_dir; char *bindb_file; } *


decompiled_code:
__int64 __fastcall config_delete(_QWORD *a1)
{
__int64 *v2; // rbx
__int64 i; // rdi
__int64 result; // rax

if ( a1 )
{
xfree(*a1);
v2 = (__int64 *)a1[1];
if ( v2 )
{
for ( i = *v2; *v2; i = *v2 )
{
xfree(i);
++v2;
}
xfree(a1[1]);
}
xfree(a1[2]);
result = xfree(a1[3]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
__int64 *v2; // rbx
__int64 i; // rdi
__int64 result; // rax

if ( a1 )
{
xfree(*a1);
v2 = (__int64 *)a1[1];
if ( v2 )
{
for ( i = *v2; *v2; i = *v2 )
{
xfree(i);
++v2;
}
xfree(a1[1]);
}
xfree(a1[2]);
result = xfree(a1[3]);
}
return result;
}

original_code:
void config_delete(struct config *config)
{
    if (!config)
        return;
    xfree(config->update_server);
    if (config->repositories) {
        for (char **repo = config->repositories; *repo; repo++) {
            xfree(*repo);
        }
        xfree(config->repositories);
    }
    xfree(config->bindb_dir);
    xfree(config->bindb_file);
}

variable_types: struct config { char *update_server; char **repositories; char *bindb_dir; char *bindb_file; } *

variable_types:
repo
char **


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

xfree(*a1);
result = xstrdup(a2);
*a1 = result;
return result;
}

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

xfree(*a1);
result = xstrdup(a2);
*a1 = result;
return result;
}

original_code:
void
dcontext_set_string(char **dst, const char *src)
{
    xfree(*dst);
    *dst = xstrdup(src);
}

canonical_original_code:
void dcontext_set_string(char **dst, char *src)
{
    xfree(*dst);
    *dst = xstrdup(src);
}

variable_types:
dst
char **

variable_types:
src
char *


decompiled_code:
__int64 __fastcall slist_delete(__int64 a1)
{
__int64 v1; // rbx
_QWORD *v2; // rbp

v1 = slist_head(a1);
while ( v1 )
{
v2 = (_QWORD *)v1;
v1 = slist_entry_next(v1);
xfree(*v2);
xfree(v2);
}
return xfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
_QWORD *v2; // rbp

v1 = func0(a1);
while ( v1 )
{
v2 = (_QWORD *)v1;
v1 = func1(v1);
xfree(*v2);
xfree(v2);
}
return xfree(a1);
}

original_code:
void
slist_delete(struct slist *slist)
{
    struct slist_entry *next;
    for (struct slist_entry *ent = slist_head(slist);
         ent;
         ent = next) {
        next = slist_entry_next(ent);
        xfree(ent->data);
        xfree(ent);
    }
    xfree(slist);
}

variable_types: struct slist { struct slist_entry { void *data; struct slist_entry *next; } *head; struct slist_entry *tail; } *


canonical_decompiled_code:
_BOOL8 __fastcall func0(_QWORD *a1)
{
_BOOL8 result; // rax

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

canonical_original_code:
static inline int slist_empty(struct slist *slist)
{
    return !slist->head && !slist->tail;
}

user_defined_types: struct slist_entry { void *data; struct slist_entry *next; }


decompiled_code:
__int64 slist_new()
{
return zmalloc(16LL);
}

canonical_decompiled_code:
__int64 func2()
{
return zmalloc(16LL);
}

original_code:
static inline struct slist *
slist_new()
{
    return zmalloc(sizeof(struct slist));
}

canonical_original_code:
static inline struct slist *slist_new()
{
    return zmalloc(sizeof(struct slist));
}

return_type: struct slist { struct slist_entry { void *data; struct slist_entry *next; } *head; struct slist_entry *tail; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc != 2 )
{
puts("Please use ./compile filename...");
exit(0);
}
source = fopen(argv[1], "r");
if ( !source )
{
printf(&byte_277, argv[1]);
exit(1);
}
puts("Press any key to begin lexical ananlyze...");
getchar();
while ( (unsigned int)getToken() )
;
fclose(source);
printf("%d lexical errors!\n", lex_error);
if ( lex_error )
exit(1);
lineno = 0;
lex_error = 0;
EOF_Flag = 0;
source = fopen(argv[1], "r");
if ( !source )
{
printf(&byte_277, argv[1]);
exit(2);
}
puts("Press any key to begin syntax analyze...");
getchar();
syntaxAnalyze();
printf("%d syntax errors!\n", syntax_error);
fclose(source);
if ( syntax_error )
exit(1);
puts("Press any key to generate objective code...");
getchar();
printCode();
puts("Press any key to interpret run the objective code...");
getchar();
InterpretRun();
return 0;
}

original_code:
int main(int argc, char* argv[])
{
    if (argc != 2)
    {
 printf("Please use ./compile filename...\n");
 exit(0);
    }
    source = fopen(argv[1], "r");
    if (source == ((void *)0))
    {
 printf("文件%s打开失败!\n", argv[1]);
 exit(1);
    }
    printf("Press any key to begin lexical ananlyze...\n");
    getchar();
    while (getToken() != ENDFILE)
 ;
    fclose(source);
    printf("%d lexical errors!\n", lex_error);
    if (lex_error != 0)
    {
 exit(1);
    }
    lineno = 0;
    lex_error = 0;
    EOF_Flag = 0;
    source = fopen(argv[1], "r");
    if (source == ((void *)0))
    {
 printf("文件%s打开失败!\n", argv[1]);
 exit(2);
    }
    printf("Press any key to begin syntax analyze...\n");
    getchar();
    syntaxAnalyze();
    printf("%d syntax errors!\n", syntax_error);
    fclose(source);
    if (syntax_error != 0)
    {
 exit(1);
    }
    printf("Press any key to generate objective code...\n");
    getchar();
    printCode();
    printf("Press any key to interpret run the objective code...\n");
    getchar();
    InterpretRun();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
 printf("Please use ./compile filename...\n");
 exit(0);
    }
    source = fopen(argv[1], "r");
    if (source == ((void *)0))
    {
 printf("文件%s打开失败!\n", argv[1]);
 exit(1);
    }
    printf("Press any key to begin lexical ananlyze...\n");
    getchar();
    while (getToken() != ENDFILE)
 ;
    fclose(source);
    printf("%d lexical errors!\n", lex_error);
    if (lex_error != 0)
    {
 exit(1);
    }
    lineno = 0;
    lex_error = 0;
    EOF_Flag = 0;
    source = fopen(argv[1], "r");
    if (source == ((void *)0))
    {
 printf("文件%s打开失败!\n", argv[1]);
 exit(2);
    }
    printf("Press any key to begin syntax analyze...\n");
    getchar();
    syntaxAnalyze();
    printf("%d syntax errors!\n", syntax_error);
    fclose(source);
    if (syntax_error != 0)
    {
 exit(1);
    }
    printf("Press any key to generate objective code...\n");
    getchar();
    printCode();
    printf("Press any key to interpret run the objective code...\n");
    getchar();
    InterpretRun();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


syntaxError

decompiled_code:
int __fastcall syntaxError(const char *a1)
{
int result; // eax

if ( !a1 )
_assert_fail("message != NULL", "syntax.c", 0x1Fu, "syntaxError");
printf("\n>>>");
result = printf("syntax error at line %d:%s", lineno, a1);
++syntax_error;
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

if ( !a1 )
_assert_fail("message != NULL", "syntax.c", 0x1Fu, "syntaxError");
printf("\n>>>");
result = printf("syntax error at line %d:%s", lineno, a1);
++syntax_error;
return result;
}

original_code:
void syntaxError(char* message)
{
    ((void) sizeof ((message != ((void *)0)) ? 1 : 0), __extension__ ({ if (message != ((void *)0)) ; else __assert_fail ("message != NULL", "syntax.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    if (message == ((void *)0))
 return;
    printf("\n>>>");
    printf("syntax error at line %d:%s", lineno, message);
    ++syntax_error;
}

canonical_original_code:
void syntaxError(char *message)
{
    ((void) sizeof ((message != ((void *)0)) ? 1 : 0), __extension__ ({ if (message != ((void *)0)) ; else __assert_fail ("message != NULL", "syntax.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    if (message == ((void *)0))
 return;
    printf("\n>>>");
    printf("syntax error at line %d:%s", lineno, message);
    ++syntax_error;
}

variable_types:
message
char *


match

decompiled_code:
int __fastcall match(int a1)
{
int result; // eax

if ( token == a1 )
{
result = getToken();
token = result;
}
else
{
syntaxError("unexpected token-> ");
printToken((unsigned int)token, &tokenString);
result = putchar(9);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
int result; // eax

if ( token == a1 )
{
result = getToken();
token = result;
}
else
{
func0("unexpected token-> ");
printToken((unsigned int)token, &tokenString);
result = putchar(9);
}
return result;
}

original_code:
void match(TokenType expected)
{
    if (token == expected)
    {
 token = getToken();
    }
    else
    {
 syntaxError("unexpected token-> ");
 printToken(token, tokenString);
 printf("	");
    }
}

canonical_original_code:
void match(enum TokenType expected)
{
    if (token == expected)
    {
 token = getToken();
    }
    else
    {
 syntaxError("unexpected token-> ");
 printToken(token, tokenString);
 printf("	");
    }
}

variable_types: enum TokenType { ENDFILE=0, ERROR=1, PROGRAM_K=2, CONST_K=3, VAR_K=4, PROCEDURE_K=5, BEGIN_K=6, END_K=7, IF_K=8, WHILE_K=9, CALL_K=10, DO_K=11, ELSE_K=12, THEN_K=13, WRITE_K=14, ODD_K=15, READ_K=16, NUM=17, ID=18, ASSIGN=19, EQ=20, LT=21, GT=22, PLUS=23, MINUS=24, TIMES=25, OVER=26, LPAREN=27, RPAREN=28, SEMI=29, COMM=30, LTEQ=31, GTEQ=32, NOEQ=33 }


Const

decompiled_code:
void Const()
{
if ( token )
{
if ( position(&tokenString) )
syntaxError(byte_CE1);
enter(3LL, &tokenString);
match(18);
match(19);
*(_DWORD *)(currentNodePtr + 52LL) = atoi(&tokenString);
match(17);
}
}

canonical_decompiled_code:
void func2()
{
if ( token )
{
if ( position(&tokenString) )
func0(byte_CE1);
enter(3LL, &tokenString);
func1(18);
func1(19);
*(_DWORD *)(currentNodePtr + 52LL) = atoi(&tokenString);
func1(17);
}
}

original_code:
void Const(void)
{
    if (token == ENDFILE)
    {
 return;
    }
    if (position(tokenString) != ((void *)0))
    {
 syntaxError("常量名已经被使用");
    }
    enter(CONSTANT, tokenString);
    match(ID);
    match(ASSIGN);
    currentNodePtr->table.val = atoi(tokenString);
    match(NUM);
}

canonical_original_code:
void Const()
{
    if (token == ENDFILE)
    {
 return;
    }
    if (position(tokenString) != ((void *)0))
    {
 syntaxError("常量名已经被使用");
    }
    enter(CONSTANT, tokenString);
    match(ID);
    match(ASSIGN);
    currentNodePtr->table.val = atoi(tokenString);
    match(NUM);
}


condecl

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

if ( token )
{
match(3);
Const();
while ( token == 30 )
{
match(30);
Const();
}
result = match(29);
}
return result;
}

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

if ( token )
{
func1(3);
func2();
while ( token == 30 )
{
func1(30);
func2();
}
result = func1(29);
}
return result;
}

original_code:
void condecl(void)
{
    if (token == ENDFILE)
    {
 return;
    }
    match(CONST_K);
    Const();
    while (token == COMM)
    {
 match(COMM);
 Const();
    }
    match(SEMI);
}

canonical_original_code:
void condecl()
{
    if (token == ENDFILE)
    {
 return;
    }
    match(CONST_K);
    Const();
    while (token == COMM)
    {
 match(COMM);
 Const();
    }
    match(SEMI);
}


vardecl

decompiled_code:
void vardecl()
{
if ( token )
{
match(4);
if ( position(&tokenString) )
syntaxError(byte_CFA);
enter(2LL, &tokenString);
++numVar;
match(18);
while ( token == 30 )
{
match(30);
if ( position(&tokenString) )
syntaxError(byte_CFA);
enter(2LL, &tokenString);
++numVar;
match(18);
}
match(29);
}
}

canonical_decompiled_code:
void func4()
{
if ( token )
{
func1(4);
if ( position(&tokenString) )
func0(byte_CFA);
enter(2LL, &tokenString);
++numVar;
func1(18);
while ( token == 30 )
{
func1(30);
if ( position(&tokenString) )
func0(byte_CFA);
enter(2LL, &tokenString);
++numVar;
func1(18);
}
func1(29);
}
}

original_code:
void vardecl(void)
{
    if (token == ENDFILE)
    {
 return;
    }
    match(VAR_K);
    if (position(tokenString) != ((void *)0))
    {
 syntaxError("变量名已经被使用");
    }
    enter(VARIABLE, tokenString);
    ++numVar;
    match(ID);
    while (token == COMM)
    {
 match(COMM);
 if (position(tokenString) != ((void *)0))
 {
     syntaxError("变量名已经被使用");
 }
 enter(VARIABLE, tokenString);
 ++numVar;
 match(ID);
    }
    match(SEMI);
}

canonical_original_code:
void vardecl()
{
    if (token == ENDFILE)
    {
 return;
    }
    match(VAR_K);
    if (position(tokenString) != ((void *)0))
    {
 syntaxError("变量名已经被使用");
    }
    enter(VARIABLE, tokenString);
    ++numVar;
    match(ID);
    while (token == COMM)
    {
 match(COMM);
 if (position(tokenString) != ((void *)0))
 {
     syntaxError("变量名已经被使用");
 }
 enter(VARIABLE, tokenString);
 ++numVar;
 match(ID);
    }
    match(SEMI);
}


lop

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

result = token;
if ( token )
{
switch ( token )
{
case 20:
result = match(20);
break;
case 33:
result = match(33);
break;
case 21:
result = match(21);
break;
case 31:
result = match(31);
break;
case 22:
result = match(22);
break;
case 32:
result = match(32);
break;
}
}
return result;
}

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

result = token;
if ( token )
{
switch ( token )
{
case 20:
result = func1(20);
break;
case 33:
result = func1(33);
break;
case 21:
result = func1(21);
break;
case 31:
result = func1(31);
break;
case 22:
result = func1(22);
break;
case 32:
result = func1(32);
break;
}
}
return result;
}

original_code:
void lop(void)
{
    if (token == ENDFILE)
    {
 return;
    }
    if (token == EQ)
    {
 match(EQ);
    }
    else if (token == NOEQ)
    {
 match(NOEQ);
    }
    else if (token == LT)
    {
 match(LT);
    }
    else if (token == LTEQ)
    {
 match(LTEQ);
    }
    else if (token == GT)
    {
 match(GT);
    }
    else if (token == GTEQ)
    {
 match(GTEQ);
    }
}

canonical_original_code:
void lop()
{
    if (token == ENDFILE)
    {
 return;
    }
    if (token == EQ)
    {
 match(EQ);
    }
    else if (token == NOEQ)
    {
 match(NOEQ);
    }
    else if (token == LT)
    {
 match(LT);
    }
    else if (token == LTEQ)
    {
 match(LTEQ);
    }
    else if (token == GT)
    {
 match(GT);
    }
    else if (token == GTEQ)
    {
 match(GTEQ);
    }
}


aop

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

result = token;
if ( token )
{
if ( token == 23 )
{
result = match(23);
}
else if ( token == 24 )
{
result = match(24);
}
}
return result;
}

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

result = token;
if ( token )
{
if ( token == 23 )
{
result = func1(23);
}
else if ( token == 24 )
{
result = func1(24);
}
}
return result;
}

original_code:
void aop(void)
{
    if (token == ENDFILE)
    {
 return;
    }
    if (token == PLUS)
    {
 match(PLUS);
    }
    else if (token == MINUS)
    {
 match(MINUS);
    }
}

canonical_original_code:
void aop()
{
    if (token == ENDFILE)
    {
 return;
    }
    if (token == PLUS)
    {
 match(PLUS);
    }
    else if (token == MINUS)
    {
 match(MINUS);
    }
}


mop

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

result = token;
if ( token )
{
if ( token == 25 )
{
result = match(25);
}
else if ( token == 26 )
{
result = match(26);
}
}
return result;
}

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

result = token;
if ( token )
{
if ( token == 25 )
{
result = func1(25);
}
else if ( token == 26 )
{
result = func1(26);
}
}
return result;
}

original_code:
void mop(void)
{
    if (token == ENDFILE)
    {
 return;
    }
    if (token == TIMES)
    {
 match(TIMES);
    }
    else if (token == OVER)
    {
 match(OVER);
    }
}

canonical_original_code:
void mop()
{
    if (token == ENDFILE)
    {
 return;
    }
    if (token == TIMES)
    {
 match(TIMES);
    }
    else if (token == OVER)
    {
 match(OVER);
    }
}


term

decompiled_code:
__int64 term()
{
int v0; // ebx
__int64 result; // rax

if ( token )
{
factor();
v0 = token;
for ( result = (unsigned int)(token - 25); (unsigned int)result <= 1; result = (unsigned int)(token - 25) )
{
mop();
factor();
if ( v0 == 25 )
{
gen(1LL, 0LL, 4LL);
}
else if ( v0 == 26 )
{
gen(1LL, 0LL, 5LL);
}
v0 = token;
}
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx
__int64 result; // rax

if ( token )
{
func17();
v0 = token;
for ( result = (unsigned int)(token - 25); (unsigned int)result <= 1; result = (unsigned int)(token - 25) )
{
func7();
func17();
if ( v0 == 25 )
{
gen(1LL, 0LL, 4LL);
}
else if ( v0 == 26 )
{
gen(1LL, 0LL, 5LL);
}
v0 = token;
}
}
return result;
}

original_code:
void term(void)
{
    TokenType temp;
    if (token == ENDFILE)
    {
 return;
    }
    factor();
    while (token == TIMES || token == OVER)
    {
 temp = token;
 mop();
 factor();
 if (temp == TIMES)
 {
     gen(OPR, 0, 4);
 }
 else if (temp == OVER)
 {
     gen(OPR, 0, 5);
 }
    }
}

canonical_original_code:
void term()
{
    enum TokenType temp;
    if (token == ENDFILE)
    {
 return;
    }
    factor();
    while (token == TIMES || token == OVER)
    {
 temp = token;
 mop();
 factor();
 if (temp == TIMES)
 {
     gen(OPR, 0, 4);
 }
 else if (temp == OVER)
 {
     gen(OPR, 0, 5);
 }
    }
}

user_defined_types: enum TokenType { ENDFILE=0, ERROR=1, PROGRAM_K=2, CONST_K=3, VAR_K=4, PROCEDURE_K=5, BEGIN_K=6, END_K=7, IF_K=8, WHILE_K=9, CALL_K=10, DO_K=11, ELSE_K=12, THEN_K=13, WRITE_K=14, ODD_K=15, READ_K=16, NUM=17, ID=18, ASSIGN=19, EQ=20, LT=21, GT=22, PLUS=23, MINUS=24, TIMES=25, OVER=26, LPAREN=27, RPAREN=28, SEMI=29, COMM=30, LTEQ=31, GTEQ=32, NOEQ=33 }


Exp

decompiled_code:
__int64 Exp()
{
__int64 result; // rax
int v1; // ebx

result = (unsigned int)token;
if ( token )
{
if ( token == 23 )
{
match(23);
}
else if ( token == 24 )
{
match(24);
}
term();
v1 = token;
for ( result = (unsigned int)(token - 23); (unsigned int)result <= 1; result = (unsigned int)(token - 23) )
{
aop();
term();
if ( v1 == 23 )
{
gen(1LL, 0LL, 2LL);
}
else if ( v1 == 24 )
{
gen(1LL, 0LL, 3LL);
}
v1 = token;
}
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
int v1; // ebx

result = (unsigned int)token;
if ( token )
{
if ( token == 23 )
{
func1(23);
}
else if ( token == 24 )
{
func1(24);
}
func8();
v1 = token;
for ( result = (unsigned int)(token - 23); (unsigned int)result <= 1; result = (unsigned int)(token - 23) )
{
func6();
func8();
if ( v1 == 23 )
{
gen(1LL, 0LL, 2LL);
}
else if ( v1 == 24 )
{
gen(1LL, 0LL, 3LL);
}
v1 = token;
}
}
return result;
}

original_code:
void Exp(void)
{
    TokenType temp;
    if (token == ENDFILE)
    {
 return;
    }
    if (token == PLUS)
    {
 match(PLUS);
    }
    else if (token == MINUS)
    {
 match(MINUS);
    }
    term();
    while (token == PLUS || token == MINUS)
    {
 temp = token;
 aop();
 term();
 if (temp == PLUS)
 {
     gen(OPR, 0, 2);
 }
 else if (temp == MINUS)
 {
     gen(OPR, 0, 3);
 }
    }
}

canonical_original_code:
void Exp()
{
    enum TokenType temp;
    if (token == ENDFILE)
    {
 return;
    }
    if (token == PLUS)
    {
 match(PLUS);
    }
    else if (token == MINUS)
    {
 match(MINUS);
    }
    term();
    while (token == PLUS || token == MINUS)
    {
 temp = token;
 aop();
 term();
 if (temp == PLUS)
 {
     gen(OPR, 0, 2);
 }
 else if (temp == MINUS)
 {
     gen(OPR, 0, 3);
 }
    }
}


lexp

decompiled_code:
__int64 lexp()
{
__int64 result; // rax
int v1; // ebx

result = (unsigned int)token;
if ( token )
{
if ( token == 15 )
{
match(15);
Exp();
result = gen(1LL, 0LL, 6LL);
}
else
{
Exp();
v1 = token;
lop();
result = Exp();
switch ( v1 )
{
case 20:
result = gen(1LL, 0LL, 8LL);
break;
case 33:
result = gen(1LL, 0LL, 9LL);
break;
case 21:
result = gen(1LL, 0LL, 10LL);
break;
case 31:
result = gen(1LL, 0LL, 13LL);
break;
case 32:
result = gen(1LL, 0LL, 11LL);
break;
case 22:
result = gen(1LL, 0LL, 12LL);
break;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax
int v1; // ebx

result = (unsigned int)token;
if ( token )
{
if ( token == 15 )
{
func1(15);
func9();
result = gen(1LL, 0LL, 6LL);
}
else
{
func9();
v1 = token;
func5();
result = func9();
switch ( v1 )
{
case 20:
result = gen(1LL, 0LL, 8LL);
break;
case 33:
result = gen(1LL, 0LL, 9LL);
break;
case 21:
result = gen(1LL, 0LL, 10LL);
break;
case 31:
result = gen(1LL, 0LL, 13LL);
break;
case 32:
result = gen(1LL, 0LL, 11LL);
break;
case 22:
result = gen(1LL, 0LL, 12LL);
break;
}
}
}
return result;
}

original_code:
void lexp(void)
{
    TokenType temp;
    if (token == ENDFILE)
    {
 return;
    }
    if (token == ODD_K)
    {
 match(ODD_K);
 Exp();
 gen(OPR, 0, 6);
    }
    else
    {
 Exp();
 temp = token;
 lop();
 Exp();
 if (temp == EQ)
 {
     gen(OPR, 0, 8);
 }
 else if (temp == NOEQ)
 {
     gen(OPR, 0, 9);
 }
 else if (temp == LT)
 {
     gen(OPR, 0, 10);
 }
 else if (temp == LTEQ)
 {
     gen(OPR, 0, 13);
 }
 else if (temp == GTEQ)
 {
     gen(OPR, 0, 11);
 }
 else if (temp == GT)
 {
     gen(OPR, 0, 12);
 }
    }
}

canonical_original_code:
void lexp()
{
    enum TokenType temp;
    if (token == ENDFILE)
    {
 return;
    }
    if (token == ODD_K)
    {
 match(ODD_K);
 Exp();
 gen(OPR, 0, 6);
    }
    else
    {
 Exp();
 temp = token;
 lop();
 Exp();
 if (temp == EQ)
 {
     gen(OPR, 0, 8);
 }
 else if (temp == NOEQ)
 {
     gen(OPR, 0, 9);
 }
 else if (temp == LT)
 {
     gen(OPR, 0, 10);
 }
 else if (temp == LTEQ)
 {
     gen(OPR, 0, 13);
 }
 else if (temp == GTEQ)
 {
     gen(OPR, 0, 11);
 }
 else if (temp == GT)
 {
     gen(OPR, 0, 12);
 }
    }
}


statement

decompiled_code:
int statement()
{
__int64 v0; // rax
__int64 v1; // rbx
int v2; // ebx
unsigned int v3; // ebp
int v4; // ebx
__int64 v5; // rax
__int64 v6; // rax

LODWORD(v0) = token;
if ( token )
{
switch ( token )
{
case 18:
v1 = position(&tokenString);
match(18);
match(19);
Exp();
LODWORD(v0) = gen(3LL, abs32(*(_DWORD *)(v1 + 48) - level), *(unsigned int *)(v1 + 56));
return v0;
case 8:
match(8);
lexp();
match(13);
gen(7LL, 0LL, 0LL);
v2 = dword_1038;
statement();
v0 = code + 12LL * v2;
*(_DWORD *)(v0 + 8) = dword_1038 + 1;
if ( token == 12 )
{
match(12);
LODWORD(v0) = statement();
}
break;
case 9:
match(9);
v3 = dword_1038 + 1;
lexp();
gen(7LL, 0LL, 0LL);
v4 = dword_1038;
match(11);
statement();
gen(6LL, 0LL, v3);
v0 = code + 12LL * v4;
*(_DWORD *)(v0 + 8) = dword_1038 + 1;
return v0;
case 10:
match(10);
v5 = position(&tokenString);
if ( !v5 )
{
syntaxError(byte_D13);
exit(2);
}
gen(4LL, abs32(*(_DWORD *)(v5 + 48) - level), *(unsigned int *)(v5 + 56));
LODWORD(v0) = match(18);
if ( token == 27 )
{
match(27);
Exp();
while ( token == 30 )
{
match(30);
Exp();
}
goto LABEL_29;
}
break;
default:
switch ( token )
{
case 6:
tag = 1;
LODWORD(v0) = body();
tag = 0;
return v0;
case 16:
match(16);
match(27);
gen(1LL, 0LL, 16LL);
v6 = position(&tokenString);
if ( !v6 )
{
syntaxError(byte_D2F);
exit(2);
}
gen(8LL, abs32(*(_DWORD *)(v6 + 48) - level), *(unsigned int *)(v6 + 56));
match(18);
while ( token == 30 )
{
match(30);
match(18);
}
break;
case 14:
match(14);
match(27);
Exp();
gen(9LL, 0LL, 0LL);
gen(1LL, 0LL, 15LL);
while ( token == 30 )
{
match(30);
Exp();
gen(9LL, 0LL, 0LL);
gen(1LL, 0LL, 15LL);
}
break;
default:
syntaxError("unexpected token-> ");
printToken((unsigned int)token, &tokenString);
LODWORD(v0) = getToken();
token = v0;
return v0;
}
LABEL_29:
LODWORD(v0) = match(28);
return v0;
}
}
return v0;
}

canonical_decompiled_code:
int func11()
{
__int64 v0; // rax
__int64 v1; // rbx
int v2; // ebx
unsigned int v3; // ebp
int v4; // ebx
__int64 v5; // rax
__int64 v6; // rax

LODWORD(v0) = token;
if ( token )
{
switch ( token )
{
case 18:
v1 = position(&tokenString);
func1(18);
func1(19);
func9();
LODWORD(v0) = gen(3LL, abs32(*(_DWORD *)(v1 + 48) - level), *(unsigned int *)(v1 + 56));
return v0;
case 8:
func1(8);
func10();
func1(13);
gen(7LL, 0LL, 0LL);
v2 = dword_1038;
func11();
v0 = code + 12LL * v2;
*(_DWORD *)(v0 + 8) = dword_1038 + 1;
if ( token == 12 )
{
func1(12);
LODWORD(v0) = func11();
}
break;
case 9:
func1(9);
v3 = dword_1038 + 1;
func10();
gen(7LL, 0LL, 0LL);
v4 = dword_1038;
func1(11);
func11();
gen(6LL, 0LL, v3);
v0 = code + 12LL * v4;
*(_DWORD *)(v0 + 8) = dword_1038 + 1;
return v0;
case 10:
func1(10);
v5 = position(&tokenString);
if ( !v5 )
{
func0(byte_D13);
exit(2);
}
gen(4LL, abs32(*(_DWORD *)(v5 + 48) - level), *(unsigned int *)(v5 + 56));
LODWORD(v0) = func1(18);
if ( token == 27 )
{
func1(27);
func9();
while ( token == 30 )
{
func1(30);
func9();
}
goto LABEL_29;
}
break;
default:
switch ( token )
{
case 6:
tag = 1;
LODWORD(v0) = func12();
tag = 0;
return v0;
case 16:
func1(16);
func1(27);
gen(1LL, 0LL, 16LL);
v6 = position(&tokenString);
if ( !v6 )
{
func0(byte_D2F);
exit(2);
}
gen(8LL, abs32(*(_DWORD *)(v6 + 48) - level), *(unsigned int *)(v6 + 56));
func1(18);
while ( token == 30 )
{
func1(30);
func1(18);
}
break;
case 14:
func1(14);
func1(27);
func9();
gen(9LL, 0LL, 0LL);
gen(1LL, 0LL, 15LL);
while ( token == 30 )
{
func1(30);
func9();
gen(9LL, 0LL, 0LL);
gen(1LL, 0LL, 15LL);
}
break;
default:
func0("unexpected token-> ");
printToken((unsigned int)token, &tokenString);
LODWORD(v0) = getToken();
token = v0;
return v0;
}
LABEL_29:
LODWORD(v0) = func1(28);
return v0;
}
}
return v0;
}

original_code:
void statement(void)
{
    int cx0, cx1;
    struct BSTNode *index;
    if (token == ENDFILE)
    {
 return;
    }
    if (token == ID)
    {
 index = position(tokenString);
 match(ID);
 match(ASSIGN);
 Exp();
 gen(STO, abs(index->table.lev - level), index->table.addr);
    }
    else if (token == IF_K)
    {
 match(IF_K);
 lexp();
 match(THEN_K);
 gen(JPC, 0, 0);
 cx0 = cx;
 statement();
 code[cx0].offset = cx + 1;
 if (token == ELSE_K)
 {
     match(ELSE_K);
     statement();
 }
    }
    else if (token == WHILE_K)
    {
 match(WHILE_K);
 cx1 = cx + 1;
 lexp();
 gen(JPC, 0, 0);
 cx0 = cx;
 match(DO_K);
 statement();
 gen(JMP, 0, cx1);
 code[cx0].offset = cx + 1;
    }
    else if (token == CALL_K)
    {
 match(CALL_K);
 index = position(tokenString);
 if (index == ((void *)0))
 {
     syntaxError("当前过程名没有定义");
     exit(2);
 }
 gen(CAL, abs(index->table.lev - level), index->table.addr);
 match(ID);
 if (token == LPAREN)
 {
     match(LPAREN);
     Exp();
     while (token == COMM)
     {
  match(COMM);
  Exp();
     }
     match(RPAREN);
 }
    }
    else if (token == BEGIN_K)
    {
 tag = 1;
 body();
 tag = 0;
    }
    else if (token == READ_K)
    {
 match(READ_K);
 match(LPAREN);
 gen(OPR, 0, 16);
 index = position(tokenString);
 if (index == ((void *)0))
 {
     syntaxError("当前变量名没有定义");
     exit(2);
 }
 gen(RED, abs(index->table.lev - level), index->table.addr);
 match(ID);
 while (token == COMM)
 {
     match(COMM);
     match(ID);
 }
 match(RPAREN);
    }
    else if (token == WRITE_K)
    {
 match(WRITE_K);
 match(LPAREN);
 Exp();
 gen(WRT, 0, 0);
 gen(OPR, 0, 15);
 while (token == COMM)
 {
     match(COMM);
     Exp();
     gen(WRT, 0, 0);
     gen(OPR, 0, 15);
 }
 match(RPAREN);
    }
    else if (token != ENDFILE)
    {
 syntaxError("unexpected token-> ");
 printToken(token, tokenString);
 token = getToken();
    }
}

canonical_original_code:
void statement()
{
    int cx0; int cx1;
    struct BSTNode *index;
    if (token == ENDFILE)
    {
 return;
    }
    if (token == ID)
    {
 index = position(tokenString);
 match(ID);
 match(ASSIGN);
 Exp();
 gen(STO, abs(index->table.lev - level), index->table.addr);
    }
    else if (token == IF_K)
    {
 match(IF_K);
 lexp();
 match(THEN_K);
 gen(JPC, 0, 0);
 cx0 = cx;
 statement();
 code[cx0].offset = cx + 1;
 if (token == ELSE_K)
 {
     match(ELSE_K);
     statement();
 }
    }
    else if (token == WHILE_K)
    {
 match(WHILE_K);
 cx1 = cx + 1;
 lexp();
 gen(JPC, 0, 0);
 cx0 = cx;
 match(DO_K);
 statement();
 gen(JMP, 0, cx1);
 code[cx0].offset = cx + 1;
    }
    else if (token == CALL_K)
    {
 match(CALL_K);
 index = position(tokenString);
 if (index == ((void *)0))
 {
     syntaxError("当前过程名没有定义");
     exit(2);
 }
 gen(CAL, abs(index->table.lev - level), index->table.addr);
 match(ID);
 if (token == LPAREN)
 {
     match(LPAREN);
     Exp();
     while (token == COMM)
     {
  match(COMM);
  Exp();
     }
     match(RPAREN);
 }
    }
    else if (token == BEGIN_K)
    {
 tag = 1;
 body();
 tag = 0;
    }
    else if (token == READ_K)
    {
 match(READ_K);
 match(LPAREN);
 gen(OPR, 0, 16);
 index = position(tokenString);
 if (index == ((void *)0))
 {
     syntaxError("当前变量名没有定义");
     exit(2);
 }
 gen(RED, abs(index->table.lev - level), index->table.addr);
 match(ID);
 while (token == COMM)
 {
     match(COMM);
     match(ID);
 }
 match(RPAREN);
    }
    else if (token == WRITE_K)
    {
 match(WRITE_K);
 match(LPAREN);
 Exp();
 gen(WRT, 0, 0);
 gen(OPR, 0, 15);
 while (token == COMM)
 {
     match(COMM);
     Exp();
     gen(WRT, 0, 0);
     gen(OPR, 0, 15);
 }
 match(RPAREN);
    }
    else if (token != ENDFILE)
    {
 syntaxError("unexpected token-> ");
 printToken(token, tokenString);
 token = getToken();
    }
}

variable_types: struct BSTNode { struct symbolTable { char name[-1]; enum TypeInSymbolTable { MAINPROCEDURE=0, PROCEDURE=1, VARIABLE=2, CONSTANT=3 } kind; int lev; int val; int addr; int size; } table; int bf; struct BSTNode *lchild; struct BSTNode *rchild; struct BSTNode *next; struct BSTNode *prev; } *

user_defined_types: struct BSTNode { struct symbolTable table; int bf; struct BSTNode *lchild; struct BSTNode *rchild; struct BSTNode *next; struct BSTNode *prev; }

user_defined_types: struct symbolTable { char name[-1]; enum TypeInSymbolTable kind; int lev; int val; int addr; int size; }


body

decompiled_code:
void body()
{
__int64 v0; // rax
__int64 v1; // rdx

if ( token )
{
match(6);
if ( !tag )
{
gen(5LL, 0LL, *(unsigned int *)(currentProcAddr + 60LL));
v0 = currentProcAddr;
*(_DWORD *)(currentProcAddr + 56LL) = dword_1038;
v1 = *(_QWORD *)(v0 + 88);
if ( v1 )
{
if ( *(_DWORD *)(v0 + 44) )
gen(4LL, abs32(level - *(_DWORD *)(v1 + 48)), *(unsigned int *)(v1 + 56));
}
}
statement();
while ( token == 29 )
{
match(29);
statement();
}
match(7);
if ( !tag )
{
--level;
gen(1LL, 0LL, 0LL);
}
}
}

canonical_decompiled_code:
void func12()
{
__int64 v0; // rax
__int64 v1; // rdx

if ( token )
{
func1(6);
if ( !tag )
{
gen(5LL, 0LL, *(unsigned int *)(currentProcAddr + 60LL));
v0 = currentProcAddr;
*(_DWORD *)(currentProcAddr + 56LL) = dword_1038;
v1 = *(_QWORD *)(v0 + 88);
if ( v1 )
{
if ( *(_DWORD *)(v0 + 44) )
gen(4LL, abs32(level - *(_DWORD *)(v1 + 48)), *(unsigned int *)(v1 + 56));
}
}
func11();
while ( token == 29 )
{
func1(29);
func11();
}
func1(7);
if ( !tag )
{
--level;
gen(1LL, 0LL, 0LL);
}
}
}

original_code:
void body(void)
{
    struct BSTNode * temp;
    if (token == ENDFILE)
    {
 return;
    }
    match(BEGIN_K);
    if (tag == 0)
    {
 gen(INT, 0, currentProcAddr->table.size);
 currentProcAddr->table.addr = cx;
        temp = currentProcAddr->next;
 if (temp != ((void *)0) && currentProcAddr->table.kind != MAINPROCEDURE)
 {
     gen(CAL, abs(level - temp->table.lev), temp->table.addr);
 }
    }
    statement();
    while (token == SEMI)
    {
 match(SEMI);
 statement();
    }
    match(END_K);
    if (tag == 0)
    {
 --level;
    }
    if (tag == 0)
    {
 gen(OPR, 0, 0);
    }
}

canonical_original_code:
void body()
{
    struct BSTNode *temp;
    if (token == ENDFILE)
    {
 return;
    }
    match(BEGIN_K);
    if (tag == 0)
    {
 gen(INT, 0, currentProcAddr->table.size);
 currentProcAddr->table.addr = cx;
        temp = currentProcAddr->next;
 if (temp != ((void *)0) && currentProcAddr->table.kind != MAINPROCEDURE)
 {
     gen(CAL, abs(level - temp->table.lev), temp->table.addr);
 }
    }
    statement();
    while (token == SEMI)
    {
 match(SEMI);
 statement();
    }
    match(END_K);
    if (tag == 0)
    {
 --level;
    }
    if (tag == 0)
    {
 gen(OPR, 0, 0);
    }
}

user_defined_types: enum TypeInSymbolTable { MAINPROCEDURE=0, PROCEDURE=1, VARIABLE=2, CONSTANT=3 }


block

decompiled_code:
__int64 block()
{
__int64 result; // rax
int v1; // ebx

gen(6LL, 0LL, 0LL);
result = (unsigned int)token;
if ( token )
{
v1 = dword_1038;
if ( token == 3 )
condecl();
if ( token == 4 )
vardecl();
*(_DWORD *)(currentProcAddr + 60LL) = numVar + 3;
numVar = 0;
if ( token == 5 )
{
procNest = 1;
proc();
}
*(_DWORD *)(code + 12LL * v1 + 8) = dword_1038 + 1;
body();
result = *(_QWORD *)(currentProcAddr + 96LL);
currentProcAddr = result;
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
int v1; // ebx

gen(6LL, 0LL, 0LL);
result = (unsigned int)token;
if ( token )
{
v1 = dword_1038;
if ( token == 3 )
func3();
if ( token == 4 )
func4();
*(_DWORD *)(currentProcAddr + 60LL) = numVar + 3;
numVar = 0;
if ( token == 5 )
{
procNest = 1;
func16();
}
*(_DWORD *)(code + 12LL * v1 + 8) = dword_1038 + 1;
func12();
result = *(_QWORD *)(currentProcAddr + 96LL);
currentProcAddr = result;
}
return result;
}

original_code:
void block(void)
{
    int cx0;
    int tempAddr;
    gen(JMP, 0, 0);
    cx0 = cx;
    if (token == ENDFILE)
 return;
    if (token == CONST_K)
    {
 condecl();
    }
    if (token == VAR_K)
    {
 vardecl();
    }
    currentProcAddr->table.size = numVar + 3;
    numVar = 0;
    if (token == PROCEDURE_K)
    {
 procNest = 1;
 proc();
    }
    code[cx0].offset = cx + 1;
    body();
    currentProcAddr = currentProcAddr->prev;
}

canonical_original_code:
void block()
{
    int cx0;
    int tempAddr;
    gen(JMP, 0, 0);
    cx0 = cx;
    if (token == ENDFILE)
 return;
    if (token == CONST_K)
    {
 condecl();
    }
    if (token == VAR_K)
    {
 vardecl();
    }
    currentProcAddr->table.size = numVar + 3;
    numVar = 0;
    if (token == PROCEDURE_K)
    {
 procNest = 1;
 proc();
    }
    code[cx0].offset = cx + 1;
    body();
    currentProcAddr = currentProcAddr->prev;
}

variable_types: tempAddr int


prog

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

result = getToken();
token = result;
if ( (_DWORD)result )
{
match(2);
if ( position(&tokenString) )
syntaxError(byte_D4B);
enter(0LL, &tokenString);
match(18);
match(29);
result = block();
}
return result;
}

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

result = getToken();
token = result;
if ( (_DWORD)result )
{
func1(2);
if ( position(&tokenString) )
func0(byte_D4B);
enter(0LL, &tokenString);
func1(18);
func1(29);
result = func13();
}
return result;
}

original_code:
void prog(void)
{
    token = getToken();
    if (token == ENDFILE)
    {
 return;
    }
    match(PROGRAM_K);
    if (position(tokenString) != ((void *)0))
    {
 syntaxError("过程名字已经被使用");
    }
    enter(MAINPROCEDURE, tokenString);
    match(ID);
    match(SEMI);
    block();
}

canonical_original_code:
void prog()
{
    token = getToken();
    if (token == ENDFILE)
    {
 return;
    }
    match(PROGRAM_K);
    if (position(tokenString) != ((void *)0))
    {
 syntaxError("过程名字已经被使用");
    }
    enter(MAINPROCEDURE, tokenString);
    match(ID);
    match(SEMI);
    block();
}


syntaxAnalyze

decompiled_code:
__int64 syntaxAnalyze()
{
return prog();
}

canonical_decompiled_code:
__int64 func15()
{
return func14();
}

original_code:
void syntaxAnalyze(void)
{
    prog();
}

canonical_original_code:
void syntaxAnalyze()
{
    prog();
}


proc

decompiled_code:
void proc()
{
__int64 v0; // rbx
__int64 v1; // rax

if ( token )
{
match(5);
if ( position(&tokenString) )
syntaxError(byte_D67);
++level;
v0 = currentProcAddr;
enter(1LL, &tokenString);
if ( procNest == 1 )
{
v1 = currentProcAddr;
*(_QWORD *)(v0 + 88) = currentProcAddr;
*(_QWORD *)(v1 + 96) = v0;
procNest = 0;
}
match(18);
match(27);
match(18);
while ( token == 30 )
{
match(30);
match(18);
}
match(28);
match(29);
if ( (unsigned int)(token - 3) <= 3 )
block();
while ( token == 29 )
{
match(29);
proc();
}
}
}

canonical_decompiled_code:
void func16()
{
__int64 v0; // rbx
__int64 v1; // rax

if ( token )
{
func1(5);
if ( position(&tokenString) )
func0(byte_D67);
++level;
v0 = currentProcAddr;
enter(1LL, &tokenString);
if ( procNest == 1 )
{
v1 = currentProcAddr;
*(_QWORD *)(v0 + 88) = currentProcAddr;
*(_QWORD *)(v1 + 96) = v0;
procNest = 0;
}
func1(18);
func1(27);
func1(18);
while ( token == 30 )
{
func1(30);
func1(18);
}
func1(28);
func1(29);
if ( (unsigned int)(token - 3) <= 3 )
func13();
while ( token == 29 )
{
func1(29);
func16();
}
}
}

original_code:
void proc(void)
{
    struct BSTNode * tempAddr;
    if (token == ENDFILE)
    {
 return;
    }
    match(PROCEDURE_K);
    if (position(tokenString) != ((void *)0))
    {
 syntaxError("过程名已经被使用");
    }
    ++level;
    tempAddr = currentProcAddr;
    enter(PROCEDURE, tokenString);
    if (procNest == 1)
    {
 tempAddr->next = currentProcAddr;
 currentProcAddr->prev = tempAddr;
 procNest = 0;
    }
    match(ID);
    match(LPAREN);
    match(ID);
    while (token == COMM)
    {
 match(COMM);
 match(ID);
    }
    match(RPAREN);
    match(SEMI);
    if (token == VAR_K || token == CONST_K ||
       token == PROCEDURE_K || token == BEGIN_K)
    {
 block();
    }
    while (token == SEMI && token != ENDFILE)
    {
 match(SEMI);
 proc();
    }
}

canonical_original_code:
void proc()
{
    struct BSTNode *tempAddr;
    if (token == ENDFILE)
    {
 return;
    }
    match(PROCEDURE_K);
    if (position(tokenString) != ((void *)0))
    {
 syntaxError("过程名已经被使用");
    }
    ++level;
    tempAddr = currentProcAddr;
    enter(PROCEDURE, tokenString);
    if (procNest == 1)
    {
 tempAddr->next = currentProcAddr;
 currentProcAddr->prev = tempAddr;
 procNest = 0;
    }
    match(ID);
    match(LPAREN);
    match(ID);
    while (token == COMM)
    {
 match(COMM);
 match(ID);
    }
    match(RPAREN);
    match(SEMI);
    if (token == VAR_K || token == CONST_K ||
       token == PROCEDURE_K || token == BEGIN_K)
    {
 block();
    }
    while (token == SEMI && token != ENDFILE)
    {
 match(SEMI);
 proc();
    }
}


factor

decompiled_code:
int factor()
{
int result; // eax
_DWORD *v1; // rax
int v2; // edx
unsigned int v3; // eax

result = token;
if ( token )
{
switch ( token )
{
case 18:
v1 = (_DWORD *)position(&tokenString);
if ( !v1 )
{
syntaxError(byte_D2F);
exit(2);
}
v2 = v1[11];
if ( v2 == 3 )
{
gen(0LL, 0LL, (unsigned int)v1[13]);
}
else if ( v2 == 2 )
{
gen(2LL, abs32(v1[12] - level), (unsigned int)v1[14]);
}
result = match(18);
break;
case 17:
v3 = atoi(&tokenString);
gen(0LL, 0LL, v3);
result = match(17);
break;
case 27:
match(27);
Exp();
result = match(28);
break;
}
}
return result;
}

canonical_decompiled_code:
int func17()
{
int result; // eax
_DWORD *v1; // rax
int v2; // edx
unsigned int v3; // eax

result = token;
if ( token )
{
switch ( token )
{
case 18:
v1 = (_DWORD *)position(&tokenString);
if ( !v1 )
{
func0(byte_D2F);
exit(2);
}
v2 = v1[11];
if ( v2 == 3 )
{
gen(0LL, 0LL, (unsigned int)v1[13]);
}
else if ( v2 == 2 )
{
gen(2LL, abs32(v1[12] - level), (unsigned int)v1[14]);
}
result = func1(18);
break;
case 17:
v3 = atoi(&tokenString);
gen(0LL, 0LL, v3);
result = func1(17);
break;
case 27:
func1(27);
func9();
result = func1(28);
break;
}
}
return result;
}

original_code:
void factor(void)
{
    struct BSTNode* index;
    if (token == ENDFILE)
    {
 return;
    }
    if (token == ID)
    {
 index = position(tokenString);
 if (index == ((void *)0))
 {
     syntaxError("当前变量名没有定义");
     exit(2);
 }
 if (index->table.kind == CONSTANT)
 {
     gen(LIT, 0, index->table.val);
 }
 else if (index->table.kind == VARIABLE)
 {
     gen(LOD, abs(index->table.lev - level), index->table.addr);
 }
 match(ID);
    }
    else if (token == NUM)
    {
 gen(LIT, 0, atoi(tokenString));
 match(NUM);
    }
    else if (token == LPAREN)
    {
 match(LPAREN);
 Exp();
 match(RPAREN);
    }
}

canonical_original_code:
void factor()
{
    struct BSTNode *index;
    if (token == ENDFILE)
    {
 return;
    }
    if (token == ID)
    {
 index = position(tokenString);
 if (index == ((void *)0))
 {
     syntaxError("当前变量名没有定义");
     exit(2);
 }
 if (index->table.kind == CONSTANT)
 {
     gen(LIT, 0, index->table.val);
 }
 else if (index->table.kind == VARIABLE)
 {
     gen(LOD, abs(index->table.lev - level), index->table.addr);
 }
 match(ID);
    }
    else if (token == NUM)
    {
 gen(LIT, 0, atoi(tokenString));
 match(NUM);
    }
    else if (token == LPAREN)
    {
 match(LPAREN);
 Exp();
 match(RPAREN);
    }
}


base

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

result = (unsigned int)currentProcBase;
if ( a1 > 0 )
{
do
{
result = (unsigned int)runStack[(int)result];
--a1;
}
while ( a1 );
}
return result;
}

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

result = (unsigned int)currentProcBase;
if ( a1 > 0 )
{
do
{
result = (unsigned int)runStack[(int)result];
--a1;
}
while ( a1 );
}
return result;
}

original_code:
int base(int l)
{
    int b1;
    b1 = currentProcBase;
    while (l > 0)
    {
 b1 = runStack[b1];
 l = l -1;
    }
    return b1;
}

variable_types: l int


InterpretRun

decompiled_code:
__int64 InterpretRun()
{
__int64 result; // rax
int v1; // edx
_DWORD *v2; // rbx
int v3; // edx
int v4; // eax
int v5; // eax
int v6; // edx
int v7; // eax
int v8; // ecx
int v9; // esi
int v10; // edx
int v11[3]; // [rsp+0h] [rbp-Ch] BYREF

result = (unsigned int)instruction;
v1 = dword_1758;
if ( instruction <= dword_1758 )
{
do
{
v2 = (_DWORD *)(code + 12LL * (int)result);
switch ( *v2 )
{
case 0:
runStack[++topOfRunStack] = v2[2];
++pc;
break;
case 1:
switch ( v2[2] )
{
case 0:
topOfRunStack = currentProcBase - 1;
if ( pc == v1 )
v3 = v1 + 1;
else
v3 = runStack[currentProcBase + 2];
pc = v3;
currentProcBase = runStack[currentProcBase + 1];
break;
case 1:
runStack[topOfRunStack] = -runStack[topOfRunStack];
++pc;
break;
case 2:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] += v11[0];
++pc;
break;
case 3:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] -= v11[0];
++pc;
break;
case 4:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] *= v11[0];
++pc;
break;
case 5:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] /= v11[0];
++pc;
break;
case 6:
runStack[topOfRunStack] = ((unsigned __int8)runStack[topOfRunStack] ^ 1) & 1;
++pc;
break;
case 7:
++pc;
break;
case 8:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = runStack[topOfRunStack] == v11[0];
++pc;
break;
case 9:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = runStack[topOfRunStack] != v11[0];
++pc;
break;
case 0xA:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = v11[0] > runStack[topOfRunStack];
++pc;
break;
case 0xB:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = v11[0] <= runStack[topOfRunStack];
++pc;
break;
case 0xC:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = v11[0] < runStack[topOfRunStack];
++pc;
break;
case 0xD:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = v11[0] >= runStack[topOfRunStack];
++pc;
break;
case 0xE:
v11[0] = runStack[topOfRunStack--];
printf("Output a number: ");
printf("%d", (unsigned int)v11[0]);
++pc;
break;
case 0xF:
putchar(10);
++pc;
break;
case 0x10:
printf("Please input a number: ");
_isoc99_scanf("%d", v11);
runStack[++topOfRunStack] = v11[0];
++pc;
break;
default:
goto LABEL_4;
}
break;
case 2:
v4 = base(v2[1]);
runStack[++topOfRunStack] = runStack[v2[2] + v4];
++pc;
break;
case 3:
case 8:
v5 = base(v2[1]);
v6 = topOfRunStack;
runStack[v2[2] + v5] = runStack[topOfRunStack];
++pc;
topOfRunStack = v6 - 1;
break;
case 4:
v7 = topOfRunStack;
v8 = topOfRunStack + 1;
v9 = currentProcBase;
runStack[v8] = currentProcBase;
runStack[v7 + 2] = v9;
runStack[v7 + 3] = pc + 1;
currentProcBase = v8;
pc = v2[2];
break;
case 5:
topOfRunStack += v2[2];
++pc;
break;
case 6:
pc = v2[2];
break;
case 7:
if ( runStack[topOfRunStack] )
v10 = pc + 1;
else
v10 = v2[2];
pc = v10;
--topOfRunStack;
break;
case 9:
printf("Output a number: ");
printf("%d", (unsigned int)runStack[topOfRunStack]);
++pc;
--topOfRunStack;
break;
default:
break;
}
LABEL_4:
result = (unsigned int)pc;
instruction = pc;
v1 = dword_1758;
}
while ( pc <= dword_1758 );
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1; // edx
_DWORD *v2; // rbx
int v3; // edx
int v4; // eax
int v5; // eax
int v6; // edx
int v7; // eax
int v8; // ecx
int v9; // esi
int v10; // edx
int v11[3]; // [rsp+0h] [rbp-Ch] BYREF

result = (unsigned int)instruction;
v1 = dword_1758;
if ( instruction <= dword_1758 )
{
do
{
v2 = (_DWORD *)(code + 12LL * (int)result);
switch ( *v2 )
{
case 0:
runStack[++topOfRunStack] = v2[2];
++pc;
break;
case 1:
switch ( v2[2] )
{
case 0:
topOfRunStack = currentProcBase - 1;
if ( pc == v1 )
v3 = v1 + 1;
else
v3 = runStack[currentProcBase + 2];
pc = v3;
currentProcBase = runStack[currentProcBase + 1];
break;
case 1:
runStack[topOfRunStack] = -runStack[topOfRunStack];
++pc;
break;
case 2:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] += v11[0];
++pc;
break;
case 3:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] -= v11[0];
++pc;
break;
case 4:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] *= v11[0];
++pc;
break;
case 5:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] /= v11[0];
++pc;
break;
case 6:
runStack[topOfRunStack] = ((unsigned __int8)runStack[topOfRunStack] ^ 1) & 1;
++pc;
break;
case 7:
++pc;
break;
case 8:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = runStack[topOfRunStack] == v11[0];
++pc;
break;
case 9:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = runStack[topOfRunStack] != v11[0];
++pc;
break;
case 0xA:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = v11[0] > runStack[topOfRunStack];
++pc;
break;
case 0xB:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = v11[0] <= runStack[topOfRunStack];
++pc;
break;
case 0xC:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = v11[0] < runStack[topOfRunStack];
++pc;
break;
case 0xD:
v11[0] = runStack[topOfRunStack--];
runStack[topOfRunStack] = v11[0] >= runStack[topOfRunStack];
++pc;
break;
case 0xE:
v11[0] = runStack[topOfRunStack--];
printf("Output a number: ");
printf("%d", (unsigned int)v11[0]);
++pc;
break;
case 0xF:
putchar(10);
++pc;
break;
case 0x10:
printf("Please input a number: ");
_isoc99_scanf("%d", v11);
runStack[++topOfRunStack] = v11[0];
++pc;
break;
default:
goto LABEL_4;
}
break;
case 2:
v4 = func0(v2[1]);
runStack[++topOfRunStack] = runStack[v2[2] + v4];
++pc;
break;
case 3:
case 8:
v5 = func0(v2[1]);
v6 = topOfRunStack;
runStack[v2[2] + v5] = runStack[topOfRunStack];
++pc;
topOfRunStack = v6 - 1;
break;
case 4:
v7 = topOfRunStack;
v8 = topOfRunStack + 1;
v9 = currentProcBase;
runStack[v8] = currentProcBase;
runStack[v7 + 2] = v9;
runStack[v7 + 3] = pc + 1;
currentProcBase = v8;
pc = v2[2];
break;
case 5:
topOfRunStack += v2[2];
++pc;
break;
case 6:
pc = v2[2];
break;
case 7:
if ( runStack[topOfRunStack] )
v10 = pc + 1;
else
v10 = v2[2];
pc = v10;
--topOfRunStack;
break;
case 9:
printf("Output a number: ");
printf("%d", (unsigned int)runStack[topOfRunStack]);
++pc;
--topOfRunStack;
break;
default:
break;
}
LABEL_4:
result = (unsigned int)pc;
instruction = pc;
v1 = dword_1758;
}
while ( pc <= dword_1758 );
}
return result;
}

original_code:
void InterpretRun()
{
    int temp1, temp2, baseAddr;
    while (instruction <= cx)
    {
 switch (code[instruction].cmd)
 {
 case LIT:
      topOfRunStack = topOfRunStack + 1;
      runStack[topOfRunStack] = code[instruction].offset;
      ++pc;
      break;
 case OPR:
      switch (code[instruction].offset)
      {
      case 0:
           topOfRunStack = currentProcBase - 1;
    if (pc == cx)
        pc = cx + 1;
    else
    {
        pc = runStack[topOfRunStack + 3];
    }
    currentProcBase = runStack[topOfRunStack + 2];
    break;
      case 1:
           runStack[topOfRunStack] = 0 - runStack[topOfRunStack];
    ++pc;
    break;
      case 2:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    runStack[topOfRunStack] = temp1 + temp2;
    ++pc;
    break;
      case 3:
         temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    runStack[topOfRunStack] = temp2 - temp1;
    ++pc;
    break;
      case 4:
         temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    runStack[topOfRunStack] = temp1 * temp2;
    ++pc;
    break;
      case 5:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    runStack[topOfRunStack] = temp2 / temp1;
    ++pc;
    break;
      case 6:
           if(runStack[topOfRunStack] % 2 == 0)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 7:
           ++pc;
    break;
      case 8:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp1 == temp2)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 9:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp1 != temp2)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 10:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp2 < temp1)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 11:
         temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp2 >= temp1)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 12:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp2 > temp1)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 13:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp2 <= temp1)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 14:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    printf("Output a number: ");
    printf("%d", temp1);
    ++pc;
    break;
      case 15:
         printf("\n");
    ++pc;
    break;
      case 16:
         printf("Please input a number: ");
    scanf("%d", &temp1);
    ++topOfRunStack;
    runStack[topOfRunStack] = temp1;
    ++pc;
    break;
      default:
           break;
      }
      break;
 case LOD:
      baseAddr = base(code[instruction].lev);
      ++topOfRunStack;
      runStack[topOfRunStack] = runStack[baseAddr + code[instruction].offset];
      ++pc;
      break;
 case STO:
      baseAddr = base(code[instruction].lev);
      runStack[baseAddr + code[instruction].offset] = runStack[topOfRunStack];
      ++pc;
      --topOfRunStack;
      break;
 case CAL:
      runStack[topOfRunStack + 1] = currentProcBase;
      runStack[topOfRunStack + 2] = currentProcBase;
      runStack[topOfRunStack + 3] = pc + 1;
      currentProcBase = topOfRunStack + 1;
      pc = code[instruction].offset;
      break;
 case INT:
      topOfRunStack += code[instruction].offset;
      ++pc;
      break;
 case JMP:
      pc = code[instruction].offset;
      break;
 case JPC:
      if (runStack[topOfRunStack] == 0)
      {
   pc = code[instruction].offset;
      }
      else
      {
   ++pc;
      }
      --topOfRunStack;
      break;
 case RED:
      baseAddr = base(code[instruction].lev);
      runStack[baseAddr + code[instruction].offset] = runStack[topOfRunStack];
      ++pc;
      --topOfRunStack;
      break;
 case WRT:
      printf("Output a number: ");
      printf("%d", runStack[topOfRunStack]);
      ++pc;
      --topOfRunStack;
      break;
 default:
      break;
 }
 instruction = pc;
    }
}

canonical_original_code:
void InterpretRun()
{
    int temp1; int temp2; int baseAddr;
    while (instruction <= cx)
    {
 switch (code[instruction].cmd)
 {
 case LIT:
      topOfRunStack = topOfRunStack + 1;
      runStack[topOfRunStack] = code[instruction].offset;
      ++pc;
      break;
 case OPR:
      switch (code[instruction].offset)
      {
      case 0:
           topOfRunStack = currentProcBase - 1;
    if (pc == cx)
        pc = cx + 1;
    else
    {
        pc = runStack[topOfRunStack + 3];
    }
    currentProcBase = runStack[topOfRunStack + 2];
    break;
      case 1:
           runStack[topOfRunStack] = 0 - runStack[topOfRunStack];
    ++pc;
    break;
      case 2:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    runStack[topOfRunStack] = temp1 + temp2;
    ++pc;
    break;
      case 3:
         temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    runStack[topOfRunStack] = temp2 - temp1;
    ++pc;
    break;
      case 4:
         temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    runStack[topOfRunStack] = temp1 * temp2;
    ++pc;
    break;
      case 5:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    runStack[topOfRunStack] = temp2 / temp1;
    ++pc;
    break;
      case 6:
           if(runStack[topOfRunStack] % 2 == 0)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 7:
           ++pc;
    break;
      case 8:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp1 == temp2)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 9:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp1 != temp2)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 10:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp2 < temp1)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 11:
         temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp2 >= temp1)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 12:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp2 > temp1)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 13:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    temp2 = runStack[topOfRunStack];
    if (temp2 <= temp1)
    {
        runStack[topOfRunStack] = 1;
    }
    else
    {
        runStack[topOfRunStack] = 0;
    }
    ++pc;
    break;
      case 14:
           temp1 = runStack[topOfRunStack];
    --topOfRunStack;
    printf("Output a number: ");
    printf("%d", temp1);
    ++pc;
    break;
      case 15:
         printf("\n");
    ++pc;
    break;
      case 16:
         printf("Please input a number: ");
    scanf("%d", &temp1);
    ++topOfRunStack;
    runStack[topOfRunStack] = temp1;
    ++pc;
    break;
      default:
           break;
      }
      break;
 case LOD:
      baseAddr = base(code[instruction].lev);
      ++topOfRunStack;
      runStack[topOfRunStack] = runStack[baseAddr + code[instruction].offset];
      ++pc;
      break;
 case STO:
      baseAddr = base(code[instruction].lev);
      runStack[baseAddr + code[instruction].offset] = runStack[topOfRunStack];
      ++pc;
      --topOfRunStack;
      break;
 case CAL:
      runStack[topOfRunStack + 1] = currentProcBase;
      runStack[topOfRunStack + 2] = currentProcBase;
      runStack[topOfRunStack + 3] = pc + 1;
      currentProcBase = topOfRunStack + 1;
      pc = code[instruction].offset;
      break;
 case INT:
      topOfRunStack += code[instruction].offset;
      ++pc;
      break;
 case JMP:
      pc = code[instruction].offset;
      break;
 case JPC:
      if (runStack[topOfRunStack] == 0)
      {
   pc = code[instruction].offset;
      }
      else
      {
   ++pc;
      }
      --topOfRunStack;
      break;
 case RED:
      baseAddr = base(code[instruction].lev);
      runStack[baseAddr + code[instruction].offset] = runStack[topOfRunStack];
      ++pc;
      --topOfRunStack;
      break;
 case WRT:
      printf("Output a number: ");
      printf("%d", runStack[topOfRunStack]);
      ++pc;
      --topOfRunStack;
      break;
 default:
      break;
 }
 instruction = pc;
    }
}

variable_types: baseAddr int


reservedLookup

decompiled_code:
__int64 __fastcall reservedLookup(char *s1)
{
int v1; // ebp
int v2; // er12
int v4; // ebx
int v5; // eax

if ( !s1 )
_assert_fail("str != NULL", "lexical.c", 0x21u, "reservedLookup");
v1 = 14;
v2 = 0;
do
{
v4 = (v2 + v1) / 2;
v5 = strcmp(s1, (&reservedWords)[2 * v4]);
if ( !v5 )
return LODWORD((&reservedWords)[2 * v4 + 1]);
if ( v5 < 0 )
v1 = v4 - 1;
else
v2 = v4 + 1;
}
while ( v2 <= v1 );
return 18LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
int v1; // ebp
int v2; // er12
int v4; // ebx
int v5; // eax

if ( !s1 )
_assert_fail("str != NULL", "lexical.c", 0x21u, "reservedLookup");
v1 = 14;
v2 = 0;
do
{
v4 = (v2 + v1) / 2;
v5 = strcmp(s1, (&reservedWords)[2 * v4]);
if ( !v5 )
return LODWORD((&reservedWords)[2 * v4 + 1]);
if ( v5 < 0 )
v1 = v4 - 1;
else
v2 = v4 + 1;
}
while ( v2 <= v1 );
return 18LL;
}

original_code:
TokenType reservedLookup(const char* str)
{
    ((void) sizeof ((str != ((void *)0)) ? 1 : 0), __extension__ ({ if (str != ((void *)0)) ; else __assert_fail ("str != NULL", "lexical.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    int low = 0;
    int high = 15 - 1;
    while (low <= high)
    {
 int mid = (low + high) / 2;
 if (strcmp(str, reservedWords[mid].str) == 0)
 {
     return reservedWords[mid].tok;
 }
 else if (strcmp(str, reservedWords[mid].str) < 0)
 {
     high = mid - 1;
 }
 else if (strcmp(str, reservedWords[mid].str) > 0)
 {
     low = mid + 1;
 }
    }
    return ID;
}

canonical_original_code:
enum TokenType reservedLookup(char *str)
{
    ((void) sizeof ((str != ((void *)0)) ? 1 : 0), __extension__ ({ if (str != ((void *)0)) ; else __assert_fail ("str != NULL", "lexical.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    int low = 0;
    int high = 15 - 1;
    while (low <= high)
    {
 int mid = (low + high) / 2;
 if (strcmp(str, reservedWords[mid].str) == 0)
 {
     return reservedWords[mid].tok;
 }
 else if (strcmp(str, reservedWords[mid].str) < 0)
 {
     high = mid - 1;
 }
 else if (strcmp(str, reservedWords[mid].str) > 0)
 {
     low = mid + 1;
 }
    }
    return ID;
}

variable_types:
str
char *

variable_types: low int

variable_types: high int

variable_types: mid int

return_type: enum TokenType { ENDFILE=0, ERROR=1, PROGRAM_K=2, CONST_K=3, VAR_K=4, PROCEDURE_K=5, BEGIN_K=6, END_K=7, IF_K=8, WHILE_K=9, CALL_K=10, DO_K=11, ELSE_K=12, THEN_K=13, WRITE_K=14, ODD_K=15, READ_K=16, NUM=17, ID=18, ASSIGN=19, EQ=20, LT=21, GT=22, PLUS=23, MINUS=24, TIMES=25, OVER=26, LPAREN=27, RPAREN=28, SEMI=29, COMM=30, LTEQ=31, GTEQ=32, NOEQ=33 }


getNextChar

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

v0 = linepos;
if ( linepos >= buffersize )
{
++lineno;
if ( fgets(lineBuf, 127, source) )
{
printf("%4d: %s", (unsigned int)lineno, lineBuf);
buffersize = strlen(lineBuf);
linepos = 1;
result = (unsigned int)lineBuf[0];
}
else
{
EOF_Flag = 1;
result = 0xFFFFFFFFLL;
}
}
else
{
++linepos;
result = (unsigned int)lineBuf[v0];
}
return result;
}

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

v0 = linepos;
if ( linepos >= buffersize )
{
++lineno;
if ( fgets(lineBuf, 127, source) )
{
printf("%4d: %s", (unsigned int)lineno, lineBuf);
buffersize = strlen(lineBuf);
linepos = 1;
result = (unsigned int)lineBuf[0];
}
else
{
EOF_Flag = 1;
result = 0xFFFFFFFFLL;
}
}
else
{
++linepos;
result = (unsigned int)lineBuf[v0];
}
return result;
}

original_code:
int getNextChar(void)
{
    if (!(linepos < buffersize))
    {
 lineno++;
 if (fgets(lineBuf, 128 - 1, source))
 {
     printf("%4d: %s", lineno, lineBuf);
     buffersize = strlen(lineBuf);
     linepos = 0;
     return lineBuf[linepos++];
 }
 else
 {
     EOF_Flag = 1;
     return (-1);
 }
    }
    else
    {
 return lineBuf[linepos++];
    }
}

canonical_original_code:
int getNextChar()
{
    if (!(linepos < buffersize))
    {
 lineno++;
 if (fgets(lineBuf, 128 - 1, source))
 {
     printf("%4d: %s", lineno, lineBuf);
     buffersize = strlen(lineBuf);
     linepos = 0;
     return lineBuf[linepos++];
 }
 else
 {
     EOF_Flag = 1;
     return (-1);
 }
    }
    else
    {
 return lineBuf[linepos++];
    }
}


ungetNextChar

decompiled_code:
void ungetNextChar()
{
if ( !EOF_Flag )
--linepos;
}

canonical_decompiled_code:
void func2()
{
if ( !EOF_Flag )
--linepos;
}

original_code:
void ungetNextChar(void)
{
    if (!EOF_Flag)
    {
 linepos--;
    }
}

canonical_original_code:
void ungetNextChar()
{
    if (!EOF_Flag)
    {
 linepos--;
    }
}


printToken

decompiled_code:
int __fastcall printToken(unsigned int a1, const char *a2)
{
int result; // eax

if ( !a2 )
_assert_fail("tokString != NULL", "lexical.c", 0x11Du, "printToken");
switch ( a1 )
{
case 0u:
result = puts("EOF");
break;
case 1u:
result = printf("ERROR: %s\n", a2);
++lex_error;
break;
case 2u:
case 3u:
case 4u:
case 5u:
case 6u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
result = printf("reserved word: %s\n", a2);
break;
case 0x11u:
result = printf("NUM, val = %s\n", a2);
break;
case 0x12u:
result = printf("ID, name = %s\n", a2);
break;
case 0x13u:
result = puts(":=");
break;
case 0x14u:
result = puts(asc_7DC);
break;
case 0x15u:
result = puts(&asc_7DC[2]);
break;
case 0x16u:
result = puts(&asc_7DC[4]);
break;
case 0x17u:
result = puts(&asc_7DC[6]);
break;
case 0x19u:
result = puts(&asc_7DC[8]);
break;
case 0x1Au:
result = puts(&asc_7DC[10]);
break;
case 0x1Bu:
result = puts(&asc_7DC[12]);
break;
case 0x1Cu:
result = puts(&asc_7DC[14]);
break;
case 0x1Du:
result = puts(&asc_7DC[16]);
break;
case 0x1Eu:
result = puts(&asc_7DC[18]);
break;
case 0x1Fu:
result = puts("<=");
break;
case 0x20u:
result = puts(">=");
break;
case 0x21u:
result = puts("<>");
break;
default:
result = printf("Unkown token: %d\n", a1);
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, const char *a2)
{
int result; // eax

if ( !a2 )
_assert_fail("tokString != NULL", "lexical.c", 0x11Du, "printToken");
switch ( a1 )
{
case 0u:
result = puts("EOF");
break;
case 1u:
result = printf("ERROR: %s\n", a2);
++lex_error;
break;
case 2u:
case 3u:
case 4u:
case 5u:
case 6u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
result = printf("reserved word: %s\n", a2);
break;
case 0x11u:
result = printf("NUM, val = %s\n", a2);
break;
case 0x12u:
result = printf("ID, name = %s\n", a2);
break;
case 0x13u:
result = puts(":=");
break;
case 0x14u:
result = puts(asc_7DC);
break;
case 0x15u:
result = puts(&asc_7DC[2]);
break;
case 0x16u:
result = puts(&asc_7DC[4]);
break;
case 0x17u:
result = puts(&asc_7DC[6]);
break;
case 0x19u:
result = puts(&asc_7DC[8]);
break;
case 0x1Au:
result = puts(&asc_7DC[10]);
break;
case 0x1Bu:
result = puts(&asc_7DC[12]);
break;
case 0x1Cu:
result = puts(&asc_7DC[14]);
break;
case 0x1Du:
result = puts(&asc_7DC[16]);
break;
case 0x1Eu:
result = puts(&asc_7DC[18]);
break;
case 0x1Fu:
result = puts("<=");
break;
case 0x20u:
result = puts(">=");
break;
case 0x21u:
result = puts("<>");
break;
default:
result = printf("Unkown token: %d\n", a1);
break;
}
return result;
}

original_code:
void printToken(TokenType token, const char* tokString)
{
    ((void) sizeof ((tokString != ((void *)0)) ? 1 : 0), __extension__ ({ if (tokString != ((void *)0)) ; else __assert_fail ("tokString != NULL", "lexical.c", 285, __extension__ __PRETTY_FUNCTION__); }));
    switch (token)
    {
    case PROGRAM_K:
    case CONST_K:
    case VAR_K:
    case PROCEDURE_K:
    case BEGIN_K:
    case END_K:
    case IF_K:
    case WHILE_K:
    case CALL_K:
    case DO_K:
    case ELSE_K:
    case THEN_K:
    case WRITE_K:
    case ODD_K:
    case READ_K:
         printf("reserved word: %s\n", tokString);
  break;
    case ENDFILE:
         printf("EOF\n");
  break;
    case ERROR:
         printf("ERROR: %s\n", tokString);
  ++lex_error;
  break;
    case NUM:
         printf("NUM, val = %s\n", tokString);
  break;
    case ID:
         printf("ID, name = %s\n", tokString);
  break;
    case ASSIGN:
         printf(":=\n");
  break;
    case EQ:
         printf("=\n");
  break;
    case LT:
         printf("<\n");
  break;
    case GT:
         printf(">\n");
  break;
    case PLUS:
         printf("+\n");
  break;
    case TIMES:
         printf("*\n");
         break;
    case OVER:
         printf("/\n");
  break;
    case LPAREN:
         printf("(\n");
  break;
    case RPAREN:
         printf(")\n");
  break;
    case SEMI:
         printf(";\n");
  break;
    case COMM:
         printf(",\n");
  break;
    case LTEQ:
         printf("<=\n");
  break;
    case GTEQ:
         printf(">=\n");
  break;
    case NOEQ:
         printf("<>\n");
  break;
    default:
         printf("Unkown token: %d\n", token);
  break;
    }
}

canonical_original_code:
void printToken(enum TokenType token, char *tokString)
{
    ((void) sizeof ((tokString != ((void *)0)) ? 1 : 0), __extension__ ({ if (tokString != ((void *)0)) ; else __assert_fail ("tokString != NULL", "lexical.c", 285, __extension__ __PRETTY_FUNCTION__); }));
    switch (token)
    {
    case PROGRAM_K:
    case CONST_K:
    case VAR_K:
    case PROCEDURE_K:
    case BEGIN_K:
    case END_K:
    case IF_K:
    case WHILE_K:
    case CALL_K:
    case DO_K:
    case ELSE_K:
    case THEN_K:
    case WRITE_K:
    case ODD_K:
    case READ_K:
         printf("reserved word: %s\n", tokString);
  break;
    case ENDFILE:
         printf("EOF\n");
  break;
    case ERROR:
         printf("ERROR: %s\n", tokString);
  ++lex_error;
  break;
    case NUM:
         printf("NUM, val = %s\n", tokString);
  break;
    case ID:
         printf("ID, name = %s\n", tokString);
  break;
    case ASSIGN:
         printf(":=\n");
  break;
    case EQ:
         printf("=\n");
  break;
    case LT:
         printf("<\n");
  break;
    case GT:
         printf(">\n");
  break;
    case PLUS:
         printf("+\n");
  break;
    case TIMES:
         printf("*\n");
         break;
    case OVER:
         printf("/\n");
  break;
    case LPAREN:
         printf("(\n");
  break;
    case RPAREN:
         printf(")\n");
  break;
    case SEMI:
         printf(";\n");
  break;
    case COMM:
         printf(",\n");
  break;
    case LTEQ:
         printf("<=\n");
  break;
    case GTEQ:
         printf(">=\n");
  break;
    case NOEQ:
         printf("<>\n");
  break;
    default:
         printf("Unkown token: %d\n", token);
  break;
    }
}

variable_types:
tokString
char *