main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
_QWORD v14[12]; // [rsp+0h] [rbp-B8h] BYREF
int v15; // [rsp+60h] [rbp-58h]
char v16[72]; // [rsp+70h] [rbp-48h] BYREF

strcpy(v16, "This is my test string, but its not much of a test string.");
v14[0] = 1953719668LL;
v14[1] = 0LL;
v14[2] = 0LL;
v14[3] = 0LL;
v14[4] = 0LL;
v14[5] = 0LL;
v14[6] = 0LL;
v14[7] = 0LL;
v14[8] = 0LL;
v14[9] = 0LL;
v14[10] = 0LL;
v14[11] = 0LL;
v15 = 0;
printf("In the string: \"%s\"\n", v16);
v3 = strindex(v16, (char *)v14);
printf("The leftmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v3);
v4 = strrindex(v16, (const char *)v14);
printf("The rightmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v4);
putchar(10);
strcpy((char *)v14, "string");
printf("In the string: \"%s\"\n", v16);
v5 = strindex(v16, (char *)v14);
printf("The leftmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v5);
v6 = strrindex(v16, (const char *)v14);
printf("The rightmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v6);
putchar(10);
strcpy((char *)v14, "This");
printf("In the string: \"%s\"\n", v16);
v7 = strindex(v16, (char *)v14);
printf("The leftmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v7);
v8 = strrindex(v16, (const char *)v14);
printf("The rightmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v8);
putchar(10);
strcpy((char *)v14, ".");
printf("In the string: \"%s\"\n", v16);
v9 = strindex(v16, (char *)v14);
printf("The leftmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v9);
v10 = strrindex(v16, (const char *)v14);
printf("The rightmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v10);
putchar(10);
strcpy((char *)v14, "not in string");
printf("In the string: \"%s\"\n", v16);
v11 = strindex(v16, (char *)v14);
printf("The leftmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v11);
v12 = strrindex(v16, (const char *)v14);
printf("The rightmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v12);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
_QWORD v14[12]; // [rsp+0h] [rbp-B8h] BYREF
int v15; // [rsp+60h] [rbp-58h]
char v16[72]; // [rsp+70h] [rbp-48h] BYREF

strcpy(v16, "This is my test string, but its not much of a test string.");
v14[0] = 1953719668LL;
v14[1] = 0LL;
v14[2] = 0LL;
v14[3] = 0LL;
v14[4] = 0LL;
v14[5] = 0LL;
v14[6] = 0LL;
v14[7] = 0LL;
v14[8] = 0LL;
v14[9] = 0LL;
v14[10] = 0LL;
v14[11] = 0LL;
v15 = 0;
printf("In the string: \"%s\"\n", v16);
v3 = func0(v16, (char *)v14);
printf("The leftmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v3);
v4 = func1(v16, (const char *)v14);
printf("The rightmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v4);
putchar(10);
strcpy((char *)v14, "string");
printf("In the string: \"%s\"\n", v16);
v5 = func0(v16, (char *)v14);
printf("The leftmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v5);
v6 = func1(v16, (const char *)v14);
printf("The rightmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v6);
putchar(10);
strcpy((char *)v14, "This");
printf("In the string: \"%s\"\n", v16);
v7 = func0(v16, (char *)v14);
printf("The leftmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v7);
v8 = func1(v16, (const char *)v14);
printf("The rightmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v8);
putchar(10);
strcpy((char *)v14, ".");
printf("In the string: \"%s\"\n", v16);
v9 = func0(v16, (char *)v14);
printf("The leftmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v9);
v10 = func1(v16, (const char *)v14);
printf("The rightmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v10);
putchar(10);
strcpy((char *)v14, "not in string");
printf("In the string: \"%s\"\n", v16);
v11 = func0(v16, (char *)v14);
printf("The leftmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v11);
v12 = func1(v16, (const char *)v14);
printf("The rightmost occurrence of \"%s\" is at position %d.\n", (const char *)v14, v12);
return 0;
}

original_code:
int main(void) {
    char s[] = "This is my test string, but its not much of a test string.";
    char t[100] = "";
    (void)strcpy(t, "test");
    printf("In the string: \"%s\"\n", s);
    printf("The leftmost  occurrence of \"%s\" is at position %d.\n", t, strindex(s, t));
    printf("The rightmost occurrence of \"%s\" is at position %d.\n", t, strrindex(s, t));
    (void)putchar('\n');
    (void)strcpy(t, "string");
    printf("In the string: \"%s\"\n", s);
    printf("The leftmost  occurrence of \"%s\" is at position %d.\n", t, strindex(s, t));
    printf("The rightmost occurrence of \"%s\" is at position %d.\n", t, strrindex(s, t));
    (void)putchar('\n');
    (void)strcpy(t, "This");
    printf("In the string: \"%s\"\n", s);
    printf("The leftmost  occurrence of \"%s\" is at position %d.\n", t, strindex(s, t));
    printf("The rightmost occurrence of \"%s\" is at position %d.\n", t, strrindex(s, t));
    (void)putchar('\n');
    (void)strcpy(t, ".");
    printf("In the string: \"%s\"\n", s);
    printf("The leftmost  occurrence of \"%s\" is at position %d.\n", t, strindex(s, t));
    printf("The rightmost occurrence of \"%s\" is at position %d.\n", t, strrindex(s, t));
    (void)putchar('\n');
    (void)strcpy(t, "not in string");
    printf("In the string: \"%s\"\n", s);
    printf("The leftmost  occurrence of \"%s\" is at position %d.\n", t, strindex(s, t));
    printf("The rightmost occurrence of \"%s\" is at position %d.\n", t, strrindex(s, t));
    return 0;
}

canonical_original_code:
int main() {
    char s[] = "This is my test string, but its not much of a test string.";
    char t[100] = "";
    (void)strcpy(t, "test");
    printf("In the string: \"%s\"\n", s);
    printf("The leftmost  occurrence of \"%s\" is at position %d.\n", t, strindex(s, t));
    printf("The rightmost occurrence of \"%s\" is at position %d.\n", t, strrindex(s, t));
    (void)putchar('\n');
    (void)strcpy(t, "string");
    printf("In the string: \"%s\"\n", s);
    printf("The leftmost  occurrence of \"%s\" is at position %d.\n", t, strindex(s, t));
    printf("The rightmost occurrence of \"%s\" is at position %d.\n", t, strrindex(s, t));
    (void)putchar('\n');
    (void)strcpy(t, "This");
    printf("In the string: \"%s\"\n", s);
    printf("The leftmost  occurrence of \"%s\" is at position %d.\n", t, strindex(s, t));
    printf("The rightmost occurrence of \"%s\" is at position %d.\n", t, strrindex(s, t));
    (void)putchar('\n');
    (void)strcpy(t, ".");
    printf("In the string: \"%s\"\n", s);
    printf("The leftmost  occurrence of \"%s\" is at position %d.\n", t, strindex(s, t));
    printf("The rightmost occurrence of \"%s\" is at position %d.\n", t, strrindex(s, t));
    (void)putchar('\n');
    (void)strcpy(t, "not in string");
    printf("In the string: \"%s\"\n", s);
    printf("The leftmost  occurrence of \"%s\" is at position %d.\n", t, strindex(s, t));
    printf("The rightmost occurrence of \"%s\" is at position %d.\n", t, strrindex(s, t));
    return 0;
}

variable_types:
t
char [100]


lowerstr

repo: ptdecker/cbasics

decompiled_code:
void __fastcall lowerstr(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func1(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
static void lowerstr(char *s) {
    for ( ; *s != '\0'; s++)
        *s = tolower(*s);
}

variable_types:
s
char *

return_type: void


listprint

decompiled_code:
int listprint()
{
__int64 v0; // rbx
int result; // eax

if ( listcount > 0 )
{
v0 = 0LL;
do
{
result = printf("%5d %s\n", *(unsigned int *)(list[v0] + 8), *(const char **)list[v0]);
++v0;
}
while ( listcount > (int)v0 );
}
return result;
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rbx
int result; // eax

if ( listcount > 0 )
{
v0 = 0LL;
do
{
result = printf("%5d %s\n", *(unsigned int *)(list[v0] + 8), *(const char **)list[v0]);
++v0;
}
while ( listcount > (int)v0 );
}
return result;
}

original_code:
static void listprint(void) {
    int i;
    for (i = 0; i < listcount; i++)
        printf("%5d %s\n", list[i]->count, list[i]->word);
}

canonical_original_code:
static void listprint() {
    int i;
    for (i = 0; i < listcount; i++)
        printf("%5d %s\n", list[i]->count, list[i]->word);
}

variable_types: i int


talloc

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

result = malloc(0x20uLL);
if ( !result )
{
printf("Error: ran out of memory");
exit(1);
}
return result;
}

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

result = malloc(0x20uLL);
if ( !result )
{
printf("Error: ran out of memory");
exit(1);
}
return result;
}

original_code:
static struct tnode *talloc(void) {
    struct tnode *p = (struct tnode *)malloc(sizeof(struct tnode));
    if (p == ((void *)0)) {
        printf("Error: ran out of memory");
        exit(1);
    }
    return p;
}

canonical_original_code:
static struct tnode *talloc() {
    struct tnode *p = (struct tnode *)malloc(sizeof(struct tnode));
    if (p == ((void *)0)) {
        printf("Error: ran out of memory");
        exit(1);
    }
    return p;
}

variable_types: struct tnode { char *word; int count; struct tnode *left; struct tnode *right; } *


mystrdup

decompiled_code:
char *__fastcall mystrdup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
if ( !v2 )
{
printf("Error: ran out of memory");
exit(1);
}
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func4(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
if ( !v2 )
{
printf("Error: ran out of memory");
exit(1);
}
return strcpy(v2, src);
}

original_code:
static char *mystrdup(char *s) {
    char *p = (char *)malloc(strlen(s) + 1);
    if (p == ((void *)0)) {
        printf("Error: ran out of memory");
        exit(1);
    }
    strcpy(p, s);
    return p;
}

variable_types:
p
char *

return_type: char *


liststore

decompiled_code:
void __fastcall liststore(__int64 a1)
{
int v1; // eax

if ( a1 )
{
liststore(*(_QWORD *)(a1 + 16));
v1 = listcount;
if ( listcount > (int)&unk_1869F )
{
puts("error: too many distinct words");
exit(1);
}
++listcount;
list[v1] = a1;
liststore(*(_QWORD *)(a1 + 24));
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
int v1; // eax

if ( a1 )
{
func8(*(_QWORD *)(a1 + 16));
v1 = listcount;
if ( listcount > (int)&unk_1869F )
{
puts("error: too many distinct words");
exit(1);
}
++listcount;
list[v1] = a1;
func8(*(_QWORD *)(a1 + 24));
}
}

original_code:
static void liststore(struct tnode *p) {
    if (p != ((void *)0)) {
        liststore(p->left);
        if (listcount < 100000)
            list[listcount++] = p;
        else {
            printf("error: too many distinct words\n");
            exit(1);
        }
        liststore(p->right);
    }
}

user_defined_types: struct tnode { char *word; int count; struct tnode *left; struct tnode *right; }


hash

decompiled_code:
__int64 __fastcall hash(char *a1)
{
char v1; // al
unsigned int v2; // ecx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v2 = v1 + 31 * v2;
v1 = *++a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 % 0x65;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // al
unsigned int v2; // ecx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v2 = v1 + 31 * v2;
v1 = *++a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 % 0x65;
}

original_code:
static unsigned hash(char *s) {
    unsigned hashval;
    for (hashval = 0; *s != '\0'; s++)
        hashval = *s + 31 * hashval;
    return hashval % 101;
}

canonical_original_code:
static unsigned int hash(char *s) {
    unsigned int hashval;
    for (hashval = 0; *s != '\0'; s++)
        hashval = *s + 31 * hashval;
    return hashval % 101;
}

variable_types:
hashval
unsigned int

return_type: unsigned int


lookup

decompiled_code:
__int64 __fastcall lookup(char *s1)
{
__int64 i; // rbx

for ( i = hashtab[(unsigned int)hash(s1)]; i; i = *(_QWORD *)i )
{
if ( !strcmp(s1, *(const char **)(i + 8)) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
__int64 i; // rbx

for ( i = hashtab[(unsigned int)func0(s1)]; i; i = *(_QWORD *)i )
{
if ( !strcmp(s1, *(const char **)(i + 8)) )
break;
}
return i;
}

original_code:
static struct nlist *lookup(char *s) {
    struct nlist *np;
    for (np = hashtab[hash(s)]; np != ((void *)0); np = np->next)
        if (strcmp(s, np->name) == 0)
            return np;
    return ((void *)0);
}

variable_types: struct nlist { struct nlist *next; char *name; char *defn; } *


undef

decompiled_code:
void __fastcall undef(char *s1)
{
int v1; // er13
__int64 v2; // rbx
_QWORD *v3; // r12

v1 = hash(s1);
v2 = hashtab[v1];
if ( v2 )
{
v3 = 0LL;
while ( strcmp(s1, *(const char **)(v2 + 8)) )
{
v3 = (_QWORD *)v2;
if ( !*(_QWORD *)v2 )
return;
v2 = *(_QWORD *)v2;
}
if ( v3 )
*v3 = *(_QWORD *)v2;
else
hashtab[v1] = *(_QWORD *)v2;
free(*(void **)(v2 + 8));
free(*(void **)(v2 + 16));
free((void *)v2);
}
}

canonical_decompiled_code:
void __fastcall func3(char *s1)
{
int v1; // er13
__int64 v2; // rbx
_QWORD *v3; // r12

v1 = func0(s1);
v2 = hashtab[v1];
if ( v2 )
{
v3 = 0LL;
while ( strcmp(s1, *(const char **)(v2 + 8)) )
{
v3 = (_QWORD *)v2;
if ( !*(_QWORD *)v2 )
return;
v2 = *(_QWORD *)v2;
}
if ( v3 )
*v3 = *(_QWORD *)v2;
else
hashtab[v1] = *(_QWORD *)v2;
free(*(void **)(v2 + 8));
free(*(void **)(v2 + 16));
free((void *)v2);
}
}

original_code:
static void undef(char *s) {
    unsigned h;
    struct nlist *prior;
    struct nlist *np;
    prior = ((void *)0);
    h = hash(s);
    for (np = hashtab[h]; np != ((void *)0); np = np->next) {
        if (strcmp(s, np->name) == 0)
            break;
        prior = np;
    }
    if (np != ((void *)0)) {
        if (prior == ((void *)0))
            hashtab[h] = np->next;
        else
            prior->next = np->next;
        free((void *)np->name);
        free((void *)np->defn);
        free((void *)np);
    }
}

canonical_original_code:
static void undef(char *s) {
    unsigned int h;
    struct nlist *prior;
    struct nlist *np;
    prior = ((void *)0);
    h = hash(s);
    for (np = hashtab[h]; np != ((void *)0); np = np->next) {
        if (strcmp(s, np->name) == 0)
            break;
        prior = np;
    }
    if (np != ((void *)0)) {
        if (prior == ((void *)0))
            hashtab[h] = np->next;
        else
            prior->next = np->next;
        free((void *)np->name);
        free((void *)np->defn);
        free((void *)np);
    }
}

variable_types:
h
unsigned int

user_defined_types: struct nlist { struct nlist *next; char *name; char *defn; }


mystrdup

canonical_original_code:
static char *mystrdup(char *s) {
    char *p = (char *)malloc(strlen(s) + 1);
    if (p == ((void *)0)) {
        printf("Error: ran out of memory");
        exit(1);
    }
    strcpy(p, s);
    return p;
}


skipblanks

decompiled_code:
__int64 skipblanks()
{
char v0; // al

do
{
do
v0 = getch();
while ( v0 == 9 );
}
while ( v0 == 32 );
return ungetch(v0);
}

canonical_decompiled_code:
__int64 func6()
{
char v0; // al

do
{
do
v0 = func2();
while ( v0 == 9 );
}
while ( v0 == 32 );
return func5(v0);
}

original_code:
static void skipblanks(void) {
    int c;
    while ((c = getch()) == ' ' || c == '\t')
        ;
    ungetch(c);
}

canonical_original_code:
static void skipblanks() {
    int c;
    while ((c = getch()) == ' ' || c == '\t')
        ;
    ungetch(c);
}

variable_types: c int


peekch

decompiled_code:
__int64 peekch()
{
unsigned int v0; // ebx

v0 = getch();
ungetch(v0);
return v0;
}

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

v0 = func2();
func5(v0);
return v0;
}

original_code:
static char peekch() {
    char c;
    ungetch(c = getch());
    return c;
}

variable_types: c char

return_type: char


getdef

original_code:
static void getdef(void) {
    char def[100] = "";
    char dir[100] = "";
    char name[100] = "";
    int i;
    skipblanks();
    if (!((*__ctype_b_loc ())[(int) ((getword(dir, 100)))] & (unsigned short int) _ISalpha))
        error(dir[0], "getdef: expecting a directive after '#'--got '%s'");
    else if (strcmp(dir, "define") == 0) {
        skipblanks();
        if (!((*__ctype_b_loc ())[(int) ((getword(name, 100)))] & (unsigned short int) _ISalpha))
            error(name[0], "getdef: non-alpha name expected");
        else {
            skipblanks();
            for (i = 0; i < 100 - 1; i++)
                if ((def[i] = getch()) == (-1) || def[i] == '\n')
                    break;
            def[i] = '\0';
            if (i <= 0)
                error('\n', "getdef; incomplete define");
            else
                (void)install(name, def);
        }
    } else if (strcmp(dir, "undef") == 0) {
        skipblanks();
        if (!((*__ctype_b_loc ())[(int) ((getword(name, 100)))] & (unsigned short int) _ISalpha))
            error(name[0], "getdef: non-alpha in undef");
        else
            undef(name);
    } else if (strcmp(dir, "include") == 0) {
        printf("#include");
    } else
        error(dir[0], "getdef: expecting a directive after #");
}

canonical_original_code:
static void getdef() {
    char def[100] = "";
    char dir[100] = "";
    char name[100] = "";
    int i;
    skipblanks();
    if (!((*__ctype_b_loc ())[(int) ((getword(dir, 100)))] & (unsigned short) _ISalpha))
        error(dir[0], "getdef: expecting a directive after '#'--got '%s'");
    else if (strcmp(dir, "define") == 0) {
        skipblanks();
        if (!((*__ctype_b_loc ())[(int) ((getword(name, 100)))] & (unsigned short) _ISalpha))
            error(name[0], "getdef: non-alpha name expected");
        else {
            skipblanks();
            for (i = 0; i < 100 - 1; i++)
                if ((def[i] = getch()) == (-1) || def[i] == '\n')
                    break;
            def[i] = '\0';
            if (i <= 0)
                error('\n', "getdef; incomplete define");
            else
                (void)install(name, def);
        }
    } else if (strcmp(dir, "undef") == 0) {
        skipblanks();
        if (!((*__ctype_b_loc ())[(int) ((getword(name, 100)))] & (unsigned short) _ISalpha))
            error(name[0], "getdef: non-alpha in undef");
        else
            undef(name);
    } else if (strcmp(dir, "include") == 0) {
        printf("#include");
    } else
        error(dir[0], "getdef: expecting a directive after #");
}

variable_types:
def
char [100]

variable_types:
dir
char [100]

variable_types:
name
char [100]


ungets

decompiled_code:
size_t __fastcall ungets(const char *a1)
{
size_t result; // rax
size_t i; // rbx

result = strlen(a1);
for ( i = result; i; result = ungetch(a1[i]) )
--i;
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(const char *a1)
{
size_t result; // rax
size_t i; // rbx

result = strlen(a1);
for ( i = result; i; result = func5(a1[i]) )
--i;
return result;
}

original_code:
static void ungets(char s[]) {
    size_t slen = strlen(s);
    while (slen > 0)
        ungetch(s[--slen]);
}

canonical_original_code:
static void ungets(char s[]) {
    unsigned long slen = strlen(s);
    while (slen > 0)
        ungetch(s[--slen]);
}

variable_types:
s
char []

variable_types:
slen
unsigned long


error

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

result = puts(a2);
if ( a1 != -1 && a1 != 10 )
{
do
result = getch();
while ( (_BYTE)result != 0xFF && (char)result != 10 );
}
return result;
}

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

result = puts(a2);
if ( a1 != -1 && a1 != 10 )
{
do
result = func2();
while ( (_BYTE)result != 0xFF && (char)result != 10 );
}
return result;
}

original_code:
static void error(int c, char *s) {
    printf("%s\n", s);
    while (c != (-1) && c != '\n')
        c = getch();
}


dapeek

decompiled_code:
double dapeek()
{
if ( dstackptr )
return *(double *)(8 * dstackptr + 0x198);
puts("Empty stack");
return 0.0;
}

canonical_decompiled_code:
double func2()
{
if ( dstackptr )
return *(double *)(8 * dstackptr + 0x198);
puts("Empty stack");
return 0.0;
}

original_code:
double dapeek(void) {
    if (dstackptr > 0)
        return dstack[(dstackptr - 1)];
    printf("Empty stack\n");
    return 0.0L;
}

canonical_original_code:
double dapeek() {
    if (dstackptr > 0)
        return dstack[(dstackptr - 1)];
    printf("Empty stack\n");
    return 0.0L;
}

return_type: double


dadup

decompiled_code:
int dadup()
{
__int64 v0; // rax
double v1; // xmm0_8

v0 = dstackptr;
if ( dstackptr )
{
if ( dstackptr == 100 )
{
LODWORD(v0) = puts("Stack is full");
}
else
{
v1 = *(double *)(8 * dstackptr++ + 0x198);
dstack[v0] = v1;
}
}
else
{
LODWORD(v0) = puts("Empty stack");
}
return v0;
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rax
double v1; // xmm0_8

v0 = dstackptr;
if ( dstackptr )
{
if ( dstackptr == 100 )
{
LODWORD(v0) = puts("Stack is full");
}
else
{
v1 = *(double *)(8 * dstackptr++ + 0x198);
dstack[v0] = v1;
}
}
else
{
LODWORD(v0) = puts("Empty stack");
}
return v0;
}

original_code:
void dadup(void) {
    if (dstackptr == 0)
        printf("Empty stack\n");
    else if (dstackptr == 100)
        printf("Stack is full\n");
    else {
        double temp = dstack[dstackptr - 1];
        dstack[dstackptr++] = temp;
    }
}

canonical_original_code:
void dadup() {
    if (dstackptr == 0)
        printf("Empty stack\n");
    else if (dstackptr == 100)
        printf("Stack is full\n");
    else {
        double temp = dstack[dstackptr - 1];
        dstack[dstackptr++] = temp;
    }
}

variable_types: temp double


daswap

decompiled_code:
int daswap()
{
double v0; // xmm0_8
__int64 v1; // rax

if ( (unsigned __int64)dstackptr <= 1 )
{
LODWORD(v1) = puts("Less than two items are on the stack");
}
else
{
v0 = dstack[dstackptr - 1];
v1 = dstackptr - 2;
dstack[dstackptr - 1] = dstack[dstackptr - 2];
dstack[v1] = v0;
}
return v1;
}

canonical_decompiled_code:
int func4()
{
double v0; // xmm0_8
__int64 v1; // rax

if ( (unsigned __int64)dstackptr <= 1 )
{
LODWORD(v1) = puts("Less than two items are on the stack");
}
else
{
v0 = dstack[dstackptr - 1];
v1 = dstackptr - 2;
dstack[dstackptr - 1] = dstack[dstackptr - 2];
dstack[v1] = v0;
}
return v1;
}

original_code:
void daswap(void) {
    if (dstackptr < 2)
        printf("Less than two items are on the stack\n");
    else {
        double temp;
        temp = dstack[dstackptr - 1];
        dstack[dstackptr - 1] = dstack[dstackptr - 2];
        dstack[dstackptr - 2] = temp;
    }
}

canonical_original_code:
void daswap() {
    if (dstackptr < 2)
        printf("Less than two items are on the stack\n");
    else {
        double temp;
        temp = dstack[dstackptr - 1];
        dstack[dstackptr - 1] = dstack[dstackptr - 2];
        dstack[dstackptr - 2] = temp;
    }
}


dalist

decompiled_code:
int dalist()
{
unsigned __int64 v0; // rbx
int result; // eax

if ( dstackptr )
{
v0 = 0LL;
do
result = printf("%.8g\n", dstack[v0++]);
while ( dstackptr > v0 );
}
return result;
}

canonical_decompiled_code:
int func5()
{
unsigned __int64 v0; // rbx
int result; // eax

if ( dstackptr )
{
v0 = 0LL;
do
result = printf("%.8g\n", dstack[v0++]);
while ( dstackptr > v0 );
}
return result;
}

original_code:
void dalist(void) {
    size_t i;
    for (i = 0; i < dstackptr; i++)
        printf("%.8g\n", dstack[i]);
}

canonical_original_code:
void dalist() {
    unsigned long i;
    for (i = 0; i < dstackptr; i++)
        printf("%.8g\n", dstack[i]);
}

variable_types:
i
unsigned long


daclear

decompiled_code:
void daclear()
{
dstackptr = 0LL;
}

canonical_decompiled_code:
void func6()
{
dstackptr = 0LL;
}

original_code:
void daclear(void) {
    dstackptr = 0;
}

canonical_original_code:
void daclear() {
    dstackptr = 0;
}


dasize

decompiled_code:
__int64 dasize()
{
return dstackptr;
}

canonical_decompiled_code:
__int64 func7()
{
return dstackptr;
}

original_code:
size_t dasize(void) {
    return dstackptr;
}

canonical_original_code:
unsigned long dasize() {
    return dstackptr;
}

return_type: unsigned long


fseek

decompiled_code:
__int64 __fastcall fseek(int *a1, __off_t a2, int a3)
{
__off_t v3; // r12
int v5; // eax
__off_t v6; // rax
__int64 result; // rax
const void *v8; // rsi
__int64 v9; // r13
ssize_t v10; // rdx

v3 = a2;
v5 = a1[6];
if ( (v5 & 1) != 0 )
{
if ( a3 == 1 )
v3 = a2 - *a1;
v6 = lseek(a1[7], v3, a3);
*a1 = 0;
return (unsigned int)-(v6 == -1);
}
result = v5 & 2;
if ( (_DWORD)result )
{
v8 = (const void *)*((_QWORD *)a1 + 2);
v9 = *((_QWORD *)a1 + 1) - (_QWORD)v8;
if ( (unsigned int)*((_QWORD *)a1 + 1) == (_DWORD)v8
|| (v10 = write(a1[7], v8, (unsigned int)v9), v6 = -1LL, v10 == (unsigned int)v9) )
{
v6 = lseek(a1[7], v3, a3);
}
return (unsigned int)-(v6 == -1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, __off_t a2, int a3)
{
__off_t v3; // r12
int v5; // eax
__off_t v6; // rax
__int64 result; // rax
const void *v8; // rsi
__int64 v9; // r13
ssize_t v10; // rdx

v3 = a2;
v5 = a1[6];
if ( (v5 & 1) != 0 )
{
if ( a3 == 1 )
v3 = a2 - *a1;
v6 = lseek(a1[7], v3, a3);
*a1 = 0;
return (unsigned int)-(v6 == -1);
}
result = v5 & 2;
if ( (_DWORD)result )
{
v8 = (const void *)*((_QWORD *)a1 + 2);
v9 = *((_QWORD *)a1 + 1) - (_QWORD)v8;
if ( (unsigned int)*((_QWORD *)a1 + 1) == (_DWORD)v8
|| (v10 = write(a1[7], v8, (unsigned int)v9), v6 = -1LL, v10 == (unsigned int)v9) )
{
v6 = lseek(a1[7], v3, a3);
}
return (unsigned int)-(v6 == -1);
}
return result;
}

original_code:
int fseek(FILE *fp, long offset, int origin) {
    unsigned nc;
    long rc = 0;
    if (fp->flag & _READ) {
        if (origin == 1)
            offset -= fp->cnt;
        rc = lseek(fp->fd, offset, origin);
        fp->cnt = 0;
    } else if (fp->flag & _WRITE) {
        nc = (fp->ptr - fp->base);
        if (nc > 0)
            if (write(fp->fd, fp->base, nc) != nc)
                rc = -1;
        if (rc != -1)
            rc = lseek(fp->fd, offset, origin);
    }
    return (rc == -1) ? -1 : 0;
}

canonical_original_code:
int fseek(struct _iobuf *fp, long offset, int origin) {
    unsigned int nc;
    long rc = 0;
    if (fp->flag & _READ) {
        if (origin == 1)
            offset -= fp->cnt;
        rc = lseek(fp->fd, offset, origin);
        fp->cnt = 0;
    } else if (fp->flag & _WRITE) {
        nc = (fp->ptr - fp->base);
        if (nc > 0)
            if (write(fp->fd, fp->base, nc) != nc)
                rc = -1;
        if (rc != -1)
            rc = lseek(fp->fd, offset, origin);
    }
    return (rc == -1) ? -1 : 0;
}

variable_types: struct _iobuf { int cnt; char *ptr; char *base; int flag; int fd; } *

variable_types: offset long

variable_types: origin int

variable_types:
nc
unsigned int

variable_types: rc long

return_type: int


casize

decompiled_code:
__int64 casize()
{
return cstackptr;
}

canonical_decompiled_code:
__int64 func0()
{
return cstackptr;
}

original_code:
static size_t casize(void) {
    return cstackptr;
}

canonical_original_code:
static unsigned long casize() {
    return cstackptr;
}


capop

decompiled_code:
__int64 capop()
{
__int64 v0; // rax
__int64 result; // rax

v0 = cstackptr;
if ( cstackptr )
{
--cstackptr;
result = *(unsigned __int8 *)(v0 + 159);
}
else
{
puts("Error: Stack is empty--nothing to remove (pop) from it");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 result; // rax

v0 = cstackptr;
if ( cstackptr )
{
--cstackptr;
result = *(unsigned __int8 *)(v0 + 159);
}
else
{
puts("Error: Stack is empty--nothing to remove (pop) from it");
result = 0LL;
}
return result;
}

original_code:
char capop(void) {
    if (cstackptr > 0)
        return cstack[--cstackptr];
    printf("Error: Stack is empty--nothing to remove (pop) from it\n");
    return '\0';
}

canonical_original_code:
char capop() {
    if (cstackptr > 0)
        return cstack[--cstackptr];
    printf("Error: Stack is empty--nothing to remove (pop) from it\n");
    return '\0';
}


caempty

decompiled_code:
bool caempty()
{
return casize() == 0;
}

canonical_decompiled_code:
bool func3()
{
return func0() == 0;
}

original_code:
_Bool caempty(void) {
    return (casize() == 0);
}

canonical_original_code:
_Bool caempty() {
    return (casize() == 0);
}


isleap

original_code:
static _Bool isleap(int year) {
    return ((year % 4 == 0) && (year % 100) != 0) || (year % 400 == 0);
}

variable_types: year int


decompiled_code:
const char *__fastcall month_name(int a1)
{
const char *result; // rax

result = "Illegal month";
if ( (unsigned int)(a1 - 1) <= 0xB )
result = name_0[a1];
return result;
}

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

result = "Illegal month";
if ( (unsigned int)(a1 - 1) <= 0xB )
result = name_0[a1];
return result;
}

original_code:
static void *month_name(int month) {
    static char *name[] = {
        "Illegal month",
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
    };
    return (month < 1 || month > 12) ? name[0] : name[month];
}

variable_types: month int

variable_types:
name
char *[]

return_type: void *


compare

decompiled_code:
__int64 __fastcall compare(char *a1, __int64 a2, int a3, _BYTE *a4)
{
_BYTE *v7; // rdx
char v8; // cl
char *v9; // rax
int v10; // esi
int v11; // edi
__int64 result; // rax

v7 = *(_BYTE **)a2;
v8 = *a1;
if ( *a1 == **(_BYTE **)a2 )
{
v9 = a1;
v10 = 1 - (_DWORD)a1;
while ( v8 )
{
v11 = v10 + (_DWORD)v9++;
++v7;
v8 = *v9;
if ( *v9 != *v7 )
goto LABEL_5;
}
result = 0LL;
}
else
{
v9 = a1;
v11 = 0;
LABEL_5:
if ( a3 <= v11 )
{
*a4 = 1;
*(_BYTE *)(a2 + 8) = 1;
}
result = (unsigned int)(*v9 - (char)*v7);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __int64 a2, int a3, _BYTE *a4)
{
_BYTE *v7; // rdx
char v8; // cl
char *v9; // rax
int v10; // esi
int v11; // edi
__int64 result; // rax

v7 = *(_BYTE **)a2;
v8 = *a1;
if ( *a1 == **(_BYTE **)a2 )
{
v9 = a1;
v10 = 1 - (_DWORD)a1;
while ( v8 )
{
v11 = v10 + (_DWORD)v9++;
++v7;
v8 = *v9;
if ( *v9 != *v7 )
goto LABEL_5;
}
result = 0LL;
}
else
{
v9 = a1;
v11 = 0;
LABEL_5:
if ( a3 <= v11 )
{
*a4 = 1;
*(_BYTE *)(a2 + 8) = 1;
}
result = (unsigned int)(*v9 - (char)*v7);
}
return result;
}

original_code:
static int compare(char *s, struct tnode *p, int num, _Bool *found) {
    int i;
    char *t = p->word;
    for (i = 0; *s == *t; i++, s++, t++)
        if (*s == '\0')
            return 0;
    if (i >= num) {
        *found = 1;
        p->match = 1;
    }
    return *s - *t;
}

variable_types:
s
char *

variable_types: struct tnode { char *word; _Bool match; struct tnode *left; struct tnode *right; } *

variable_types: num int

variable_types:
found
_Bool *

variable_types: i int

variable_types:
t
char *


talloc

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

result = malloc(0x20uLL);
if ( !result )
{
printf("Error: ran out of memory");
exit(1);
}
return result;
}

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

result = malloc(0x20uLL);
if ( !result )
{
printf("Error: ran out of memory");
exit(1);
}
return result;
}

original_code:
static struct tnode *talloc(void) {
    struct tnode *p = (struct tnode *)malloc(sizeof(struct tnode));
    if (p == ((void *)0)) {
        printf("Error: ran out of memory");
        exit(1);
    }
    return p;
}

canonical_original_code:
static struct tnode *talloc() {
    struct tnode *p = (struct tnode *)malloc(sizeof(struct tnode));
    if (p == ((void *)0)) {
        printf("Error: ran out of memory");
        exit(1);
    }
    return p;
}

variable_types: struct tnode { char *word; int count; struct tnode *left; struct tnode *right; } *


mystrdup

decompiled_code:
char *__fastcall mystrdup(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
if ( !v2 )
{
printf("Error: ran out of memory");
exit(1);
}
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func9(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
if ( !v2 )
{
printf("Error: ran out of memory");
exit(1);
}
return strcpy(v2, src);
}

original_code:
static char *mystrdup(char *s) {
    char *p = (char *)malloc(strlen(s) + 1);
    if (p == ((void *)0)) {
        printf("Error: ran out of memory");
        exit(1);
    }
    strcpy(p, s);
    return p;
}

variable_types:
p
char *


wordlength

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

LODWORD(result) = 1;
do
result = (unsigned int)(result + 1);
while ( (_DWORD)result != 32 );
return result;
}

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

LODWORD(result) = 1;
do
result = (unsigned int)(result + 1);
while ( (_DWORD)result != 32 );
return result;
}

original_code:
static unsigned wordlength(void) {
    unsigned i;
    unsigned v = (unsigned)~0x00;
    for(i = 1; (v = v >> 1) > 0; i++)
        ;
    return i;
}

canonical_original_code:
static unsigned int wordlength() {
    unsigned int i;
    unsigned int v = (unsigned)~0x00;
    for(i = 1; (v = v >> 1) > 0; i++)
        ;
    return i;
}

variable_types:
i
unsigned int

variable_types:
v
unsigned int


rightrot

decompiled_code:
__int64 __fastcall rightrot(unsigned int a1, int a2)
{
int v2; // ebp
char v3; // cl
__int64 result; // rax

if ( !a2 )
return a1;
v2 = a2 - 1;
v3 = wordlength() - 1;
LODWORD(result) = a1;
do
{
result = ((result & 1) << v3) | ((unsigned int)result >> 1);
--v2;
}
while ( v2 != -1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2)
{
int v2; // ebp
char v3; // cl
__int64 result; // rax

if ( !a2 )
return a1;
v2 = a2 - 1;
v3 = func0() - 1;
LODWORD(result) = a1;
do
{
result = ((result & 1) << v3) | ((unsigned int)result >> 1);
--v2;
}
while ( v2 != -1 );
return result;
}

original_code:
static int rightrot(int x, unsigned n) {
    unsigned rbit;
    while (n-- > 0) {
        rbit = ((unsigned)x & 0x01) << (wordlength() - 1);
        x = (int)((unsigned)x >> 1);
        x = (int)((unsigned)x | rbit);
    }
    return x;
}

canonical_original_code:
static int rightrot(int x, unsigned int n) {
    unsigned int rbit;
    while (n-- > 0) {
        rbit = ((unsigned int)x & 0x01) << (wordlength() - 1);
        x = (int)((unsigned int)x >> 1);
        x = (int)((unsigned int)x | rbit);
    }
    return x;
}

variable_types: x int

variable_types:
n
unsigned int

variable_types:
rbit
unsigned int


printbits

decompiled_code:
int __fastcall printbits(int a1)
{
int v1; // ebx
int result; // eax

printf("0b");
v1 = 32;
do
{
if ( (a1 & (1 << --v1)) != 0 )
result = putchar(49);
else
result = putchar(48);
}
while ( v1 );
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int v1; // ebx
int result; // eax

printf("0b");
v1 = 32;
do
{
if ( (a1 & (1 << --v1)) != 0 )
result = putchar(49);
else
result = putchar(48);
}
while ( v1 );
return result;
}

original_code:
static void printbits(unsigned x) {
    unsigned i;
    printf("0b");
    for(i = (unsigned)(8 * sizeof(int)); i > 0; i--)
        (_Bool)(x & (1 << (i - 1))) ? putchar('1') : putchar('0');
}

canonical_original_code:
static void printbits(unsigned int x) {
    unsigned int i;
    printf("0b");
    for(i = (unsigned int)(8 * sizeof(int)); i > 0; i--)
        (_Bool)(x & (1 << (i - 1))) ? putchar('1') : putchar('0');
}

variable_types:
x
unsigned int


errmsg

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

result = printf("%s", a1);
prevtoken = 1;
return result;
}

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

result = printf("%s", a1);
prevtoken = 1;
return result;
}

original_code:
static void errmsg(char *msg) {
    printf("%s", msg);
    prevtoken = 1;
}

variable_types:
msg
char *


typespec

decompiled_code:
bool typespec()
{
char *key; // [rsp+8h] [rbp-10h] BYREF

key = token;
return bsearch(&key, &types_1, 9uLL, 8uLL, scompare) != 0LL;
}

canonical_decompiled_code:
bool func2()
{
char *key; // [rsp+8h] [rbp-10h] BYREF

key = token;
return bsearch(&key, &types_1, 9uLL, 8uLL, scompare) != 0LL;
}

original_code:
static _Bool typespec(void) {
    static char *types[] = {
        "char",
        "double",
        "float",
        "int",
        "long",
        "short",
        "signed",
        "unsigned",
        "void"
    };
    char *pt = token;
    char **result;
    result = (char **)bsearch( (char *) &pt, (char *)types, sizeof(types)/sizeof(types[0]),
                              sizeof( char * ), (int (*)(const void*, const void*))scompare);
    return (result != ((void *)0));}

canonical_original_code:
static _Bool typespec() {
    static char *types[] = {
        "char",
        "double",
        "float",
        "int",
        "long",
        "short",
        "signed",
        "unsigned",
        "void"
    };
    char *pt = token;
    char **result;
    result = (char **)bsearch( (char *) &pt, (char *)types, sizeof(types)/sizeof(types[0]),
                              sizeof( char * ), (int (*)(void *, void *))scompare);
    return (result != ((void *)0));}

variable_types:
types
char *[]

variable_types:
pt
char *

variable_types:
result
char **


typequal

decompiled_code:
bool typequal()
{
char *key; // [rsp+8h] [rbp-10h] BYREF

key = token;
return bsearch(&key, typeq_0, 2uLL, 8uLL, scompare) != 0LL;
}

canonical_decompiled_code:
bool func3()
{
char *key; // [rsp+8h] [rbp-10h] BYREF

key = token;
return bsearch(&key, typeq_0, 2uLL, 8uLL, scompare) != 0LL;
}

original_code:
static _Bool typequal(void) {
    static char *typeq[] = {
        "const",
        "volatile"
    };
    char *pt = token;
    char **result;
    result = (char **)bsearch( (char *) &pt, (char *)typeq, sizeof(typeq)/sizeof(typeq[0]),
                              sizeof( char * ), (int (*)(const void*, const void*))scompare);
    return (result != ((void *)0));
}

canonical_original_code:
static _Bool typequal() {
    static char *typeq[] = {
        "const",
        "volatile"
    };
    char *pt = token;
    char **result;
    result = (char **)bsearch( (char *) &pt, (char *)typeq, sizeof(typeq)/sizeof(typeq[0]),
                              sizeof( char * ), (int (*)(void *, void *))scompare);
    return (result != ((void *)0));
}

variable_types:
typeq
char *[]


scompare

decompiled_code:
int __fastcall scompare(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func4(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int scompare(char **s, char **t) {
    return strcmp(*s, *t);
}

variable_types:
s
char **

variable_types:
t
char **


gettoken

decompiled_code:
__int64 gettoken()
{
int v0; // eax
int v1; // ebx
const unsigned __int16 **v2; // rbp
int v4; // eax
char *v5; // rbx
char v6; // al
char *i; // rbx
const unsigned __int16 *v8; // r12
int v9; // eax

if ( prevtoken )
{
prevtoken = 0;
v1 = tokentype;
}
else
{
do
{
do
{
v0 = getch();
v1 = v0;
}
while ( v0 == 9 );
}
while ( v0 == 32 );
if ( v0 == 40 )
{
v4 = getch();
if ( v4 == 41 )
{
strcpy(token, "()");
tokentype = 1;
v1 = 1;
}
else
{
ungetch(v4);
tokentype = 40;
}
}
else if ( v0 == 91 )
{
token[0] = 91;
v5 = &token[1];
do
{
v6 = getch();
*v5++ = v6;
}
while ( v6 != 93 );
*v5 = 0;
tokentype = 2;
v1 = 2;
}
else
{
v2 = _ctype_b_loc();
if ( ((*v2)[v1] & 0x400) != 0 )
{
token[0] = v1;
for ( i = &token[1]; ; *(i - 1) = v9 )
{
v8 = *v2;
v9 = getch();
if ( (v8[v9] & 8) == 0 )
break;
++i;
}
*i = 0;
ungetch(v9);
tokentype = 0;
v1 = 0;
}
else
{
tokentype = v1;
}
}
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
int v1; // ebx
const unsigned __int16 **v2; // rbp
int v4; // eax
char *v5; // rbx
char v6; // al
char *i; // rbx
const unsigned __int16 *v8; // r12
int v9; // eax

if ( prevtoken )
{
prevtoken = 0;
v1 = tokentype;
}
else
{
do
{
do
{
v0 = func5();
v1 = v0;
}
while ( v0 == 9 );
}
while ( v0 == 32 );
if ( v0 == 40 )
{
v4 = func5();
if ( v4 == 41 )
{
strcpy(token, "()");
tokentype = 1;
v1 = 1;
}
else
{
func0(v4);
tokentype = 40;
}
}
else if ( v0 == 91 )
{
token[0] = 91;
v5 = &token[1];
do
{
v6 = func5();
*v5++ = v6;
}
while ( v6 != 93 );
*v5 = 0;
tokentype = 2;
v1 = 2;
}
else
{
v2 = _ctype_b_loc();
if ( ((*v2)[v1] & 0x400) != 0 )
{
token[0] = v1;
for ( i = &token[1]; ; *(i - 1) = v9 )
{
v8 = *v2;
v9 = func5();
if ( (v8[v9] & 8) == 0 )
break;
++i;
}
*i = 0;
func0(v9);
tokentype = 0;
v1 = 0;
}
else
{
tokentype = v1;
}
}
}
return (unsigned int)v1;
}

original_code:
static int gettoken(void) {
    int c;
    char *p = token;
    if (prevtoken) {
        prevtoken = 0;
        return tokentype;
    }
    while ((c = getch()) == ' ' || c == '\t')
        ;
    if (c == '(') {
        if ((c = getch()) == ')') {
            strcpy(token, "()");
            return (tokentype = PARENS);
        }
        ungetch(c);
        return (tokentype = '(');
    }
    if (c == '[') {
        for (*p++ = c; (*p++ = getch()) != ']'; )
            ;
        *p = '\0';
        return (tokentype = BRACKETS);
    }
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha)) {
        for (*p++ = c; ((*__ctype_b_loc ())[(int) ((c = getch()))] & (unsigned short int) _ISalnum); )
            *p++ = c;
        *p = '\0';
        ungetch(c);
        return (tokentype = NAME);
    }
    return (tokentype = c);
}

canonical_original_code:
static int gettoken() {
    int c;
    char *p = token;
    if (prevtoken) {
        prevtoken = 0;
        return tokentype;
    }
    while ((c = getch()) == ' ' || c == '\t')
        ;
    if (c == '(') {
        if ((c = getch()) == ')') {
            strcpy(token, "()");
            return (tokentype = PARENS);
        }
        ungetch(c);
        return (tokentype = '(');
    }
    if (c == '[') {
        for (*p++ = c; (*p++ = getch()) != ']'; )
            ;
        *p = '\0';
        return (tokentype = BRACKETS);
    }
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha)) {
        for (*p++ = c; ((*__ctype_b_loc ())[(int) ((c = getch()))] & (unsigned short) _ISalnum); )
            *p++ = c;
        *p = '\0';
        ungetch(c);
        return (tokentype = NAME);
    }
    return (tokentype = c);
}

variable_types: c int


dcl

decompiled_code:
size_t dcl()
{
int v0; // ebp
size_t result; // rax
int v2; // ebx

v0 = 0;
while ( (unsigned int)gettoken() == 42 )
++v0;
result = dirdcl();
v2 = v0 - 1;
if ( v0 > 0 )
{
do
{
result = strlen(out);
*(_QWORD *)&out[result] = 0x7265746E696F7020LL;
*(_DWORD *)((char *)&qword_5C8 + result) = 7304224;
--v2;
}
while ( v2 != -1 );
}
return result;
}

canonical_decompiled_code:
size_t func8()
{
int v0; // ebp
size_t result; // rax
int v2; // ebx

v0 = 0;
while ( (unsigned int)func6() == 42 )
++v0;
result = func7();
v2 = v0 - 1;
if ( v0 > 0 )
{
do
{
result = strlen(out);
*(_QWORD *)&out[result] = 0x7265746E696F7020LL;
*(_DWORD *)((char *)&qword_5C8 + result) = 7304224;
--v2;
}
while ( v2 != -1 );
}
return result;
}

original_code:
static void dcl(void) {
    int ns;
    for (ns = 0; gettoken() == '*'; )
        ns++;
    dirdcl();
    while (ns-- > 0)
        strcat(out, " pointer to");
}

canonical_original_code:
static void dcl() {
    int ns;
    for (ns = 0; gettoken() == '*'; )
        ns++;
    dirdcl();
    while (ns-- > 0)
        strcat(out, " pointer to");
}

variable_types: ns int


dclspec

decompiled_code:
size_t __fastcall dclspec(__int64 a1)
{
int v1; // ebx
size_t result; // rax
char v3[120]; // [rsp+0h] [rbp-78h] BYREF

v3[0] = 0;
gettoken(a1);
do
{
if ( tokentype )
{
prevtoken = 1;
dcl();
}
else if ( typespec() || typequal() )
{
*(_WORD *)&v3[strlen(v3)] = 32;
strcat(v3, token);
gettoken(v3);
}
else
{
errmsg("unknown type in parameter list\n");
}
v1 = tokentype;
}
while ( tokentype != 44 && tokentype != 41 );
result = (size_t)strcat(out, v3);
if ( v1 == 44 )
{
result = strlen(out);
*(_WORD *)&out[result] = 44;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func9(__int64 a1)
{
int v1; // ebx
size_t result; // rax
char v3[120]; // [rsp+0h] [rbp-78h] BYREF

v3[0] = 0;
func6(a1);
do
{
if ( tokentype )
{
prevtoken = 1;
func8();
}
else if ( func2() || func3() )
{
*(_WORD *)&v3[strlen(v3)] = 32;
strcat(v3, token);
func6(v3);
}
else
{
func1("unknown type in parameter list\n");
}
v1 = tokentype;
}
while ( tokentype != 44 && tokentype != 41 );
result = (size_t)strcat(out, v3);
if ( v1 == 44 )
{
result = strlen(out);
*(_WORD *)&out[result] = 44;
}
return result;
}

original_code:
static void dclspec(void) {
    char temp[100];
    temp[0] = '\0';
    (void)gettoken();
    do {
        if (tokentype != NAME) {
            prevtoken = 1;
            dcl();
        } else if (typespec() || typequal()) {
            strcat(temp, " ");
            strcat(temp, token);
            (void)gettoken();
        } else
            errmsg("unknown type in parameter list\n");
    } while (tokentype != ',' && tokentype != ')');
    strcat(out, temp);
    if (tokentype == ',')
        strcat(out, ",");
}

canonical_original_code:
static void dclspec() {
    char temp[100];
    temp[0] = '\0';
    (void)gettoken();
    do {
        if (tokentype != NAME) {
            prevtoken = 1;
            dcl();
        } else if (typespec() || typequal()) {
            strcat(temp, " ");
            strcat(temp, token);
            (void)gettoken();
        } else
            errmsg("unknown type in parameter list\n");
    } while (tokentype != ',' && tokentype != ')');
    strcat(out, temp);
    if (tokentype == ',')
        strcat(out, ",");
}

variable_types:
temp
char [100]


parmdcl

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

do
{
dclspec(a1);
result = tokentype;
}
while ( tokentype == 44 );
if ( tokentype != 41 )
result = errmsg("missing ')' in parameter declaration\n");
return result;
}

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

do
{
func9(a1);
result = tokentype;
}
while ( tokentype == 44 );
if ( tokentype != 41 )
result = func1("missing ')' in parameter declaration\n");
return result;
}

original_code:
static void parmdcl(void) {
    do {
        dclspec();
    } while (tokentype == ',');
    if (tokentype != ')')
        errmsg("missing ')' in parameter declaration\n");
}

canonical_original_code:
static void parmdcl() {
    do {
        dclspec();
    } while (tokentype == ',');
    if (tokentype != ')')
        errmsg("missing ')' in parameter declaration\n");
}


readargs

original_code:
static void readargs(int argc, char *argv[]) {
    int c;
    while (--argc > 0 && ((c = (*++argv)[0]) == '-' || c == '+'))
        if (c == '-' && !((*__ctype_b_loc ())[(int) ((*(argv[0]+1)))] & (unsigned short int) _ISdigit))
            while ((c = *++argv[0]) != '\0')
                switch (c) {
                    case 'n':
                        numeric = 1;
                        break;
                    case 'r':
                        descend = 1;
                        break;
                    case 'f':
                        fold = 1;
                        break;
                    case 'd':
                        dir = 1;
                        break;
                    default:
                        printf("sort: illegal option %c\n", c);
                        exit(1);
                }
        else if (c == '-')
            pos2 = (size_t)atoi(argv[0]+1);
        else
            pos1 = (size_t)atoi(argv[0]+1);
    if ((argc == 0) || (pos1 > pos2))
        error("usage: sort -dnfr [+pos1] [-pos2] [FILE]");
}

canonical_original_code:
static void readargs(int argc, char *argv[]) {
    int c;
    while (--argc > 0 && ((c = (*++argv)[0]) == '-' || c == '+'))
        if (c == '-' && !((*__ctype_b_loc ())[(int) ((*(argv[0]+1)))] & (unsigned short) _ISdigit))
            while ((c = *++argv[0]) != '\0')
                switch (c) {
                    case 'n':
                        numeric = 1;
                        break;
                    case 'r':
                        descend = 1;
                        break;
                    case 'f':
                        fold = 1;
                        break;
                    case 'd':
                        dir = 1;
                        break;
                    default:
                        printf("sort: illegal option %c\n", c);
                        exit(1);
                }
        else if (c == '-')
            pos2 = (unsigned long)atoi(argv[0]+1);
        else
            pos1 = (unsigned long)atoi(argv[0]+1);
    if ((argc == 0) || (pos1 > pos2))
        error("usage: sort -dnfr [+pos1] [-pos2] [FILE]");
}

variable_types: argc int

variable_types:
argv
char *[]


alloc

decompiled_code:
void *__fastcall alloc(int a1)
{
void *v1; // rdx

v1 = allocp;
if ( "substr: string is too short" - (_BYTE *)allocp < a1 )
return 0LL;
allocp = (char *)allocp + a1;
return v1;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *v1; // rdx

v1 = allocp;
if ( "substr: string is too short" - (_BYTE *)allocp < a1 )
return 0LL;
allocp = (char *)allocp + a1;
return v1;
}

original_code:
static char *alloc(int n) {
    if (allocbuf + 10000000 - allocp >= n) {
        allocp += n;
        return allocp - n;
    }
    return 0;
}

variable_types: n int


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
puts(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
puts(a1);
exit(1);
}

original_code:
static void error(char *s) {
    printf("%s\n", s);
    exit(1);
}

variable_types:
s
char *


dircmp

decompiled_code:
__int64 __fastcall dircmp(const char *a1, const char *a2)
{
unsigned __int64 v3; // r14
size_t v4; // rbx
size_t v5; // rax
unsigned __int64 i; // r12
unsigned __int64 v7; // rax
char v8; // dl
char v9; // cl
unsigned __int64 v10; // rax
const unsigned __int16 **v11; // rdx
char v12; // al
const unsigned __int16 *v13; // rsi
char v14; // dl

v3 = pos1;
v4 = pos2;
if ( !pos2 )
{
v4 = strlen(a1);
v5 = strlen(a2);
if ( v5 <= v4 )
v4 = v5;
}
for ( i = v3 + 1; ; ++i )
{
if ( i - 1 < v4 )
{
v11 = _ctype_b_loc();
v12 = a1[i - 1];
if ( ((*v11)[v12] & 8) == 0 && (v12 & 0xDF) != 0 )
continue;
}
if ( v3 >= v4 )
{
v7 = v3;
}
else
{
v13 = *_ctype_b_loc();
v7 = v3;
while ( 1 )
{
v14 = a2[v7];
if ( (v13[v14] & 8) != 0 || (v14 & 0xDF) == 0 )
break;
if ( ++v7 == v4 )
{
v7 = v4;
break;
}
}
}
v8 = a1[i - 1];
v3 = v7 + 1;
v9 = a2[v7];
if ( !((unsigned __int8)v9 | (unsigned __int8)v8) )
break;
v10 = i;
if ( v3 >= i )
v10 = v3;
if ( v4 <= v10 || v8 != v9 )
return (unsigned int)(v8 - v9);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, const char *a2)
{
unsigned __int64 v3; // r14
size_t v4; // rbx
size_t v5; // rax
unsigned __int64 i; // r12
unsigned __int64 v7; // rax
char v8; // dl
char v9; // cl
unsigned __int64 v10; // rax
const unsigned __int16 **v11; // rdx
char v12; // al
const unsigned __int16 *v13; // rsi
char v14; // dl

v3 = pos1;
v4 = pos2;
if ( !pos2 )
{
v4 = strlen(a1);
v5 = strlen(a2);
if ( v5 <= v4 )
v4 = v5;
}
for ( i = v3 + 1; ; ++i )
{
if ( i - 1 < v4 )
{
v11 = _ctype_b_loc();
v12 = a1[i - 1];
if ( ((*v11)[v12] & 8) == 0 && (v12 & 0xDF) != 0 )
continue;
}
if ( v3 >= v4 )
{
v7 = v3;
}
else
{
v13 = *_ctype_b_loc();
v7 = v3;
while ( 1 )
{
v14 = a2[v7];
if ( (v13[v14] & 8) != 0 || (v14 & 0xDF) == 0 )
break;
if ( ++v7 == v4 )
{
v7 = v4;
break;
}
}
}
v8 = a1[i - 1];
v3 = v7 + 1;
v9 = a2[v7];
if ( !((unsigned __int8)v9 | (unsigned __int8)v8) )
break;
v10 = i;
if ( v3 >= i )
v10 = v3;
if ( v4 <= v10 || v8 != v9 )
return (unsigned int)(v8 - v9);
}
return 0LL;
}

original_code:
static int dircmp(const char *s, const char *t) {
    char a;
    char b;
    size_t i = pos1;
    size_t j = pos1;
    size_t endpos;
    if (pos2 > 0)
        endpos = pos2;
    else if ((endpos = strlen(s)) > strlen(t))
        endpos = strlen(t);
    do {
        while (i < endpos && !((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISalnum) && s[i] != ' ' && s[i] != '\0')
            i++;
        while (j < endpos && !((*__ctype_b_loc ())[(int) ((t[j]))] & (unsigned short int) _ISalnum) && t[j] != ' ' && t[j] != '\0')
            j++;
        a = s[i++];
        b = t[j++];
        if (a == '\0' && b == '\0')
            return 0;
    } while (a == b && i < endpos && j < endpos);
    return a - b;
}

canonical_original_code:
static int dircmp(char *s, char *t) {
    char a;
    char b;
    unsigned long i = pos1;
    unsigned long j = pos1;
    unsigned long endpos;
    if (pos2 > 0)
        endpos = pos2;
    else if ((endpos = strlen(s)) > strlen(t))
        endpos = strlen(t);
    do {
        while (i < endpos && !((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISalnum) && s[i] != ' ' && s[i] != '\0')
            i++;
        while (j < endpos && !((*__ctype_b_loc ())[(int) ((t[j]))] & (unsigned short) _ISalnum) && t[j] != ' ' && t[j] != '\0')
            j++;
        a = s[i++];
        b = t[j++];
        if (a == '\0' && b == '\0')
            return 0;
    } while (a == b && i < endpos && j < endpos);
    return a - b;
}

variable_types:
t
char *

variable_types: a char

variable_types: b char

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
endpos
unsigned long


foldcmp

decompiled_code:
__int64 __fastcall foldcmp(const char *a1, const char *a2)
{
unsigned __int64 v3; // rbx
size_t v4; // r14
size_t v5; // rax
const __int32_t *v6; // rcx
char v7; // al
__int32_t v8; // edx
__int32_t v9; // esi

v3 = pos1;
v4 = pos2;
if ( !pos2 )
{
v4 = strlen(a1);
v5 = strlen(a2);
if ( v5 <= v4 )
v4 = v5;
}
v6 = *_ctype_tolower_loc();
while ( 1 )
{
v7 = a1[v3];
v8 = v6[v7];
v9 = v6[a2[v3]];
if ( v8 != v9 || v4 <= v3 )
break;
if ( !v7 )
return 0LL;
++v3;
}
return (unsigned int)(v8 - v9);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, const char *a2)
{
unsigned __int64 v3; // rbx
size_t v4; // r14
size_t v5; // rax
const __int32_t *v6; // rcx
char v7; // al
__int32_t v8; // edx
__int32_t v9; // esi

v3 = pos1;
v4 = pos2;
if ( !pos2 )
{
v4 = strlen(a1);
v5 = strlen(a2);
if ( v5 <= v4 )
v4 = v5;
}
v6 = *_ctype_tolower_loc();
while ( 1 )
{
v7 = a1[v3];
v8 = v6[v7];
v9 = v6[a2[v3]];
if ( v8 != v9 || v4 <= v3 )
break;
if ( !v7 )
return 0LL;
++v3;
}
return (unsigned int)(v8 - v9);
}

original_code:
static int foldcmp(const char *s, const char *t) {
    size_t i = pos1;
    size_t j = pos1;
    size_t endpos;
    if (pos2 > 0)
        endpos = pos2;
    else if ((endpos = strlen(s)) > strlen(t))
        endpos = strlen(t);
    for ( ; tolower(s[i]) == tolower(t[j]) && i < endpos && j < endpos; i++, j++)
        if (s[i] == '\0')
            return 0;
    return tolower(s[i]) - tolower(t[j]);
}

canonical_original_code:
static int foldcmp(char *s, char *t) {
    unsigned long i = pos1;
    unsigned long j = pos1;
    unsigned long endpos;
    if (pos2 > 0)
        endpos = pos2;
    else if ((endpos = strlen(s)) > strlen(t))
        endpos = strlen(t);
    for ( ; tolower(s[i]) == tolower(t[j]) && i < endpos && j < endpos; i++, j++)
        if (s[i] == '\0')
            return 0;
    return tolower(s[i]) - tolower(t[j]);
}


folddircmp

decompiled_code:
__int64 __fastcall folddircmp(const char *a1, const char *a2)
{
unsigned __int64 v2; // r15
size_t v3; // rbp
size_t v4; // rax
unsigned __int64 i; // r13
unsigned __int64 v6; // rbx
const __int32_t *v7; // rax
__int32_t v8; // edx
__int32_t v9; // eax
size_t v10; // rcx
const unsigned __int16 **v11; // rdx
char v12; // al
const unsigned __int16 *v13; // rcx
char v14; // al

v2 = pos1;
v3 = pos2;
if ( !pos2 )
{
v3 = strlen(a1);
v4 = strlen(a2);
if ( v4 <= v3 )
v3 = v4;
}
for ( i = v2 + 1; ; ++i )
{
if ( v3 > i - 1 )
{
v11 = _ctype_b_loc();
v12 = a1[i - 1];
if ( ((*v11)[v12] & 8) == 0 && (v12 & 0xDF) != 0 )
continue;
}
if ( v3 <= v2 )
{
v6 = v2;
}
else
{
v13 = *_ctype_b_loc();
v6 = v2;
do
{
v14 = a2[v6];
if ( (v13[v14] & 8) != 0 )
break;
if ( (v14 & 0xDF) == 0 )
break;
++v6;
}
while ( v3 != v6 );
}
v7 = *_ctype_tolower_loc();
v8 = v7[a1[i - 1]];
v2 = v6 + 1;
v9 = v7[a2[v6]];
if ( !((unsigned __int8)v8 | (unsigned __int8)v9) )
break;
v10 = i;
if ( v2 >= i )
v10 = v6 + 1;
if ( v3 <= v10 || (_BYTE)v8 != (_BYTE)v9 )
return (unsigned int)((char)v8 - (char)v9);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, const char *a2)
{
unsigned __int64 v2; // r15
size_t v3; // rbp
size_t v4; // rax
unsigned __int64 i; // r13
unsigned __int64 v6; // rbx
const __int32_t *v7; // rax
__int32_t v8; // edx
__int32_t v9; // eax
size_t v10; // rcx
const unsigned __int16 **v11; // rdx
char v12; // al
const unsigned __int16 *v13; // rcx
char v14; // al

v2 = pos1;
v3 = pos2;
if ( !pos2 )
{
v3 = strlen(a1);
v4 = strlen(a2);
if ( v4 <= v3 )
v3 = v4;
}
for ( i = v2 + 1; ; ++i )
{
if ( v3 > i - 1 )
{
v11 = _ctype_b_loc();
v12 = a1[i - 1];
if ( ((*v11)[v12] & 8) == 0 && (v12 & 0xDF) != 0 )
continue;
}
if ( v3 <= v2 )
{
v6 = v2;
}
else
{
v13 = *_ctype_b_loc();
v6 = v2;
do
{
v14 = a2[v6];
if ( (v13[v14] & 8) != 0 )
break;
if ( (v14 & 0xDF) == 0 )
break;
++v6;
}
while ( v3 != v6 );
}
v7 = *_ctype_tolower_loc();
v8 = v7[a1[i - 1]];
v2 = v6 + 1;
v9 = v7[a2[v6]];
if ( !((unsigned __int8)v8 | (unsigned __int8)v9) )
break;
v10 = i;
if ( v2 >= i )
v10 = v6 + 1;
if ( v3 <= v10 || (_BYTE)v8 != (_BYTE)v9 )
return (unsigned int)((char)v8 - (char)v9);
}
return 0LL;
}

original_code:
static int folddircmp(const char *s, const char *t) {
    char a;
    char b;
    size_t i = pos1;
    size_t j = pos1;
    size_t endpos;
    if (pos2 > 0)
        endpos = pos2;
    else if ((endpos = strlen(s)) > strlen(t))
        endpos = strlen(t);
    do {
        while (i < endpos && !((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short int) _ISalnum) && s[i] != ' ' && s[i] != '\0')
            i++;
        while (j < endpos && !((*__ctype_b_loc ())[(int) ((t[j]))] & (unsigned short int) _ISalnum) && t[j] != ' ' && t[j] != '\0')
            j++;
        a = tolower(s[i++]);
        b = tolower(t[j++]);
        if (a == '\0' && b == '\0')
            return 0;
    } while (a == b && i < endpos && j < endpos);
    return a - b;
}

canonical_original_code:
static int folddircmp(char *s, char *t) {
    char a;
    char b;
    unsigned long i = pos1;
    unsigned long j = pos1;
    unsigned long endpos;
    if (pos2 > 0)
        endpos = pos2;
    else if ((endpos = strlen(s)) > strlen(t))
        endpos = strlen(t);
    do {
        while (i < endpos && !((*__ctype_b_loc ())[(int) ((s[i]))] & (unsigned short) _ISalnum) && s[i] != ' ' && s[i] != '\0')
            i++;
        while (j < endpos && !((*__ctype_b_loc ())[(int) ((t[j]))] & (unsigned short) _ISalnum) && t[j] != ' ' && t[j] != '\0')
            j++;
        a = tolower(s[i++]);
        b = tolower(t[j++]);
        if (a == '\0' && b == '\0')
            return 0;
    } while (a == b && i < endpos && j < endpos);
    return a - b;
}


numcmp

decompiled_code:
__int64 __fastcall numcmp(char *nptr, char *a2)
{
double v2; // rbp
double v3; // xmm0_8
__int64 result; // rax
_BYTE v5[1032]; // [rsp+0h] [rbp-408h] BYREF

substr(nptr, v5);
v2 = atof(nptr);
substr(a2, v5);
v3 = atof(a2);
result = 0xFFFFFFFFLL;
if ( v3 <= v2 )
result = v2 > v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *nptr, char *a2)
{
double v2; // rbp
double v3; // xmm0_8
__int64 result; // rax
_BYTE v5[1032]; // [rsp+0h] [rbp-408h] BYREF

substr(nptr, v5);
v2 = atof(nptr);
substr(a2, v5);
v3 = atof(a2);
result = 0xFFFFFFFFLL;
if ( v3 <= v2 )
result = v2 > v3;
return result;
}

original_code:
static int numcmp(const char *s1, const char *s2) {
    double v1;
    double v2;
    char str[1000];
    substr(s1, str);
    v1 = atof(s1);
    substr(s2, str);
    v2 = atof(s2);
    if (v1 < v2)
        return -1;
    else if (v1 > v2)
        return 1;
    else
        return 0;
}

canonical_original_code:
static int numcmp(char *s1, char *s2) {
    double v1;
    double v2;
    char str[1000];
    substr(s1, str);
    v1 = atof(s1);
    substr(s2, str);
    v2 = atof(s2);
    if (v1 < v2)
        return -1;
    else if (v1 > v2)
        return 1;
    else
        return 0;
}

variable_types:
str
char [1000]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // dl
int v4; // eax
int v5; // ebx

readargs(argc, (char **)argv);
v4 = readlines((__int64)&lineptr, 10000, v3);
if ( v4 < 0 )
{
puts("Input is too big to sort");
exit(1);
}
v5 = v4;
if ( numeric )
{
myqsort((__int64)&lineptr, 0, v4 - 1, (int (__fastcall *)(_QWORD, _QWORD))numcmp);
}
else if ( fold )
{
if ( dir )
myqsort((__int64)&lineptr, 0, v4 - 1, (int (__fastcall *)(_QWORD, _QWORD))folddircmp);
else
myqsort((__int64)&lineptr, 0, v4 - 1, (int (__fastcall *)(_QWORD, _QWORD))foldcmp);
}
else if ( dir )
{
myqsort((__int64)&lineptr, 0, v4 - 1, (int (__fastcall *)(_QWORD, _QWORD))dircmp);
}
else
{
myqsort((__int64)&lineptr, 0, v4 - 1, (int (__fastcall *)(_QWORD, _QWORD))&strcmp);
}
writelines((const char **)&lineptr, v5, descend);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // dl
int v4; // eax
int v5; // ebx

func8(argc, (char **)argv);
v4 = func9((__int64)&lineptr, 10000, v3);
if ( v4 < 0 )
{
puts("Input is too big to sort");
exit(1);
}
v5 = v4;
if ( numeric )
{
func1((__int64)&lineptr, 0, v4 - 1, (int (__fastcall *)(_QWORD, _QWORD))numcmp);
}
else if ( fold )
{
if ( dir )
func1((__int64)&lineptr, 0, v4 - 1, (int (__fastcall *)(_QWORD, _QWORD))folddircmp);
else
func1((__int64)&lineptr, 0, v4 - 1, (int (__fastcall *)(_QWORD, _QWORD))foldcmp);
}
else if ( dir )
{
func1((__int64)&lineptr, 0, v4 - 1, (int (__fastcall *)(_QWORD, _QWORD))dircmp);
}
else
{
func1((__int64)&lineptr, 0, v4 - 1, (int (__fastcall *)(_QWORD, _QWORD))&strcmp);
}
func2((const char **)&lineptr, v5, descend);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    int nlines;
    readargs(argc, argv);
    if ((nlines = readlines(lineptr, 10000)) < 0) {
        printf("Input is too big to sort\n");
        exit(1);
    }
    if (numeric)
        myqsort(
                (void **) lineptr,
                0,
                nlines - 1,
                (int (*)(void*, void*))numcmp
            );
    else if (fold && dir)
        myqsort(
                (void **) lineptr,
                0,
                nlines - 1,
                (int (*)(void*, void*))folddircmp
            );
    else if (fold)
        myqsort(
                (void **) lineptr,
                0,
                nlines - 1,
                (int (*)(void*, void*))foldcmp
            );
    else if (dir)
        myqsort(
                (void **) lineptr,
                0,
                nlines - 1,
                (int (*)(void*, void*))dircmp
            );
    else
        myqsort(
                (void **) lineptr,
                0,
                nlines - 1,
                (int (*)(void*, void*))strcmp
            );
    writelines(lineptr, nlines, descend);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    int nlines;
    readargs(argc, argv);
    if ((nlines = readlines(lineptr, 10000)) < 0) {
        printf("Input is too big to sort\n");
        exit(1);
    }
    if (numeric)
        myqsort(
                (void **) lineptr,
                0,
                nlines - 1,
                (int (*)(void *, void *))numcmp
            );
    else if (fold && dir)
        myqsort(
                (void **) lineptr,
                0,
                nlines - 1,
                (int (*)(void *, void *))folddircmp
            );
    else if (fold)
        myqsort(
                (void **) lineptr,
                0,
                nlines - 1,
                (int (*)(void *, void *))foldcmp
            );
    else if (dir)
        myqsort(
                (void **) lineptr,
                0,
                nlines - 1,
                (int (*)(void *, void *))dircmp
            );
    else
        myqsort(
                (void **) lineptr,
                0,
                nlines - 1,
                (int (*)(void *, void *))strcmp
            );
    writelines(lineptr, nlines, descend);
    return 0;
}

variable_types: nlines int


strcat

decompiled_code:
__int64 __fastcall strcat(_BYTE *a1, __int64 a2)
{
__int64 result; // rax
char v3; // dl

for ( ; *a1; ++a1 )
;
result = 0LL;
do
{
v3 = *(_BYTE *)(a2 + result);
a1[result++] = v3;
}
while ( v3 );
return result;
}

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

for ( ; *a1; ++a1 )
;
result = 0LL;
do
{
v3 = *(_BYTE *)(a2 + result);
a1[result++] = v3;
}
while ( v3 );
return result;
}

original_code:
static void strcat(char *leftstr, char *rightstr) {
    while (*leftstr != '\0')
        leftstr++;
    while ((*leftstr++ = *rightstr++) != '\0')
        ;
}

variable_types:
leftstr
char *

variable_types:
rightstr
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[24]; // [rsp+0h] [rbp-7E8h] BYREF
__int64 v5; // [rsp+18h] [rbp-7D0h]
char v6[968]; // [rsp+20h] [rbp-7C8h] BYREF
char v7[32]; // [rsp+3F0h] [rbp-3F8h] BYREF
char v8[968]; // [rsp+410h] [rbp-3D8h] BYREF

strcpy(v7, "This is the first string");
memset(v8, 0, sizeof(v8));
strcpy(v4, "And this is a second");
v5 = 0LL;
memset(v6, 0, sizeof(v6));
printf("Adding \"%s\" to the end of \"%s\" results in: ", v4, v7);
strcat(v7, (__int64)v4);
printf("\"%s\"\n", v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[24]; // [rsp+0h] [rbp-7E8h] BYREF
__int64 v5; // [rsp+18h] [rbp-7D0h]
char v6[968]; // [rsp+20h] [rbp-7C8h] BYREF
char v7[32]; // [rsp+3F0h] [rbp-3F8h] BYREF
char v8[968]; // [rsp+410h] [rbp-3D8h] BYREF

strcpy(v7, "This is the first string");
memset(v8, 0, sizeof(v8));
strcpy(v4, "And this is a second");
v5 = 0LL;
memset(v6, 0, sizeof(v6));
printf("Adding \"%s\" to the end of \"%s\" results in: ", v4, v7);
func0(v7, (__int64)v4);
printf("\"%s\"\n", v7);
return 0;
}

original_code:
int main(void) {
    char string1[1000] = "This is the first string";
    char string2[1000] = "And this is a second";
    printf("Adding \"%s\" to the end of \"%s\" results in: ", string2, string1);
    strcat(string1, string2);
    printf("\"%s\"\n", string1);
    return 0;
}

canonical_original_code:
int main() {
    char string1[1000] = "This is the first string";
    char string2[1000] = "And this is a second";
    printf("Adding \"%s\" to the end of \"%s\" results in: ", string2, string1);
    strcat(string1, string2);
    printf("\"%s\"\n", string1);
    return 0;
}


header

decompiled_code:
__int64 __fastcall header(const char *a1, unsigned int a2)
{
fprintf(stdout, "\n\n%s\t(page %d)\n", a1, a2);
fputc(10, stdout);
fputc(10, stdout);
return 6LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, unsigned int a2)
{
fprintf(stdout, "\n\n%s\t(page %d)\n", a1, a2);
fputc(10, stdout);
fputc(10, stdout);
return 6LL;
}

original_code:
static int header(char *fname, int pageno) {
    int ln = 3;
    fprintf(stdout, "\n\n%s\t(page %d)\n", fname, pageno);
    while (ln++ < 5)
        fprintf(stdout, "\n");
    return ln;
}

variable_types:
fname
char *

variable_types: pageno int

variable_types: ln int


footer

decompiled_code:
int footer()
{
return fputc(12, stdout);
}

canonical_decompiled_code:
int func1()
{
return fputc(12, stdout);
}

original_code:
static void footer(void) {
    fprintf(stdout, "\f");
}

canonical_original_code:
static void footer() {
    fprintf(stdout, "\f");
}


bitcount

decompiled_code:
__int64 __fastcall bitcount(int a1)
{
unsigned int v1; // edx

if ( !a1 )
return 0;
v1 = 0;
do
{
++v1;
a1 &= a1 - 1;
}
while ( a1 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // edx

if ( !a1 )
return 0;
v1 = 0;
do
{
++v1;
a1 &= a1 - 1;
}
while ( a1 );
return v1;
}

original_code:
static unsigned bitcount(int x) {
        unsigned bits;
        unsigned ux;
        ux = (unsigned)x;
        for (bits = 0; ux != 0; ux &= (ux - 1))
            bits++;
        return bits;
    }

canonical_original_code:
static unsigned int bitcount(int x) {
        unsigned int bits;
        unsigned int ux;
        ux = (unsigned int)x;
        for (bits = 0; ux != 0; ux &= (ux - 1))
            bits++;
        return bits;
    }

variable_types: x int

variable_types:
bits
unsigned int

variable_types:
ux
unsigned int


printbits

decompiled_code:
int __fastcall printbits(int a1)
{
int v1; // ebx
int result; // eax

printf("0b");
v1 = 32;
do
{
if ( (a1 & (1 << --v1)) != 0 )
result = putchar(49);
else
result = putchar(48);
}
while ( v1 );
return result;
}

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

printf("0b");
v1 = 32;
do
{
if ( (a1 & (1 << --v1)) != 0 )
result = putchar(49);
else
result = putchar(48);
}
while ( v1 );
return result;
}

original_code:
static void printbits(unsigned x) {
    unsigned i;
    printf("0b");
    for(i = (unsigned)(8 * sizeof(int)); i > 0; i--)
        (_Bool)(x & (1 << (i - 1))) ? putchar('1') : putchar('0');
}

variable_types:
x
unsigned int

variable_types:
i
unsigned int


makepoint

decompiled_code:
__int64 __fastcall makepoint(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

original_code:
static struct point makepoint(const int x, const int y) {
    struct point temp;
    temp.x = x;
    temp.y = y;
    return temp;
}

canonical_original_code:
static struct point makepoint(int x, int y) {
    struct point temp;
    temp.x = x;
    temp.y = y;
    return temp;
}

variable_types: y int

variable_types:
temp
struct point { int x; int y; }

return_type: struct point { int x; int y; }


canonrect

decompiled_code:
__int64 __fastcall canonrect(__int64 a1, __int64 a2)
{
unsigned int v2; // er8
__int64 v3; // rcx

v2 = a2;
if ( (int)a1 <= (int)a2 )
v2 = a1;
v3 = HIDWORD(a2);
if ( SHIDWORD(a1) <= SHIDWORD(a2) )
v3 = HIDWORD(a1);
return (v3 << 32) | v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // er8
__int64 v3; // rcx

v2 = a2;
if ( (int)a1 <= (int)a2 )
v2 = a1;
v3 = HIDWORD(a2);
if ( SHIDWORD(a1) <= SHIDWORD(a2) )
v3 = HIDWORD(a1);
return (v3 << 32) | v2;
}

original_code:
static struct rect canonrect(const struct rect r) {
    struct rect temp;
    temp.p1.x = ((r.p1.x) < (r.p2.x) ? (r.p1.x) : (r.p2.x));
    temp.p1.y = ((r.p1.y) < (r.p2.y) ? (r.p1.y) : (r.p2.y));
    temp.p2.x = ((r.p1.x) > (r.p2.x) ? (r.p1.x) : (r.p2.x));
    temp.p2.y = ((r.p1.y) > (r.p2.y) ? (r.p1.y) : (r.p2.y));
    return temp;
}

canonical_original_code:
static struct rect canonrect(struct rect r) {
    struct rect temp;
    temp.p1.x = ((r.p1.x) < (r.p2.x) ? (r.p1.x) : (r.p2.x));
    temp.p1.y = ((r.p1.y) < (r.p2.y) ? (r.p1.y) : (r.p2.y));
    temp.p2.x = ((r.p1.x) > (r.p2.x) ? (r.p1.x) : (r.p2.x));
    temp.p2.y = ((r.p1.y) > (r.p2.y) ? (r.p1.y) : (r.p2.y));
    return temp;
}

variable_types:
r
struct rect

variable_types: struct rect { struct point { int x; int y; } p1; struct point p2; }

user_defined_types: struct rect { struct point p1; struct point p2; }


origindist

decompiled_code:
double __fastcall origindist(__int64 a1)
{
double v1; // xmm0_8
double result; // xmm0_8

v1 = (double)(int)a1 * (double)(int)a1 + (double)SHIDWORD(a1) * (double)SHIDWORD(a1);
if ( v1 < 0.0 )
result = sqrt(v1);
else
result = sqrt(v1);
return result;
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1)
{
double v1; // xmm0_8
double result; // xmm0_8

v1 = (double)(int)a1 * (double)(int)a1 + (double)SHIDWORD(a1) * (double)SHIDWORD(a1);
if ( v1 < 0.0 )
result = sqrt(v1);
else
result = sqrt(v1);
return result;
}

original_code:
static double origindist(const struct point pt) {
    return sqrt((double)pt.x * pt.x + (double)pt.y * pt.y);
}

canonical_original_code:
static double origindist(struct point pt) {
    return sqrt((double)pt.x * pt.x + (double)pt.y * pt.y);
}

variable_types:
pt
struct point { int x; int y; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
__int64 v4; // rbp
unsigned __int64 v5; // r12
__int64 v6; // r13
__int64 v7; // rbx
unsigned __int64 v8; // rdx
double v9; // xmm0_8
const char *v10; // rsi
bool v11; // al
const char *v12; // rcx
__int64 v14; // [rsp+0h] [rbp-48h]
unsigned __int64 v15; // [rsp+8h] [rbp-40h]

v3 = makepoint(0xAu, 20LL);
v4 = makepoint(0xC8u, 400LL);
v5 = makepoint(0x71u, 42LL);
v6 = makepoint(0xA0u, 100LL);
v7 = addpoint(0xC800000140LL, 0xC800000140LL);
v14 = canonrect(v4, v5);
v15 = v8;
printf("Point 'pt' is at coordinates (%d, %d)\n", (unsigned int)v3, v3 >> 32);
printf("Point 'origin' is at coordinate (%d, %d)\n", 0LL, 0LL);
printf("Or, when we access it another way with '->' it is still at (%d, %d)\n", 0LL, 0LL);
printf("Point 'maxpt' is at coordinates (%d, %d)\n", 320LL, 200LL);
printf("This point added with itself is (%d, %d)\n", (unsigned int)v7, HIDWORD(v7));
v9 = origindist(v3);
printf("The distance between 'pt' and the origin is %f\n", v9);
printf("Rectangle 'screen' is defined by points (%d, %d) and (%d, %d)\n", 0LL, 0LL, 320LL, 200LL);
printf("The midpoint between these two points is (%d, %d)\n", (unsigned int)v6, v6 >> 32);
v10 = (const char *)&unk_323;
if ( !ptinrect(v6, 0LL, 0xC800000140LL) )
v10 = (const char *)&unk_327;
printf("Is the midpoint inside the rectangle 'screen'? %s\n", v10);
v11 = ptinrect(v7, 0LL, 0xC800000140LL);
v12 = (const char *)&unk_323;
if ( !v11 )
v12 = (const char *)&unk_327;
printf("Is point (%d, %d) inside the rectangle 'screen'? %s\n", (unsigned int)v7, HIDWORD(v7), v12);
printf(
"A non-canonical rectange example is defined by (%d, %d) and (%d, %d)\n",
(unsigned int)v4,
v4 >> 32,
(unsigned int)v5,
HIDWORD(v5));
printf("And it's canonical version is (%d, %d) and (%d, %d)\n", (unsigned int)v14, v14 >> 32, v15, HIDWORD(v15));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
__int64 v4; // rbp
unsigned __int64 v5; // r12
__int64 v6; // r13
__int64 v7; // rbx
unsigned __int64 v8; // rdx
double v9; // xmm0_8
const char *v10; // rsi
bool v11; // al
const char *v12; // rcx
__int64 v14; // [rsp+0h] [rbp-48h]
unsigned __int64 v15; // [rsp+8h] [rbp-40h]

v3 = func0(0xAu, 20LL);
v4 = func0(0xC8u, 400LL);
v5 = func0(0x71u, 42LL);
v6 = func0(0xA0u, 100LL);
v7 = func1(0xC800000140LL, 0xC800000140LL);
v14 = func2(v4, v5);
v15 = v8;
printf("Point 'pt' is at coordinates (%d, %d)\n", (unsigned int)v3, v3 >> 32);
printf("Point 'origin' is at coordinate (%d, %d)\n", 0LL, 0LL);
printf("Or, when we access it another way with '->' it is still at (%d, %d)\n", 0LL, 0LL);
printf("Point 'maxpt' is at coordinates (%d, %d)\n", 320LL, 200LL);
printf("This point added with itself is (%d, %d)\n", (unsigned int)v7, HIDWORD(v7));
v9 = func4(v3);
printf("The distance between 'pt' and the origin is %f\n", v9);
printf("Rectangle 'screen' is defined by points (%d, %d) and (%d, %d)\n", 0LL, 0LL, 320LL, 200LL);
printf("The midpoint between these two points is (%d, %d)\n", (unsigned int)v6, v6 >> 32);
v10 = (const char *)&unk_323;
if ( !func3(v6, 0LL, 0xC800000140LL) )
v10 = (const char *)&unk_327;
printf("Is the midpoint inside the rectangle 'screen'? %s\n", v10);
v11 = func3(v7, 0LL, 0xC800000140LL);
v12 = (const char *)&unk_323;
if ( !v11 )
v12 = (const char *)&unk_327;
printf("Is point (%d, %d) inside the rectangle 'screen'? %s\n", (unsigned int)v7, HIDWORD(v7), v12);
printf(
"A non-canonical rectange example is defined by (%d, %d) and (%d, %d)\n",
(unsigned int)v4,
v4 >> 32,
(unsigned int)v5,
HIDWORD(v5));
printf("And it's canonical version is (%d, %d) and (%d, %d)\n", (unsigned int)v14, v14 >> 32, v15, HIDWORD(v15));
return 0;
}

original_code:
int main(void) {
    struct point pt;
    struct point origin = { 0, 0 };
    struct point maxpt = { 320, 200 };
    struct point middle;
    struct point outside;
    struct rect screen;
    struct rect noncanon;
    struct rect canon;
    struct point *porigin;
    pt = makepoint(10, 20);
    screen.p1.x = 0;
    screen.p1.y = 0;
    screen.p2 = maxpt;
    noncanon.p1 = makepoint(200, 400);
    noncanon.p2 = makepoint(113, 42);
    middle = makepoint((screen.p1.x + screen.p2.x) / 2,
                       (screen.p1.y + screen.p2.y) / 2);
    outside = addpoint(maxpt, maxpt);
    canon = canonrect(noncanon);
    porigin = &origin;
    printf("Point 'pt' is at coordinates (%d, %d)\n", pt.x, pt.y);
    printf("Point 'origin' is at coordinate (%d, %d)\n", (*porigin).x, (*porigin).y);
    printf("Or, when we access it another way with '->' it is still at (%d, %d)\n", porigin->x, porigin->y);
    printf("Point 'maxpt' is at coordinates (%d, %d)\n", maxpt.x, maxpt.y);
    printf("This point added with itself is (%d, %d)\n", outside.x, outside.y);
    printf("The distance between 'pt' and the origin is %f\n", origindist(pt));
    printf("Rectangle 'screen' is defined by points (%d, %d) and (%d, %d)\n", screen.p1.x, screen.p1.y, screen.p2.x, screen.p2.y);
    printf("The midpoint between these two points is (%d, %d)\n", middle.x, middle.y);
    printf("Is the midpoint inside the rectangle 'screen'?  %s\n", ptinrect(middle, screen) ? "Yes" : "No");
    printf("Is point (%d, %d) inside the rectangle 'screen'?  %s\n", outside.x, outside.y, ptinrect(outside, screen) ? "Yes" : "No");
    printf("A non-canonical rectange example is defined by (%d, %d) and (%d, %d)\n", noncanon.p1.x, noncanon.p1.y, noncanon.p2.x, noncanon.p2.y);
    printf("And it's canonical version is (%d, %d) and (%d, %d)\n", canon.p1.x, canon.p1.y, canon.p2.x, canon.p2.y);
    return 0;
}

canonical_original_code:
int main() {
    struct point pt;
    struct point origin = { 0, 0 };
    struct point maxpt = { 320, 200 };
    struct point middle;
    struct point outside;
    struct rect screen;
    struct rect noncanon;
    struct rect canon;
    struct point *porigin;
    pt = makepoint(10, 20);
    screen.p1.x = 0;
    screen.p1.y = 0;
    screen.p2 = maxpt;
    noncanon.p1 = makepoint(200, 400);
    noncanon.p2 = makepoint(113, 42);
    middle = makepoint((screen.p1.x + screen.p2.x) / 2,
                       (screen.p1.y + screen.p2.y) / 2);
    outside = addpoint(maxpt, maxpt);
    canon = canonrect(noncanon);
    porigin = &origin;
    printf("Point 'pt' is at coordinates (%d, %d)\n", pt.x, pt.y);
    printf("Point 'origin' is at coordinate (%d, %d)\n", (*porigin).x, (*porigin).y);
    printf("Or, when we access it another way with '->' it is still at (%d, %d)\n", porigin->x, porigin->y);
    printf("Point 'maxpt' is at coordinates (%d, %d)\n", maxpt.x, maxpt.y);
    printf("This point added with itself is (%d, %d)\n", outside.x, outside.y);
    printf("The distance between 'pt' and the origin is %f\n", origindist(pt));
    printf("Rectangle 'screen' is defined by points (%d, %d) and (%d, %d)\n", screen.p1.x, screen.p1.y, screen.p2.x, screen.p2.y);
    printf("The midpoint between these two points is (%d, %d)\n", middle.x, middle.y);
    printf("Is the midpoint inside the rectangle 'screen'?  %s\n", ptinrect(middle, screen) ? "Yes" : "No");
    printf("Is point (%d, %d) inside the rectangle 'screen'?  %s\n", outside.x, outside.y, ptinrect(outside, screen) ? "Yes" : "No");
    printf("A non-canonical rectange example is defined by (%d, %d) and (%d, %d)\n", noncanon.p1.x, noncanon.p1.y, noncanon.p2.x, noncanon.p2.y);
    printf("And it's canonical version is (%d, %d) and (%d, %d)\n", canon.p1.x, canon.p1.y, canon.p2.x, canon.p2.y);
    return 0;
}

variable_types:
origin
struct point { int x; int y; }

variable_types:
maxpt
struct point { int x; int y; }

variable_types:
middle
struct point { int x; int y; }

variable_types:
outside
struct point { int x; int y; }

variable_types:
porigin
struct point { int x; int y; } *


gettoken

decompiled_code:
__int64 gettoken()
{
int v0; // eax
int v1; // ebx
const unsigned __int16 **v2; // rbp
int v4; // eax
char *v5; // rbx
char v6; // al
char *i; // rbx
const unsigned __int16 *v8; // r12
int v9; // eax

if ( prevtoken )
{
prevtoken = 0;
v1 = tokentype;
}
else
{
do
{
do
{
v0 = getch();
v1 = v0;
}
while ( v0 == 9 );
}
while ( v0 == 32 );
if ( v0 == 40 )
{
v4 = getch();
if ( v4 == 41 )
{
strcpy(token, "()");
tokentype = 1;
v1 = 1;
}
else
{
ungetch(v4);
tokentype = 40;
}
}
else if ( v0 == 91 )
{
token[0] = 91;
v5 = &token[1];
do
{
v6 = getch();
*v5++ = v6;
}
while ( v6 != 93 );
*v5 = 0;
tokentype = 2;
v1 = 2;
}
else
{
v2 = _ctype_b_loc();
if ( ((*v2)[v1] & 0x400) != 0 )
{
token[0] = v1;
for ( i = &token[1]; ; *(i - 1) = v9 )
{
v8 = *v2;
v9 = getch();
if ( (v8[v9] & 8) == 0 )
break;
++i;
}
*i = 0;
ungetch(v9);
tokentype = 0;
v1 = 0;
}
else
{
tokentype = v1;
}
}
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
int v1; // ebx
const unsigned __int16 **v2; // rbp
int v4; // eax
char *v5; // rbx
char v6; // al
char *i; // rbx
const unsigned __int16 *v8; // r12
int v9; // eax

if ( prevtoken )
{
prevtoken = 0;
v1 = tokentype;
}
else
{
do
{
do
{
v0 = func0();
v1 = v0;
}
while ( v0 == 9 );
}
while ( v0 == 32 );
if ( v0 == 40 )
{
v4 = func0();
if ( v4 == 41 )
{
strcpy(token, "()");
tokentype = 1;
v1 = 1;
}
else
{
func1(v4);
tokentype = 40;
}
}
else if ( v0 == 91 )
{
token[0] = 91;
v5 = &token[1];
do
{
v6 = func0();
*v5++ = v6;
}
while ( v6 != 93 );
*v5 = 0;
tokentype = 2;
v1 = 2;
}
else
{
v2 = _ctype_b_loc();
if ( ((*v2)[v1] & 0x400) != 0 )
{
token[0] = v1;
for ( i = &token[1]; ; *(i - 1) = v9 )
{
v8 = *v2;
v9 = func0();
if ( (v8[v9] & 8) == 0 )
break;
++i;
}
*i = 0;
func1(v9);
tokentype = 0;
v1 = 0;
}
else
{
tokentype = v1;
}
}
}
return (unsigned int)v1;
}

original_code:
static int gettoken(void) {
    int c;
    char *p = token;
    if (prevtoken) {
        prevtoken = 0;
        return tokentype;
    }
    while ((c = getch()) == ' ' || c == '\t')
        ;
    if (c == '(') {
        if ((c = getch()) == ')') {
            strcpy(token, "()");
            return (tokentype = PARENS);
        }
        ungetch(c);
        return (tokentype = '(');
    }
    if (c == '[') {
        for (*p++ = c; (*p++ = getch()) != ']'; )
            ;
        *p = '\0';
        return (tokentype = BRACKETS);
    }
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha)) {
        for (*p++ = c; ((*__ctype_b_loc ())[(int) ((c = getch()))] & (unsigned short int) _ISalnum); )
            *p++ = c;
        *p = '\0';
        ungetch(c);
        return (tokentype = NAME);
    }
    return (tokentype = c);
}

canonical_original_code:
static int gettoken() {
    int c;
    char *p = token;
    if (prevtoken) {
        prevtoken = 0;
        return tokentype;
    }
    while ((c = getch()) == ' ' || c == '\t')
        ;
    if (c == '(') {
        if ((c = getch()) == ')') {
            strcpy(token, "()");
            return (tokentype = PARENS);
        }
        ungetch(c);
        return (tokentype = '(');
    }
    if (c == '[') {
        for (*p++ = c; (*p++ = getch()) != ']'; )
            ;
        *p = '\0';
        return (tokentype = BRACKETS);
    }
    if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha)) {
        for (*p++ = c; ((*__ctype_b_loc ())[(int) ((c = getch()))] & (unsigned short) _ISalnum); )
            *p++ = c;
        *p = '\0';
        ungetch(c);
        return (tokentype = NAME);
    }
    return (tokentype = c);
}

variable_types: c int

variable_types:
p
char *


nexttoken

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

result = gettoken();
prevtoken = 1;
return result;
}

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

result = func2();
prevtoken = 1;
return result;
}

original_code:
static int nexttoken(void) {
    int type;
    type = gettoken();
    prevtoken = 1;
    return type;
}

canonical_original_code:
static int nexttoken() {
    int type;
    type = gettoken();
    prevtoken = 1;
    return type;
}

variable_types: type int


bfree

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

fprintf(stderr, "bfree(): attempting to free block at %px of %lu bytes\n", a1, a2);
result = 0LL;
if ( a2 > 0xF )
{
a1[1] = a2 >> 4;
free(a1 + 2);
result = a1[1];
}
return result;
}

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

fprintf(stderr, "bfree(): attempting to free block at %px of %lu bytes\n", a1, a2);
result = 0LL;
if ( a2 > 0xF )
{
a1[1] = a2 >> 4;
func0(a1 + 2);
result = a1[1];
}
return result;
}

original_code:
unsigned long bfree(char *p, unsigned long n) {
    Header *hp;
    fprintf(stderr, "bfree(): attempting to free block at %px of %lu bytes\n", p, n);
    if (n < sizeof(Header))
        return 0;
    hp = (Header *) p;
    hp->s.size = n / sizeof(Header);
    free((void *)(hp + 1));
    return hp->s.size;
}

canonical_original_code:
unsigned long bfree(char *p, unsigned long n) {
    union header *hp;
    fprintf(stderr, "bfree(): attempting to free block at %px of %lu bytes\n", p, n);
    if (n < sizeof(Header))
        return 0;
    hp = (union header *) p;
    hp->s.size = n / sizeof(Header);
    free((void *)(hp + 1));
    return hp->s.size;
}

variable_types:
n
unsigned long

variable_types: union header { struct { union header *ptr; unsigned long size; } s; long x; } *


isnottab

decompiled_code:
_BOOL8 __fastcall isnottab(int a1, __int64 a2)
{
bool v2; // al

v2 = 0;
if ( a1 <= 250 )
v2 = *(_BYTE *)(a2 + a1) == 0;
return v2;
}

original_code:
static _Bool isnottab(int pos, char *tabstop) {
    return (pos < (250 + 1)) && (tabstop[pos] == 0);
}

variable_types: pos int

variable_types:
tabstop
char *


entab

decompiled_code:
int __fastcall entab(__int64 a1)
{
int v1; // ebp
int v2; // ebx
int i; // er13
int result; // eax
char v5; // r12

v1 = 0;
v2 = 0;
for ( i = 1; ; ++i )
{
result = getchar();
v5 = result;
if ( (_BYTE)result == 0xFF )
break;
if ( (_BYTE)result == 32 )
{
++v2;
if ( !isnottab(i, a1) )
{
++v1;
v2 = 0;
}
}
else
{
if ( v1 > 0 )
{
do
{
putchar(9);
--v1;
}
while ( v1 );
}
if ( v5 == 9 )
{
putchar(9);
v2 = 0;
while ( isnottab(i, a1) )
++i;
}
else
{
if ( v2 > 0 )
{
do
{
putchar(32);
--v2;
}
while ( v2 );
}
putchar(v5);
if ( v5 == 10 )
i = 0;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
int v1; // ebp
int v2; // ebx
int i; // er13
int result; // eax
char v5; // r12

v1 = 0;
v2 = 0;
for ( i = 1; ; ++i )
{
result = getchar();
v5 = result;
if ( (_BYTE)result == 0xFF )
break;
if ( (_BYTE)result == 32 )
{
++v2;
if ( !func0(i, a1) )
{
++v1;
v2 = 0;
}
}
else
{
if ( v1 > 0 )
{
do
{
putchar(9);
--v1;
}
while ( v1 );
}
if ( v5 == 9 )
{
putchar(9);
v2 = 0;
while ( func0(i, a1) )
++i;
}
else
{
if ( v2 > 0 )
{
do
{
putchar(32);
--v2;
}
while ( v2 );
}
putchar(v5);
if ( v5 == 10 )
i = 0;
}
}
}
return result;
}

original_code:
static void entab(char *tab) {
    char c;
    int pos = 1;
    int ns = 0;
    int nt = 0;
    for ( ; (c = getchar()) != (-1); pos++) {
        if (c == ' ') {
            if (isnottab(pos, tab))
                ++ns;
            else {
                ns = 0;
                ++nt;
            }
            continue;
        }
        for ( ; nt > 0; nt--)
            (void)putchar('\t');
        for (ns = (c == '\t') ? 0 : ns; ns > 0; ns--)
            (void)putchar(' ');
        (void)putchar(c);
        if (c == '\n')
            pos = 0;
        if (c == '\t')
            while (isnottab(pos, tab))
                ++pos;
    }
}

variable_types:
tab
char *

variable_types: c char

variable_types: ns int

variable_types: nt int


findblank

decompiled_code:
__int64 __fastcall findblank(__int64 a1)
{
if ( !a1 )
return 20LL;
while ( line[a1] != 32 )
{
if ( !--a1 )
return 20LL;
}
return a1 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
return 20LL;
while ( line[a1] != 32 )
{
if ( !--a1 )
return 20LL;
}
return a1 + 1;
}

original_code:
static size_t findblank(size_t pos) {
    while (pos > 0 && line[pos] != ' ')
        pos--;
    if (pos == 0)
        return 20;
    else
        return (pos + 1);
}

canonical_original_code:
static unsigned long findblank(unsigned long pos) {
    while (pos > 0 && line[pos] != ' ')
        pos--;
    if (pos == 0)
        return 20;
    else
        return (pos + 1);
}

variable_types:
pos
unsigned long


squish

original_code:
static size_t squish(size_t pos) {
    size_t i = 0;
    size_t j;
    if (pos == 0 || pos >= 20)
        return 0;
    for (j = pos; j < 20; ++j) {
        line[i] = line[j];
        i++;
    }
    return i;
}

canonical_original_code:
static unsigned long squish(unsigned long pos) {
    unsigned long i = 0;
    unsigned long j;
    if (pos == 0 || pos >= 20)
        return 0;
    for (j = pos; j < 20; ++j) {
        line[i] = line[j];
        i++;
    }
    return i;
}

variable_types:
i
unsigned long

variable_types:
j
unsigned long


printline

decompiled_code:
int __fastcall printline(__int64 a1)
{
__int64 i; // rbx
int result; // eax

if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
putchar(line[i]);
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 i; // rbx
int result; // eax

if ( a1 )
{
for ( i = 0LL; i != a1; ++i )
putchar(line[i]);
result = putchar(10);
}
return result;
}

original_code:
static void printline(size_t pos) {
    size_t i;
    for (i = 0; i < pos; i++)
        (void)putchar(line[i]);
    if (pos > 0)
        (void)putchar('\n');
}

canonical_original_code:
static void printline(unsigned long pos) {
    unsigned long i;
    for (i = 0; i < pos; i++)
        (void)putchar(line[i]);
    if (pos > 0)
        (void)putchar('\n');
}


expandtab

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

line[a1] = 32;
result = a1 + 1;
if ( (unsigned __int64)(a1 + 1) <= 0x13 )
{
if ( (result & 3) == 0 )
return result;
while ( 1 )
{
line[result++] = 32;
if ( result == 20 )
break;
if ( (result & 3) == 0 )
return result;
}
}
printline(result);
return 0LL;
}

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

line[a1] = 32;
result = a1 + 1;
if ( (unsigned __int64)(a1 + 1) <= 0x13 )
{
if ( (result & 3) == 0 )
return result;
while ( 1 )
{
line[result++] = 32;
if ( result == 20 )
break;
if ( (result & 3) == 0 )
return result;
}
}
func2(result);
return 0LL;
}

original_code:
static size_t expandtab(size_t pos) {
    line[pos] = ' ';
    for (++pos; pos < 20 && pos % 4 != 0; pos++)
        line[pos] = ' ';
    if (pos < 20)
        return pos;
    else {
        printline(pos);
        return 0;
    }
}

canonical_original_code:
static unsigned long expandtab(unsigned long pos) {
    line[pos] = ' ';
    for (++pos; pos < 20 && pos % 4 != 0; pos++)
        line[pos] = ' ';
    if (pos < 20)
        return pos;
    else {
        printline(pos);
        return 0;
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // eax
__int64 v5; // rbx

v3 = 0LL;
while ( 1 )
{
v4 = getchar();
if ( v4 == -1 )
break;
line[v3] = v4;
if ( v4 == 9 )
{
v3 = expandtab(v3);
}
else if ( v4 == 10 )
{
printline(v3);
v3 = 0LL;
}
else if ( (unsigned __int64)++v3 > 0x13 )
{
v5 = findblank(v3);
printline(v5);
v3 = squish(v5);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // eax
__int64 v5; // rbx

v3 = 0LL;
while ( 1 )
{
v4 = getchar();
if ( v4 == -1 )
break;
line[v3] = v4;
if ( v4 == 9 )
{
v3 = func3(v3);
}
else if ( v4 == 10 )
{
func2(v3);
v3 = 0LL;
}
else if ( (unsigned __int64)++v3 > 0x13 )
{
v5 = func0(v3);
func2(v5);
v3 = func1(v5);
}
}
return 0;
}

original_code:
int main(void) {
    int c;
    size_t pos = 0;
    while ((c = getchar()) != (-1)) {
        line[pos] = c;
        if (c == '\t') {
            pos = expandtab(pos);
        } else if (c == '\n') {
            printline(pos);
            pos = 0;
        } else if (++pos >= 20) {
            pos = findblank(pos);
            printline(pos);
            pos = squish(pos);
        }
    }
    return 0;
}

canonical_original_code:
int main() {
    int c;
    unsigned long pos = 0;
    while ((c = getchar()) != (-1)) {
        line[pos] = c;
        if (c == '\t') {
            pos = expandtab(pos);
        } else if (c == '\n') {
            printline(pos);
            pos = 0;
        } else if (++pos >= 20) {
            pos = findblank(pos);
            printline(pos);
            pos = squish(pos);
        }
    }
    return 0;
}


lowerstr

decompiled_code:
void __fastcall lowerstr(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func0(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
static void lowerstr(char *s) {
    for ( ; *s != '\0'; s++)
        *s = tolower(*s);
}

variable_types:
s
char *


isnotstopword

decompiled_code:
bool __fastcall isnotstopword(__int64 a1)
{
__int64 key; // [rsp+8h] [rbp-10h] BYREF

key = a1;
return bsearch(&key, &stopwords_0, 0xAEuLL, 8uLL, scompare) == 0LL;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
__int64 key; // [rsp+8h] [rbp-10h] BYREF

key = a1;
return bsearch(&key, &stopwords_0, 0xAEuLL, 8uLL, scompare) == 0LL;
}

original_code:
static _Bool isnotstopword(char *w) {
    static char *stopwords[] = {
        "a","about","above","after","again","against","all","am","an","and","any","are","aren't","as","at","be",
        "because","been","before","being","below","between","both","but","by","can't","cannot","could","couldn't",
        "did","didn't","do","does","doesn't","doing","don't","down","during","each","few","for","from","further",
        "had","hadn't","has","hasn't","have","haven't","having","he","he'd","he'll","he's","her","here","here's",
        "hers","herself","him","himself","his","how","how's","i","i'd","i'll","i'm","i've","if","in","into","is",
        "isn't","it","it's","its","itself","let's","me","more","most","mustn't","my","myself","no","nor","not","of",
        "off","on","once","only","or","other","ought","our","ours","ourselves","out","over","own","same","shan't",
        "she","she'd","she'll","she's","should","shouldn't","so","some","such","than","that","that's","the","their",
        "theirs","them","themselves","then","there","there's","these","they","they'd","they'll","they're","they've",
        "this","those","through","to","too","under","until","up","very","was","wasn't","we","we'd","we'll","we're",
        "we've","were","weren't","what","what's","when","when's","where","where's","which","while","who","who's",
        "whom","why","why's","with","won't","would","wouldn't","you","you'd","you'll","you're","you've","your",
        "yours","yourself","yourselves"
    };
    char **result;
    result = (char **)bsearch( (char *) &w, (char *)stopwords, sizeof(stopwords)/sizeof(stopwords[0]),
                              sizeof( char * ), (int (*)(const void*, const void*))scompare);
    return result == ((void *)0);
}

canonical_original_code:
static _Bool isnotstopword(char *w) {
    static char *stopwords[] = {
        "a","about","above","after","again","against","all","am","an","and","any","are","aren't","as","at","be",
        "because","been","before","being","below","between","both","but","by","can't","cannot","could","couldn't",
        "did","didn't","do","does","doesn't","doing","don't","down","during","each","few","for","from","further",
        "had","hadn't","has","hasn't","have","haven't","having","he","he'd","he'll","he's","her","here","here's",
        "hers","herself","him","himself","his","how","how's","i","i'd","i'll","i'm","i've","if","in","into","is",
        "isn't","it","it's","its","itself","let's","me","more","most","mustn't","my","myself","no","nor","not","of",
        "off","on","once","only","or","other","ought","our","ours","ourselves","out","over","own","same","shan't",
        "she","she'd","she'll","she's","should","shouldn't","so","some","such","than","that","that's","the","their",
        "theirs","them","themselves","then","there","there's","these","they","they'd","they'll","they're","they've",
        "this","those","through","to","too","under","until","up","very","was","wasn't","we","we'd","we'll","we're",
        "we've","were","weren't","what","what's","when","when's","where","where's","which","while","who","who's",
        "whom","why","why's","with","won't","would","wouldn't","you","you'd","you'll","you're","you've","your",
        "yours","yourself","yourselves"
    };
    char **result;
    result = (char **)bsearch( (char *) &w, (char *)stopwords, sizeof(stopwords)/sizeof(stopwords[0]),
                              sizeof( char * ), (int (*)(void *, void *))scompare);
    return result == ((void *)0);
}

variable_types:
w
char *

variable_types:
stopwords
char *[]

variable_types:
result
char **


scompare

decompiled_code:
int __fastcall scompare(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func2(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int scompare(char **s, char **t) {
    return strcmp(*s, *t);
}

variable_types:
s
char **

variable_types:
t
char **