decompiled_code:
__int64 msgpack_version_minor()
{
return 6LL;
}

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

original_code:
int msgpack_version_minor(void)
{
 return 6;
}

canonical_original_code:
int msgpack_version_minor()
{
 return 6;
}


repo: harmanpa/crecon

decompiled_code:
__int64 __fastcall recon_wall_table_n_signals(__int64 a1, _DWORD *a2, _DWORD *a3)
{
*a2 = *(_QWORD *)(a1 + 16);
*a3 = *(_QWORD *)(a1 + 32);
return 0LL;
}

original_code:
recon_status recon_wall_table_n_signals(recon_wall_table tab, int* nsignals, int* naliases) {
    wall_table* table = (wall_table*) tab;
    *nsignals = table->nsignals;
    *naliases = table->naliases;
    return 0;
}

canonical_original_code:
int recon_wall_table_n_signals(void *tab, int *nsignals, int *naliases) {
    struct wall_table *table = (wall_table*) tab;
    *nsignals = table->nsignals;
    *naliases = table->naliases;
    return 0;
}

variable_types:
tab
void *

variable_types:
nsignals
int *

variable_types:
naliases
int *

variable_types: struct wall_table { void *wall; char *name; unsigned long nsignals; unsigned long ndefinedsignals; unsigned long naliases; unsigned long ndefinedaliases; char **signals; char **aliases; char **aliased; char **transforms; unsigned long nrows; } *

return_type: int


original_code:
recon_status recon_wall_free_table(wall_table* table) {
    int i;
    for (i = 0; i < table->ndefinedsignals; i++) {
        free(table->signals[i]);
        table->signals[i] = ((void *)0);
    }
    for (i = 0; i < table->ndefinedaliases; i++) {
        free(table->aliases[i]);
        free(table->aliased[i]);
        if (0 != strcmp(table->transforms[i], "")) {
            free(table->transforms[i]);
            table->transforms[i] = ((void *)0);
        }
    }
    if (table->nsignals > 0) {
        free(table->signals);
        table->signals = ((void *)0);
    }
    if (table->naliases > 0) {
        free(table->aliases);
        free(table->aliased);
        free(table->transforms);
        table->aliases = ((void *)0);
        table->aliased = ((void *)0);
        table->transforms = ((void *)0);
    }
    free(table->name);
    return 0;
}

canonical_original_code:
int recon_wall_free_table(struct wall_table *table) {
    int i;
    for (i = 0; i < table->ndefinedsignals; i++) {
        free(table->signals[i]);
        table->signals[i] = ((void *)0);
    }
    for (i = 0; i < table->ndefinedaliases; i++) {
        free(table->aliases[i]);
        free(table->aliased[i]);
        if (0 != strcmp(table->transforms[i], "")) {
            free(table->transforms[i]);
            table->transforms[i] = ((void *)0);
        }
    }
    if (table->nsignals > 0) {
        free(table->signals);
        table->signals = ((void *)0);
    }
    if (table->naliases > 0) {
        free(table->aliases);
        free(table->aliased);
        free(table->transforms);
        table->aliases = ((void *)0);
        table->aliased = ((void *)0);
        table->transforms = ((void *)0);
    }
    free(table->name);
    return 0;
}

variable_types: i int

user_defined_types: struct wall_table { void *wall; char *name; unsigned long nsignals; unsigned long ndefinedsignals; unsigned long naliases; unsigned long ndefinedaliases; char **signals; char **aliases; char **aliased; char **transforms; unsigned long nrows; }


decompiled_code:
int __fastcall recon_wall_table_find_signal(__int64 a1, const char *a2, _DWORD *a3)
{
__int64 v3; // r12
__int64 v5; // r13
__int64 v6; // rbx
int result; // eax

v3 = *(_QWORD *)(a1 + 24);
if ( !v3 )
return -4;
v5 = *(_QWORD *)(a1 + 48);
v6 = 0LL;
while ( 1 )
{
result = strcmp(a2, *(const char **)(v5 + 8 * v6));
if ( !result )
break;
if ( ++v6 == v3 )
return -4;
}
*a3 = v6;
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2, _DWORD *a3)
{
__int64 v3; // r12
__int64 v5; // r13
__int64 v6; // rbx
int result; // eax

v3 = *(_QWORD *)(a1 + 24);
if ( !v3 )
return -4;
v5 = *(_QWORD *)(a1 + 48);
v6 = 0LL;
while ( 1 )
{
result = strcmp(a2, *(const char **)(v5 + 8 * v6));
if ( !result )
break;
if ( ++v6 == v3 )
return -4;
}
*a3 = v6;
return result;
}

original_code:
recon_status recon_wall_table_find_signal(recon_wall_table tab, const char* name, int* index) {
    int i;
    wall_table* table = (wall_table*) tab;
    for (i = 0; i < table->ndefinedsignals; i++) {
        if (strcmp(name, table->signals[i]) == 0) {
            *index = i;
            return 0;
        }
    }
    return -4;
}

canonical_original_code:
int recon_wall_table_find_signal(void *tab, char *name, int *index) {
    int i;
    struct wall_table *table = (wall_table*) tab;
    for (i = 0; i < table->ndefinedsignals; i++) {
        if (strcmp(name, table->signals[i]) == 0) {
            *index = i;
            return 0;
        }
    }
    return -4;
}

variable_types:
name
char *

variable_types:
index
int *


decompiled_code:
__int64 __fastcall recon_wall_table_add_signal(_QWORD *a1, const char *a2)
{
size_t v2; // rax
void **v3; // r12
size_t v4; // rax
int v6[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( a1[3] >= a1[2] )
return 0xFFFFFFFFLL;
if ( !recon_wall_table_find_signal((__int64)a1, a2, v6) )
return 4294967294LL;
v2 = strlen(a2);
v3 = (void **)(a1[6] + 8LL * a1[3]);
*v3 = malloc(v2 + 1);
v4 = strlen(a2);
memcpy(*(void **)(a1[6] + 8LL * a1[3]++), a2, v4 + 1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, const char *a2)
{
size_t v2; // rax
void **v3; // r12
size_t v4; // rax
int v6[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( a1[3] >= a1[2] )
return 0xFFFFFFFFLL;
if ( !func3((__int64)a1, a2, v6) )
return 4294967294LL;
v2 = strlen(a2);
v3 = (void **)(a1[6] + 8LL * a1[3]);
*v3 = malloc(v2 + 1);
v4 = strlen(a2);
memcpy(*(void **)(a1[6] + 8LL * a1[3]++), a2, v4 + 1);
return 0LL;
}

original_code:
recon_status recon_wall_table_add_signal(recon_wall_table tab, const char* name) {
    int other;
    wall_table* table = (wall_table*) tab;
    if (table->ndefinedsignals >= table->nsignals) {
        return -1;
    }
    if (recon_wall_table_find_signal(table, name, &other) == 0) {
        return -2;
    }
    table->signals[table->ndefinedsignals] = (char*) malloc(strlen(name) + 1);
    memcpy(table->signals[table->ndefinedsignals], name, strlen(name) + 1);
    table->ndefinedsignals++;
    return 0;
}

canonical_original_code:
int recon_wall_table_add_signal(void *tab, char *name) {
    int other;
    struct wall_table *table = (wall_table*) tab;
    if (table->ndefinedsignals >= table->nsignals) {
        return -1;
    }
    if (recon_wall_table_find_signal(table, name, &other) == 0) {
        return -2;
    }
    table->signals[table->ndefinedsignals] = (char *) malloc(strlen(name) + 1);
    memcpy(table->signals[table->ndefinedsignals], name, strlen(name) + 1);
    table->ndefinedsignals++;
    return 0;
}

variable_types: other int


decompiled_code:
int __fastcall recon_wall_table_find_alias(_QWORD *a1, const char *a2, _QWORD *a3, _QWORD *a4)
{
__int64 v4; // r12
__int64 v5; // r14
__int64 v6; // rbx
int result; // eax

v4 = a1[5];
if ( !v4 )
return -4;
v5 = a1[7];
v6 = 0LL;
while ( 1 )
{
result = strcmp(a2, *(const char **)(v5 + 8 * v6));
if ( !result )
break;
if ( ++v6 == v4 )
return -4;
}
*a3 = *(_QWORD *)(a1[8] + 8 * v6);
*a4 = *(_QWORD *)(a1[9] + 8 * v6);
return result;
}

canonical_decompiled_code:
int __fastcall func5(_QWORD *a1, const char *a2, _QWORD *a3, _QWORD *a4)
{
__int64 v4; // r12
__int64 v5; // r14
__int64 v6; // rbx
int result; // eax

v4 = a1[5];
if ( !v4 )
return -4;
v5 = a1[7];
v6 = 0LL;
while ( 1 )
{
result = strcmp(a2, *(const char **)(v5 + 8 * v6));
if ( !result )
break;
if ( ++v6 == v4 )
return -4;
}
*a3 = *(_QWORD *)(a1[8] + 8 * v6);
*a4 = *(_QWORD *)(a1[9] + 8 * v6);
return result;
}

original_code:
recon_status recon_wall_table_find_alias(recon_wall_table tab, const char* name, char** of, char** transform) {
    int i;
    wall_table* table = (wall_table*) tab;
    for (i = 0; i < table->ndefinedaliases; i++) {
        if (strcmp(name, table->aliases[i]) == 0) {
            *of = table->aliased[i];
            *transform = table->transforms[i];
            return 0;
        }
    }
    return -4;
}

canonical_original_code:
int recon_wall_table_find_alias(void *tab, char *name, char **of, char **transform) {
    int i;
    struct wall_table *table = (wall_table*) tab;
    for (i = 0; i < table->ndefinedaliases; i++) {
        if (strcmp(name, table->aliases[i]) == 0) {
            *of = table->aliased[i];
            *transform = table->transforms[i];
            return 0;
        }
    }
    return -4;
}

variable_types:
of
char **

variable_types:
transform
char **


decompiled_code:
__int64 __fastcall recon_wall_table_get_signal(__int64 a1, int a2, _QWORD *a3)
{
if ( a2 < 0 )
return 4294967285LL;
if ( (unsigned __int64)a2 >= *(_QWORD *)(a1 + 24) )
return 4294967285LL;
*a3 = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL * a2);
return 0LL;
}

original_code:
recon_status recon_wall_table_get_signal(recon_wall_table tab, int index, char** name) {
    wall_table* table = (wall_table*) tab;
    if (index < 0 || index >= table->ndefinedsignals) {
        return -11;
    }
    *name = table->signals[index];
    return 0;
}

canonical_original_code:
int recon_wall_table_get_signal(void *tab, int index, char **name) {
    struct wall_table *table = (wall_table*) tab;
    if (index < 0 || index >= table->ndefinedsignals) {
        return -11;
    }
    *name = table->signals[index];
    return 0;
}

variable_types: index int

variable_types:
name
char **


decompiled_code:
__int64 __fastcall recon_wall_table_get_alias(__int64 a1, int a2, _QWORD *a3)
{
if ( a2 < 0 )
return 4294967285LL;
if ( (unsigned __int64)a2 >= *(_QWORD *)(a1 + 40) )
return 4294967285LL;
*a3 = *(_QWORD *)(*(_QWORD *)(a1 + 56) + 8LL * a2);
return 0LL;
}

original_code:
recon_status recon_wall_table_get_alias(recon_wall_table tab, int index, char** name) {
    wall_table* table = (wall_table*) tab;
    if (index < 0 || index >= table->ndefinedaliases) {
        return -11;
    }
    *name = table->aliases[index];
    return 0;
}

canonical_original_code:
int recon_wall_table_get_alias(void *tab, int index, char **name) {
    struct wall_table *table = (wall_table*) tab;
    if (index < 0 || index >= table->ndefinedaliases) {
        return -11;
    }
    *name = table->aliases[index];
    return 0;
}


decompiled_code:
__int64 __fastcall recon_wall_table_add_alias(_QWORD *a1, const char *a2, const char *a3, const char *a4)
{
unsigned int v6; // er14
size_t v7; // rax
void **v8; // r15
size_t v9; // rax
size_t v10; // rax
void **v11; // r12
size_t v12; // rax
size_t v13; // rax
void **v14; // rbp
size_t v15; // rax
int v17[15]; // [rsp+Ch] [rbp-3Ch] BYREF

if ( a1[5] >= a1[4] )
return (unsigned int)-1;
v6 = recon_wall_table_find_signal((__int64)a1, a3, v17);
if ( v6 )
return (unsigned int)-4;
v7 = strlen(a2);
v8 = (void **)(a1[7] + 8LL * a1[5]);
*v8 = malloc(v7 + 1);
v9 = strlen(a2);
memcpy(*(void **)(a1[7] + 8LL * a1[5]), a2, v9 + 1);
v10 = strlen(a3);
v11 = (void **)(a1[8] + 8LL * a1[5]);
*v11 = malloc(v10 + 1);
v12 = strlen(a3);
memcpy(*(void **)(a1[8] + 8LL * a1[5]), a3, v12 + 1);
if ( a4 )
{
v13 = strlen(a4);
v14 = (void **)(a1[9] + 8LL * a1[5]);
*v14 = malloc(v13 + 1);
v15 = strlen(a4);
memcpy(*(void **)(a1[9] + 8LL * a1[5]), a4, v15 + 1);
}
else
{
*(_QWORD *)(a1[9] + 8LL * a1[5]) = &unk_66F;
}
++a1[5];
return v6;
}

original_code:
recon_status recon_wall_table_add_alias(recon_wall_table tab, const char* alias, const char* signal, char* transform) {
    int other;
    wall_table* table = (wall_table*) tab;
    if (table->ndefinedaliases >= table->naliases) {
        return -1;
    }
    if (recon_wall_table_find_signal(table, signal, &other) != 0) {
        return -4;
    }
    table->aliases[table->ndefinedaliases] = (char*) malloc(strlen(alias) + 1);
    memcpy(table->aliases[table->ndefinedaliases], alias, strlen(alias) + 1);
    table->aliased[table->ndefinedaliases] = (char*) malloc(strlen(signal) + 1);
    memcpy(table->aliased[table->ndefinedaliases], signal, strlen(signal) + 1);
    if (transform) {
        table->transforms[table->ndefinedaliases] = (char*) malloc(strlen(transform) + 1);
        memcpy(table->transforms[table->ndefinedaliases], transform, strlen(transform) + 1);
    } else {
        table->transforms[table->ndefinedaliases] = "";
    }
    table->ndefinedaliases++;
    return 0;
}

canonical_original_code:
int recon_wall_table_add_alias(void *tab, char *alias, char *signal, char *transform) {
    int other;
    struct wall_table *table = (wall_table*) tab;
    if (table->ndefinedaliases >= table->naliases) {
        return -1;
    }
    if (recon_wall_table_find_signal(table, signal, &other) != 0) {
        return -4;
    }
    table->aliases[table->ndefinedaliases] = (char *) malloc(strlen(alias) + 1);
    memcpy(table->aliases[table->ndefinedaliases], alias, strlen(alias) + 1);
    table->aliased[table->ndefinedaliases] = (char *) malloc(strlen(signal) + 1);
    memcpy(table->aliased[table->ndefinedaliases], signal, strlen(signal) + 1);
    if (transform) {
        table->transforms[table->ndefinedaliases] = (char *) malloc(strlen(transform) + 1);
        memcpy(table->transforms[table->ndefinedaliases], transform, strlen(transform) + 1);
    } else {
        table->transforms[table->ndefinedaliases] = "";
    }
    table->ndefinedaliases++;
    return 0;
}

variable_types:
alias
char *

variable_types:
signal
char *

variable_types:
transform
char *


decompiled_code:
__int64 __fastcall call_finalizer_array(__int64 *a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *a1; a1[2] != i; i -= 16LL )
result = (*(__int64 (__fastcall **)(_QWORD))(i - 16))(*(_QWORD *)(i - 8));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *a1; a1[2] != i; i -= 16LL )
result = (*(__int64 (__fastcall **)(_QWORD))(i - 16))(*(_QWORD *)(i - 8));
return result;
}

original_code:
static inline void call_finalizer_array(msgpack_zone_finalizer_array* fa)
{
 msgpack_zone_finalizer* fin = fa->tail;
 for(; fin != fa->array; --fin) {
  (*(fin-1)->func)((fin-1)->data);
 }
}

canonical_original_code:
static inline void call_finalizer_array(struct msgpack_zone_finalizer_array *fa)
{
 struct msgpack_zone_finalizer *fin = fa->tail;
 for(; fin != fa->array; --fin) {
  (*(fin-1)->func)((fin-1)->data);
 }
}

variable_types: struct msgpack_zone_finalizer_array { struct msgpack_zone_finalizer { void (*func)(void *data); void *data; } *tail; struct msgpack_zone_finalizer *end; struct msgpack_zone_finalizer *array; } *

return_type: void

user_defined_types: struct msgpack_zone_finalizer_array { struct msgpack_zone_finalizer *tail; struct msgpack_zone_finalizer *end; struct msgpack_zone_finalizer *array; }


decompiled_code:
__int64 __fastcall init_chunk_list(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(a2 + 8);
if ( !v2 )
return 0LL;
a1[2] = v2;
*a1 = a2;
a1[1] = v2 + 1;
*v2 = 0LL;
return 1LL;
}

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

v2 = malloc(a2 + 8);
if ( !v2 )
return 0LL;
a1[2] = v2;
*a1 = a2;
a1[1] = v2 + 1;
*v2 = 0LL;
return 1LL;
}

original_code:
static inline _Bool init_chunk_list(msgpack_zone_chunk_list* cl, size_t chunk_size)
{
 msgpack_zone_chunk* chunk = (msgpack_zone_chunk*)malloc(
   sizeof(msgpack_zone_chunk) + chunk_size);
 if(chunk == ((void *)0)) {
  return 0;
 }
 cl->head = chunk;
 cl->free = chunk_size;
 cl->ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk);
 chunk->next = ((void *)0);
 return 1;
}

canonical_original_code:
static inline _Bool init_chunk_list(struct msgpack_zone_chunk_list *cl, unsigned long chunk_size)
{
 struct msgpack_zone_chunk *chunk = (msgpack_zone_chunk*)malloc(
   sizeof(msgpack_zone_chunk) + chunk_size);
 if(chunk == ((void *)0)) {
  return 0;
 }
 cl->head = chunk;
 cl->free = chunk_size;
 cl->ptr = ((char *)chunk) + sizeof(msgpack_zone_chunk);
 chunk->next = ((void *)0);
 return 1;
}

variable_types: struct msgpack_zone_chunk_list { unsigned long free; char *ptr; struct msgpack_zone_chunk { struct msgpack_zone_chunk *next; } *head; } *

user_defined_types: struct msgpack_zone_chunk_list { unsigned long free; char *ptr; struct msgpack_zone_chunk *head; }


decompiled_code:
void __fastcall destroy_finalizer_array(__int64 a1)
{
call_finalizer_array((__int64 *)a1);
free(*(void **)(a1 + 16));
}

original_code:
static inline void destroy_finalizer_array(msgpack_zone_finalizer_array* fa)
{
 call_finalizer_array(fa);
 free(fa->array);
}

canonical_original_code:
static inline void destroy_finalizer_array(struct msgpack_zone_finalizer_array *fa)
{
 call_finalizer_array(fa);
 free(fa->array);
}

user_defined_types: struct msgpack_zone_finalizer { void (*func)(void *data); void *data; }


original_code:
_Bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone,
  void (*func)(void* data), void* data)
{
 msgpack_zone_finalizer* tmp;
 msgpack_zone_finalizer_array* const fa = &zone->finalizer_array;
 const size_t nused = fa->end - fa->array;
 size_t nnext;
 if(nused == 0) {
  nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ?
    72 / sizeof(msgpack_zone_finalizer) : 8;
 } else {
  nnext = nused * 2;
 }
 tmp =
  (msgpack_zone_finalizer*)realloc(fa->array,
    sizeof(msgpack_zone_finalizer) * nnext);
 if(tmp == ((void *)0)) {
  return 0;
 }
 fa->array = tmp;
 fa->end = tmp + nnext;
 fa->tail = tmp + nused;
 fa->tail->func = func;
 fa->tail->data = data;
 ++fa->tail;
 return 1;
}

canonical_original_code:
_Bool msgpack_zone_push_finalizer_expand(struct msgpack_zone *zone, void (*func)(void *data), void *data)
{
 struct msgpack_zone_finalizer *tmp;
 struct msgpack_zone_finalizer_array *fa = &zone->finalizer_array;
 unsigned long nused = fa->end - fa->array;
 unsigned long nnext;
 if(nused == 0) {
  nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ?
    72 / sizeof(msgpack_zone_finalizer) : 8;
 } else {
  nnext = nused * 2;
 }
 tmp =
  (struct msgpack_zone_finalizer *)realloc(fa->array,
    sizeof(msgpack_zone_finalizer) * nnext);
 if(tmp == ((void *)0)) {
  return 0;
 }
 fa->array = tmp;
 fa->end = tmp + nnext;
 fa->tail = tmp + nused;
 fa->tail->func = func;
 fa->tail->data = data;
 ++fa->tail;
 return 1;
}

variable_types: struct msgpack_zone { struct msgpack_zone_chunk_list { unsigned long free; char *ptr; struct msgpack_zone_chunk { struct msgpack_zone_chunk *next; } *head; } chunk_list; struct msgpack_zone_finalizer_array { struct msgpack_zone_finalizer { void (*func)(void *data); void *data; } *tail; struct msgpack_zone_finalizer *end; struct msgpack_zone_finalizer *array; } finalizer_array; unsigned long chunk_size; } *

variable_types:
func
void (*)(void *data)

variable_types:
data
void *

variable_types:
nused
unsigned long

variable_types:
nnext
unsigned long

user_defined_types: struct msgpack_zone { struct msgpack_zone_chunk_list chunk_list; struct msgpack_zone_finalizer_array finalizer_array; unsigned long chunk_size; }


original_code:
_Bool msgpack_zone_is_empty(msgpack_zone* zone)
{
 msgpack_zone_chunk_list* const cl = &zone->chunk_list;
 msgpack_zone_finalizer_array* const fa = &zone->finalizer_array;
 return cl->free == zone->chunk_size && cl->head->next == ((void *)0) &&
  fa->tail == fa->array;
}

canonical_original_code:
_Bool msgpack_zone_is_empty(struct msgpack_zone *zone)
{
 struct msgpack_zone_chunk_list *cl = &zone->chunk_list;
 struct msgpack_zone_finalizer_array *fa = &zone->finalizer_array;
 return cl->free == zone->chunk_size && cl->head->next == ((void *)0) &&
  fa->tail == fa->array;
}

user_defined_types: struct msgpack_zone_chunk { struct msgpack_zone_chunk *next; }


decompiled_code:
void __fastcall msgpack_zone_destroy(__int64 a1)
{
destroy_finalizer_array(a1 + 24);
destroy_chunk_list(a1);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
func4(a1 + 24);
func5(a1);
}

original_code:
void msgpack_zone_destroy(msgpack_zone* zone)
{
 destroy_finalizer_array(&zone->finalizer_array);
 destroy_chunk_list(&zone->chunk_list);
}

canonical_original_code:
void msgpack_zone_destroy(struct msgpack_zone *zone)
{
 destroy_finalizer_array(&zone->finalizer_array);
 destroy_chunk_list(&zone->chunk_list);
}


decompiled_code:
__int64 __fastcall msgpack_zone_init(_QWORD *a1, __int64 a2)
{
unsigned int v2; // ebp

a1[6] = a2;
v2 = init_chunk_list(a1, a2);
if ( (_BYTE)v2 )
init_finalizer_array(a1 + 3);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, __int64 a2)
{
unsigned int v2; // ebp

a1[6] = a2;
v2 = func3(a1, a2);
if ( (_BYTE)v2 )
func0(a1 + 3);
return v2;
}

original_code:
_Bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size)
{
 zone->chunk_size = chunk_size;
 if(!init_chunk_list(&zone->chunk_list, chunk_size)) {
  return 0;
 }
 init_finalizer_array(&zone->finalizer_array);
 return 1;
}

canonical_original_code:
_Bool msgpack_zone_init(struct msgpack_zone *zone, unsigned long chunk_size)
{
 zone->chunk_size = chunk_size;
 if(!init_chunk_list(&zone->chunk_list, chunk_size)) {
  return 0;
 }
 init_finalizer_array(&zone->finalizer_array);
 return 1;
}


decompiled_code:
void __fastcall msgpack_zone_free(void *ptr)
{
if ( ptr )
{
msgpack_zone_destroy((__int64)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
if ( ptr )
{
func9((__int64)ptr);
free(ptr);
}
}

original_code:
void msgpack_zone_free(msgpack_zone* zone)
{
 if(zone == ((void *)0)) { return; }
 msgpack_zone_destroy(zone);
 free(zone);
}

canonical_original_code:
void msgpack_zone_free(struct msgpack_zone *zone)
{
 if(zone == ((void *)0)) { return; }
 msgpack_zone_destroy(zone);
 free(zone);
}


decompiled_code:
__int64 __fastcall msgpack_vrefbuffer_init(_QWORD *a1, __int64 a2, __int64 a3)
{
char *v4; // rax
void *v5; // rbp
_QWORD *v6; // rax
__int64 result; // rax

a1[3] = a3;
a1[4] = a2;
v4 = (char *)malloc(0x40uLL);
if ( !v4 )
return 0LL;
v5 = v4;
*a1 = v4;
a1[1] = v4 + 64;
a1[2] = v4;
v6 = malloc(a3 + 8);
if ( v6 )
{
a1[5] = a3;
a1[6] = v6 + 1;
a1[7] = v6;
*v6 = 0LL;
result = 1LL;
}
else
{
free(v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, __int64 a3)
{
char *v4; // rax
void *v5; // rbp
_QWORD *v6; // rax
__int64 result; // rax

a1[3] = a3;
a1[4] = a2;
v4 = (char *)malloc(0x40uLL);
if ( !v4 )
return 0LL;
v5 = v4;
*a1 = v4;
a1[1] = v4 + 64;
a1[2] = v4;
v6 = malloc(a3 + 8);
if ( v6 )
{
a1[5] = a3;
a1[6] = v6 + 1;
a1[7] = v6;
*v6 = 0LL;
result = 1LL;
}
else
{
free(v5);
result = 0LL;
}
return result;
}

original_code:
_Bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
  size_t ref_size, size_t chunk_size)
{
 size_t nfirst;
 struct iovec* array;
 msgpack_vrefbuffer_chunk* chunk;
 msgpack_vrefbuffer_inner_buffer* ib;
 vbuf->chunk_size = chunk_size;
 vbuf->ref_size = ref_size;
  nfirst = (sizeof(struct iovec) < 72/2) ?
   72 / sizeof(struct iovec) : 8;
 array = (struct iovec*)malloc(
   sizeof(struct iovec) * nfirst);
 if(array == ((void *)0)) {
  return 0;
 }
 vbuf->tail = array;
 vbuf->end = array + nfirst;
 vbuf->array = array;
 chunk = (msgpack_vrefbuffer_chunk*)malloc(
   sizeof(msgpack_vrefbuffer_chunk) + chunk_size);
 if(chunk == ((void *)0)) {
  free(array);
  return 0;
 }
 ib = &vbuf->inner_buffer;
 ib->free = chunk_size;
 ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 ib->head = chunk;
 chunk->next = ((void *)0);
 return 1;
}

canonical_original_code:
_Bool msgpack_vrefbuffer_init(struct msgpack_vrefbuffer *vbuf, unsigned long ref_size, unsigned long chunk_size)
{
 unsigned long nfirst;
 struct iovec *array;
 struct msgpack_vrefbuffer_chunk *chunk;
 struct msgpack_vrefbuffer_inner_buffer *ib;
 vbuf->chunk_size = chunk_size;
 vbuf->ref_size = ref_size;
  nfirst = (sizeof(struct iovec) < 72/2) ?
   72 / sizeof(struct iovec) : 8;
 array = (struct iovec *)malloc(
   sizeof(struct iovec) * nfirst);
 if(array == ((void *)0)) {
  return 0;
 }
 vbuf->tail = array;
 vbuf->end = array + nfirst;
 vbuf->array = array;
 chunk = (struct msgpack_vrefbuffer_chunk *)malloc(
   sizeof(msgpack_vrefbuffer_chunk) + chunk_size);
 if(chunk == ((void *)0)) {
  free(array);
  return 0;
 }
 ib = &vbuf->inner_buffer;
 ib->free = chunk_size;
 ib->ptr = ((char *)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 ib->head = chunk;
 chunk->next = ((void *)0);
 return 1;
}

variable_types: struct msgpack_vrefbuffer { struct iovec { void *iov_base; unsigned long iov_len; } *tail; struct iovec *end; struct iovec *array; unsigned long chunk_size; unsigned long ref_size; struct msgpack_vrefbuffer_inner_buffer { unsigned long free; char *ptr; struct msgpack_vrefbuffer_chunk { struct msgpack_vrefbuffer_chunk *next; } *head; } inner_buffer; } *

variable_types:
nfirst
unsigned long

variable_types: struct msgpack_vrefbuffer_inner_buffer { unsigned long free; char *ptr; struct msgpack_vrefbuffer_chunk { struct msgpack_vrefbuffer_chunk *next; } *head; } *

user_defined_types: struct msgpack_vrefbuffer { struct iovec *tail; struct iovec *end; struct iovec *array; unsigned long chunk_size; unsigned long ref_size; struct msgpack_vrefbuffer_inner_buffer inner_buffer; }

user_defined_types: struct msgpack_vrefbuffer_inner_buffer { unsigned long free; char *ptr; struct msgpack_vrefbuffer_chunk *head; }


decompiled_code:
void __fastcall msgpack_vrefbuffer_destroy(__int64 a1)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)(a1 + 56);
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
while ( v2 );
free(*(void **)(a1 + 16));
}

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

v2 = *(_QWORD **)(a1 + 56);
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
while ( v2 );
free(*(void **)(a1 + 16));
}

original_code:
void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf)
{
 msgpack_vrefbuffer_chunk* c = vbuf->inner_buffer.head;
 while(1) {
  msgpack_vrefbuffer_chunk* n = c->next;
  free(c);
  if(n != ((void *)0)) {
   c = n;
  } else {
   break;
  }
 }
 free(vbuf->array);
}

canonical_original_code:
void msgpack_vrefbuffer_destroy(struct msgpack_vrefbuffer *vbuf)
{
 struct msgpack_vrefbuffer_chunk *c = vbuf->inner_buffer.head;
 while(1) {
  struct msgpack_vrefbuffer_chunk *n = c->next;
  free(c);
  if(n != ((void *)0)) {
   c = n;
  } else {
   break;
  }
 }
 free(vbuf->array);
}

variable_types: struct msgpack_vrefbuffer_chunk { struct msgpack_vrefbuffer_chunk *next; } *

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }


decompiled_code:
__int64 __fastcall msgpack_vrefbuffer_clear(__int64 a1)
{
_QWORD *v2; // rbx
void *v3; // rdi
_QWORD *v4; // rax
__int64 result; // rax

v2 = **(_QWORD ***)(a1 + 56);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
v4 = *(_QWORD **)(a1 + 56);
*v4 = 0LL;
*(_QWORD *)(a1 + 40) = *(_QWORD *)(a1 + 24);
*(_QWORD *)(a1 + 48) = v4 + 1;
result = *(_QWORD *)(a1 + 16);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vbuf)
{
 msgpack_vrefbuffer_inner_buffer* ib;
 msgpack_vrefbuffer_chunk* chunk;
 msgpack_vrefbuffer_chunk* c = vbuf->inner_buffer.head->next;
 msgpack_vrefbuffer_chunk* n;
 while(c != ((void *)0)) {
  n = c->next;
  free(c);
  c = n;
 }
 ib = &vbuf->inner_buffer;
 chunk = ib->head;
 chunk->next = ((void *)0);
 ib->free = vbuf->chunk_size;
 ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 vbuf->tail = vbuf->array;
}

canonical_original_code:
void msgpack_vrefbuffer_clear(struct msgpack_vrefbuffer *vbuf)
{
 struct msgpack_vrefbuffer_inner_buffer *ib;
 struct msgpack_vrefbuffer_chunk *chunk;
 struct msgpack_vrefbuffer_chunk *c = vbuf->inner_buffer.head->next;
 struct msgpack_vrefbuffer_chunk *n;
 while(c != ((void *)0)) {
  n = c->next;
  free(c);
  c = n;
 }
 ib = &vbuf->inner_buffer;
 chunk = ib->head;
 chunk->next = ((void *)0);
 ib->free = vbuf->chunk_size;
 ib->ptr = ((char *)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 vbuf->tail = vbuf->array;
}

user_defined_types: struct msgpack_vrefbuffer_chunk { struct msgpack_vrefbuffer_chunk *next; }


decompiled_code:
__int64 __fastcall msgpack_vrefbuffer_append_ref(char **a1, __int64 a2, unsigned int a3)
{
char *v5; // rax
char *v7; // rdi
signed __int64 v8; // rbp
size_t v9; // r14
char *v10; // rax

v5 = *a1;
if ( *a1 != a1[1] )
goto LABEL_2;
v7 = a1[2];
v8 = v5 - v7;
v9 = 32 * ((v5 - v7) >> 4);
v10 = (char *)realloc(v7, v9);
if ( v10 )
{
a1[2] = v10;
a1[1] = &v10[v9];
*a1 = &v10[v8];
LABEL_2:
*(_QWORD *)*a1 = a2;
*((_QWORD *)*a1 + 1) = a3;
*a1 += 16;
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
  const char* buf, unsigned int len)
{
 if(vbuf->tail == vbuf->end) {
  const size_t nused = vbuf->tail - vbuf->array;
  const size_t nnext = nused * 2;
  struct iovec* nvec = (struct iovec*)realloc(
    vbuf->array, sizeof(struct iovec)*nnext);
  if(nvec == ((void *)0)) {
   return -1;
  }
  vbuf->array = nvec;
  vbuf->end = nvec + nnext;
  vbuf->tail = nvec + nused;
 }
 vbuf->tail->iov_base = (char*)buf;
 vbuf->tail->iov_len = len;
 ++vbuf->tail;
 return 0;
}

canonical_original_code:
int msgpack_vrefbuffer_append_ref(struct msgpack_vrefbuffer *vbuf, char *buf, unsigned int len)
{
 if(vbuf->tail == vbuf->end) {
  unsigned long nused = vbuf->tail - vbuf->array;
  unsigned long nnext = nused * 2;
  struct iovec *nvec = (struct iovec*)realloc(
    vbuf->array, sizeof(struct iovec)*nnext);
  if(nvec == ((void *)0)) {
   return -1;
  }
  vbuf->array = nvec;
  vbuf->end = nvec + nnext;
  vbuf->tail = nvec + nused;
 }
 vbuf->tail->iov_base = (char *)buf;
 vbuf->tail->iov_len = len;
 ++vbuf->tail;
 return 0;
}

variable_types:
buf
char *

variable_types:
len
unsigned int

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } *


original_code:
int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf,
  const char* buf, unsigned int len)
{
 msgpack_vrefbuffer_chunk* chunk;
 char* m;
 msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer;
 if(ib->free < len) {
  size_t sz = vbuf->chunk_size;
  if(sz < len) {
   sz = len;
  }
  chunk = (msgpack_vrefbuffer_chunk*)malloc(
    sizeof(msgpack_vrefbuffer_chunk) + sz);
  if(chunk == ((void *)0)) {
   return -1;
  }
  chunk->next = ib->head;
  ib->head = chunk;
  ib->free = sz;
  ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 }
 m = ib->ptr;
 memcpy(m, buf, len);
 ib->free -= len;
 ib->ptr += len;
 if(vbuf->tail != vbuf->array && m ==
   (const char*)((vbuf->tail-1)->iov_base) + (vbuf->tail-1)->iov_len) {
  (vbuf->tail-1)->iov_len += len;
  return 0;
 } else {
  return msgpack_vrefbuffer_append_ref(vbuf, m, len);
 }
}

canonical_original_code:
int msgpack_vrefbuffer_append_copy(struct msgpack_vrefbuffer *vbuf, char *buf, unsigned int len)
{
 struct msgpack_vrefbuffer_chunk *chunk;
 char *m;
 struct msgpack_vrefbuffer_inner_buffer *ib = &vbuf->inner_buffer;
 if(ib->free < len) {
  unsigned long sz = vbuf->chunk_size;
  if(sz < len) {
   sz = len;
  }
  chunk = (struct msgpack_vrefbuffer_chunk *)malloc(
    sizeof(msgpack_vrefbuffer_chunk) + sz);
  if(chunk == ((void *)0)) {
   return -1;
  }
  chunk->next = ib->head;
  ib->head = chunk;
  ib->free = sz;
  ib->ptr = ((char *)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 }
 m = ib->ptr;
 memcpy(m, buf, len);
 ib->free -= len;
 ib->ptr += len;
 if(vbuf->tail != vbuf->array && m ==
   (char *)((vbuf->tail-1)->iov_base) + (vbuf->tail-1)->iov_len) {
  (vbuf->tail-1)->iov_len += len;
  return 0;
 } else {
  return msgpack_vrefbuffer_append_ref(vbuf, m, len);
 }
}

variable_types:
m
char *

variable_types:
sz
unsigned long


original_code:
int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
{
    size_t nused;
 struct iovec* nvec;
 msgpack_vrefbuffer_inner_buffer* ib;
 msgpack_vrefbuffer_inner_buffer* toib;
 msgpack_vrefbuffer_chunk* last;
 size_t sz = vbuf->chunk_size;
 msgpack_vrefbuffer_chunk* empty = (msgpack_vrefbuffer_chunk*)malloc(
   sizeof(msgpack_vrefbuffer_chunk) + sz);
 if(empty == ((void *)0)) {
  return -1;
 }
 empty->next = ((void *)0);
    nused = vbuf->tail - vbuf->array;
 if(to->tail + nused < vbuf->end) {
  const size_t tosize = to->tail - to->array;
  const size_t reqsize = nused + tosize;
  size_t nnext = (to->end - to->array) * 2;
  while(nnext < reqsize) {
   nnext *= 2;
  }
  nvec = (struct iovec*)realloc(
    to->array, sizeof(struct iovec)*nnext);
  if(nvec == ((void *)0)) {
   free(empty);
   return -1;
  }
  to->array = nvec;
  to->end = nvec + nnext;
  to->tail = nvec + tosize;
 }
 memcpy(to->tail, vbuf->array, sizeof(struct iovec)*nused);
 to->tail += nused;
 vbuf->tail = vbuf->array;
 ib = &vbuf->inner_buffer;
 toib = &to->inner_buffer;
 last = ib->head;
 while(last->next != ((void *)0)) {
  last = last->next;
 }
 last->next = toib->head;
 toib->head = ib->head;
 if(toib->free < ib->free) {
  toib->free = ib->free;
  toib->ptr = ib->ptr;
 }
 ib->head = empty;
 ib->free = sz;
 ib->ptr = ((char*)empty) + sizeof(msgpack_vrefbuffer_chunk);
 return 0;
}

canonical_original_code:
int msgpack_vrefbuffer_migrate(struct msgpack_vrefbuffer *vbuf, struct msgpack_vrefbuffer *to)
{
    unsigned long nused;
 struct iovec *nvec;
 struct msgpack_vrefbuffer_inner_buffer *ib;
 struct msgpack_vrefbuffer_inner_buffer *toib;
 struct msgpack_vrefbuffer_chunk *last;
 unsigned long sz = vbuf->chunk_size;
 struct msgpack_vrefbuffer_chunk *empty = (msgpack_vrefbuffer_chunk*)malloc(
   sizeof(msgpack_vrefbuffer_chunk) + sz);
 if(empty == ((void *)0)) {
  return -1;
 }
 empty->next = ((void *)0);
    nused = vbuf->tail - vbuf->array;
 if(to->tail + nused < vbuf->end) {
  unsigned long tosize = to->tail - to->array;
  unsigned long reqsize = nused + tosize;
  unsigned long nnext = (to->end - to->array) * 2;
  while(nnext < reqsize) {
   nnext *= 2;
  }
  nvec = (struct iovec *)realloc(
    to->array, sizeof(struct iovec)*nnext);
  if(nvec == ((void *)0)) {
   free(empty);
   return -1;
  }
  to->array = nvec;
  to->end = nvec + nnext;
  to->tail = nvec + tosize;
 }
 memcpy(to->tail, vbuf->array, sizeof(struct iovec)*nused);
 to->tail += nused;
 vbuf->tail = vbuf->array;
 ib = &vbuf->inner_buffer;
 toib = &to->inner_buffer;
 last = ib->head;
 while(last->next != ((void *)0)) {
  last = last->next;
 }
 last->next = toib->head;
 toib->head = ib->head;
 if(toib->free < ib->free) {
  toib->free = ib->free;
  toib->ptr = ib->ptr;
 }
 ib->head = empty;
 ib->free = sz;
 ib->ptr = ((char *)empty) + sizeof(msgpack_vrefbuffer_chunk);
 return 0;
}

variable_types:
to
struct msgpack_vrefbuffer *

variable_types:
tosize
unsigned long

variable_types:
reqsize
unsigned long


decompiled_code:
__int64 __fastcall recon_transform_create_none(_QWORD *a1)
{
*a1 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
*a1 = 0LL;
return 0LL;
}

original_code:
recon_status recon_transform_create_none(char** t) {
    *t = ((void *)0);
    return 0;
}

canonical_original_code:
int recon_transform_create_none(char **t) {
    *t = ((void *)0);
    return 0;
}

variable_types:
t
char **


decompiled_code:
__int64 __fastcall recon_transform_create_inverse(_QWORD *a1)
{
_BYTE *v1; // rax

v1 = malloc(4uLL);
*a1 = v1;
*(_WORD *)v1 = 28265;
v1[2] = 118;
v1[3] = 0;
return 0LL;
}

original_code:
recon_status recon_transform_create_inverse(char** t) {
    *t = (char*) malloc(strlen("inv") + 1);
    memcpy(*t, "inv", strlen("inv"));
    (*t)[strlen("inv")] = '\0';
    return 0;
}

canonical_original_code:
int recon_transform_create_inverse(char **t) {
    *t = (char *) malloc(strlen("inv") + 1);
    memcpy(*t, "inv", strlen("inv"));
    (*t)[strlen("inv")] = '\0';
    return 0;
}


decompiled_code:
__int64 __fastcall recon_transform_create_affine(_QWORD *a1, double a2, double a3)
{
char *v3; // rbp
size_t v5; // rax
void *v6; // rbx
size_t v7; // rax

v3 = (char *)malloc(0x2BuLL);
if ( a2 == 1.0 && a3 == 0.0 )
return recon_transform_create_none(a1);
if ( a2 == -1.0 && a3 == 0.0 )
return recon_transform_create_inverse(a1);
sprintf(v3, "aff(%.*g,%.*g)", 16, a2, 16, a3);
v5 = strlen(v3);
v6 = malloc(v5 + 1);
*a1 = v6;
v7 = strlen(v3);
memcpy(v6, v3, v7 + 1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, double a2, double a3)
{
char *v3; // rbp
size_t v5; // rax
void *v6; // rbx
size_t v7; // rax

v3 = (char *)malloc(0x2BuLL);
if ( a2 == 1.0 && a3 == 0.0 )
return func0(a1);
if ( a2 == -1.0 && a3 == 0.0 )
return func1(a1);
sprintf(v3, "aff(%.*g,%.*g)", 16, a2, 16, a3);
v5 = strlen(v3);
v6 = malloc(v5 + 1);
*a1 = v6;
v7 = strlen(v3);
memcpy(v6, v3, v7 + 1);
return 0LL;
}

original_code:
recon_status recon_transform_create_affine(char** t, double scale, double offset) {
    int max_sig_digits = 16;
    char* transform_string;
    transform_string = (char*) malloc(strlen("aff(-.,-.)") + 2 * max_sig_digits + 1);
    if (scale == 1.0 && offset == 0.0) {
        return recon_transform_create_none(t);
    }
    if (scale == -1.0 && offset == 0.0) {
        return recon_transform_create_inverse(t);
    }
    sprintf(transform_string, "aff(%.*g,%.*g)", max_sig_digits, scale, max_sig_digits, offset);
    *t = (char*) malloc(strlen(transform_string) + 1);
    memcpy(*t, transform_string, strlen(transform_string) + 1);
    return 0;
}

canonical_original_code:
int recon_transform_create_affine(char **t, double scale, double offset) {
    int max_sig_digits = 16;
    char *transform_string;
    transform_string = (char *) malloc(strlen("aff(-.,-.)") + 2 * max_sig_digits + 1);
    if (scale == 1.0 && offset == 0.0) {
        return recon_transform_create_none(t);
    }
    if (scale == -1.0 && offset == 0.0) {
        return recon_transform_create_inverse(t);
    }
    sprintf(transform_string, "aff(%.*g,%.*g)", max_sig_digits, scale, max_sig_digits, offset);
    *t = (char *) malloc(strlen(transform_string) + 1);
    memcpy(*t, transform_string, strlen(transform_string) + 1);
    return 0;
}

variable_types: scale double

variable_types: offset double


decompiled_code:
__int64 __fastcall recon_transform_apply_double(const char *a1, double *a2, double a3)
{
double v4; // [rsp+0h] [rbp-28h] BYREF
double v5; // [rsp+8h] [rbp-20h] BYREF

if ( !a1 )
{
LABEL_5:
*a2 = a3;
return 0LL;
}
if ( strcmp(a1, "inv") )
{
if ( (unsigned int)_isoc99_sscanf(a1, "aff(%lf,%lf)", &v5, &v4) == 2 )
{
*a2 = (a3 + v4) * v5;
return 0LL;
}
goto LABEL_5;
}
*(_QWORD *)a2 = *(_QWORD *)&a3 ^ LC5;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, double *a2, double a3)
{
double v4; // [rsp+0h] [rbp-28h] BYREF
double v5; // [rsp+8h] [rbp-20h] BYREF

if ( !a1 )
{
LABEL_5:
*a2 = a3;
return 0LL;
}
if ( strcmp(a1, "inv") )
{
if ( (unsigned int)_isoc99_sscanf(a1, "aff(%lf,%lf)", &v5, &v4) == 2 )
{
*a2 = (a3 + v4) * v5;
return 0LL;
}
goto LABEL_5;
}
*(_QWORD *)a2 = *(_QWORD *)&a3 ^ LC5;
return 0LL;
}

original_code:
recon_status recon_transform_apply_double(char* transform, double in, double* out) {
    double scale;
    double offset;
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            *out = in * -1.0;
            return 0;
        }
        if (sscanf(transform, "aff(%lf,%lf)", &scale, &offset) == 2) {
            *out = (in + offset) * scale;
            return 0;
        }
    }
    *out = in;
    return 0;
}

canonical_original_code:
int recon_transform_apply_double(char *transform, double in, double *out) {
    double scale;
    double offset;
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            *out = in * -1.0;
            return 0;
        }
        if (sscanf(transform, "aff(%lf,%lf)", &scale, &offset) == 2) {
            *out = (in + offset) * scale;
            return 0;
        }
    }
    *out = in;
    return 0;
}

variable_types:
transform
char *

variable_types: in double

variable_types:
out
double *


decompiled_code:
__int64 __fastcall recon_transform_apply_int(const char *a1, int a2, int *a3)
{
int v3; // eax

v3 = a2;
if ( a1 && !strcmp(a1, "inv") )
v3 = -a2;
*a3 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, int a2, int *a3)
{
int v3; // eax

v3 = a2;
if ( a1 && !strcmp(a1, "inv") )
v3 = -a2;
*a3 = v3;
return 0LL;
}

original_code:
recon_status recon_transform_apply_int(char* transform, int in, int* out) {
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            *out = in * -1;
            return 0;
        }
    }
    *out = in;
    return 0;
}

canonical_original_code:
int recon_transform_apply_int(char *transform, int in, int *out) {
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            *out = in * -1;
            return 0;
        }
    }
    *out = in;
    return 0;
}

variable_types: in int

variable_types:
out
int *


decompiled_code:
__int64 __fastcall recon_transform_apply_boolean(const char *a1, bool a2, bool *a3)
{
if ( a1 && !strcmp(a1, "inv") )
*a3 = !a2;
else
*a3 = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, bool a2, bool *a3)
{
if ( a1 && !strcmp(a1, "inv") )
*a3 = !a2;
else
*a3 = a2;
return 0LL;
}

original_code:
recon_status recon_transform_apply_boolean(char* transform, recon_booleantype in, recon_booleantype* out) {
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            if (in) {
                *out = 0;;
            } else {
                *out = 1;;
            }
            return 0;
        }
    }
    *out = in;
    return 0;
}

canonical_original_code:
int recon_transform_apply_boolean(char *transform, unsigned char in, unsigned char *out) {
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            if (in) {
                *out = 0;;
            } else {
                *out = 1;;
            }
            return 0;
        }
    }
    *out = in;
    return 0;
}

variable_types:
in
unsigned char

variable_types:
out
unsigned char *


original_code:
uint32_t recon_util_bytes_to_int(unsigned char* bytes) {
    return (((uint32_t) bytes[0]) << 24) + (((uint32_t) bytes[1]) << 16) + (((uint32_t) bytes[2]) << 8) + (uint32_t) bytes[3];
}

canonical_original_code:
unsigned int recon_util_bytes_to_int(unsigned char *bytes) {
    return (((unsigned int) bytes[0]) << 24) + (((unsigned int) bytes[1]) << 16) + (((unsigned int) bytes[2]) << 8) + (unsigned int) bytes[3];
}

variable_types:
bytes
unsigned char *

return_type: unsigned int


decompiled_code:
void recon_util_tic()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void recon_util_tic(void** t) {
}

canonical_original_code:
void recon_util_tic(void **t) {
}

variable_types:
t
void **


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

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

original_code:
long recon_util_toc(void* t) {
    return 0L;
}

canonical_original_code:
long recon_util_toc(void *t) {
    return 0L;
}

variable_types:
t
void *

return_type: long


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

if ( !a1 )
return 1;
v1 = 1;
do
{
a1 /= 10;
++v1;
}
while ( a1 );
return v1;
}

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

if ( !a1 )
return 1;
v1 = 1;
do
{
a1 /= 10;
++v1;
}
while ( a1 );
return v1;
}

original_code:
int recon_util_digits(int n) {
    int count = 1;
    while (n != 0) {
        n /= 10;
        ++count;
    }
    return count;
}

variable_types: n int

variable_types: count int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
atexit((void (*)(void))&sudokuExit);
printWelcomeScreen(&sudokuExit, argv);
printf("\x1B[2J");
printMenu();
return 0;
}

original_code:
int main(int argc, char** argv) {
    atexit(sudokuExit);
    printWelcomeScreen();
    printf("\033[2J");
    printMenu();
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    atexit(sudokuExit);
    printWelcomeScreen();
    printf("\033[2J");
    printMenu();
    return (0);
}

variable_types: argc int

variable_types:
argv
char **


repo: harshasrisri/tomasulo

decompiled_code:
__int64 create_arch()
{
void *v0; // r13
void *v1; // r14
void *v2; // r12
void *v3; // rbp
void *v4; // rbx
void *v5; // rdx
int v6; // ecx
__int64 result; // rax
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
__int64 v11; // rdx
__int64 v12; // rdx
__int64 v13; // rdx

v0 = malloc(0xA0uLL);
add_fp_rs = (__int64)v0;
v1 = malloc(0xA0uLL);
add_int_rs = (__int64)v1;
v2 = malloc(0x50uLL);
mul_fp_rs = (__int64)v2;
v3 = malloc(0x50uLL);
mul_int_rs = (__int64)v3;
v4 = malloc(0x50uLL);
ld_rs = (__int64)v4;
v5 = malloc(0x50uLL);
sd_rs = (__int64)v5;
if ( v4 == 0LL || v3 == 0LL || v2 == 0LL || v0 == 0LL || v1 == 0LL || !v5 )
{
fprintf(stderr, "[FATAL] (%s:%d) Error creating the architecture\n", "tomasulo.c", 29LL);
exit(-1);
}
v6 = 1;
for ( result = 0LL; ; result += 40LL )
{
*(_DWORD *)(add_fp_rs + result) = 1;
v8 = add_fp_rs + result;
*(_DWORD *)(v8 + 32) = 0;
*(_QWORD *)(v8 + 24) = 0LL;
*(_QWORD *)(v8 + 16) = 0LL;
*(_DWORD *)(add_int_rs + result) = 1;
v9 = add_int_rs + result;
*(_DWORD *)(v9 + 32) = 0;
*(_QWORD *)(v9 + 24) = 0LL;
*(_QWORD *)(v9 + 16) = 0LL;
if ( v6 - 1 > 1 )
break;
*(_DWORD *)(mul_fp_rs + result) = 1;
v10 = mul_fp_rs + result;
*(_DWORD *)(v10 + 32) = 0;
*(_QWORD *)(v10 + 24) = 0LL;
*(_QWORD *)(v10 + 16) = 0LL;
*(_DWORD *)(mul_int_rs + result) = 1;
v11 = mul_int_rs + result;
*(_DWORD *)(v11 + 32) = 0;
*(_QWORD *)(v11 + 24) = 0LL;
*(_QWORD *)(v11 + 16) = 0LL;
*(_DWORD *)(ld_rs + result) = 1;
v12 = ld_rs + result;
*(_DWORD *)(v12 + 32) = 0;
*(_QWORD *)(v12 + 24) = 0LL;
*(_QWORD *)(v12 + 16) = 0LL;
*(_DWORD *)(sd_rs + result) = 1;
v13 = sd_rs + result;
*(_DWORD *)(v13 + 32) = 0;
*(_QWORD *)(v13 + 24) = 0LL;
*(_QWORD *)(v13 + 16) = 0LL;
LABEL_6:
++v6;
}
if ( v6 <= 3 )
goto LABEL_6;
return result;
}

original_code:
void create_arch()
{
 int i;
 add_fp_rs = malloc (4 * sizeof (RS));
 add_int_rs = malloc (4 * sizeof (RS));
 mul_fp_rs = malloc (2 * sizeof (RS));
 mul_int_rs = malloc (2 * sizeof (RS));
 ld_rs = malloc (2 * sizeof (RS));
 sd_rs = malloc (2 * sizeof (RS));
 if(!add_fp_rs || !add_int_rs || !mul_fp_rs || !mul_int_rs || !ld_rs || !sd_rs){
  do {fprintf(stderr, "[FATAL] (%s:%d) " "Error creating the architecture\n", "tomasulo.c", 29); exit(-1); } while (0);
 }
 for (i = 0; i < ((((2)>(2)?(2):(2)))>(((((4)>(2)?(4):(2)))>(((4)>(2)?(4):(2)))?(((4)>(2)?(4):(2))):(((4)>(2)?(4):(2)))))?(((2)>(2)?(2):(2))):(((((4)>(2)?(4):(2)))>(((4)>(2)?(4):(2)))?(((4)>(2)?(4):(2))):(((4)>(2)?(4):(2)))))); i++) {
  if (i < 4) {
   add_fp_rs[i].status = AVAILABLE;
   add_fp_rs[i].timer = 0;
   add_fp_rs[i].qj = add_fp_rs[i].qk = ((void *)0);
  }
  if (i < 4) {
   add_int_rs[i].status = AVAILABLE;
   add_int_rs[i].timer = 0;
   add_int_rs[i].qj = add_int_rs[i].qk = ((void *)0);
  }
  if (i < 2) {
   mul_fp_rs[i].status = AVAILABLE;
   mul_fp_rs[i].timer = 0;
   mul_fp_rs[i].qj = mul_fp_rs[i].qk = ((void *)0);
  }
  if (i < 2) {
   mul_int_rs[i].status = AVAILABLE;
   mul_int_rs[i].timer = 0;
   mul_int_rs[i].qj = mul_int_rs[i].qk = ((void *)0);
  }
  if (i < 2) {
   ld_rs[i].status = AVAILABLE;
   ld_rs[i].timer = 0;
   ld_rs[i].qj = ld_rs[i].qk = ((void *)0);
  }
  if (i < 2) {
   sd_rs[i].status = AVAILABLE;
   sd_rs[i].timer = 0;
   sd_rs[i].qj = sd_rs[i].qk = ((void *)0);
  }
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall dep_lookup(char *s2)
{
__int64 v1; // rbx
unsigned __int64 v2; // r12

if ( instr_proc - 1 <= 0 )
return 0LL;
v1 = iq + ((__int64)(instr_proc - 1) << 6);
v2 = v1 - 64 - ((unsigned __int64)(unsigned int)(instr_proc - 2) << 6);
while ( strcmp(*(const char **)(v1 + 8), s2) )
{
v1 -= 64LL;
if ( v1 == v2 )
return 0LL;
}
return *(_QWORD *)(v1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2)
{
__int64 v1; // rbx
unsigned __int64 v2; // r12

if ( instr_proc - 1 <= 0 )
return 0LL;
v1 = iq + ((__int64)(instr_proc - 1) << 6);
v2 = v1 - 64 - ((unsigned __int64)(unsigned int)(instr_proc - 2) << 6);
while ( strcmp(*(const char **)(v1 + 8), s2) )
{
v1 -= 64LL;
if ( v1 == v2 )
return 0LL;
}
return *(_QWORD *)(v1 + 40);
}

original_code:
RS *dep_lookup(char *src)
{
 int instr = instr_proc-1;
 while(instr>0){
  if(!strcmp(iq[instr].dest,src)){
   return iq[instr].cur;
  }
  instr--;
 }
 return ((void *)0);
}

canonical_original_code:
struct resrv_stn *dep_lookup(char *src)
{
 int instr = instr_proc-1;
 while(instr>0){
  if(!strcmp(iq[instr].dest,src)){
   return iq[instr].cur;
  }
  instr--;
 }
 return ((void *)0);
}

variable_types:
src
char *

variable_types: instr int

return_type: struct resrv_stn { enum rs_status { UNKNOWN=0, AVAILABLE=1, BUSY=2, RESULT_READY=3 } status; struct Instruction { char *opcd; char *dest; char *src1; char *src2; int num_ops; int latency; struct resrv_stn *cur; unsigned int issue_time; unsigned int exec_time; unsigned int write_time; } *instr; struct resrv_stn *qj; struct resrv_stn *qk; int timer; } *

user_defined_types: struct resrv_stn { enum rs_status status; struct Instruction *instr; struct resrv_stn *qj; struct resrv_stn *qk; int timer; }


execute

decompiled_code:
void execute()
{
update_rs_exec(0, 4);
update_rs_exec(1, 2);
update_rs_exec(2, 4);
update_rs_exec(3, 2);
update_rs_exec(4, 2);
update_rs_exec(5, 2);
}

original_code:
void execute()
{
  update_rs_exec(0,4);
  update_rs_exec(1,2);
 update_rs_exec(2,4);
 update_rs_exec(3,2);
 update_rs_exec(4,2);
 update_rs_exec(5,2);
}


decompiled_code:
void write_back()
{
update_rs_write(0, 4);
update_rs_write(1, 2);
update_rs_write(2, 4);
update_rs_write(3, 2);
update_rs_write(4, 2);
update_rs_write(5, 2);
}

original_code:
void write_back()
{
  update_rs_write(0,4);
  update_rs_write(1,2);
 update_rs_write(2,4);
 update_rs_write(3,2);
 update_rs_write(4,2);
 update_rs_write(5,2);
}


issue

decompiled_code:
__int64 __fastcall issue(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5, __int64 a6)
{
__int64 v6; // rbx
_DWORD *v7; // rdx
__int64 result; // rax
__int64 v9; // rbp
char *v10; // rdi
char *v11; // rdi

v6 = iq + ((__int64)instr_proc << 6);
if ( !strcmp("ADD", *(const char **)v6) || !strcmp("SUB", *(const char **)v6) )
{
a6 = add_int_rs;
a5 = 4;
}
else if ( !strcmp("ADDD", *(const char **)v6) || !strcmp("SUBD", *(const char **)v6) )
{
a6 = mul_int_rs;
a5 = 4;
}
else if ( !strcmp("MUL", *(const char **)v6) || !strcmp("DIV", *(const char **)v6) )
{
a6 = add_fp_rs;
a5 = 2;
}
else if ( !strcmp("MULD", *(const char **)v6) || !strcmp("DIVD", *(const char **)v6) )
{
a6 = mul_fp_rs;
a5 = 2;
}
else if ( !strcmp("LD", *(const char **)v6) )
{
a6 = ld_rs;
a5 = 2;
}
else if ( !strcmp("SD", *(const char **)v6) )
{
a6 = sd_rs;
a5 = 2;
}
v7 = (_DWORD *)a6;
result = 0LL;
while ( *v7 != 1 )
{
result = (unsigned int)(result + 1);
v7 += 10;
if ( a5 == (_DWORD)result )
return result;
}
if ( a5 > (int)result )
{
v9 = a6 + 40LL * (int)result;
*(_DWORD *)v9 = 2;
*(_QWORD *)(v9 + 8) = v6;
v10 = *(char **)(v6 + 16);
if ( v10 )
*(_QWORD *)(v9 + 16) = dep_lookup(v10);
v11 = *(char **)(v6 + 24);
if ( v11 )
*(_QWORD *)(v9 + 24) = dep_lookup(v11);
result = (unsigned int)cycles;
*(_DWORD *)(v6 + 48) = cycles;
++instr_proc;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5, __int64 a6)
{
__int64 v6; // rbx
_DWORD *v7; // rdx
__int64 result; // rax
__int64 v9; // rbp
char *v10; // rdi
char *v11; // rdi

v6 = iq + ((__int64)instr_proc << 6);
if ( !strcmp("ADD", *(const char **)v6) || !strcmp("SUB", *(const char **)v6) )
{
a6 = add_int_rs;
a5 = 4;
}
else if ( !strcmp("ADDD", *(const char **)v6) || !strcmp("SUBD", *(const char **)v6) )
{
a6 = mul_int_rs;
a5 = 4;
}
else if ( !strcmp("MUL", *(const char **)v6) || !strcmp("DIV", *(const char **)v6) )
{
a6 = add_fp_rs;
a5 = 2;
}
else if ( !strcmp("MULD", *(const char **)v6) || !strcmp("DIVD", *(const char **)v6) )
{
a6 = mul_fp_rs;
a5 = 2;
}
else if ( !strcmp("LD", *(const char **)v6) )
{
a6 = ld_rs;
a5 = 2;
}
else if ( !strcmp("SD", *(const char **)v6) )
{
a6 = sd_rs;
a5 = 2;
}
v7 = (_DWORD *)a6;
result = 0LL;
while ( *v7 != 1 )
{
result = (unsigned int)(result + 1);
v7 += 10;
if ( a5 == (_DWORD)result )
return result;
}
if ( a5 > (int)result )
{
v9 = a6 + 40LL * (int)result;
*(_DWORD *)v9 = 2;
*(_QWORD *)(v9 + 8) = v6;
v10 = *(char **)(v6 + 16);
if ( v10 )
*(_QWORD *)(v9 + 16) = func3(v10);
v11 = *(char **)(v6 + 24);
if ( v11 )
*(_QWORD *)(v9 + 24) = func3(v11);
result = (unsigned int)cycles;
*(_DWORD *)(v6 + 48) = cycles;
++instr_proc;
}
return result;
}

original_code:
void issue () {
 int i, rs_count;
 Instruction *curr;
 RS *rs_type, *rs;
 curr = &iq[instr_proc];
 if (!(strcmp ("ADD", curr->opcd)) || !(strcmp ("SUB", curr->opcd))) {
  rs_count = 4; rs_type = add_int_rs;
 }
 else if (!(strcmp ("ADDD", curr->opcd)) || !(strcmp ("SUBD", curr->opcd))) {
  rs_count = 4; rs_type = mul_int_rs;
 }
 else if (!(strcmp ("MUL", curr->opcd)) || !(strcmp ("DIV", curr->opcd))) {
  rs_count = 2; rs_type = add_fp_rs;
 }
 else if (!(strcmp ("MULD", curr->opcd)) || !(strcmp ("DIVD", curr->opcd))) {
  rs_count = 2; rs_type = mul_fp_rs;
 }
 else if (!(strcmp ("LD", curr->opcd))) {
  rs_count = 2; rs_type = ld_rs;
 }
 else if (!(strcmp ("SD", curr->opcd))) {
  rs_count = 2; rs_type = sd_rs;
 }
 for (i = 0; i < rs_count; i++)
  if (rs_type[i].status == AVAILABLE)
   break;
 if (i >= rs_count) return;
 rs = &rs_type[i];
 rs->status = BUSY;
 rs->instr = curr;
 if (curr->src1)
  rs->qj = dep_lookup (curr->src1);
 if (curr->src2)
  rs->qk = dep_lookup (curr->src2);
 curr->issue_time = cycles;
 instr_proc++;
}

canonical_original_code:
void issue() {
 int i; int rs_count;
 struct Instruction *curr;
 struct resrv_stn *rs_type; struct resrv_stn *rs;
 curr = &iq[instr_proc];
 if (!(strcmp ("ADD", curr->opcd)) || !(strcmp ("SUB", curr->opcd))) {
  rs_count = 4; rs_type = add_int_rs;
 }
 else if (!(strcmp ("ADDD", curr->opcd)) || !(strcmp ("SUBD", curr->opcd))) {
  rs_count = 4; rs_type = mul_int_rs;
 }
 else if (!(strcmp ("MUL", curr->opcd)) || !(strcmp ("DIV", curr->opcd))) {
  rs_count = 2; rs_type = add_fp_rs;
 }
 else if (!(strcmp ("MULD", curr->opcd)) || !(strcmp ("DIVD", curr->opcd))) {
  rs_count = 2; rs_type = mul_fp_rs;
 }
 else if (!(strcmp ("LD", curr->opcd))) {
  rs_count = 2; rs_type = ld_rs;
 }
 else if (!(strcmp ("SD", curr->opcd))) {
  rs_count = 2; rs_type = sd_rs;
 }
 for (i = 0; i < rs_count; i++)
  if (rs_type[i].status == AVAILABLE)
   break;
 if (i >= rs_count) return;
 rs = &rs_type[i];
 rs->status = BUSY;
 rs->instr = curr;
 if (curr->src1)
  rs->qj = dep_lookup (curr->src1);
 if (curr->src2)
  rs->qk = dep_lookup (curr->src2);
 curr->issue_time = cycles;
 instr_proc++;
}

variable_types: struct Instruction { char *opcd; char *dest; char *src1; char *src2; int num_ops; int latency; struct resrv_stn { enum rs_status { UNKNOWN=0, AVAILABLE=1, BUSY=2, RESULT_READY=3 } status; struct Instruction *instr; struct resrv_stn *qj; struct resrv_stn *qk; int timer; } *cur; unsigned int issue_time; unsigned int exec_time; unsigned int write_time; } *

variable_types: struct resrv_stn { enum rs_status { UNKNOWN=0, AVAILABLE=1, BUSY=2, RESULT_READY=3 } status; struct Instruction { char *opcd; char *dest; char *src1; char *src2; int num_ops; int latency; struct resrv_stn *cur; unsigned int issue_time; unsigned int exec_time; unsigned int write_time; } *instr; struct resrv_stn *qj; struct resrv_stn *qk; int timer; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
__int64 v4; // rdx
__int64 v5; // rcx
int v6; // er8
__int64 v7; // r9

parse_args(argc, argv, envp);
parse_file(inst_defn_file, 100LL);
v3 = inst_trace_file;
parse_file(inst_trace_file, 116LL);
create_arch();
while ( instr_proc < instr_count )
{
++cycles;
issue(v3, 116LL, v4, v5, v6, v7);
execute();
write_back();
}
finish();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
__int64 v4; // rdx
__int64 v5; // rcx
int v6; // er8
__int64 v7; // r9

parse_args(argc, argv, envp);
parse_file(inst_defn_file, 100LL);
v3 = inst_trace_file;
parse_file(inst_trace_file, 116LL);
func2();
while ( instr_proc < instr_count )
{
++cycles;
func6(v3, 116LL, v4, v5, v6, v7);
func4();
func5();
}
finish();
return 0;
}

original_code:
int main (int argc, char **argv) {
 parse_args (argc, argv);
 parse_file (inst_defn_file, 'd');
 parse_file (inst_trace_file, 't');
 create_arch();
 while (instr_proc < instr_count) {
  cycles++;
  issue ();
  execute ();
  write_back();
 }
 finish ();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 parse_args (argc, argv);
 parse_file (inst_defn_file, 'd');
 parse_file (inst_trace_file, 't');
 create_arch();
 while (instr_proc < instr_count) {
  cycles++;
  issue ();
  execute ();
  write_back();
 }
 finish ();
 return 0;
}


decompiled_code:
int __fastcall create_operation(char *s)
{
char *v1; // rax
char **v2; // rbp
char *v3; // rax
int v4; // edx
char *v5; // rax
int v6; // edx
char v7; // al
int result; // eax
char v9[32]; // [rsp+0h] [rbp-58h] BYREF
char dest[56]; // [rsp+20h] [rbp-38h] BYREF

if ( op_count == 10 * (op_count / 10) )
ops = realloc(ops, 0xF0uLL);
v1 = strtok(s, " \t,");
strcpy(dest, v1);
if ( !dest[0] )
{
fprintf(stderr, "[FATAL] (%s:%d) OP name not proper : %s\n", "parser.c", 13LL, s);
exit(-1);
}
v2 = (char **)((char *)ops + 24 * op_count);
*v2 = strdup(dest);
v3 = strtok(0LL, " \t,");
v4 = atoi(v3);
if ( v4 < 0 )
{
fprintf(stderr, "[FATAL] (%s:%d) Operand count not proper : %s\n", "parser.c", 18LL, s);
exit(-1);
}
*((_DWORD *)ops + 6 * op_count + 2) = v4;
v5 = strtok(0LL, " \t,");
v6 = atoi(v5);
if ( v6 <= 0 )
{
fprintf(stderr, "[FATAL] (%s:%d) Latency not proper : %s\n", "parser.c", 23LL, s);
exit(-1);
}
*((_DWORD *)ops + 6 * op_count + 3) = v6;
v7 = *strtok(0LL, " \t,");
switch ( v7 )
{
case 'I':
*((_DWORD *)ops + 6 * op_count + 4) = 1;
strcpy(v9, "Integer");
break;
case 'F':
*((_DWORD *)ops + 6 * op_count + 4) = 2;
strcpy(v9, "Floating Point");
break;
case 'C':
*((_DWORD *)ops + 6 * op_count + 4) = 3;
strcpy(v9, "Common");
break;
default:
fprintf(stderr, "[FATAL] (%s:%d) Unknown instruction type : %s\n", "parser.c", 40LL, s);
exit(-1);
}
result = fprintf(
stderr,
"[INFO] (%s:%d) %d : %s operation %s defined taking %d operands with latency %d\n",
"parser.c",
42LL,
op_count,
v9,
*((const char **)ops + 3 * op_count),
*((unsigned int *)ops + 6 * op_count + 2),
*((unsigned int *)ops + 6 * op_count + 3));
++op_count;
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s)
{
char *v1; // rax
char **v2; // rbp
char *v3; // rax
int v4; // edx
char *v5; // rax
int v6; // edx
char v7; // al
int result; // eax
char v9[32]; // [rsp+0h] [rbp-58h] BYREF
char dest[56]; // [rsp+20h] [rbp-38h] BYREF

if ( op_count == 10 * (op_count / 10) )
ops = realloc(ops, 0xF0uLL);
v1 = strtok(s, " \t,");
strcpy(dest, v1);
if ( !dest[0] )
{
fprintf(stderr, "[FATAL] (%s:%d) OP name not proper : %s\n", "parser.c", 13LL, s);
exit(-1);
}
v2 = (char **)((char *)ops + 24 * op_count);
*v2 = strdup(dest);
v3 = strtok(0LL, " \t,");
v4 = atoi(v3);
if ( v4 < 0 )
{
fprintf(stderr, "[FATAL] (%s:%d) Operand count not proper : %s\n", "parser.c", 18LL, s);
exit(-1);
}
*((_DWORD *)ops + 6 * op_count + 2) = v4;
v5 = strtok(0LL, " \t,");
v6 = atoi(v5);
if ( v6 <= 0 )
{
fprintf(stderr, "[FATAL] (%s:%d) Latency not proper : %s\n", "parser.c", 23LL, s);
exit(-1);
}
*((_DWORD *)ops + 6 * op_count + 3) = v6;
v7 = *strtok(0LL, " \t,");
switch ( v7 )
{
case 'I':
*((_DWORD *)ops + 6 * op_count + 4) = 1;
strcpy(v9, "Integer");
break;
case 'F':
*((_DWORD *)ops + 6 * op_count + 4) = 2;
strcpy(v9, "Floating Point");
break;
case 'C':
*((_DWORD *)ops + 6 * op_count + 4) = 3;
strcpy(v9, "Common");
break;
default:
fprintf(stderr, "[FATAL] (%s:%d) Unknown instruction type : %s\n", "parser.c", 40LL, s);
exit(-1);
}
result = fprintf(
stderr,
"[INFO] (%s:%d) %d : %s operation %s defined taking %d operands with latency %d\n",
"parser.c",
42LL,
op_count,
v9,
*((const char **)ops + 3 * op_count),
*((unsigned int *)ops + 6 * op_count + 2),
*((unsigned int *)ops + 6 * op_count + 3));
++op_count;
return result;
}

original_code:
static void create_operation (char *line) {
 char name[20], typ[20];
 int num_ops, latency;
 char type;
 if (!(op_count % 10))
  ops = (Operation *) realloc (ops, sizeof(Operation) * 10);
 strcpy (name, strtok (line," \t,"));
 if (!name[0])
  do {fprintf(stderr, "[FATAL] (%s:%d) " "OP name not proper : %s\n", "parser.c", 13, line); exit(-1); } while (0);
 ops[op_count].name = strdup (name);
 num_ops = atoi (strtok (((void *)0), " \t,"));
 if (0 > num_ops)
  do {fprintf(stderr, "[FATAL] (%s:%d) " "Operand count not proper : %s\n", "parser.c", 18, line); exit(-1); } while (0);
 ops[op_count].num_ops = num_ops;
 latency = atoi (strtok (((void *)0), " \t,"));
 if (0 >= latency)
  do {fprintf(stderr, "[FATAL] (%s:%d) " "Latency not proper : %s\n", "parser.c", 23, line); exit(-1); } while (0);
 ops[op_count].latency = latency;
 type = (strtok (((void *)0), " \t,"))[0];
 if ('I' == type) {
  ops[op_count].type = INTEGER;
  strcpy (typ, "Integer");
 }
 else if ('F' == type) {
  ops[op_count].type = FLOAT;
  strcpy (typ, "Floating Point");
 }
 else if ('C' == type) {
  ops[op_count].type = COMMON;
  strcpy (typ, "Common");
 }
 else
  do {fprintf(stderr, "[FATAL] (%s:%d) " "Unknown instruction type : %s\n", "parser.c", 40, line); exit(-1); } while (0);
 do {fprintf(stderr, "[INFO] (%s:%d) " "%d : %s operation %s defined taking %d operands with latency %d\n", "parser.c", 42, op_count, typ, ops[op_count].name, ops[op_count].num_ops, ops[op_count].latency); } while (0);
 op_count++;
}

canonical_original_code:
static void create_operation(char *line) {
 char name[20]; char typ[20];
 int num_ops; int latency;
 char type;
 if (!(op_count % 10))
  ops = (struct Operation *) realloc (ops, sizeof(Operation) * 10);
 strcpy (name, strtok (line," \t,"));
 if (!name[0])
  do {fprintf(stderr, "[FATAL] (%s:%d) " "OP name not proper : %s\n", "parser.c", 13, line); exit(-1); } while (0);
 ops[op_count].name = strdup (name);
 num_ops = atoi (strtok (((void *)0), " \t,"));
 if (0 > num_ops)
  do {fprintf(stderr, "[FATAL] (%s:%d) " "Operand count not proper : %s\n", "parser.c", 18, line); exit(-1); } while (0);
 ops[op_count].num_ops = num_ops;
 latency = atoi (strtok (((void *)0), " \t,"));
 if (0 >= latency)
  do {fprintf(stderr, "[FATAL] (%s:%d) " "Latency not proper : %s\n", "parser.c", 23, line); exit(-1); } while (0);
 ops[op_count].latency = latency;
 type = (strtok (((void *)0), " \t,"))[0];
 if ('I' == type) {
  ops[op_count].type = INTEGER;
  strcpy (typ, "Integer");
 }
 else if ('F' == type) {
  ops[op_count].type = FLOAT;
  strcpy (typ, "Floating Point");
 }
 else if ('C' == type) {
  ops[op_count].type = COMMON;
  strcpy (typ, "Common");
 }
 else
  do {fprintf(stderr, "[FATAL] (%s:%d) " "Unknown instruction type : %s\n", "parser.c", 40, line); exit(-1); } while (0);
 do {fprintf(stderr, "[INFO] (%s:%d) " "%d : %s operation %s defined taking %d operands with latency %d\n", "parser.c", 42, op_count, typ, ops[op_count].name, ops[op_count].num_ops, ops[op_count].latency); } while (0);
 op_count++;
}

variable_types:
line
char *

variable_types:
name
char [20]

variable_types:
typ
char [20]

variable_types: latency int

variable_types: type char

user_defined_types: struct Operation { char *name; int num_ops; int latency; enum instr_type type; }

user_defined_types: enum instr_type { UNDEFINED=0, INTEGER=1, FLOAT=2, COMMON=3 }


decompiled_code:
__int64 __fastcall lookup_definition(char *s1, __m128i *a2)
{
const char **v2; // rbx
const char **v3; // r13

if ( op_count <= 0 )
return 0LL;
v2 = (const char **)ops;
v3 = (const char **)((char *)ops + 24 * (unsigned int)(op_count - 1) + 24);
while ( strcmp(s1, *v2) )
{
v2 += 3;
if ( v2 == v3 )
return 0LL;
}
*a2 = _mm_loadu_si128((const __m128i *)v2);
a2[1].m128i_i64[0] = (__int64)v2[2];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1, __m128i *a2)
{
const char **v2; // rbx
const char **v3; // r13

if ( op_count <= 0 )
return 0LL;
v2 = (const char **)ops;
v3 = (const char **)((char *)ops + 24 * (unsigned int)(op_count - 1) + 24);
while ( strcmp(s1, *v2) )
{
v2 += 3;
if ( v2 == v3 )
return 0LL;
}
*a2 = _mm_loadu_si128((const __m128i *)v2);
a2[1].m128i_i64[0] = (__int64)v2[2];
return 1LL;
}

original_code:
static int lookup_definition (char *opcode, Operation *instr_defn) {
 int i;
 for (i = 0; i < op_count; i++)
  if (!strcmp (opcode, ops[i].name)) {
   *instr_defn = ops[i];
   return 1;
  }
 return 0;
}

canonical_original_code:
static int lookup_definition(char *opcode, struct Operation *instr_defn) {
 int i;
 for (i = 0; i < op_count; i++)
  if (!strcmp (opcode, ops[i].name)) {
   *instr_defn = ops[i];
   return 1;
  }
 return 0;
}

variable_types:
opcode
char *

variable_types: struct Operation { char *name; int num_ops; int latency; enum instr_type { UNDEFINED=0, INTEGER=1, FLOAT=2, COMMON=3 } type; } *


decompiled_code:
int __fastcall queue_instuction(char *s)
{
char *v1; // rax
char *v2; // rax
char **v3; // rbx
int v4; // edx
int result; // eax
char *v6; // rax
char *v7; // rbx
char *v8; // rax
char *v9; // rbx
char *v10; // rax
char *v11; // rbx
__m128i v12; // [rsp+0h] [rbp-48h] BYREF
char s1[40]; // [rsp+20h] [rbp-28h] BYREF

if ( instr_count == 10 * (instr_count / 10) )
iq = realloc(iq, 0x280uLL);
v1 = (char *)iq + 64 * (__int64)instr_count;
*((_QWORD *)v1 + 3) = 0LL;
*((_QWORD *)v1 + 2) = 0LL;
*((_QWORD *)v1 + 1) = 0LL;
*((_DWORD *)v1 + 14) = 0;
*((_DWORD *)v1 + 13) = 0;
*((_DWORD *)v1 + 12) = 0;
_isoc99_sscanf(s, "%s", s1);
if ( !(unsigned int)lookup_definition(s1, &v12) )
{
fprintf(stderr, "[FATAL] (%s:%d) Undefined instruction : %s\n", "parser.c", 72LL, s);
exit(-1);
}
v2 = strtok(s, " \t,");
v3 = (char **)((char *)iq + 64 * (__int64)instr_count);
*v3 = strdup(v2);
v4 = v12.m128i_i32[2];
*((_QWORD *)iq + 8 * (__int64)instr_count + 4) = v12.m128i_i64[1];
if ( v4 > 0 )
{
v6 = strtok(0LL, " \t,");
v7 = (char *)iq + 64 * (__int64)instr_count;
*((_QWORD *)v7 + 1) = strdup(v6);
}
if ( v12.m128i_i32[2] > 1 )
{
v8 = strtok(0LL, " \t,");
v9 = (char *)iq + 64 * (__int64)instr_count;
*((_QWORD *)v9 + 2) = strdup(v8);
}
if ( v12.m128i_i32[2] > 2 )
{
v10 = strtok(0LL, " \t,");
v11 = (char *)iq + 64 * (__int64)instr_count;
*((_QWORD *)v11 + 3) = strdup(v10);
}
result = fprintf(
stderr,
"[INFO] (%s:%d) Instruction %d : %s %s, %s, %s \n",
"parser.c",
87LL,
instr_count,
*((const char **)iq + 8 * (__int64)instr_count),
*((const char **)iq + 8 * (__int64)instr_count + 1),
*((const char **)iq + 8 * (__int64)instr_count + 2),
*((const char **)iq + 8 * (__int64)instr_count + 3));
++instr_count;
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s)
{
char *v1; // rax
char *v2; // rax
char **v3; // rbx
int v4; // edx
int result; // eax
char *v6; // rax
char *v7; // rbx
char *v8; // rax
char *v9; // rbx
char *v10; // rax
char *v11; // rbx
__m128i v12; // [rsp+0h] [rbp-48h] BYREF
char s1[40]; // [rsp+20h] [rbp-28h] BYREF

if ( instr_count == 10 * (instr_count / 10) )
iq = realloc(iq, 0x280uLL);
v1 = (char *)iq + 64 * (__int64)instr_count;
*((_QWORD *)v1 + 3) = 0LL;
*((_QWORD *)v1 + 2) = 0LL;
*((_QWORD *)v1 + 1) = 0LL;
*((_DWORD *)v1 + 14) = 0;
*((_DWORD *)v1 + 13) = 0;
*((_DWORD *)v1 + 12) = 0;
_isoc99_sscanf(s, "%s", s1);
if ( !(unsigned int)func1(s1, &v12) )
{
fprintf(stderr, "[FATAL] (%s:%d) Undefined instruction : %s\n", "parser.c", 72LL, s);
exit(-1);
}
v2 = strtok(s, " \t,");
v3 = (char **)((char *)iq + 64 * (__int64)instr_count);
*v3 = strdup(v2);
v4 = v12.m128i_i32[2];
*((_QWORD *)iq + 8 * (__int64)instr_count + 4) = v12.m128i_i64[1];
if ( v4 > 0 )
{
v6 = strtok(0LL, " \t,");
v7 = (char *)iq + 64 * (__int64)instr_count;
*((_QWORD *)v7 + 1) = strdup(v6);
}
if ( v12.m128i_i32[2] > 1 )
{
v8 = strtok(0LL, " \t,");
v9 = (char *)iq + 64 * (__int64)instr_count;
*((_QWORD *)v9 + 2) = strdup(v8);
}
if ( v12.m128i_i32[2] > 2 )
{
v10 = strtok(0LL, " \t,");
v11 = (char *)iq + 64 * (__int64)instr_count;
*((_QWORD *)v11 + 3) = strdup(v10);
}
result = fprintf(
stderr,
"[INFO] (%s:%d) Instruction %d : %s %s, %s, %s \n",
"parser.c",
87LL,
instr_count,
*((const char **)iq + 8 * (__int64)instr_count),
*((const char **)iq + 8 * (__int64)instr_count + 1),
*((const char **)iq + 8 * (__int64)instr_count + 2),
*((const char **)iq + 8 * (__int64)instr_count + 3));
++instr_count;
return result;
}

original_code:
static void queue_instuction (char *line) {
 char opcode[20];
 Operation instr_defn;
 if (!(instr_count % 10))
  iq = (Instruction *) realloc (iq, sizeof(Instruction) * 10);
 iq[instr_count].dest = iq[instr_count].src1 = iq[instr_count].src2 = 0;
 iq[instr_count].issue_time = iq[instr_count].exec_time = iq[instr_count].write_time = 0;
 sscanf (line, "%s", opcode);
 if (!lookup_definition (opcode, &instr_defn))
  do {fprintf(stderr, "[FATAL] (%s:%d) " "Undefined instruction : %s\n", "parser.c", 72, line); exit(-1); } while (0);
 iq[instr_count].opcd = strdup (strtok (line, " \t,"));
 iq[instr_count].num_ops = instr_defn.num_ops;
 iq[instr_count].latency = instr_defn.latency;
 if (instr_defn.num_ops > 0)
  iq[instr_count].dest = strdup (strtok (((void *)0), " \t,"));
 if (instr_defn.num_ops > 1)
  iq[instr_count].src1 = strdup (strtok (((void *)0), " \t,"));
 if (instr_defn.num_ops > 2)
  iq[instr_count].src2 = strdup (strtok (((void *)0), " \t,"));
 do {fprintf(stderr, "[INFO] (%s:%d) " "Instruction %d : %s %s, %s, %s \n", "parser.c", 87, instr_count, iq[instr_count].opcd, iq[instr_count].dest, iq[instr_count].src1, iq[instr_count].src2); } while (0);
 instr_count++;
}

canonical_original_code:
static void queue_instuction(char *line) {
 char opcode[20];
 struct Operation instr_defn;
 if (!(instr_count % 10))
  iq = (struct Instruction *) realloc (iq, sizeof(Instruction) * 10);
 iq[instr_count].dest = iq[instr_count].src1 = iq[instr_count].src2 = 0;
 iq[instr_count].issue_time = iq[instr_count].exec_time = iq[instr_count].write_time = 0;
 sscanf (line, "%s", opcode);
 if (!lookup_definition (opcode, &instr_defn))
  do {fprintf(stderr, "[FATAL] (%s:%d) " "Undefined instruction : %s\n", "parser.c", 72, line); exit(-1); } while (0);
 iq[instr_count].opcd = strdup (strtok (line, " \t,"));
 iq[instr_count].num_ops = instr_defn.num_ops;
 iq[instr_count].latency = instr_defn.latency;
 if (instr_defn.num_ops > 0)
  iq[instr_count].dest = strdup (strtok (((void *)0), " \t,"));
 if (instr_defn.num_ops > 1)
  iq[instr_count].src1 = strdup (strtok (((void *)0), " \t,"));
 if (instr_defn.num_ops > 2)
  iq[instr_count].src2 = strdup (strtok (((void *)0), " \t,"));
 do {fprintf(stderr, "[INFO] (%s:%d) " "Instruction %d : %s %s, %s, %s \n", "parser.c", 87, instr_count, iq[instr_count].opcd, iq[instr_count].dest, iq[instr_count].src1, iq[instr_count].src2); } while (0);
 instr_count++;
}

variable_types:
opcode
char [20]

variable_types: struct Operation { char *name; int num_ops; int latency; enum instr_type { UNDEFINED=0, INTEGER=1, FLOAT=2, COMMON=3 } type; }

user_defined_types: struct Instruction { char *opcd; char *dest; char *src1; char *src2; int num_ops; int latency; struct resrv_stn *cur; unsigned int issue_time; unsigned int exec_time; unsigned int write_time; }

user_defined_types: enum rs_status { UNKNOWN=0, AVAILABLE=1, BUSY=2, RESULT_READY=3 }


decompiled_code:
unsigned int __fastcall parse_args(int argc, char **argv)
{
unsigned int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "d:t:h");
if ( result == -1 )
break;
switch ( result )
{
case 'h':
fprintf(stderr, "[WARN] (%s:%d) Help file to come here\n", "utils.c", 23LL);
break;
case 't':
inst_trace_file = strdup(optarg);
fprintf(
stderr,
"[INFO] (%s:%d) Instruction trace File set to : %s\n",
"utils.c",
20LL,
(const char *)inst_trace_file);
break;
case 'd':
inst_defn_file = strdup(optarg);
fprintf(
stderr,
"[INFO] (%s:%d) Instruction Definition File set to : %s\n",
"utils.c",
16LL,
(const char *)inst_defn_file);
break;
default:
fprintf(stderr, "[FATAL] (%s:%d) Invalid command line option : -%c\n", "utils.c", 27LL, result);
exit(-1);
}
}
if ( !inst_defn_file )
{
inst_defn_file = strdup("instr.def");
result = fprintf(
stderr,
"[INFO] (%s:%d) Using default instruction definition file : %s\n",
"utils.c",
31LL,
(const char *)inst_defn_file);
}
if ( !inst_trace_file )
{
inst_trace_file = strdup("trace");
result = fprintf(
stderr,
"[INFO] (%s:%d) Using default instruction trace file : %s\n",
"utils.c",
34LL,
(const char *)inst_trace_file);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func0(int argc, char **argv)
{
unsigned int result; // eax

while ( 1 )
{
result = getopt(argc, argv, "d:t:h");
if ( result == -1 )
break;
switch ( result )
{
case 'h':
fprintf(stderr, "[WARN] (%s:%d) Help file to come here\n", "utils.c", 23LL);
break;
case 't':
inst_trace_file = strdup(optarg);
fprintf(
stderr,
"[INFO] (%s:%d) Instruction trace File set to : %s\n",
"utils.c",
20LL,
(const char *)inst_trace_file);
break;
case 'd':
inst_defn_file = strdup(optarg);
fprintf(
stderr,
"[INFO] (%s:%d) Instruction Definition File set to : %s\n",
"utils.c",
16LL,
(const char *)inst_defn_file);
break;
default:
fprintf(stderr, "[FATAL] (%s:%d) Invalid command line option : -%c\n", "utils.c", 27LL, result);
exit(-1);
}
}
if ( !inst_defn_file )
{
inst_defn_file = strdup("instr.def");
result = fprintf(
stderr,
"[INFO] (%s:%d) Using default instruction definition file : %s\n",
"utils.c",
31LL,
(const char *)inst_defn_file);
}
if ( !inst_trace_file )
{
inst_trace_file = strdup("trace");
result = fprintf(
stderr,
"[INFO] (%s:%d) Using default instruction trace file : %s\n",
"utils.c",
34LL,
(const char *)inst_trace_file);
}
return result;
}

original_code:
void parse_args (int argc, char **argv) {
 int c;
 while ((c = getopt (argc, argv, "d:t:h")) != -1)
  switch (c) {
   case 'd' :
    inst_defn_file = strdup (optarg);
    do {fprintf(stderr, "[INFO] (%s:%d) " "Instruction Definition File set to : %s\n", "utils.c", 16, inst_defn_file); } while (0);
    break;
   case 't' :
    inst_trace_file = strdup (optarg);
    do {fprintf(stderr, "[INFO] (%s:%d) " "Instruction trace File set to : %s\n", "utils.c", 20, inst_trace_file); } while (0);
    break;
   case 'h' :
    do {fprintf(stderr, "[WARN] (%s:%d) " "Help file to come here\n", "utils.c", 23); } while (0);
    break;
   default :
    do {fprintf(stderr, "[FATAL] (%s:%d) " "Invalid command line option : -%c\n", "utils.c", 27, c); exit(-1); } while (0);
  }
 if (!inst_defn_file)
  do {fprintf(stderr, "[INFO] (%s:%d) " "Using default instruction definition file : %s\n", "utils.c", 31, inst_defn_file = strdup ("instr.def")); } while (0);
 if (!inst_trace_file)
  do {fprintf(stderr, "[INFO] (%s:%d) " "Using default instruction trace file : %s\n", "utils.c", 34, inst_trace_file = strdup ("trace")); } while (0);
}

canonical_original_code:
void parse_args(int argc, char **argv) {
 int c;
 while ((c = getopt (argc, argv, "d:t:h")) != -1)
  switch (c) {
   case 'd' :
    inst_defn_file = strdup (optarg);
    do {fprintf(stderr, "[INFO] (%s:%d) " "Instruction Definition File set to : %s\n", "utils.c", 16, inst_defn_file); } while (0);
    break;
   case 't' :
    inst_trace_file = strdup (optarg);
    do {fprintf(stderr, "[INFO] (%s:%d) " "Instruction trace File set to : %s\n", "utils.c", 20, inst_trace_file); } while (0);
    break;
   case 'h' :
    do {fprintf(stderr, "[WARN] (%s:%d) " "Help file to come here\n", "utils.c", 23); } while (0);
    break;
   default :
    do {fprintf(stderr, "[FATAL] (%s:%d) " "Invalid command line option : -%c\n", "utils.c", 27, c); exit(-1); } while (0);
  }
 if (!inst_defn_file)
  do {fprintf(stderr, "[INFO] (%s:%d) " "Using default instruction definition file : %s\n", "utils.c", 31, inst_defn_file = strdup ("instr.def")); } while (0);
 if (!inst_trace_file)
  do {fprintf(stderr, "[INFO] (%s:%d) " "Using default instruction trace file : %s\n", "utils.c", 34, inst_trace_file = strdup ("trace")); } while (0);
}

variable_types: c int


finish

decompiled_code:
void finish()
{
int v0; // eax
bool v1; // zf
int i; // eax

v0 = instr_count;
if ( instr_count )
{
do
{
free(*((void **)iq + 8 * (__int64)v0));
free(*((void **)iq + 8 * (__int64)instr_count + 1));
free(*((void **)iq + 8 * (__int64)instr_count + 2));
free(*((void **)iq + 8 * (__int64)instr_count + 3));
v1 = instr_count == 1;
v0 = --instr_count;
}
while ( !v1 );
}
for ( i = op_count; op_count; i = op_count )
{
op_count = i - 1;
free(*((void **)ops + 3 * i));
}
free(iq);
free(ops);
free(inst_trace_file);
free(inst_defn_file);
}

canonical_decompiled_code:
void func1()
{
int v0; // eax
bool v1; // zf
int i; // eax

v0 = instr_count;
if ( instr_count )
{
do
{
free(*((void **)iq + 8 * (__int64)v0));
free(*((void **)iq + 8 * (__int64)instr_count + 1));
free(*((void **)iq + 8 * (__int64)instr_count + 2));
free(*((void **)iq + 8 * (__int64)instr_count + 3));
v1 = instr_count == 1;
v0 = --instr_count;
}
while ( !v1 );
}
for ( i = op_count; op_count; i = op_count )
{
op_count = i - 1;
free(*((void **)ops + 3 * i));
}
free(iq);
free(ops);
free(inst_trace_file);
free(inst_defn_file);
}

original_code:
void finish (void) {
 while (instr_count) {
  free (iq[instr_count].opcd);
  free (iq[instr_count].dest);
  free (iq[instr_count].src1);
  free (iq[instr_count].src2);
  instr_count--;
 }
 while (op_count)
  free (ops[op_count--].name);
 free (iq);
 free (ops);
 free (inst_trace_file);
 free (inst_defn_file);
}

canonical_original_code:
void finish() {
 while (instr_count) {
  free (iq[instr_count].opcd);
  free (iq[instr_count].dest);
  free (iq[instr_count].src1);
  free (iq[instr_count].src2);
  instr_count--;
 }
 while (op_count)
  free (ops[op_count--].name);
 free (iq);
 free (ops);
 free (inst_trace_file);
 free (inst_defn_file);
}


main

repo: harto/realpath-osx

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4[4104]; // [rsp+0h] [rbp-1008h] BYREF

if ( argc == 2 )
{
if ( realpath(argv[1], v4) )
{
puts(v4);
result = 0;
}
else
{
fprintf(stderr, "Bad path: %s\n", v4);
result = 2;
}
}
else
{
fwrite("Usage: realpath <path>\n", 1uLL, 0x17uLL, stderr);
result = 1;
}
return result;
}

original_code:
int main(int argc, char** argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: realpath <path>\n");
    return 1;
  }
  char* path = argv[1];
  char result[4096];
  if (realpath(path, result)) {
    printf("%s\n", result);
    return 0;
  } else {
    fprintf(stderr, "Bad path: %s\n", result);
    return 2;
  }
}

canonical_original_code:
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: realpath <path>\n");
    return 1;
  }
  char *path = argv[1];
  char result[4096];
  if (realpath(path, result)) {
    printf("%s\n", result);
    return 0;
  } else {
    fprintf(stderr, "Bad path: %s\n", result);
    return 2;
  }
}

variable_types: argc int

variable_types:
path
char *

variable_types:
result
char [4096]


repo: hartwork/mysecureshell-issues

decompiled_code:
int __fastcall print_status(int a1, int a2)
{
char v3; // di

v3 = 46;
if ( a1 )
{
v3 = 67;
if ( a1 == 3 )
{
v3 = 47;
if ( a2 != -1 )
v3 = 67;
}
}
return fputc(v3, stdout);
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2)
{
char v3; // di

v3 = 46;
if ( a1 )
{
v3 = 67;
if ( a1 == 3 )
{
v3 = 47;
if ( a2 != -1 )
v3 = 67;
}
}
return fputc(v3, stdout);
}

original_code:
static void print_status(u_int32_t status, u_int32_t pid) {
 char char_to_print;
 switch (status) {
 case 0:
  char_to_print = '.';
  break;
 case 3:
  if (pid == ((u_int32_t)-1)) {
   char_to_print = '/';
  } else {
   char_to_print = 'C';
  }
  break;
 default:
  char_to_print = 'C';
  break;
 }
 fprintf(stdout, "%c", char_to_print);
}

canonical_original_code:
static void print_status(unsigned int status, unsigned int pid) {
 char char_to_print;
 switch (status) {
 case 0:
  char_to_print = '.';
  break;
 case 3:
  if (pid == ((u_int32_t)-1)) {
   char_to_print = '/';
  } else {
   char_to_print = 'C';
  }
  break;
 default:
  char_to_print = 'C';
  break;
 }
 fprintf(stdout, "%c", char_to_print);
}

variable_types:
status
unsigned int

variable_types:
pid
unsigned int


process

original_code:
static void process(t_sftpwho * who, task_t task) {
 size_t i = 0;
 for (; i < 128; i++) {
  if ((i > 0) && (i % 64 == 0)) {
   fprintf(stdout, "\n");
  }
  switch (task) {
  case TASK_BLOCK:
   if (who[i].status == 0) {
    who[i].status = 3;
    who[i].pid = ((u_int32_t)-1);
    who[i].time_begin = ((u_int32_t)-1) - 10;
    who[i].time_total = 0;
   }
   break;
  case TASK_UNBLOCK:
   if ((who[i].status == 3)
     && (who[i].pid == ((u_int32_t)-1))) {
    who[i].pid = 0;
    who[i].time_begin = 0;
    who[i].time_total = 0;
    who[i].status = 0;
   }
   break;
  default:
   break;
  }
  print_status(who[i].status, who[i].pid);
 }
 fprintf(stdout, "\n");
}

canonical_original_code:
static void process(struct s_sftpwho *who, enum _task_t task) {
 unsigned long i = 0;
 for (; i < 128; i++) {
  if ((i > 0) && (i % 64 == 0)) {
   fprintf(stdout, "\n");
  }
  switch (task) {
  case TASK_BLOCK:
   if (who[i].status == 0) {
    who[i].status = 3;
    who[i].pid = ((u_int32_t)-1);
    who[i].time_begin = ((u_int32_t)-1) - 10;
    who[i].time_total = 0;
   }
   break;
  case TASK_UNBLOCK:
   if ((who[i].status == 3)
     && (who[i].pid == ((u_int32_t)-1))) {
    who[i].pid = 0;
    who[i].time_begin = 0;
    who[i].time_total = 0;
    who[i].status = 0;
   }
   break;
  default:
   break;
  }
  print_status(who[i].status, who[i].pid);
 }
 fprintf(stdout, "\n");
}

variable_types: struct s_sftpwho { char user[30]; char ip[30]; char path[200]; char file[200]; char home[196]; unsigned int status; unsigned int pid; unsigned int mode; unsigned int download_pos; unsigned int download_current; unsigned int download_total; unsigned int download_max; unsigned int upload_current; unsigned int upload_total; unsigned int upload_max; unsigned int time_maxidle; unsigned int time_maxlife; unsigned int time_idle; unsigned int time_total; unsigned int time_begin; unsigned int time_transf; } *

variable_types: enum _task_t { TASK_BLOCK=0, TASK_UNBLOCK=1, TASK_SHOW=2 }

variable_types:
i
unsigned long


legend

decompiled_code:
int legend()
{
fwrite("LEGEND\n", 1uLL, 7uLL, stdout);
fprintf(stdout, " %c = used by a client\n", 67LL);
fprintf(stdout, " %c = blocked\n", 47LL);
fprintf(stdout, " %c = unused\n", 46LL);
return fputc(10, stdout);
}

canonical_decompiled_code:
int func10()
{
fwrite("LEGEND\n", 1uLL, 7uLL, stdout);
fprintf(stdout, " %c = used by a client\n", 67LL);
fprintf(stdout, " %c = blocked\n", 47LL);
fprintf(stdout, " %c = unused\n", 46LL);
return fputc(10, stdout);
}

original_code:
static void legend() {
 fprintf(stdout, "LEGEND\n");
 fprintf(stdout, "  %c = used by a client\n", 'C');
 fprintf(stdout, "  %c = blocked\n", '/');
 fprintf(stdout, "  %c = unused\n", '.');
 fprintf(stdout, "\n");
}


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // er13
unsigned int v6; // ebp
int v7; // er12
key_t v8; // edi
int v9; // edi
void *v10; // rax
const void *v11; // rbx

if ( argc != 2 )
return usage(*(__int64 *)&argc, argv);
v3 = argv[1];
if ( !strcmp(v3, "block") )
{
v4 = 0;
}
else if ( !strcmp(v3, "unblock") )
{
v4 = 1;
}
else
{
v4 = 2;
if ( strcmp(v3, "show") )
return usage(2LL, argv);
}
legend();
v6 = 0;
do
{
v7 = v6++;
fprintf(stdout, "SEGMENT %d\n", v6);
v8 = ftok("/dev/null", v7 + 1927);
if ( !v8 )
__assert_fail("segment_key != 0", "local-dos.c", 0xC2u, "main");
v9 = shmget(v8, 0x16610uLL, 950);
if ( v9 == -1 )
__assert_fail("segment_id != -1", "local-dos.c", 0xC5u, "main");
v10 = shmat(v9, 0LL, 0);
v11 = v10;
if ( v10 == (void *)-1LL )
__assert_fail("segment_address != (void *)-1", "local-dos.c", 0xC8u, "main");
process((__int64)v10 + 16, v4);
if ( shmdt(v11) == -1 )
__assert_fail("detach_res != -1", "local-dos.c", 0xCEu, "main");
if ( v7 <= 1 )
fputc(10, stdout);
}
while ( v6 != 3 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // er13
unsigned int v6; // ebp
int v7; // er12
key_t v8; // edi
int v9; // edi
void *v10; // rax
const void *v11; // rbx

if ( argc != 2 )
return func7(*(__int64 *)&argc, argv);
v3 = argv[1];
if ( !strcmp(v3, "block") )
{
v4 = 0;
}
else if ( !strcmp(v3, "unblock") )
{
v4 = 1;
}
else
{
v4 = 2;
if ( strcmp(v3, "show") )
return func7(2LL, argv);
}
func10();
v6 = 0;
do
{
v7 = v6++;
fprintf(stdout, "SEGMENT %d\n", v6);
v8 = ftok("/dev/null", v7 + 1927);
if ( !v8 )
__assert_fail("segment_key != 0", "local-dos.c", 0xC2u, "main");
v9 = shmget(v8, 0x16610uLL, 950);
if ( v9 == -1 )
__assert_fail("segment_id != -1", "local-dos.c", 0xC5u, "main");
v10 = shmat(v9, 0LL, 0);
v11 = v10;
if ( v10 == (void *)-1LL )
__assert_fail("segment_address != (void *)-1", "local-dos.c", 0xC8u, "main");
func9((__int64)v10 + 16, v4);
if ( shmdt(v11) == -1 )
__assert_fail("detach_res != -1", "local-dos.c", 0xCEu, "main");
if ( v7 <= 1 )
fputc(10, stdout);
}
while ( v6 != 3 );
return 0;
}

original_code:
int main(int argc, char ** argv) {
 if (argc != 2) {
  return usage(argc, argv);
 }
 ((argc == 2) ? (void) (0) : __assert_fail ("argc == 2", "local-dos.c", 176, __extension__ __PRETTY_FUNCTION__));
 task_t task = TASK_SHOW;
 if (strcmp(argv[1], "block") == 0) {
  task = TASK_BLOCK;
 } else if (strcmp(argv[1], "unblock") == 0) {
  task = TASK_UNBLOCK;
 } else if (strcmp(argv[1], "show") == 0) {
 } else {
  return usage(argc, argv);
 }
 legend();
 int project_id_offset = 0;
 for (; project_id_offset < 3; project_id_offset++) {
  fprintf(stdout, "SEGMENT %d\n", project_id_offset + 1);
  const key_t segment_key = ftok(_shmfile, _shmkey + project_id_offset);
  ((segment_key != 0) ? (void) (0) : __assert_fail ("segment_key != 0", "local-dos.c", 194, __extension__ __PRETTY_FUNCTION__));
  const int segment_id = shmget(segment_key, sizeof(t_shm), 01000 | 0666);
  ((segment_id != -1) ? (void) (0) : __assert_fail ("segment_id != -1", "local-dos.c", 197, __extension__ __PRETTY_FUNCTION__));
  void * const segment_address = shmat(segment_id, 0, 0);
  ((segment_address != (void *)-1) ? (void) (0) : __assert_fail ("segment_address != (void *)-1", "local-dos.c", 200, __extension__ __PRETTY_FUNCTION__));
  t_sftpwho * const who = ((t_shm *)segment_address)->who;
  process(who, task);
  const int detach_res = shmdt(segment_address);
  ((detach_res != -1) ? (void) (0) : __assert_fail ("detach_res != -1", "local-dos.c", 206, __extension__ __PRETTY_FUNCTION__));
  if (project_id_offset < 3 - 1) {
   fprintf(stdout, "\n");
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 if (argc != 2) {
  return usage(argc, argv);
 }
 ((argc == 2) ? (void) (0) : __assert_fail ("argc == 2", "local-dos.c", 176, __extension__ __PRETTY_FUNCTION__));
 enum _task_t task = TASK_SHOW;
 if (strcmp(argv[1], "block") == 0) {
  task = TASK_BLOCK;
 } else if (strcmp(argv[1], "unblock") == 0) {
  task = TASK_UNBLOCK;
 } else if (strcmp(argv[1], "show") == 0) {
 } else {
  return usage(argc, argv);
 }
 legend();
 int project_id_offset = 0;
 for (; project_id_offset < 3; project_id_offset++) {
  fprintf(stdout, "SEGMENT %d\n", project_id_offset + 1);
  int segment_key = ftok(_shmfile, _shmkey + project_id_offset);
  ((segment_key != 0) ? (void) (0) : __assert_fail ("segment_key != 0", "local-dos.c", 194, __extension__ __PRETTY_FUNCTION__));
  int segment_id = shmget(segment_key, sizeof(t_shm), 01000 | 0666);
  ((segment_id != -1) ? (void) (0) : __assert_fail ("segment_id != -1", "local-dos.c", 197, __extension__ __PRETTY_FUNCTION__));
  void *segment_address = shmat(segment_id, 0, 0);
  ((segment_address != (void *)-1) ? (void) (0) : __assert_fail ("segment_address != (void *)-1", "local-dos.c", 200, __extension__ __PRETTY_FUNCTION__));
  struct s_sftpwho *who = ((t_shm *)segment_address)->who;
  process(who, task);
  int detach_res = shmdt(segment_address);
  ((detach_res != -1) ? (void) (0) : __assert_fail ("detach_res != -1", "local-dos.c", 206, __extension__ __PRETTY_FUNCTION__));
  if (project_id_offset < 3 - 1) {
   fprintf(stdout, "\n");
  }
 }
 return 0;
}

variable_types:
argv
char **

user_defined_types: enum _task_t { TASK_BLOCK=0, TASK_UNBLOCK=1, TASK_SHOW=2 }

user_defined_types: struct s_sftpwho { char user[30]; char ip[30]; char path[200]; char file[200]; char home[196]; unsigned int status; unsigned int pid; unsigned int mode; unsigned int download_pos; unsigned int download_current; unsigned int download_total; unsigned int download_max; unsigned int upload_current; unsigned int upload_total; unsigned int upload_max; unsigned int time_maxidle; unsigned int time_maxlife; unsigned int time_idle; unsigned int time_total; unsigned int time_begin; unsigned int time_transf; }


repo: hashmal/shirka

decompiled_code:
char *__fastcall symbol_id_from_string(char *src)
{
char *v1; // r12
char *v2; // rbx

v1 = symbol_list;
if ( symbol_list )
{
v2 = symbol_list;
while ( strcmp(src, v2) )
{
v2 = (char *)*((_QWORD *)v2 + 32);
if ( !v2 )
goto LABEL_5;
}
}
else
{
LABEL_5:
v2 = (char *)malloc(0x108uLL);
strcpy(v2, src);
*((_QWORD *)v2 + 32) = v1;
symbol_list = v2;
}
return v2;
}

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

v1 = symbol_list;
if ( symbol_list )
{
v2 = symbol_list;
while ( strcmp(src, v2) )
{
v2 = (char *)*((_QWORD *)v2 + 32);
if ( !v2 )
goto LABEL_5;
}
}
else
{
LABEL_5:
v2 = (char *)malloc(0x108uLL);
strcpy(v2, src);
*((_QWORD *)v2 + 32) = v1;
symbol_list = v2;
}
return v2;
}

original_code:
symbol *symbol_id_from_string (char *str)
{
 symbol *sym = symbol_list;
 while (sym) {
  if (strcmp(str, sym->name) == 0) {
   goto symbol_found;
  }
  sym = sym->next;
 }
 sym = malloc(sizeof(symbol));
 strcpy(sym->name, str);
 sym->next = symbol_list;
 symbol_list = sym;
symbol_found:
 return sym;
}

canonical_original_code:
struct symbol *symbol_id_from_string(char *str)
{
 struct symbol *sym = symbol_list;
 while (sym) {
  if (strcmp(str, sym->name) == 0) {
   goto symbol_found;
  }
  sym = sym->next;
 }
 sym = malloc(sizeof(symbol));
 strcpy(sym->name, str);
 sym->next = symbol_list;
 symbol_list = sym;
symbol_found:
 return sym;
}

variable_types:
str
char *

variable_types: struct symbol { char name[256]; struct symbol *next; } *


decompiled_code:
void __fastcall skO_free(__int64 a1)
{
unsigned int v2; // eax
_QWORD *v3; // rbx
_QWORD *v4; // rdi

v2 = *(_DWORD *)(a1 + 8);
if ( v2 > 4 )
{
if ( v2 != 5 )
{
fwrite("Internal type error.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
v3 = *(_QWORD **)(a1 + 16);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)*v3;
skO_free(v4);
}
}
free((void *)a1);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
unsigned int v2; // eax
_QWORD *v3; // rbx
_QWORD *v4; // rdi

v2 = *(_DWORD *)(a1 + 8);
if ( v2 > 4 )
{
if ( v2 != 5 )
{
fwrite("Internal type error.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
v3 = *(_QWORD **)(a1 + 16);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)*v3;
func1(v4);
}
}
free((void *)a1);
}

original_code:
void skO_free (skO *obj)
{
 skO *node;
 skO *next;
 switch (obj->tag) {
 case SKO_LIST:
  node = obj->data.list;
  while (node) {
   next = node->next;
   skO_free(node);
   node = next;
  }
 case SKO_SYMBOL:
 case SKO_QSYMBOL:
 case SKO_NUMBER:
 case SKO_BOOLEAN:
 case SKO_CHARACTER:
  free (obj);
  break;
 default:
  fprintf(stderr, "Internal type error.\n");
  exit(1);
  break;
 }
}

canonical_original_code:
void skO_free(struct skO *obj)
{
 struct skO *node;
 struct skO *next;
 switch (obj->tag) {
 case SKO_LIST:
  node = obj->data.list;
  while (node) {
   next = node->next;
   skO_free(node);
   node = next;
  }
 case SKO_SYMBOL:
 case SKO_QSYMBOL:
 case SKO_NUMBER:
 case SKO_BOOLEAN:
 case SKO_CHARACTER:
  free (obj);
  break;
 default:
  fprintf(stderr, "Internal type error.\n");
  exit(1);
  break;
 }
}

variable_types: struct skO { struct skO *next; enum skO_t { SKO_NUMBER=0, SKO_BOOLEAN=1, SKO_CHARACTER=2, SKO_QSYMBOL=3, SKO_SYMBOL=4, SKO_LIST=5 } tag; union { double number; int boolean; char character; struct symbol { char name[256]; struct symbol *next; } *sym; struct skO *list; } data; } *

user_defined_types: struct skO { struct skO *next; enum skO_t tag; union { double number; int boolean; char character; struct symbol *sym; struct skO *list; } data; }


decompiled_code:
double *__fastcall skO_number_new(double a1)
{
double *result; // rax

result = (double *)malloc(0x18uLL);
*result = 0.0;
*((_DWORD *)result + 2) = 0;
result[2] = a1;
return result;
}

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

result = (double *)malloc(0x18uLL);
*result = 0.0;
*((_DWORD *)result + 2) = 0;
result[2] = a1;
return result;
}

original_code:
skO *skO_number_new (double d)
{
 skO *obj = malloc(sizeof(skO));
 obj->next = ((void *)0);
 obj->tag = SKO_NUMBER;
 obj->data.number = d;
 return obj;
}

canonical_original_code:
struct skO *skO_number_new(double d)
{
 struct skO *obj = malloc(sizeof(skO));
 obj->next = ((void *)0);
 obj->tag = SKO_NUMBER;
 obj->data.number = d;
 return obj;
}

variable_types: d double

return_type: struct skO { struct skO *next; enum skO_t { SKO_NUMBER=0, SKO_BOOLEAN=1, SKO_CHARACTER=2, SKO_QSYMBOL=3, SKO_SYMBOL=4, SKO_LIST=5 } tag; union { double number; int boolean; char character; struct symbol { char name[256]; struct symbol *next; } *sym; struct skO *list; } data; } *


decompiled_code:
_DWORD *skO_list_new()
{
_DWORD *result; // rax

result = malloc(0x18uLL);
*(_QWORD *)result = 0LL;
result[2] = 5;
*((_QWORD *)result + 2) = 0LL;
return result;
}

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

result = malloc(0x18uLL);
*(_QWORD *)result = 0LL;
result[2] = 5;
*((_QWORD *)result + 2) = 0LL;
return result;
}

original_code:
skO *skO_list_new (void)
{
 skO *obj = malloc(sizeof(skO));
 obj->next = ((void *)0);
 obj->tag = SKO_LIST;
 obj->data.list = ((void *)0);
 return obj;
}

canonical_original_code:
struct skO *skO_list_new()
{
 struct skO *obj = malloc(sizeof(skO));
 obj->next = ((void *)0);
 obj->tag = SKO_LIST;
 obj->data.list = ((void *)0);
 return obj;
}

user_defined_types: enum skO_t { SKO_NUMBER=0, SKO_BOOLEAN=1, SKO_CHARACTER=2, SKO_QSYMBOL=3, SKO_SYMBOL=4, SKO_LIST=5 }

user_defined_types: struct symbol { char name[256]; struct symbol *next; }


tystr

decompiled_code:
char *__fastcall tystr(__int64 a1)
{
char *result; // rax

switch ( a1 )
{
case 0LL:
result = NUMBER_AS_STRING;
break;
case 1LL:
result = BOOLEAN_AS_STRING;
break;
case 2LL:
result = CHARACTER_AS_STRING;
break;
case 3LL:
result = QSYMBOL_AS_STRING;
break;
case 4LL:
result = SYMBOL_AS_STRING;
break;
case 5LL:
result = LIST_AS_STRING;
break;
default:
fwrite("Internal type error.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
char *result; // rax

switch ( a1 )
{
case 0LL:
result = NUMBER_AS_STRING;
break;
case 1LL:
result = BOOLEAN_AS_STRING;
break;
case 2LL:
result = CHARACTER_AS_STRING;
break;
case 3LL:
result = QSYMBOL_AS_STRING;
break;
case 4LL:
result = SYMBOL_AS_STRING;
break;
case 5LL:
result = LIST_AS_STRING;
break;
default:
fwrite("Internal type error.\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
return result;
}

original_code:
const char *tystr (size_t i)
{
 switch (i) {
 case SKO_NUMBER: return NUMBER_AS_STRING;
 case SKO_BOOLEAN: return BOOLEAN_AS_STRING;
 case SKO_CHARACTER: return CHARACTER_AS_STRING;
 case SKO_QSYMBOL: return QSYMBOL_AS_STRING;
 case SKO_SYMBOL: return SYMBOL_AS_STRING;
 case SKO_LIST: return LIST_AS_STRING;
 default:
  fprintf(stderr, "Internal type error.\n");
  exit(1);
 }
}

canonical_original_code:
char *tystr(unsigned long i)
{
 switch (i) {
 case SKO_NUMBER: return NUMBER_AS_STRING;
 case SKO_BOOLEAN: return BOOLEAN_AS_STRING;
 case SKO_CHARACTER: return CHARACTER_AS_STRING;
 case SKO_QSYMBOL: return QSYMBOL_AS_STRING;
 case SKO_SYMBOL: return SYMBOL_AS_STRING;
 case SKO_LIST: return LIST_AS_STRING;
 default:
  fprintf(stderr, "Internal type error.\n");
  exit(1);
 }
}

return_type: char *


decompiled_code:
__int64 __fastcall skO_checkType(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char *v3; // rbp
char *v4; // rax

result = *(unsigned int *)(a1 + 8);
if ( (_DWORD)result != a2 )
{
v3 = tystr((unsigned int)result);
v4 = tystr(a2);
fprintf(stderr, "INTERPRETER ERROR! Expected `%s' but got `%s'.\n", v4, v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char *v3; // rbp
char *v4; // rax

result = *(unsigned int *)(a1 + 8);
if ( (_DWORD)result != a2 )
{
v3 = func4((unsigned int)result);
v4 = func4(a2);
fprintf(stderr, "INTERPRETER ERROR! Expected `%s' but got `%s'.\n", v4, v3);
exit(1);
}
return result;
}

original_code:
void skO_checkType(skO *obj, skO_t type)
{
 if (obj->tag == type)
  return;
 fprintf(stderr, "INTERPRETER ERROR! Expected `%s' but got `%s'.\n",
  tystr(type), tystr(obj->tag));
 exit(1);
}

canonical_original_code:
void skO_checkType(struct skO *obj, enum skO_t type)
{
 if (obj->tag == type)
  return;
 fprintf(stderr, "INTERPRETER ERROR! Expected `%s' but got `%s'.\n",
  tystr(type), tystr(obj->tag));
 exit(1);
}

variable_types: enum skO_t { SKO_NUMBER=0, SKO_BOOLEAN=1, SKO_CHARACTER=2, SKO_QSYMBOL=3, SKO_SYMBOL=4, SKO_LIST=5 }


original_code:
void consume_leading (char **next)
{
 char *c = *next;
 while (*c != 0) {
  if (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISspace)) {
   c++;
  } else if (c[0] == '-' && c[1] == '-') {
   while (*c != '\n' && *c != 0)
    c++;
  } else {
   break;
  }
 }
 *next = c;
}

canonical_original_code:
void consume_leading(char **next)
{
 char *c = *next;
 while (*c != 0) {
  if (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISspace)) {
   c++;
  } else if (c[0] == '-' && c[1] == '-') {
   while (*c != '\n' && *c != 0)
    c++;
  } else {
   break;
  }
 }
 *next = c;
}

variable_types:
next
char **

variable_types:
c
char *