decompiled_code:
__int64 __fastcall td_env_r(__int64 a1)
{
__int64 result; // rax
void *v2; // r12
void (__fastcall *v3)(__int64); // r12
char *v4; // rax
char *v5; // rax
char *v6; // rax

result = cached_r_env;
if ( !cached_r_env )
{
v2 = dlopen("libtd_r.so", 258);
if ( !v2 )
{
v4 = dlerror();
fprintf(stderr, "%s\n", v4);
v2 = dlopen("libtd_r.dll", 258);
if ( !v2 )
{
v5 = dlerror();
fprintf(stderr, "%s\n", v5);
v2 = dlopen("libtd_r.dylib", 258);
if ( !v2 )
{
v6 = dlerror();
fprintf(stderr, "%s\n", v6);
}
}
}
fprintf(stderr, "h: 0x%px\n", v2);
v3 = (void (__fastcall *)(__int64))dlsym(v2, "td_r_init");
fprintf(stderr, "got here: 0x%px\n", v3);
v3(a1);
fwrite("after init\n", 1uLL, 0xBuLL, stderr);
result = cached_r_env;
if ( !cached_r_env )
_assert_fail("cached_r_env", "td.c", 0xCEu, "td_env_r");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1)
{
__int64 result; // rax
void *v2; // r12
void (__fastcall *v3)(__int64); // r12
char *v4; // rax
char *v5; // rax
char *v6; // rax

result = cached_r_env;
if ( !cached_r_env )
{
v2 = dlopen("libtd_r.so", 258);
if ( !v2 )
{
v4 = dlerror();
fprintf(stderr, "%s\n", v4);
v2 = dlopen("libtd_r.dll", 258);
if ( !v2 )
{
v5 = dlerror();
fprintf(stderr, "%s\n", v5);
v2 = dlopen("libtd_r.dylib", 258);
if ( !v2 )
{
v6 = dlerror();
fprintf(stderr, "%s\n", v6);
}
}
}
fprintf(stderr, "h: 0x%px\n", v2);
v3 = (void (__fastcall *)(__int64))dlsym(v2, "td_r_init");
fprintf(stderr, "got here: 0x%px\n", v3);
v3(a1);
fwrite("after init\n", 1uLL, 0xBuLL, stderr);
result = cached_r_env;
if ( !cached_r_env )
_assert_fail("cached_r_env", "td.c", 0xCEu, "td_env_r");
}
return result;
}

original_code:
td_env_t *td_env_r(char *homedir) {
  if (cached_r_env == ((void *)0)) {
    void *h = dlopen("libtd_r.so", 0x00100 | 0x00002);
    if (h == ((void *)0)) {
      fprintf(stderr, "%s\n", dlerror());
      h = dlopen("libtd_r.dll", 0x00100 | 0x00002);
    }
    if (h == ((void *)0)) {
      fprintf(stderr, "%s\n", dlerror());
      h = dlopen("libtd_r.dylib", 0x00100 | 0x00002);
    }
    if (h == ((void *)0)) {
      fprintf(stderr, "%s\n", dlerror());
    }
    fprintf(stderr, "h: 0x%px\n", h);
    td_env_t *(*init)(char*) = dlsym(h, "td_r_init");
    fprintf(stderr, "got here: 0x%px\n", init);
    init(homedir);
    fprintf(stderr, "after init\n");
    ((void) sizeof ((cached_r_env) ? 1 : 0), __extension__ ({ if (cached_r_env) ; else __assert_fail ("cached_r_env", "td.c", 206, __extension__ __PRETTY_FUNCTION__); }));
  }
  return cached_r_env;
}

canonical_original_code:
struct _td_env_t *td_env_r(char *homedir) {
  if (cached_r_env == ((void *)0)) {
    void *h = dlopen("libtd_r.so", 0x00100 | 0x00002);
    if (h == ((void *)0)) {
      fprintf(stderr, "%s\n", dlerror());
      h = dlopen("libtd_r.dll", 0x00100 | 0x00002);
    }
    if (h == ((void *)0)) {
      fprintf(stderr, "%s\n", dlerror());
      h = dlopen("libtd_r.dylib", 0x00100 | 0x00002);
    }
    if (h == ((void *)0)) {
      fprintf(stderr, "%s\n", dlerror());
    }
    fprintf(stderr, "h: 0x%px\n", h);
    struct _td_env_t *(*init)(char *) = dlsym(h, "td_r_init");
    fprintf(stderr, "got here: 0x%px\n", init);
    init(homedir);
    fprintf(stderr, "after init\n");
    ((void) sizeof ((cached_r_env) ? 1 : 0), __extension__ ({ if (cached_r_env) ; else __assert_fail ("cached_r_env", "td.c", 206, __extension__ __PRETTY_FUNCTION__); }));
  }
  return cached_r_env;
}

variable_types:
homedir
char *

variable_types: struct _td_env_t { char *name; void (*eval)(struct td_val_t { union { enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } tag; struct _td_env_t *owner; }; union { char int8_val; unsigned char uint8_val; short int16_val; unsigned short uint16_val; int int32_val; unsigned int uint32_val; long int64_val; unsigned long uint64_val; float float_val; double double_val; void *ptr_val; void *object; }; } *out, char *str); void (*invoke0)(struct td_val_t *out, char *f); void (*invoke1)(struct td_val_t *out, char *f, struct td_val_t *); void (*invoke2)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *); void (*invoke3)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke4)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke5)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invokeGraph0)(struct graph_t { int numNodes; char **nodeNames; double *edgeValues; double *nodeValues; int *rowOffsets; int *colIndices; } *out, char *f); void (*invokeGraph1)(struct graph_t *out, char *f, struct graph_t *in); void (*invokeGraph2)(struct graph_t *out, char *f, struct graph_t *in, int k); void (*invokeGraphAndCSC)(struct td_val_t *out, char *f, struct graph_t *in_graph, int *in_csc_offsets, int *in_csc_indics); void (*retain)(void *obj); void (*release)(void *obj); enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } (*get_type)(void *); enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } (*get_eltype)(void *); void *(*get_dataptr)(void *); unsigned long (*get_length)(void *); unsigned long (*get_ndims)(void *); void (*get_dims)(void *, unsigned long *dims); void (*get_strides)(void *, unsigned long *strides); } *(*)(char *)


repo: darpa-xdata/xlang

decompiled_code:
void __fastcall td_provide_r(__int64 a1)
{
cached_r_env = a1;
}

canonical_decompiled_code:
void __fastcall func24(__int64 a1)
{
cached_r_env = a1;
}

original_code:
void td_provide_r(td_env_t *e) {
  cached_r_env = e;
}

canonical_original_code:
void td_provide_r(struct _td_env_t *e) {
  cached_r_env = e;
}

variable_types: struct _td_env_t { char *name; void (*eval)(struct td_val_t { union { enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } tag; struct _td_env_t *owner; }; union { char int8_val; unsigned char uint8_val; short int16_val; unsigned short uint16_val; int int32_val; unsigned int uint32_val; long int64_val; unsigned long uint64_val; float float_val; double double_val; void *ptr_val; void *object; }; } *out, char *str); void (*invoke0)(struct td_val_t *out, char *f); void (*invoke1)(struct td_val_t *out, char *f, struct td_val_t *); void (*invoke2)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *); void (*invoke3)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke4)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke5)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invokeGraph0)(struct graph_t { int numNodes; char **nodeNames; double *edgeValues; double *nodeValues; int *rowOffsets; int *colIndices; } *out, char *f); void (*invokeGraph1)(struct graph_t *out, char *f, struct graph_t *in); void (*invokeGraph2)(struct graph_t *out, char *f, struct graph_t *in, int k); void (*invokeGraphAndCSC)(struct td_val_t *out, char *f, struct graph_t *in_graph, int *in_csc_offsets, int *in_csc_indics); void (*retain)(void *obj); void (*release)(void *obj); enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } (*get_type)(void *); enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } (*get_eltype)(void *); void *(*get_dataptr)(void *); unsigned long (*get_length)(void *); unsigned long (*get_ndims)(void *); void (*get_dims)(void *, unsigned long *dims); void (*get_strides)(void *, unsigned long *strides); } *

return_type: void

user_defined_types: struct _td_env_t { char *name; void (*eval)(struct td_val_t *out, char *str); void (*invoke0)(struct td_val_t *out, char *f); void (*invoke1)(struct td_val_t *out, char *f, struct td_val_t *); void (*invoke2)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *); void (*invoke3)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke4)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invoke5)(struct td_val_t *out, char *f, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *, struct td_val_t *); void (*invokeGraph0)(struct graph_t *out, char *f); void (*invokeGraph1)(struct graph_t *out, char *f, struct graph_t *in); void (*invokeGraph2)(struct graph_t *out, char *f, struct graph_t *in, int k); void (*invokeGraphAndCSC)(struct td_val_t *out, char *f, struct graph_t *in_graph, int *in_csc_offsets, int *in_csc_indics); void (*retain)(void *obj); void (*release)(void *obj); enum td_tag_t (*get_type)(void *); enum td_tag_t (*get_eltype)(void *); void *(*get_dataptr)(void *); unsigned long (*get_length)(void *); unsigned long (*get_ndims)(void *); void (*get_dims)(void *, unsigned long *dims); void (*get_strides)(void *, unsigned long *strides); }

user_defined_types: struct td_val_t { union { enum td_tag_t tag; struct _td_env_t *owner; }; union { char int8_val; unsigned char uint8_val; short int16_val; unsigned short uint16_val; int int32_val; unsigned int uint32_val; long int64_val; unsigned long uint64_val; float float_val; double double_val; void *ptr_val; void *object; }; }


decompiled_code:
__int64 __fastcall td_create_simple_graph(_QWORD *a1)
{
*a1 = 0xF00000007LL;
a1[1] = &names_2;
a1[4] = &row_offsets_1;
a1[5] = &col_indices_0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func25(_QWORD *a1)
{
*a1 = 0xF00000007LL;
a1[1] = &names_2;
a1[4] = &row_offsets_1;
a1[5] = &col_indices_0;
return 0LL;
}

original_code:
int td_create_simple_graph(graph_t *graph)
{
  size_t num_nodes = 7;
  size_t num_edges = 15;
  size_t top_nodes = 3;
  static char* names[7] = {"a", "b", "c", "d", "e", "f", "g"};
  static unsigned int row_offsets[8] = {0,3,6,9,11,14,15,15};
  static int col_indices[15] = {1,2,3,0,2,4,3,4,5,5,6,2,5,6,6};
  graph->numNodes = num_nodes;
  graph->numEdges = num_edges;
  graph->nodeNames = names;
  graph->rowOffsets = row_offsets;
  graph->colIndices = col_indices;
  return 0;
}

canonical_original_code:
int td_create_simple_graph(struct graph_t *graph)
{
  unsigned long num_nodes = 7;
  unsigned long num_edges = 15;
  unsigned long top_nodes = 3;
  static char *names[7] = {"a", "b", "c", "d", "e", "f", "g"};
  static unsigned int row_offsets[8] = {0,3,6,9,11,14,15,15};
  static int col_indices[15] = {1,2,3,0,2,4,3,4,5,5,6,2,5,6,6};
  graph->numNodes = num_nodes;
  graph->numEdges = num_edges;
  graph->nodeNames = names;
  graph->rowOffsets = row_offsets;
  graph->colIndices = col_indices;
  return 0;
}

variable_types: struct graph_t { int numNodes; char **nodeNames; double *edgeValues; double *nodeValues; int *rowOffsets; int *colIndices; } *

variable_types:
names
char *[7]

return_type: int


decompiled_code:
__int64 __fastcall parse_char_token(_BYTE **a1, __int64 a2, char a3)
{
_BYTE *v3; // rax

v3 = *a1;
if ( a2 - (__int64)*a1 <= 0 || *v3 != a3 )
return 0LL;
*a1 = v3 + 1;
return 1LL;
}

original_code:
static int parse_char_token(const char **pbegin, const char *end, char token)
{
    const char *begin = *pbegin;
    if (1 <= end - begin && *begin == token) {
        *pbegin = begin + 1;
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
static int parse_char_token(char **pbegin, char *end, char token)
{
    char *begin = *pbegin;
    if (1 <= end - begin && *begin == token) {
        *pbegin = begin + 1;
        return 1;
    } else {
        return 0;
    }
}

variable_types:
pbegin
char **

variable_types:
end
char *

variable_types: token char

variable_types:
begin
char *


original_code:
static int parse_size_t(const char **pbegin, const char *end, size_t *out)
{
    const char *begin = *pbegin;
    if (begin == end || !(*begin >= '0' && *begin <= '9')) {
        return 0;
    }
    size_t result = 0;
    while (*begin >= '0' && *begin <= '9') {
        result = 10 * result + *begin++ - '0';
    }
    *out = result;
    *pbegin = begin;
    return 0;
}

canonical_original_code:
static int parse_size_t(char **pbegin, char *end, unsigned long *out)
{
    char *begin = *pbegin;
    if (begin == end || !(*begin >= '0' && *begin <= '9')) {
        return 0;
    }
    unsigned long result = 0;
    while (*begin >= '0' && *begin <= '9') {
        result = 10 * result + *begin++ - '0';
    }
    *out = result;
    *pbegin = begin;
    return 0;
}

variable_types:
out
unsigned long *

variable_types:
result
unsigned long


decompiled_code:
__int64 __fastcall parse_name(unsigned __int64 *a1, unsigned __int64 a2, _QWORD *a3, unsigned __int64 *a4)
{
_BYTE *v4; // r8
__int64 result; // rax
_BYTE *v7; // rax
char v8; // cl
_BYTE *v9; // rsi

v4 = (_BYTE *)*a1;
if ( *a1 == a2 )
return 0LL;
if ( (unsigned __int8)((*v4 & 0xDF) - 65) <= 0x19u || (result = 0LL, *v4 == 95) )
{
v7 = v4 + 1;
if ( a2 > (unsigned __int64)(v4 + 1) )
{
while ( 1 )
{
v8 = *v7;
if ( (unsigned __int8)((*v7 & 0xDF) - 65) > 0x19u && (unsigned __int8)(v8 - 48) > 9u && v8 != 95 )
break;
if ( (_BYTE *)a2 == ++v7 )
{
*a3 = v4;
result = 1LL;
*a4 = a2;
*a1 = a2;
return result;
}
}
}
v9 = v7;
*a3 = v4;
result = 1LL;
*a4 = (unsigned __int64)v9;
*a1 = (unsigned __int64)v9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 *a1, unsigned __int64 a2, _QWORD *a3, unsigned __int64 *a4)
{
_BYTE *v4; // r8
__int64 result; // rax
_BYTE *v7; // rax
char v8; // cl
_BYTE *v9; // rsi

v4 = (_BYTE *)*a1;
if ( *a1 == a2 )
return 0LL;
if ( (unsigned __int8)((*v4 & 0xDF) - 65) <= 0x19u || (result = 0LL, *v4 == 95) )
{
v7 = v4 + 1;
if ( a2 > (unsigned __int64)(v4 + 1) )
{
while ( 1 )
{
v8 = *v7;
if ( (unsigned __int8)((*v7 & 0xDF) - 65) > 0x19u && (unsigned __int8)(v8 - 48) > 9u && v8 != 95 )
break;
if ( (_BYTE *)a2 == ++v7 )
{
*a3 = v4;
result = 1LL;
*a4 = a2;
*a1 = a2;
return result;
}
}
}
v9 = v7;
*a3 = v4;
result = 1LL;
*a4 = (unsigned __int64)v9;
*a1 = (unsigned __int64)v9;
}
return result;
}

original_code:
static int parse_name(const char **pbegin, const char *end,
                      const char **out_strbegin, const char **out_strend)
{
    const char *begin = *pbegin;
    if (begin == end) {
        return 0;
    }
    if (('a' <= *begin && *begin <= 'z') || ('A' <= *begin && *begin <= 'Z') ||
            *begin == '_') {
        ++begin;
    } else {
        return 0;
    }
    while (begin < end && (('a' <= *begin && *begin <= 'z') ||
                           ('A' <= *begin && *begin <= 'Z') ||
                           ('0' <= *begin && *begin <= '9') || *begin == '_')) {
        ++begin;
    }
    *out_strbegin = *pbegin;
    *out_strend = begin;
    *pbegin = begin;
    return 1;
}

canonical_original_code:
static int parse_name(char **pbegin, char *end, char **out_strbegin, char **out_strend)
{
    char *begin = *pbegin;
    if (begin == end) {
        return 0;
    }
    if (('a' <= *begin && *begin <= 'z') || ('A' <= *begin && *begin <= 'Z') ||
            *begin == '_') {
        ++begin;
    } else {
        return 0;
    }
    while (begin < end && (('a' <= *begin && *begin <= 'z') ||
                           ('A' <= *begin && *begin <= 'Z') ||
                           ('0' <= *begin && *begin <= '9') || *begin == '_')) {
        ++begin;
    }
    *out_strbegin = *pbegin;
    *out_strend = begin;
    *pbegin = begin;
    return 1;
}


decompiled_code:
__int64 __fastcall parse_token(const void **a1, __int64 a2, const char *a3)
{
unsigned int v3; // er15
char *v5; // r14
size_t v6; // rax
size_t v7; // rbp

v3 = 0;
v5 = (char *)*a1;
v6 = strlen(a3);
if ( a2 - (__int64)v5 >= v6 )
{
v7 = v6;
if ( !memcmp(v5, a3, v6) )
{
v3 = 1;
*a1 = &v5[v7];
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(const void **a1, __int64 a2, const char *a3)
{
unsigned int v3; // er15
char *v5; // r14
size_t v6; // rax
size_t v7; // rbp

v3 = 0;
v5 = (char *)*a1;
v6 = strlen(a3);
if ( a2 - (__int64)v5 >= v6 )
{
v7 = v6;
if ( !memcmp(v5, a3, v6) )
{
v3 = 1;
*a1 = &v5[v7];
}
}
return v3;
}

original_code:
static int parse_token(const char **pbegin, const char *end, const char *token)
{
    const char *begin = *pbegin;
    size_t tokenlen = strlen(token);
    if (tokenlen <= end - begin && memcmp(begin, token, tokenlen) == 0) {
        *pbegin = begin + tokenlen;
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
static int parse_token(char **pbegin, char *end, char *token)
{
    char *begin = *pbegin;
    unsigned long tokenlen = strlen(token);
    if (tokenlen <= end - begin && memcmp(begin, token, tokenlen) == 0) {
        *pbegin = begin + tokenlen;
        return 1;
    } else {
        return 0;
    }
}

variable_types:
token
char *

variable_types:
tokenlen
unsigned long


decompiled_code:
_QWORD *create_struct_ds()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
if ( result )
{
*result = 13LL;
}
else
{
td_error("out of memory");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
if ( result )
{
*result = 13LL;
}
else
{
td_error("out of memory");
result = 0LL;
}
return result;
}

original_code:
static td_ds_struct_t *create_struct_ds()
{
    td_ds_struct_t *res = malloc(sizeof(td_ds_struct_t));
    if (res == ((void *)0)) {
        td_error("out of memory");
        return ((void *)0);
    }
    res->ds.tag = TD_STRUCT;
    res->size = 0;
    return res;
}

canonical_original_code:
static struct td_ds_struct_t *create_struct_ds()
{
    struct td_ds_struct_t *res = malloc(sizeof(td_ds_struct_t));
    if (res == ((void *)0)) {
        td_error("out of memory");
        return ((void *)0);
    }
    res->ds.tag = TD_STRUCT;
    res->size = 0;
    return res;
}

variable_types: struct td_ds_struct_t { struct td_ds_t { enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } tag; } ds; int size; struct td_struct_field_t { char *name; struct td_ds_t *type; long offset; } fields[1]; } *

user_defined_types: struct td_ds_struct_t { struct td_ds_t ds; int size; struct td_struct_field_t fields[1]; }


decompiled_code:
void __fastcall skip_whitespace(__int64 *a1, char *a2)
{
char *v2; // rbp
__int64 v3; // r12
const unsigned __int16 *v4; // rcx
__int64 v5; // rdx
char *v6; // rax
char *v7; // [rsp+8h] [rbp-20h] BYREF

v2 = (char *)*a1;
v7 = v2;
if ( v2 >= a2 )
{
v3 = (__int64)v2;
goto LABEL_8;
}
v3 = (__int64)a2;
v4 = *_ctype_b_loc();
while ( 1 )
{
v5 = *v2;
if ( (v4[v5] & 0x2000) == 0 )
break;
v7 = ++v2;
if ( v2 == a2 )
goto LABEL_8;
}
if ( a2 > v2 && (_BYTE)v5 == 35 )
{
v6 = (char *)memchr(v2, 10, a2 - v2);
if ( !v6 )
goto LABEL_8;
v7 = v6 + 1;
skip_whitespace(&v7, a2);
}
v3 = (__int64)v7;
LABEL_8:
*a1 = v3;
}

original_code:
static void skip_whitespace(const char **pbegin, const char *end)
{
    const char *begin = *pbegin;
    while (begin < end && ((*__ctype_b_loc ())[(int) ((*begin))] & (unsigned short int) _ISspace)) {
        ++begin;
    }
    if (begin < end && *begin == '#') {
        const char *line_end = (const char *)memchr(begin, '\n', end - begin);
        if (line_end == ((void *)0)) {
            begin = end;
        } else {
            begin = line_end + 1;
            skip_whitespace(&begin, end);
        }
    }
    *pbegin = begin;
}

canonical_original_code:
static void skip_whitespace(char **pbegin, char *end)
{
    char *begin = *pbegin;
    while (begin < end && ((*__ctype_b_loc ())[(int) ((*begin))] & (unsigned short) _ISspace)) {
        ++begin;
    }
    if (begin < end && *begin == '#') {
        char *line_end = (const char *)memchr(begin, '\n', end - begin);
        if (line_end == ((void *)0)) {
            begin = end;
        } else {
            begin = line_end + 1;
            skip_whitespace(&begin, end);
        }
    }
    *pbegin = begin;
}


decompiled_code:
void *__fastcall td_parse_datashape(__int64 a1, char *a2)
{
_QWORD *v2; // rax
void *v3; // r12
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = a1;
v2 = parse_datashape(v5, a2);
if ( v2 )
{
v3 = v2;
skip_whitespace(v5, a2);
if ( (char *)v5[0] == a2 )
return v3;
td_free_datashape_localalias(v3);
}
td_error("unrecognized datashape");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, char *a2)
{
_QWORD *v2; // rax
void *v3; // r12
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = a1;
v2 = parse_datashape(v5, a2);
if ( v2 )
{
v3 = v2;
func5(v5, a2);
if ( (char *)v5[0] == a2 )
return v3;
func6(v3);
}
td_error("unrecognized datashape");
return 0LL;
}

original_code:
td_ds_t *td_parse_datashape(const char *strbegin,
                            const char *strend)
{
    td_ds_t *res = parse_datashape(&strbegin, strend);
    if (res != ((void *)0)) {
        skip_whitespace(&strbegin, strend);
        if (strbegin == strend) {
            return res;
        } else {
            td_free_datashape(res);
        }
    }
    td_error("unrecognized datashape");
    return 0;
}

canonical_original_code:
struct td_ds_t *td_parse_datashape(char *strbegin, char *strend)
{
    struct td_ds_t *res = parse_datashape(&strbegin, strend);
    if (res != ((void *)0)) {
        skip_whitespace(&strbegin, strend);
        if (strbegin == strend) {
            return res;
        } else {
            td_free_datashape(res);
        }
    }
    td_error("unrecognized datashape");
    return 0;
}

variable_types:
strbegin
char *

variable_types:
strend
char *

variable_types: struct td_ds_t { enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } tag; } *


decompiled_code:
__int64 __fastcall parse_struct_field(_BYTE **a1, char *a2, _QWORD *a3, unsigned __int64 *a4, _QWORD *a5)
{
_QWORD *v7; // rax
_BYTE *v8[6]; // [rsp+8h] [rbp-30h] BYREF

v8[0] = *a1;
if ( !(unsigned int)parse_name((unsigned __int64 *)v8, (unsigned __int64)a2, a3, a4) )
return 0LL;
skip_whitespace((__int64 *)v8, a2);
if ( !(unsigned int)parse_char_token(v8, (__int64)a2, 58) )
return 0LL;
v7 = parse_datashape((__int64 *)v8, a2);
*a5 = v7;
if ( !v7 )
return 0LL;
*a1 = v8[0];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE **a1, char *a2, _QWORD *a3, unsigned __int64 *a4, _QWORD *a5)
{
_QWORD *v7; // rax
_BYTE *v8[6]; // [rsp+8h] [rbp-30h] BYREF

v8[0] = *a1;
if ( !(unsigned int)func2((unsigned __int64 *)v8, (unsigned __int64)a2, a3, a4) )
return 0LL;
func5((__int64 *)v8, a2);
if ( !(unsigned int)func0(v8, (__int64)a2, 58) )
return 0LL;
v7 = parse_datashape((__int64 *)v8, a2);
*a5 = v7;
if ( !v7 )
return 0LL;
*a1 = v8[0];
return 1LL;
}

original_code:
static int parse_struct_field(const char **pbegin, const char *end,
                              const char **pnamebegin, const char **pnameend,
                              td_ds_t **type)
{
    const char *begin = *pbegin;
    if (!parse_name(&begin, end, pnamebegin, pnameend)) {
        return 0;
    }
    skip_whitespace(&begin, end);
    if (!parse_char_token(&begin, end, ':')) {
        return 0;
    }
    *type = parse_datashape(&begin, end);
    if (*type == ((void *)0)) {
        return 0;
    }
    *pbegin = begin;
    return 1;
}

canonical_original_code:
static int parse_struct_field(char **pbegin, char *end, char **pnamebegin, char **pnameend, struct td_ds_t **type)
{
    char *begin = *pbegin;
    if (!parse_name(&begin, end, pnamebegin, pnameend)) {
        return 0;
    }
    skip_whitespace(&begin, end);
    if (!parse_char_token(&begin, end, ':')) {
        return 0;
    }
    *type = parse_datashape(&begin, end);
    if (*type == ((void *)0)) {
        return 0;
    }
    *pbegin = begin;
    return 1;
}

variable_types:
pnamebegin
char **

variable_types:
pnameend
char **

variable_types: struct td_ds_t { enum td_tag_t { TD_INT8=0, TD_UINT8=1, TD_INT16=2, TD_UINT16=3, TD_INT32=4, TD_UINT32=5, TD_INT64=6, TD_UINT64=7, TD_FLOAT=8, TD_DOUBLE=9, TD_PTR=10, TD_UTF8=11, TD_ARRAY=12, TD_STRUCT=13, TD_OBJECT=14, TD_UNKNOWN=15, TD_MAX_TAG=16 } tag; } **


intHandler

repo: dasca/datalogger

decompiled_code:
void intHandler()
{
strcpy(&log_buf[16], "leaning up");
*(__m128i *)log_buf = _mm_load_si128((const __m128i *)&LC0);
log_entry(log_buf, 1LL);
}

canonical_decompiled_code:
void func0()
{
strcpy(&log_buf[16], "leaning up");
*(__m128i *)log_buf = _mm_load_si128((const __m128i *)&LC0);
log_entry(log_buf, 1LL);
}

original_code:
void intHandler() {
    sprintf(log_buf, "SIGINT caught, cleaning up");
    log_entry(log_buf, 1);
}


onPowerPulse

decompiled_code:
__suseconds_t onPowerPulse()
{
__int64 v0; // rsi
__suseconds_t result; // rax
__int64 v2; // rdx
double v3; // xmm1_8
double v4; // xmm0_8
unsigned __int64 v5; // rsi

gettimeofday(&tv, 0LL);
v0 = pulseTime;
result = tv.tv_usec + 1000000 * tv.tv_sec;
lastTime = pulseTime;
pulseTime = result;
if ( firstPulse == 1 )
{
firstPulse = 0;
elapsedTicks = 0;
power = 0LL;
}
else
{
v2 = ++pulseCount;
result -= v0;
if ( result < 0 )
{
v5 = result;
result &= 1u;
v3 = (double)(int)(result | (v5 >> 1)) + (double)(int)(result | (v5 >> 1));
}
else
{
v3 = (double)(int)result;
}
*(double *)&power = 3600000000.0 / v3 / (double)ppwh + *(double *)&power;
if ( v2 < 0 )
{
result = v2 & 1 | ((unsigned __int64)v2 >> 1);
v4 = (double)(int)result + (double)(int)result;
}
else
{
v4 = (double)(int)v2;
}
++elapsedTicks;
*(double *)&elapsedkWh = v4 / (double)(1000 * ppwh);
}
return result;
}

canonical_decompiled_code:
__suseconds_t func3()
{
__int64 v0; // rsi
__suseconds_t result; // rax
__int64 v2; // rdx
double v3; // xmm1_8
double v4; // xmm0_8
unsigned __int64 v5; // rsi

gettimeofday(&tv, 0LL);
v0 = pulseTime;
result = tv.tv_usec + 1000000 * tv.tv_sec;
lastTime = pulseTime;
pulseTime = result;
if ( firstPulse == 1 )
{
firstPulse = 0;
elapsedTicks = 0;
power = 0LL;
}
else
{
v2 = ++pulseCount;
result -= v0;
if ( result < 0 )
{
v5 = result;
result &= 1u;
v3 = (double)(int)(result | (v5 >> 1)) + (double)(int)(result | (v5 >> 1));
}
else
{
v3 = (double)(int)result;
}
*(double *)&power = 3600000000.0 / v3 / (double)ppwh + *(double *)&power;
if ( v2 < 0 )
{
result = v2 & 1 | ((unsigned __int64)v2 >> 1);
v4 = (double)(int)result + (double)(int)result;
}
else
{
v4 = (double)(int)v2;
}
++elapsedTicks;
*(double *)&elapsedkWh = v4 / (double)(1000 * ppwh);
}
return result;
}

original_code:
void onPowerPulse() {
    gettimeofday(&tv, ((void *)0));
    lastTime = pulseTime;
    pulseTime = 1000000 * tv.tv_sec + tv.tv_usec;
    if (firstPulse == 1) {
        firstPulse = 0;
        elapsedTicks = 0;
        power = 0;
        return;
    }
    pulseCount++;
    power += (3600000000.0 / (pulseTime - lastTime)) / ppwh;
    elapsedkWh = (1.0 * pulseCount / (ppwh * 1000));
    elapsedTicks++;
}


cPoll

decompiled_code:
void *__fastcall cPoll(void *a1)
{
struct pollfd fds; // [rsp+8h] [rbp-50h] BYREF
char buf[72]; // [rsp+10h] [rbp-48h] BYREF

fds.fd = open("/sys/class/gpio/gpio71/value", 0);
LABEL_3:
while ( KEEP_RUNNING == 1 )
{
fds.events = 2;
if ( poll(&fds, 1uLL, -1) >= 0 )
{
if ( (fds.revents & 2) == 0 )
goto LABEL_3;
}
else
{
log_entry("poll() failed!", 1LL);
if ( (fds.revents & 2) == 0 )
goto LABEL_3;
}
read(fds.fd, buf, 0x40uLL);
onPowerPulse();
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
struct pollfd fds; // [rsp+8h] [rbp-50h] BYREF
char buf[72]; // [rsp+10h] [rbp-48h] BYREF

fds.fd = open("/sys/class/gpio/gpio71/value", 0);
LABEL_3:
while ( KEEP_RUNNING == 1 )
{
fds.events = 2;
if ( poll(&fds, 1uLL, -1) >= 0 )
{
if ( (fds.revents & 2) == 0 )
goto LABEL_3;
}
else
{
log_entry("poll() failed!", 1LL);
if ( (fds.revents & 2) == 0 )
goto LABEL_3;
}
read(fds.fd, buf, 0x40uLL);
func3();
}
return 0LL;
}

original_code:
void *cPoll(void *notUsed) {
    struct pollfd fd[1];
    char buf[64];
    int i = 0, len = 0;
    fd[0].fd = open("/sys/class/gpio/gpio71/value", 00);
    while (KEEP_RUNNING == 1) {
        fd[0].events = 0x002;
        i = poll(fd, 1, -1);
        if (i < 0) {
            log_entry("poll() failed!", 1);
        }
        if (fd[0].revents & 0x002) {
            len = read(fd[0].fd, buf, 64);
            onPowerPulse();
        }
    }
    return 0;
}

canonical_original_code:
void *cPoll(void *notUsed) {
    struct pollfd fd[1];
    char buf[64];
    int i = 0; int len = 0;
    fd[0].fd = open("/sys/class/gpio/gpio71/value", 00);
    while (KEEP_RUNNING == 1) {
        fd[0].events = 0x002;
        i = poll(fd, 1, -1);
        if (i < 0) {
            log_entry("poll() failed!", 1);
        }
        if (fd[0].revents & 0x002) {
            len = read(fd[0].fd, buf, 64);
            onPowerPulse();
        }
    }
    return 0;
}

variable_types:
notUsed
void *

variable_types: struct pollfd { int fd; short events; short revents; } [1]

variable_types:
buf
char [64]

variable_types: i int

variable_types: len int

return_type: void *


decompiled_code:
// attributes: thunk
__int64 log_device()
{
return addReading();
}

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

original_code:
int log_device(struct sOneWireDevice *device_to_log) {
    return (addReading(device_to_log));
}

variable_types: struct sOneWireDevice { char *adress; char *type; float value; struct sOneWireDevice *next; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__time_t v3; // rbx
__int64 v4; // rbp
__time_t v5; // r12
__int64 v6; // rbx
void *v7; // rdi
pthread_t newthread; // [rsp+8h] [rbp-30h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

log_entry("Starting up", 0LL);
KEEP_RUNNING = 1;
zExitCode = 0;
signal(2, (__sighandler_t)intHandler);
initDB();
initGPIO();
if ( pthread_create(&newthread, 0LL, cPoll, 0LL) )
log_entry("Error creating thread", 1LL);
gettimeofday(&tv, 0LL);
v3 = tv.tv_sec;
v4 = list_devices();
while ( KEEP_RUNNING == 1 )
{
gettimeofday(&tv, 0LL);
v5 = tv.tv_sec;
if ( (unsigned __int64)(tv.tv_sec - v3) > 0x3B )
{
if ( v4 )
{
v6 = v4;
do
{
if ( updateValue(v6) )
log_device(v6);
v6 = *(_QWORD *)(v6 + 24);
}
while ( v6 );
}
power = 0LL;
v3 = v5;
elapsedTicks = 0;
}
sleep(1u);
}
if ( pthread_join(newthread, 0LL) )
log_entry("Error joining thread\n", 1LL);
while ( v4 )
{
v7 = (void *)v4;
v4 = *(_QWORD *)(v4 + 24);
free(v7);
}
restoreGPIO();
log_entry("Cleanup finished, exiting", 0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__time_t v3; // rbx
__int64 v4; // rbp
__time_t v5; // r12
__int64 v6; // rbx
void *v7; // rdi
pthread_t newthread; // [rsp+8h] [rbp-30h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

log_entry("Starting up", 0LL);
KEEP_RUNNING = 1;
zExitCode = 0;
signal(2, (__sighandler_t)intHandler);
initDB();
func2();
if ( pthread_create(&newthread, 0LL, cPoll, 0LL) )
log_entry("Error creating thread", 1LL);
gettimeofday(&tv, 0LL);
v3 = tv.tv_sec;
v4 = list_devices();
while ( KEEP_RUNNING == 1 )
{
gettimeofday(&tv, 0LL);
v5 = tv.tv_sec;
if ( (unsigned __int64)(tv.tv_sec - v3) > 0x3B )
{
if ( v4 )
{
v6 = v4;
do
{
if ( updateValue(v6) )
func5(v6);
v6 = *(_QWORD *)(v6 + 24);
}
while ( v6 );
}
power = 0LL;
v3 = v5;
elapsedTicks = 0;
}
sleep(1u);
}
if ( pthread_join(newthread, 0LL) )
log_entry("Error joining thread\n", 1LL);
while ( v4 )
{
v7 = (void *)v4;
v4 = *(_QWORD *)(v4 + 24);
free(v7);
}
func1();
log_entry("Cleanup finished, exiting", 0LL);
return 0;
}

original_code:
int main() {
    struct sOneWireDevice *devices, *device;
    pthread_t poll_thread;
    struct timeval tick;
    unsigned long last_tick;
    log_entry("Starting up", 0);
    KEEP_RUNNING = 1;
    zExitCode = 0;
    signal(2, intHandler);
    initDB();
    initGPIO();
    if (pthread_create(&poll_thread, ((void *)0), cPoll, ((void *)0))) {
        log_entry("Error creating thread", 1);
    }
    gettimeofday(&tick, ((void *)0));
    last_tick = tick.tv_sec;
    devices = list_devices();
    while (KEEP_RUNNING == 1) {
        gettimeofday(&tick, ((void *)0));
        if ((tick.tv_sec - last_tick) >= 60) {
            last_tick = tick.tv_sec;
            device = devices;
            while (device != ((void *)0)) {
                if (updateValue(device) != ((void *)0))
                    log_device(device);
                device = device->next;
            }
            power = 0;
            elapsedTicks = 0;
        }
        sleep(1);
    }
    if (pthread_join(poll_thread, ((void *)0))) {
        log_entry("Error joining thread\n", 1);
    }
    device = devices;
    while (device != ((void *)0)) {
        devices = device->next;
        free(device);
        device = devices;
    }
    restoreGPIO();
    log_entry("Cleanup finished, exiting", 0);
    return (0);
}

canonical_original_code:
int main() {
    struct sOneWireDevice *devices; struct sOneWireDevice *device;
    unsigned long poll_thread;
    struct timeval tick;
    unsigned long last_tick;
    log_entry("Starting up", 0);
    KEEP_RUNNING = 1;
    zExitCode = 0;
    signal(2, intHandler);
    initDB();
    initGPIO();
    if (pthread_create(&poll_thread, ((void *)0), cPoll, ((void *)0))) {
        log_entry("Error creating thread", 1);
    }
    gettimeofday(&tick, ((void *)0));
    last_tick = tick.tv_sec;
    devices = list_devices();
    while (KEEP_RUNNING == 1) {
        gettimeofday(&tick, ((void *)0));
        if ((tick.tv_sec - last_tick) >= 60) {
            last_tick = tick.tv_sec;
            device = devices;
            while (device != ((void *)0)) {
                if (updateValue(device) != ((void *)0))
                    log_device(device);
                device = device->next;
            }
            power = 0;
            elapsedTicks = 0;
        }
        sleep(1);
    }
    if (pthread_join(poll_thread, ((void *)0))) {
        log_entry("Error joining thread\n", 1);
    }
    device = devices;
    while (device != ((void *)0)) {
        devices = device->next;
        free(device);
        device = devices;
    }
    restoreGPIO();
    log_entry("Cleanup finished, exiting", 0);
    return (0);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

user_defined_types: struct sOneWireDevice { char *adress; char *type; float value; struct sOneWireDevice *next; }


decompiled_code:
__int64 __fastcall get_file_size(const char *a1)
{
int *v2; // rax
char *v3; // rax
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v4) )
{
v2 = _errno_location();
v3 = strerror(*v2);
sprintf(log_buf, "'stat' failed for '%s': %s", a1, v3);
log_entry(log_buf, 1LL);
}
return LODWORD(v4.st_size);
}

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

if ( stat(a1, &v4) )
{
v2 = _errno_location();
v3 = strerror(*v2);
sprintf(log_buf, "'stat' failed for '%s': %s", a1, v3);
log_entry(log_buf, 1LL);
}
return LODWORD(v4.st_size);
}

original_code:
unsigned get_file_size(const char * file_name) {
    struct stat sb;
    if (stat(file_name, & sb) != 0) {
        sprintf(log_buf, "'stat' failed for '%s': %s",
                file_name, strerror((*__errno_location ())));
        log_entry(log_buf, 1);
    }
    return sb.st_size;
}

canonical_original_code:
unsigned int get_file_size(char *file_name) {
    struct stat sb;
    if (stat(file_name, & sb) != 0) {
        sprintf(log_buf, "'stat' failed for '%s': %s",
                file_name, strerror((*__errno_location ())));
        log_entry(log_buf, 1);
    }
    return sb.st_size;
}

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

return_type: unsigned int

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


decompiled_code:
int __fastcall log_entry(const char *a1, int a2)
{
struct tm *v2; // rax
int result; // eax
time_t timer; // [rsp+8h] [rbp-90h] BYREF
char s[136]; // [rsp+10h] [rbp-88h] BYREF

time(&timer);
v2 = localtime(&timer);
strftime(s, 0x64uLL, "%y-%m-%d %H:%M:%S", v2);
result = fprintf(stderr, "%s:%s\r\n", s, a1);
if ( a2 )
{
KEEP_RUNNING = 0;
zExitCode = a2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, int a2)
{
struct tm *v2; // rax
int result; // eax
time_t timer; // [rsp+8h] [rbp-90h] BYREF
char s[136]; // [rsp+10h] [rbp-88h] BYREF

time(&timer);
v2 = localtime(&timer);
strftime(s, 0x64uLL, "%y-%m-%d %H:%M:%S", v2);
result = fprintf(stderr, "%s:%s\r\n", s, a1);
if ( a2 )
{
KEEP_RUNNING = 0;
zExitCode = a2;
}
return result;
}

original_code:
void log_entry(char *text, int doexit) {
    time_t rawtime;
    struct tm *timeinfo;
    char buf[100];
    time(&rawtime);
    timeinfo = localtime(&rawtime);
    strftime(buf, 100, "%y-%m-%d %H:%M:%S", timeinfo);
    fprintf(stderr, "%s:%s\r\n", buf, text);
    if (doexit != 0) {
        KEEP_RUNNING = 0;
        zExitCode = doexit;
    }
}

canonical_original_code:
void log_entry(char *text, int doexit) {
    long rawtime;
    struct tm *timeinfo;
    char buf[100];
    time(&rawtime);
    timeinfo = localtime(&rawtime);
    strftime(buf, 100, "%y-%m-%d %H:%M:%S", timeinfo);
    fprintf(stderr, "%s:%s\r\n", buf, text);
    if (doexit != 0) {
        KEEP_RUNNING = 0;
        zExitCode = doexit;
    }
}

variable_types:
text
char *

variable_types: doexit int

variable_types: rawtime long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
buf
char [100]


deviceFindCallback

decompiled_code:
__int64 __fastcall deviceFindCallback(_DWORD *a1, __int64 a2, _QWORD *a3)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(*a3, &unk_444, v4);
*a1 = v4[0];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, __int64 a2, _QWORD *a3)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(*a3, &unk_444, v4);
*a1 = v4[0];
return 0LL;
}

original_code:
static int deviceFindCallback(void *retval, int numCols, char **colText,
char **colName) {
    int i;
    sscanf(colText[0], "%i", &i);
    *(int*) retval = i;
    return 0;
}

canonical_original_code:
static int deviceFindCallback(void *retval, int numCols, char **colText, char **colName) {
    int i;
    sscanf(colText[0], "%i", &i);
    *(int *) retval = i;
    return 0;
}

variable_types:
retval
void *

variable_types: numCols int

variable_types:
colText
char **

variable_types:
colName
char **


main

repo: daschaich/susy

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // [rsp+0h] [rbp-28h] BYREF
int v4; // [rsp+4h] [rbp-24h] BYREF
char v5[4]; // [rsp+8h] [rbp-20h] BYREF
int v6; // [rsp+Ch] [rbp-1Ch] BYREF
double v7; // [rsp+10h] [rbp-18h] BYREF
double v8[2]; // [rsp+18h] [rbp-10h] BYREF

scanf("%d", &v3);
printf("Nroot %d\n\n", (unsigned int)v3);
scanf("%d", &v4);
scanf("%d", v5);
scanf("%le", &v7);
scanf("%le", v8);
scanf("%d", &v6);
work(v3, v4, v7, v8[0], v6, "OMIT", "MD");
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // [rsp+0h] [rbp-28h] BYREF
int v4; // [rsp+4h] [rbp-24h] BYREF
char v5[4]; // [rsp+8h] [rbp-20h] BYREF
int v6; // [rsp+Ch] [rbp-1Ch] BYREF
double v7; // [rsp+10h] [rbp-18h] BYREF
double v8[2]; // [rsp+18h] [rbp-10h] BYREF

scanf("%d", &v3);
printf("Nroot %d\n\n", (unsigned int)v3);
scanf("%d", &v4);
scanf("%d", v5);
scanf("%le", &v7);
scanf("%le", v8);
scanf("%d", &v6);
func1(v3, v4, v7, v8[0], v6, "OMIT", "MD");
}

original_code:
int main(int argc, char* argv[]) {
  int i, order;
  double alpha, epsilon, delta, err, c[1000 + 1];
  if (argc != 3) {
    printf("Usage: %s epsilon delta\n", argv[0]);
    return -1;
  }
  epsilon = atof(argv[1]);
  delta = atof(argv[2]);
  squareroot(delta, epsilon, c, &order, &err);
  printf("order = %d;\n", order);
  printf("epsilon = %.8g;\n", epsilon);
  printf("err = %.8g;\n\n", err);
  for (alpha = 0; alpha <= 3.0; alpha += 0.5) {
    printf("star(%.2g) = %.8g;\n", alpha,
           star(delta, epsilon, order, c, alpha));
  }
  printf("\n");
  for (i = 0; i <= order; i++)
    printf("coeffs[%d] = %.16g;\n", i, c[i]);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int i; int order;
  double alpha; double epsilon; double delta; double err; double c[-1];
  if (argc != 3) {
    printf("Usage: %s epsilon delta\n", argv[0]);
    return -1;
  }
  epsilon = atof(argv[1]);
  delta = atof(argv[2]);
  squareroot(delta, epsilon, c, &order, &err);
  printf("order = %d;\n", order);
  printf("epsilon = %.8g;\n", epsilon);
  printf("err = %.8g;\n\n", err);
  for (alpha = 0; alpha <= 3.0; alpha += 0.5) {
    printf("star(%.2g) = %.8g;\n", alpha,
           star(delta, epsilon, order, c, alpha));
  }
  printf("\n");
  for (i = 0; i <= order; i++)
    printf("coeffs[%d] = %.16g;\n", i, c[i]);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: order int

variable_types: alpha double

variable_types: epsilon double

variable_types: delta double

variable_types: err double

variable_types:
c
double [-1]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rbx
int *v4; // rbp
pthread_t *v5; // r12
pthread_t v6; // rdi
int v8; // [rsp+Ch] [rbp-7Ch]
pthread_t newthread[4]; // [rsp+10h] [rbp-78h] BYREF
int arg[12]; // [rsp+30h] [rbp-58h] BYREF
char v11; // [rsp+60h] [rbp-28h] BYREF

printf("Max int: ");
__isoc99_scanf();
v3 = (int *)newthread;
arg[0] = 1;
v4 = arg;
v5 = newthread;
arg[1] = v8 / 4;
arg[3] = v8 / 4 + 1;
arg[4] = v8 / 4;
arg[9] = 3 * (v8 / 4) + 1;
arg[6] = 2 * (v8 / 4) + 1;
arg[7] = v8 / 4;
arg[10] = v8 / 4 + v8 % 4;
do
{
pthread_create(v5, 0LL, worker, v4);
v4 += 3;
++v5;
}
while ( &v11 != (char *)v4 );
puts("Threads started");
do
{
v6 = *(_QWORD *)v3;
v3 += 2;
pthread_join(v6, 0LL);
}
while ( v3 != arg );
puts("Threads finished");
printf("Sum is %i\n", (unsigned int)(arg[11] + arg[8] + arg[2] + arg[5]));
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int max;
 printf("Max int: " );
 scanf("%i", &max);
 struct Work workList[4];
 pthread_t threadList[4];
 int chunkSize = max / 4;
 for (int i = 0; i < 4; i++) {
  workList[i].start = 1 + (i * chunkSize);
  workList[i].len = chunkSize;
  if (i == 4 - 1) {
   workList[i].len += (max % 4);
  }
 }
 for (int i = 0; i < 4; i++) {
  pthread_create(&threadList[i], ((void *)0), &worker, &workList[i]);
 }
 printf("Threads started\n");
 for (int i = 0; i < 4; i++) {
  pthread_join(threadList[i], ((void *)0));
 }
 printf("Threads finished\n");
 int global_sum = 0;
 for (int i = 0; i < 4; i++) {
  global_sum += workList[i].sum;
 }
 printf("Sum is %i\n", global_sum);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int max;
 printf("Max int: " );
 scanf("%i", &max);
 struct Work workList[4];
 unsigned long threadList[4];
 int chunkSize = max / 4;
 for (int i = 0; i < 4; i++) {
  workList[i].start = 1 + (i * chunkSize);
  workList[i].len = chunkSize;
  if (i == 4 - 1) {
   workList[i].len += (max % 4);
  }
 }
 for (int i = 0; i < 4; i++) {
  pthread_create(&threadList[i], ((void *)0), &worker, &workList[i]);
 }
 printf("Threads started\n");
 for (int i = 0; i < 4; i++) {
  pthread_join(threadList[i], ((void *)0));
 }
 printf("Threads finished\n");
 int global_sum = 0;
 for (int i = 0; i < 4; i++) {
  global_sum += workList[i].sum;
 }
 printf("Sum is %i\n", global_sum);
 return 0;
}

variable_types:
argv
char **

variable_types: max int

variable_types: struct Work { int start; int len; int sum; } [4]

variable_types:
threadList
unsigned long [4]

variable_types: chunkSize int

variable_types: i int


worker

original_code:
void *worker(void *arg)
{
 struct Work *work = arg;
 work->sum = 0;
 for (int i = work->start; i < work->start + work->len; i++) {
  work->sum += i;
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct Work { int start; int len; int sum; } *


main

repo: davidamaro/sw

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
time_t *v4; // rbp
_DWORD *v5; // rax
_DWORD *v6; // r14
int v7; // eax
const char *v8; // r15
size_t v9; // r15
struct tm *v10; // rax
__int64 v11; // rcx
struct tm *v12; // r8
char *v13; // rax
char *v14; // rax
time_t v15; // rax
WINDOW *v16; // rdi
char *v17; // rax
double v18; // xmm0_8
char *src; // [rsp+8h] [rbp-60h]
char v20; // [rsp+1Bh] [rbp-4Dh] BYREF
int v21; // [rsp+1Ch] [rbp-4Ch] BYREF
int longind; // [rsp+20h] [rbp-48h] BYREF
int v23; // [rsp+24h] [rbp-44h] BYREF
time_t timer; // [rsp+28h] [rbp-40h] BYREF

v3 = 0LL;
v21 = 20;
v4 = (time_t *)malloc(8uLL);
v5 = malloc(4uLL);
longind = 0;
*v5 = 0;
v6 = v5;
v20 = 109;
while ( 1 )
{
v7 = getopt_long(argc, (char *const *)argv, "t:s:", &long_options, &longind);
if ( v7 == -1 )
break;
if ( v7 == 115 )
{
src = optarg;
v9 = strlen(optarg);
v3 = malloc((int)v9 + 1);
memcpy(v3, src, v9 + 1);
}
else if ( v7 == 116 )
{
v8 = optarg;
v21 = atoi(optarg);
v20 = v8[strlen(v8) - 1];
}
}
initscr();
noecho();
cbreak();
wtimeout(_bss_start, 500);
*v4 = time(0LL);
v10 = localtime(v4);
setTime(&v21, &v20, v10, v11, v10);
timer = mktime(v12);
v13 = ctime(v4);
mvprintw(0, 0, "Tiempo inicial: %s", v13);
if ( !v3 )
{
v3 = malloc(0x17uLL);
strcpy((char *)v3, "Tarea no especificada.");
}
mvprintw(5, 0, "Tarea: %s", (const char *)v3);
while ( 1 )
{
v18 = difftime(timer, *v4);
if ( v18 <= 0.0 )
break;
v14 = ctime(&timer);
mvprintw(1, 0, "Tiempo final: %s", v14);
v15 = time(0LL);
v16 = _bss_start;
*v4 = v15;
v23 = wgetch(v16);
eleccion(v6, &v23, v4);
if ( *v6 )
timer = *v4 + (int)v18;
v17 = ctime(v4);
mvprintw(2, 0, "Tiempo actual: %s", v17);
}
endwin();
free(v6);
free(v4);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
time_t *v4; // rbp
_DWORD *v5; // rax
_DWORD *v6; // r14
int v7; // eax
const char *v8; // r15
size_t v9; // r15
struct tm *v10; // rax
__int64 v11; // rcx
struct tm *v12; // r8
char *v13; // rax
char *v14; // rax
time_t v15; // rax
WINDOW *v16; // rdi
char *v17; // rax
double v18; // xmm0_8
char *src; // [rsp+8h] [rbp-60h]
char v20; // [rsp+1Bh] [rbp-4Dh] BYREF
int v21; // [rsp+1Ch] [rbp-4Ch] BYREF
int longind; // [rsp+20h] [rbp-48h] BYREF
int v23; // [rsp+24h] [rbp-44h] BYREF
time_t timer; // [rsp+28h] [rbp-40h] BYREF

v3 = 0LL;
v21 = 20;
v4 = (time_t *)malloc(8uLL);
v5 = malloc(4uLL);
longind = 0;
*v5 = 0;
v6 = v5;
v20 = 109;
while ( 1 )
{
v7 = getopt_long(argc, (char *const *)argv, "t:s:", &long_options, &longind);
if ( v7 == -1 )
break;
if ( v7 == 115 )
{
src = optarg;
v9 = strlen(optarg);
v3 = malloc((int)v9 + 1);
memcpy(v3, src, v9 + 1);
}
else if ( v7 == 116 )
{
v8 = optarg;
v21 = atoi(optarg);
v20 = v8[strlen(v8) - 1];
}
}
initscr();
noecho();
cbreak();
wtimeout(_bss_start, 500);
*v4 = time(0LL);
v10 = localtime(v4);
func7(&v21, &v20, v10, v11, v10);
timer = mktime(v12);
v13 = ctime(v4);
mvprintw(0, 0, "Tiempo inicial: %s", v13);
if ( !v3 )
{
v3 = malloc(0x17uLL);
strcpy((char *)v3, "Tarea no especificada.");
}
mvprintw(5, 0, "Tarea: %s", (const char *)v3);
while ( 1 )
{
v18 = difftime(timer, *v4);
if ( v18 <= 0.0 )
break;
v14 = ctime(&timer);
mvprintw(1, 0, "Tiempo final: %s", v14);
v15 = time(0LL);
v16 = _bss_start;
*v4 = v15;
v23 = wgetch(v16);
func8(v6, &v23, v4);
if ( *v6 )
timer = *v4 + (int)v18;
v17 = ctime(v4);
mvprintw(2, 0, "Tiempo actual: %s", v17);
}
endwin();
free(v6);
free(v4);
exit(0);
}

original_code:
int main(int argc, char *argv[]) {
  struct tm *tiempo;
  time_t final;
  time_t *actual;
  int valor = 20;
  double diferencia = 0;
  actual = (time_t *)malloc(sizeof(time_t));
  int *sesion = ((void *)0);
  sesion = (int *)malloc(sizeof(int));
  *sesion = 0;
  int long_index = 0;
  int opt = 0;
  int longitud = 0;
  char tipo = 'm';
  char *tarea = ((void *)0);
  while ((opt = getopt_long(argc, argv, "t:s:",
          long_options, &long_index)) != -1) {
    switch(opt) {
      case 't':
        valor = atoi(optarg);
        tipo = *(optarg + strlen(optarg) - 1);
        break;
      case 's':
        longitud = strlen(optarg);
        tarea = (char *)malloc(longitud + 1);
        strcpy(tarea, optarg);
      default:
        break;
    }
  }
  initscr();
  noecho();
  cbreak();
  wtimeout(stdscr,(500));
  *actual = time(((void *)0));
  tiempo = localtime(actual);
  setTime(&valor, &tipo, tiempo);
  final = mktime(tiempo);
  mvprintw(0,0,"Tiempo inicial: %s", ctime(actual));
  if (tarea == ((void *)0)) {
    longitud = strlen("Tarea no especificada.");
    tarea = (char *)malloc(longitud + 1);
    strcpy(tarea, "Tarea no especificada.");
  }
  mvprintw(5,0,"Tarea: %s", tarea);
  while ((diferencia = difftime(final, *actual)) > 0) {
    mvprintw(1,0,"Tiempo final:   %s", ctime(&final));
    *actual = time(((void *)0));
    int c = wgetch(stdscr);
    eleccion(sesion, &c, actual);
    if (*sesion) {
      final = *actual + (int) diferencia;
    }
    mvprintw(2,0,"Tiempo actual:  %s", ctime(actual));
  }
  endwin();
  if (sesion != ((void *)0)) free(sesion);
  if (actual != ((void *)0)) free(actual);
  exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
  struct tm *tiempo;
  long final;
  long *actual;
  int valor = 20;
  double diferencia = 0;
  actual = (long *)malloc(sizeof(time_t));
  int *sesion = ((void *)0);
  sesion = (int *)malloc(sizeof(int));
  *sesion = 0;
  int long_index = 0;
  int opt = 0;
  int longitud = 0;
  char tipo = 'm';
  char *tarea = ((void *)0);
  while ((opt = getopt_long(argc, argv, "t:s:",
          long_options, &long_index)) != -1) {
    switch(opt) {
      case 't':
        valor = atoi(optarg);
        tipo = *(optarg + strlen(optarg) - 1);
        break;
      case 's':
        longitud = strlen(optarg);
        tarea = (char *)malloc(longitud + 1);
        strcpy(tarea, optarg);
      default:
        break;
    }
  }
  initscr();
  noecho();
  cbreak();
  wtimeout(stdscr,(500));
  *actual = time(((void *)0));
  tiempo = localtime(actual);
  setTime(&valor, &tipo, tiempo);
  final = mktime(tiempo);
  mvprintw(0,0,"Tiempo inicial: %s", ctime(actual));
  if (tarea == ((void *)0)) {
    longitud = strlen("Tarea no especificada.");
    tarea = (char *)malloc(longitud + 1);
    strcpy(tarea, "Tarea no especificada.");
  }
  mvprintw(5,0,"Tarea: %s", tarea);
  while ((diferencia = difftime(final, *actual)) > 0) {
    mvprintw(1,0,"Tiempo final:   %s", ctime(&final));
    *actual = time(((void *)0));
    int c = wgetch(stdscr);
    eleccion(sesion, &c, actual);
    if (*sesion) {
      final = *actual + (int) diferencia;
    }
    mvprintw(2,0,"Tiempo actual:  %s", ctime(actual));
  }
  endwin();
  if (sesion != ((void *)0)) free(sesion);
  if (actual != ((void *)0)) free(actual);
  exit(0);
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: final long

variable_types:
actual
long *

variable_types: valor int

variable_types: diferencia double

variable_types:
sesion
int *

variable_types: opt int

variable_types: longitud int

variable_types: tipo char

variable_types:
tarea
char *

variable_types: c int


setTime

decompiled_code:
__int64 __fastcall setTime(_DWORD *a1, char *a2, _DWORD *a3)
{
char v3; // al
__int64 result; // rax

v3 = *a2;
if ( *a2 != 115 )
{
if ( v3 != 109 )
{
if ( v3 != 104 )
{
result = (unsigned int)*a1;
*a3 += result;
return result;
}
LABEL_8:
result = (unsigned int)*a1;
a3[2] += result;
return result;
}
goto LABEL_6;
}
*a3 += *a1;
result = (unsigned __int8)*a2;
if ( (_BYTE)result == 109 )
{
LABEL_6:
a3[1] += *a1;
result = (unsigned __int8)*a2;
}
if ( (_BYTE)result == 104 )
goto LABEL_8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, char *a2, _DWORD *a3)
{
char v3; // al
__int64 result; // rax

v3 = *a2;
if ( *a2 != 115 )
{
if ( v3 != 109 )
{
if ( v3 != 104 )
{
result = (unsigned int)*a1;
*a3 += result;
return result;
}
LABEL_8:
result = (unsigned int)*a1;
a3[2] += result;
return result;
}
goto LABEL_6;
}
*a3 += *a1;
result = (unsigned __int8)*a2;
if ( (_BYTE)result == 109 )
{
LABEL_6:
a3[1] += *a1;
result = (unsigned __int8)*a2;
}
if ( (_BYTE)result == 104 )
goto LABEL_8;
return result;
}

original_code:
void setTime(int *valor, char *tipo, struct tm *tiempo) {
  if (*tipo == 's' || *tipo == 'm' || *tipo == 'h') {
    if (*tipo == 's') tiempo->tm_sec += *valor;
    if (*tipo == 'm') tiempo->tm_min += *valor;
    if (*tipo == 'h') tiempo->tm_hour += *valor;
  }
  else tiempo->tm_sec += *valor;
}

variable_types:
valor
int *

variable_types:
tipo
char *

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


eleccion

decompiled_code:
int __fastcall eleccion(_DWORD *a1, int *a2, void *a3)
{
int result; // eax

result = *a2;
if ( *a2 == 32 )
{
if ( *a1 )
{
result = mvprintw(3, 0, " ");
*a1 = 0;
}
else
{
*a1 = 1;
result = mvprintw(3, 0, "Pausado");
}
}
else if ( result == 115 )
{
endwin();
if ( a3 )
free(a3);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(_DWORD *a1, int *a2, void *a3)
{
int result; // eax

result = *a2;
if ( *a2 == 32 )
{
if ( *a1 )
{
result = mvprintw(3, 0, " ");
*a1 = 0;
}
else
{
*a1 = 1;
result = mvprintw(3, 0, "Pausado");
}
}
else if ( result == 115 )
{
endwin();
if ( a3 )
free(a3);
exit(1);
}
return result;
}

original_code:
void eleccion(int *menu, int *c, time_t *actual) {
  switch (*c) {
    case 's':
      endwin();
      if (actual != ((void *)0)) free(actual);
      exit(1);
    case ' ':
      if (*menu) {
        mvprintw(3,0,"     ");
        *menu = 0;
      }
      else {
        *menu = 1;
        mvprintw(3,0,"Pausado");
      }
      break;
    default:
      break;
  }
}

canonical_original_code:
void eleccion(int *menu, int *c, long *actual) {
  switch (*c) {
    case 's':
      endwin();
      if (actual != ((void *)0)) free(actual);
      exit(1);
    case ' ':
      if (*menu) {
        mvprintw(3,0,"     ");
        *menu = 0;
      }
      else {
        *menu = 1;
        mvprintw(3,0,"Pausado");
      }
      break;
    default:
      break;
  }
}

variable_types:
menu
int *

variable_types:
c
int *


isPE

repo: davidgfnet/exec-analysis

decompiled_code:
_BOOL8 __fastcall isPE(_BYTE *a1)
{
_BOOL8 result; // rax

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

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

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

original_code:
int isPE(unsigned char * pBuffer) {
 return (pBuffer[0] == 0x4d && pBuffer[1] == 0x5a);
}

canonical_original_code:
int isPE(unsigned char *pBuffer) {
 return (pBuffer[0] == 0x4d && pBuffer[1] == 0x5a);
}

variable_types:
pBuffer
unsigned char *


floatabs

repo: davidgfnet/math-evaluator

decompiled_code:
__m128 __fastcall floatabs(__m128 result)
{
if ( result.m128_f32[0] < 0.0 )
result = _mm_xor_ps(result, (__m128)LC1);
return result;
}

canonical_decompiled_code:
__m128 __fastcall func0(__m128 result)
{
if ( result.m128_f32[0] < 0.0 )
result = _mm_xor_ps(result, (__m128)LC1);
return result;
}

original_code: float floatabs(float a) { if (a < 0) return -a; return a; }

variable_types: a float

return_type: float


ReadLiteral

original_code:
float ReadLiteral(const char * string, int length) {
 float sign = 1;
 if (*string == '-') { sign = -1; string++; length--; }
 int i = 0;
 int p1 = 0, p2 = 0;
 while (i < length) {
  if (string[i] == '.') break;
  p1 = p1 * 10;
  p1 = p1 + (int)(string[i]-'0');
  i++;
 }
 if (string[i++] != '.') {
  float ret = p1;
  return sign*ret;
 }else{
  float div = 1;
  while (i < length) {
   p2 = p2 * 10;
   p2 = p2 + (int)(string[i]-'0');
   div *= 10;
   i++;
  }
  float ret = p1; float ret2 = p2;
  ret2 = ret2 / div;
  return sign*(ret+ret2);
 }
}

canonical_original_code:
float ReadLiteral(char *string, int length) {
 float sign = 1;
 if (*string == '-') { sign = -1; string++; length--; }
 int i = 0;
 int p1 = 0; int p2 = 0;
 while (i < length) {
  if (string[i] == '.') break;
  p1 = p1 * 10;
  p1 = p1 + (int)(string[i]-'0');
  i++;
 }
 if (string[i++] != '.') {
  float ret = p1;
  return sign*ret;
 }else{
  float div = 1;
  while (i < length) {
   p2 = p2 * 10;
   p2 = p2 + (int)(string[i]-'0');
   div *= 10;
   i++;
  }
  float ret = p1; float ret2 = p2;
  ret2 = ret2 / div;
  return sign*(ret+ret2);
 }
}

variable_types:
string
char *

variable_types: length int

variable_types: sign float

variable_types: i int

variable_types: ret float

variable_types: div float


SearchCloseParenthesis

decompiled_code:
__int64 __fastcall SearchCloseParenthesis(__int64 a1, int a2)
{
__int64 v2; // rcx
__int64 v3; // rax
int v4; // esi
char v5; // dl
unsigned int v6; // er8

if ( a2 > 0 )
{
v2 = a2;
v3 = 0LL;
v4 = 0;
do
{
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v3);
v6 = v3;
if ( v5 != 40 )
break;
++v3;
++v4;
if ( v3 == v2 )
return 0;
}
if ( v5 == 41 )
{
if ( !v4 )
return v6;
--v4;
}
++v3;
}
while ( v3 != v2 );
}
return 0;
}

original_code:
int SearchCloseParenthesis(const char * string, int length) {
 int i = 0, nump = 0;
 while (i < length) {
  if (string[i] == '(') nump++;
  else if (string[i] == ')') {
   if (nump == 0) return i;
   nump--;
  }
  i++;
 }
 return 0;
}

canonical_original_code:
int SearchCloseParenthesis(char *string, int length) {
 int i = 0; int nump = 0;
 while (i < length) {
  if (string[i] == '(') nump++;
  else if (string[i] == ')') {
   if (nump == 0) return i;
   nump--;
  }
  i++;
 }
 return 0;
}

variable_types: nump int


SearchCloseParenthesisInv

decompiled_code:
__int64 __fastcall SearchCloseParenthesisInv(__int64 a1, int a2)
{
int v2; // esi
__int64 v3; // rax
int v4; // ecx
char v5; // dl
unsigned int v6; // er8

v2 = a2 - 1;
if ( v2 >= 0 )
{
v3 = v2;
v4 = 0;
do
{
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v3);
v6 = v3;
if ( v5 != 41 )
break;
--v3;
++v4;
if ( (int)v3 < 0 )
return 0;
}
if ( v5 == 40 )
{
if ( !v4 )
return v6;
--v4;
}
--v3;
}
while ( (int)v3 >= 0 );
}
return 0;
}

original_code:
int SearchCloseParenthesisInv(const char * string, int length) {
 int i = length-1, nump = 0;
 while (i >= 0) {
  if (string[i] == ')') nump++;
  else if (string[i] == '(') {
   if (nump == 0) return i;
   nump--;
  }
  i--;
 }
 return 0;
}

canonical_original_code:
int SearchCloseParenthesisInv(char *string, int length) {
 int i = length-1; int nump = 0;
 while (i >= 0) {
  if (string[i] == ')') nump++;
  else if (string[i] == '(') {
   if (nump == 0) return i;
   nump--;
  }
  i--;
 }
 return 0;
}


original_code:
struct expression * CreateExpressionFromString_int (const char * string, int length, struct expression * ret) {
 int i,j,k;
 int changed = 1;
 while (changed) {
  changed = 0;
  if (length > 2) {
   if (string[0] == '(') {
   if (SearchCloseParenthesis(&string[1],length-1) == length-2) {
    string++;
    length-=2;
    changed = 1;
   }
   }
  }
 }
 int literal = 1;
 for (i = 1; i < length; i++)
  if (!((string[i] >= '0' && string[i] <= '9') || string[i] == '.')) { literal = 0; break; }
 if (!((string[0] >= '0' && string[0] <= '9') || string[0] == '.' || string[0] == '-')) literal = 0;
 if (literal == 1) {
  ret->type = eLiteral;
  ret->evalue.literal_value = ReadLiteral(string,length);
  return ret+1;
 }
 if (length == 1) {
  ret->type = eVariable;
  ret->evalue.var = *string;
  return ret+1;
 }
 for (i = length-1; i >= 0; i--) {
  if (string[i] == '+' || string[i] == '-') {
   ret->type = eParent;
   if (string[i] == '+') ret->evalue.child.op = mAdd;
   else ret->evalue.child.op = mSub;
   ret->evalue.child.e1 = ret +1;
   ret->evalue.child.e2 = CreateExpressionFromString_int(string,i,ret->evalue.child.e1);
   return CreateExpressionFromString_int(&string[i+1],length-i-1,ret->evalue.child.e2);
  }
  if (string[i] == ')') {
   j = SearchCloseParenthesisInv(string,i);
   i = j-1+1;
  }
 }
 for (i = length-1; i >= 0; i--) {
  if (string[i] == '*' || string[i] == '/') {
   ret->type = eParent;
   if (string[i] == '*') ret->evalue.child.op = mMul;
   else ret->evalue.child.op = mDiv;
   ret->evalue.child.e1 = ret +1;
   ret->evalue.child.e2 = CreateExpressionFromString_int(string,i,ret->evalue.child.e1);
   return CreateExpressionFromString_int(&string[i+1],length-i-1,ret->evalue.child.e2);
  }
  if (string[i] == ')') {
   j = SearchCloseParenthesisInv(string,i);
   i = j-1+1;
  }
 }
 for (i = 0; i < length; i++) {
  if (string[i] == '(') {
   j = SearchCloseParenthesis(&string[i+1],length -i -1);
   i = i+1+ j+1;
  }
  if (string[i] == '^') {
   ret->type = eParent;
   ret->evalue.child.op = mPow;
   ret->evalue.child.e1 = ret +1;
   ret->evalue.child.e2 = CreateExpressionFromString_int(string,i,ret->evalue.child.e1);
   return CreateExpressionFromString_int(&string[i+1],length-i-1,ret->evalue.child.e2);
  }
 }
 for (i = 0; i < length; i++) {
  if (string[i] == '(') {
   for (j = 0; j < 9; j++) {
    if (_mem_compare(string,function_names[j].fname,_internal_strlen(function_names[j].fname)) == 0) {
     ret->type = eFunction;
     ret->evalue.function.func = function_names[j].fnumber;
     ret->evalue.function.e = ret+1;
     return CreateExpressionFromString_int(&string[i+1],length-i-1-1,ret->evalue.function.e);
    }
   }
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct expression *CreateExpressionFromString_int(char *string, int length, struct expression *ret) {
 int i; int j; int k;
 int changed = 1;
 while (changed) {
  changed = 0;
  if (length > 2) {
   if (string[0] == '(') {
   if (SearchCloseParenthesis(&string[1],length-1) == length-2) {
    string++;
    length-=2;
    changed = 1;
   }
   }
  }
 }
 int literal = 1;
 for (i = 1; i < length; i++)
  if (!((string[i] >= '0' && string[i] <= '9') || string[i] == '.')) { literal = 0; break; }
 if (!((string[0] >= '0' && string[0] <= '9') || string[0] == '.' || string[0] == '-')) literal = 0;
 if (literal == 1) {
  ret->type = eLiteral;
  ret->evalue.literal_value = ReadLiteral(string,length);
  return ret+1;
 }
 if (length == 1) {
  ret->type = eVariable;
  ret->evalue.var = *string;
  return ret+1;
 }
 for (i = length-1; i >= 0; i--) {
  if (string[i] == '+' || string[i] == '-') {
   ret->type = eParent;
   if (string[i] == '+') ret->evalue.child.op = mAdd;
   else ret->evalue.child.op = mSub;
   ret->evalue.child.e1 = ret +1;
   ret->evalue.child.e2 = CreateExpressionFromString_int(string,i,ret->evalue.child.e1);
   return CreateExpressionFromString_int(&string[i+1],length-i-1,ret->evalue.child.e2);
  }
  if (string[i] == ')') {
   j = SearchCloseParenthesisInv(string,i);
   i = j-1+1;
  }
 }
 for (i = length-1; i >= 0; i--) {
  if (string[i] == '*' || string[i] == '/') {
   ret->type = eParent;
   if (string[i] == '*') ret->evalue.child.op = mMul;
   else ret->evalue.child.op = mDiv;
   ret->evalue.child.e1 = ret +1;
   ret->evalue.child.e2 = CreateExpressionFromString_int(string,i,ret->evalue.child.e1);
   return CreateExpressionFromString_int(&string[i+1],length-i-1,ret->evalue.child.e2);
  }
  if (string[i] == ')') {
   j = SearchCloseParenthesisInv(string,i);
   i = j-1+1;
  }
 }
 for (i = 0; i < length; i++) {
  if (string[i] == '(') {
   j = SearchCloseParenthesis(&string[i+1],length -i -1);
   i = i+1+ j+1;
  }
  if (string[i] == '^') {
   ret->type = eParent;
   ret->evalue.child.op = mPow;
   ret->evalue.child.e1 = ret +1;
   ret->evalue.child.e2 = CreateExpressionFromString_int(string,i,ret->evalue.child.e1);
   return CreateExpressionFromString_int(&string[i+1],length-i-1,ret->evalue.child.e2);
  }
 }
 for (i = 0; i < length; i++) {
  if (string[i] == '(') {
   for (j = 0; j < 9; j++) {
    if (_mem_compare(string,function_names[j].fname,_internal_strlen(function_names[j].fname)) == 0) {
     ret->type = eFunction;
     ret->evalue.function.func = function_names[j].fnumber;
     ret->evalue.function.e = ret+1;
     return CreateExpressionFromString_int(&string[i+1],length-i-1-1,ret->evalue.function.e);
    }
   }
  }
 }
 return ((void *)0);
}

variable_types:
ret
struct expression *

variable_types: j int

variable_types: k int

variable_types: changed int

variable_types: literal int

return_type: struct expression { enum expType { eLiteral=0, eVariable=1, eFunction=2, eParent=3 } type; union evalue { float literal_value; char var; struct sfunction { enum math_function { fSin=0, fCos=1, fTan=2, fASin=3, fACos=4, fATan=5, fAbs=6, fLog=7, fLn=8 } func; struct expression *e; } function; struct schild { enum math_operation { mAdd=0, mSub=1, mMul=2, mDiv=3, mMod=4, mPow=5, mRoot=6 } op; struct expression *e1; struct expression *e2; } child; } evalue; } *

user_defined_types: struct expression { enum expType type; union evalue evalue; }

user_defined_types: union evalue { float literal_value; char var; struct sfunction function; struct schild child; }

user_defined_types: struct sfunction { enum math_function func; struct expression *e; }

user_defined_types: struct schild { enum math_operation op; struct expression *e1; struct expression *e2; }


CreateExpressionFromString

original_code:
struct expression * CreateExpressionFromString (const char * string) {
 char * good_expr = (char*)malloc(_internal_strlen(string)+1);
 char * tptr = good_expr;
 int len = 0;
 while (*string != 0) {
  if (*string != ' ') {
   *(tptr++) = *string;
   len++;
  }
  string++;
 }
 int i; int num_nodes = 0;
 for (i = 0; i < len; i++) {
  switch (good_expr[i]) {
  case '+': case '-': case '*': case '/': case '%': case '^':
   num_nodes++; break;
  default:
   if ((good_expr[i] >= '0' && good_expr[i] <= '9') || good_expr[i] == '.') {
    num_nodes++;
    while ((good_expr[i+1] >= '0' && good_expr[i+1] <= '9') || good_expr[i+1] == '.') i++;
   }
   if (good_expr[i] >= 'a' && good_expr[i] <= 'z') {
    num_nodes++;
    while (good_expr[i+1] >= 'a' && good_expr[i+1] <= 'z') i++;
   }
   break;
  }
 }
 struct expression * elist = (struct expression *)malloc((num_nodes)*sizeof(struct expression));
 CreateExpressionFromString_int(&good_expr[0],len,elist);
 free(good_expr);
 return elist;
}

canonical_original_code:
struct expression *CreateExpressionFromString(char *string) {
 char *good_expr = (char*)malloc(_internal_strlen(string)+1);
 char *tptr = good_expr;
 int len = 0;
 while (*string != 0) {
  if (*string != ' ') {
   *(tptr++) = *string;
   len++;
  }
  string++;
 }
 int i; int num_nodes = 0;
 for (i = 0; i < len; i++) {
  switch (good_expr[i]) {
  case '+': case '-': case '*': case '/': case '%': case '^':
   num_nodes++; break;
  default:
   if ((good_expr[i] >= '0' && good_expr[i] <= '9') || good_expr[i] == '.') {
    num_nodes++;
    while ((good_expr[i+1] >= '0' && good_expr[i+1] <= '9') || good_expr[i+1] == '.') i++;
   }
   if (good_expr[i] >= 'a' && good_expr[i] <= 'z') {
    num_nodes++;
    while (good_expr[i+1] >= 'a' && good_expr[i+1] <= 'z') i++;
   }
   break;
  }
 }
 struct expression *elist = (struct expression *)malloc((num_nodes)*sizeof(struct expression));
 CreateExpressionFromString_int(&good_expr[0],len,elist);
 free(good_expr);
 return elist;
}

variable_types:
tptr
char *

variable_types: len int

variable_types: struct expression { enum expType { eLiteral=0, eVariable=1, eFunction=2, eParent=3 } type; union evalue { float literal_value; char var; struct sfunction { enum math_function { fSin=0, fCos=1, fTan=2, fASin=3, fACos=4, fATan=5, fAbs=6, fLog=7, fLn=8 } func; struct expression *e; } function; struct schild { enum math_operation { mAdd=0, mSub=1, mMul=2, mDiv=3, mMod=4, mPow=5, mRoot=6 } op; struct expression *e1; struct expression *e2; } child; } evalue; } *


EvaluateExpression

decompiled_code:
float __fastcall EvaluateExpression(__int64 a1, float *a2, float result)
{
unsigned int v3; // eax
char v4; // al
unsigned int v5; // eax
void (*v6)(void); // r12

v3 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 2 )
{
v6 = (void (*)(void))*(&function_pointers + *(unsigned int *)(a1 + 8));
EvaluateExpression(*(_QWORD *)(a1 + 16));
v6();
return result;
}
if ( v3 > 2 )
{
if ( v3 == 3 )
{
v5 = *(_DWORD *)(a1 + 8);
if ( v5 == 2 )
{
EvaluateExpression(*(_QWORD *)(a1 + 16));
EvaluateExpression(*(_QWORD *)(a1 + 24));
return result * result;
}
if ( v5 <= 2 )
{
if ( v5 )
{
EvaluateExpression(*(_QWORD *)(a1 + 16));
EvaluateExpression(*(_QWORD *)(a1 + 24));
result = result - result;
}
else
{
EvaluateExpression(*(_QWORD *)(a1 + 16));
EvaluateExpression(*(_QWORD *)(a1 + 24));
result = result + result;
}
return result;
}
if ( v5 == 3 )
{
EvaluateExpression(*(_QWORD *)(a1 + 16));
EvaluateExpression(*(_QWORD *)(a1 + 24));
return result / result;
}
}
return 0.0;
}
if ( !v3 )
return *(float *)(a1 + 8);
v4 = *(_BYTE *)a2;
if ( !*(_BYTE *)a2 )
return 0.0;
while ( *(_BYTE *)(a1 + 8) != v4 )
{
v4 = *((_BYTE *)a2 + 8);
a2 += 2;
if ( !v4 )
return 0.0;
}
return a2[1];
}

canonical_decompiled_code:
float __fastcall func8(__int64 a1, float *a2, float result)
{
unsigned int v3; // eax
char v4; // al
unsigned int v5; // eax
void (*v6)(void); // r12

v3 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 2 )
{
v6 = (void (*)(void))*(&function_pointers + *(unsigned int *)(a1 + 8));
func8(*(_QWORD *)(a1 + 16));
v6();
return result;
}
if ( v3 > 2 )
{
if ( v3 == 3 )
{
v5 = *(_DWORD *)(a1 + 8);
if ( v5 == 2 )
{
func8(*(_QWORD *)(a1 + 16));
func8(*(_QWORD *)(a1 + 24));
return result * result;
}
if ( v5 <= 2 )
{
if ( v5 )
{
func8(*(_QWORD *)(a1 + 16));
func8(*(_QWORD *)(a1 + 24));
result = result - result;
}
else
{
func8(*(_QWORD *)(a1 + 16));
func8(*(_QWORD *)(a1 + 24));
result = result + result;
}
return result;
}
if ( v5 == 3 )
{
func8(*(_QWORD *)(a1 + 16));
func8(*(_QWORD *)(a1 + 24));
return result / result;
}
}
return 0.0;
}
if ( !v3 )
return *(float *)(a1 + 8);
v4 = *(_BYTE *)a2;
if ( !*(_BYTE *)a2 )
return 0.0;
while ( *(_BYTE *)(a1 + 8) != v4 )
{
v4 = *((_BYTE *)a2 + 8);
a2 += 2;
if ( !v4 )
return 0.0;
}
return a2[1];
}

original_code:
float EvaluateExpression (struct expression * expr, struct type_variable * variables) {
 switch (expr->type) {
 case eLiteral:
  return expr->evalue.literal_value;
  break;
 case eVariable:
  while (variables->variable != 0) {
   if (expr->evalue.var == variables->variable)
    return variables->value;
   variables++;
  }
  return 0;
  break;
 case eFunction:
  return function_pointers[expr->evalue.function.func](EvaluateExpression(expr->evalue.function.e,variables));
  break;
 case eParent:
  switch (expr->evalue.child.op) {
   case mAdd:
    return EvaluateExpression(expr->evalue.child.e1,variables)+EvaluateExpression(expr->evalue.child.e2,variables); break;
   case mSub:
    return EvaluateExpression(expr->evalue.child.e1,variables)-EvaluateExpression(expr->evalue.child.e2,variables); break;
   case mMul:
    return EvaluateExpression(expr->evalue.child.e1,variables)*EvaluateExpression(expr->evalue.child.e2,variables); break;
   case mDiv:
    return EvaluateExpression(expr->evalue.child.e1,variables)/EvaluateExpression(expr->evalue.child.e2,variables); break;
   case mMod:
    return 0; break;
   case mPow:
    return 0; break;
   default: return 0; break;
  };
  break;
 default: return 0; break;
 };
}

canonical_original_code:
float EvaluateExpression(struct expression *expr, struct type_variable *variables) {
 switch (expr->type) {
 case eLiteral:
  return expr->evalue.literal_value;
  break;
 case eVariable:
  while (variables->variable != 0) {
   if (expr->evalue.var == variables->variable)
    return variables->value;
   variables++;
  }
  return 0;
  break;
 case eFunction:
  return function_pointers[expr->evalue.function.func](EvaluateExpression(expr->evalue.function.e,variables));
  break;
 case eParent:
  switch (expr->evalue.child.op) {
   case mAdd:
    return EvaluateExpression(expr->evalue.child.e1,variables)+EvaluateExpression(expr->evalue.child.e2,variables); break;
   case mSub:
    return EvaluateExpression(expr->evalue.child.e1,variables)-EvaluateExpression(expr->evalue.child.e2,variables); break;
   case mMul:
    return EvaluateExpression(expr->evalue.child.e1,variables)*EvaluateExpression(expr->evalue.child.e2,variables); break;
   case mDiv:
    return EvaluateExpression(expr->evalue.child.e1,variables)/EvaluateExpression(expr->evalue.child.e2,variables); break;
   case mMod:
    return 0; break;
   case mPow:
    return 0; break;
   default: return 0; break;
  };
  break;
 default: return 0; break;
 };
}

variable_types: struct type_variable { char variable; float value; } *

user_defined_types: enum expType { eLiteral=0, eVariable=1, eFunction=2, eParent=3 }

user_defined_types: enum math_function { fSin=0, fCos=1, fTan=2, fASin=3, fACos=4, fATan=5, fAbs=6, fLog=7, fLn=8 }

user_defined_types: enum math_operation { mAdd=0, mSub=1, mMul=2, mDiv=3, mMod=4, mPow=5, mRoot=6 }


DeleteExpression

decompiled_code:
// attributes: thunk
void DeleteExpression(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func9(void *ptr)
{
free(ptr);
}

original_code:
void DeleteExpression (struct expression * expr) {
 free(expr);
}

canonical_original_code:
void DeleteExpression(struct expression *expr) {
 free(expr);
}


main

original_code:
int main() {
 struct expression * ret = CreateExpressionFromString("(1-(1*5*(3*(9-3*1-3)/4)*2/3)-1*cos(3.1416))");
 printf("%f\n",EvaluateExpression(ret,((void *)0)));
 DeleteExpression(ret);
 ret = CreateExpressionFromString("2*2*(4*3)+2*2-3*1-1*6-5*6*(5-6+1)*(-1)");
 printf("%f\n",EvaluateExpression(ret,((void *)0)));
 DeleteExpression(ret);
 ret = CreateExpressionFromString("1/2/3/4/5+(4*1-(8*6*(-5))/3/2)");
 printf("%f\n",EvaluateExpression(ret,((void *)0)));
 DeleteExpression(ret);
 ret = CreateExpressionFromString("(((5*6))/(2*((2-1-1+1))))");
 printf("%f\n",EvaluateExpression(ret,((void *)0)));
 DeleteExpression(ret);
 struct type_variable vlist[3];
 vlist[0].variable = 'b';
 vlist[0].value = 1.6f;
 vlist[1].variable = 'c';
 vlist[1].value = -3.0f;
 vlist[2].variable = 0;
 ret = CreateExpressionFromString("(((5*c))/(2*((2-b-1+1))))");
 printf("%f\n",EvaluateExpression(ret,&vlist[0]));
 DeleteExpression(ret);
 return 0;
}

canonical_original_code:
int main() {
 struct expression *ret = CreateExpressionFromString("(1-(1*5*(3*(9-3*1-3)/4)*2/3)-1*cos(3.1416))");
 printf("%f\n",EvaluateExpression(ret,((void *)0)));
 DeleteExpression(ret);
 ret = CreateExpressionFromString("2*2*(4*3)+2*2-3*1-1*6-5*6*(5-6+1)*(-1)");
 printf("%f\n",EvaluateExpression(ret,((void *)0)));
 DeleteExpression(ret);
 ret = CreateExpressionFromString("1/2/3/4/5+(4*1-(8*6*(-5))/3/2)");
 printf("%f\n",EvaluateExpression(ret,((void *)0)));
 DeleteExpression(ret);
 ret = CreateExpressionFromString("(((5*6))/(2*((2-1-1+1))))");
 printf("%f\n",EvaluateExpression(ret,((void *)0)));
 DeleteExpression(ret);
 struct type_variable vlist[3];
 vlist[0].variable = 'b';
 vlist[0].value = 1.6f;
 vlist[1].variable = 'c';
 vlist[1].value = -3.0f;
 vlist[2].variable = 0;
 ret = CreateExpressionFromString("(((5*c))/(2*((2-b-1+1))))");
 printf("%f\n",EvaluateExpression(ret,&vlist[0]));
 DeleteExpression(ret);
 return 0;
}

variable_types: struct type_variable { char variable; float value; } [3]


notify

repo: davidgfnet/pecomparator

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

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

original_code:
void notify(const char * c) {
 printf("%s\n",c);
 exit(0);
}

canonical_original_code:
void notify(char *c) {
 printf("%s\n",c);
 exit(0);
}

variable_types:
c
char *


checkFileName

original_code:
int checkFileName(char fname[13], const unsigned char DIR_Name[11]){
    int i,j;
    for(i=0;i<8 && DIR_Name[i] != ' ';i++){
        fname[i] = DIR_Name[i];
    }
    if(DIR_Name[8] != ' '){
        fname[i++] = '.';
        for(j=8;j<=10 && DIR_Name[j] != ' ';j++,i++){
            fname[i] = DIR_Name[j];
        }
    }
    fname[i] = 0;
    return i;
}

canonical_original_code:
int checkFileName(char fname[13], unsigned char DIR_Name[11]){
    int i; int j;
    for(i=0;i<8 && DIR_Name[i] != ' ';i++){
        fname[i] = DIR_Name[i];
    }
    if(DIR_Name[8] != ' '){
        fname[i++] = '.';
        for(j=8;j<=10 && DIR_Name[j] != ' ';j++,i++){
            fname[i] = DIR_Name[j];
        }
    }
    fname[i] = 0;
    return i;
}

variable_types:
fname
char [13]


printInfo

decompiled_code:
int __fastcall printInfo(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8, unsigned __int8 a9)
{
_DWORD *v10; // rax
__int64 v11; // rsi
__int64 v12; // rcx
int v13; // edx
unsigned int v14; // ebp

printf("Number of FATs = %hhu\n", a9);
printf("Number of bytes per sector = %hu\n", *(unsigned __int16 *)((char *)&a8 + 3));
printf("Number of sectors per cluster = %hhu\n", BYTE5(a8));
printf("Number of reserved sectors = %hu\n", HIWORD(a8));
if ( a2 <= 2 )
{
v14 = 2;
v11 = 0LL;
}
else
{
v10 = (_DWORD *)(a1 + 8);
v11 = 0LL;
v12 = a1 + 4LL * (a2 - 3) + 12;
v13 = 0;
do
{
while ( !*v10 )
{
++v10;
++v13;
if ( v10 == (_DWORD *)v12 )
goto LABEL_6;
}
++v10;
v11 = (unsigned int)(v11 + 1);
}
while ( v10 != (_DWORD *)v12 );
LABEL_6:
v14 = v13 + 2;
}
printf("Number of allocated clusters = %d\n", v11);
return printf("Number of free clusters = %d\n", v14);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8, unsigned __int8 a9)
{
_DWORD *v10; // rax
__int64 v11; // rsi
__int64 v12; // rcx
int v13; // edx
unsigned int v14; // ebp

printf("Number of FATs = %hhu\n", a9);
printf("Number of bytes per sector = %hu\n", *(unsigned __int16 *)((char *)&a8 + 3));
printf("Number of sectors per cluster = %hhu\n", BYTE5(a8));
printf("Number of reserved sectors = %hu\n", HIWORD(a8));
if ( a2 <= 2 )
{
v14 = 2;
v11 = 0LL;
}
else
{
v10 = (_DWORD *)(a1 + 8);
v11 = 0LL;
v12 = a1 + 4LL * (a2 - 3) + 12;
v13 = 0;
do
{
while ( !*v10 )
{
++v10;
++v13;
if ( v10 == (_DWORD *)v12 )
goto LABEL_6;
}
++v10;
v11 = (unsigned int)(v11 + 1);
}
while ( v10 != (_DWORD *)v12 );
LABEL_6:
v14 = v13 + 2;
}
printf("Number of allocated clusters = %d\n", v11);
return printf("Number of free clusters = %d\n", v14);
}

original_code:
void printInfo(BOOTSECTOR be,unsigned int *FAT,unsigned int totalDataCluster){
    int i;
    int numOfAlloc = 0;
    int numOfFree = 0;
    printf("Number of FATs = %hhu\n",be.BPB_NumFATs);
    printf("Number of bytes per sector = %hu\n",be.BPB_BytsPerSec);
    printf("Number of sectors per cluster = %hhu\n",be.BPB_SecPerClus);
    printf("Number of reserved sectors = %hu\n",be.BPB_RsvdSecCnt);
    for(i=2;i<totalDataCluster;i++){
        if(FAT[i]==0){
            numOfFree++;
        }else{
            numOfAlloc++;
        }
    }
    printf("Number of allocated clusters = %d\n",numOfAlloc);
    printf("Number of free clusters = %d\n",numOfFree+2);
}

canonical_original_code:
void printInfo(struct BootEntry be, unsigned int *FAT, unsigned int totalDataCluster){
    int i;
    int numOfAlloc = 0;
    int numOfFree = 0;
    printf("Number of FATs = %hhu\n",be.BPB_NumFATs);
    printf("Number of bytes per sector = %hu\n",be.BPB_BytsPerSec);
    printf("Number of sectors per cluster = %hhu\n",be.BPB_SecPerClus);
    printf("Number of reserved sectors = %hu\n",be.BPB_RsvdSecCnt);
    for(i=2;i<totalDataCluster;i++){
        if(FAT[i]==0){
            numOfFree++;
        }else{
            numOfAlloc++;
        }
    }
    printf("Number of allocated clusters = %d\n",numOfAlloc);
    printf("Number of free clusters = %d\n",numOfFree+2);
}

variable_types: struct BootEntry { unsigned char BS_jmpBoot[3]; unsigned char BS_OEMName[8]; unsigned short BPB_BytsPerSec; unsigned char BPB_SecPerClus; unsigned short BPB_RsvdSecCnt; unsigned char BPB_NumFATs; unsigned short BPB_RootEntCnt; unsigned short BPB_TotSec16; unsigned char BPB_Media; unsigned short BPB_FATSz16; unsigned short BPB_SecPerTrk; unsigned short BPB_NumHeads; unsigned int BPB_HiddSec; unsigned int BPB_TotSec32; unsigned int BPB_FATSz32; unsigned short BPB_ExtFlags; unsigned short BPB_FSVer; unsigned int BPB_RootClus; unsigned short BPB_FSInfo; unsigned short BPB_BkBootSec; unsigned char BPB_Reserved[12]; unsigned char BS_DrvNum; unsigned char BS_Reserved1; unsigned char BS_BootSig; unsigned int BS_VolID; unsigned char BS_VolLab[11]; unsigned char BS_FilSysType[8]; }

variable_types:
FAT
unsigned int *

variable_types:
totalDataCluster
unsigned int

variable_types: numOfAlloc int

variable_types: numOfFree int


detectArgv

original_code:
char detectArgv(int argc,char** argv){
    int i;
    int hasD = 0;
    int hasI = 0;
    int hasL = 0;
    int hasR = 0;
    int hasr = 0;
    int hasM = 0;
    if(argc < 4){
        return 0;
    }else{
     for(i = 1; i < argc; i++){
      if(hasD == 2){
       if(argv[i][0]=='-'){
        return 0;
       }else{
        devicename = argv[i];
        hasD=1;
       }
      }else if(hasr == 2){
       if(argv[i][0]=='-'){
        return 0;
       }else{
        filename = argv[i];
                    filenameLength = strlen(argv[i]);
        hasr=1;
       }
      }else if(hasR == 2){
       if(argv[i][0]=='-'){
        return 0;
       }else{
        filename = argv[i];
                    filenameLength = strlen(argv[i]);
        hasR=1;
       }
      }else if(hasM == 2){
       if(argv[i][0]=='-'){
        return 0;
       }else{
        md5 = argv[i];
                    md5Length = strlen(argv[i]);
        hasM=1;
       }
      }else if(strcmp(argv[i],"-d")==0){
       if(hasD == 0){ hasD = 2; }else{ return 0; }
      }else if(strcmp(argv[i],"-r")==0){
       if(hasr == 0){ hasr = 2; }else{ return 0; }
      }else if(strcmp(argv[i],"-R")==0){
       if(hasR == 0){ hasR = 2; }else{ return 0; }
      }else if(strcmp(argv[i],"-m")==0){
       if(hasM == 0){ hasM = 2; }else{ return 0; }
      }else if(strcmp(argv[i],"-i")==0){
       if(hasI == 0){ hasI = 1; }else{ return 0; }
      }else if(strcmp(argv[i],"-l")==0){
       if(hasL == 0){ hasL = 1; }else{ return 0; }
      }else{
       return 0;
      }
     }
     if(hasD == 0 || hasD == 2){ return 0;}
     if((hasI + hasL + hasR + hasr)>1){ return 0; }
     if((hasM + hasI) > 1 || (hasM + hasL) > 1 || (hasM + hasR) > 1){ return 0;}
     if(hasI == 1){ return 'i';}
     if(hasL == 1){ return 'l';}
  if(hasr == 1){ if(hasM == 1){ return 'm';}
        else if(hasM == 2){ return 0; }
        else{return 'r';}
      }
  if(hasR == 1){ return 'R';}
  return 0;
    }
}

canonical_original_code:
char detectArgv(int argc, char **argv){
    int i;
    int hasD = 0;
    int hasI = 0;
    int hasL = 0;
    int hasR = 0;
    int hasr = 0;
    int hasM = 0;
    if(argc < 4){
        return 0;
    }else{
     for(i = 1; i < argc; i++){
      if(hasD == 2){
       if(argv[i][0]=='-'){
        return 0;
       }else{
        devicename = argv[i];
        hasD=1;
       }
      }else if(hasr == 2){
       if(argv[i][0]=='-'){
        return 0;
       }else{
        filename = argv[i];
                    filenameLength = strlen(argv[i]);
        hasr=1;
       }
      }else if(hasR == 2){
       if(argv[i][0]=='-'){
        return 0;
       }else{
        filename = argv[i];
                    filenameLength = strlen(argv[i]);
        hasR=1;
       }
      }else if(hasM == 2){
       if(argv[i][0]=='-'){
        return 0;
       }else{
        md5 = argv[i];
                    md5Length = strlen(argv[i]);
        hasM=1;
       }
      }else if(strcmp(argv[i],"-d")==0){
       if(hasD == 0){ hasD = 2; }else{ return 0; }
      }else if(strcmp(argv[i],"-r")==0){
       if(hasr == 0){ hasr = 2; }else{ return 0; }
      }else if(strcmp(argv[i],"-R")==0){
       if(hasR == 0){ hasR = 2; }else{ return 0; }
      }else if(strcmp(argv[i],"-m")==0){
       if(hasM == 0){ hasM = 2; }else{ return 0; }
      }else if(strcmp(argv[i],"-i")==0){
       if(hasI == 0){ hasI = 1; }else{ return 0; }
      }else if(strcmp(argv[i],"-l")==0){
       if(hasL == 0){ hasL = 1; }else{ return 0; }
      }else{
       return 0;
      }
     }
     if(hasD == 0 || hasD == 2){ return 0;}
     if((hasI + hasL + hasR + hasr)>1){ return 0; }
     if((hasM + hasI) > 1 || (hasM + hasL) > 1 || (hasM + hasR) > 1){ return 0;}
     if(hasI == 1){ return 'i';}
     if(hasL == 1){ return 'l';}
  if(hasr == 1){ if(hasM == 1){ return 'm';}
        else if(hasM == 2){ return 0; }
        else{return 'r';}
      }
  if(hasR == 1){ return 'R';}
  return 0;
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: hasD int

variable_types: hasI int

variable_types: hasL int

variable_types: hasR int

variable_types: hasr int

variable_types: hasM int

return_type: char


toUpperCase

decompiled_code:
__int64 __fastcall toUpperCase(_BYTE *a1)
{
__int64 result; // rax

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (unsigned __int8)(result - 97) <= 0x19u )
*a1 = result - 32;
++a1;
}
return result;
}

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

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (unsigned __int8)(result - 97) <= 0x19u )
*a1 = result - 32;
++a1;
}
return result;
}

original_code:
void toUpperCase(char *str){
    int i;
    for(i=0;str[i];i++){
        if(str[i] >= 'a' && str[i] <= 'z'){
            str[i] -= ('a' - 'A');
        }
    }
}

variable_types:
str
char *


decompiled_code:
void __fastcall base64_encode_init(__int64 a1)
{
*(_DWORD *)a1 = 0;
*(_BYTE *)(a1 + 4) = 0;
}

original_code:
void base64_encode_init(base64_encodestate *S) {
    S->step = step_A;
    S->result = 0;
}

canonical_original_code:
void base64_encode_init(struct base64_encodestate *S) {
    S->step = step_A;
    S->result = 0;
}

variable_types: struct base64_encodestate { enum base64_encodestep { step_A=0, step_B=1, step_C=2 } step; unsigned char result; } *

user_defined_types: struct base64_encodestate { enum base64_encodestep step; unsigned char result; }


decompiled_code:
__int64 __fastcall base64_encode_value(unsigned __int8 a1)
{
__int64 result; // rax

result = 61LL;
if ( a1 <= 0x3Fu )
result = (unsigned __int8)byte_402040[a1];
return result;
}

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

result = 61LL;
if ( a1 <= 0x3Fu )
result = (unsigned __int8)byte_402040[a1];
return result;
}

original_code:
char base64_encode_value(uint8_t value) {
    static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    if (value > 63) return '=';
    return encoding[value];
}

canonical_original_code:
char base64_encode_value(unsigned char value) {
    static char *encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    if (value > 63) return '=';
    return encoding[value];
}

variable_types:
value
unsigned char

variable_types:
encoding
char *


decompiled_code:
__int64 __fastcall base64_encode_final(__int64 a1, __int64 a2)
{
char v2; // al
__int64 result; // rax

if ( *(_DWORD *)a1 == 1 )
{
*(_BYTE *)a2 = base64_encode_value(*(_BYTE *)(a1 + 4));
*(_WORD *)(a2 + 1) = 15677;
result = 3LL;
}
else if ( *(_DWORD *)a1 == 2 )
{
v2 = base64_encode_value(*(_BYTE *)(a1 + 4));
*(_BYTE *)(a2 + 1) = 61;
*(_BYTE *)a2 = v2;
result = 2LL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
ptrdiff_t base64_encode_final(base64_encodestate *S, char *encoded) {
    char *encoded_begin = encoded;
    switch (S->step) {
    case step_B:
        *encoded++ = base64_encode_value(S->result);
        *encoded++ = '=';
        *encoded++ = '=';
        break;
    case step_C:
        *encoded++ = base64_encode_value(S->result);
        *encoded++ = '=';
        break;
    case step_A:
        break;
    }
    return encoded - encoded_begin;
}

canonical_original_code:
long base64_encode_final(struct base64_encodestate *S, char *encoded) {
    char *encoded_begin = encoded;
    switch (S->step) {
    case step_B:
        *encoded++ = base64_encode_value(S->result);
        *encoded++ = '=';
        *encoded++ = '=';
        break;
    case step_C:
        *encoded++ = base64_encode_value(S->result);
        *encoded++ = '=';
        break;
    case step_A:
        break;
    }
    return encoded - encoded_begin;
}

variable_types:
encoded
char *

return_type: long

user_defined_types: enum base64_encodestep { step_A=0, step_B=1, step_C=2 }


decompiled_code:
int __fastcall print_usage(const char *a1)
{
return fprintf(stderr, "Usage: %s [-hv]\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "Usage: %s [-hv]\n", a1);
}

original_code:
void print_usage(char *name) {
 fprintf(stderr, "Usage: %s [-hv]\n", name);
}

variable_types:
name
char *


decompiled_code:
int print_version()
{
return fprintf(stdout, "Version %s\n", version);
}

canonical_decompiled_code:
int func1()
{
return fprintf(stdout, "Version %s\n", version);
}

original_code:
void print_version() {
 fprintf(stdout, "Version %s\n", version);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r13
const char *v4; // rbp
size_t v5; // rbx
char v6; // al
int result; // eax
char *v8; // rbp
void *v9; // r12
unsigned int v10; // eax
unsigned int v11; // eax
void *v12; // [rsp+0h] [rbp-58h] BYREF
char *ptr; // [rsp+8h] [rbp-50h] BYREF
void *v14[9]; // [rsp+10h] [rbp-48h] BYREF

if ( argc <= 1 )
{
v12 = 0LL;
get_latest_version(v14, VERSIONS_URL, envp);
v8 = (char *)v14[0];
v9 = v14[2];
printf("Latest available version is %s\n", (const char *)v14[0]);
v10 = get_current_version(&v12);
if ( v10 > 1 )
{
fprintf(stderr, "current version failed with %d\n", v10);
result = 1;
}
else
{
printf("Current version is %s\n", (const char *)v12);
if ( !v12 || (int)compare_versions(v8) > 0 )
{
ptr = 0LL;
asprintf(&ptr, "%s%s.jar", SERVER_FILE, v8);
if ( !v9 )
puts("No download URL!\n");
v11 = update_minecraft(ptr, v9);
if ( v11 )
fprintf(stderr, "Failed to update minecraft server: error %d\n", v11);
}
free(v8);
free(v14[1]);
free(v9);
free(v12);
result = 0;
}
}
else
{
v3 = argv + 1;
while ( 1 )
{
v4 = *v3;
if ( **v3 != 45 )
break;
v5 = 1LL;
if ( strlen(*v3) > 1 )
{
do
{
v6 = v4[v5];
if ( v6 == 104 )
{
print_usage(*argv);
}
else
{
if ( v6 != 118 )
goto LABEL_11;
print_version();
}
v4 = *v3;
++v5;
}
while ( strlen(*v3) > v5 );
}
if ( ++v3 == &argv[(unsigned int)(argc - 2) + 2] )
return 0;
}
LABEL_11:
print_usage(*argv);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r13
const char *v4; // rbp
size_t v5; // rbx
char v6; // al
int result; // eax
char *v8; // rbp
void *v9; // r12
unsigned int v10; // eax
unsigned int v11; // eax
void *v12; // [rsp+0h] [rbp-58h] BYREF
char *ptr; // [rsp+8h] [rbp-50h] BYREF
void *v14[9]; // [rsp+10h] [rbp-48h] BYREF

if ( argc <= 1 )
{
v12 = 0LL;
get_latest_version(v14, VERSIONS_URL, envp);
v8 = (char *)v14[0];
v9 = v14[2];
printf("Latest available version is %s\n", (const char *)v14[0]);
v10 = get_current_version(&v12);
if ( v10 > 1 )
{
fprintf(stderr, "current version failed with %d\n", v10);
result = 1;
}
else
{
printf("Current version is %s\n", (const char *)v12);
if ( !v12 || (int)compare_versions(v8) > 0 )
{
ptr = 0LL;
asprintf(&ptr, "%s%s.jar", SERVER_FILE, v8);
if ( !v9 )
puts("No download URL!\n");
v11 = update_minecraft(ptr, v9);
if ( v11 )
fprintf(stderr, "Failed to update minecraft server: error %d\n", v11);
}
free(v8);
free(v14[1]);
free(v9);
free(v12);
result = 0;
}
}
else
{
v3 = argv + 1;
while ( 1 )
{
v4 = *v3;
if ( **v3 != 45 )
break;
v5 = 1LL;
if ( strlen(*v3) > 1 )
{
do
{
v6 = v4[v5];
if ( v6 == 104 )
{
func0(*argv);
}
else
{
if ( v6 != 118 )
goto LABEL_11;
func1();
}
v4 = *v3;
++v5;
}
while ( strlen(*v3) > v5 );
}
if ( ++v3 == &argv[(unsigned int)(argc - 2) + 2] )
return 0;
}
LABEL_11:
func0(*argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 if (argc > 1) {
  for (int i = 1; i < argc; ++i) {
   if (argv[i][0] != '-') {
    print_usage(argv[0]);
    return 1;
   }
   for (int j = 1; j < strlen(argv[i]); ++j) {
    switch (argv[i][j]) {
     case 'v': print_version(); break;
     case 'h': print_usage(argv[0]); break;
     default: print_usage(argv[0]); return 1;
    }
   }
  }
  return 0;
 }
 char *current_ver = ((void *)0);
 Version latest_ver;
 latest_ver = get_latest_version(VERSIONS_URL);
 printf("Latest available version is %s\n", latest_ver.id);
 int success = get_current_version(&current_ver);
 if (success != 0 && success != 1) {
   fprintf(stderr, "current version failed with %d\n", success);
   return 1;
 }
 printf("Current version is %s\n", current_ver);
 if (current_ver == ((void *)0) || compare_versions(latest_ver.id, current_ver) > 0 ) {
  char * filename = ((void *)0);
  asprintf(&filename, "%s%s.jar", SERVER_FILE, latest_ver.id);
  if (latest_ver.download_url == ((void *)0)) {
   puts("No download URL!\n");
  }
  success = update_minecraft(filename,
   latest_ver.download_url);
  if (success != 0) {
    fprintf(stderr, "Failed to update minecraft server: error %d\n", success);
  }
 }
 free(latest_ver.id);
 free(latest_ver.metadata_url);
 free(latest_ver.download_url);
 free(current_ver);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if (argc > 1) {
  for (int i = 1; i < argc; ++i) {
   if (argv[i][0] != '-') {
    print_usage(argv[0]);
    return 1;
   }
   for (int j = 1; j < strlen(argv[i]); ++j) {
    switch (argv[i][j]) {
     case 'v': print_version(); break;
     case 'h': print_usage(argv[0]); break;
     default: print_usage(argv[0]); return 1;
    }
   }
  }
  return 0;
 }
 char *current_ver = ((void *)0);
 struct Version latest_ver;
 latest_ver = get_latest_version(VERSIONS_URL);
 printf("Latest available version is %s\n", latest_ver.id);
 int success = get_current_version(&current_ver);
 if (success != 0 && success != 1) {
   fprintf(stderr, "current version failed with %d\n", success);
   return 1;
 }
 printf("Current version is %s\n", current_ver);
 if (current_ver == ((void *)0) || compare_versions(latest_ver.id, current_ver) > 0 ) {
  char *filename = ((void *)0);
  asprintf(&filename, "%s%s.jar", SERVER_FILE, latest_ver.id);
  if (latest_ver.download_url == ((void *)0)) {
   puts("No download URL!\n");
  }
  success = update_minecraft(filename,
   latest_ver.download_url);
  if (success != 0) {
    fprintf(stderr, "Failed to update minecraft server: error %d\n", success);
  }
 }
 free(latest_ver.id);
 free(latest_ver.metadata_url);
 free(latest_ver.download_url);
 free(current_ver);
 return 0;
}

variable_types:
argv
char *[]

variable_types: j int

variable_types: struct Version { char *id; char *metadata_url; char *download_url; }

variable_types: success int

variable_types:
filename
char *


FieldVarMore

decompiled_code:
void FieldVarMore()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void FieldVarMore(TreeNode * t){
}

canonical_original_code:
void FieldVarMore(struct node *t){
}

variable_types: struct node { struct node *child[3]; struct node *Sibling; int Lineno; enum NodeKind { ProK=0, PheadK=1, TypeK=2, VarK=3, ProcDecK=4, StmLK=5, DecK=6, StmtK=7, ExpK=8 } nodeKind; char nodeKindStr[30]; union k { enum dec { ArrayK=0, CharK=1, IntegerK=2, RecordK=3, IdK=4 } d; enum stmt { IfK=0, WhileK=1, AssignK=2, ReadK=3, WriteK=4, CallK=5, ReturnK=6 } s; enum exp { OpK=0, ConstK=1, IdEK=2 } e; char name[30]; } kind; int idnum; char name[10][30]; char type_name[30]; union a { struct array { int low; int up; enum dec { ArrayK=0, CharK=1, IntegerK=2, RecordK=3, IdK=4 } childType; } a_attr; struct expAttr { char op; int val; enum varKind { IdV=0, ArrayMembV=1, FieldMembV=2 } varkind; enum ExpType { Void=0, Integer=1, Boolean=2 } type; } e_attr; struct proc { enum ProcAttrType { valparamtype=0, varparamtype=1 } paramt; } p_attr; } attr; } *

user_defined_types: struct node { struct node *child[3]; struct node *Sibling; int Lineno; enum NodeKind nodeKind; char nodeKindStr[30]; union k kind; int idnum; char name[10][30]; char type_name[30]; union a attr; }

user_defined_types: union k { enum dec d; enum stmt s; enum exp e; char name[30]; }

user_defined_types: union a { struct array a_attr; struct expAttr e_attr; struct proc p_attr; }

user_defined_types: struct array { int low; int up; enum dec childType; }

user_defined_types: struct expAttr { char op; int val; enum varKind varkind; enum ExpType type; }

user_defined_types: struct proc { enum ProcAttrType paramt; }