decompiled_code:
int __fastcall data_queue_init(__int64 a1, int a2)
{
int result; // eax
void *v3; // rax

if ( !a1 )
return 1;
result = 1;
if ( a2 > 0 )
{
v3 = malloc(532LL * a2);
*(_QWORD *)(a1 + 8) = v3;
if ( v3 )
{
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL) )
{
free(*(void **)(a1 + 8));
result = 3;
}
else
{
result = pthread_cond_init((pthread_cond_t *)(a1 + 56), 0LL);
if ( result )
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
free(*(void **)(a1 + 8));
result = 4;
}
else
{
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
}
}
}
else
{
result = 2;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2)
{
int result; // eax
void *v3; // rax

if ( !a1 )
return 1;
result = 1;
if ( a2 > 0 )
{
v3 = malloc(532LL * a2);
*(_QWORD *)(a1 + 8) = v3;
if ( v3 )
{
if ( pthread_mutex_init((pthread_mutex_t *)(a1 + 16), 0LL) )
{
free(*(void **)(a1 + 8));
result = 3;
}
else
{
result = pthread_cond_init((pthread_cond_t *)(a1 + 56), 0LL);
if ( result )
{
pthread_mutex_destroy((pthread_mutex_t *)(a1 + 16));
free(*(void **)(a1 + 8));
result = 4;
}
else
{
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
}
}
}
else
{
result = 2;
}
}
return result;
}

original_code:
int data_queue_init(data_queue * dq, int size) {
    if(dq == (void *) 0 || size <= 0) {
 return 1;
    }
    dq->data = (data_queue_element *) malloc(sizeof(data_queue_element) * size);
    if(dq->data == (void *) 0) {
 return 2;
    }
    if(pthread_mutex_init(&(dq->mutex), (void *) 0)) {
 free((void *)dq->data);
 return 3;
    }
    if(pthread_cond_init(&(dq->cond), (void *) 0)) {
 pthread_mutex_destroy(&(dq->mutex));
 free((void *)dq->data);
 return 4;
    }
    dq->size = size;
    dq->count = 0;
    return 0;
}

canonical_original_code:
int data_queue_init(struct _data_queue *dq, int size) {
    if(dq == (void *) 0 || size <= 0) {
 return 1;
    }
    dq->data = (struct _data_queue_element *) malloc(sizeof(data_queue_element) * size);
    if(dq->data == (void *) 0) {
 return 2;
    }
    if(pthread_mutex_init(&(dq->mutex), (void *) 0)) {
 free((void *)dq->data);
 return 3;
    }
    if(pthread_cond_init(&(dq->cond), (void *) 0)) {
 pthread_mutex_destroy(&(dq->mutex));
 free((void *)dq->data);
 return 4;
    }
    dq->size = size;
    dq->count = 0;
    return 0;
}

variable_types: struct _data_queue { int size; int count; struct _data_queue_element { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; char data[512]; int data_len; } *data; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; } *

variable_types: size int

user_defined_types: struct _data_queue { int size; int count; struct _data_queue_element *data; union pthread_mutex_t mutex; union pthread_cond_t cond; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


repo: dbondin/testdnsd

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

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

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

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

original_code:
int data_queue_get_size(const data_queue * dq) {
    if(dq == (void *) 0) {
 return 0;
    }
    return dq->size;
}

canonical_original_code:
int data_queue_get_size(struct _data_queue *dq) {
    if(dq == (void *) 0) {
 return 0;
    }
    return dq->size;
}

return_type: int

user_defined_types: struct _data_queue_element { struct sockaddr_in addr; char data[512]; int data_len; }

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall data_queue_get_count(__int64 a1)
{
unsigned int v1; // er12

if ( !a1 || pthread_mutex_lock((pthread_mutex_t *)(a1 + 16)) )
return (unsigned int)-1;
v1 = *(_DWORD *)(a1 + 4);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // er12

if ( !a1 || pthread_mutex_lock((pthread_mutex_t *)(a1 + 16)) )
return (unsigned int)-1;
v1 = *(_DWORD *)(a1 + 4);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 16));
return v1;
}

original_code:
int data_queue_get_count(data_queue * dq) {
    int res = -1;
    if(dq != (void *) 0) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     res = dq->count;
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

canonical_original_code:
int data_queue_get_count(struct _data_queue *dq) {
    int res = -1;
    if(dq != (void *) 0) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     res = dq->count;
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

variable_types: res int


decompiled_code:
__int64 __fastcall data_queue_get_data(__int64 a1, _QWORD *a2)
{
pthread_mutex_t *v2; // rbp
unsigned int v4; // er12
int i; // eax
int v6; // eax
_QWORD *v7; // rsi

if ( !a1 )
return (unsigned int)-1;
v2 = (pthread_mutex_t *)(a1 + 16);
if ( (v4 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 16))) != 0 )
return (unsigned int)-1;
for ( i = *(_DWORD *)(a1 + 4); !i; i = *(_DWORD *)(a1 + 4) )
pthread_cond_wait((pthread_cond_t *)(a1 + 56), v2);
v6 = i - 1;
*(_DWORD *)(a1 + 4) = v6;
if ( a2 )
{
v7 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 532LL * v6);
*a2 = *v7;
*(_QWORD *)((char *)a2 + 524) = *(_QWORD *)((char *)v7 + 524);
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v7 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 532) >> 3));
}
pthread_mutex_unlock(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
pthread_mutex_t *v2; // rbp
unsigned int v4; // er12
int i; // eax
int v6; // eax
_QWORD *v7; // rsi

if ( !a1 )
return (unsigned int)-1;
v2 = (pthread_mutex_t *)(a1 + 16);
if ( (v4 = pthread_mutex_lock((pthread_mutex_t *)(a1 + 16))) != 0 )
return (unsigned int)-1;
for ( i = *(_DWORD *)(a1 + 4); !i; i = *(_DWORD *)(a1 + 4) )
pthread_cond_wait((pthread_cond_t *)(a1 + 56), v2);
v6 = i - 1;
*(_DWORD *)(a1 + 4) = v6;
if ( a2 )
{
v7 = (_QWORD *)(*(_QWORD *)(a1 + 8) + 532LL * v6);
*a2 = *v7;
*(_QWORD *)((char *)a2 + 524) = *(_QWORD *)((char *)v7 + 524);
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v7 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 532) >> 3));
}
pthread_mutex_unlock(v2);
return v4;
}

original_code:
int data_queue_get_data(data_queue * dq, data_queue_element * data) {
    int res = -1;
    if(dq != (void *) 0) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     while(1) {
  if(dq->count == 0) {
      pthread_cond_wait(&(dq->cond), &(dq->mutex));
      continue;
  }
  dq->count --;
  if(data != (void *) 0) {
      memcpy((void *) data,
      (void *) &(dq->data[dq->count]),
      sizeof(data_queue_element));
  }
  res = 0;
  break;
     }
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

canonical_original_code:
int data_queue_get_data(struct _data_queue *dq, struct _data_queue_element *data) {
    int res = -1;
    if(dq != (void *) 0) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     while(1) {
  if(dq->count == 0) {
      pthread_cond_wait(&(dq->cond), &(dq->mutex));
      continue;
  }
  dq->count --;
  if(data != (void *) 0) {
      memcpy((void *) data,
      (void *) &(dq->data[dq->count]),
      sizeof(data_queue_element));
  }
  res = 0;
  break;
     }
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

variable_types:
data
struct _data_queue_element *


original_code:
int data_queue_put_data(data_queue * dq, const struct sockaddr_in * addr, const void * data, int data_len) {
    int res = -1;
    if(dq != (void *) 0 &&
       data != (void *) 0 &&
       addr != (void *) 0 &&
       data_len > 0 &&
       data_len <= 512) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     if(dq->count < dq->size) {
  memcpy((void *) &(dq->data[dq->count].addr),
         (void *) addr,
         sizeof(addr));
  memcpy((void *) &(dq->data[dq->count].data),
         (void *) data,
         data_len);
  dq->data[dq->count].data_len = data_len;
  dq->count ++;
  res = 0;
  pthread_cond_signal(&(dq->cond));
     }
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

canonical_original_code:
int data_queue_put_data(struct _data_queue *dq, struct sockaddr_in *addr, void *data, int data_len) {
    int res = -1;
    if(dq != (void *) 0 &&
       data != (void *) 0 &&
       addr != (void *) 0 &&
       data_len > 0 &&
       data_len <= 512) {
 if(!pthread_mutex_lock(&(dq->mutex))) {
     if(dq->count < dq->size) {
  memcpy((void *) &(dq->data[dq->count].addr),
         (void *) addr,
         sizeof(addr));
  memcpy((void *) &(dq->data[dq->count].data),
         (void *) data,
         data_len);
  dq->data[dq->count].data_len = data_len;
  dq->count ++;
  res = 0;
  pthread_cond_signal(&(dq->cond));
     }
     pthread_mutex_unlock(&(dq->mutex));
 }
    }
    return res;
}

variable_types:
addr
struct sockaddr_in *

variable_types:
data
void *


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

result = malloc(0x408uLL);
if ( result )
{
result[128] = 0LL;
memset(result, 0, 0x400uLL);
}
return result;
}

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

result = malloc(0x408uLL);
if ( result )
{
result[128] = 0LL;
memset(result, 0, 0x400uLL);
}
return result;
}

original_code:
lookupdb_entry * new_lookupdb_entry() {
    lookupdb_entry * e = (lookupdb_entry *) malloc(sizeof(lookupdb_entry));
    if(e != ((void *)0)) {
 e->addr_list = ((void *)0);
        memset((void *) e->next, 0, sizeof(e->next));
    }
    return e;
}

canonical_original_code:
struct _lookupdb_entry *new_lookupdb_entry() {
    struct _lookupdb_entry *e = (lookupdb_entry *) malloc(sizeof(lookupdb_entry));
    if(e != ((void *)0)) {
 e->addr_list = ((void *)0);
        memset((void *) e->next, 0, sizeof(e->next));
    }
    return e;
}

variable_types: struct _lookupdb_entry { struct _lookupdb_entry *next[128]; struct _lookupdb_addr { struct in_addr { unsigned int s_addr; } addr; struct _lookupdb_addr *next; } *addr_list; } *

user_defined_types: struct _lookupdb_entry { struct _lookupdb_entry *next[128]; struct _lookupdb_addr *addr_list; }

user_defined_types: struct _lookupdb_addr { struct in_addr addr; struct _lookupdb_addr *next; }


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

if ( !a1 )
return 0xFFFFFFFFLL;
*a1 = 0LL;
v1 = new_lookupdb_entry();
a1[1] = v1;
return (unsigned int)-(v1 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
*a1 = 0LL;
v1 = func0();
a1[1] = v1;
return (unsigned int)-(v1 == 0LL);
}

original_code:
int lookupdb_init(lookupdb * ldb) {
    if(ldb == ((void *)0)) {
 return -1;
    }
    ldb->size = 0;
    ldb->entry = new_lookupdb_entry();
    if(ldb->entry == ((void *)0)) {
 return -1;
    }
    return 0;
}

canonical_original_code:
int lookupdb_init(struct _lookupdb *ldb) {
    if(ldb == ((void *)0)) {
 return -1;
    }
    ldb->size = 0;
    ldb->entry = new_lookupdb_entry();
    if(ldb->entry == ((void *)0)) {
 return -1;
    }
    return 0;
}

variable_types: struct _lookupdb { unsigned long size; struct _lookupdb_entry { struct _lookupdb_entry *next[128]; struct _lookupdb_addr { struct in_addr { unsigned int s_addr; } addr; struct _lookupdb_addr *next; } *addr_list; } *entry; } *

user_defined_types: struct _lookupdb { unsigned long size; struct _lookupdb_entry *entry; }


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

if ( a1 )
result = *a1;
else
result = -1LL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = -1LL;
return result;
}

original_code:
long lookupdb_size(const lookupdb * ldb) {
    if(ldb == ((void *)0)) {
 return -1;
    }
    return ldb->size;
}

canonical_original_code:
long lookupdb_size(struct _lookupdb *ldb) {
    if(ldb == ((void *)0)) {
 return -1;
    }
    return ldb->size;
}

return_type: long


decompiled_code:
__int64 __fastcall lookupdb_search(__int64 a1, char *a2)
{
char *v2; // rbp
__int64 v3; // rbx
__int64 v4; // r12
const __int32_t *v5; // rdx
__int32_t v6; // eax

if ( a1 )
{
v2 = a2;
if ( a2 )
{
v3 = *a2;
v4 = *(_QWORD *)(a1 + 8);
if ( (_BYTE)v3 )
{
if ( !v4 )
return v4;
v5 = *_ctype_tolower_loc();
while ( 1 )
{
v6 = v5[v3];
v3 = *++v2;
v4 = *(_QWORD *)(v4 + 8LL * (v6 & 0x7F));
if ( !(_BYTE)v3 )
break;
if ( !v4 )
return v4;
}
}
if ( v4 )
v4 = *(_QWORD *)(v4 + 1024);
return v4;
}
}
return 0LL;
}

original_code:
lookupdb_addr * lookupdb_search(const lookupdb * ldb, const char * name) {
    lookupdb_entry * ep;
    int idx;
    if(ldb != ((void *)0) && name != ((void *)0)) {
 ep = ldb->entry;
 for(;*name != 0; name ++) {
     if(ep != ((void *)0)) {
  idx = 0x7f & tolower(*name);
  ep = ep->next[idx];
     }
     else {
  break;
     }
 }
 if(ep != ((void *)0)) {
     return ep->addr_list;
 }
    }
    return ((void *)0);
}

canonical_original_code:
struct _lookupdb_addr *lookupdb_search(struct _lookupdb *ldb, char *name) {
    struct _lookupdb_entry *ep;
    int idx;
    if(ldb != ((void *)0) && name != ((void *)0)) {
 ep = ldb->entry;
 for(;*name != 0; name ++) {
     if(ep != ((void *)0)) {
  idx = 0x7f & tolower(*name);
  ep = ep->next[idx];
     }
     else {
  break;
     }
 }
 if(ep != ((void *)0)) {
     return ep->addr_list;
 }
    }
    return ((void *)0);
}

variable_types: struct _lookupdb { unsigned long size; struct _lookupdb_entry { struct _lookupdb_entry *next[128]; struct _lookupdb_addr *addr_list; } *entry; } *

variable_types:
name
char *

variable_types: idx int

return_type: struct _lookupdb_addr { struct in_addr { unsigned int s_addr; } addr; struct _lookupdb_addr *next; } *


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

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

original_code:
int lookupdb_clear(lookupdb * ldb) {
    return 0;
}

canonical_original_code:
int lookupdb_clear(struct _lookupdb *ldb) {
    return 0;
}


decompiled_code:
__int64 __fastcall dns_question_load(const char *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = a1;
v2 = strlen(a1);
*(_WORD *)(a2 + 8) = _bswap_16(*(_WORD *)&a1[v2 + 1]);
*(_WORD *)(a2 + 10) = _bswap_16(*(_WORD *)&a1[v3 + 3]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = a1;
v2 = strlen(a1);
*(_WORD *)(a2 + 8) = func0(*(_WORD *)&a1[v2 + 1]);
*(_WORD *)(a2 + 10) = func0(*(_WORD *)&a1[v3 + 3]);
return 0LL;
}

original_code:
int dns_question_load(const void * data, dns_question * dnsq) {
    int res = -1;
    if(data != ((void *)0) && dnsq != ((void *)0)) {
 int qname_len;
 dnsq->qname = (char *) data;
 qname_len = strlen(dnsq->qname);
 dnsq->qtype = ntohs(*(uint16_t *)(data + qname_len + 1));
 dnsq->qclass = ntohs(*(uint16_t *)(data + qname_len + 1 + sizeof(dnsq->qtype)));
 res = 0;
    }
    return res;
}

canonical_original_code:
int dns_question_load(void *data, struct _dns_question *dnsq) {
    int res = -1;
    if(data != ((void *)0) && dnsq != ((void *)0)) {
 int qname_len;
 dnsq->qname = (char *) data;
 qname_len = strlen(dnsq->qname);
 dnsq->qtype = ntohs(*(unsigned short *)(data + qname_len + 1));
 dnsq->qclass = ntohs(*(unsigned short *)(data + qname_len + 1 + sizeof(dnsq->qtype)));
 res = 0;
    }
    return res;
}

variable_types: struct _dns_question { char *qname; unsigned short qtype; unsigned short qclass; } *


decompiled_code:
void XXLOG_INIT()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void XXLOG_INIT() {
}

canonical_original_code:
void XXLOG_INIT() {
}

return_type: void


XXLOG

decompiled_code:
int XXLOG(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
return putchar(10);
}

canonical_decompiled_code:
int func1(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
return putchar(10);
}

original_code:
void XXLOG(const char * format, ...) {
    va_list ap;
    __builtin_va_start(ap,format);
    vprintf(format, ap);
    printf("\n");
    __builtin_va_end(ap);
}

canonical_original_code:
void XXLOG(char *format, ...) {
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    vprintf(format, ap);
    printf("\n");
    __builtin_va_end(ap);
}

variable_types:
format
char *


decompiled_code:
int XXLOG_DEBUG(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
return putchar(10);
}

canonical_decompiled_code:
int func2(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
return putchar(10);
}

original_code:
void XXLOG_DEBUG(const char * format, ...) {
    va_list ap;
    __builtin_va_start(ap,format);
    vprintf(format, ap);
    printf("\n");
    __builtin_va_end(ap);
}

canonical_original_code:
void XXLOG_DEBUG(char *format, ...) {
    __builtin_va_list ap;
    __builtin_va_start(ap,format);
    vprintf(format, ap);
    printf("\n");
    __builtin_va_end(ap);
}


GetLevelString

repo: dbuchwald/sextium

decompiled_code:
char *__fastcall GetLevelString(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 4 )
result = CSWTCH_12[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func7(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 4 )
result = CSWTCH_12[a1];
return result;
}

original_code:
static const char* GetLevelString(const TRACE_ERRORLEVEL level)
{
  switch (level)
  {
    case TRACE_OFF:
      return __TRACE_LEVEL_OFF;
    case TRACE_ERROR:
      return __TRACE_LEVEL_ERROR;
    case TRACE_WARNING:
      return __TRACE_LEVEL_WARNING;
    case TRACE_INFO:
      return __TRACE_LEVEL_INFO;
    case TRACE_DEBUG:
      return __TRACE_LEVEL_DEBUG;
  }
  return ((void *)0);
}

canonical_original_code:
static char *GetLevelString(enum TRACE_ERRORLEVEL level)
{
  switch (level)
  {
    case TRACE_OFF:
      return __TRACE_LEVEL_OFF;
    case TRACE_ERROR:
      return __TRACE_LEVEL_ERROR;
    case TRACE_WARNING:
      return __TRACE_LEVEL_WARNING;
    case TRACE_INFO:
      return __TRACE_LEVEL_INFO;
    case TRACE_DEBUG:
      return __TRACE_LEVEL_DEBUG;
  }
  return ((void *)0);
}

variable_types: enum TRACE_ERRORLEVEL { TRACE_OFF=0, TRACE_ERROR=1, TRACE_WARNING=2, TRACE_INFO=3, TRACE_DEBUG=4 }

return_type: char *


PrintTraceLine

decompiled_code:
int PrintTraceLine(const char *a1, const char *a2, unsigned int a3, unsigned int a4, const char *a5, ...)
{
int result; // eax
struct tm *v9; // rax
char *v10; // rax
const char *v11; // rdx
time_t v12; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a5);
result = trace_initialized;
if ( trace_initialized )
{
if ( trace_level < a4 )
return result;
LABEL_5:
time(&v12);
v9 = localtime(&v12);
strftime(timestamp_1, 0x200uLL, "%Y.%m.%d %H:%M:%S", v9);
v10 = GetLevelString(a4);
fprintf(trace_file, "[%s] %s ", v11, v10);
fprintf(trace_file, "<%s> (%s:%d) > ", a1, a2, a3);
vfprintf(trace_file, a5, arg);
fputc(10, trace_file);
return fflush(trace_file);
}
result = InitializeTrace();
if ( trace_level >= a4 )
goto LABEL_5;
return result;
}

canonical_decompiled_code:
int func8(const char *a1, const char *a2, unsigned int a3, unsigned int a4, const char *a5, ...)
{
int result; // eax
struct tm *v9; // rax
char *v10; // rax
const char *v11; // rdx
time_t v12; // [rsp+0h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a5);
result = trace_initialized;
if ( trace_initialized )
{
if ( trace_level < a4 )
return result;
LABEL_5:
time(&v12);
v9 = localtime(&v12);
strftime(timestamp_1, 0x200uLL, "%Y.%m.%d %H:%M:%S", v9);
v10 = func7(a4);
fprintf(trace_file, "[%s] %s ", v11, v10);
fprintf(trace_file, "<%s> (%s:%d) > ", a1, a2, a3);
vfprintf(trace_file, a5, arg);
fputc(10, trace_file);
return fflush(trace_file);
}
result = func9();
if ( trace_level >= a4 )
goto LABEL_5;
return result;
}

original_code:
void PrintTraceLine(const char* function, const char* source_file, const int source_line, const TRACE_ERRORLEVEL level, const char* format, ...)
{
  va_list vl;
  __builtin_va_start(vl,format);
  static char timestamp[512];
  if (!_trace_initialized)
  {
    InitializeTrace();
  }
  if (level <= _trace_level)
  {
    time_t t;
    struct tm *tmp;
    time(&t);
    tmp = localtime(&t);
    strftime(timestamp, sizeof(timestamp), "%Y.%m.%d %H:%M:%S", tmp);
    fprintf(_trace_file, "[%s] %s ", timestamp, GetLevelString(level));
    fprintf(_trace_file, "<%s> (%s:%d) > ", function, source_file, source_line);
    vfprintf(_trace_file, format, vl);
    fprintf(_trace_file, "\n");
    fflush(_trace_file);
  }
}

canonical_original_code:
void PrintTraceLine(char *function, char *source_file, int source_line, enum TRACE_ERRORLEVEL level, char *format, ...)
{
  __builtin_va_list vl;
  __builtin_va_start(vl,format);
  static char timestamp[512];
  if (!_trace_initialized)
  {
    InitializeTrace();
  }
  if (level <= _trace_level)
  {
    long t;
    struct tm *tmp;
    time(&t);
    tmp = localtime(&t);
    strftime(timestamp, sizeof(timestamp), "%Y.%m.%d %H:%M:%S", tmp);
    fprintf(_trace_file, "[%s] %s ", timestamp, GetLevelString(level));
    fprintf(_trace_file, "<%s> (%s:%d) > ", function, source_file, source_line);
    vfprintf(_trace_file, format, vl);
    fprintf(_trace_file, "\n");
    fflush(_trace_file);
  }
}

variable_types:
function
char *

variable_types:
timestamp
char [512]

variable_types: t 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; } *

user_defined_types: enum TRACE_ERRORLEVEL { TRACE_OFF=0, TRACE_ERROR=1, TRACE_WARNING=2, TRACE_INFO=3, TRACE_DEBUG=4 }


InitializeTrace

decompiled_code:
int InitializeTrace()
{
char *v0; // rax
int v1; // ebx
char *v2; // rax
char *v3; // rax
int result; // eax
char *v5; // rax
unsigned int v6; // edx
unsigned int v7; // ecx
const char *v8; // r8
char *v9; // rbx
char *v10; // rax
char *v11; // rax
char *v12; // rax
char *v13; // rax
char *v14; // rax

if ( getenv("TRACE_LEVEL") )
{
v0 = getenv("TRACE_LEVEL");
if ( !strcmp(v0, "OFF") )
{
trace_level = 0;
v1 = 2;
}
else
{
v11 = getenv("TRACE_LEVEL");
if ( !strcmp(v11, "ERROR") )
{
trace_level = 1;
v1 = 2;
}
else
{
v12 = getenv("TRACE_LEVEL");
if ( !strcmp(v12, "WARNING") )
{
trace_level = 2;
v1 = 2;
}
else
{
v13 = getenv("TRACE_LEVEL");
if ( !strcmp(v13, "INFO") )
{
trace_level = 3;
v1 = 2;
}
else
{
v14 = getenv("TRACE_LEVEL");
if ( !strcmp(v14, "DEBUG") )
{
trace_level = 4;
v1 = 2;
}
else
{
trace_level = 1;
v1 = 3;
}
}
}
}
}
}
else
{
trace_level = 1;
v1 = 1;
}
if ( getenv("TRACE_FILE") )
{
v2 = getenv("TRACE_FILE");
trace_file = fopen(v2, "a");
if ( trace_file )
{
trace_initialized = 1;
if ( v1 != 2 )
goto LABEL_7;
LABEL_11:
v5 = GetLevelString(trace_level);
return PrintTraceLine("InitializeTrace", "./src/trace.c", v6, v7, v8, v5);
}
}
trace_initialized = 1;
trace_file = stdout;
if ( v1 == 2 )
goto LABEL_11;
LABEL_7:
if ( v1 == 3 )
{
v9 = GetLevelString(1u);
v10 = getenv("TRACE_LEVEL");
PrintTraceLine(
"InitializeTrace",
"./src/trace.c",
0x74u,
1u,
"Wrong trace level selected: %s, defaulting to %s",
v10,
v9);
result = PrintTraceLine(
"InitializeTrace",
"./src/trace.c",
0x7Eu,
1u,
"Unable to open trace file, outputting to standard output");
}
else
{
v3 = GetLevelString(1u);
PrintTraceLine("InitializeTrace", "./src/trace.c", 0x6Eu, 1u, "No trace level selected, defaulting to %s", v3);
result = PrintTraceLine(
"InitializeTrace",
"./src/trace.c",
0x7Bu,
2u,
"No trace file specified, outputting to standard output");
}
return result;
}

canonical_decompiled_code:
int func9()
{
char *v0; // rax
int v1; // ebx
char *v2; // rax
char *v3; // rax
int result; // eax
char *v5; // rax
unsigned int v6; // edx
unsigned int v7; // ecx
const char *v8; // r8
char *v9; // rbx
char *v10; // rax
char *v11; // rax
char *v12; // rax
char *v13; // rax
char *v14; // rax

if ( getenv("TRACE_LEVEL") )
{
v0 = getenv("TRACE_LEVEL");
if ( !strcmp(v0, "OFF") )
{
trace_level = 0;
v1 = 2;
}
else
{
v11 = getenv("TRACE_LEVEL");
if ( !strcmp(v11, "ERROR") )
{
trace_level = 1;
v1 = 2;
}
else
{
v12 = getenv("TRACE_LEVEL");
if ( !strcmp(v12, "WARNING") )
{
trace_level = 2;
v1 = 2;
}
else
{
v13 = getenv("TRACE_LEVEL");
if ( !strcmp(v13, "INFO") )
{
trace_level = 3;
v1 = 2;
}
else
{
v14 = getenv("TRACE_LEVEL");
if ( !strcmp(v14, "DEBUG") )
{
trace_level = 4;
v1 = 2;
}
else
{
trace_level = 1;
v1 = 3;
}
}
}
}
}
}
else
{
trace_level = 1;
v1 = 1;
}
if ( getenv("TRACE_FILE") )
{
v2 = getenv("TRACE_FILE");
trace_file = fopen(v2, "a");
if ( trace_file )
{
trace_initialized = 1;
if ( v1 != 2 )
goto LABEL_7;
LABEL_11:
v5 = func7(trace_level);
return func8("InitializeTrace", "./src/trace.c", v6, v7, v8, v5);
}
}
trace_initialized = 1;
trace_file = stdout;
if ( v1 == 2 )
goto LABEL_11;
LABEL_7:
if ( v1 == 3 )
{
v9 = func7(1u);
v10 = getenv("TRACE_LEVEL");
func8(
"InitializeTrace",
"./src/trace.c",
0x74u,
1u,
"Wrong trace level selected: %s, defaulting to %s",
v10,
v9);
result = func8(
"InitializeTrace",
"./src/trace.c",
0x7Eu,
1u,
"Unable to open trace file, outputting to standard output");
}
else
{
v3 = func7(1u);
func8("InitializeTrace", "./src/trace.c", 0x6Eu, 1u, "No trace level selected, defaulting to %s", v3);
result = func8(
"InitializeTrace",
"./src/trace.c",
0x7Bu,
2u,
"No trace file specified, outputting to standard output");
}
return result;
}

original_code:
static void InitializeTrace()
{
  int trace_level_defined;
  int trace_file_defined;
  if (!getenv("TRACE_LEVEL"))
  {
    _trace_level = TRACE_ERROR;
    trace_level_defined=1;
  }
  else if (!strcmp(getenv("TRACE_LEVEL"), __TRACE_LEVEL_OFF))
  {
    _trace_level = TRACE_OFF;
    trace_level_defined=2;
  }
  else if (!strcmp(getenv("TRACE_LEVEL"), __TRACE_LEVEL_ERROR))
  {
    _trace_level = TRACE_ERROR;
    trace_level_defined=2;
  }
  else if (!strcmp(getenv("TRACE_LEVEL"), __TRACE_LEVEL_WARNING))
  {
    _trace_level = TRACE_WARNING;
    trace_level_defined=2;
  }
  else if (!strcmp(getenv("TRACE_LEVEL"), __TRACE_LEVEL_INFO))
  {
    _trace_level = TRACE_INFO;
    trace_level_defined=2;
  }
  else if (!strcmp(getenv("TRACE_LEVEL"), __TRACE_LEVEL_DEBUG))
  {
    _trace_level = TRACE_DEBUG;
    trace_level_defined=2;
  }
  else
  {
    _trace_level = TRACE_ERROR;
    trace_level_defined=3;
  }
  if (!getenv("TRACE_FILE"))
  {
    _trace_file = stdout;
    trace_file_defined=1;
  }
  else if (!(_trace_file=fopen(getenv("TRACE_FILE"), "a")))
  {
    _trace_file = stdout;
    trace_file_defined=3;
  }
  else
  {
    trace_file_defined=2;
  }
  _trace_initialized=1;
  switch(trace_level_defined)
  {
    case 1:
      PrintTraceLine(__func__, "./src/trace.c", 110, TRACE_ERROR, "No trace level selected, defaulting to %s", GetLevelString(TRACE_ERROR));
      break;
    case 2:
      PrintTraceLine(__func__, "./src/trace.c", 113, TRACE_INFO, "Trace level: %s", GetLevelString(_trace_level));
      break;
    case 3:
      PrintTraceLine(__func__, "./src/trace.c", 116, TRACE_ERROR, "Wrong trace level selected: %s, defaulting to %s", getenv("TRACE_LEVEL"), GetLevelString(TRACE_ERROR));
      break;
  }
  switch(trace_level_defined)
  {
    case 1:
      PrintTraceLine(__func__, "./src/trace.c", 123, TRACE_WARNING, "No trace file specified, outputting to standard output");
      break;
    case 3:
      PrintTraceLine(__func__, "./src/trace.c", 126, TRACE_ERROR, "Unable to open trace file, outputting to standard output");
      break;
  }
}


yywrap

decompiled_code:
__int64 yywrap()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 1LL;
}

original_code:
int yywrap()
{
  return 1;
}

canonical_original_code:
int yywrap()
{
  return 1;
}


yyparse

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    YYSTYPE yyvsa[200];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 40)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-71))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 285 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 134 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 4:
    {
                    INSTRUCTION_LIST list;
                    list = createInstructionList();
                    if (list == 0)
                    {
                      exit(1);
                    }
                    addInstruction(list, (yyvsp[0].instruction));
                    (yyval.instruction_list) = list;
                  }
    break;
  case 5:
    {
                       INSTRUCTION_LIST list = (yyvsp[-1].instruction_list);
                       addInstruction(list, (yyvsp[0].instruction));
                       (yyval.instruction_list) = list;
                     }
    break;
  case 14:
    {
                (yyval.instruction_list) = (yyvsp[-1].instruction_list);
              }
    break;
  case 15:
    {
                  printf("Skip instruction\n");
                  INSTRUCTION instruction = createSkipInstruction();
                  if (instruction == 0)
                  {
                    exit(1);
                  }
                }
    break;
  case 16:
    {
                  printf("Read instruction for label <%s>\n", (yyvsp[-1].string));
                  printf(">> CONST %s\n", (yyvsp[-1].string));
                  printf(">> SWAPA\n");
                  printf(">> READ\n");
                  printf(">> STORE\n");
                  VARIABLE_TYPE label = createVariable((yyvsp[-1].string));
                  if (label == 0)
                  {
                    exit(1);
                  }
                  INSTRUCTION instruction = createReadInstruction(label);
                  if (instruction == 0)
                  {
                    exit(1);
                  }
                  (yyval.instruction) = instruction;
                }
    break;
  case 17:
    {
                   printf("Write instruction\n");
                   printf(">> WRITE\n");
                   INSTRUCTION instruction = createWriteInstruction((yyvsp[-1].arithmetic_expression_type));
                   if (instruction == 0)
                   {
                     exit(1);
                   }
                   (yyval.instruction) = instruction;
                 }
    break;
  case 18:
    {
                    printf("Assign instruction for label <%s>\n", (yyvsp[-3].string));
                    printf(">> SWAPD\n");
                    printf(">> CONST %s\n", (yyvsp[-3].string));
                    printf(">> SWAPA\n");
                    printf(">> SWAPD\n");
                    printf(">> STORE\n");
                    VARIABLE_TYPE label = createVariable((yyvsp[-3].string));
                    if (label == 0)
                    {
                      exit(1);
                    }
                    INSTRUCTION instruction = createAssignInstruction(label, (yyvsp[-1].arithmetic_expression_type));
                    if (instruction == 0)
                    {
                      exit(1);
                    }
                    (yyval.instruction) = instruction;
                  }
    break;
  case 19:
    {
              printf("If instruction\n");
            }
    break;
  case 20:
    {
                   printf("If-else instruction\n");
                 }
    break;
  case 21:
    {
                 printf("While instruction\n");
               }
    break;
  case 25:
    {
                            printf("Complete if-else instruction\n");
                          }
    break;
  case 26:
    {
                          printf("Complete while instruction\n");
                        }
    break;
  case 29:
    {
                         INSTRUCTION_LIST list;
                         list = createInstructionList();
                         if (list == 0)
                         {
                           exit(1);
                         }
                         addInstruction(list, (yyvsp[0].instruction));
                         (yyval.instruction_list) = list;
                       }
    break;
  case 32:
    {
                                  INSTRUCTION_LIST list;
                                  list = createInstructionList();
                                  if (list == 0)
                                  {
                                    exit(1);
                                  }
                                  addInstruction(list, (yyvsp[0].instruction));
                                  (yyval.instruction_list) = list;
                                }
    break;
  case 37:
    {
                              (yyval.arithmetic_expression_type) = (yyvsp[-1].arithmetic_expression_type);
                            }
    break;
  case 38:
    {
              printf("Factor with label <%s> loaded\n", (yyvsp[0].string));
              printf(">> CONST %s\n", (yyvsp[0].string));
              printf(">> SWAPA\n");
              printf(">> LOAD\n");
            }
    break;
  case 39:
    {
               printf("Factor with value <%d> loaded\n", (yyvsp[0].number));
               printf(">> CONST %d\n", (yyvsp[0].number));
             }
    break;
  case 40:
    {
                 printf("Negative factor loaded\n");
                 printf(">> CONST -%d\n", (yyvsp[0].number));
               }
    break;
  case 45:
    {
               printf("Mul operation loaded\n");
             }
    break;
  case 46:
    {
               printf("Div operation loaded\n");
             }
    break;
  case 47:
    {
               printf("Mod operation loaded\n");
             }
    break;
  case 51:
    {
               printf("Add operation loaded\n");
             }
    break;
  case 52:
    {
               printf("Sub operation loaded\n");
             }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 31;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 134 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 285 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-71))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 134 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 285 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

canonical_original_code:
int yyparse()
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    union YYSTYPE yyvsa[200];
    union YYSTYPE *yyvs;
    union YYSTYPE *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  union YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 40)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-71))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 285 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 134 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 4:
    {
                    struct _T_INSTRUCTION_LIST *list;
                    list = createInstructionList();
                    if (list == 0)
                    {
                      exit(1);
                    }
                    addInstruction(list, (yyvsp[0].instruction));
                    (yyval.instruction_list) = list;
                  }
    break;
  case 5:
    {
                       struct _T_INSTRUCTION_LIST *list = (yyvsp[-1].instruction_list);
                       addInstruction(list, (yyvsp[0].instruction));
                       (yyval.instruction_list) = list;
                     }
    break;
  case 14:
    {
                (yyval.instruction_list) = (yyvsp[-1].instruction_list);
              }
    break;
  case 15:
    {
                  printf("Skip instruction\n");
                  struct T_INSTRUCTION *instruction = createSkipInstruction();
                  if (instruction == 0)
                  {
                    exit(1);
                  }
                }
    break;
  case 16:
    {
                  printf("Read instruction for label <%s>\n", (yyvsp[-1].string));
                  printf(">> CONST %s\n", (yyvsp[-1].string));
                  printf(">> SWAPA\n");
                  printf(">> READ\n");
                  printf(">> STORE\n");
                  struct T_VARIABLE_TYPE *label = createVariable((yyvsp[-1].string));
                  if (label == 0)
                  {
                    exit(1);
                  }
                  struct T_INSTRUCTION *instruction = createReadInstruction(label);
                  if (instruction == 0)
                  {
                    exit(1);
                  }
                  (yyval.instruction) = instruction;
                }
    break;
  case 17:
    {
                   printf("Write instruction\n");
                   printf(">> WRITE\n");
                   struct T_INSTRUCTION *instruction = createWriteInstruction((yyvsp[-1].arithmetic_expression_type));
                   if (instruction == 0)
                   {
                     exit(1);
                   }
                   (yyval.instruction) = instruction;
                 }
    break;
  case 18:
    {
                    printf("Assign instruction for label <%s>\n", (yyvsp[-3].string));
                    printf(">> SWAPD\n");
                    printf(">> CONST %s\n", (yyvsp[-3].string));
                    printf(">> SWAPA\n");
                    printf(">> SWAPD\n");
                    printf(">> STORE\n");
                    struct T_VARIABLE_TYPE *label = createVariable((yyvsp[-3].string));
                    if (label == 0)
                    {
                      exit(1);
                    }
                    struct T_INSTRUCTION *instruction = createAssignInstruction(label, (yyvsp[-1].arithmetic_expression_type));
                    if (instruction == 0)
                    {
                      exit(1);
                    }
                    (yyval.instruction) = instruction;
                  }
    break;
  case 19:
    {
              printf("If instruction\n");
            }
    break;
  case 20:
    {
                   printf("If-else instruction\n");
                 }
    break;
  case 21:
    {
                 printf("While instruction\n");
               }
    break;
  case 25:
    {
                            printf("Complete if-else instruction\n");
                          }
    break;
  case 26:
    {
                          printf("Complete while instruction\n");
                        }
    break;
  case 29:
    {
                         struct _T_INSTRUCTION_LIST *list;
                         list = createInstructionList();
                         if (list == 0)
                         {
                           exit(1);
                         }
                         addInstruction(list, (yyvsp[0].instruction));
                         (yyval.instruction_list) = list;
                       }
    break;
  case 32:
    {
                                  struct _T_INSTRUCTION_LIST *list;
                                  list = createInstructionList();
                                  if (list == 0)
                                  {
                                    exit(1);
                                  }
                                  addInstruction(list, (yyvsp[0].instruction));
                                  (yyval.instruction_list) = list;
                                }
    break;
  case 37:
    {
                              (yyval.arithmetic_expression_type) = (yyvsp[-1].arithmetic_expression_type);
                            }
    break;
  case 38:
    {
              printf("Factor with label <%s> loaded\n", (yyvsp[0].string));
              printf(">> CONST %s\n", (yyvsp[0].string));
              printf(">> SWAPA\n");
              printf(">> LOAD\n");
            }
    break;
  case 39:
    {
               printf("Factor with value <%d> loaded\n", (yyvsp[0].number));
               printf(">> CONST %d\n", (yyvsp[0].number));
             }
    break;
  case 40:
    {
                 printf("Negative factor loaded\n");
                 printf(">> CONST -%d\n", (yyvsp[0].number));
               }
    break;
  case 45:
    {
               printf("Mul operation loaded\n");
             }
    break;
  case 46:
    {
               printf("Div operation loaded\n");
             }
    break;
  case 47:
    {
               printf("Mod operation loaded\n");
             }
    break;
  case 51:
    {
               printf("Add operation loaded\n");
             }
    break;
  case 52:
    {
               printf("Sub operation loaded\n");
             }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 31;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 134 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 285 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-71))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 134 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 285 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types: union YYSTYPE { char *string; int number; struct T_INSTRUCTION { enum INSTRUCTION_TYPE { INSTRUCTION_SKIP=0, INSTRUCTION_READ=1, INSTRUCTION_WRITE=2, INSTRUCTION_ASSIGN=3, INSTRUCTION_IF=4, INSTRUCTION_WHILE=5 } type; union { struct INSTRUCTION_READ_PARAMS { struct T_VARIABLE_TYPE { enum VARIABLE_ENTRY_TYPE { CONST_VARIABLE=0, MUTABLE_VARIABLE=1 } type; union { char *variable_name; int variable_value; }; } *variable; } read_params; struct INSTRUCTION_WRITE_PARAMS { struct _T_ARITHMETIC_EXPRESSION { enum ARITHMETIC_EXPRESSION_ENTRY_TYPE { SIMPLE_ARITHMETIC_EXPRESSION=0, COMPOSITE_ARITHMETIC_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum ARITHMETIC_OPERATION { ARITHMETIC_ADD=0, ARITHMETIC_SUB=1, ARITHMETIC_MUL=2, ARITHMETIC_DIV=3, ARITHMETIC_MOD=4 } operation; struct _T_ARITHMETIC_EXPRESSION *param1; struct _T_ARITHMETIC_EXPRESSION *param2; }; }; } *expression; } write_params; struct INSTRUCTION_ASSIGN_PARAMS { struct T_VARIABLE_TYPE *variable; struct _T_ARITHMETIC_EXPRESSION *expression; } assign_params; struct INSTRUCTION_IF_PARAMS { struct _T_LOGICAL_EXPRESSION { enum LOGICAL_EXPRESSION_ENTRY_TYPE { SIMPLE_LOGICAL_EXPRESSION=0, COMPOSITE_LOGICAL_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum LOGICAL_OPERATION { LOGICAL_TRUE=0, LOGICAL_FALSE=1, LOGICAL_NOT=2, LOGICAL_AND=3, LOGICAL_OR=4 } operation; struct _T_LOGICAL_EXPRESSION *param1; struct _T_LOGICAL_EXPRESSION *param2; }; }; } *expression; struct _T_INSTRUCTION_LIST { struct _T_INSTRUCTION_LIST_ENTRY { struct T_INSTRUCTION *instruction; struct _T_INSTRUCTION_LIST_ENTRY *next; } *first; struct _T_INSTRUCTION_LIST_ENTRY *last; } *nested_true_code_block; struct _T_INSTRUCTION_LIST *nested_false_code_block; } if_params; struct INSTRUCTION_WHILE_PARAMS { struct _T_LOGICAL_EXPRESSION *expression; struct _T_INSTRUCTION_LIST *nested_code_block; } while_params; }; } *instruction; struct _T_INSTRUCTION_LIST *instruction_list; struct _T_ARITHMETIC_EXPRESSION *arithmetic_expression_type; } [200]

variable_types: union YYSTYPE { char *string; int number; struct T_INSTRUCTION { enum INSTRUCTION_TYPE { INSTRUCTION_SKIP=0, INSTRUCTION_READ=1, INSTRUCTION_WRITE=2, INSTRUCTION_ASSIGN=3, INSTRUCTION_IF=4, INSTRUCTION_WHILE=5 } type; union { struct INSTRUCTION_READ_PARAMS { struct T_VARIABLE_TYPE { enum VARIABLE_ENTRY_TYPE { CONST_VARIABLE=0, MUTABLE_VARIABLE=1 } type; union { char *variable_name; int variable_value; }; } *variable; } read_params; struct INSTRUCTION_WRITE_PARAMS { struct _T_ARITHMETIC_EXPRESSION { enum ARITHMETIC_EXPRESSION_ENTRY_TYPE { SIMPLE_ARITHMETIC_EXPRESSION=0, COMPOSITE_ARITHMETIC_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum ARITHMETIC_OPERATION { ARITHMETIC_ADD=0, ARITHMETIC_SUB=1, ARITHMETIC_MUL=2, ARITHMETIC_DIV=3, ARITHMETIC_MOD=4 } operation; struct _T_ARITHMETIC_EXPRESSION *param1; struct _T_ARITHMETIC_EXPRESSION *param2; }; }; } *expression; } write_params; struct INSTRUCTION_ASSIGN_PARAMS { struct T_VARIABLE_TYPE *variable; struct _T_ARITHMETIC_EXPRESSION *expression; } assign_params; struct INSTRUCTION_IF_PARAMS { struct _T_LOGICAL_EXPRESSION { enum LOGICAL_EXPRESSION_ENTRY_TYPE { SIMPLE_LOGICAL_EXPRESSION=0, COMPOSITE_LOGICAL_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum LOGICAL_OPERATION { LOGICAL_TRUE=0, LOGICAL_FALSE=1, LOGICAL_NOT=2, LOGICAL_AND=3, LOGICAL_OR=4 } operation; struct _T_LOGICAL_EXPRESSION *param1; struct _T_LOGICAL_EXPRESSION *param2; }; }; } *expression; struct _T_INSTRUCTION_LIST { struct _T_INSTRUCTION_LIST_ENTRY { struct T_INSTRUCTION *instruction; struct _T_INSTRUCTION_LIST_ENTRY *next; } *first; struct _T_INSTRUCTION_LIST_ENTRY *last; } *nested_true_code_block; struct _T_INSTRUCTION_LIST *nested_false_code_block; } if_params; struct INSTRUCTION_WHILE_PARAMS { struct _T_LOGICAL_EXPRESSION *expression; struct _T_INSTRUCTION_LIST *nested_code_block; } while_params; }; } *instruction; struct _T_INSTRUCTION_LIST *instruction_list; struct _T_ARITHMETIC_EXPRESSION *arithmetic_expression_type; } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; union YYSTYPE { char *string; int number; struct T_INSTRUCTION { enum INSTRUCTION_TYPE { INSTRUCTION_SKIP=0, INSTRUCTION_READ=1, INSTRUCTION_WRITE=2, INSTRUCTION_ASSIGN=3, INSTRUCTION_IF=4, INSTRUCTION_WHILE=5 } type; union { struct INSTRUCTION_READ_PARAMS { struct T_VARIABLE_TYPE { enum VARIABLE_ENTRY_TYPE { CONST_VARIABLE=0, MUTABLE_VARIABLE=1 } type; union { char *variable_name; int variable_value; }; } *variable; } read_params; struct INSTRUCTION_WRITE_PARAMS { struct _T_ARITHMETIC_EXPRESSION { enum ARITHMETIC_EXPRESSION_ENTRY_TYPE { SIMPLE_ARITHMETIC_EXPRESSION=0, COMPOSITE_ARITHMETIC_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum ARITHMETIC_OPERATION { ARITHMETIC_ADD=0, ARITHMETIC_SUB=1, ARITHMETIC_MUL=2, ARITHMETIC_DIV=3, ARITHMETIC_MOD=4 } operation; struct _T_ARITHMETIC_EXPRESSION *param1; struct _T_ARITHMETIC_EXPRESSION *param2; }; }; } *expression; } write_params; struct INSTRUCTION_ASSIGN_PARAMS { struct T_VARIABLE_TYPE *variable; struct _T_ARITHMETIC_EXPRESSION *expression; } assign_params; struct INSTRUCTION_IF_PARAMS { struct _T_LOGICAL_EXPRESSION { enum LOGICAL_EXPRESSION_ENTRY_TYPE { SIMPLE_LOGICAL_EXPRESSION=0, COMPOSITE_LOGICAL_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum LOGICAL_OPERATION { LOGICAL_TRUE=0, LOGICAL_FALSE=1, LOGICAL_NOT=2, LOGICAL_AND=3, LOGICAL_OR=4 } operation; struct _T_LOGICAL_EXPRESSION *param1; struct _T_LOGICAL_EXPRESSION *param2; }; }; } *expression; struct _T_INSTRUCTION_LIST { struct _T_INSTRUCTION_LIST_ENTRY { struct T_INSTRUCTION *instruction; struct _T_INSTRUCTION_LIST_ENTRY *next; } *first; struct _T_INSTRUCTION_LIST_ENTRY *last; } *nested_true_code_block; struct _T_INSTRUCTION_LIST *nested_false_code_block; } if_params; struct INSTRUCTION_WHILE_PARAMS { struct _T_LOGICAL_EXPRESSION *expression; struct _T_INSTRUCTION_LIST *nested_code_block; } while_params; }; } *instruction; struct _T_INSTRUCTION_LIST *instruction_list; struct _T_ARITHMETIC_EXPRESSION *arithmetic_expression_type; } yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: struct _T_INSTRUCTION_LIST { struct _T_INSTRUCTION_LIST_ENTRY { struct T_INSTRUCTION { enum INSTRUCTION_TYPE { INSTRUCTION_SKIP=0, INSTRUCTION_READ=1, INSTRUCTION_WRITE=2, INSTRUCTION_ASSIGN=3, INSTRUCTION_IF=4, INSTRUCTION_WHILE=5 } type; union { struct INSTRUCTION_READ_PARAMS { struct T_VARIABLE_TYPE { enum VARIABLE_ENTRY_TYPE { CONST_VARIABLE=0, MUTABLE_VARIABLE=1 } type; union { char *variable_name; int variable_value; }; } *variable; } read_params; struct INSTRUCTION_WRITE_PARAMS { struct _T_ARITHMETIC_EXPRESSION { enum ARITHMETIC_EXPRESSION_ENTRY_TYPE { SIMPLE_ARITHMETIC_EXPRESSION=0, COMPOSITE_ARITHMETIC_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum ARITHMETIC_OPERATION { ARITHMETIC_ADD=0, ARITHMETIC_SUB=1, ARITHMETIC_MUL=2, ARITHMETIC_DIV=3, ARITHMETIC_MOD=4 } operation; struct _T_ARITHMETIC_EXPRESSION *param1; struct _T_ARITHMETIC_EXPRESSION *param2; }; }; } *expression; } write_params; struct INSTRUCTION_ASSIGN_PARAMS { struct T_VARIABLE_TYPE *variable; struct _T_ARITHMETIC_EXPRESSION *expression; } assign_params; struct INSTRUCTION_IF_PARAMS { struct _T_LOGICAL_EXPRESSION { enum LOGICAL_EXPRESSION_ENTRY_TYPE { SIMPLE_LOGICAL_EXPRESSION=0, COMPOSITE_LOGICAL_EXPRESSION=1 } type; union { struct T_VARIABLE_TYPE *variable; struct { enum LOGICAL_OPERATION { LOGICAL_TRUE=0, LOGICAL_FALSE=1, LOGICAL_NOT=2, LOGICAL_AND=3, LOGICAL_OR=4 } operation; struct _T_LOGICAL_EXPRESSION *param1; struct _T_LOGICAL_EXPRESSION *param2; }; }; } *expression; struct _T_INSTRUCTION_LIST *nested_true_code_block; struct _T_INSTRUCTION_LIST *nested_false_code_block; } if_params; struct INSTRUCTION_WHILE_PARAMS { struct _T_LOGICAL_EXPRESSION *expression; struct _T_INSTRUCTION_LIST *nested_code_block; } while_params; }; } *instruction; struct _T_INSTRUCTION_LIST_ENTRY *next; } *first; struct _T_INSTRUCTION_LIST_ENTRY *last; } *

variable_types: yylhs int

variable_types: yyi int

user_defined_types: union YYSTYPE { char *string; int number; struct T_INSTRUCTION *instruction; struct _T_INSTRUCTION_LIST *instruction_list; struct _T_ARITHMETIC_EXPRESSION *arithmetic_expression_type; }

user_defined_types: union yyalloc { short yyss_alloc; union YYSTYPE yyvs_alloc; }

user_defined_types: struct _T_INSTRUCTION_LIST { struct _T_INSTRUCTION_LIST_ENTRY *first; struct _T_INSTRUCTION_LIST_ENTRY *last; }

user_defined_types: struct T_INSTRUCTION { enum INSTRUCTION_TYPE type; union { struct INSTRUCTION_READ_PARAMS read_params; struct INSTRUCTION_WRITE_PARAMS write_params; struct INSTRUCTION_ASSIGN_PARAMS assign_params; struct INSTRUCTION_IF_PARAMS if_params; struct INSTRUCTION_WHILE_PARAMS while_params; }; }

user_defined_types: struct T_VARIABLE_TYPE { enum VARIABLE_ENTRY_TYPE type; union { char *variable_name; int variable_value; }; }

user_defined_types: struct INSTRUCTION_READ_PARAMS { struct T_VARIABLE_TYPE *variable; }

user_defined_types: struct INSTRUCTION_WRITE_PARAMS { struct _T_ARITHMETIC_EXPRESSION *expression; }

user_defined_types: struct INSTRUCTION_IF_PARAMS { struct _T_LOGICAL_EXPRESSION *expression; struct _T_INSTRUCTION_LIST *nested_true_code_block; struct _T_INSTRUCTION_LIST *nested_false_code_block; }

user_defined_types: struct _T_ARITHMETIC_EXPRESSION { enum ARITHMETIC_EXPRESSION_ENTRY_TYPE type; union { struct T_VARIABLE_TYPE *variable; struct { enum ARITHMETIC_OPERATION operation; struct _T_ARITHMETIC_EXPRESSION *param1; struct _T_ARITHMETIC_EXPRESSION *param2; }; }; }

user_defined_types: struct _T_LOGICAL_EXPRESSION { enum LOGICAL_EXPRESSION_ENTRY_TYPE type; union { struct T_VARIABLE_TYPE *variable; struct { enum LOGICAL_OPERATION operation; struct _T_LOGICAL_EXPRESSION *param1; struct _T_LOGICAL_EXPRESSION *param2; }; }; }


hctoi

repo: dce/one-timer

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

switch ( a1 )
{
case '0':
result = 0LL;
break;
case '1':
result = 1LL;
break;
case '2':
result = 2LL;
break;
case '3':
result = 3LL;
break;
case '4':
result = 4LL;
break;
case '5':
result = 5LL;
break;
case '6':
result = 6LL;
break;
case '7':
result = 7LL;
break;
case '8':
result = 8LL;
break;
case '9':
result = 9LL;
break;
case 'a':
result = 10LL;
break;
case 'b':
result = 11LL;
break;
case 'c':
result = 12LL;
break;
case 'd':
result = 13LL;
break;
case 'e':
result = 14LL;
break;
case 'f':
result = 15LL;
break;
default:
puts("Invalid hex char.");
exit(1);
}
return result;
}

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

switch ( a1 )
{
case '0':
result = 0LL;
break;
case '1':
result = 1LL;
break;
case '2':
result = 2LL;
break;
case '3':
result = 3LL;
break;
case '4':
result = 4LL;
break;
case '5':
result = 5LL;
break;
case '6':
result = 6LL;
break;
case '7':
result = 7LL;
break;
case '8':
result = 8LL;
break;
case '9':
result = 9LL;
break;
case 'a':
result = 10LL;
break;
case 'b':
result = 11LL;
break;
case 'c':
result = 12LL;
break;
case 'd':
result = 13LL;
break;
case 'e':
result = 14LL;
break;
case 'f':
result = 15LL;
break;
default:
puts("Invalid hex char.");
exit(1);
}
return result;
}

original_code:
int
hctoi(char c)
{
    int i;
    switch (c) {
        case '0': i = 0; break;
        case '1': i = 1; break;
        case '2': i = 2; break;
        case '3': i = 3; break;
        case '4': i = 4; break;
        case '5': i = 5; break;
        case '6': i = 6; break;
        case '7': i = 7; break;
        case '8': i = 8; break;
        case '9': i = 9; break;
        case 'a': i = 10; break;
        case 'b': i = 11; break;
        case 'c': i = 12; break;
        case 'd': i = 13; break;
        case 'e': i = 14; break;
        case 'f': i = 15; break;
        default:
            printf("Invalid hex char.\n");
            exit(1);
    }
    return i;
}

variable_types: c char

variable_types: i int


itohc

decompiled_code:
__int64 __fastcall itohc(unsigned int a1)
{
if ( a1 > 0xF )
{
puts("Invalid hex int.");
exit(1);
}
return (unsigned __int8)CSWTCH_2[a1];
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
if ( a1 > 0xF )
{
puts("Invalid hex int.");
exit(1);
}
return (unsigned __int8)CSWTCH_2[a1];
}

original_code:
char
itohc(int i) {
    char c;
    switch (i) {
        case 0: c = '0'; break;
        case 1: c = '1'; break;
        case 2: c = '2'; break;
        case 3: c = '3'; break;
        case 4: c = '4'; break;
        case 5: c = '5'; break;
        case 6: c = '6'; break;
        case 7: c = '7'; break;
        case 8: c = '8'; break;
        case 9: c = '9'; break;
        case 10: c = 'a'; break;
        case 11: c = 'b'; break;
        case 12: c = 'c'; break;
        case 13: c = 'd'; break;
        case 14: c = 'e'; break;
        case 15: c = 'f'; break;
        default:
            printf("Invalid hex int.\n");
            exit(1);
    }
    return c;
}

return_type: char


hctoi

canonical_original_code:
int hctoi(char c)
{
    int i;
    switch (c) {
        case '0': i = 0; break;
        case '1': i = 1; break;
        case '2': i = 2; break;
        case '3': i = 3; break;
        case '4': i = 4; break;
        case '5': i = 5; break;
        case '6': i = 6; break;
        case '7': i = 7; break;
        case '8': i = 8; break;
        case '9': i = 9; break;
        case 'a': i = 10; break;
        case 'b': i = 11; break;
        case 'c': i = 12; break;
        case 'd': i = 13; break;
        case 'e': i = 14; break;
        case 'f': i = 15; break;
        default:
            printf("Invalid hex char.\n");
            exit(1);
    }
    return i;
}


itohc

canonical_original_code:
char itohc(int i) {
    char c;
    switch (i) {
        case 0: c = '0'; break;
        case 1: c = '1'; break;
        case 2: c = '2'; break;
        case 3: c = '3'; break;
        case 4: c = '4'; break;
        case 5: c = '5'; break;
        case 6: c = '6'; break;
        case 7: c = '7'; break;
        case 8: c = '8'; break;
        case 9: c = '9'; break;
        case 10: c = 'a'; break;
        case 11: c = 'b'; break;
        case 12: c = 'c'; break;
        case 13: c = 'd'; break;
        case 14: c = 'e'; break;
        case 15: c = 'f'; break;
        default:
            printf("Invalid hex int.\n");
            exit(1);
    }
    return c;
}


main

canonical_name: main

repo: dcolascione/cygspawn

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rdi
int v5; // ebp
char *v6; // rdi
size_t v7; // r14
void *v8; // rax
int v9; // ebx
int result; // eax

v4 = getenv("ITER");
if ( !v4 )
v4 = "1";
v5 = atoi(v4);
v6 = getenv("JUNKBYTES");
if ( !v6 )
v6 = "0";
v7 = atoi(v6);
v8 = malloc(v7);
memset(v8, 42, v7);
if ( !v5 )
return 0;
v9 = 0;
while ( 1 )
{
result = do_work((unsigned int)argc, argv);
if ( result )
break;
if ( v5 == ++v9 )
return 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rdi
int v5; // ebp
char *v6; // rdi
size_t v7; // r14
void *v8; // rax
int v9; // ebx
int result; // eax

v4 = getenv("ITER");
if ( !v4 )
v4 = "1";
v5 = atoi(v4);
v6 = getenv("JUNKBYTES");
if ( !v6 )
v6 = "0";
v7 = atoi(v6);
v8 = malloc(v7);
memset(v8, 42, v7);
if ( !v5 )
return 0;
v9 = 0;
while ( 1 )
{
result = func9((unsigned int)argc, argv);
if ( result )
break;
if ( v5 == ++v9 )
return 0;
}
return result;
}

original_code:
int
main (int argc, char **argv)
{
  int i;
  int ret;
  unsigned iter = atoi (getenv ("ITER") ?: "1");
  size_t junk_size = atoi (getenv ("JUNKBYTES") ?: "0");
  char *junk = malloc (junk_size);
  memset (junk, 42, junk_size);
  for (i = 0; i < iter; ++i)
    {
      ret = do_work (argc, argv);
      if (ret != 0)
        break;
    }
  return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int i;
  int ret;
  unsigned int iter = atoi (getenv ("ITER") ?: "1");
  unsigned long junk_size = atoi (getenv ("JUNKBYTES") ?: "0");
  char *junk = malloc (junk_size);
  memset (junk, 42, junk_size);
  for (i = 0; i < iter; ++i)
    {
      ret = do_work (argc, argv);
      if (ret != 0)
        break;
    }
  return ret;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ret int

variable_types:
iter
unsigned int

variable_types:
junk
char *


usage

decompiled_code:
size_t usage()
{
return fwrite("testspawn [-vg] SHELL_REDIR* PROGRAM ARGS*: test posix_spawn\n", 1uLL, 0x3DuLL, _bss_start);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite("testspawn [-vg] SHELL_REDIR* PROGRAM ARGS*: test posix_spawn\n", 1uLL, 0x3DuLL, _bss_start);
}

original_code:
static void
usage ()
{
  fprintf (stderr,
           "testspawn [-vg] SHELL_REDIR* PROGRAM ARGS*: test posix_spawn\n");
}

canonical_original_code:
static void usage()
{
  fprintf (stderr,
           "testspawn [-vg] SHELL_REDIR* PROGRAM ARGS*: test posix_spawn\n");
}


decompiled_code:
__int64 __fastcall do_work(__int64 a1, __int64 a2)
{
__pid_t v2; // eax
__int64 v3; // r12
const char *i; // rbp
char v5; // al
char *v6; // rbp
__int64 result; // rax
unsigned __int8 v8; // ah
__int64 v9; // rsi
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = fork();
if ( v2 < 0 )
{
perror("fork");
result = 1LL;
}
else if ( v2 )
{
if ( wait((__WAIT_STATUS)&stat_loc) < 0 )
{
perror("wait");
result = 1LL;
}
else
{
v8 = BYTE1(stat_loc.__uptr);
v9 = (__int64)stat_loc.__uptr & 0x7F;
if ( ((__int64)stat_loc.__uptr & 0x7F) != 0 )
{
if ( verbose )
{
printf("child killed: %d\n", v9);
LODWORD(v9) = (__int64)stat_loc.__uptr & 0x7F;
}
result = (unsigned int)(v9 + 127);
}
else
{
if ( verbose )
{
printf("child exited: %d\n", BYTE1(stat_loc.__uptr));
v8 = BYTE1(stat_loc.__uptr);
}
result = v8;
}
}
}
else
{
v3 = a2 + 8;
for ( i = *(const char **)(a2 + 8); i; v3 += 8LL )
{
if ( *i == 45 )
{
v5 = i[1];
v6 = (char *)(i + 1);
if ( v5 )
{
if ( v5 != 118 )
{
LABEL_13:
fprintf(_bss_start, "testspawn: unknown flag '%c'\n", (unsigned int)v5);
usage();
return 1LL;
}
while ( 1 )
{
verbose = 1;
v5 = *++v6;
if ( !v5 )
break;
if ( v5 != 118 )
goto LABEL_13;
}
}
}
else
{
if ( !strchr("0123456789<>", *i) )
{
execvp(i, (char *const *)v3);
perror("execvp");
_exit(127);
}
if ( (int)process_redirection_constprop_0(i) < 0 )
goto LABEL_15;
}
i = *(const char **)(v3 + 8);
}
fwrite("testspawn: no program given!\n", 1uLL, 0x1DuLL, _bss_start);
usage();
LABEL_15:
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__pid_t v2; // eax
__int64 v3; // r12
const char *i; // rbp
char v5; // al
char *v6; // rbp
__int64 result; // rax
unsigned __int8 v8; // ah
__int64 v9; // rsi
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = fork();
if ( v2 < 0 )
{
perror("fork");
result = 1LL;
}
else if ( v2 )
{
if ( wait((__WAIT_STATUS)&stat_loc) < 0 )
{
perror("wait");
result = 1LL;
}
else
{
v8 = BYTE1(stat_loc.__uptr);
v9 = (__int64)stat_loc.__uptr & 0x7F;
if ( ((__int64)stat_loc.__uptr & 0x7F) != 0 )
{
if ( verbose )
{
printf("child killed: %d\n", v9);
LODWORD(v9) = (__int64)stat_loc.__uptr & 0x7F;
}
result = (unsigned int)(v9 + 127);
}
else
{
if ( verbose )
{
printf("child exited: %d\n", BYTE1(stat_loc.__uptr));
v8 = BYTE1(stat_loc.__uptr);
}
result = v8;
}
}
}
else
{
v3 = a2 + 8;
for ( i = *(const char **)(a2 + 8); i; v3 += 8LL )
{
if ( *i == 45 )
{
v5 = i[1];
v6 = (char *)(i + 1);
if ( v5 )
{
if ( v5 != 118 )
{
LABEL_13:
fprintf(_bss_start, "testspawn: unknown flag '%c'\n", (unsigned int)v5);
func7();
return 1LL;
}
while ( 1 )
{
verbose = 1;
v5 = *++v6;
if ( !v5 )
break;
if ( v5 != 118 )
goto LABEL_13;
}
}
}
else
{
if ( !strchr("0123456789<>", *i) )
{
execvp(i, (char *const *)v3);
perror("execvp");
_exit(127);
}
if ( (int)func8(i) < 0 )
goto LABEL_15;
}
i = *(const char **)(v3 + 8);
}
fwrite("testspawn: no program given!\n", 1uLL, 0x1DuLL, _bss_start);
func7();
LABEL_15:
result = 1LL;
}
return result;
}

original_code:
int
do_work (int argc, char **argv)
{
  char *c;
  pid_t child;
  int status;
  void *file_actions;
  child = fork ();
  if (child < 0)
    {
      perror ("fork");
      return 1;
    }
  if (child != 0)
    goto parent;
  for (++argv; *argv; ++argv)
    {
      if (**argv == '-')
        {
          for (c = *argv + 1; *c; ++c)
            switch (*c)
              {
              case 'v':
                verbose = 1;
                break;
              default:
                fprintf (stderr, "testspawn: unknown flag '%c'\n", *c);
                usage ();
                return 1;
              }
          continue;
        }
      if (!strchr ("0123456789<>", **argv))
        break;
      if (process_redirection (&file_actions, *argv) < 0)
        return 1;
    }
  if (!argv[0])
    {
      fprintf (stderr, "testspawn: no program given!\n");
      usage ();
      return 1;
    }
  execvp (argv[0], argv);
  perror ("execvp");
  _exit (127);
 parent:
  if (wait (&status) < 0)
    {
      perror ("wait");
      return 1;
    }
  if ((((status) & 0x7f) == 0))
    {
      if (verbose)
        printf ("child exited: %d\n", (((status) & 0xff00) >> 8));
      return (((status) & 0xff00) >> 8);
    }
  if (verbose)
    printf ("child killed: %d\n", ((status) & 0x7f));
  return 127 + ((status) & 0x7f);
}

canonical_original_code:
int do_work(int argc, char **argv)
{
  char *c;
  int child;
  int status;
  void *file_actions;
  child = fork ();
  if (child < 0)
    {
      perror ("fork");
      return 1;
    }
  if (child != 0)
    goto parent;
  for (++argv; *argv; ++argv)
    {
      if (**argv == '-')
        {
          for (c = *argv + 1; *c; ++c)
            switch (*c)
              {
              case 'v':
                verbose = 1;
                break;
              default:
                fprintf (stderr, "testspawn: unknown flag '%c'\n", *c);
                usage ();
                return 1;
              }
          continue;
        }
      if (!strchr ("0123456789<>", **argv))
        break;
      if (process_redirection (&file_actions, *argv) < 0)
        return 1;
    }
  if (!argv[0])
    {
      fprintf (stderr, "testspawn: no program given!\n");
      usage ();
      return 1;
    }
  execvp (argv[0], argv);
  perror ("execvp");
  _exit (127);
 parent:
  if (wait (&status) < 0)
    {
      perror ("wait");
      return 1;
    }
  if ((((status) & 0x7f) == 0))
    {
      if (verbose)
        printf ("child exited: %d\n", (((status) & 0xff00) >> 8));
      return (((status) & 0xff00) >> 8);
    }
  if (verbose)
    printf ("child killed: %d\n", ((status) & 0x7f));
  return 127 + ((status) & 0x7f);
}

variable_types:
c
char *

variable_types: child int

variable_types: status int


repo: dcollien/Alcubierre

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

result = malloc(0x18uLL);
if ( !result )
_assert_fail("list != NULL", "types/List.c", 0x1Au, "new_List");
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

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

result = malloc(0x18uLL);
if ( !result )
_assert_fail("list != NULL", "types/List.c", 0x1Au, "new_List");
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
List new_List(void) {
 List list = malloc(sizeof(struct _list));
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "types/List.c", 26, __extension__ __PRETTY_FUNCTION__); }));
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->size = 0;
 return list;
}

canonical_original_code:
struct _list *new_List() {
 struct _list *list = malloc(sizeof(struct _list));
 ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "types/List.c", 26, __extension__ __PRETTY_FUNCTION__); }));
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->size = 0;
 return list;
}

variable_types: struct _list { struct listNode { unsigned long value; struct listNode *next; struct listNode *prev; } *first; struct listNode *last; unsigned int size; } *

user_defined_types: struct _list { struct listNode *first; struct listNode *last; unsigned int size; }


decompiled_code:
void __fastcall destroy_List(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

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

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void destroy_List(List list) {
 listNodePtr_t node, prevNode;
 node = list->first;
 while (node != ((void *)0)) {
  prevNode = node;
  node = node->next;
  free(prevNode);
 }
 free(list);
}

canonical_original_code:
void destroy_List(struct _list *list) {
 struct listNode *node; struct listNode *prevNode;
 node = list->first;
 while (node != ((void *)0)) {
  prevNode = node;
  node = node->next;
  free(prevNode);
 }
 free(list);
}

variable_types: struct listNode { unsigned long value; struct listNode *next; struct listNode *prev; } *


decompiled_code:
__int64 __fastcall removeFirst_List(__int64 a1)
{
__int64 *v2; // rdi
__int64 v3; // r12
__int64 result; // rax

v2 = *(__int64 **)a1;
if ( !v2 )
_assert_fail("list->first != NULL", "types/List.c", 0x4Du, "removeFirst_List");
v3 = *v2;
*(_QWORD *)a1 = v2[1];
free(v2);
if ( *(_QWORD *)a1 )
{
*(_QWORD *)(*(_QWORD *)a1 + 16LL) = 0LL;
result = v3;
--*(_DWORD *)(a1 + 16);
}
else
{
--*(_DWORD *)(a1 + 16);
result = v3;
*(_QWORD *)(a1 + 8) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 *v2; // rdi
__int64 v3; // r12
__int64 result; // rax

v2 = *(__int64 **)a1;
if ( !v2 )
_assert_fail("list->first != NULL", "types/List.c", 0x4Du, "removeFirst_List");
v3 = *v2;
*(_QWORD *)a1 = v2[1];
free(v2);
if ( *(_QWORD *)a1 )
{
*(_QWORD *)(*(_QWORD *)a1 + 16LL) = 0LL;
result = v3;
--*(_DWORD *)(a1 + 16);
}
else
{
--*(_DWORD *)(a1 + 16);
result = v3;
*(_QWORD *)(a1 + 8) = 0LL;
}
return result;
}

original_code:
any_t removeFirst_List(List list) {
 ((void) sizeof ((list->first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->first != ((void *)0)) ; else __assert_fail ("list->first != NULL", "types/List.c", 77, __extension__ __PRETTY_FUNCTION__); }));
 any_t value = list->first->value;
 listNodePtr_t removedNode = list->first;
 list->first = removedNode->next;
 free(removedNode);
 if (list->first == ((void *)0)) {
  list->last = list->first;
 } else {
  list->first->prev = ((void *)0);
 }
 --(list->size);
 return value;
}

canonical_original_code:
unsigned long removeFirst_List(struct _list *list) {
 ((void) sizeof ((list->first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->first != ((void *)0)) ; else __assert_fail ("list->first != NULL", "types/List.c", 77, __extension__ __PRETTY_FUNCTION__); }));
 unsigned long value = list->first->value;
 struct listNode *removedNode = list->first;
 list->first = removedNode->next;
 free(removedNode);
 if (list->first == ((void *)0)) {
  list->last = list->first;
 } else {
  list->first->prev = ((void *)0);
 }
 --(list->size);
 return value;
}

variable_types:
value
unsigned long

return_type: unsigned long

user_defined_types: struct listNode { unsigned long value; struct listNode *next; struct listNode *prev; }


decompiled_code:
__int64 __fastcall removeLast_List(__int64 a1)
{
__int64 *v2; // rdi
__int64 v3; // r12
__int64 v4; // rax
__int64 result; // rax

v2 = *(__int64 **)(a1 + 8);
if ( !v2 )
_assert_fail("list->last != NULL", "types/List.c", 0x62u, "removeLast_List");
v3 = *v2;
*(_QWORD *)(a1 + 8) = v2[2];
free(v2);
v4 = *(_QWORD *)(a1 + 8);
if ( v4 )
{
*(_QWORD *)(v4 + 8) = 0LL;
result = v3;
--*(_DWORD *)(a1 + 16);
}
else
{
--*(_DWORD *)(a1 + 16);
result = v3;
*(_QWORD *)a1 = 0LL;
}
return result;
}

original_code:
any_t removeLast_List(List list) {
 ((void) sizeof ((list->last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->last != ((void *)0)) ; else __assert_fail ("list->last != NULL", "types/List.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 any_t value = list->last->value;
 listNodePtr_t removedNode = list->last;
 list->last = removedNode->prev;
 free(removedNode);
 if (list->last == ((void *)0)) {
  list->first = list->last;
 } else {
  list->last->next = ((void *)0);
 }
 --(list->size);
 return value;
}

canonical_original_code:
unsigned long removeLast_List(struct _list *list) {
 ((void) sizeof ((list->last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->last != ((void *)0)) ; else __assert_fail ("list->last != NULL", "types/List.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 unsigned long value = list->last->value;
 struct listNode *removedNode = list->last;
 list->last = removedNode->prev;
 free(removedNode);
 if (list->last == ((void *)0)) {
  list->first = list->last;
 } else {
  list->last->next = ((void *)0);
 }
 --(list->size);
 return value;
}


decompiled_code:
char __fastcall in_List(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(_QWORD, __int64))
{
_QWORD *v3; // rbx
char result; // al

v3 = (_QWORD *)*a1;
if ( !*a1 )
return 0;
do
{
result = a2 == *v3;
if ( a3 )
result = a3(*v3, a2);
v3 = (_QWORD *)v3[1];
}
while ( v3 && result != 1 );
return result;
}

canonical_decompiled_code:
char __fastcall func4(_QWORD *a1, __int64 a2, __int64 (__fastcall *a3)(_QWORD, __int64))
{
_QWORD *v3; // rbx
char result; // al

v3 = (_QWORD *)*a1;
if ( !*a1 )
return 0;
do
{
result = a2 == *v3;
if ( a3 )
result = a3(*v3, a2);
v3 = (_QWORD *)v3[1];
}
while ( v3 && result != 1 );
return result;
}

original_code:
_Bool in_List(List list, any_t value, anyEqDelegate isEqualFunc) {
 _Bool isFound = 0;
 listNodePtr_t currentNode = list->first;
 while (currentNode != ((void *)0) && !isFound) {
  if (isEqualFunc == ((void *)0) && currentNode->value == value) {
   isFound = 1;
  } else if (isEqualFunc != ((void *)0) && isEqualFunc(currentNode->value, value)) {
   isFound = 1;
  }
  currentNode = currentNode->next;
 }
 return isFound;
}

canonical_original_code:
_Bool in_List(struct _list *list, unsigned long value, _Bool (*isEqualFunc)(unsigned long, unsigned long)) {
 _Bool isFound = 0;
 struct listNode *currentNode = list->first;
 while (currentNode != ((void *)0) && !isFound) {
  if (isEqualFunc == ((void *)0) && currentNode->value == value) {
   isFound = 1;
  } else if (isEqualFunc != ((void *)0) && isEqualFunc(currentNode->value, value)) {
   isFound = 1;
  }
  currentNode = currentNode->next;
 }
 return isFound;
}

variable_types:
isEqualFunc
_Bool (*)(unsigned long, unsigned long)


decompiled_code:
__int64 __fastcall size_List(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
unsigned int size_List(List list) {
 return list->size;
}

canonical_original_code:
unsigned int size_List(struct _list *list) {
 return list->size;
}

return_type: unsigned int


canonical_decompiled_code:
void func0()
{
;
}

original_code:
vector2d_t v_(scalar_t x, scalar_t y) {
 vector2d_t v;
 v.x = x;
 v.y = y;
 return v;
}

canonical_original_code:
struct vector2d_t v_(double x, double y) {
 struct vector2d_t v;
 v.x = x;
 v.y = y;
 return v;
}

variable_types: x double

variable_types: y double

variable_types: struct vector2d_t { double x; double y; }


decompiled_code:
double __fastcall v_len2(double a1, double a2)
{
double v3; // [rsp+0h] [rbp-18h]

v3 = ((double (*)(void))sq)();
return sq(a2) + v3;
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2)
{
double v3; // [rsp+0h] [rbp-18h]

v3 = ((double (*)(void))sq)();
return sq(a2) + v3;
}

original_code:
scalar_t v_len2(vector2d_t v) {
 return sq(v.x) + sq(v.y);
}

canonical_original_code:
double v_len2(struct vector2d_t v) {
 return sq(v.x) + sq(v.y);
}

return_type: double

user_defined_types: struct vector2d_t { double x; double y; }


decompiled_code:
void __fastcall v_len(double a1, double a2)
{
double v2; // xmm0_8

v2 = v_len2(a1, a2);
if ( v2 < 0.0 )
sqrt(v2);
}

canonical_decompiled_code:
void __fastcall func2(double a1, double a2)
{
double v2; // xmm0_8

v2 = func1(a1, a2);
if ( v2 < 0.0 )
sqrt(v2);
}

original_code:
scalar_t v_len(vector2d_t v) {
 return sqrt(v_len2(v));
}

canonical_original_code:
double v_len(struct vector2d_t v) {
 return sqrt(v_len2(v));
}


decompiled_code:
void __fastcall v_angle(double a1, double a2)
{
atan2(a2, a1);
}

canonical_decompiled_code:
void __fastcall func3(double a1, double a2)
{
atan2(a2, a1);
}

original_code:
double v_angle(vector2d_t v) {
 return atan2(v.y, v.x);
}

canonical_original_code:
double v_angle(struct vector2d_t v) {
 return atan2(v.y, v.x);
}


decompiled_code:
bool __fastcall v_eq(double a1, double a2, double a3, double a4)
{
bool result; // al

if ( a1 == a3 )
result = a2 == a4;
else
result = 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func4(double a1, double a2, double a3, double a4)
{
bool result; // al

if ( a1 == a3 )
result = a2 == a4;
else
result = 0;
return result;
}

original_code:
_Bool v_eq(vector2d_t v1, vector2d_t v2) {
 return (v1.x == v2.x && v1.y == v2.y);
}

canonical_original_code:
_Bool v_eq(struct vector2d_t v1, struct vector2d_t v2) {
 return (v1.x == v2.x && v1.y == v2.y);
}


decompiled_code:
void v_rotate()
{
v_();
}

canonical_decompiled_code:
void func5()
{
func0();
}

original_code:
vector2d_t v_rotate(vector2d_t v1, vector2d_t v2) {
 return v_(v1.x * v2.x - v1.y * v2.y, v1.x * v2.y + v1.y * v2.x);
}

canonical_original_code:
struct vector2d_t v_rotate(struct vector2d_t v1, struct vector2d_t v2) {
 return v_(v1.x * v2.x - v1.y * v2.y, v1.x * v2.y + v1.y * v2.x);
}

return_type: struct vector2d_t { double x; double y; }


decompiled_code:
void v_add()
{
v_();
}

canonical_decompiled_code:
void func6()
{
func0();
}

original_code:
vector2d_t v_add(vector2d_t v1, vector2d_t v2) {
 return v_(v1.x + v2.x, v1.y + v2.y);
}

canonical_original_code:
struct vector2d_t v_add(struct vector2d_t v1, struct vector2d_t v2) {
 return v_(v1.x + v2.x, v1.y + v2.y);
}


decompiled_code:
void v_sub()
{
v_();
}

canonical_decompiled_code:
void func7()
{
func0();
}

original_code:
vector2d_t v_sub(vector2d_t v1, vector2d_t v2) {
 return v_(v1.x - v2.x, v1.y - v2.y);
}

canonical_original_code:
struct vector2d_t v_sub(struct vector2d_t v1, struct vector2d_t v2) {
 return v_(v1.x - v2.x, v1.y - v2.y);
}


decompiled_code:
void v_mul()
{
v_();
}

canonical_decompiled_code:
void func8()
{
func0();
}

original_code:
vector2d_t v_mul(vector2d_t v1, scalar_t s) {
 return v_(v1.x * s, v1.y * s);
}

canonical_original_code:
struct vector2d_t v_mul(struct vector2d_t v1, double s) {
 return v_(v1.x * s, v1.y * s);
}

variable_types: s double


decompiled_code:
void v_div()
{
v_();
}

canonical_decompiled_code:
void func9()
{
func0();
}

original_code:
vector2d_t v_div(vector2d_t v1, scalar_t s) {
 return v_(v1.x / s, v1.y / s);
}

canonical_original_code:
struct vector2d_t v_div(struct vector2d_t v1, double s) {
 return v_(v1.x / s, v1.y / s);
}


decompiled_code:
void __fastcall v_lerp(double a1, double a2, double a3, double a4, double a5)
{
lerp(a1, a3, a5);
lerp(a1, a2, a4);
v_();
}

canonical_decompiled_code:
void __fastcall func10(double a1, double a2, double a3, double a4, double a5)
{
lerp(a1, a3, a5);
lerp(a1, a2, a4);
func0();
}

original_code:
vector2d_t v_lerp(scalar_t t, vector2d_t v1, vector2d_t v2) {
 return v_(lerp(t, v1.x, v2.x), lerp(t, v1.y, v2.y));
}

canonical_original_code:
struct vector2d_t v_lerp(double t, struct vector2d_t v1, struct vector2d_t v2) {
 return v_(lerp(t, v1.x, v2.x), lerp(t, v1.y, v2.y));
}

variable_types: t double


decompiled_code:
void __fastcall v_unit(double a1, double a2)
{
v_len(a1, a2);
v_();
}

canonical_decompiled_code:
void __fastcall func11(double a1, double a2)
{
func2(a1, a2);
func0();
}

original_code:
vector2d_t v_unit(vector2d_t v1) {
  int len = v_len(v1);
  return v_(v1.x/len, v1.y/len);
}

canonical_original_code:
struct vector2d_t v_unit(struct vector2d_t v1) {
  int len = v_len(v1);
  return v_(v1.x/len, v1.y/len);
}

variable_types: len int


decompiled_code:
void __fastcall v_scale(double a1, double a2)
{
v_unit(a1, a2);
v_mul();
}

canonical_decompiled_code:
void __fastcall func12(double a1, double a2)
{
func11(a1, a2);
func8();
}

original_code:
vector2d_t v_scale(vector2d_t v1, scalar_t s) {
  return v_mul(v_unit(v1), s);
}

canonical_original_code:
struct vector2d_t v_scale(struct vector2d_t v1, double s) {
  return v_mul(v_unit(v1), s);
}


decompiled_code:
void __fastcall v_forAngle(double a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a1, sinx, (double *)&v1);
v_();
}

canonical_decompiled_code:
void __fastcall func13(double a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a1, sinx, (double *)&v1);
func0();
}

canonical_original_code:
struct vector2d_t v_forAngle(double a) {
 return v_(cos(a), sin(a));
}

variable_types: a double


decompiled_code:
void __fastcall v_rotateAngle(double a1, double a2, double a3)
{
v_forAngle(a3);
v_rotate();
}

canonical_decompiled_code:
void __fastcall func14(double a1, double a2, double a3)
{
func13(a3);
func5();
}

original_code:
vector2d_t v_rotateAngle(vector2d_t v1, double a) {
 return v_rotate(v1, v_forAngle(a));
}

canonical_original_code:
struct vector2d_t v_rotateAngle(struct vector2d_t v1, double a) {
 return v_rotate(v1, v_forAngle(a));
}


decompiled_code:
void __fastcall v_forAngleLength(double a1)
{
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

sincos(a1, sinx, &cosx);
v_();
}

canonical_decompiled_code:
void __fastcall func15(double a1)
{
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

sincos(a1, sinx, &cosx);
func0();
}

original_code:
vector2d_t v_forAngleLength(double a, scalar_t s) {
 return v_(cos(a) * s, sin(a) * s);
}

canonical_original_code:
struct vector2d_t v_forAngleLength(double a, double s) {
 return v_(cos(a) * s, sin(a) * s);
}


decompiled_code:
double __fastcall v_dot(double a1, double a2, double a3, double a4)
{
return a1 * a3 + a2 * a4;
}

canonical_decompiled_code:
double __fastcall func16(double a1, double a2, double a3, double a4)
{
return a1 * a3 + a2 * a4;
}

original_code:
scalar_t v_dot(vector2d_t v1, vector2d_t v2) {
 return (v1.x * v2.x + v1.y * v2.y);
}

canonical_original_code:
double v_dot(struct vector2d_t v1, struct vector2d_t v2) {
 return (v1.x * v2.x + v1.y * v2.y);
}


decompiled_code:
void __fastcall v_dist(double a1, double a2)
{
v_sub();
v_len(a1, a2);
}

canonical_decompiled_code:
void __fastcall func17(double a1, double a2)
{
func7();
func2(a1, a2);
}

original_code:
scalar_t v_dist(vector2d_t v1, vector2d_t v2) {
 return v_len(v_sub(v1, v2));
}

canonical_original_code:
double v_dist(struct vector2d_t v1, struct vector2d_t v2) {
 return v_len(v_sub(v1, v2));
}


decompiled_code:
double __fastcall v_dist2(double a1, double a2)
{
v_sub();
return v_len2(a1, a2);
}

canonical_decompiled_code:
double __fastcall func18(double a1, double a2)
{
func7();
return func1(a1, a2);
}

original_code:
scalar_t v_dist2(vector2d_t v1, vector2d_t v2) {
 return v_len2(v_sub(v1, v2));
}

canonical_original_code:
double v_dist2(struct vector2d_t v1, struct vector2d_t v2) {
 return v_len2(v_sub(v1, v2));
}


original_code:
void remove_HashMap(HashMap map, any_t key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   collisionNode_t *node = map->array[hash];
   collisionNode_t *prev = ((void *)0);
   while (node != ((void *)0) && !isEqual(map, node->key, key)) {
      node = node->next;
   }
   if (node != ((void *)0) && isEqual(map, node->key, key)) {
      if (prev == ((void *)0)) {
         map->array[hash] = node->next;
      } else {
         prev->next = node->next;
      }
      free(node);
   }
}

canonical_original_code:
void remove_HashMap(struct _hashmap *map, unsigned long key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   struct collisionNode *node = map->array[hash];
   struct collisionNode *prev = ((void *)0);
   while (node != ((void *)0) && !isEqual(map, node->key, key)) {
      node = node->next;
   }
   if (node != ((void *)0) && isEqual(map, node->key, key)) {
      if (prev == ((void *)0)) {
         map->array[hash] = node->next;
      } else {
         prev->next = node->next;
      }
      free(node);
   }
}

variable_types: struct _hashmap { struct collisionNode { unsigned long key; unsigned long value; struct collisionNode *next; } **array; int size; unsigned int (*hashFunction)(unsigned long); _Bool (*isEqual)(unsigned long, unsigned long); } *

variable_types:
key
unsigned long

variable_types:
hash
unsigned int

user_defined_types: struct _hashmap { struct collisionNode **array; int size; unsigned int (*hashFunction)(unsigned long); _Bool (*isEqual)(unsigned long, unsigned long); }


original_code:
void set_HashMap(HashMap map, any_t key, any_t value) {
   unsigned int hash = map->hashFunction(key) % map->size;
   collisionNode_t *prevNode;
   collisionNode_t *node = malloc(sizeof(collisionNode_t));
   ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "types/HashMap.c", 71, __extension__ __PRETTY_FUNCTION__); }));
   node->key = key;
   node->value = value;
   node->next = ((void *)0);
   prevNode = map->array[hash];
   if (prevNode == ((void *)0)) {
      map->array[hash] = node;
   } else {
      while (prevNode->next != ((void *)0)) {
         if (isEqual(map, prevNode->key, key)) {
            break;
         }
         prevNode = prevNode->next;
      }
      if (isEqual(map, prevNode->key, key)) {
         prevNode->value = node->value;
         free(node);
      } else {
         prevNode->next = node;
      }
   }
}

canonical_original_code:
void set_HashMap(struct _hashmap *map, unsigned long key, unsigned long value) {
   unsigned int hash = map->hashFunction(key) % map->size;
   struct collisionNode *prevNode;
   struct collisionNode *node = malloc(sizeof(collisionNode_t));
   ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "types/HashMap.c", 71, __extension__ __PRETTY_FUNCTION__); }));
   node->key = key;
   node->value = value;
   node->next = ((void *)0);
   prevNode = map->array[hash];
   if (prevNode == ((void *)0)) {
      map->array[hash] = node;
   } else {
      while (prevNode->next != ((void *)0)) {
         if (isEqual(map, prevNode->key, key)) {
            break;
         }
         prevNode = prevNode->next;
      }
      if (isEqual(map, prevNode->key, key)) {
         prevNode->value = node->value;
         free(node);
      } else {
         prevNode->next = node;
      }
   }
}

variable_types: struct collisionNode { unsigned long key; unsigned long value; struct collisionNode *next; } *


decompiled_code:
__int64 __fastcall get_HashMap(__int64 a1, __int64 a2)
{
__int64 *v2; // rbx
__int64 result; // rax

v2 = *(__int64 **)(*(_QWORD *)a1
+ 8LL * ((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)(a1 + 8)));
if ( !v2 )
goto LABEL_6;
while ( !(unsigned __int8)isEqual_isra_0(*(__int64 (__fastcall **)(__int64, __int64))(a1 + 24), *v2, a2) )
{
v2 = (__int64 *)v2[2];
if ( !v2 )
goto LABEL_6;
}
if ( (unsigned __int8)isEqual_isra_0(*(__int64 (__fastcall **)(__int64, __int64))(a1 + 24), *v2, a2) )
result = v2[1];
else
LABEL_6:
result = 0LL;
return result;
}

original_code:
any_t get_HashMap(HashMap map, any_t key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   collisionNode_t *node = map->array[hash];
   any_t value;
   while (node != ((void *)0) && !isEqual(map, node->key, key)) {
      node = node->next;
   }
   if (node == ((void *)0) || !isEqual(map, node->key, key)) {
      value = (any_t)((void *)0);
   } else {
      value = node->value;
   }
   return value;
}

canonical_original_code:
unsigned long get_HashMap(struct _hashmap *map, unsigned long key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   struct collisionNode *node = map->array[hash];
   unsigned long value;
   while (node != ((void *)0) && !isEqual(map, node->key, key)) {
      node = node->next;
   }
   if (node == ((void *)0) || !isEqual(map, node->key, key)) {
      value = (any_t)((void *)0);
   } else {
      value = node->value;
   }
   return value;
}

user_defined_types: struct collisionNode { unsigned long key; unsigned long value; struct collisionNode *next; }


decompiled_code:
__int64 __fastcall in_HashMap(__int64 a1, __int64 a2)
{
__int64 *v2; // rbx
__int64 result; // rax

v2 = *(__int64 **)(*(_QWORD *)a1
+ 8LL * ((*(unsigned int (__fastcall **)(__int64))(a1 + 16))(a2) % *(_DWORD *)(a1 + 8)));
if ( !v2 )
return 0LL;
while ( 1 )
{
result = isEqual_isra_0(*(__int64 (__fastcall **)(__int64, __int64))(a1 + 24), *v2, a2);
if ( (_BYTE)result )
break;
v2 = (__int64 *)v2[2];
if ( !v2 )
return 0LL;
}
return result;
}

original_code:
_Bool in_HashMap(HashMap map, any_t key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   collisionNode_t *node = map->array[hash];
   while (node != ((void *)0)) {
      if (isEqual(map, node->key, key)) {
         return 1;
      }
      node = node->next;
   }
   return 0;
}

canonical_original_code:
_Bool in_HashMap(struct _hashmap *map, unsigned long key) {
   unsigned int hash = map->hashFunction(key) % map->size;
   struct collisionNode *node = map->array[hash];
   while (node != ((void *)0)) {
      if (isEqual(map, node->key, key)) {
         return 1;
      }
      node = node->next;
   }
   return 0;
}


decompiled_code:
void __fastcall destroy_HashMap(void *ptr)
{
empty_HashMap((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
empty_HashMap((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}

original_code:
void destroy_HashMap(HashMap map) {
   empty_HashMap(map);
   free(map->array);
   free(map);
}

canonical_original_code:
void destroy_HashMap(struct _hashmap *map) {
   empty_HashMap(map);
   free(map->array);
   free(map);
}


randDouble

decompiled_code:
double __fastcall randDouble(double a1)
{
return (double)rand() / 2147483647.0 * a1;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
return (double)rand() / 2147483647.0 * a1;
}

original_code:
double randDouble(double amt) {
   return amt * (rand()/(double)2147483647);
}

variable_types: amt double


vary

decompiled_code:
double __fastcall vary(double a1)
{
return (randDouble(1.0) - 0.5) * (a1 + a1);
}

canonical_decompiled_code:
double __fastcall func1(double a1)
{
return (func0(1.0) - 0.5) * (a1 + a1);
}

original_code:
double vary(double amt) {
   return 2.0 * amt * (randDouble(1.0) - 0.5);
}


randInt

decompiled_code:
__int64 __fastcall randInt(int a1)
{
return (unsigned int)(rand() % a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (unsigned int)(rand() % a1);
}

original_code:
int randInt(int amt) {
   return rand() % amt;
}

variable_types: amt int