lerp

decompiled_code:
double __fastcall lerp(double a1, double a2, double a3)
{
return (1.0 - a1) * a2 + a1 * a3;
}

canonical_decompiled_code:
double __fastcall func3(double a1, double a2, double a3)
{
return (1.0 - a1) * a2 + a1 * a3;
}

original_code:
double lerp(double t, double from, double to) {
   return t * to + (1.0 - t) * from;
}

variable_types: from double

variable_types: to double


sq

repo: dcollien/Alcubierre

decompiled_code:
double __fastcall sq(double a1)
{
return a1 * a1;
}

canonical_decompiled_code:
double __fastcall func4(double a1)
{
return a1 * a1;
}

original_code:
double sq(double x) {
   return x * x;
}

canonical_original_code:
double sq(double x) {
   return x * x;
}

variable_types: x double

return_type: double


cube

decompiled_code:
double __fastcall cube(double a1)
{
return a1 * a1 * a1;
}

canonical_decompiled_code:
double __fastcall func5(double a1)
{
return a1 * a1 * a1;
}

original_code:
double cube(double x) {
   return x * x * x;
}


decompiled_code:
_QWORD *new_PQueue()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rax

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("pq != NULL", "types/PQueue.c", 0x1Au, "new_PQueue");
v1 = v0;
v2 = malloc(0x400uLL);
*v1 = v2;
if ( !v2 )
_assert_fail("pq->elements != NULL", "types/PQueue.c", 0x1Du, "new_PQueue");
v1[1] = 128LL;
return v1;
}

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

v0 = malloc(0x10uLL);
if ( !v0 )
_assert_fail("pq != NULL", "types/PQueue.c", 0x1Au, "new_PQueue");
v1 = v0;
v2 = malloc(0x400uLL);
*v1 = v2;
if ( !v2 )
_assert_fail("pq->elements != NULL", "types/PQueue.c", 0x1Du, "new_PQueue");
v1[1] = 128LL;
return v1;
}

original_code:
PQueue new_PQueue(void) {
   PQueue pq = malloc(sizeof(struct _pq));
   ((void) sizeof ((pq != ((void *)0)) ? 1 : 0), __extension__ ({ if (pq != ((void *)0)) ; else __assert_fail ("pq != NULL", "types/PQueue.c", 26, __extension__ __PRETTY_FUNCTION__); }));
   pq->elements = malloc(sizeof(pq_node_ptr) * 128);
   ((void) sizeof ((pq->elements != ((void *)0)) ? 1 : 0), __extension__ ({ if (pq->elements != ((void *)0)) ; else __assert_fail ("pq->elements != NULL", "types/PQueue.c", 29, __extension__ __PRETTY_FUNCTION__); }));
   pq->size = 128;
   pq->length = 0;
   return pq;
}

canonical_original_code:
struct _pq *new_PQueue() {
   struct _pq *pq = malloc(sizeof(struct _pq));
   ((void) sizeof ((pq != ((void *)0)) ? 1 : 0), __extension__ ({ if (pq != ((void *)0)) ; else __assert_fail ("pq != NULL", "types/PQueue.c", 26, __extension__ __PRETTY_FUNCTION__); }));
   pq->elements = malloc(sizeof(pq_node_ptr) * 128);
   ((void) sizeof ((pq->elements != ((void *)0)) ? 1 : 0), __extension__ ({ if (pq->elements != ((void *)0)) ; else __assert_fail ("pq->elements != NULL", "types/PQueue.c", 29, __extension__ __PRETTY_FUNCTION__); }));
   pq->size = 128;
   pq->length = 0;
   return pq;
}

variable_types: struct _pq { struct pq_node { unsigned long value; int priority; } **elements; int size; int length; } *

user_defined_types: struct _pq { struct pq_node **elements; int size; int length; }


original_code:
any_t remove_PQueue(PQueue pq) {
   ((void) sizeof ((pq->length > 0) ? 1 : 0), __extension__ ({ if (pq->length > 0) ; else __assert_fail ("pq->length > 0", "types/PQueue.c", 46, __extension__ __PRETTY_FUNCTION__); }));
   pq_node_ptr removed = pq->elements[0];
   any_t removedValue = removed->value;
   free(removed);
   pq->elements[0] = pq->elements[pq->length-1];
   --(pq->length);
   heapify(pq, 0);
   return removedValue;
}

canonical_original_code:
unsigned long remove_PQueue(struct _pq *pq) {
   ((void) sizeof ((pq->length > 0) ? 1 : 0), __extension__ ({ if (pq->length > 0) ; else __assert_fail ("pq->length > 0", "types/PQueue.c", 46, __extension__ __PRETTY_FUNCTION__); }));
   struct pq_node *removed = pq->elements[0];
   unsigned long removedValue = removed->value;
   free(removed);
   pq->elements[0] = pq->elements[pq->length-1];
   --(pq->length);
   heapify(pq, 0);
   return removedValue;
}

variable_types: struct pq_node { unsigned long value; int priority; } *

variable_types:
removedValue
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall destroy_PQueue(void *ptr)
{
while ( *((int *)ptr + 3) > 0 )
remove_PQueue((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
while ( *((int *)ptr + 3) > 0 )
func2((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}

original_code:
void destroy_PQueue(PQueue pq) {
   while (pq->length > 0) {
      remove_PQueue(pq);
   }
   free(pq->elements);
   free(pq);
}

canonical_original_code:
void destroy_PQueue(struct _pq *pq) {
   while (pq->length > 0) {
      remove_PQueue(pq);
   }
   free(pq->elements);
   free(pq);
}

return_type: void

user_defined_types: struct pq_node { unsigned long value; int priority; }


decompiled_code:
__int64 __fastcall size_PQueue(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

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

original_code:
unsigned int size_PQueue(PQueue pq) {
   return pq->length;
}

canonical_original_code:
unsigned int size_PQueue(struct _pq *pq) {
   return pq->length;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall printPriorities_PQueue(__int64 a1, void (__fastcall *a2)(_QWORD))
{
int v2; // er13
__int64 result; // rax
int v4; // er12
__int64 v5; // r14
int v6; // ebx
int v7; // [rsp+8h] [rbp-40h]
int v8; // [rsp+Ch] [rbp-3Ch]

v2 = 0;
result = *(unsigned int *)(a1 + 12);
v8 = 1;
v4 = (int)result / 2;
if ( (int)result > 0 )
{
do
{
v5 = 8LL * v2;
v7 = v2 + v8;
if ( v2 < (int)result )
{
do
{
v6 = 0;
if ( v4 )
{
do
{
printf(" ");
if ( a2 )
a2(0LL);
++v6;
}
while ( v6 != v4 );
}
printf("%3d", *(unsigned int *)(*(_QWORD *)(*(_QWORD *)a1 + v5) + 8LL));
if ( a2 )
a2(**(_QWORD **)(*(_QWORD *)a1 + v5));
++v2;
v5 += 8LL;
}
while ( v7 != v2 && v2 < *(_DWORD *)(a1 + 12) );
}
v8 *= 2;
putchar(10);
result = *(unsigned int *)(a1 + 12);
v4 /= 2;
}
while ( v2 < (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, void (__fastcall *a2)(_QWORD))
{
int v2; // er13
__int64 result; // rax
int v4; // er12
__int64 v5; // r14
int v6; // ebx
int v7; // [rsp+8h] [rbp-40h]
int v8; // [rsp+Ch] [rbp-3Ch]

v2 = 0;
result = *(unsigned int *)(a1 + 12);
v8 = 1;
v4 = (int)result / 2;
if ( (int)result > 0 )
{
do
{
v5 = 8LL * v2;
v7 = v2 + v8;
if ( v2 < (int)result )
{
do
{
v6 = 0;
if ( v4 )
{
do
{
printf(" ");
if ( a2 )
a2(0LL);
++v6;
}
while ( v6 != v4 );
}
printf("%3d", *(unsigned int *)(*(_QWORD *)(*(_QWORD *)a1 + v5) + 8LL));
if ( a2 )
a2(**(_QWORD **)(*(_QWORD *)a1 + v5));
++v2;
v5 += 8LL;
}
while ( v7 != v2 && v2 < *(_DWORD *)(a1 + 12) );
}
v8 *= 2;
putchar(10);
result = *(unsigned int *)(a1 + 12);
v4 /= 2;
}
while ( v2 < (int)result );
}
return result;
}

original_code:
void printPriorities_PQueue(PQueue pq, anyPrintDelegate printer) {
   int i;
   int space;
   int spacing;
   int col;
   int rowLength;
   spacing = pq->length/2;
   rowLength = 1;
   i = 0;
   while (i < pq->length) {
      for (col = 0; col < rowLength && i < pq->length; ++col) {
         for (space = 0; space != spacing; ++space) {
            printf("   ");
            if (printer != ((void *)0)) {
               printer((any_t)((void *)0));
            }
         }
         printf("%3d", pq->elements[i]->priority);
         if (printer != ((void *)0)) {
            printer(pq->elements[i]->value);
         }
         i++;
      }
      spacing /= 2;
      rowLength *= 2;
      printf("\n");
   }
}

canonical_original_code:
void printPriorities_PQueue(struct _pq *pq, void (*printer)(unsigned long)) {
   int i;
   int space;
   int spacing;
   int col;
   int rowLength;
   spacing = pq->length/2;
   rowLength = 1;
   i = 0;
   while (i < pq->length) {
      for (col = 0; col < rowLength && i < pq->length; ++col) {
         for (space = 0; space != spacing; ++space) {
            printf("   ");
            if (printer != ((void *)0)) {
               printer((any_t)((void *)0));
            }
         }
         printf("%3d", pq->elements[i]->priority);
         if (printer != ((void *)0)) {
            printer(pq->elements[i]->value);
         }
         i++;
      }
      spacing /= 2;
      rowLength *= 2;
      printf("\n");
   }
}

variable_types:
printer
void (*)(unsigned long)

variable_types: i int

variable_types: space int

variable_types: spacing int

variable_types: col int

variable_types: rowLength int


keymapHash

decompiled_code:
__int64 __fastcall keymapHash(__int64 a1)
{
return a1;
}

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

original_code:
static unsigned int keymapHash(any_t value) {
   return (unsigned int)value;
}

canonical_original_code:
static unsigned int keymapHash(unsigned long value) {
   return (unsigned int)value;
}

variable_types:
value
unsigned long


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

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

original_code:
int send_net(net_address_t address, protocol_t protocol) {
    return 0;
}

canonical_original_code:
int send_net(int address, struct protocol protocol) {
    return 0;
}

variable_types: address int

variable_types:
protocol
struct protocol {  }

return_type: int


version

repo: ddribin/kents-nes-stuff

decompiled_code:
void __noreturn version()
{
puts(program_version);
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
puts(program_version);
exit(0);
}

original_code:
static void version()
{
    printf("%s\n", program_version);
    exit(0);
}


original_code:
void pack_chr(const char *chr_in, int sz_in, int null_tile, int nametable_base,
              char **chr_out, long *sz_out, unsigned char *nametable)
{
    static const char null_tile_data[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    long buf_sz = 0;
    long pos_in = 0;
    long pos_out = 0;
    long nametable_pos = 0;
    int warn_wraparound = 1;
    *chr_out = 0;
    while (pos_in < sz_in) {
 long i;
 const char *tile_in = &chr_in[pos_in];
 const int is_null_tile = !memcmp(tile_in, null_tile_data, 16);
 if (!is_null_tile || (null_tile == -1)) {
     for (i = 0; i < pos_out; i += 16) {
  if (!memcmp(tile_in, &(*chr_out)[i], 16))
      break;
     }
     if (i == pos_out) {
  if (pos_out == buf_sz) {
      buf_sz += 1024;
      *chr_out = realloc(*chr_out, buf_sz);
      ((void) sizeof ((*chr_out) ? 1 : 0), __extension__ ({ if (*chr_out) ; else __assert_fail ("*chr_out", "packchr.c", 92, __extension__ __PRETTY_FUNCTION__); }));
  }
  memcpy(&(*chr_out)[pos_out], tile_in, 16);
  pos_out += 16;
     }
     int tile_index = (i / 16) + nametable_base;
     if ((tile_index >= 256) && warn_wraparound) {
  fprintf(stderr, "packchr: warning: tile index >= 256 (wrap-around); "
   "you should reduce the size and/or detail of the input and retry\n");
  warn_wraparound = 0;
     }
     nametable[nametable_pos] = (unsigned char)tile_index;
 } else {
     nametable[nametable_pos] = (unsigned char)null_tile;
 }
 ++nametable_pos;
 pos_in += 16;
    }
    *sz_out = pos_out;
    ((void) sizeof (((sz_in/16) == nametable_pos) ? 1 : 0), __extension__ ({ if ((sz_in/16) == nametable_pos) ; else __assert_fail ("(sz_in/16) == nametable_pos", "packchr.c", 111, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void pack_chr(char *chr_in, int sz_in, int null_tile, int nametable_base, char **chr_out, long *sz_out, unsigned char *nametable)
{
    static char null_tile_data[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    long buf_sz = 0;
    long pos_in = 0;
    long pos_out = 0;
    long nametable_pos = 0;
    int warn_wraparound = 1;
    *chr_out = 0;
    while (pos_in < sz_in) {
 long i;
 char *tile_in = &chr_in[pos_in];
 int is_null_tile = !memcmp(tile_in, null_tile_data, 16);
 if (!is_null_tile || (null_tile == -1)) {
     for (i = 0; i < pos_out; i += 16) {
  if (!memcmp(tile_in, &(*chr_out)[i], 16))
      break;
     }
     if (i == pos_out) {
  if (pos_out == buf_sz) {
      buf_sz += 1024;
      *chr_out = realloc(*chr_out, buf_sz);
      ((void) sizeof ((*chr_out) ? 1 : 0), __extension__ ({ if (*chr_out) ; else __assert_fail ("*chr_out", "packchr.c", 92, __extension__ __PRETTY_FUNCTION__); }));
  }
  memcpy(&(*chr_out)[pos_out], tile_in, 16);
  pos_out += 16;
     }
     int tile_index = (i / 16) + nametable_base;
     if ((tile_index >= 256) && warn_wraparound) {
  fprintf(stderr, "packchr: warning: tile index >= 256 (wrap-around); "
   "you should reduce the size and/or detail of the input and retry\n");
  warn_wraparound = 0;
     }
     nametable[nametable_pos] = (unsigned char)tile_index;
 } else {
     nametable[nametable_pos] = (unsigned char)null_tile;
 }
 ++nametable_pos;
 pos_in += 16;
    }
    *sz_out = pos_out;
    ((void) sizeof (((sz_in/16) == nametable_pos) ? 1 : 0), __extension__ ({ if ((sz_in/16) == nametable_pos) ; else __assert_fail ("(sz_in/16) == nametable_pos", "packchr.c", 111, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types:
nametable
unsigned char *

variable_types: i long


decompiled_code:
__int64 __fastcall eat_ws(__int64 a1, int *a2)
{
__int64 result; // rax
char v3; // dl
char v4; // dl

result = *a2;
v3 = *(_BYTE *)(a1 + result);
if ( v3 == 9 || v3 == 32 )
{
result = (int)result + 1;
do
{
do
{
*a2 = result;
v4 = *(_BYTE *)(a1 + result++);
}
while ( v4 == 9 );
}
while ( v4 == 32 );
}
return result;
}

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

result = *a2;
v3 = *(_BYTE *)(a1 + result);
if ( v3 == 9 || v3 == 32 )
{
result = (int)result + 1;
do
{
do
{
*a2 = result;
v4 = *(_BYTE *)(a1 + result++);
}
while ( v4 == 9 );
}
while ( v4 == 32 );
}
return result;
}

variable_types:
s
char *

variable_types:
i
int *


original_code:
static int get_key(char *s, int *i, char *d)
{
    char key;
    key = s[(*i)++];
    if ((key == '\0') || (key == '\n')) { return 0; }
    if (key == '\\') {
        key = s[(*i)++];
        if ((key == '\0') || (key == '\n')) { return 0; }
        switch (key) {
            case '0': key = '\0'; break;
            case 'a': key = '\a'; break;
            case 'b': key = '\b'; break;
            case 't': key = '\t'; break;
            case 'f': key = '\f'; break;
            case 'n': key = '\n'; break;
            case 'r': key = '\r'; break;
        }
    }
    *d = key;
    return 1;
}

variable_types:
d
char *

variable_types: key char


maperr

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

va_start(arg, a3);
fprintf(stderr, "error: %s:%d: ", a1, a2);
vfprintf(stderr, a3, arg);
return fputc(10, stderr);
}

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

va_start(arg, a3);
fprintf(stderr, "error: %s:%d: ", a1, a2);
vfprintf(stderr, a3, arg);
return fputc(10, stderr);
}

original_code:
static void maperr(const char *filename, int line, char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    fprintf(stderr, "error: %s:%d: ", filename, line);
    vfprintf(stderr, fmt, ap);
    fprintf(stderr, "\n");
    __builtin_va_end(ap);
}

canonical_original_code:
static void maperr(char *filename, int line, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    fprintf(stderr, "error: %s:%d: ", filename, line);
    vfprintf(stderr, fmt, ap);
    fprintf(stderr, "\n");
    __builtin_va_end(ap);
}

variable_types:
filename
char *

variable_types: line int

variable_types:
fmt
char *


original_code:
void xm_destroy(struct xm *xm)
{
    int i;
    for (i = 0; i < xm->header.pattern_count; ++i)
        free(xm->patterns[i].data);
    free(xm->patterns);
}

variable_types: struct xm { struct xm_header { char id_text[17]; char module_name[20]; char pad1a; char tracker_name[20]; unsigned short version; unsigned int header_size; unsigned short song_length; unsigned short restart_position; unsigned short channel_count; unsigned short pattern_count; unsigned short instrument_count; unsigned short flags; unsigned short default_tempo; unsigned short default_bpm; unsigned char pattern_order_table[256]; } header; struct xm_pattern { int row_count; struct xm_pattern_slot { unsigned char note; unsigned char instrument; unsigned char volume; unsigned char effect_type; unsigned char effect_param; } *data; } *patterns; } *

variable_types: i int

user_defined_types: struct xm { struct xm_header header; struct xm_pattern *patterns; }

user_defined_types: struct xm_pattern { int row_count; struct xm_pattern_slot *data; }


decompiled_code:
float __fastcall note_hz(int a1)
{
return pow(2.0, (double)(a1 - 57) / 12.0) * 440.0;
}

canonical_decompiled_code:
float __fastcall func0(int a1)
{
return pow(2.0, (double)(a1 - 57) / 12.0) * 440.0;
}

original_code:
static float note_hz(int note)
{
    return pow(2, (note - 57) / 12.0) * 440;
}

variable_types: note int

return_type: float


version

canonical_decompiled_code:
void __noreturn func3()
{
puts(program_version);
exit(0);
}

canonical_original_code:
static void version()
{
    printf("%s\n", program_version);
    exit(0);
}


decompiled_code:
__int64 __fastcall get_ident(__int64 a1, int a2)
{
const unsigned __int16 *v2; // rcx
__int64 v3; // rax
__int64 v4; // rdx
unsigned int v5; // er8

v2 = *_ctype_b_loc();
v3 = 0LL;
do
{
v4 = *(char *)(a1 + a2 + v3);
v5 = v3++;
}
while ( (v2[v4] & 0x400) != 0 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
const unsigned __int16 *v2; // rcx
__int64 v3; // rax
__int64 v4; // rdx
unsigned int v5; // er8

v2 = *_ctype_b_loc();
v3 = 0LL;
do
{
v4 = *(char *)(a1 + a2 + v3);
v5 = v3++;
}
while ( (v2[v4] & 0x400) != 0 );
return v5;
}

original_code:
static int get_ident(char *s, int i)
{
    int len = 0;
    while (((*__ctype_b_loc ())[(int) ((s[i+len]))] & (unsigned short int) _ISalpha))
        ++len;
    return len;
}

canonical_original_code:
static int get_ident(char *s, int i)
{
    int len = 0;
    while (((*__ctype_b_loc ())[(int) ((s[i+len]))] & (unsigned short) _ISalpha))
        ++len;
    return len;
}

variable_types: len int


canonical_decompiled_code:
void __noreturn func9()
{
puts(program_version);
exit(0);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
kmpGetNext(argc, argv, envp);
kmpSearch();
kmpSearch2();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func6(argc, argv, envp);
func7();
func8();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 kmpGetNext();
 kmpSearch();
 kmpSearch2();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


kmpGetNext

original_code:
void kmpGetNext(void)
{
 int i = 0, j = -1;
 b[i] = j;
 while (i < m)
 {
  while (j >= 0 && p[i] != p[j])
   j = b[j];
  i++;
  j++;
  b[i] = j;
 }
 return;
}

canonical_original_code:
void kmpGetNext()
{
 int i = 0; int j = -1;
 b[i] = j;
 while (i < m)
 {
  while (j >= 0 && p[i] != p[j])
   j = b[j];
  i++;
  j++;
  b[i] = j;
 }
 return;
}

variable_types: j int


kmpSearch

original_code:
void kmpSearch(void)
{
 int i = 0, j = 0;
 while (i < n)
 {
  while (j >= 0 && t[i] !=p [j])
   j =b [j];
  i++;
  j++;
  if (j == m)
  {
   j = b[j];
  }
 }
 return;
}

canonical_original_code:
void kmpSearch()
{
 int i = 0; int j = 0;
 while (i < n)
 {
  while (j >= 0 && t[i] !=p [j])
   j =b [j];
  i++;
  j++;
  if (j == m)
  {
   j = b[j];
  }
 }
 return;
}


original_code:
void kmpSearch2(void)
{
 int i = 0, j = 0;
 while (i < n)
 {
  while (j >= 0 && t2[i] !=p [j])
   j = b[j];
  i++;
  j++;
  if (j == m)
  {
   j = b[j];
  }
 }
 return;
}

canonical_original_code:
void kmpSearch2()
{
 int i = 0; int j = 0;
 while (i < n)
 {
  while (j >= 0 && t2[i] !=p [j])
   j = b[j];
  i++;
  j++;
  if (j == m)
  {
   j = b[j];
  }
 }
 return;
}


repo: deardaniel/PizzaTest

decompiled_code:
__int64 __fastcall val_relation(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_relation )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "relation");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_relation )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "relation");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

original_code: cst_relation *val_relation(const cst_val *v) { if (v && ((v)->c.a.type) == cst_val_type_relation) return (cst_relation *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "relation", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

canonical_original_code: struct cst_relation_struct *val_relation(struct cst_val_struct *v) { if (v && ((v)->c.a.type) == cst_val_type_relation) return (struct cst_relation_struct *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "relation", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

variable_types:
v
struct cst_val_struct *

return_type: struct cst_relation_struct { char *name; struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *head; struct cst_item_struct *tail; } *

user_defined_types: struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; }

user_defined_types: struct cst_features_struct { struct cst_featvalpair_struct *head; void *ctx; }

user_defined_types: struct cst_item_struct { struct cst_item_contents_struct *contents; struct cst_relation_struct *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; }

user_defined_types: struct cst_featvalpair_struct { char *name; struct cst_val_struct *val; struct cst_featvalpair_struct *next; }

user_defined_types: struct cst_val_struct { union { struct cst_val_cons_struct cc; struct cst_val_atom_struct a; } c; }


decompiled_code:
__int64 __fastcall relation_val(__int64 a1)
{
return val_new_typed(cst_val_type_relation, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return val_new_typed(cst_val_type_relation, a1);
}

original_code: cst_val *relation_val(const cst_relation *v) { return val_new_typed(cst_val_type_relation, (void *)v); }

canonical_original_code: struct cst_val_struct *relation_val(struct cst_relation_struct *v) { return val_new_typed(cst_val_type_relation, (void *)v); }

variable_types: struct cst_relation_struct { char *name; struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *head; struct cst_item_struct *tail; } *

return_type: struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *


decompiled_code:
__int64 __fastcall val_item(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_item )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "item");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_item )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "item");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

original_code: cst_item *val_item(const cst_val *v) { if (v && ((v)->c.a.type) == cst_val_type_item) return (cst_item *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "item", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

canonical_original_code: struct cst_item_struct *val_item(struct cst_val_struct *v) { if (v && ((v)->c.a.type) == cst_val_type_item) return (struct cst_item_struct *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "item", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

return_type: struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; } *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *

user_defined_types: struct cst_item_contents_struct { struct cst_features_struct *features; struct cst_features_struct *relations; }


decompiled_code:
__int64 __fastcall item_val(__int64 a1)
{
return val_new_typed(cst_val_type_item, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return val_new_typed(cst_val_type_item, a1);
}

original_code: cst_val *item_val(const cst_item *v) { return val_new_typed(cst_val_type_item, (void *)v); }

canonical_original_code: struct cst_val_struct *item_val(struct cst_item_struct *v) { return val_new_typed(cst_val_type_item, (void *)v); }

variable_types: struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; } *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *

user_defined_types: struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; }

user_defined_types: struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; }


decompiled_code:
__int64 __fastcall val_utterance(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_utterance )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "utterance");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_utterance )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "utterance");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

original_code: cst_utterance *val_utterance(const cst_val *v) { if (v && ((v)->c.a.type) == cst_val_type_utterance) return (cst_utterance *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "utterance", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

canonical_original_code: struct cst_utterance_struct *val_utterance(struct cst_val_struct *v) { if (v && ((v)->c.a.type) == cst_val_type_utterance) return (struct cst_utterance_struct *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "utterance", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

return_type: struct cst_utterance_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *

user_defined_types: struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; }


decompiled_code:
// attributes: thunk
__int64 val_delete_utterance()
{
return delete_utterance();
}

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

original_code: void val_delete_utterance(void *v) { delete_utterance((cst_utterance *)v); }

canonical_original_code: void val_delete_utterance(void *v) { delete_utterance((struct cst_utterance_struct *)v); }

variable_types:
v
void *


decompiled_code:
__int64 __fastcall utterance_val(__int64 a1)
{
return val_new_typed(cst_val_type_utterance, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return val_new_typed(cst_val_type_utterance, a1);
}

original_code: cst_val *utterance_val(const cst_utterance *v) { return val_new_typed(cst_val_type_utterance, (void *)v); }

canonical_original_code: struct cst_val_struct *utterance_val(struct cst_utterance_struct *v) { return val_new_typed(cst_val_type_utterance, (void *)v); }

variable_types: struct cst_utterance_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *


decompiled_code:
__int64 __fastcall val_itemfunc(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_itemfunc )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "itemfunc");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_itemfunc )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "itemfunc");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

original_code: cst_itemfunc val_itemfunc(const cst_val *v) { if (v && ((v)->c.a.type) == cst_val_type_itemfunc) return (cst_itemfunc)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "itemfunc", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

canonical_original_code: struct cst_val_struct *(*val_itemfunc(struct cst_val_struct *v))(struct cst_item_struct *i) { if (v && ((v)->c.a.type) == cst_val_type_itemfunc) return (cst_itemfunc)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "itemfunc", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

return_type: struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *(*)(struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; } *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *i)


decompiled_code:
__int64 __fastcall itemfunc_val(__int64 a1)
{
return val_new_typed(cst_val_type_itemfunc, a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return val_new_typed(cst_val_type_itemfunc, a1);
}

original_code: cst_val *itemfunc_val(const cst_itemfunc v) { return val_new_typed(cst_val_type_itemfunc, (void *)v); }

canonical_original_code: struct cst_val_struct *itemfunc_val(struct cst_val_struct *(*v)(struct cst_item_struct *i)) { return val_new_typed(cst_val_type_itemfunc, (void *)v); }

variable_types: struct cst_val_struct *(*)(struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; } *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *i)


decompiled_code:
void __fastcall item_unref_contents(_QWORD **a1)
{
if ( a1 && *a1 )
{
feat_remove((*a1)[1], *a1[1]);
if ( !(unsigned int)feat_length((*a1)[1]) )
{
delete_features((*a1)[1]);
delete_features(**a1);
cst_free(*a1);
}
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func9(_QWORD **a1)
{
if ( a1 && *a1 )
{
feat_remove((*a1)[1], *a1[1]);
if ( !(unsigned int)feat_length((*a1)[1]) )
{
delete_features((*a1)[1]);
delete_features(**a1);
cst_free(*a1);
}
*a1 = 0LL;
}
}

original_code:
void item_unref_contents(cst_item *item)
{
    if (item && item->contents)
    {
 feat_remove(item->contents->relations,item->relation->name);
 if (feat_length(item->contents->relations) == 0)
 {
     delete_features(item->contents->relations);
     delete_features(item->contents->features);
     cst_free((item->contents));
 }
 item->contents = ((void *)0);
    }
}

canonical_original_code:
void item_unref_contents(struct cst_item_struct *item)
{
    if (item && item->contents)
    {
 feat_remove(item->contents->relations,item->relation->name);
 if (feat_length(item->contents->relations) == 0)
 {
     delete_features(item->contents->relations);
     delete_features(item->contents->features);
     cst_free((item->contents));
 }
 item->contents = ((void *)0);
    }
}

variable_types: struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; } *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *


original_code:
void delete_item(cst_item *item)
{
    cst_item *ds, *nds;
    if (item->n != ((void *)0))
    {
 item->n->p = item->p;
 item->n->u = item->u;
    }
    if (item->p != ((void *)0)) item->p->n = item->n;
    if (item->u != ((void *)0)) item->u->d = item->n;
    if (item->relation)
    {
 if (item->relation->head == item)
     item->relation->head = item->n;
 if (item->relation->tail == item)
     item->relation->tail = item->p;
    }
    for (ds = item->d; ds; ds=nds)
    {
 nds = ds->n;
 delete_item(ds);
    }
    item_unref_contents(item);
    cst_free((item));
}

canonical_original_code:
void delete_item(struct cst_item_struct *item)
{
    struct cst_item_struct *ds; struct cst_item_struct *nds;
    if (item->n != ((void *)0))
    {
 item->n->p = item->p;
 item->n->u = item->u;
    }
    if (item->p != ((void *)0)) item->p->n = item->n;
    if (item->u != ((void *)0)) item->u->d = item->n;
    if (item->relation)
    {
 if (item->relation->head == item)
     item->relation->head = item->n;
 if (item->relation->tail == item)
     item->relation->tail = item->p;
    }
    for (ds = item->d; ds; ds=nds)
    {
 nds = ds->n;
 delete_item(ds);
    }
    item_unref_contents(item);
    cst_free((item));
}


decompiled_code:
void __fastcall item_contents_set(__int64 a1, _QWORD *a2)
{
_QWORD *v3; // rbp
_QWORD *v4; // rax
__int64 v5; // rdi
__int64 v6; // rax
__int16 *v7; // rax
__int64 v8; // rbp
__int64 v9; // rax

if ( a2 )
v3 = (_QWORD *)*a2;
else
v3 = new_item_contents(a1);
if ( *(_QWORD **)a1 != v3 )
{
item_unref_contents((_QWORD **)a1);
v4 = *(_QWORD **)(a1 + 8);
v5 = v3[1];
*(_QWORD *)a1 = v3;
if ( (unsigned int)feat_present(v5, *v4) )
{
v7 = (__int16 *)feat_val(*(_QWORD *)(*(_QWORD *)a1 + 8LL), **(_QWORD **)(a1 + 8));
v8 = val_item(v7);
v9 = item_val(v8);
feat_set(*(_QWORD *)(*(_QWORD *)v8 + 8LL), **(_QWORD **)(a1 + 8), v9);
}
v6 = item_val(a1);
feat_set(*(_QWORD *)(*(_QWORD *)a1 + 8LL), **(_QWORD **)(a1 + 8), v6);
}
}

original_code:
void item_contents_set(cst_item *current, cst_item *i)
{
    cst_item_contents *c = 0;
    cst_item *nn_item;
    if (i == 0)
 c = new_item_contents(current);
    else
 c = i->contents;
    if (c != current->contents)
    {
 item_unref_contents(current);
 current->contents = c;
 if (feat_present(current->contents->relations,current->relation->name))
 {
     nn_item = val_item(feat_val(current->contents->relations,
     current->relation->name));
     feat_set(nn_item->contents->relations,
       current->relation->name,
       item_val(nn_item));
 }
 feat_set(current->contents->relations,
   current->relation->name,
   item_val(current));
    }
}

canonical_original_code:
void item_contents_set(struct cst_item_struct *current, struct cst_item_struct *i)
{
    struct cst_item_contents_struct *c = 0;
    struct cst_item_struct *nn_item;
    if (i == 0)
 c = new_item_contents(current);
    else
 c = i->contents;
    if (c != current->contents)
    {
 item_unref_contents(current);
 current->contents = c;
 if (feat_present(current->contents->relations,current->relation->name))
 {
     nn_item = val_item(feat_val(current->contents->relations,
     current->relation->name));
     feat_set(nn_item->contents->relations,
       current->relation->name,
       item_val(nn_item));
 }
 feat_set(current->contents->relations,
   current->relation->name,
   item_val(current));
    }
}

variable_types:
i
struct cst_item_struct *

variable_types: struct cst_item_contents_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *relations; } *


decompiled_code:
__int64 __fastcall item_as(__int64 a1, __int64 a2)
{
__int16 *v2; // rax

if ( !a1 )
return 0LL;
if ( !(unsigned int)feat_present(*(_QWORD *)(*(_QWORD *)a1 + 8LL), a2) )
return 0LL;
v2 = (__int16 *)feat_val(*(_QWORD *)(*(_QWORD *)a1 + 8LL), a2);
return val_item(v2);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int16 *v2; // rax

if ( !a1 )
return 0LL;
if ( !(unsigned int)feat_present(*(_QWORD *)(*(_QWORD *)a1 + 8LL), a2) )
return 0LL;
v2 = (__int16 *)feat_val(*(_QWORD *)(*(_QWORD *)a1 + 8LL), a2);
return func2(v2);
}

original_code:
cst_item *item_as(const cst_item *i,const char *rname)
{
    if (i == ((void *)0))
 return ((void *)0);
    else if (feat_present(i->contents->relations,rname))
 return val_item(feat_val(i->contents->relations,rname));
    else
 return ((void *)0);
}

canonical_original_code:
struct cst_item_struct *item_as(struct cst_item_struct *i, char *rname)
{
    if (i == ((void *)0))
 return ((void *)0);
    else if (feat_present(i->contents->relations,rname))
 return val_item(feat_val(i->contents->relations,rname));
    else
 return ((void *)0);
}

variable_types:
rname
char *


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

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

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

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

original_code:
cst_item *item_next(const cst_item *i)
{
    if (i == ((void *)0))
 return ((void *)0);
    else
 return i->n;
}

canonical_original_code:
struct cst_item_struct *item_next(struct cst_item_struct *i)
{
    if (i == ((void *)0))
 return ((void *)0);
    else
 return i->n;
}


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

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

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

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

original_code:
cst_item *item_prev(const cst_item *i)
{
    if (i == ((void *)0))
 return ((void *)0);
    else
 return i->p;
}

canonical_original_code:
struct cst_item_struct *item_prev(struct cst_item_struct *i)
{
    if (i == ((void *)0))
 return ((void *)0);
    else
 return i->p;
}


decompiled_code:
__int64 __fastcall item_parent(__int64 a1)
{
__int64 v2; // r8

do
a1 = item_prev(a1);
while ( a1 );
if ( v2 )
v2 = *(_QWORD *)(v2 + 32);
return v2;
}

original_code:
cst_item *item_parent(const cst_item *i)
{
    const cst_item *n;
    for (n=i; item_prev(n); n=item_prev(n));
    if (n == ((void *)0))
 return ((void *)0);
    else
 return n->u;
}

canonical_original_code:
struct cst_item_struct *item_parent(struct cst_item_struct *i)
{
    struct cst_item_struct *n;
    for (n=i; item_prev(n); n=item_prev(n));
    if (n == ((void *)0))
 return ((void *)0);
    else
 return n->u;
}


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

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

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

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

original_code:
cst_item *item_daughter(const cst_item *i)
{
    if (i == ((void *)0))
 return ((void *)0);
    else
 return i->d;
}

canonical_original_code:
struct cst_item_struct *item_daughter(struct cst_item_struct *i)
{
    if (i == ((void *)0))
 return ((void *)0);
    else
 return i->d;
}


decompiled_code:
__int64 __fastcall item_nth_daughter(__int64 a1, int a2)
{
__int64 v2; // rdi
__int64 v3; // rax
int v4; // edx
int v5; // edx

v2 = item_daughter(a1);
if ( v2 && a2 > 0 )
{
do
{
v3 = item_next(v2);
v5 = v4 + 1;
v2 = v3;
}
while ( v3 && a2 > v5 );
}
return v2;
}

original_code:
cst_item *item_nth_daughter(const cst_item *i,int n)
{
    int d;
    cst_item *p;
    for (d=0,p=item_daughter(i); p && (d < n); p=item_next(p),d++);
    return p;
}

canonical_original_code:
struct cst_item_struct *item_nth_daughter(struct cst_item_struct *i, int n)
{
    int d;
    struct cst_item_struct *p;
    for (d=0,p=item_daughter(i); p && (d < n); p=item_next(p),d++);
    return p;
}

variable_types: n int

variable_types: d int


decompiled_code:
__int64 __fastcall item_last_daughter(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r8

v1 = item_daughter(a1);
do
v1 = item_next(v1);
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r8

v1 = func16(a1);
do
v1 = func13(v1);
while ( v1 );
return v2;
}

original_code:
cst_item *item_last_daughter(const cst_item *i)
{
    cst_item *p;
    for (p=item_daughter(i); item_next(p); p=item_next(p));
    return p;
}

canonical_original_code:
struct cst_item_struct *item_last_daughter(struct cst_item_struct *i)
{
    struct cst_item_struct *p;
    for (p=item_daughter(i); item_next(p); p=item_next(p));
    return p;
}


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

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

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

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

original_code:
cst_features *item_feats(const cst_item *i)
{
    return (i ? i->contents->features : ((void *)0));
}

canonical_original_code:
struct cst_features_struct *item_feats(struct cst_item_struct *i)
{
    return (i ? i->contents->features : ((void *)0));
}

variable_types: struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; } *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *

return_type: struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *


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

v2 = item_feats(a1);
return feat_present(v2, a2);
}

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

v2 = func19(a1);
return feat_present(v2, a2);
}

original_code:
int item_feat_present(const cst_item *i,const char *name)
{
    return feat_present(item_feats(i),name);
}

canonical_original_code:
int item_feat_present(struct cst_item_struct *i, char *name)
{
    return feat_present(item_feats(i),name);
}

variable_types:
name
char *


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

v2 = item_feats(a1);
return feat_remove(v2, a2);
}

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

v2 = func19(a1);
return feat_remove(v2, a2);
}

original_code:
int item_feat_remove(const cst_item *i,const char *name)
{
    return feat_remove(item_feats(i),name);
}

canonical_original_code:
int item_feat_remove(struct cst_item_struct *i, char *name)
{
    return feat_remove(item_feats(i),name);
}


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

v2 = item_feats(a1);
return feat_val(v2, a2);
}

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

v2 = func19(a1);
return feat_val(v2, a2);
}

original_code:
const cst_val *item_feat(const cst_item *i,const char *name)
{
    return feat_val(item_feats(i),name);
}

canonical_original_code:
struct cst_val_struct *item_feat(struct cst_item_struct *i, char *name)
{
    return feat_val(item_feats(i),name);
}


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

v1 = item_feats(a1);
return feat_int(v1);
}

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

v1 = func19(a1);
return feat_int(v1);
}

original_code:
int item_feat_int(const cst_item *i,const char *name)
{
    return feat_int(item_feats(i),name);
}

canonical_original_code:
int item_feat_int(struct cst_item_struct *i, char *name)
{
    return feat_int(item_feats(i),name);
}


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

v1 = item_feats(a1);
return feat_float(v1);
}

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

v1 = func19(a1);
return feat_float(v1);
}

original_code:
float item_feat_float(const cst_item *i,const char *name)
{
    return feat_float(item_feats(i),name);
}

canonical_original_code:
float item_feat_float(struct cst_item_struct *i, char *name)
{
    return feat_float(item_feats(i),name);
}


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

v1 = item_feats(a1);
return feat_string(v1);
}

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

v1 = func19(a1);
return feat_string(v1);
}

original_code:
const char *item_feat_string(const cst_item *i,const char *name)
{
    return feat_string(item_feats(i),name);
}

canonical_original_code:
char *item_feat_string(struct cst_item_struct *i, char *name)
{
    return feat_string(item_feats(i),name);
}

return_type: char *


decompiled_code:
__int64 __fastcall item_set(__int64 **a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

v2 = item_feats(a1);
return feat_set(v2, a2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 **a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

v2 = func19(a1);
return feat_set(v2, a2, v3);
}

original_code:
void item_set(const cst_item *i,const char *name,const cst_val *val)
{
    feat_set(item_feats(i),name,val);
}

canonical_original_code:
void item_set(struct cst_item_struct *i, char *name, struct cst_val_struct *val)
{
    feat_set(item_feats(i),name,val);
}

variable_types:
val
struct cst_val_struct *


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

v1 = item_feats(a1);
return feat_set_int(v1);
}

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

v1 = func19(a1);
return feat_set_int(v1);
}

original_code:
void item_set_int(const cst_item *i,const char *name,int val)
{
    feat_set_int(item_feats(i),name,val);
}

canonical_original_code:
void item_set_int(struct cst_item_struct *i, char *name, int val)
{
    feat_set_int(item_feats(i),name,val);
}

variable_types: val int


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

v1 = item_feats(a1);
return feat_set_float(v1);
}

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

v1 = func19(a1);
return feat_set_float(v1);
}

original_code:
void item_set_float(const cst_item *i,const char *name,float val)
{
    feat_set_float(item_feats(i),name,val);
}

canonical_original_code:
void item_set_float(struct cst_item_struct *i, char *name, float val)
{
    feat_set_float(item_feats(i),name,val);
}

variable_types: val float


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

v1 = item_feats(a1);
return feat_set_string(v1);
}

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

v1 = func19(a1);
return feat_set_string(v1);
}

original_code:
void item_set_string(const cst_item *i,const char *name,const char *val)
{
    feat_set_string(item_feats(i),name,val);
}

canonical_original_code:
void item_set_string(struct cst_item_struct *i, char *name, char *val)
{
    feat_set_string(item_feats(i),name,val);
}

variable_types:
val
char *


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

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

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

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

original_code:
cst_utterance *item_utt(const cst_item *i)
{
    if (i && i->relation)
 return i->relation->utterance;
    else
 return ((void *)0);
}

canonical_original_code:
struct cst_utterance_struct *item_utt(struct cst_item_struct *i)
{
    if (i && i->relation)
 return i->relation->utterance;
    else
 return ((void *)0);
}

variable_types: struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; } *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *


decompiled_code:
_BOOL8 __fastcall item_equal(_QWORD *a1, _QWORD *a2)
{
if ( a1 == a2 )
return 1LL;
if ( a1 && a2 )
return *a1 == *a2;
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func31(_QWORD *a1, _QWORD *a2)
{
if ( a1 == a2 )
return 1LL;
if ( a1 && a2 )
return *a1 == *a2;
return 0LL;
}

original_code:
int item_equal(const cst_item *a, const cst_item *b)
{
    if ((a == b) ||
 (a && b && (a->contents == b->contents)))
 return TRUE;
    else
 return FALSE;
}

canonical_original_code:
int item_equal(struct cst_item_struct *a, struct cst_item_struct *b)
{
    if ((a == b) ||
 (a && b && (a->contents == b->contents)))
 return TRUE;
    else
 return FALSE;
}

variable_types:
b
struct cst_item_struct *


decompiled_code:
__int64 __fastcall val_track(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_track )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "track");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_track )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "track");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

original_code: cst_track *val_track(const cst_val *v) { if (v && ((v)->c.a.type) == cst_val_type_track) return (cst_track *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "track", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

canonical_original_code: struct cst_track_struct *val_track(struct cst_val_struct *v) { if (v && ((v)->c.a.type) == cst_val_type_track) return (struct cst_track_struct *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "track", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

variable_types: struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *

return_type: struct cst_track_struct { char *type; int samples_rate; int num_frames; int num_channels; float *times; float **frames; } *


decompiled_code:
__int64 __fastcall track_val(__int64 a1)
{
return val_new_typed(cst_val_type_track, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return val_new_typed(cst_val_type_track, a1);
}

original_code: cst_val *track_val(const cst_track *v) { return val_new_typed(cst_val_type_track, (void *)v); }

canonical_original_code: struct cst_val_struct *track_val(struct cst_track_struct *v) { return val_new_typed(cst_val_type_track, (void *)v); }

variable_types: struct cst_track_struct { char *type; int samples_rate; int num_frames; int num_channels; float *times; float **frames; } *


decompiled_code:
__int64 new_track()
{
return cst_safe_alloc(40LL);
}

canonical_decompiled_code:
__int64 func2()
{
return cst_safe_alloc(40LL);
}

original_code:
cst_track *new_track()
{
    cst_track *w = ((struct cst_track_struct *)cst_safe_alloc(sizeof(struct cst_track_struct)*(1)));
    return w;
}

canonical_original_code:
struct cst_track_struct *new_track()
{
    struct cst_track_struct *w = ((struct cst_track_struct *)cst_safe_alloc(sizeof(struct cst_track_struct)*(1)));
    return w;
}

user_defined_types: struct cst_track_struct { char *type; int samples_rate; int num_frames; int num_channels; float *times; float **frames; }


decompiled_code:
__int64 __fastcall delete_track(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

if ( a1 )
{
cst_free(*(_QWORD *)(a1 + 24));
if ( *(int *)(a1 + 12) > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v2++);
cst_free(v3);
}
while ( *(_DWORD *)(a1 + 12) > (int)v2 );
}
cst_free(*(_QWORD *)(a1 + 32));
result = cst_free(a1);
}
return result;
}

original_code:
void delete_track(cst_track *w)
{
    int i;
    if (w)
    {
 cst_free(w->times);
 for (i=0; i < w->num_frames; i++)
     cst_free(w->frames[i]);
 cst_free(w->frames);
 cst_free(w);
    }
    return;
}

canonical_original_code:
void delete_track(struct cst_track_struct *w)
{
    int i;
    if (w)
    {
 cst_free(w->times);
 for (i=0; i < w->num_frames; i++)
     cst_free(w->frames[i]);
 cst_free(w->frames);
 cst_free(w);
    }
    return;
}

variable_types: i int


decompiled_code:
// attributes: thunk
__int64 __fastcall val_delete_track(__int64 a1)
{
return delete_track(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return func3(a1);
}

original_code: void val_delete_track(void *v) { delete_track((cst_track *)v); }

canonical_original_code: void val_delete_track(void *v) { delete_track((struct cst_track_struct *)v); }

variable_types:
v
void *


decompiled_code:
float __fastcall track_frame_shift(__int64 a1, int a2)
{
float *v2; // rax
float result; // xmm0_4

v2 = *(float **)(a1 + 24);
if ( a2 )
result = v2[a2] - v2[a2 - 1];
else
result = *v2;
return result;
}

canonical_decompiled_code:
float __fastcall func5(__int64 a1, int a2)
{
float *v2; // rax
float result; // xmm0_4

v2 = *(float **)(a1 + 24);
if ( a2 )
result = v2[a2] - v2[a2 - 1];
else
result = *v2;
return result;
}

original_code:
float track_frame_shift(cst_track *t, int frame)
{
    if (frame == 0)
 return t->times[frame];
    else
 return t->times[frame]-t->times[frame-1];
}

canonical_original_code:
float track_frame_shift(struct cst_track_struct *t, int frame)
{
    if (frame == 0)
 return t->times[frame];
    else
 return t->times[frame]-t->times[frame-1];
}

variable_types: frame int


original_code:
void cst_track_resize(cst_track *t,int num_frames, int num_channels)
{
    float *n_times;
    float **n_frames;
    int i;
    n_times = ((float *)cst_safe_alloc(sizeof(float)*(num_frames)));
    memmove(n_times,t->times,
     (sizeof(float)*((num_frames < t->num_frames) ?
       num_frames : t->num_frames)));
    n_frames = ((float* *)cst_safe_alloc(sizeof(float*)*(num_frames)));
    for (i=0; i<num_frames; i++)
    {
 n_frames[i] = ((float *)cst_safe_alloc(sizeof(float)*(num_channels)));
 if (i<t->num_frames)
 {
     memmove(n_frames[i],
      t->frames[i],
      sizeof(float)*((num_channels < t->num_channels) ?
       num_channels : t->num_channels));
     cst_free(t->frames[i]);
 }
    }
    for ( ; i<t->num_frames; i++)
 cst_free(t->frames[i]);
    cst_free(t->frames);
    t->frames = n_frames;
    cst_free(t->times);
    t->times = n_times;
    t->num_frames = num_frames;
    t->num_channels = num_channels;
}

canonical_original_code:
void cst_track_resize(struct cst_track_struct *t, int num_frames, int num_channels)
{
    float *n_times;
    float **n_frames;
    int i;
    n_times = ((float *)cst_safe_alloc(sizeof(float)*(num_frames)));
    memmove(n_times,t->times,
     (sizeof(float)*((num_frames < t->num_frames) ?
       num_frames : t->num_frames)));
    n_frames = ((float **)cst_safe_alloc(sizeof(float *)*(num_frames)));
    for (i=0; i<num_frames; i++)
    {
 n_frames[i] = ((float *)cst_safe_alloc(sizeof(float)*(num_channels)));
 if (i<t->num_frames)
 {
     memmove(n_frames[i],
      t->frames[i],
      sizeof(float)*((num_channels < t->num_channels) ?
       num_channels : t->num_channels));
     cst_free(t->frames[i]);
 }
    }
    for ( ; i<t->num_frames; i++)
 cst_free(t->frames[i]);
    cst_free(t->frames);
    t->frames = n_frames;
    cst_free(t->times);
    t->times = n_times;
    t->num_frames = num_frames;
    t->num_channels = num_channels;
}


original_code:
static cst_lts_phone apply_model(char *vals,cst_lts_addr start,
     const cst_lts_model *model)
{
    cst_lts_rule state;
    short nstate;
    static const int sizeof_cst_lts_rule = 6;
    memmove(&state,&model[start*sizeof_cst_lts_rule],sizeof_cst_lts_rule);
    for ( ;
  state.feat != 255;
 )
    {
 if (vals[state.feat] == state.val)
     nstate = state.qtrue;
 else
     nstate = state.qfalse;
 if ((((char *)&cst_endian_loc)[0] == 0))
     nstate = ((((unsigned)nstate) & 0xff) << 8 | (((unsigned)nstate) & 0xff00) >> 8);
 memmove(&state,&model[nstate*sizeof_cst_lts_rule],sizeof_cst_lts_rule);
    }
    return (cst_lts_phone)state.val;
}

canonical_original_code:
static unsigned char apply_model(char *vals, unsigned short start, unsigned char *model)
{
    struct cst_lts_rule_struct state;
    short nstate;
    static int sizeof_cst_lts_rule = 6;
    memmove(&state,&model[start*sizeof_cst_lts_rule],sizeof_cst_lts_rule);
    for ( ;
  state.feat != 255;
 )
    {
 if (vals[state.feat] == state.val)
     nstate = state.qtrue;
 else
     nstate = state.qfalse;
 if ((((char *)&cst_endian_loc)[0] == 0))
     nstate = ((((unsigned int)nstate) & 0xff) << 8 | (((unsigned int)nstate) & 0xff00) >> 8);
 memmove(&state,&model[nstate*sizeof_cst_lts_rule],sizeof_cst_lts_rule);
    }
    return (unsigned char)state.val;
}

variable_types:
vals
char *

variable_types:
start
unsigned short

variable_types:
model
unsigned char *

variable_types: struct cst_lts_rule_struct { unsigned char feat; char val; unsigned short qtrue; unsigned short qfalse; }

variable_types: nstate short

return_type: unsigned char


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

result = (_QWORD *)cst_safe_alloc(40LL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
return result;
}

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

result = (_QWORD *)cst_safe_alloc(40LL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
return result;
}

original_code:
cst_lts_rules *new_lts_rules()
{
    cst_lts_rules *lt = ((cst_lts_rules *)cst_safe_alloc(sizeof(cst_lts_rules)*(1)));
    lt->name = 0;
    lt->letter_index = 0;
    lt->models = 0;
    lt->phone_table = 0;
    lt->context_window_size = 0;
    lt->context_extra_feats = 0;
    return lt;
}

canonical_original_code:
struct cst_lts_rules_struct *new_lts_rules()
{
    struct cst_lts_rules_struct *lt = ((cst_lts_rules *)cst_safe_alloc(sizeof(cst_lts_rules)*(1)));
    lt->name = 0;
    lt->letter_index = 0;
    lt->models = 0;
    lt->phone_table = 0;
    lt->context_window_size = 0;
    lt->context_extra_feats = 0;
    return lt;
}

variable_types: struct cst_lts_rules_struct { char *name; unsigned short *letter_index; unsigned char *models; char **phone_table; int context_window_size; int context_extra_feats; } *


original_code:
cst_val *lts_apply(const char *word,const char *feats,const cst_lts_rules *r)
{
    int pos;
    cst_val *phones=0;
    cst_lts_letter *fval_buff;
    cst_lts_letter *full_buff;
    cst_lts_phone phone;
    char *left, *right, *p;
    fval_buff = ((cst_lts_letter *)cst_safe_alloc(sizeof(cst_lts_letter)*((r->context_window_size*2)+ r->context_extra_feats)));
    full_buff = ((cst_lts_letter *)cst_safe_alloc(sizeof(cst_lts_letter)*((r->context_window_size*2)+ strlen(word)+1)));
    sprintf(full_buff,"%.*s#%s#%.*s",
     r->context_window_size-1, "00000000",
     word,
     r->context_window_size-1, "00000000");
    for (pos = r->context_window_size + strlen(word) - 1;
  full_buff[pos] != '#';
  pos--)
    {
 sprintf(fval_buff,"%.*s%.*s%s",
  r->context_window_size,
  full_buff+pos-r->context_window_size,
  r->context_window_size,
  full_buff+pos+1,
  feats);
 if ((full_buff[pos] < 'a') ||
     (full_buff[pos] > 'z'))
 {
     continue;
 }
 phone = apply_model(fval_buff,
       r->letter_index[((full_buff[pos])-'a')%26],
       r->models);
 if ((strcmp("epsilon",r->phone_table[phone]) == 0))
     continue;
 else if ((p=strchr(r->phone_table[phone],'-')) != ((void *)0))
 {
     left = cst_substr(r->phone_table[phone],0,
         strlen(r->phone_table[phone])-strlen(p));
     right = cst_substr(r->phone_table[phone],
          (strlen(r->phone_table[phone])-strlen(p))+1,
          (strlen(p)-1));
     phones = cons_val(string_val(left),
         cons_val(string_val(right),phones));
     cst_free(left);
     cst_free(right);
 }
 else
     phones = cons_val(string_val(r->phone_table[phone]),phones);
    }
    cst_free(full_buff);
    cst_free(fval_buff);
    return phones;
}

canonical_original_code:
struct cst_val_struct *lts_apply(char *word, char *feats, struct cst_lts_rules_struct *r)
{
    int pos;
    struct cst_val_struct *phones = 0;
    char *fval_buff;
    char *full_buff;
    unsigned char phone;
    char *left; char *right; char *p;
    fval_buff = ((char *)cst_safe_alloc(sizeof(cst_lts_letter)*((r->context_window_size*2)+ r->context_extra_feats)));
    full_buff = ((char *)cst_safe_alloc(sizeof(cst_lts_letter)*((r->context_window_size*2)+ strlen(word)+1)));
    sprintf(full_buff,"%.*s#%s#%.*s",
     r->context_window_size-1, "00000000",
     word,
     r->context_window_size-1, "00000000");
    for (pos = r->context_window_size + strlen(word) - 1;
  full_buff[pos] != '#';
  pos--)
    {
 sprintf(fval_buff,"%.*s%.*s%s",
  r->context_window_size,
  full_buff+pos-r->context_window_size,
  r->context_window_size,
  full_buff+pos+1,
  feats);
 if ((full_buff[pos] < 'a') ||
     (full_buff[pos] > 'z'))
 {
     continue;
 }
 phone = apply_model(fval_buff,
       r->letter_index[((full_buff[pos])-'a')%26],
       r->models);
 if ((strcmp("epsilon",r->phone_table[phone]) == 0))
     continue;
 else if ((p=strchr(r->phone_table[phone],'-')) != ((void *)0))
 {
     left = cst_substr(r->phone_table[phone],0,
         strlen(r->phone_table[phone])-strlen(p));
     right = cst_substr(r->phone_table[phone],
          (strlen(r->phone_table[phone])-strlen(p))+1,
          (strlen(p)-1));
     phones = cons_val(string_val(left),
         cons_val(string_val(right),phones));
     cst_free(left);
     cst_free(right);
 }
 else
     phones = cons_val(string_val(r->phone_table[phone]),phones);
    }
    cst_free(full_buff);
    cst_free(fval_buff);
    return phones;
}

variable_types:
word
char *

variable_types:
feats
char *

variable_types: pos int

variable_types:
phone
unsigned char

variable_types:
left
char *

variable_types:
right
char *

variable_types:
p
char *

user_defined_types: struct cst_lts_rules_struct { char *name; unsigned short *letter_index; unsigned char *models; char **phone_table; int context_window_size; int context_extra_feats; }


decompiled_code:
__int64 __fastcall val_phoneset(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_phoneset )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "phoneset");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 *a1)
{
if ( !a1 || *a1 != cst_val_type_phoneset )
{
cst_errmsg("VAL: tried to access %s in %d type val\n", "phoneset");
if ( cst_errjmp )
longjmp(cst_errjmp, 1);
exit(-1);
}
return *((_QWORD *)a1 + 1);
}

original_code: cst_phoneset *val_phoneset(const cst_val *v) { if (v && ((v)->c.a.type) == cst_val_type_phoneset) return (cst_phoneset *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "phoneset", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

canonical_original_code: struct cst_phoneset_struct *val_phoneset(struct cst_val_struct *v) { if (v && ((v)->c.a.type) == cst_val_type_phoneset) return (struct cst_phoneset_struct *)((v)->c.a.v.vval); else { cst_errmsg("VAL: tried to access %s in %d type val\n", "phoneset", (v ? ((v)->c.a.type) : -1)); (cst_errjmp ? longjmp(*cst_errjmp,1) : exit(-1)); } return ((void *)0); }

variable_types:
v
struct cst_val_struct *

return_type: struct cst_phoneset_struct { char *name; char **featnames; struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } **featvals; char **phonenames; char *silence; int num_phones; int **fvtable; } *

user_defined_types: struct cst_phoneset_struct { char *name; char **featnames; struct cst_val_struct **featvals; char **phonenames; char *silence; int num_phones; int **fvtable; }


decompiled_code:
__int64 __fastcall phoneset_val(__int64 a1)
{
return val_new_typed(cst_val_type_phoneset, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return val_new_typed(cst_val_type_phoneset, a1);
}

original_code: cst_val *phoneset_val(const cst_phoneset *v) { return val_new_typed(cst_val_type_phoneset, (void *)v); }

canonical_original_code: struct cst_val_struct *phoneset_val(struct cst_phoneset_struct *v) { return val_new_typed(cst_val_type_phoneset, (void *)v); }

variable_types: struct cst_phoneset_struct { char *name; char **featnames; struct cst_val_struct **featvals; char **phonenames; char *silence; int num_phones; int **fvtable; } *


decompiled_code:
__int64 new_phoneset()
{
return cst_safe_alloc(56LL);
}

canonical_decompiled_code:
__int64 func2()
{
return cst_safe_alloc(56LL);
}

original_code:
cst_phoneset *new_phoneset()
{
    cst_phoneset *v = ((struct cst_phoneset_struct *)cst_safe_alloc(sizeof(struct cst_phoneset_struct)*(1)));
    return v;
}

canonical_original_code:
struct cst_phoneset_struct *new_phoneset()
{
    struct cst_phoneset_struct *v = ((struct cst_phoneset_struct *)cst_safe_alloc(sizeof(struct cst_phoneset_struct)*(1)));
    return v;
}

variable_types: struct cst_phoneset_struct { char *name; char **featnames; struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } **featvals; char **phonenames; char *silence; int num_phones; int **fvtable; } *


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

if ( a1 )
result = cst_free();
return result;
}

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

if ( a1 )
result = cst_free();
return result;
}

original_code:
void delete_phoneset(cst_phoneset *v)
{
    if (v)
    {
 cst_free(v);
    }
}

canonical_original_code:
void delete_phoneset(struct cst_phoneset_struct *v)
{
    if (v)
    {
 cst_free(v);
    }
}


decompiled_code:
__int64 __fastcall phone_id(__int64 a1, const char *a2)
{
__int64 v2; // rbp
__int64 v3; // r14
__int64 v4; // rbx

v2 = *(int *)(a1 + 40);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = *(_QWORD *)(a1 + 24);
v4 = 0LL;
while ( strcmp(*(const char **)(v3 + 8 * v4), a2) )
{
if ( ++v4 == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
__int64 v2; // rbp
__int64 v3; // r14
__int64 v4; // rbx

v2 = *(int *)(a1 + 40);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = *(_QWORD *)(a1 + 24);
v4 = 0LL;
while ( strcmp(*(const char **)(v3 + 8 * v4), a2) )
{
if ( ++v4 == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v4;
}

original_code:
int phone_id(const cst_phoneset *ps,const char* phonename)
{
    int i;
    for (i=0; i< ps->num_phones; i++)
 if ((strcmp(ps->phonenames[i],phonename) == 0))
     return i;
    return -1;
}

canonical_original_code:
int phone_id(struct cst_phoneset_struct *ps, char *phonename)
{
    int i;
    for (i=0; i< ps->num_phones; i++)
 if ((strcmp(ps->phonenames[i],phonename) == 0))
     return i;
    return -1;
}

variable_types:
phonename
char *

variable_types: i int


decompiled_code:
__int64 __fastcall phone_feat_id(__int64 a1, const char *a2)
{
const char **v2; // r12
const char *v3; // rdi
__int64 v4; // rbx

v2 = *(const char ***)(a1 + 8);
v3 = *v2;
if ( !*v2 )
return 0xFFFFFFFFLL;
v4 = 0LL;
while ( strcmp(v3, a2) )
{
v3 = v2[++v4];
if ( !v3 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2)
{
const char **v2; // r12
const char *v3; // rdi
__int64 v4; // rbx

v2 = *(const char ***)(a1 + 8);
v3 = *v2;
if ( !*v2 )
return 0xFFFFFFFFLL;
v4 = 0LL;
while ( strcmp(v3, a2) )
{
v3 = v2[++v4];
if ( !v3 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v4;
}

original_code:
int phone_feat_id(const cst_phoneset *ps,const char* featname)
{
    int i;
    for (i=0; ps->featnames[i]; i++)
 if ((strcmp(ps->featnames[i],featname) == 0))
     return i;
    return -1;
}

canonical_original_code:
int phone_feat_id(struct cst_phoneset_struct *ps, char *featname)
{
    int i;
    for (i=0; ps->featnames[i]; i++)
 if ((strcmp(ps->featnames[i],featname) == 0))
     return i;
    return -1;
}

variable_types:
featname
char *


decompiled_code:
__int64 __fastcall phone_feature(__int64 a1, const char *a2, const char *a3)
{
__int64 v4; // rbp

v4 = (int)phone_id(a1, a2);
return *(_QWORD *)(*(_QWORD *)(a1 + 16)
+ 8LL * *(int *)(*(_QWORD *)(*(_QWORD *)(a1 + 48) + 8 * v4) + 4LL * (int)phone_feat_id(a1, a3)));
}

original_code:
const cst_val *phone_feature(const cst_phoneset *ps,
        const char* phonename,
        const char *featname)
{
    return ps->featvals[ps->fvtable[phone_id(ps,phonename)]
                       [phone_feat_id(ps,featname)]];
}

canonical_original_code:
struct cst_val_struct *phone_feature(struct cst_phoneset_struct *ps, char *phonename, char *featname)
{
    return ps->featvals[ps->fvtable[phone_id(ps,phonename)]
                       [phone_feat_id(ps,featname)]];
}


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

v3 = phone_feature(a1, a2, a3);
return val_string(v3);
}

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

v3 = func6(a1, a2, a3);
return val_string(v3);
}

original_code:
const char *phone_feature_string(const cst_phoneset *ps,
     const char* phonename,
     const char *featname)
{
    return val_string(phone_feature(ps,phonename,featname));
}

canonical_original_code:
char *phone_feature_string(struct cst_phoneset_struct *ps, char *phonename, char *featname)
{
    return val_string(phone_feature(ps,phonename,featname));
}


decompiled_code:
__int64 item_phoneset()
{
_QWORD *v0; // rax
__int16 *v1; // rax

v0 = (_QWORD *)item_utt();
v1 = (__int16 *)feat_val(*v0, "phoneset");
return val_phoneset(v1);
}

canonical_decompiled_code:
__int64 func8()
{
_QWORD *v0; // rax
__int16 *v1; // rax

v0 = (_QWORD *)item_utt();
v1 = (__int16 *)feat_val(*v0, "phoneset");
return func0(v1);
}

original_code:
const cst_phoneset *item_phoneset(const cst_item *p)
{
    return val_phoneset(feat_val(item_utt(p)->features,"phoneset"));
}

canonical_original_code:
struct cst_phoneset_struct *item_phoneset(struct cst_item_struct *p)
{
    return val_phoneset(feat_val(item_utt(p)->features,"phoneset"));
}

variable_types: struct cst_item_struct { struct cst_item_contents_struct { struct cst_features_struct { struct cst_featvalpair_struct { char *name; struct cst_val_struct *val; struct cst_featvalpair_struct *next; } *head; void *ctx; } *features; struct cst_features_struct *relations; } *contents; struct cst_relation_struct { char *name; struct cst_features_struct *features; struct cst_utterance_struct { struct cst_features_struct *features; struct cst_features_struct *ffunctions; struct cst_features_struct *relations; void *ctx; } *utterance; struct cst_item_struct *head; struct cst_item_struct *tail; } *relation; struct cst_item_struct *n; struct cst_item_struct *p; struct cst_item_struct *u; struct cst_item_struct *d; } *


decompiled_code:
_BOOL8 __fastcall item_match(__int64 a1, __int64 a2, __int64 a3)
{
const char *v4; // r12
const char *v5; // rax
int v6; // er8
_BOOL8 result; // rax
const char *v8; // r12
__int64 v9; // rax
__int64 v10; // rax
const char *v11; // rax
__int64 v12; // rax
__int64 v13; // rbp
__int64 v14; // rax

v4 = (const char *)val_string(a2);
v5 = (const char *)val_string(a1);
v6 = strcmp(v5, v4);
result = 1LL;
if ( v6 )
{
while ( 1 )
{
if ( !a3 )
return 0LL;
v8 = (const char *)val_string(a1);
v9 = val_car(a3);
v10 = val_car(v9);
v11 = (const char *)val_string(v10);
if ( !strcmp(v11, v8) )
break;
a3 = val_cdr(a3);
}
v12 = val_car(a3);
v13 = val_cdr(v12);
v14 = val_string(a2);
result = (unsigned int)val_member_string(v14, v13) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
const char *v4; // r12
const char *v5; // rax
int v6; // er8
_BOOL8 result; // rax
const char *v8; // r12
__int64 v9; // rax
__int64 v10; // rax
const char *v11; // rax
__int64 v12; // rax
__int64 v13; // rbp
__int64 v14; // rax

v4 = (const char *)val_string(a2);
v5 = (const char *)val_string(a1);
v6 = strcmp(v5, v4);
result = 1LL;
if ( v6 )
{
while ( 1 )
{
if ( !a3 )
return 0LL;
v8 = (const char *)val_string(a1);
v9 = val_car(a3);
v10 = val_car(v9);
v11 = (const char *)val_string(v10);
if ( !strcmp(v11, v8) )
break;
a3 = val_cdr(a3);
}
v12 = val_car(a3);
v13 = val_cdr(v12);
v14 = val_string(a2);
result = (unsigned int)val_member_string(v14, v13) != 0;
}
return result;
}

original_code:
static int item_match(const cst_val *PATT, const cst_val *THING,
        const cst_val *sets)
{
    const cst_val *sss;
    if ((strcmp(val_string(PATT),val_string(THING)) == 0))
 return TRUE;
    for (sss=sets; sss; sss=val_cdr(sss))
    {
 if ((strcmp(val_string(val_car(val_car(sss))),val_string(PATT)) == 0))
 {
     if (val_member_string(val_string(THING),val_cdr(val_car(sss))))
     {
  return TRUE;
     }
     else
     {
  return FALSE;
     }
 }
    }
    return FALSE;
}

canonical_original_code:
static int item_match(struct cst_val_struct *PATT, struct cst_val_struct *THING, struct cst_val_struct *sets)
{
    struct cst_val_struct *sss;
    if ((strcmp(val_string(PATT),val_string(THING)) == 0))
 return TRUE;
    for (sss=sets; sss; sss=val_cdr(sss))
    {
 if ((strcmp(val_string(val_car(val_car(sss))),val_string(PATT)) == 0))
 {
     if (val_member_string(val_string(THING),val_cdr(val_car(sss))))
     {
  return TRUE;
     }
     else
     {
  return FALSE;
     }
 }
    }
    return FALSE;
}

variable_types: struct cst_val_struct { union { struct cst_val_cons_struct { struct cst_val_struct *car; struct cst_val_struct *cdr; } cc; struct cst_val_atom_struct { short type; short ref_count; union { float fval; int ival; void *vval; } v; } a; } c; } *

variable_types:
THING
struct cst_val_struct *

variable_types:
sets
struct cst_val_struct *


decompiled_code:
_BOOL8 __fastcall context_match(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rbp
__int64 v6; // r14
__int64 v7; // rax
__int64 v8; // rax
_BYTE *v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v14; // r14
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // r12
__int64 v18; // rax
__int64 v19; // rax

if ( !a1 )
return 1LL;
v5 = a1;
while ( 1 )
{
if ( !a2 )
return 0LL;
if ( val_cdr(v5) )
{
v8 = val_car(v5);
v9 = (_BYTE *)val_string(v8);
if ( *v9 == 42 && !v9[1] )
break;
}
v6 = val_car(a2);
v7 = val_car(v5);
if ( !item_match(v7, v6, a3) )
return 0LL;
a2 = val_cdr(a2);
v5 = val_cdr(v5);
if ( !v5 )
return 1LL;
}
v10 = val_cdr(v5);
v11 = val_cdr(v10);
if ( (unsigned int)context_match(v11, a2, a3) )
return 1LL;
v12 = val_cdr(v5);
if ( (unsigned int)context_match(v12, a2, a3) )
return 1LL;
v14 = val_car(a2);
v15 = val_cdr(v5);
v16 = val_car(v15);
if ( !item_match(v16, v14, a3) )
return 0LL;
v17 = val_cdr(a2);
v18 = val_cdr(v5);
v19 = val_cdr(v18);
return (unsigned int)context_match(v19, v17, a3) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rbp
__int64 v6; // r14
__int64 v7; // rax
__int64 v8; // rax
_BYTE *v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v14; // r14
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // r12
__int64 v18; // rax
__int64 v19; // rax

if ( !a1 )
return 1LL;
v5 = a1;
while ( 1 )
{
if ( !a2 )
return 0LL;
if ( val_cdr(v5) )
{
v8 = val_car(v5);
v9 = (_BYTE *)val_string(v8);
if ( *v9 == 42 && !v9[1] )
break;
}
v6 = val_car(a2);
v7 = val_car(v5);
if ( !func0(v7, v6, a3) )
return 0LL;
a2 = val_cdr(a2);
v5 = val_cdr(v5);
if ( !v5 )
return 1LL;
}
v10 = val_cdr(v5);
v11 = val_cdr(v10);
if ( (unsigned int)func1(v11, a2, a3) )
return 1LL;
v12 = val_cdr(v5);
if ( (unsigned int)func1(v12, a2, a3) )
return 1LL;
v14 = val_car(a2);
v15 = val_cdr(v5);
v16 = val_car(v15);
if ( !func0(v16, v14, a3) )
return 0LL;
v17 = val_cdr(a2);
v18 = val_cdr(v5);
v19 = val_cdr(v18);
return (unsigned int)func1(v19, v17, a3) != 0;
}

original_code:
static int context_match(const cst_val *PATTERN, const cst_val *STRING,
    const cst_val *sets)
{
    if (!PATTERN)
 return TRUE;
    else if (!STRING)
 return FALSE;
    else if (val_cdr(PATTERN) &&
      ((strcmp("*",val_string(val_car(PATTERN))) == 0)))
 return
     context_match(val_cdr(val_cdr(PATTERN)),STRING,sets) ||
     context_match(val_cdr(PATTERN),STRING,sets) ||
     (item_match(val_car(val_cdr(PATTERN)),val_car(STRING),sets) &&
      context_match(val_cdr(val_cdr(PATTERN)),
      val_cdr(STRING),sets));
    else if (item_match(val_car(PATTERN),val_car(STRING),sets))
 return context_match(val_cdr(PATTERN),val_cdr(STRING),sets);
    else
 return FALSE;
}

canonical_original_code:
static int context_match(struct cst_val_struct *PATTERN, struct cst_val_struct *STRING, struct cst_val_struct *sets)
{
    if (!PATTERN)
 return TRUE;
    else if (!STRING)
 return FALSE;
    else if (val_cdr(PATTERN) &&
      ((strcmp("*",val_string(val_car(PATTERN))) == 0)))
 return
     context_match(val_cdr(val_cdr(PATTERN)),STRING,sets) ||
     context_match(val_cdr(PATTERN),STRING,sets) ||
     (item_match(val_car(val_cdr(PATTERN)),val_car(STRING),sets) &&
      context_match(val_cdr(val_cdr(PATTERN)),
      val_cdr(STRING),sets));
    else if (item_match(val_car(PATTERN),val_car(STRING),sets))
 return context_match(val_cdr(PATTERN),val_cdr(STRING),sets);
    else
 return FALSE;
}

variable_types:
STRING
struct cst_val_struct *


decompiled_code:
_BOOL8 __fastcall rule_matches(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v9; // rbp
__int64 v10; // rax
const char *v11; // r14
__int64 v12; // rax
const char *v13; // rax

if ( a4 )
{
v9 = a4;
while ( a2 )
{
v10 = val_car(a2);
v11 = (const char *)val_string(v10);
v12 = val_car(v9);
v13 = (const char *)val_string(v12);
if ( strcmp(v13, v11) )
break;
v9 = val_cdr(v9);
a2 = val_cdr(a2);
if ( !v9 )
goto LABEL_7;
}
return 0LL;
}
LABEL_7:
if ( !context_match(a3, a1, a6) )
return 0LL;
return context_match(a5, a2, a6);
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v9; // rbp
__int64 v10; // rax
const char *v11; // r14
__int64 v12; // rax
const char *v13; // rax

if ( a4 )
{
v9 = a4;
while ( a2 )
{
v10 = val_car(a2);
v11 = (const char *)val_string(v10);
v12 = val_car(v9);
v13 = (const char *)val_string(v12);
if ( strcmp(v13, v11) )
break;
v9 = val_cdr(v9);
a2 = val_cdr(a2);
if ( !v9 )
goto LABEL_7;
}
return 0LL;
}
LABEL_7:
if ( !func1(a3, a1, a6) )
return 0LL;
return func1(a5, a2, a6);
}

original_code:
static int rule_matches(const cst_val *LC, const cst_val *RC,
   const cst_val *RLC, const cst_val *RA,
   const cst_val *RRC,
   const cst_val *sets)
{
    const cst_val *rc, *ra;
    for (rc=RC,ra=RA; ra; ra=val_cdr(ra),rc=val_cdr(rc))
    {
 if (!rc) return FALSE;
 if (!(strcmp(val_string(val_car(ra)),val_string(val_car(rc))) == 0))
     return FALSE;
    }
    if (context_match(RLC,LC,sets) && context_match(RRC,rc,sets))
 return TRUE;
    else
 return FALSE;
}

canonical_original_code:
static int rule_matches(struct cst_val_struct *LC, struct cst_val_struct *RC, struct cst_val_struct *RLC, struct cst_val_struct *RA, struct cst_val_struct *RRC, struct cst_val_struct *sets)
{
    struct cst_val_struct *rc; struct cst_val_struct *ra;
    for (rc=RC,ra=RA; ra; ra=val_cdr(ra),rc=val_cdr(rc))
    {
 if (!rc) return FALSE;
 if (!(strcmp(val_string(val_car(ra)),val_string(val_car(rc))) == 0))
     return FALSE;
    }
    if (context_match(RLC,LC,sets) && context_match(RRC,rc,sets))
 return TRUE;
    else
 return FALSE;
}

variable_types:
RC
struct cst_val_struct *

variable_types:
RLC
struct cst_val_struct *

variable_types:
RA
struct cst_val_struct *

variable_types:
RRC
struct cst_val_struct *


decompiled_code:
__int64 __fastcall find_rewrite_rule(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp
__int64 v5; // rax
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 result; // rax

v3 = *(_QWORD *)(a3 + 16);
if ( v3 )
{
while ( 1 )
{
v5 = val_car(v3);
v6 = val_car(v5);
v7 = val_car(v3);
v8 = val_cdr(v7);
v9 = val_car(v8);
v10 = val_car(v3);
v11 = val_cdr(v10);
v12 = val_cdr(v11);
v13 = val_car(v12);
if ( rule_matches(a1, a2, v6, v9, v13, *(_QWORD *)(a3 + 8)) )
break;
v3 = val_cdr(v3);
if ( !v3 )
goto LABEL_6;
}
result = val_car(v3);
}
else
{
LABEL_6:
fwrite("LTS_REWRITES: unable to find a matching rules for:\n", 1uLL, 0x33uLL, stderr);
fwrite("CL: ", 1uLL, 4uLL, stderr);
val_print(stderr, a1);
fputc(10, stderr);
fwrite("RC: ", 1uLL, 4uLL, stderr);
val_print(stderr, a2);
fputc(10, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp
__int64 v5; // rax
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 result; // rax

v3 = *(_QWORD *)(a3 + 16);
if ( v3 )
{
while ( 1 )
{
v5 = val_car(v3);
v6 = val_car(v5);
v7 = val_car(v3);
v8 = val_cdr(v7);
v9 = val_car(v8);
v10 = val_car(v3);
v11 = val_cdr(v10);
v12 = val_cdr(v11);
v13 = val_car(v12);
if ( func2(a1, a2, v6, v9, v13, *(_QWORD *)(a3 + 8)) )
break;
v3 = val_cdr(v3);
if ( !v3 )
goto LABEL_6;
}
result = val_car(v3);
}
else
{
LABEL_6:
fwrite("LTS_REWRITES: unable to find a matching rules for:\n", 1uLL, 0x33uLL, stderr);
fwrite("CL: ", 1uLL, 4uLL, stderr);
val_print(stderr, a1);
fputc(10, stderr);
fwrite("RC: ", 1uLL, 4uLL, stderr);
val_print(stderr, a2);
fputc(10, stderr);
result = 0LL;
}
return result;
}

original_code:
static const cst_val *find_rewrite_rule(const cst_val *LC,
     const cst_val *RC,
     const cst_lts_rewrites *r)
{
    const cst_val *i, *RLC, *RA, *RRC;
    for (i=r->rules; i; i=val_cdr(i))
    {
 RLC = val_car(val_car(i));
 RA = val_car(val_cdr(val_car(i)));
 RRC = val_car(val_cdr(val_cdr(val_car(i))));
 if (rule_matches(LC,RC,RLC,RA,RRC,r->sets))
     return val_car(i);
    }
    fprintf(stderr,"LTS_REWRITES: unable to find a matching rules for:\n");
    fprintf(stderr,"CL: ");
    val_print(stderr,LC);
    fprintf(stderr,"\n");
    fprintf(stderr,"RC: ");
    val_print(stderr,RC);
    fprintf(stderr,"\n");
    return ((void *)0);
}

canonical_original_code:
static struct cst_val_struct *find_rewrite_rule(struct cst_val_struct *LC, struct cst_val_struct *RC, struct cst_lts_rewrites_struct *r)
{
    struct cst_val_struct *i; struct cst_val_struct *RLC; struct cst_val_struct *RA; struct cst_val_struct *RRC;
    for (i=r->rules; i; i=val_cdr(i))
    {
 RLC = val_car(val_car(i));
 RA = val_car(val_cdr(val_car(i)));
 RRC = val_car(val_cdr(val_cdr(val_car(i))));
 if (rule_matches(LC,RC,RLC,RA,RRC,r->sets))
     return val_car(i);
    }
    fprintf(stderr,"LTS_REWRITES: unable to find a matching rules for:\n");
    fprintf(stderr,"CL: ");
    val_print(stderr,LC);
    fprintf(stderr,"\n");
    fprintf(stderr,"RC: ");
    val_print(stderr,RC);
    fprintf(stderr,"\n");
    return ((void *)0);
}

variable_types:
LC
struct cst_val_struct *

variable_types: struct cst_lts_rewrites_struct { char *name; struct cst_val_struct *sets; struct cst_val_struct *rules; } *


decompiled_code:
__int64 __fastcall lts_rewrites(__int64 a1, __int64 a2)
{
__int64 v2; // r14
__int64 v3; // rax
__int64 v4; // r13
__int64 v5; // r12
__int64 v6; // rax
__int64 v7; // r15
__int64 v8; // rax
__int64 i; // rbp
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rbp
__int64 v15; // rax

v2 = 0LL;
v3 = val_car(a1);
v4 = cons_val(v3, 0LL);
v5 = val_cdr(a1);
LABEL_2:
while ( val_cdr(v5) )
{
v6 = find_rewrite_rule(v4, v5, a2);
v7 = v6;
if ( !v6 )
break;
v8 = val_cdr(v6);
for ( i = val_car(v8); i; i = val_cdr(i) )
{
v10 = val_car(v5);
v4 = cons_val(v10, v4);
v5 = val_cdr(v5);
}
v11 = val_cdr(v7);
v12 = val_cdr(v11);
v13 = val_cdr(v12);
v14 = val_car(v13);
if ( !v14 )
goto LABEL_2;
do
{
v15 = val_car(v14);
v2 = cons_val(v15, v2);
v14 = val_cdr(v14);
}
while ( v14 );
}
delete_val_list(v4);
return val_reverse(v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // r14
__int64 v3; // rax
__int64 v4; // r13
__int64 v5; // r12
__int64 v6; // rax
__int64 v7; // r15
__int64 v8; // rax
__int64 i; // rbp
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rbp
__int64 v15; // rax

v2 = 0LL;
v3 = val_car(a1);
v4 = cons_val(v3, 0LL);
v5 = val_cdr(a1);
LABEL_2:
while ( val_cdr(v5) )
{
v6 = func3(v4, v5, a2);
v7 = v6;
if ( !v6 )
break;
v8 = val_cdr(v6);
for ( i = val_car(v8); i; i = val_cdr(i) )
{
v10 = val_car(v5);
v4 = cons_val(v10, v4);
v5 = val_cdr(v5);
}
v11 = val_cdr(v7);
v12 = val_cdr(v11);
v13 = val_cdr(v12);
v14 = val_car(v13);
if ( !v14 )
goto LABEL_2;
do
{
v15 = val_car(v14);
v2 = cons_val(v15, v2);
v14 = val_cdr(v14);
}
while ( v14 );
}
delete_val_list(v4);
return val_reverse(v2);
}

original_code:
cst_val *lts_rewrites(const cst_val *itape, const cst_lts_rewrites *r)
{
    cst_val *LC;
    const cst_val *RC, *i;
    const cst_val *rule;
    cst_val *otape;
    LC = cons_val(val_car(itape),((void *)0));
    RC = val_cdr(itape);
    otape = ((void *)0);
    while (val_cdr(RC))
    {
 rule = find_rewrite_rule(LC,RC,r);
 if (!rule)
     break;
 for (i=val_car(val_cdr(rule)); i; i=val_cdr(i))
 {
     LC = cons_val(val_car(RC),LC);
     RC = val_cdr(RC);
 }
 for (i=val_car(val_cdr(val_cdr(val_cdr(rule)))); i; i=val_cdr(i))
     otape = cons_val(val_car(i),otape);
    }
    delete_val_list(LC);
    return val_reverse(otape);
}

canonical_original_code:
struct cst_val_struct *lts_rewrites(struct cst_val_struct *itape, struct cst_lts_rewrites_struct *r)
{
    struct cst_val_struct *LC;
    struct cst_val_struct *RC; struct cst_val_struct *i;
    struct cst_val_struct *rule;
    struct cst_val_struct *otape;
    LC = cons_val(val_car(itape),((void *)0));
    RC = val_cdr(itape);
    otape = ((void *)0);
    while (val_cdr(RC))
    {
 rule = find_rewrite_rule(LC,RC,r);
 if (!rule)
     break;
 for (i=val_car(val_cdr(rule)); i; i=val_cdr(i))
 {
     LC = cons_val(val_car(RC),LC);
     RC = val_cdr(RC);
 }
 for (i=val_car(val_cdr(val_cdr(val_cdr(rule)))); i; i=val_cdr(i))
     otape = cons_val(val_car(i),otape);
    }
    delete_val_list(LC);
    return val_reverse(otape);
}

variable_types:
itape
struct cst_val_struct *

user_defined_types: struct cst_lts_rewrites_struct { char *name; struct cst_val_struct *sets; struct cst_val_struct *rules; }


decompiled_code:
__int64 __fastcall lts_rewrites_word(char *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbp
char v4; // al
_BYTE *v5; // rbx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rbp
__int64 v10; // r12
char v12[26]; // [rsp+Eh] [rbp-1Ah] BYREF

v12[1] = 0;
v2 = string_val("#");
v3 = cons_val(v2, 0LL);
v4 = *a1;
if ( *a1 )
{
v5 = a1 + 1;
do
{
v12[0] = v4;
++v5;
v6 = string_val(v12);
v3 = cons_val(v6, v3);
v4 = *(v5 - 1);
}
while ( v4 );
}
v7 = string_val("#");
v8 = cons_val(v7, v3);
v9 = val_reverse(v8);
v10 = lts_rewrites(v9, a2);
delete_val(v9);
return v10;
}

original_code:
cst_val *lts_rewrites_word(const char *word, const cst_lts_rewrites *r)
{
    cst_val *w, *p;
    char x[2];
    int i;
    x[1] = '\0';
    w = cons_val(string_val("#"),((void *)0));
    for (i=0; word[i]; i++)
    {
 x[0] = word[i];
 w = cons_val(string_val(x),w);
    }
    w = cons_val(string_val("#"),w);
    w = val_reverse(w);
    p = lts_rewrites(w,r);
    delete_val(w);
    return p;
}

canonical_original_code:
struct cst_val_struct *lts_rewrites_word(char *word, struct cst_lts_rewrites_struct *r)
{
    struct cst_val_struct *w; struct cst_val_struct *p;
    char x[2];
    int i;
    x[1] = '\0';
    w = cons_val(string_val("#"),((void *)0));
    for (i=0; word[i]; i++)
    {
 x[0] = word[i];
 w = cons_val(string_val(x),w);
    }
    w = cons_val(string_val("#"),w);
    w = val_reverse(w);
    p = lts_rewrites(w,r);
    delete_val(w);
    return p;
}

variable_types:
word
char *

variable_types:
x
char [2]


decompiled_code:
__int64 new_val()
{
return cst_safe_alloc(16LL);
}

canonical_decompiled_code:
__int64 func0()
{
return cst_safe_alloc(16LL);
}

original_code:
static cst_val *new_val()
{
   return ((struct cst_val_struct *)cst_safe_alloc(sizeof(struct cst_val_struct)*(1)));
}

canonical_original_code:
static struct cst_val_struct *new_val()
{
   return ((struct cst_val_struct *)cst_safe_alloc(sizeof(struct cst_val_struct)*(1)));
}


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

result = new_val();
*(_WORD *)result = 1;
*(_DWORD *)(result + 8) = a1;
return result;
}

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

result = func0();
*(_WORD *)result = 1;
*(_DWORD *)(result + 8) = a1;
return result;
}

original_code:
cst_val *int_val(int i)
{
   cst_val *v = new_val();
   ((v)->c.a.type) = 1;
   ((v)->c.a.v.ival) = i;
   return v;
}

canonical_original_code:
struct cst_val_struct *int_val(int i)
{
   struct cst_val_struct *v = new_val();
   ((v)->c.a.type) = 1;
   ((v)->c.a.v.ival) = i;
   return v;
}


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

result = new_val();
*(_WORD *)result = 3;
*(float *)(result + 8) = a1;
return result;
}

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

result = func0();
*(_WORD *)result = 3;
*(float *)(result + 8) = a1;
return result;
}

original_code:
cst_val *float_val(float f)
{
   cst_val *v = new_val();
   ((v)->c.a.type) = 3;
   ((v)->c.a.v.fval) = f;
   return v;
}

canonical_original_code:
struct cst_val_struct *float_val(float f)
{
   struct cst_val_struct *v = new_val();
   ((v)->c.a.type) = 3;
   ((v)->c.a.v.fval) = f;
   return v;
}

variable_types: f float


decompiled_code:
__int64 __fastcall string_val(__int64 a1)
{
__int64 v1; // r12

v1 = new_val();
*(_WORD *)v1 = 5;
*(_QWORD *)(v1 + 8) = cst_strdup(a1);
return v1;
}

original_code:
cst_val *string_val(const char *s)
{
   cst_val *v = new_val();
   ((v)->c.a.type) = 5;
   ((v)->c.a.v.vval) = cst_strdup(s);
   return v;
}

canonical_original_code:
struct cst_val_struct *string_val(char *s)
{
   struct cst_val_struct *v = new_val();
   ((v)->c.a.type) = 5;
   ((v)->c.a.v.vval) = cst_strdup(s);
   return v;
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall val_new_typed(__int16 a1, __int64 a2)
{
__int64 result; // rax

result = new_val();
*(_WORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
return result;
}

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

result = func0();
*(_WORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
return result;
}

original_code:
cst_val *val_new_typed(int type,void *vv)
{
   cst_val *v = new_val();
   ((v)->c.a.type) = type;
   ((v)->c.a.v.vval) = vv;
   return v;
}

canonical_original_code:
struct cst_val_struct *val_new_typed(int type, void *vv)
{
   struct cst_val_struct *v = new_val();
   ((v)->c.a.type) = type;
   ((v)->c.a.v.vval) = vv;
   return v;
}

variable_types: type int

variable_types:
vv
void *