decompiled_code:
int *__fastcall cell_sub(__int64 a1, int a2, int a3)
{
__int64 v4; // rbx
int *v5; // r13
int v6; // eax
__int64 v7; // r12
int v8; // edx
char v9; // si

v4 = a2;
v5 = (int *)new_cell(&src);
if ( !v5 || a3 < 0 )
return v5;
v6 = *(_DWORD *)a1;
v7 = *(_QWORD *)(a1 + 8);
if ( a2 < 0 )
v4 = 0LL;
if ( a3 )
{
v8 = a3;
if ( v6 <= a3 )
v8 = *(_DWORD *)a1;
if ( (int)v4 >= v8 )
return v5;
if ( v6 > a3 )
{
do
{
v9 = *(_BYTE *)(v7 + v4++);
cell_add_char(v5, v9);
}
while ( a3 > (int)v4 );
return v5;
}
}
else if ( v6 <= (int)v4 )
{
return v5;
}
return cell_add_str(v5, (const char *)(v7 + v4));
}

canonical_decompiled_code:
int *__fastcall func6(__int64 a1, int a2, int a3)
{
__int64 v4; // rbx
int *v5; // r13
int v6; // eax
__int64 v7; // r12
int v8; // edx
char v9; // si

v4 = a2;
v5 = (int *)func2(&src);
if ( !v5 || a3 < 0 )
return v5;
v6 = *(_DWORD *)a1;
v7 = *(_QWORD *)(a1 + 8);
if ( a2 < 0 )
v4 = 0LL;
if ( a3 )
{
v8 = a3;
if ( v6 <= a3 )
v8 = *(_DWORD *)a1;
if ( (int)v4 >= v8 )
return v5;
if ( v6 > a3 )
{
do
{
v9 = *(_BYTE *)(v7 + v4++);
func4(v5, v9);
}
while ( a3 > (int)v4 );
return v5;
}
}
else if ( v6 <= (int)v4 )
{
return v5;
}
return func3(v5, (const char *)(v7 + v4));
}

original_code:
Cell*
cell_sub(Cell *c, int start, int end) {
    Cell *d;
    int i, l;
    const char *p;
    d = new_cell("");
    if (((void *)0) == d) return d;
    l = c->length;
    p = c->data;
    if (end < 0) return d;
    if (start < 0) start = 0;
    if (end == 0) end = l;
    if (end <= start) return d;
    if (start >= l) return d;
    if (end >= l) {
 return cell_add_str(d, &p[start]);
    }
    for (i=start; i<end; i++) {
 cell_add_char(d, p[i]);
    }
    return d;
}

canonical_original_code:
struct _cell *cell_sub(struct _cell *c, int start, int end) {
    struct _cell *d;
    int i; int l;
    char *p;
    d = new_cell("");
    if (((void *)0) == d) return d;
    l = c->length;
    p = c->data;
    if (end < 0) return d;
    if (start < 0) start = 0;
    if (end == 0) end = l;
    if (end <= start) return d;
    if (start >= l) return d;
    if (end >= l) {
 return cell_add_str(d, &p[start]);
    }
    for (i=start; i<end; i++) {
 cell_add_char(d, p[i]);
    }
    return d;
}

variable_types:
c
struct _cell *

variable_types: start int

variable_types: end int

variable_types: i int

variable_types: l int


decompiled_code:
__int64 __fastcall read_size(int fd, __int64 a2, int a3)
{
int v3; // er13
int v5; // eax

v3 = 0;
do
{
v5 = read(fd, (void *)(a2 + v3), a3);
if ( (unsigned int)(v5 + 1) <= 1 )
return 0xFFFFFFFFLL;
a3 -= v5;
v3 += v5;
}
while ( a3 > 0 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2, int a3)
{
int v3; // er13
int v5; // eax

v3 = 0;
do
{
v5 = read(fd, (void *)(a2 + v3), a3);
if ( (unsigned int)(v5 + 1) <= 1 )
return 0xFFFFFFFFLL;
a3 -= v5;
v3 += v5;
}
while ( a3 > 0 );
return 1LL;
}

original_code:
static int
read_size(int fd, char* buff, int size) {
    int sts;
    int pos = 0;
    int remain = size;
    do {
 sts = read(fd, &buff[pos], remain);
 if (-1 == sts) return -1;
 if ( 0 == sts) return -1;
 pos += sts;
 remain -= sts;
    } while (remain > 0);
    return 1;
}

canonical_original_code:
static int read_size(int fd, char *buff, int size) {
    int sts;
    int pos = 0;
    int remain = size;
    do {
 sts = read(fd, &buff[pos], remain);
 if (-1 == sts) return -1;
 if ( 0 == sts) return -1;
 pos += sts;
 remain -= sts;
    } while (remain > 0);
    return 1;
}

variable_types: fd int

variable_types:
buff
char *

variable_types: size int

variable_types: sts int

variable_types: pos int

variable_types: remain int

return_type: int


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

result = GC_malloc(24LL);
if ( !result )
{
puts("alloc failed.");
exit(255);
}
*(_QWORD *)(result + 16) = 0LL;
*(_OWORD *)result = 0LL;
*(_DWORD *)(result + 12) = 1;
return result;
}

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

result = GC_malloc(24LL);
if ( !result )
{
puts("alloc failed.");
exit(255);
}
*(_QWORD *)(result + 16) = 0LL;
*(_OWORD *)result = 0LL;
*(_DWORD *)(result + 12) = 1;
return result;
}

original_code:
Bulk*
new_bulk() {
    Bulk *bulk;
    bulk = GC_malloc(sizeof(Bulk));
    if (!bulk) {printf("alloc failed.\n"); exit(255);};
    memset(bulk, 0, sizeof(Bulk));
    bulk->line = 1;
    return bulk;
}

canonical_original_code:
struct _bulk *new_bulk() {
    struct _bulk *bulk;
    bulk = GC_malloc(sizeof(Bulk));
    if (!bulk) {printf("alloc failed.\n"); exit(255);};
    memset(bulk, 0, sizeof(Bulk));
    bulk->line = 1;
    return bulk;
}

variable_types: struct _bulk { int length; int allocsize; int pos; int line; char *data; } *


decompiled_code:
__int64 __fastcall bulk_load_file(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
__int64 v5; // rax
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

if ( a1 )
{
v2 = open(a2, 0);
v3 = v2;
if ( v2 != -1 )
{
if ( fstat(v2, &v7) != -1 )
{
v4 = v7.st_size;
v5 = GC_malloc_atomic(SLODWORD(v7.st_size));
*(_QWORD *)(a1 + 16) = v5;
if ( !v5 )
{
puts("alloc failed.");
exit(255);
}
*(_DWORD *)a1 = v4;
*(_DWORD *)(a1 + 4) = v4;
*(_QWORD *)(a1 + 8) = 0x100000000LL;
if ( (unsigned int)read_size(v3, v5, v4) != -1 )
{
close(v3);
return 1LL;
}
}
close(v3);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0x100000000LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
__int64 v5; // rax
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

if ( a1 )
{
v2 = open(a2, 0);
v3 = v2;
if ( v2 != -1 )
{
if ( fstat(v2, &v7) != -1 )
{
v4 = v7.st_size;
v5 = GC_malloc_atomic(SLODWORD(v7.st_size));
*(_QWORD *)(a1 + 16) = v5;
if ( !v5 )
{
puts("alloc failed.");
exit(255);
}
*(_DWORD *)a1 = v4;
*(_DWORD *)(a1 + 4) = v4;
*(_QWORD *)(a1 + 8) = 0x100000000LL;
if ( (unsigned int)func0(v3, v5, v4) != -1 )
{
close(v3);
return 1LL;
}
}
close(v3);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0x100000000LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
}
return 0LL;
}

original_code:
int
bulk_load_file(Bulk *bulk, const char *file) {
    int fd;
    struct stat statbuff;
    int size;
    if (((void *)0) == bulk) return 0;
    if (-1 == (fd = open(file, 00))) return 0;
    if (-1 == fstat(fd, &statbuff)) goto error;
    size = statbuff.st_size;
    bulk->data = GC_malloc_atomic(size);
    if (!bulk->data) {printf("alloc failed.\n"); exit(255);};
    bulk->length = size;
    bulk->allocsize = size;
    bulk->pos = 0;
    bulk->line = 1;
    if (-1 == read_size(fd, bulk->data, size)) goto error;
    close(fd);
    return 1;
error:
    close(fd);
    bulk->length = 0;
    bulk->allocsize = 0;
    bulk->pos = 0;
    bulk->line = 1;
    bulk->data = 0;
    return 0;
}

canonical_original_code:
int bulk_load_file(struct _bulk *bulk, char *file) {
    int fd;
    struct stat statbuff;
    int size;
    if (((void *)0) == bulk) return 0;
    if (-1 == (fd = open(file, 00))) return 0;
    if (-1 == fstat(fd, &statbuff)) goto error;
    size = statbuff.st_size;
    bulk->data = GC_malloc_atomic(size);
    if (!bulk->data) {printf("alloc failed.\n"); exit(255);};
    bulk->length = size;
    bulk->allocsize = size;
    bulk->pos = 0;
    bulk->line = 1;
    if (-1 == read_size(fd, bulk->data, size)) goto error;
    close(fd);
    return 1;
error:
    close(fd);
    bulk->length = 0;
    bulk->allocsize = 0;
    bulk->pos = 0;
    bulk->line = 1;
    bulk->data = 0;
    return 0;
}

variable_types:
file
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct _bulk { int length; int allocsize; int pos; int line; char *data; }


decompiled_code:
__int64 __fastcall bulk_set_string(__int64 a1, const char *a2)
{
int v2; // eax
size_t v3; // r13
int v4; // er12
void *v5; // rax

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v2 = strlen(a2);
v3 = v2;
v4 = v2;
v5 = (void *)GC_malloc_atomic(v2);
*(_QWORD *)(a1 + 16) = v5;
if ( !v5 )
{
puts("alloc failed.");
exit(255);
}
*(_DWORD *)a1 = v4;
*(_DWORD *)(a1 + 4) = v4;
*(_QWORD *)(a1 + 8) = 0x100000000LL;
memcpy(v5, a2, v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
int v2; // eax
size_t v3; // r13
int v4; // er12
void *v5; // rax

if ( !a2 )
return 0LL;
if ( !a1 )
return 0LL;
v2 = strlen(a2);
v3 = v2;
v4 = v2;
v5 = (void *)GC_malloc_atomic(v2);
*(_QWORD *)(a1 + 16) = v5;
if ( !v5 )
{
puts("alloc failed.");
exit(255);
}
*(_DWORD *)a1 = v4;
*(_DWORD *)(a1 + 4) = v4;
*(_QWORD *)(a1 + 8) = 0x100000000LL;
memcpy(v5, a2, v3);
return 1LL;
}

original_code:
int
bulk_set_string(Bulk *bulk, const char *str) {
    int len;
    if (((void *)0) == bulk) return 0;
    if (((void *)0) == str) return 0;
    len = strlen(str);
    bulk->data = GC_malloc_atomic(len);
    if (!bulk->data) {printf("alloc failed.\n"); exit(255);};
    bulk->length = len;
    bulk->allocsize = len;
    bulk->pos = 0;
    bulk->line = 1;
    memcpy(bulk->data, str, len);
    return 1;
}

canonical_original_code:
int bulk_set_string(struct _bulk *bulk, char *str) {
    int len;
    if (((void *)0) == bulk) return 0;
    if (((void *)0) == str) return 0;
    len = strlen(str);
    bulk->data = GC_malloc_atomic(len);
    if (!bulk->data) {printf("alloc failed.\n"); exit(255);};
    bulk->length = len;
    bulk->allocsize = len;
    bulk->pos = 0;
    bulk->line = 1;
    memcpy(bulk->data, str, len);
    return 1;
}

variable_types:
str
char *

variable_types: len int


original_code:
int
bulk_rewind(Bulk *bulk) {
    if (((void *)0) == bulk) return 0;
    if (((void *)0) == bulk->data) return 0;
    bulk->pos = 0;
    bulk->line = 1;
    return 1;
}

canonical_original_code:
int bulk_rewind(struct _bulk *bulk) {
    if (((void *)0) == bulk) return 0;
    if (((void *)0) == bulk->data) return 0;
    bulk->pos = 0;
    bulk->line = 1;
    return 1;
}


original_code:
int
bulk_ungetchar(Bulk *bulk) {
    if (((void *)0) == bulk) return (-1);
    if (bulk->pos > 0) bulk->pos--;
    if ('\n' == bulk->data[bulk->pos]) {
 bulk->line--;
    }
    return 1;
}

canonical_original_code:
int bulk_ungetchar(struct _bulk *bulk) {
    if (((void *)0) == bulk) return (-1);
    if (bulk->pos > 0) bulk->pos--;
    if ('\n' == bulk->data[bulk->pos]) {
 bulk->line--;
    }
    return 1;
}


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

if ( a1 && *(_QWORD *)(a1 + 16) )
result = 2 * (unsigned int)(*(_DWORD *)(a1 + 8) < *(_DWORD *)a1) - 1;
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 && *(_QWORD *)(a1 + 16) )
result = 2 * (unsigned int)(*(_DWORD *)(a1 + 8) < *(_DWORD *)a1) - 1;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
bulk_is_eof(Bulk *bulk) {
    if (((void *)0) == bulk) return (-1);
    if (((void *)0) == bulk->data) return (-1);
    if ((bulk->pos) >= (bulk->length)) return (-1);
    return 1;
}

canonical_original_code:
int bulk_is_eof(struct _bulk *bulk) {
    if (((void *)0) == bulk) return (-1);
    if (((void *)0) == bulk->data) return (-1);
    if ((bulk->pos) >= (bulk->length)) return (-1);
    return 1;
}


decompiled_code:
__int64 __fastcall bulk_getchar(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
result = bulk_is_eof(a1);
if ( (_DWORD)result != -1 )
{
v2 = *(int *)(a1 + 8);
result = (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + v2);
if ( (_DWORD)result == 10 )
++*(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 8) = v2 + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
result = func6(a1);
if ( (_DWORD)result != -1 )
{
v2 = *(int *)(a1 + 8);
result = (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + v2);
if ( (_DWORD)result == 10 )
++*(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 8) = v2 + 1;
}
return result;
}

original_code:
int
bulk_getchar(Bulk *bulk) {
    int c;
    if (((void *)0) == bulk) return (-1);
    if ((-1) == bulk_is_eof(bulk)) return (-1);
    c = bulk->data[bulk->pos];
    if ('\n' == c) {
 bulk->line++;
    }
    bulk->pos++;
    return c;
}

canonical_original_code:
int bulk_getchar(struct _bulk *bulk) {
    int c;
    if (((void *)0) == bulk) return (-1);
    if ((-1) == bulk_is_eof(bulk)) return (-1);
    c = bulk->data[bulk->pos];
    if ('\n' == c) {
 bulk->line++;
    }
    bulk->pos++;
    return c;
}

variable_types: c int


decompiled_code:
__int64 __fastcall bulk_get_length(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
bulk_get_length(Bulk *bulk) {
    if (((void *)0) == bulk) return (-1);
    return bulk->length;
}

canonical_original_code:
int bulk_get_length(struct _bulk *bulk) {
    if (((void *)0) == bulk) return (-1);
    return bulk->length;
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
bulk_get_position(Bulk *bulk) {
    if (((void *)0) == bulk) return (-1);
    return bulk->pos;
}

canonical_original_code:
int bulk_get_position(struct _bulk *bulk) {
    if (((void *)0) == bulk) return (-1);
    return bulk->pos;
}


decompiled_code:
__int64 __fastcall bulk_set_position(_DWORD *a1, int a2)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = bulk_is_eof((__int64)a1);
if ( (_DWORD)result != -1 )
{
if ( *a1 <= a2 )
{
a1[2] = *a1;
result = 0xFFFFFFFFLL;
}
else
{
a1[2] = a2;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1, int a2)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = func6((__int64)a1);
if ( (_DWORD)result != -1 )
{
if ( *a1 <= a2 )
{
a1[2] = *a1;
result = 0xFFFFFFFFLL;
}
else
{
a1[2] = a2;
result = 1LL;
}
}
return result;
}

original_code:
int
bulk_set_position(Bulk *bulk, int pos) {
    if (((void *)0) == bulk) return 0;
    if ((-1) == bulk_is_eof(bulk)) return (-1);
    if (pos >= bulk->length) {
 bulk->pos = bulk->length;
 return (-1);
    }
    bulk->pos = pos;
    return 1;
}

canonical_original_code:
int bulk_set_position(struct _bulk *bulk, int pos) {
    if (((void *)0) == bulk) return 0;
    if ((-1) == bulk_is_eof(bulk)) return (-1);
    if (pos >= bulk->length) {
 bulk->pos = bulk->length;
 return (-1);
    }
    bulk->pos = pos;
    return 1;
}


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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

original_code:
char*
bulk_get_addr(Bulk *bulk) {
    if (((void *)0) == bulk) return 0;
    return bulk->data;
}

canonical_original_code:
char *bulk_get_addr(struct _bulk *bulk) {
    if (((void *)0) == bulk) return 0;
    return bulk->data;
}

return_type: char *


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

if ( a1 )
result = *(unsigned int *)(a1 + 12);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 12);
else
result = 0LL;
return result;
}

original_code:
int
bulk_get_line(Bulk *bulk) {
    if (((void *)0) == bulk) return 0;
    return bulk->line;
}

canonical_original_code:
int bulk_get_line(struct _bulk *bulk) {
    if (((void *)0) == bulk) return 0;
    return bulk->line;
}


original_code:
static Array*
array_realloc(Array* array) {
    Toy_Type *orig_array, *new_array;
    int alloc_size;
    int i;
    alloc_size = array->alloc_size * 2;
    orig_array = array->array;
    new_array = GC_malloc(sizeof(Toy_Type) * alloc_size);
    if (!new_array) {printf("alloc failed.\n"); exit(255);};
    memset(new_array, 0, sizeof(Toy_Type) * alloc_size);
    for (i=0; i<array->cur_size; i++) {
 new_array[i] = orig_array[i];
    }
    array->alloc_size = alloc_size;
    array->array = new_array;
    return array;
}

canonical_original_code:
static struct _array *array_realloc(struct _array *array) {
    struct _toy_type *orig_array; struct _toy_type *new_array;
    int alloc_size;
    int i;
    alloc_size = array->alloc_size * 2;
    orig_array = array->array;
    new_array = GC_malloc(sizeof(Toy_Type) * alloc_size);
    if (!new_array) {printf("alloc failed.\n"); exit(255);};
    memset(new_array, 0, sizeof(Toy_Type) * alloc_size);
    for (i=0; i<array->cur_size; i++) {
 new_array[i] = orig_array[i];
    }
    array->alloc_size = alloc_size;
    array->array = new_array;
    return array;
}

variable_types:
array
struct _array *

variable_types: struct _toy_type { unsigned int tag; union _u { struct _symbol { struct _cell { int length; int allocsize; char *data; } *cell; unsigned int hash_index; } symbol; struct _ref { struct _cell *cell; unsigned int hash_index; } ref; struct _list { struct _toy_type *item; struct _toy_type *nextp; } list; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } biginteger[1]; double real; struct _cell *string; struct _toy_type *statement_list; struct _statement { struct _toy_type *item_list; struct _toy_func_trace_info { int line; struct _toy_type *object_name; struct _toy_type *func_name; struct _toy_type *statement; } *trace_info; } statement; struct _toy_type *block_body; struct _toy_type *eval_body; struct _native { struct _toy_type *(*cfunc)(struct _toy_interp { char *name; int stack_size; int cur_func_stack; struct _toy_func_env { struct _hash { int bucket_size; struct hash_bucket { char *key; unsigned int index; struct _toy_type *item; struct hash_bucket *next; } **bucket; int items; int synonyms; } *localvar; struct _toy_func_env *upstack; struct _toy_type *tobe_bind_val; struct _toy_func_trace_info *trace_info; int script_id; } **func_stack; int cur_obj_stack; struct _toy_obj_env { struct _hash *cur_object_slot; struct _toy_type *cur_object; struct _toy_type *self; } **obj_stack; struct _hash *funcs; struct _hash *classes; struct _hash *globals; struct _hash *scripts; struct _toy_func_trace_info *trace_info; int script_id; struct _hash *gcache; int cache_hit; int cache_missing; int trace; int trace_fd; int cstack_id; void *cstack; int cstack_size; void *coroid; struct _toy_interp *co_parent; struct _toy_type *co_value; int co_calling; } *interp, struct _toy_type *posargs, struct _hash *namedargs, int arglen); struct _toy_type *argspec_list; } native; struct _object { struct _hash *slots; struct _toy_type *delegate_list; } object; struct _exception { struct _cell *code; struct _toy_type *msg_list; } exception; struct _closure { struct _toy_type *block_body; struct _toy_env { struct _toy_func_env *func_env; struct _toy_obj_env *object_env; struct _toy_type *tobe_bind_val; } *env; } closure; struct _func { struct _toy_argspec { struct _toy_type *list; int posarg_len; struct _array { int alloc_size; int cur_size; struct _toy_type *array; } *posarg_array; struct _hash *namedarg; } *argspec; struct _toy_type *closure; } func; struct _control { unsigned int code; struct _toy_type *ret_value; } control; void *container; struct _getmacro { struct _toy_type *obj; struct _toy_type *para; } getmacro; struct _initmacro { struct _toy_type *class; struct _toy_type *param; } initmacro; struct _alias { struct _hash *slot; struct _toy_type *key; } alias; struct _cell *rquote; struct _toy_type *bind_var; struct _hash *dict; struct _array *vector; struct _toy_coroutine { struct _toy_interp *interp; struct _toy_type *script; int state; void *coro_id; } *coroutine; } u; } *

return_type: struct _array { int alloc_size; int cur_size; struct _toy_type { unsigned int tag; union _u { struct _symbol { struct _cell { int length; int allocsize; char *data; } *cell; unsigned int hash_index; } symbol; struct _ref { struct _cell *cell; unsigned int hash_index; } ref; struct _list { struct _toy_type *item; struct _toy_type *nextp; } list; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } biginteger[1]; double real; struct _cell *string; struct _toy_type *statement_list; struct _statement { struct _toy_type *item_list; struct _toy_func_trace_info { int line; struct _toy_type *object_name; struct _toy_type *func_name; struct _toy_type *statement; } *trace_info; } statement; struct _toy_type *block_body; struct _toy_type *eval_body; struct _native { struct _toy_type *(*cfunc)(struct _toy_interp { char *name; int stack_size; int cur_func_stack; struct _toy_func_env { struct _hash { int bucket_size; struct hash_bucket { char *key; unsigned int index; struct _toy_type *item; struct hash_bucket *next; } **bucket; int items; int synonyms; } *localvar; struct _toy_func_env *upstack; struct _toy_type *tobe_bind_val; struct _toy_func_trace_info *trace_info; int script_id; } **func_stack; int cur_obj_stack; struct _toy_obj_env { struct _hash *cur_object_slot; struct _toy_type *cur_object; struct _toy_type *self; } **obj_stack; struct _hash *funcs; struct _hash *classes; struct _hash *globals; struct _hash *scripts; struct _toy_func_trace_info *trace_info; int script_id; struct _hash *gcache; int cache_hit; int cache_missing; int trace; int trace_fd; int cstack_id; void *cstack; int cstack_size; void *coroid; struct _toy_interp *co_parent; struct _toy_type *co_value; int co_calling; } *interp, struct _toy_type *posargs, struct _hash *namedargs, int arglen); struct _toy_type *argspec_list; } native; struct _object { struct _hash *slots; struct _toy_type *delegate_list; } object; struct _exception { struct _cell *code; struct _toy_type *msg_list; } exception; struct _closure { struct _toy_type *block_body; struct _toy_env { struct _toy_func_env *func_env; struct _toy_obj_env *object_env; struct _toy_type *tobe_bind_val; } *env; } closure; struct _func { struct _toy_argspec { struct _toy_type *list; int posarg_len; struct _array *posarg_array; struct _hash *namedarg; } *argspec; struct _toy_type *closure; } func; struct _control { unsigned int code; struct _toy_type *ret_value; } control; void *container; struct _getmacro { struct _toy_type *obj; struct _toy_type *para; } getmacro; struct _initmacro { struct _toy_type *class; struct _toy_type *param; } initmacro; struct _alias { struct _hash *slot; struct _toy_type *key; } alias; struct _cell *rquote; struct _toy_type *bind_var; struct _hash *dict; struct _array *vector; struct _toy_coroutine { struct _toy_interp *interp; struct _toy_type *script; int state; void *coro_id; } *coroutine; } u; } *array; } *

user_defined_types: struct _toy_type { unsigned int tag; union _u u; }

user_defined_types: union _u { struct _symbol symbol; struct _ref ref; struct _list list; struct __mpz_struct biginteger[1]; double real; struct _cell *string; struct _toy_type *statement_list; struct _statement statement; struct _toy_type *block_body; struct _toy_type *eval_body; struct _native native; struct _object object; struct _exception exception; struct _closure closure; struct _func func; struct _control control; void *container; struct _getmacro getmacro; struct _initmacro initmacro; struct _alias alias; struct _cell *rquote; struct _toy_type *bind_var; struct _hash *dict; struct _array *vector; struct _toy_coroutine *coroutine; }

user_defined_types: struct _symbol { struct _cell *cell; unsigned int hash_index; }

user_defined_types: struct _statement { struct _toy_type *item_list; struct _toy_func_trace_info *trace_info; }

user_defined_types: struct _native { struct _toy_type *(*cfunc)(struct _toy_interp *interp, struct _toy_type *posargs, struct _hash *namedargs, int arglen); struct _toy_type *argspec_list; }

user_defined_types: struct _closure { struct _toy_type *block_body; struct _toy_env *env; }

user_defined_types: struct _func { struct _toy_argspec *argspec; struct _toy_type *closure; }

user_defined_types: struct _toy_interp { char *name; int stack_size; int cur_func_stack; struct _toy_func_env **func_stack; int cur_obj_stack; struct _toy_obj_env **obj_stack; struct _hash *funcs; struct _hash *classes; struct _hash *globals; struct _hash *scripts; struct _toy_func_trace_info *trace_info; int script_id; struct _hash *gcache; int cache_hit; int cache_missing; int trace; int trace_fd; int cstack_id; void *cstack; int cstack_size; void *coroid; struct _toy_interp *co_parent; struct _toy_type *co_value; int co_calling; }

user_defined_types: struct _toy_func_env { struct _hash *localvar; struct _toy_func_env *upstack; struct _toy_type *tobe_bind_val; struct _toy_func_trace_info *trace_info; int script_id; }

user_defined_types: struct _hash { int bucket_size; struct hash_bucket **bucket; int items; int synonyms; }


decompiled_code:
_QWORD *new_array()
{
__int64 v0; // rax
_QWORD *v1; // r12
_QWORD *v2; // rax
_QWORD *result; // rax

v0 = GC_malloc(16LL);
if ( !v0 || (v1 = (_QWORD *)v0, v2 = (_QWORD *)GC_malloc(6144LL), (v1[1] = v2) == 0LL) )
{
puts("alloc failed.");
exit(255);
}
*v2 = 0LL;
v2[767] = 0LL;
memset(
(void *)((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 6144) >> 3));
result = v1;
*v1 = 256LL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
__int64 v0; // rax
_QWORD *v1; // r12
_QWORD *v2; // rax
_QWORD *result; // rax

v0 = GC_malloc(16LL);
if ( !v0 || (v1 = (_QWORD *)v0, v2 = (_QWORD *)GC_malloc(6144LL), (v1[1] = v2) == 0LL) )
{
puts("alloc failed.");
exit(255);
}
*v2 = 0LL;
v2[767] = 0LL;
memset(
(void *)((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 6144) >> 3));
result = v1;
*v1 = 256LL;
return result;
}

original_code:
Array*
new_array() {
    Array *array;
    array = GC_malloc(sizeof(Array));
    if (!array) {printf("alloc failed.\n"); exit(255);};
    array->array = GC_malloc(sizeof(Toy_Type) * (256));
    if (!array->array) {printf("alloc failed.\n"); exit(255);};
    memset(array->array, 0, sizeof(Toy_Type) * (256));
    array->alloc_size = (256);
    array->cur_size = 0;
    return array;
}

canonical_original_code:
struct _array *new_array() {
    struct _array *array;
    array = GC_malloc(sizeof(Array));
    if (!array) {printf("alloc failed.\n"); exit(255);};
    array->array = GC_malloc(sizeof(Toy_Type) * (256));
    if (!array->array) {printf("alloc failed.\n"); exit(255);};
    memset(array->array, 0, sizeof(Toy_Type) * (256));
    array->alloc_size = (256);
    array->cur_size = 0;
    return array;
}

variable_types: struct _array { int alloc_size; int cur_size; struct _toy_type { unsigned int tag; union _u { struct _symbol { struct _cell { int length; int allocsize; char *data; } *cell; unsigned int hash_index; } symbol; struct _ref { struct _cell *cell; unsigned int hash_index; } ref; struct _list { struct _toy_type *item; struct _toy_type *nextp; } list; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } biginteger[1]; double real; struct _cell *string; struct _toy_type *statement_list; struct _statement { struct _toy_type *item_list; struct _toy_func_trace_info { int line; struct _toy_type *object_name; struct _toy_type *func_name; struct _toy_type *statement; } *trace_info; } statement; struct _toy_type *block_body; struct _toy_type *eval_body; struct _native { struct _toy_type *(*cfunc)(struct _toy_interp { char *name; int stack_size; int cur_func_stack; struct _toy_func_env { struct _hash { int bucket_size; struct hash_bucket { char *key; unsigned int index; struct _toy_type *item; struct hash_bucket *next; } **bucket; int items; int synonyms; } *localvar; struct _toy_func_env *upstack; struct _toy_type *tobe_bind_val; struct _toy_func_trace_info *trace_info; int script_id; } **func_stack; int cur_obj_stack; struct _toy_obj_env { struct _hash *cur_object_slot; struct _toy_type *cur_object; struct _toy_type *self; } **obj_stack; struct _hash *funcs; struct _hash *classes; struct _hash *globals; struct _hash *scripts; struct _toy_func_trace_info *trace_info; int script_id; struct _hash *gcache; int cache_hit; int cache_missing; int trace; int trace_fd; int cstack_id; void *cstack; int cstack_size; void *coroid; struct _toy_interp *co_parent; struct _toy_type *co_value; int co_calling; } *interp, struct _toy_type *posargs, struct _hash *namedargs, int arglen); struct _toy_type *argspec_list; } native; struct _object { struct _hash *slots; struct _toy_type *delegate_list; } object; struct _exception { struct _cell *code; struct _toy_type *msg_list; } exception; struct _closure { struct _toy_type *block_body; struct _toy_env { struct _toy_func_env *func_env; struct _toy_obj_env *object_env; struct _toy_type *tobe_bind_val; } *env; } closure; struct _func { struct _toy_argspec { struct _toy_type *list; int posarg_len; struct _array *posarg_array; struct _hash *namedarg; } *argspec; struct _toy_type *closure; } func; struct _control { unsigned int code; struct _toy_type *ret_value; } control; void *container; struct _getmacro { struct _toy_type *obj; struct _toy_type *para; } getmacro; struct _initmacro { struct _toy_type *class; struct _toy_type *param; } initmacro; struct _alias { struct _hash *slot; struct _toy_type *key; } alias; struct _cell *rquote; struct _toy_type *bind_var; struct _hash *dict; struct _array *vector; struct _toy_coroutine { struct _toy_interp *interp; struct _toy_type *script; int state; void *coro_id; } *coroutine; } u; } *array; } *

user_defined_types: struct _array { int alloc_size; int cur_size; struct _toy_type *array; }


original_code:
Array*
array_append(Array *array, Toy_Type *item) {
    if (((void *)0) == array) return ((void *)0);
    if ((array->cur_size + 1) > array->alloc_size) {
 if (((void *)0) == array_realloc(array)) return ((void *)0);
    }
    array->array[array->cur_size] = *item;
    array->cur_size++;
    return array;
}

canonical_original_code:
struct _array *array_append(struct _array *array, struct _toy_type *item) {
    if (((void *)0) == array) return ((void *)0);
    if ((array->cur_size + 1) > array->alloc_size) {
 if (((void *)0) == array_realloc(array)) return ((void *)0);
    }
    array->array[array->cur_size] = *item;
    array->cur_size++;
    return array;
}

variable_types:
item
struct _toy_type *

user_defined_types: struct _ref { struct _cell *cell; unsigned int hash_index; }

user_defined_types: struct _list { struct _toy_type *item; struct _toy_type *nextp; }

user_defined_types: struct _object { struct _hash *slots; struct _toy_type *delegate_list; }

user_defined_types: struct _exception { struct _cell *code; struct _toy_type *msg_list; }

user_defined_types: struct _control { unsigned int code; struct _toy_type *ret_value; }

user_defined_types: struct _getmacro { struct _toy_type *obj; struct _toy_type *para; }

user_defined_types: struct _initmacro { struct _toy_type *class; struct _toy_type *param; }

user_defined_types: struct _alias { struct _hash *slot; struct _toy_type *key; }

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }

user_defined_types: struct _toy_coroutine { struct _toy_interp *interp; struct _toy_type *script; int state; void *coro_id; }

user_defined_types: struct _cell { int length; int allocsize; char *data; }

user_defined_types: struct _toy_func_trace_info { int line; struct _toy_type *object_name; struct _toy_type *func_name; struct _toy_type *statement; }

user_defined_types: struct _toy_env { struct _toy_func_env *func_env; struct _toy_obj_env *object_env; struct _toy_type *tobe_bind_val; }

user_defined_types: struct _toy_argspec { struct _toy_type *list; int posarg_len; struct _array *posarg_array; struct _hash *namedarg; }

user_defined_types: struct _toy_obj_env { struct _hash *cur_object_slot; struct _toy_type *cur_object; struct _toy_type *self; }

user_defined_types: struct hash_bucket { char *key; unsigned int index; struct _toy_type *item; struct hash_bucket *next; }


original_code:
Array*
array_set(Array *array, Toy_Type *item, int pos) {
    if (((void *)0) == array) return ((void *)0);
    if ((pos < 0) || (pos >= array->cur_size)) return ((void *)0);
    array->array[pos] = *item;
    return array;
}

canonical_original_code:
struct _array *array_set(struct _array *array, struct _toy_type *item, int pos) {
    if (((void *)0) == array) return ((void *)0);
    if ((pos < 0) || (pos >= array->cur_size)) return ((void *)0);
    array->array[pos] = *item;
    return array;
}

user_defined_types: struct _array { int alloc_size; int cur_size; struct _toy_type *array; }

user_defined_types: struct _toy_type { unsigned int tag; union _u u; }

user_defined_types: union _u { struct _symbol symbol; struct _ref ref; struct _list list; struct __mpz_struct biginteger[1]; double real; struct _cell *string; struct _toy_type *statement_list; struct _statement statement; struct _toy_type *block_body; struct _toy_type *eval_body; struct _native native; struct _object object; struct _exception exception; struct _closure closure; struct _func func; struct _control control; void *container; struct _getmacro getmacro; struct _initmacro initmacro; struct _alias alias; struct _cell *rquote; struct _toy_type *bind_var; struct _hash *dict; struct _array *vector; struct _toy_coroutine *coroutine; }

user_defined_types: struct _symbol { struct _cell *cell; unsigned int hash_index; }

user_defined_types: struct _statement { struct _toy_type *item_list; struct _toy_func_trace_info *trace_info; }

user_defined_types: struct _native { struct _toy_type *(*cfunc)(struct _toy_interp *interp, struct _toy_type *posargs, struct _hash *namedargs, int arglen); struct _toy_type *argspec_list; }

user_defined_types: struct _closure { struct _toy_type *block_body; struct _toy_env *env; }

user_defined_types: struct _func { struct _toy_argspec *argspec; struct _toy_type *closure; }

user_defined_types: struct _toy_interp { char *name; int stack_size; int cur_func_stack; struct _toy_func_env **func_stack; int cur_obj_stack; struct _toy_obj_env **obj_stack; struct _hash *funcs; struct _hash *classes; struct _hash *globals; struct _hash *scripts; struct _toy_func_trace_info *trace_info; int script_id; struct _hash *gcache; int cache_hit; int cache_missing; int trace; int trace_fd; int cstack_id; void *cstack; int cstack_size; void *coroid; struct _toy_interp *co_parent; struct _toy_type *co_value; int co_calling; }

user_defined_types: struct _toy_func_env { struct _hash *localvar; struct _toy_func_env *upstack; struct _toy_type *tobe_bind_val; struct _toy_func_trace_info *trace_info; int script_id; }

user_defined_types: struct _hash { int bucket_size; struct hash_bucket **bucket; int items; int synonyms; }


decompiled_code:
__int64 __fastcall array_get(__int64 a1, int a2)
{
__int64 result; // rax

if ( a1 && a2 >= 0 && *(_DWORD *)(a1 + 4) > a2 )
result = *(_QWORD *)(a1 + 8) + 24LL * a2;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 result; // rax

if ( a1 && a2 >= 0 && *(_DWORD *)(a1 + 4) > a2 )
result = *(_QWORD *)(a1 + 8) + 24LL * a2;
else
result = 0LL;
return result;
}

original_code:
struct _toy_type*
array_get(Array *array, int pos) {
    if (((void *)0) == array) return ((void *)0);
    if ((pos < 0) || (pos >= array->cur_size)) return ((void *)0);
    return &(array->array[pos]);
}

canonical_original_code:
struct _toy_type *array_get(struct _array *array, int pos) {
    if (((void *)0) == array) return ((void *)0);
    if ((pos < 0) || (pos >= array->cur_size)) return ((void *)0);
    return &(array->array[pos]);
}

return_type: struct _toy_type { unsigned int tag; union _u { struct _symbol { struct _cell { int length; int allocsize; char *data; } *cell; unsigned int hash_index; } symbol; struct _ref { struct _cell *cell; unsigned int hash_index; } ref; struct _list { struct _toy_type *item; struct _toy_type *nextp; } list; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } biginteger[1]; double real; struct _cell *string; struct _toy_type *statement_list; struct _statement { struct _toy_type *item_list; struct _toy_func_trace_info { int line; struct _toy_type *object_name; struct _toy_type *func_name; struct _toy_type *statement; } *trace_info; } statement; struct _toy_type *block_body; struct _toy_type *eval_body; struct _native { struct _toy_type *(*cfunc)(struct _toy_interp { char *name; int stack_size; int cur_func_stack; struct _toy_func_env { struct _hash { int bucket_size; struct hash_bucket { char *key; unsigned int index; struct _toy_type *item; struct hash_bucket *next; } **bucket; int items; int synonyms; } *localvar; struct _toy_func_env *upstack; struct _toy_type *tobe_bind_val; struct _toy_func_trace_info *trace_info; int script_id; } **func_stack; int cur_obj_stack; struct _toy_obj_env { struct _hash *cur_object_slot; struct _toy_type *cur_object; struct _toy_type *self; } **obj_stack; struct _hash *funcs; struct _hash *classes; struct _hash *globals; struct _hash *scripts; struct _toy_func_trace_info *trace_info; int script_id; struct _hash *gcache; int cache_hit; int cache_missing; int trace; int trace_fd; int cstack_id; void *cstack; int cstack_size; void *coroid; struct _toy_interp *co_parent; struct _toy_type *co_value; int co_calling; } *interp, struct _toy_type *posargs, struct _hash *namedargs, int arglen); struct _toy_type *argspec_list; } native; struct _object { struct _hash *slots; struct _toy_type *delegate_list; } object; struct _exception { struct _cell *code; struct _toy_type *msg_list; } exception; struct _closure { struct _toy_type *block_body; struct _toy_env { struct _toy_func_env *func_env; struct _toy_obj_env *object_env; struct _toy_type *tobe_bind_val; } *env; } closure; struct _func { struct _toy_argspec { struct _toy_type *list; int posarg_len; struct _array { int alloc_size; int cur_size; struct _toy_type *array; } *posarg_array; struct _hash *namedarg; } *argspec; struct _toy_type *closure; } func; struct _control { unsigned int code; struct _toy_type *ret_value; } control; void *container; struct _getmacro { struct _toy_type *obj; struct _toy_type *para; } getmacro; struct _initmacro { struct _toy_type *class; struct _toy_type *param; } initmacro; struct _alias { struct _hash *slot; struct _toy_type *key; } alias; struct _cell *rquote; struct _toy_type *bind_var; struct _hash *dict; struct _array *vector; struct _toy_coroutine { struct _toy_interp *interp; struct _toy_type *script; int state; void *coro_id; } *coroutine; } u; } *


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

if ( a1 )
result = *(unsigned int *)(a1 + 4);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 4);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
array_get_size(Array *array) {
    if (((void *)0) == array) return -1;
    return array->cur_size;
}

canonical_original_code:
int array_get_size(struct _array *array) {
    if (((void *)0) == array) return -1;
    return array->cur_size;
}

user_defined_types: struct _ref { struct _cell *cell; unsigned int hash_index; }

user_defined_types: struct _list { struct _toy_type *item; struct _toy_type *nextp; }

user_defined_types: struct _object { struct _hash *slots; struct _toy_type *delegate_list; }

user_defined_types: struct _exception { struct _cell *code; struct _toy_type *msg_list; }

user_defined_types: struct _control { unsigned int code; struct _toy_type *ret_value; }

user_defined_types: struct _getmacro { struct _toy_type *obj; struct _toy_type *para; }

user_defined_types: struct _initmacro { struct _toy_type *class; struct _toy_type *param; }

user_defined_types: struct _alias { struct _hash *slot; struct _toy_type *key; }

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }

user_defined_types: struct _toy_coroutine { struct _toy_interp *interp; struct _toy_type *script; int state; void *coro_id; }

user_defined_types: struct _cell { int length; int allocsize; char *data; }


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

const_Symbol = new_symbol("Symbol");
const_NilClass = new_symbol("Nil");
const_Block = new_symbol("Block");
const_List = new_symbol("List");
const_Real = new_symbol("Real");
const_Integer = new_symbol("Integer");
const_String = new_symbol("String");
const_Exception = new_symbol("Exception");
const_RQuote = new_symbol("RQuote");
const_Object = new_symbol("Object");
const_CallCC = new_symbol("CallCC");
const_Dict = new_symbol("Dict");
const_Vector = new_symbol("Vector");
const_Coro = new_symbol("Coro");
const_Nil = new_nil();
const_T = new_symbol("t");
const_Question = new_symbol("?");
const_Holder = new_symbol("@holder");
const_Init = new_symbol("init");
const_Hash = new_symbol("Hash");
const_File = new_symbol("File");
const_Args = new_symbol("args:");
const_Array = new_symbol("Array");
const_Get = new_symbol("get");
const_atout = new_symbol("@out");
const_atin = new_symbol("@in");
const_stdin = new_symbol("stdin");
const_stdout = new_symbol("stdout");
const_stderr = new_symbol("stderr");
const_filec = new_symbol("file:");
const_gets = new_symbol("gets");
const_puts = new_symbol("puts");
const_atname = new_symbol("@name");
const_atstacktrace = new_symbol("@stack-trace");
const_SIGHUP = new_symbol("SIGHUP");
const_SIGINT = new_symbol("SIGINT");
const_SIGQUIT = new_symbol("SIGQUIT");
const_SIGPIPE = new_symbol("SIGPIPE");
const_SIGALRM = new_symbol("SIGALRM");
const_SIGTERM = new_symbol("SIGTERM");
const_SIGURG = new_symbol("SIGURG");
const_SIGCHLD = new_symbol("SIGCHLD");
const_SIGUSR1 = new_symbol("SIGUSR1");
const_SIGUSR2 = new_symbol("SIGUSR2");
const_attrap = new_symbol("@trap");
const_atscriptid = new_symbol("@script-id");
const_CWD = new_symbol("CWD");
const_ENV = new_symbol("ENV");
const_up = new_symbol("up:");
const_VERSION = new_symbol("VERSION");
const_nocase = new_symbol("nocase:");
const_all = new_symbol("all:");
const_string = new_symbol("string");
const_delegate = new_symbol("delegate:");
const_init = new_symbol("init:");
const_int1 = new_integer_si(1LL);
const_new = new_symbol("new");
const_unknown = new_symbol("unknown");
const_out = new_symbol("out:");
const_local = new_symbol("local:");
const_nocascade = new_symbol("nocascade:");
const_NotImpliment = new_exception("ErrNotImpliment", "Not Impliment.", 0LL);
const_then = new_symbol("then:");
const_else = new_symbol("else:");
const_do = new_symbol("do:");
const_catch = new_symbol("catch:");
const_fin = new_symbol("fin:");
const_to = new_symbol("to:");
const_sep = new_symbol("sep:");
const_mode = new_symbol("mode:");
result = sysconf(30);
PageSize = result;
return result;
}

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

const_Symbol = new_symbol("Symbol");
const_NilClass = new_symbol("Nil");
const_Block = new_symbol("Block");
const_List = new_symbol("List");
const_Real = new_symbol("Real");
const_Integer = new_symbol("Integer");
const_String = new_symbol("String");
const_Exception = new_symbol("Exception");
const_RQuote = new_symbol("RQuote");
const_Object = new_symbol("Object");
const_CallCC = new_symbol("CallCC");
const_Dict = new_symbol("Dict");
const_Vector = new_symbol("Vector");
const_Coro = new_symbol("Coro");
const_Nil = new_nil();
const_T = new_symbol("t");
const_Question = new_symbol("?");
const_Holder = new_symbol("@holder");
const_Init = new_symbol("init");
const_Hash = new_symbol("Hash");
const_File = new_symbol("File");
const_Args = new_symbol("args:");
const_Array = new_symbol("Array");
const_Get = new_symbol("get");
const_atout = new_symbol("@out");
const_atin = new_symbol("@in");
const_stdin = new_symbol("stdin");
const_stdout = new_symbol("stdout");
const_stderr = new_symbol("stderr");
const_filec = new_symbol("file:");
const_gets = new_symbol("gets");
const_puts = new_symbol("puts");
const_atname = new_symbol("@name");
const_atstacktrace = new_symbol("@stack-trace");
const_SIGHUP = new_symbol("SIGHUP");
const_SIGINT = new_symbol("SIGINT");
const_SIGQUIT = new_symbol("SIGQUIT");
const_SIGPIPE = new_symbol("SIGPIPE");
const_SIGALRM = new_symbol("SIGALRM");
const_SIGTERM = new_symbol("SIGTERM");
const_SIGURG = new_symbol("SIGURG");
const_SIGCHLD = new_symbol("SIGCHLD");
const_SIGUSR1 = new_symbol("SIGUSR1");
const_SIGUSR2 = new_symbol("SIGUSR2");
const_attrap = new_symbol("@trap");
const_atscriptid = new_symbol("@script-id");
const_CWD = new_symbol("CWD");
const_ENV = new_symbol("ENV");
const_up = new_symbol("up:");
const_VERSION = new_symbol("VERSION");
const_nocase = new_symbol("nocase:");
const_all = new_symbol("all:");
const_string = new_symbol("string");
const_delegate = new_symbol("delegate:");
const_init = new_symbol("init:");
const_int1 = new_integer_si(1LL);
const_new = new_symbol("new");
const_unknown = new_symbol("unknown");
const_out = new_symbol("out:");
const_local = new_symbol("local:");
const_nocascade = new_symbol("nocascade:");
const_NotImpliment = new_exception("ErrNotImpliment", "Not Impliment.", 0LL);
const_then = new_symbol("then:");
const_else = new_symbol("else:");
const_do = new_symbol("do:");
const_catch = new_symbol("catch:");
const_fin = new_symbol("fin:");
const_to = new_symbol("to:");
const_sep = new_symbol("sep:");
const_mode = new_symbol("mode:");
result = sysconf(30);
PageSize = result;
return result;
}

original_code:
void def_global() {
    const_Symbol = new_symbol("Symbol");
    const_NilClass = new_symbol("Nil");
    const_Block = new_symbol("Block");
    const_List = new_symbol("List");
    const_Real = new_symbol("Real");
    const_Integer = new_symbol("Integer");
    const_String = new_symbol("String");
    const_Exception = new_symbol("Exception");
    const_RQuote = new_symbol("RQuote");
    const_Object = new_symbol("Object");
    const_CallCC = new_symbol("CallCC");
    const_Dict = new_symbol("Dict");
    const_Vector = new_symbol("Vector");
    const_Coro = new_symbol("Coro");
    const_Nil = new_nil();
    const_T = new_symbol("t");
    const_Question = new_symbol("?");
    const_Holder = new_symbol("@holder");
    const_Init = new_symbol("init");
    const_Hash = new_symbol("Hash");
    const_File = new_symbol("File");
    const_Args = new_symbol("args:");
    const_Array = new_symbol("Array");
    const_Get = new_symbol("get");
    const_atout = new_symbol("@out");
    const_atin = new_symbol("@in");
    const_stdin = new_symbol("stdin");
    const_stdout = new_symbol("stdout");
    const_stderr = new_symbol("stderr");
    const_filec = new_symbol("file:");
    const_gets = new_symbol("gets");
    const_puts = new_symbol("puts");
    const_atname = new_symbol("@name");
    const_atstacktrace = new_symbol("@stack-trace");
    const_SIGHUP = new_symbol("SIGHUP");
    const_SIGINT = new_symbol("SIGINT");
    const_SIGQUIT = new_symbol("SIGQUIT");
    const_SIGPIPE = new_symbol("SIGPIPE");
    const_SIGALRM = new_symbol("SIGALRM");
    const_SIGTERM = new_symbol("SIGTERM");
    const_SIGURG = new_symbol("SIGURG");
    const_SIGCHLD = new_symbol("SIGCHLD");
    const_SIGUSR1 = new_symbol("SIGUSR1");
    const_SIGUSR2 = new_symbol("SIGUSR2");
    const_attrap = new_symbol("@trap");
    const_atscriptid = new_symbol("@script-id");
    const_CWD = new_symbol("CWD");
    const_ENV = new_symbol("ENV");
    const_up = new_symbol("up:");
    const_VERSION = new_symbol("VERSION");
    const_nocase = new_symbol("nocase:");
    const_all = new_symbol("all:");
    const_string = new_symbol("string");
    const_delegate = new_symbol("delegate:");
    const_init = new_symbol("init:");
    const_int1 = new_integer_si(1);
    const_new = new_symbol("new");
    const_unknown = new_symbol("unknown");
    const_out = new_symbol("out:");
    const_local = new_symbol("local:");
    const_nocascade = new_symbol("nocascade:");
    const_NotImpliment = new_exception("ErrNotImpliment", "Not Impliment.", ((void *)0));
    const_then = new_symbol("then:");
    const_else = new_symbol("else:");
    const_do = new_symbol("do:");
    const_catch = new_symbol("catch:");
    const_fin = new_symbol("fin:");
    const_to = new_symbol("to:");
    const_sep = new_symbol("sep:");
    const_mode = new_symbol("mode:");
    PageSize = sysconf(_SC_PAGESIZE);
}

return_type: void


main

canonical_name: main

repo: mixu/nbar

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
nbar_init(argc, argv, envp);
while ( 1 )
nbar_loop();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
while ( 1 )
func8();
}

original_code:
int main() {
  nbar_init();
  while(1) {
    nbar_loop();
  }
  return 0;
}


decompiled_code:
int nbar_init()
{
Display *v0; // rax
Display *v1; // rdi
__int64 v2; // rax
__int64 v3; // rbx
XFontStruct *v4; // rax

v0 = XOpenDisplay(0LL);
nbar = v0;
if ( !v0 )
__assert_fail("nbar.dpy", "./src/nbar.c", 0x16u, "nbar_init");
v1 = v0;
v2 = (__int64)&v0->screens[(__int64)v0->default_screen];
v3 = *(_QWORD *)(v2 + 88);
qword_4040D8 = XCreateSimpleWindow(
v1,
*(_QWORD *)(v2 + 16),
0,
0,
0xC8u,
0x64u,
0,
*(int *)(v2 + 96),
*(int *)(v2 + 96));
XSelectInput(nbar, qword_4040D8, 163845LL);
XMapWindow(nbar, qword_4040D8);
qword_4040D0 = XCreateGC(nbar, qword_4040D8, 0LL, 0LL);
XSetForeground(nbar, qword_4040D0, (int)v3);
v4 = XLoadQueryFont(nbar, "9x15");
qword_4040E8 = v4;
if ( !v4 )
return 1;
XSetFont(nbar, qword_4040D0, v4->fid);
XTextWidth(qword_4040E8, "yay it works", 12);
dword_4040E0 = qword_4040E8->ascent + qword_4040E8->descent;
return XConnectionNumber(nbar);
}

canonical_decompiled_code:
int func7()
{
Display *v0; // rax
Display *v1; // rdi
__int64 v2; // rax
__int64 v3; // rbx
XFontStruct *v4; // rax

v0 = XOpenDisplay(0LL);
nbar = v0;
if ( !v0 )
__assert_fail("nbar.dpy", "./src/nbar.c", 0x16u, "nbar_init");
v1 = v0;
v2 = (__int64)&v0->screens[(__int64)v0->default_screen];
v3 = *(_QWORD *)(v2 + 88);
qword_4040D8 = XCreateSimpleWindow(
v1,
*(_QWORD *)(v2 + 16),
0,
0,
0xC8u,
0x64u,
0,
*(int *)(v2 + 96),
*(int *)(v2 + 96));
XSelectInput(nbar, qword_4040D8, 163845LL);
XMapWindow(nbar, qword_4040D8);
qword_4040D0 = XCreateGC(nbar, qword_4040D8, 0LL, 0LL);
XSetForeground(nbar, qword_4040D0, (int)v3);
v4 = XLoadQueryFont(nbar, "9x15");
qword_4040E8 = v4;
if ( !v4 )
return 1;
XSetFont(nbar, qword_4040D0, v4->fid);
XTextWidth(qword_4040E8, "yay it works", 12);
dword_4040E0 = qword_4040E8->ascent + qword_4040E8->descent;
return XConnectionNumber(nbar);
}

original_code:
int nbar_init() {
  nbar.dpy = XOpenDisplay(((void *)0));
  ((nbar.dpy) ? (void) (0) : __assert_fail ("nbar.dpy", "./src/nbar.c", 22, __extension__ __PRETTY_FUNCTION__));
  int blackColor = ((&((_XPrivDisplay)(nbar.dpy))->screens[(((_XPrivDisplay)(nbar.dpy))->default_screen)])->black_pixel);
  int whiteColor = ((&((_XPrivDisplay)(nbar.dpy))->screens[(((_XPrivDisplay)(nbar.dpy))->default_screen)])->white_pixel);
  nbar.win = XCreateSimpleWindow(nbar.dpy, ((&((_XPrivDisplay)(nbar.dpy))->screens[(((_XPrivDisplay)(nbar.dpy))->default_screen)])->root), 0, 0,
         200, 100, 0, blackColor, blackColor);
  XSelectInput(nbar.dpy, nbar.win, (1L<<15) | (1L<<0) | (1L<<2) | (1L<<17));
  XMapWindow(nbar.dpy, nbar.win);
  nbar.gc = XCreateGC(nbar.dpy, nbar.win, 0, ((void *)0));
  XSetForeground(nbar.dpy, nbar.gc, whiteColor);
  if ( (nbar.font_info = XLoadQueryFont(nbar.dpy, "9x15")) == ((void *)0) ) {
    return 1;
  }
  XSetFont(nbar.dpy, nbar.gc, nbar.font_info->fid);
  static int length;
  static char * message = "yay it works";
  length = XTextWidth(nbar.font_info, message, strlen(message));
  nbar.font_height = nbar.font_info->ascent + nbar.font_info->descent;
  return XConnectionNumber(nbar.dpy);
}

canonical_original_code:
int nbar_init() {
  nbar.dpy = XOpenDisplay(((void *)0));
  ((nbar.dpy) ? (void) (0) : __assert_fail ("nbar.dpy", "./src/nbar.c", 22, __extension__ __PRETTY_FUNCTION__));
  int blackColor = ((&((_XPrivDisplay)(nbar.dpy))->screens[(((_XPrivDisplay)(nbar.dpy))->default_screen)])->black_pixel);
  int whiteColor = ((&((_XPrivDisplay)(nbar.dpy))->screens[(((_XPrivDisplay)(nbar.dpy))->default_screen)])->white_pixel);
  nbar.win = XCreateSimpleWindow(nbar.dpy, ((&((_XPrivDisplay)(nbar.dpy))->screens[(((_XPrivDisplay)(nbar.dpy))->default_screen)])->root), 0, 0,
         200, 100, 0, blackColor, blackColor);
  XSelectInput(nbar.dpy, nbar.win, (1L<<15) | (1L<<0) | (1L<<2) | (1L<<17));
  XMapWindow(nbar.dpy, nbar.win);
  nbar.gc = XCreateGC(nbar.dpy, nbar.win, 0, ((void *)0));
  XSetForeground(nbar.dpy, nbar.gc, whiteColor);
  if ( (nbar.font_info = XLoadQueryFont(nbar.dpy, "9x15")) == ((void *)0) ) {
    return 1;
  }
  XSetFont(nbar.dpy, nbar.gc, nbar.font_info->fid);
  static int length;
  static char *message = "yay it works";
  length = XTextWidth(nbar.font_info, message, strlen(message));
  nbar.font_height = nbar.font_info->ascent + nbar.font_info->descent;
  return XConnectionNumber(nbar.dpy);
}

variable_types: blackColor int

variable_types: whiteColor int

variable_types: length int

variable_types:
message
char *


repo: mjames-upc/garp

decompiled_code:
__int64 __fastcall get_directory_list(char *src, char **a2)
{
size_t v2; // rax
char *v3; // rbp
unsigned int v4; // er12
__int64 v5; // r13
char *v6; // rbp
char *v7; // rax
char *v8; // rbx
char *v9; // r13
size_t v10; // rax
char *v11; // rax
char *v13; // rax

v2 = strlen(src + 1);
v3 = (char *)malloc(8 * v2);
strcpy(v3, src);
if ( strtok(v3, "/") )
{
v4 = 0;
do
v5 = (int)v4++;
while ( strtok(0LL, "/") );
strcpy(v3, src);
v6 = strtok(v3, "/");
v7 = (char *)malloc(8LL * ((int)v5 + 2));
*a2 = v7;
v8 = v7;
v9 = &v7[8 * v5 + 8];
do
{
v8 += 8;
v10 = strlen(v6);
v11 = (char *)malloc(v10 + 1);
*((_QWORD *)v8 - 1) = v11;
strcpy(v11, v6);
v6 = strtok(0LL, "/");
}
while ( v8 != v9 );
}
else
{
v4 = 0;
strcpy(v3, src);
strtok(v3, "/");
v13 = (char *)malloc(8uLL);
*a2 = v13;
v9 = v13;
}
*(_QWORD *)v9 = 0LL;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src, char **a2)
{
size_t v2; // rax
char *v3; // rbp
unsigned int v4; // er12
__int64 v5; // r13
char *v6; // rbp
char *v7; // rax
char *v8; // rbx
char *v9; // r13
size_t v10; // rax
char *v11; // rax
char *v13; // rax

v2 = strlen(src + 1);
v3 = (char *)malloc(8 * v2);
strcpy(v3, src);
if ( strtok(v3, "/") )
{
v4 = 0;
do
v5 = (int)v4++;
while ( strtok(0LL, "/") );
strcpy(v3, src);
v6 = strtok(v3, "/");
v7 = (char *)malloc(8LL * ((int)v5 + 2));
*a2 = v7;
v8 = v7;
v9 = &v7[8 * v5 + 8];
do
{
v8 += 8;
v10 = strlen(v6);
v11 = (char *)malloc(v10 + 1);
*((_QWORD *)v8 - 1) = v11;
strcpy(v11, v6);
v6 = strtok(0LL, "/");
}
while ( v8 != v9 );
}
else
{
v4 = 0;
strcpy(v3, src);
strtok(v3, "/");
v13 = (char *)malloc(8uLL);
*a2 = v13;
v9 = v13;
}
*(_QWORD *)v9 = 0LL;
return v4;
}

original_code:
int
get_directory_list ( const char *default_directory, char ***directory_list )
{
 int i, count=0;
 const char *tokensep="/";
 char *buf;
 char *token;
 char **directory_listp;
 buf = (char *) malloc (sizeof(char *) *
                            strlen ( default_directory+1 ));
 strcpy ( buf, default_directory );
 token = strtok ( buf, tokensep );
 while ( token != ((void *)0) ) {
     token = strtok ( ((void *)0), tokensep );
     count++;
 }
 strcpy ( buf, default_directory );
 token = strtok ( buf, tokensep );
 *directory_list = (char **) malloc (sizeof(char *) * (count + 1));
 for (i=0, directory_listp = *directory_list; i<count; i++) {
     *directory_listp = (char *) malloc (strlen (token) + 1);
     strcpy ( *directory_listp, token );
     *directory_listp++;
     token = strtok ( ((void *)0), tokensep );
 }
 *directory_listp = (char *) ((void *)0);
 return ( count );
}

canonical_original_code:
int get_directory_list(char *default_directory, char ***directory_list)
{
 int i; int count = 0;
 char *tokensep = "/";
 char *buf;
 char *token;
 char **directory_listp;
 buf = (char *) malloc (sizeof(char *) *
                            strlen ( default_directory+1 ));
 strcpy ( buf, default_directory );
 token = strtok ( buf, tokensep );
 while ( token != ((void *)0) ) {
     token = strtok ( ((void *)0), tokensep );
     count++;
 }
 strcpy ( buf, default_directory );
 token = strtok ( buf, tokensep );
 *directory_list = (char **) malloc (sizeof(char *) * (count + 1));
 for (i=0, directory_listp = *directory_list; i<count; i++) {
     *directory_listp = (char *) malloc (strlen (token) + 1);
     strcpy ( *directory_listp, token );
     *directory_listp++;
     token = strtok ( ((void *)0), tokensep );
 }
 *directory_listp = (char *) ((void *)0);
 return ( count );
}

variable_types: i int

variable_types: count int

variable_types:
tokensep
char *

variable_types:
buf
char *

variable_types:
token
char *


nodot

decompiled_code:
_BOOL8 __fastcall nodot(_BYTE *a1)
{
return *a1 != 46;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_BYTE *a1)
{
return *a1 != 46;
}

original_code:
static int nodot(char *fileName )
{
 if( fileName[0] == '.')
  return(0);
 return(1);
}

canonical_original_code:
static int nodot(char *fileName)
{
 if( fileName[0] == '.')
  return(0);
 return(1);
}

variable_types:
fileName
char *


AlphaSort

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

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

original_code:
static int AlphaSort( char **a, char **b)
{
        return ( strcmp ( *a, *b ) );
}

canonical_original_code:
static int AlphaSort(char **a, char **b)
{
        return ( strcmp ( *a, *b ) );
}

variable_types:
a
char **

variable_types:
b
char **


decompiled_code:
void __fastcall free_readdirectory(int a1, _QWORD *a2)
{
__int64 v3; // rbx
void *v4; // rdi

if ( a1 > 0 && (v3 = 0LL, a2) )
{
while ( 1 )
{
v4 = (void *)a2[v3];
if ( !v4 )
break;
free(v4);
if ( a1 <= (int)++v3 )
{
free(a2);
return;
}
}
puts("free_readdirectory: Bad pointer in filelist");
}
else
{
puts("free_readdirectory: Null or zero length paramaters");
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, _QWORD *a2)
{
__int64 v3; // rbx
void *v4; // rdi

if ( a1 > 0 && (v3 = 0LL, a2) )
{
while ( 1 )
{
v4 = (void *)a2[v3];
if ( !v4 )
break;
free(v4);
if ( a1 <= (int)++v3 )
{
free(a2);
return;
}
}
puts("free_readdirectory: Bad pointer in filelist");
}
else
{
puts("free_readdirectory: Null or zero length paramaters");
}
}

original_code:
int free_readdirectory( int filec, char **filelist )
{
 char **list;
 int i;
 if ( filec <= 0 || filelist == ((void *)0) ) {
  printf ("free_readdirectory: Null or zero length paramaters\n");
  return;
 }
 for (i = 0, list = filelist; i < filec; i++, *list++ ) {
  if ( ! *list ) {
   printf("free_readdirectory: Bad pointer in filelist\n");
   return;
  }
  free(*list);
 }
 free(filelist);
}

canonical_original_code:
int free_readdirectory(int filec, char **filelist)
{
 char **list;
 int i;
 if ( filec <= 0 || filelist == ((void *)0) ) {
  printf ("free_readdirectory: Null or zero length paramaters\n");
  return;
 }
 for (i = 0, list = filelist; i < filec; i++, *list++ ) {
  if ( ! *list ) {
   printf("free_readdirectory: Bad pointer in filelist\n");
   return;
  }
  free(*list);
 }
 free(filelist);
}

variable_types: filec int

variable_types:
filelist
char **

variable_types:
list
char **


readdirectory

decompiled_code:
__int64 __fastcall readdirectory(const char *a1, void **a2, _BOOL8 (__fastcall *a3)(char *a1), int (*a4)(const void *, const void *))
{
int (*v4)(const void *, const void *); // r13
_BOOL8 (__fastcall *v5)(char *); // rbx
int v6; // eax
int v7; // er12
__int64 v9; // r14
_QWORD *v10; // rax
struct dirent **v11; // r15
_QWORD *v12; // rbp
struct dirent *v13; // rdi
size_t v14; // rax
char *v15; // rax
struct dirent **v16; // rdi
char *src; // [rsp+10h] [rbp-58h]
int v18; // [rsp+1Ch] [rbp-4Ch]
struct dirent **namelist; // [rsp+28h] [rbp-40h] BYREF

v4 = a4;
v5 = a3;
if ( !a4 )
v4 = AlphaSort;
if ( !a3 )
v5 = nodot;
v6 = scandir(a1, &namelist, 0LL, 0LL);
if ( v6 < 0 )
{
v7 = 0;
*a2 = 0LL;
}
else
{
v7 = v6;
if ( v6 )
{
v9 = 0LL;
v10 = malloc(8LL * (v6 + 1));
v18 = 0;
v11 = namelist;
v12 = v10;
*a2 = v10;
do
{
if ( v5(v11[v9]->d_name) )
{
++v12;
src = v11[v9]->d_name;
v14 = strlen(src);
v15 = (char *)malloc(v14 + 1);
*(v12 - 1) = v15;
strcpy(v15, src);
++v18;
}
v13 = v11[v9++];
free(v13);
}
while ( v7 > (int)v9 );
v7 = v18;
qsort(*a2, v18, 8uLL, v4);
v16 = namelist;
*v12 = 0LL;
free(v16);
if ( !v18 )
{
free(*a2);
*a2 = 0LL;
}
}
}
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, void **a2, _BOOL8 (__fastcall *a3)(char *a1), int (*a4)(const void *, const void *))
{
int (*v4)(const void *, const void *); // r13
_BOOL8 (__fastcall *v5)(char *); // rbx
int v6; // eax
int v7; // er12
__int64 v9; // r14
_QWORD *v10; // rax
struct dirent **v11; // r15
_QWORD *v12; // rbp
struct dirent *v13; // rdi
size_t v14; // rax
char *v15; // rax
struct dirent **v16; // rdi
char *src; // [rsp+10h] [rbp-58h]
int v18; // [rsp+1Ch] [rbp-4Ch]
struct dirent **namelist; // [rsp+28h] [rbp-40h] BYREF

v4 = a4;
v5 = a3;
if ( !a4 )
v4 = AlphaSort;
if ( !a3 )
v5 = nodot;
v6 = scandir(a1, &namelist, 0LL, 0LL);
if ( v6 < 0 )
{
v7 = 0;
*a2 = 0LL;
}
else
{
v7 = v6;
if ( v6 )
{
v9 = 0LL;
v10 = malloc(8LL * (v6 + 1));
v18 = 0;
v11 = namelist;
v12 = v10;
*a2 = v10;
do
{
if ( v5(v11[v9]->d_name) )
{
++v12;
src = v11[v9]->d_name;
v14 = strlen(src);
v15 = (char *)malloc(v14 + 1);
*(v12 - 1) = v15;
strcpy(v15, src);
++v18;
}
v13 = v11[v9++];
free(v13);
}
while ( v7 > (int)v9 );
v7 = v18;
qsort(*a2, v18, 8uLL, v4);
v16 = namelist;
*v12 = 0LL;
free(v16);
if ( !v18 )
{
free(*a2);
*a2 = 0LL;
}
}
}
return (unsigned int)v7;
}

original_code:
int
readdirectory(char *dirname, char ***filelist, int (*selectFunc)(),
              int (*sortFunc)() )
{
 int i;
 int adjustedFileCount;
 int num_entries;
 char **filelistp;
 struct dirent **namelist, **list;
        int (*realSortFunc)();
 int (*realSelectFunc)();
 realSortFunc = AlphaSort;
        if ( sortFunc != ((void *)0) )
  realSortFunc = sortFunc;
 realSelectFunc = nodot;
 if ( selectFunc != ((void *)0) )
  realSelectFunc = selectFunc;
 num_entries = scandir(dirname, &namelist, ((void *)0),
                       ((void *)0));
 if ( num_entries < 0 ) {
  *filelist = ((void *)0);
  return(0);
 }
 if (num_entries == 0) {
  return(num_entries);
 }
 *filelist = (char **) malloc (sizeof(char *) * (num_entries + 1));
 adjustedFileCount = 0;
 list = namelist;
 filelistp = *filelist;
 for (i=0; i<num_entries; i++) {
  if( (*realSelectFunc)( (*list)->d_name) ) {
   *filelistp =
    (char *) malloc(strlen((*list)->d_name) + 1);
   strcpy(*filelistp, (*list)->d_name);
   *filelistp++;
   adjustedFileCount++;
  }
  free(*list);
  *list++;
 }
 if( realSortFunc )
  qsort( *filelist, adjustedFileCount, sizeof(char *),
    realSortFunc );
 *filelistp = (char *) ((void *)0);
 free( namelist );
 if ( adjustedFileCount == 0 ) {
  free ( *filelist );
  *filelist = ((void *)0);
 }
 return ( adjustedFileCount );
}

canonical_original_code:
int readdirectory(char *dirname, char ***filelist, int (*selectFunc)(), int (*sortFunc)())
{
 int i;
 int adjustedFileCount;
 int num_entries;
 char **filelistp;
 struct dirent **namelist; struct dirent **list;
        int (*realSortFunc)();
 int (*realSelectFunc)();
 realSortFunc = AlphaSort;
        if ( sortFunc != ((void *)0) )
  realSortFunc = sortFunc;
 realSelectFunc = nodot;
 if ( selectFunc != ((void *)0) )
  realSelectFunc = selectFunc;
 num_entries = scandir(dirname, &namelist, ((void *)0),
                       ((void *)0));
 if ( num_entries < 0 ) {
  *filelist = ((void *)0);
  return(0);
 }
 if (num_entries == 0) {
  return(num_entries);
 }
 *filelist = (char **) malloc (sizeof(char *) * (num_entries + 1));
 adjustedFileCount = 0;
 list = namelist;
 filelistp = *filelist;
 for (i=0; i<num_entries; i++) {
  if( (*realSelectFunc)( (*list)->d_name) ) {
   *filelistp =
    (char *) malloc(strlen((*list)->d_name) + 1);
   strcpy(*filelistp, (*list)->d_name);
   *filelistp++;
   adjustedFileCount++;
  }
  free(*list);
  *list++;
 }
 if( realSortFunc )
  qsort( *filelist, adjustedFileCount, sizeof(char *),
    realSortFunc );
 *filelistp = (char *) ((void *)0);
 free( namelist );
 if ( adjustedFileCount == 0 ) {
  free ( *filelist );
  *filelist = ((void *)0);
 }
 return ( adjustedFileCount );
}

variable_types:
dirname
char *

variable_types:
filelist
char ***

variable_types:
selectFunc
int (*)()

variable_types:
sortFunc
int (*)()

variable_types: adjustedFileCount int

variable_types:
filelistp
char **

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **

variable_types:
realSortFunc
int (*)()

variable_types:
realSelectFunc
int (*)()


DirExists

decompiled_code:
_BOOL8 __fastcall DirExists(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( v1 >= 0 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( v1 >= 0 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

original_code:
int DirExists( char *pathname )
{
 struct stat buf;
 if( stat( pathname, & buf ) < 0 )
  return( 0 );
 return( ((((buf.st_mode)) & 0170000) == (0040000)) );
}

canonical_original_code:
int DirExists(char *pathname)
{
 struct stat buf;
 if( stat( pathname, & buf ) < 0 )
  return( 0 );
 return( ((((buf.st_mode)) & 0170000) == (0040000)) );
}

variable_types:
pathname
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


FileExists

decompiled_code:
_BOOL8 __fastcall FileExists(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( v1 >= 0 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( v1 >= 0 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

original_code:
int FileExists( char *pathname )
{
 struct stat buf;
 if( stat( pathname, & buf ) < 0 )
  return( 0 );
 return( ((((buf.st_mode)) & 0170000) == (0100000)) );
}

canonical_original_code:
int FileExists(char *pathname)
{
 struct stat buf;
 if( stat( pathname, & buf ) < 0 )
  return( 0 );
 return( ((((buf.st_mode)) & 0170000) == (0100000)) );
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__int64 __fastcall ldl_u(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
return *a1;
}

original_code:
static __inline__ x86emuu32
ldl_u(x86emuu32 * p)
{
    const struct __una_u32 *ptr = (const struct __una_u32 *) p;
    return ptr->x;
}

canonical_original_code:
static __inline__ unsigned int ldl_u(unsigned int *p)
{
    struct __una_u32 *ptr = (const struct __una_u32 *) p;
    return ptr->x;
}

variable_types:
p
unsigned int *

variable_types:
ptr
struct __una_u32 { unsigned int x; } *

return_type: unsigned int


decompiled_code:
__int64 __fastcall ldw_u(unsigned __int16 *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 *a1)
{
return *a1;
}

original_code:
static __inline__ x86emuu16
ldw_u(x86emuu16 * p)
{
    const struct __una_u16 *ptr = (const struct __una_u16 *) p;
    return ptr->x;
}

canonical_original_code:
static __inline__ unsigned short ldw_u(unsigned short *p)
{
    struct __una_u16 *ptr = (const struct __una_u16 *) p;
    return ptr->x;
}

variable_types:
p
unsigned short *

variable_types: struct __una_u16 { unsigned short x; } *

return_type: unsigned short


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

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

original_code:
static x86emuu8
p_inb(X86EMU_pioAddr addr)
{

        return 0;
}

canonical_original_code:
static unsigned char p_inb(unsigned short addr)
{

        return 0;
}

variable_types:
addr
unsigned short

return_type: unsigned char


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

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

original_code:
static x86emuu16
p_inw(X86EMU_pioAddr addr)
{

        return 0;
}

canonical_original_code:
static unsigned short p_inw(unsigned short addr)
{

        return 0;
}


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

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

original_code:
static x86emuu32
p_inl(X86EMU_pioAddr addr)
{

        return 0;
}

canonical_original_code:
static unsigned int p_inl(unsigned short addr)
{

        return 0;
}


decompiled_code:
void p_outb()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
static void
p_outb(X86EMU_pioAddr addr, x86emuu8 val)
{

        return;
}

canonical_original_code:
static void p_outb(unsigned short addr, unsigned char val)
{

        return;
}

variable_types:
val
unsigned char


decompiled_code:
void p_outw()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
static void
p_outw(X86EMU_pioAddr addr, x86emuu16 val)
{

        return;
}

canonical_original_code:
static void p_outw(unsigned short addr, unsigned short val)
{

        return;
}

variable_types:
val
unsigned short


decompiled_code:
void p_outl()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
static void
p_outl(X86EMU_pioAddr addr, x86emuu32 val)
{

        return;
}

canonical_original_code:
static void p_outl(unsigned short addr, unsigned int val)
{

        return;
}

variable_types:
val
unsigned int


rdb

decompiled_code:
__int64 __fastcall rdb(unsigned int a1)
{
if ( a1 > (unsigned __int64)(X86EMU_env[1] - 1) )
X86EMU_halt_sys();
return *(unsigned __int8 *)(X86EMU_env[0] + a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
if ( a1 > (unsigned __int64)(X86EMU_env[1] - 1) )
X86EMU_halt_sys();
return *(unsigned __int8 *)(X86EMU_env[0] + a1);
}

original_code:
x86emuu8
rdb(x86emuu32 addr)
{
    x86emuu8 val;
    if (addr > _X86EMU_env.mem_size - 1) {

            X86EMU_halt_sys();
    }
    val = *(x86emuu8 *) (_X86EMU_env.mem_base + addr);

        return val;
}

canonical_original_code:
unsigned char rdb(unsigned int addr)
{
    unsigned char val;
    if (addr > _X86EMU_env.mem_size - 1) {

            X86EMU_halt_sys();
    }
    val = *(unsigned char *) (_X86EMU_env.mem_base + addr);

        return val;
}

variable_types:
addr
unsigned int


rdw

decompiled_code:
__int64 __fastcall rdw(unsigned int a1)
{
if ( a1 > (unsigned __int64)(X86EMU_env[1] - 2) )
X86EMU_halt_sys();
return ldw_u((unsigned __int16 *)(X86EMU_env[0] + a1));
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
if ( a1 > (unsigned __int64)(X86EMU_env[1] - 2) )
X86EMU_halt_sys();
return func1((unsigned __int16 *)(X86EMU_env[0] + a1));
}

original_code:
x86emuu16
rdw(x86emuu32 addr)
{
    x86emuu16 val = 0;
    if (addr > _X86EMU_env.mem_size - 2) {

            X86EMU_halt_sys();
    }
        val = ldw_u((x86emuu16 *) (_X86EMU_env.mem_base + addr));

        return val;
}

canonical_original_code:
unsigned short rdw(unsigned int addr)
{
    unsigned short val = 0;
    if (addr > _X86EMU_env.mem_size - 2) {

            X86EMU_halt_sys();
    }
        val = ldw_u((unsigned short *) (_X86EMU_env.mem_base + addr));

        return val;
}


rdl

decompiled_code:
__int64 __fastcall rdl(unsigned int a1)
{
if ( a1 > (unsigned __int64)(X86EMU_env[1] - 4) )
X86EMU_halt_sys();
return ldl_u((unsigned int *)(X86EMU_env[0] + a1));
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
if ( a1 > (unsigned __int64)(X86EMU_env[1] - 4) )
X86EMU_halt_sys();
return func0((unsigned int *)(X86EMU_env[0] + a1));
}

original_code:
x86emuu32
rdl(x86emuu32 addr)
{
    x86emuu32 val = 0;
    if (addr > _X86EMU_env.mem_size - 4) {

            X86EMU_halt_sys();
    }
        val = ldl_u((x86emuu32 *) (_X86EMU_env.mem_base + addr));

        return val;
}

canonical_original_code:
unsigned int rdl(unsigned int addr)
{
    unsigned int val = 0;
    if (addr > _X86EMU_env.mem_size - 4) {

            X86EMU_halt_sys();
    }
        val = ldl_u((unsigned int *) (_X86EMU_env.mem_base + addr));

        return val;
}


wrb

decompiled_code:
__int64 __fastcall wrb(unsigned int a1, char a2)
{
__int64 result; // rax

if ( a1 > (unsigned __int64)(X86EMU_env[1] - 1) )
X86EMU_halt_sys();
result = X86EMU_env[0];
*(_BYTE *)(X86EMU_env[0] + a1) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, char a2)
{
__int64 result; // rax

if ( a1 > (unsigned __int64)(X86EMU_env[1] - 1) )
X86EMU_halt_sys();
result = X86EMU_env[0];
*(_BYTE *)(X86EMU_env[0] + a1) = a2;
return result;
}

original_code:
void
wrb(x86emuu32 addr, x86emuu8 val)
{

        if (addr > _X86EMU_env.mem_size - 1) {

                X86EMU_halt_sys();
        }
    *(x86emuu8 *) (_X86EMU_env.mem_base + addr) = val;
}

canonical_original_code:
void wrb(unsigned int addr, unsigned char val)
{

        if (addr > _X86EMU_env.mem_size - 1) {

                X86EMU_halt_sys();
        }
    *(unsigned char *) (_X86EMU_env.mem_base + addr) = val;
}


decompiled_code:
__int64 __fastcall X86EMU_prepareForInt(int a1)
{
unsigned int v1; // ebp
__int64 v2; // rdi
__int16 v3; // ax
__int64 v4; // rdi
__int64 result; // rax

v1 = 4 * a1;
push_word(WORD2(X86EMU_env[7]));
v2 = LOWORD(X86EMU_env[8]);
HIDWORD(X86EMU_env[7]) &= 0xFFFFFCFF;
push_word(v2);
v3 = mem_access_word(v1 + 2);
v4 = LOWORD(X86EMU_env[7]);
LOWORD(X86EMU_env[8]) = v3;
push_word(v4);
result = mem_access_word(v1);
LODWORD(X86EMU_env[10]) = 0;
LOWORD(X86EMU_env[7]) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
unsigned int v1; // ebp
__int64 v2; // rdi
__int16 v3; // ax
__int64 v4; // rdi
__int64 result; // rax

v1 = 4 * a1;
push_word(WORD2(X86EMU_env[7]));
v2 = LOWORD(X86EMU_env[8]);
HIDWORD(X86EMU_env[7]) &= 0xFFFFFCFF;
push_word(v2);
v3 = mem_access_word(v1 + 2);
v4 = LOWORD(X86EMU_env[7]);
LOWORD(X86EMU_env[8]) = v3;
push_word(v4);
result = mem_access_word(v1);
LODWORD(X86EMU_env[10]) = 0;
LOWORD(X86EMU_env[7]) = result;
return result;
}

original_code:
void
X86EMU_prepareForInt(int num)
{
    push_word((x86emuu16) _X86EMU_env.x86.spc.FLAGS);
    (_X86EMU_env.x86.spc.FLAGS &= ~(0x0200));
    (_X86EMU_env.x86.spc.FLAGS &= ~(0x0100));
    push_word(_X86EMU_env.x86.seg.CS);
    _X86EMU_env.x86.seg.CS = mem_access_word(num * 4 + 2);
    push_word(_X86EMU_env.x86.spc.IP.I16_reg.x_reg);
    _X86EMU_env.x86.spc.IP.I16_reg.x_reg = mem_access_word(num * 4);
    _X86EMU_env.x86.intr = 0;
}

canonical_original_code:
void X86EMU_prepareForInt(int num)
{
    push_word((unsigned short) _X86EMU_env.x86.spc.FLAGS);
    (_X86EMU_env.x86.spc.FLAGS &= ~(0x0200));
    (_X86EMU_env.x86.spc.FLAGS &= ~(0x0100));
    push_word(_X86EMU_env.x86.seg.CS);
    _X86EMU_env.x86.seg.CS = mem_access_word(num * 4 + 2);
    push_word(_X86EMU_env.x86.spc.IP.I16_reg.x_reg);
    _X86EMU_env.x86.spc.IP.I16_reg.x_reg = mem_access_word(num * 4);
    _X86EMU_env.x86.intr = 0;
}

variable_types: num int


decompiled_code:
void x86emuOp_esc_coprocess_d8()
{
X86EMU_env[19] &= 0xFFFFF980;
}

canonical_decompiled_code:
void func0()
{
X86EMU_env[19] &= 0xFFFFF980;
}


decompiled_code:
__int64 x86emuOp_esc_coprocess_d9()
{
__int64 result; // rax
unsigned int v1; // [rsp+4h] [rbp-14h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

fetch_decode_modrm(&v1, v3, &v2);
result = v1;
if ( v1 == 1 )
{
result = decode_rm01_address(v2);
X86EMU_env[19] &= 0xFFFFF980;
}
else if ( v1 == 2 )
{
result = decode_rm10_address(v2);
X86EMU_env[19] &= 0xFFFFF980;
}
else
{
if ( !v1 )
result = decode_rm00_address(v2);
X86EMU_env[19] &= 0xFFFFF980;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
unsigned int v1; // [rsp+4h] [rbp-14h] BYREF
unsigned int v2; // [rsp+8h] [rbp-10h] BYREF
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

fetch_decode_modrm(&v1, v3, &v2);
result = v1;
if ( v1 == 1 )
{
result = decode_rm01_address(v2);
X86EMU_env[19] &= 0xFFFFF980;
}
else if ( v1 == 2 )
{
result = decode_rm10_address(v2);
X86EMU_env[19] &= 0xFFFFF980;
}
else
{
if ( !v1 )
result = decode_rm00_address(v2);
X86EMU_env[19] &= 0xFFFFF980;
}
return result;
}

original_code:
void
x86emuOp_esc_coprocess_d9(x86emuu8 op1)
{
    int mod, rl, rh;
    x86emuuint destoffset = 0;
    x86emuu8 stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (x86emuu8) rl;
        if (rh < 4) {
            ;
        }
        else {
            ;
        }
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}

canonical_original_code:
void x86emuOp_esc_coprocess_d9(unsigned char op1)
{
    int mod; int rl; int rh;
    unsigned int destoffset = 0;
    unsigned char stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (unsigned char) rl;
        if (rh < 4) {
            ;
        }
        else {
            ;
        }
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}

variable_types: mod int

variable_types: rl int

variable_types: rh int

variable_types:
destoffset
unsigned int

variable_types:
stkelem
unsigned char


decompiled_code:
// attributes: thunk
__int64 x86emuOp_esc_coprocess_da()
{
return x86emuOp_esc_coprocess_d9();
}

canonical_decompiled_code:
__int64 func2()
{
return func1();
}

original_code:
void
x86emuOp_esc_coprocess_da(x86emuu8 op1)
{
    int mod, rl, rh;
    x86emuuint destoffset = 0;
    x86emuu8 stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    ;
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (x86emuu8) rl;
        ;
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}

canonical_original_code:
void x86emuOp_esc_coprocess_da(unsigned char op1)
{
    int mod; int rl; int rh;
    unsigned int destoffset = 0;
    unsigned char stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    ;
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (unsigned char) rl;
        ;
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}


decompiled_code:
// attributes: thunk
__int64 x86emuOp_esc_coprocess_db()
{
return x86emuOp_esc_coprocess_d9();
}

canonical_decompiled_code:
__int64 func3()
{
return func1();
}

original_code:
void
x86emuOp_esc_coprocess_db(x86emuu8 op1)
{
    int mod, rl, rh;
    x86emuuint destoffset = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        break;
    case 3:
        break;
    }
    (void) destoffset;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}

canonical_original_code:
void x86emuOp_esc_coprocess_db(unsigned char op1)
{
    int mod; int rl; int rh;
    unsigned int destoffset = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        break;
    case 3:
        break;
    }
    (void) destoffset;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}


decompiled_code:
// attributes: thunk
__int64 x86emuOp_esc_coprocess_dc()
{
return x86emuOp_esc_coprocess_d9();
}

canonical_decompiled_code:
__int64 func4()
{
return func1();
}

original_code:
void
x86emuOp_esc_coprocess_dc(x86emuu8 op1)
{
    int mod, rl, rh;
    x86emuuint destoffset = 0;
    x86emuu8 stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    ;
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (x86emuu8) rl;
        ;
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}

canonical_original_code:
void x86emuOp_esc_coprocess_dc(unsigned char op1)
{
    int mod; int rl; int rh;
    unsigned int destoffset = 0;
    unsigned char stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    ;
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (unsigned char) rl;
        ;
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}


decompiled_code:
// attributes: thunk
__int64 x86emuOp_esc_coprocess_dd()
{
return x86emuOp_esc_coprocess_d9();
}

canonical_decompiled_code:
__int64 func5()
{
return func1();
}

original_code:
void
x86emuOp_esc_coprocess_dd(x86emuu8 op1)
{
    int mod, rl, rh;
    x86emuuint destoffset = 0;
    x86emuu8 stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    ;
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (x86emuu8) rl;
        ;
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}

canonical_original_code:
void x86emuOp_esc_coprocess_dd(unsigned char op1)
{
    int mod; int rl; int rh;
    unsigned int destoffset = 0;
    unsigned char stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    ;
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (unsigned char) rl;
        ;
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}


decompiled_code:
// attributes: thunk
__int64 x86emuOp_esc_coprocess_de()
{
return x86emuOp_esc_coprocess_d9();
}

canonical_decompiled_code:
__int64 func6()
{
return func1();
}

original_code:
void
x86emuOp_esc_coprocess_de(x86emuu8 op1)
{
    int mod, rl, rh;
    x86emuuint destoffset = 0;
    x86emuu8 stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    ;
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (x86emuu8) rl;
        ;
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}

canonical_original_code:
void x86emuOp_esc_coprocess_de(unsigned char op1)
{
    int mod; int rl; int rh;
    unsigned int destoffset = 0;
    unsigned char stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    ;
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (unsigned char) rl;
        ;
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}


decompiled_code:
// attributes: thunk
__int64 x86emuOp_esc_coprocess_df()
{
return x86emuOp_esc_coprocess_d9();
}

canonical_decompiled_code:
__int64 func7()
{
return func1();
}

original_code:
void
x86emuOp_esc_coprocess_df(x86emuu8 op1)
{
    int mod, rl, rh;
    x86emuuint destoffset = 0;
    x86emuu8 stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    ;
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (x86emuu8) rl;
        ;
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}

canonical_original_code:
void x86emuOp_esc_coprocess_df(unsigned char op1)
{
    int mod; int rl; int rh;
    unsigned int destoffset = 0;
    unsigned char stkelem = 0;
    ;
    fetch_decode_modrm(&mod,&rh,&rl);
    ;
    switch (mod) {
    case 0:
        destoffset = decode_rm00_address(rl);
        ;
        break;
    case 1:
        destoffset = decode_rm01_address(rl);
        ;
        break;
    case 2:
        destoffset = decode_rm10_address(rl);
        ;
        break;
    case 3:
        stkelem = (unsigned char) rl;
        ;
        break;
    }
    (void) destoffset;
    (void) stkelem;
    _X86EMU_env.x86.mode &= ~(0x00000001 | 0x00000002 | 0x00000004 | 0x00000008 | 0x00000010 | 0x00000020 | 0x00000040 | 0x00000200 | 0x00000400);
    ;
}


main

repo: mjdominus/intro-c-programming

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rax
__int64 v5; // rax
const char *v6; // rax
__int64 v7; // rax
const char *v8; // rax
__int64 v9; // rax
const char *v10; // rax
char v12[80]; // [rsp+0h] [rbp-A8h] BYREF
char s[88]; // [rsp+50h] [rbp-58h] BYREF

fgets(v12, 80, stdin);
*strchr(v12, 10) = 0;
v3 = (const char *)normalize_signed(v12);
strcpy(v12, v3);
fgets(s, 80, stdin);
*strchr(s, 10) = 0;
v4 = (const char *)normalize_signed(s);
strcpy(s, v4);
v5 = add_signed_string(v12, s);
v6 = (const char *)normalize_signed(v5);
printf("%s + %s = %s\n", v12, s, v6);
v7 = subtract_signed_string(v12, s);
v8 = (const char *)normalize_signed(v7);
printf("%s - %s = %s\n", v12, s, v8);
v9 = subtract_signed_string(s, v12);
v10 = (const char *)normalize_signed(v9);
printf("%s - %s = %s\n", s, v12, v10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rax
__int64 v5; // rax
const char *v6; // rax
__int64 v7; // rax
const char *v8; // rax
__int64 v9; // rax
const char *v10; // rax
char v12[80]; // [rsp+0h] [rbp-A8h] BYREF
char s[88]; // [rsp+50h] [rbp-58h] BYREF

fgets(v12, 80, stdin);
*strchr(v12, 10) = 0;
v3 = (const char *)func11(v12);
strcpy(v12, v3);
fgets(s, 80, stdin);
*strchr(s, 10) = 0;
v4 = (const char *)func11(s);
strcpy(s, v4);
v5 = func8(v12, s);
v6 = (const char *)func11(v5);
printf("%s + %s = %s\n", v12, s, v6);
v7 = func12(v12, s);
v8 = (const char *)func11(v7);
printf("%s - %s = %s\n", v12, s, v8);
v9 = func12(s, v12);
v10 = (const char *)func11(v9);
printf("%s - %s = %s\n", s, v12, v10);
return 0;
}

original_code:
int
  main(void)
{
  char s1[80], s2[80];
  fgets(s1, 80, stdin);
  *strchr(s1, '\n') = '\0';
  strcpy(s1, normalize_signed(s1));
  fgets(s2, 80, stdin);
  *strchr(s2, '\n') = '\0';
  strcpy(s2, normalize_signed(s2));
  printf("%s + %s = %s\n", s1, s2, normalize_signed(add_signed_string(s1,s2)));
  printf("%s - %s = %s\n", s1, s2, normalize_signed(subtract_signed_string(s1,s2)));
  printf("%s - %s = %s\n", s2, s1, normalize_signed(subtract_signed_string(s2,s1)));
  return 0;
}

canonical_original_code:
int main()
{
  char s1[80]; char s2[80];
  fgets(s1, 80, stdin);
  *strchr(s1, '\n') = '\0';
  strcpy(s1, normalize_signed(s1));
  fgets(s2, 80, stdin);
  *strchr(s2, '\n') = '\0';
  strcpy(s2, normalize_signed(s2));
  printf("%s + %s = %s\n", s1, s2, normalize_signed(add_signed_string(s1,s2)));
  printf("%s - %s = %s\n", s1, s2, normalize_signed(subtract_signed_string(s1,s2)));
  printf("%s - %s = %s\n", s2, s1, normalize_signed(subtract_signed_string(s2,s1)));
  return 0;
}


decompiled_code:
__int64 __fastcall add_signed_string(char *a1, char *a2)
{
char *v2; // r12
char *v3; // rbp
__int64 v4; // r13
__int64 v5; // rax
char v6; // al
unsigned int v7; // er13
const char *v8; // r12
const char *v9; // rax
_BYTE *v10; // rax
__int64 v12; // r12
__int64 v13; // rax
__int64 v14; // rax

v2 = a2;
v3 = a1;
v4 = signed_to_unsigned(a2);
v5 = signed_to_unsigned(a1);
if ( (int)compare_unsigned_string(v5, v4) < 0 )
{
v3 = a2;
v2 = a1;
}
v6 = *v2;
if ( *v3 == 45 )
{
v7 = -1;
if ( v6 == 45 )
goto LABEL_5;
}
else
{
v7 = 1;
if ( v6 != 45 )
{
LABEL_5:
v8 = (const char *)signed_to_unsigned(v2);
v9 = (const char *)signed_to_unsigned(v3);
v10 = add_unsigned_string(v9, v8);
return unsigned_to_signed(v7, v10);
}
}
v12 = signed_to_unsigned(v2);
v13 = signed_to_unsigned(v3);
v14 = subtract_unsigned_string(v13, v12);
return unsigned_to_signed(v7, v14);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, char *a2)
{
char *v2; // r12
char *v3; // rbp
__int64 v4; // r13
__int64 v5; // rax
char v6; // al
unsigned int v7; // er13
const char *v8; // r12
const char *v9; // rax
_BYTE *v10; // rax
__int64 v12; // r12
__int64 v13; // rax
__int64 v14; // rax

v2 = a2;
v3 = a1;
v4 = func10(a2);
v5 = func10(a1);
if ( (int)func13(v5, v4) < 0 )
{
v3 = a2;
v2 = a1;
}
v6 = *v2;
if ( *v3 == 45 )
{
v7 = -1;
if ( v6 == 45 )
goto LABEL_5;
}
else
{
v7 = 1;
if ( v6 != 45 )
{
LABEL_5:
v8 = (const char *)func10(v2);
v9 = (const char *)func10(v3);
v10 = add_unsigned_string(v9, v8);
return unsigned_to_signed(v7, v10);
}
}
v12 = func10(v2);
v13 = func10(v3);
v14 = subtract_unsigned_string(v13, v12);
return unsigned_to_signed(v7, v14);
}

original_code:
char *
  add_signed_string(const char *s1, const char *s2)
{
  int m1, m2;
  int c;
  c = compare_unsigned_string(signed_to_unsigned(s1),
         signed_to_unsigned(s2));
  if (c < 0) {
    const char *temp;
    temp = s1;
    s1 = s2;
    s2 = temp;
  }
  m1 = (((*(s1))=='-') ? -1 : 1); m2 = (((*(s2))=='-') ? -1 : 1);
  if (m1 == m2)
    return unsigned_to_signed
      (m1,
       add_unsigned_string
       (signed_to_unsigned(s1), signed_to_unsigned(s2))
       );
  else
    return unsigned_to_signed
      (m1,
       subtract_unsigned_string
       (signed_to_unsigned(s1), signed_to_unsigned(s2))
       );
}

canonical_original_code:
char *add_signed_string(char *s1, char *s2)
{
  int m1; int m2;
  int c;
  c = compare_unsigned_string(signed_to_unsigned(s1),
         signed_to_unsigned(s2));
  if (c < 0) {
    char *temp;
    temp = s1;
    s1 = s2;
    s2 = temp;
  }
  m1 = (((*(s1))=='-') ? -1 : 1); m2 = (((*(s2))=='-') ? -1 : 1);
  if (m1 == m2)
    return unsigned_to_signed
      (m1,
       add_unsigned_string
       (signed_to_unsigned(s1), signed_to_unsigned(s2))
       );
  else
    return unsigned_to_signed
      (m1,
       subtract_unsigned_string
       (signed_to_unsigned(s1), signed_to_unsigned(s2))
       );
}

variable_types: c int

variable_types:
temp
char *


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

result = strdup(a1);
if ( result )
{
if ( *result == 43 )
{
*result = 45;
}
else
{
if ( *result != 45 )
{
fprintf(stderr, "negate_signed_string (%s) fails.\n", result);
abort();
}
*result = 43;
}
}
return result;
}

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

result = strdup(a1);
if ( result )
{
if ( *result == 43 )
{
*result = 45;
}
else
{
if ( *result != 45 )
{
fprintf(stderr, "negate_signed_string (%s) fails.\n", result);
abort();
}
*result = 43;
}
}
return result;
}

original_code:
char *
  negate_signed_string(const char *s)
{
  char *sn;
  sn = strdup(s);
  if (sn == ((void *)0))
    return ((void *)0);
  switch (*sn) {
  case '-':
    *sn = '+';
    break;
  case '+':
    *sn = '-';
    break;
  default:
    fprintf(stderr, "negate_signed_string (%s) fails.\n", sn);
    abort();
  }
  return sn;
}

canonical_original_code:
char *negate_signed_string(char *s)
{
  char *sn;
  sn = strdup(s);
  if (sn == ((void *)0))
    return ((void *)0);
  switch (*sn) {
  case '-':
    *sn = '+';
    break;
  case '+':
    *sn = '-';
    break;
  default:
    fprintf(stderr, "negate_signed_string (%s) fails.\n", sn);
    abort();
  }
  return sn;
}

variable_types:
s
char *

variable_types:
sn
char *


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

result = strdup(a1);
if ( result )
result += ((*result - 43) & 0xFD) == 0;
return result;
}

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

result = strdup(a1);
if ( result )
result += ((*result - 43) & 0xFD) == 0;
return result;
}

original_code:
char *
  signed_to_unsigned(const char *s)
{
  char *sa;
  sa = strdup(s);
  if (sa == ((void *)0)) return ((void *)0);
  switch (*sa) {
  case '+':
  case '-':
    return sa+1;
  default:
    return sa;
  }
}

canonical_original_code:
char *signed_to_unsigned(char *s)
{
  char *sa;
  sa = strdup(s);
  if (sa == ((void *)0)) return ((void *)0);
  switch (*sa) {
  case '+':
  case '-':
    return sa+1;
  default:
    return sa;
  }
}

variable_types:
sa
char *


original_code:
char *
  normalize_signed(const char *s)
{
  const char *last_nonzero_digit = ((void *)0), *p;
  char *sn;
  int i = 1;
  for (p=s+1; *p; p++)
    if (*p != ((0) + '0'))
      last_nonzero_digit = p;
  if (last_nonzero_digit == ((void *)0))
    return strdup("0");
  sn = malloc(last_nonzero_digit - s + 1);
  if (sn == ((void *)0)) return ((void *)0);
  for (p = last_nonzero_digit; p>s; p--)
    sn[i++] = *p;
  sn[0] = s[0];
  sn[last_nonzero_digit - s + 1] = '\0';
  return sn;
}

canonical_original_code:
char *normalize_signed(char *s)
{
  char *last_nonzero_digit = ((void *)0); char *p;
  char *sn;
  int i = 1;
  for (p=s+1; *p; p++)
    if (*p != ((0) + '0'))
      last_nonzero_digit = p;
  if (last_nonzero_digit == ((void *)0))
    return strdup("0");
  sn = malloc(last_nonzero_digit - s + 1);
  if (sn == ((void *)0)) return ((void *)0);
  for (p = last_nonzero_digit; p>s; p--)
    sn[i++] = *p;
  sn[0] = s[0];
  sn[last_nonzero_digit - s + 1] = '\0';
  return sn;
}

variable_types:
p
char *

variable_types: i int