decompiled_code:
void test_symbol()
{
__int64 v0; // rbp
_QWORD *v1; // rbp
__int64 v2[17]; // [rsp+0h] [rbp-88h] BYREF

v0 = symbol_init(10LL);
symbol_randomize(v0);
v2[0] = 0x500000001LL;
v2[1] = 0x300000001LL;
printf("Original symbol: ");
symbol_stdout(v0);
v1 = (_QWORD *)symbol_unabstract(v0, v2, 4LL);
puts("unabstracted symbols:");
printf("1 dimension : ");
symbol_stdout(*v1);
printf("5 dimensions: ");
symbol_stdout(v1[1]);
printf("1 dimension : ");
symbol_stdout(v1[2]);
printf("3 dimensions: ");
symbol_stdout(v1[3]);
symbol_free(*v1);
symbol_free(v1[1]);
symbol_free(v1[2]);
symbol_free(v1[3]);
free(v1);
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // rbp
_QWORD *v1; // rbp
__int64 v2[17]; // [rsp+0h] [rbp-88h] BYREF

v0 = symbol_init(10LL);
symbol_randomize(v0);
v2[0] = 0x500000001LL;
v2[1] = 0x300000001LL;
printf("Original symbol: ");
symbol_stdout(v0);
v1 = (_QWORD *)symbol_unabstract(v0, v2, 4LL);
puts("unabstracted symbols:");
printf("1 dimension : ");
symbol_stdout(*v1);
printf("5 dimensions: ");
symbol_stdout(v1[1]);
printf("1 dimension : ");
symbol_stdout(v1[2]);
printf("3 dimensions: ");
symbol_stdout(v1[3]);
symbol_free(*v1);
symbol_free(v1[1]);
symbol_free(v1[2]);
symbol_free(v1[3]);
free(v1);
}

original_code:
void test_symbol(void)
{
 Symbol *sym;
 Symbol **list;
 int dims[32];
 sym = symbol_init(10);
 symbol_randomize(sym);
 dims[0] = 1;
 dims[1] = 5;
 dims[2] = 1;
 dims[3] = 3;
 printf("Original symbol: ");
 symbol_stdout(sym);
 list = symbol_unabstract(sym, dims, 4);
 printf("unabstracted symbols:\n");
 printf("1 dimension : ");
 symbol_stdout(list[0]);
 printf("5 dimensions: ");
 symbol_stdout(list[1]);
 printf("1 dimension : ");
 symbol_stdout(list[2]);
 printf("3 dimensions: ");
 symbol_stdout(list[3]);
 symbol_free(list[0]);
 symbol_free(list[1]);
 symbol_free(list[2]);
 symbol_free(list[3]);
 free(list);
}

canonical_original_code:
void test_symbol()
{
 struct Symbol_s *sym;
 struct Symbol_s **list;
 int dims[32];
 sym = symbol_init(10);
 symbol_randomize(sym);
 dims[0] = 1;
 dims[1] = 5;
 dims[2] = 1;
 dims[3] = 3;
 printf("Original symbol: ");
 symbol_stdout(sym);
 list = symbol_unabstract(sym, dims, 4);
 printf("unabstracted symbols:\n");
 printf("1 dimension : ");
 symbol_stdout(list[0]);
 printf("5 dimensions: ");
 symbol_stdout(list[1]);
 printf("1 dimension : ");
 symbol_stdout(list[2]);
 printf("3 dimensions: ");
 symbol_stdout(list[3]);
 symbol_free(list[0]);
 symbol_free(list[1]);
 symbol_free(list[2]);
 symbol_free(list[3]);
 free(list);
}

variable_types:
dims
int [32]


repo: psilord/manifold

decompiled_code:
__int64 test_intqueue()
{
int v0; // ebx
__int64 v1; // r12
float v2; // xmm0_4
__int64 v3; // rbp

v0 = 0;
v1 = intqueue_init(2LL, 4LL);
do
{
v2 = (float)v0;
v3 = symbol_init(3LL);
++v0;
symbol_set_all(v3, v2);
intqueue_enqueue(v1, v3);
intqueue_stdout(v1);
}
while ( v0 != 8 );
return intqueue_free(v1);
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx
__int64 v1; // r12
float v2; // xmm0_4
__int64 v3; // rbp

v0 = 0;
v1 = intqueue_init(2LL, 4LL);
do
{
v2 = (float)v0;
v3 = symbol_init(3LL);
++v0;
symbol_set_all(v3, v2);
intqueue_enqueue(v1, v3);
intqueue_stdout(v1);
}
while ( v0 != 8 );
return intqueue_free(v1);
}

original_code:
void test_intqueue(void)
{
 int i;
 Symbol *sym;
 IntQueue *iq;
 iq = intqueue_init(2, 4);
 for (i = 0; i < 8; i++)
 {
  sym = symbol_init(3);
  symbol_set_all(sym, i);
  intqueue_enqueue(iq, sym);
  intqueue_stdout(iq);
 }
 intqueue_free(iq);
}

canonical_original_code:
void test_intqueue()
{
 int i;
 struct Symbol_s *sym;
 struct IntQueue_s *iq;
 iq = intqueue_init(2, 4);
 for (i = 0; i < 8; i++)
 {
  sym = symbol_init(3);
  symbol_set_all(sym, i);
  intqueue_enqueue(iq, sym);
  intqueue_stdout(iq);
 }
 intqueue_free(iq);
}

variable_types: i int

variable_types: struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s { unsigned short dim; float vec[1]; } ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; } *

return_type: void

user_defined_types: struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; }


decompiled_code:
__int64 __fastcall test_cortex_ascii(__int64 a1)
{
int v1; // er12
__int64 v2; // r15
__int64 i; // rsi
unsigned int v4; // eax
__int64 v5; // rax
int v6; // eax
int v7; // ebp
int *v8; // rax
int *v9; // r14
unsigned int v10; // er13
__int64 v11; // rax
__int64 v12; // r12
__int64 v13; // rbp
char v14; // al
__int64 v15; // rdx
char v16; // bl
const char *v17; // rax
__int64 v19; // [rsp+0h] [rbp-B8h]
int v20; // [rsp+8h] [rbp-B0h]
int v21; // [rsp+Ch] [rbp-ACh]
unsigned int v22; // [rsp+10h] [rbp-A8h]
int v23; // [rsp+14h] [rbp-A4h]
int v24; // [rsp+18h] [rbp-A0h]
int v25; // [rsp+1Ch] [rbp-9Ch]
unsigned int v26; // [rsp+20h] [rbp-98h] BYREF
unsigned int v27; // [rsp+24h] [rbp-94h] BYREF
double v28; // [rsp+28h] [rbp-90h] BYREF
__int64 v29[17]; // [rsp+30h] [rbp-88h] BYREF

v1 = 0;
v2 = input_init(1LL);
v19 = cortex_init(a1);
v22 = 0;
v20 = SDL_GetTicks();
v21 = v20 + 1000;
v23 = 0;
for ( i = 73LL; ; i = (unsigned int)byte_C10[v1] )
{
v5 = input_xlate_char(v2, i);
v29[0] = symbol_copy(v5);
cortex_process(v19, v29, 1LL, 0LL);
v6 = process_events(&v26, &v27);
v7 = v6;
switch ( v6 )
{
case 2:
if ( v21 < v20 )
{
glClear(16640LL);
goto LABEL_25;
}
++v22;
v23 = 0;
break;
case 3:
v8 = (int *)cortex_resolve(v19, v26, v27);
v9 = v8;
if ( v8 )
{
v10 = 0;
if ( *v8 > 0 )
{
v24 = v1;
v25 = v7;
do
{
while ( 1 )
{
v11 = inputrestable_input(v9, v10);
v12 = v11;
if ( *(_DWORD *)(v11 + 4) == 1 && *(int *)(v11 + 8) > 0 )
break;
if ( *v9 <= (int)++v10 )
goto LABEL_22;
}
v13 = 0LL;
do
{
v14 = input_decode_to_char(v2, *(_QWORD *)(*(_QWORD *)(v12 + 16) + 8 * v13), &v28);
v15 = (unsigned int)v13;
v16 = v14;
++v13;
printf("For input %d, time step -%d: ", v10, v15);
printf("char '%c' error %f\n", (unsigned int)v16, v28);
}
while ( *(_DWORD *)(v12 + 8) > (int)v13 );
++v10;
}
while ( *v9 > (int)v10 );
LABEL_22:
v1 = v24;
v7 = v25;
}
inputrestable_destroy(v9);
if ( v21 >= v20 )
{
LABEL_4:
++v22;
break;
}
}
else
{
LABEL_3:
if ( v21 >= v20 )
goto LABEL_4;
}
glClear(16640LL);
if ( v23 == 1 )
{
LABEL_34:
cortex_draw(v19, 1LL);
v23 = 1;
goto LABEL_26;
}
LABEL_25:
cortex_draw(v19, 0LL);
v23 = 0;
LABEL_26:
SDL_GL_SwapBuffers();
v21 = v20 + 1000;
printf("Glyphs per second: %d\n", v22);
v22 = 1;
break;
case 1:
if ( v21 < v20 )
{
glClear(16640LL);
goto LABEL_34;
}
++v22;
v23 = 1;
break;
default:
goto LABEL_3;
}
v20 = SDL_GetTicks();
v4 = glGetError();
if ( v4 )
{
v17 = (const char *)gluErrorString(v4);
printf("Opengl Error: %s\n", v17);
}
if ( __ROR8__(0x84BDA12F684BDA13LL * ++v1, 3) <= 0x12F684BDA12F684uLL )
v1 = 0;
if ( v7 == 4 )
break;
}
cortex_free(v19);
return input_free(v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // er12
__int64 v2; // r15
__int64 i; // rsi
unsigned int v4; // eax
__int64 v5; // rax
int v6; // eax
int v7; // ebp
int *v8; // rax
int *v9; // r14
unsigned int v10; // er13
__int64 v11; // rax
__int64 v12; // r12
__int64 v13; // rbp
char v14; // al
__int64 v15; // rdx
char v16; // bl
const char *v17; // rax
__int64 v19; // [rsp+0h] [rbp-B8h]
int v20; // [rsp+8h] [rbp-B0h]
int v21; // [rsp+Ch] [rbp-ACh]
unsigned int v22; // [rsp+10h] [rbp-A8h]
int v23; // [rsp+14h] [rbp-A4h]
int v24; // [rsp+18h] [rbp-A0h]
int v25; // [rsp+1Ch] [rbp-9Ch]
unsigned int v26; // [rsp+20h] [rbp-98h] BYREF
unsigned int v27; // [rsp+24h] [rbp-94h] BYREF
double v28; // [rsp+28h] [rbp-90h] BYREF
__int64 v29[17]; // [rsp+30h] [rbp-88h] BYREF

v1 = 0;
v2 = input_init(1LL);
v19 = cortex_init(a1);
v22 = 0;
v20 = SDL_GetTicks();
v21 = v20 + 1000;
v23 = 0;
for ( i = 73LL; ; i = (unsigned int)byte_C10[v1] )
{
v5 = input_xlate_char(v2, i);
v29[0] = symbol_copy(v5);
cortex_process(v19, v29, 1LL, 0LL);
v6 = func2(&v26, &v27);
v7 = v6;
switch ( v6 )
{
case 2:
if ( v21 < v20 )
{
glClear(16640LL);
goto LABEL_25;
}
++v22;
v23 = 0;
break;
case 3:
v8 = (int *)cortex_resolve(v19, v26, v27);
v9 = v8;
if ( v8 )
{
v10 = 0;
if ( *v8 > 0 )
{
v24 = v1;
v25 = v7;
do
{
while ( 1 )
{
v11 = inputrestable_input(v9, v10);
v12 = v11;
if ( *(_DWORD *)(v11 + 4) == 1 && *(int *)(v11 + 8) > 0 )
break;
if ( *v9 <= (int)++v10 )
goto LABEL_22;
}
v13 = 0LL;
do
{
v14 = input_decode_to_char(v2, *(_QWORD *)(*(_QWORD *)(v12 + 16) + 8 * v13), &v28);
v15 = (unsigned int)v13;
v16 = v14;
++v13;
printf("For input %d, time step -%d: ", v10, v15);
printf("char '%c' error %f\n", (unsigned int)v16, v28);
}
while ( *(_DWORD *)(v12 + 8) > (int)v13 );
++v10;
}
while ( *v9 > (int)v10 );
LABEL_22:
v1 = v24;
v7 = v25;
}
inputrestable_destroy(v9);
if ( v21 >= v20 )
{
LABEL_4:
++v22;
break;
}
}
else
{
LABEL_3:
if ( v21 >= v20 )
goto LABEL_4;
}
glClear(16640LL);
if ( v23 == 1 )
{
LABEL_34:
cortex_draw(v19, 1LL);
v23 = 1;
goto LABEL_26;
}
LABEL_25:
cortex_draw(v19, 0LL);
v23 = 0;
LABEL_26:
SDL_GL_SwapBuffers();
v21 = v20 + 1000;
printf("Glyphs per second: %d\n", v22);
v22 = 1;
break;
case 1:
if ( v21 < v20 )
{
glClear(16640LL);
goto LABEL_34;
}
++v22;
v23 = 1;
break;
default:
goto LABEL_3;
}
v20 = SDL_GetTicks();
v4 = glGetError();
if ( v4 )
{
v17 = (const char *)gluErrorString(v4);
printf("Opengl Error: %s\n", v17);
}
if ( __ROR8__(0x84BDA12F684BDA13LL * ++v1, 3) <= 0x12F684BDA12F684uLL )
v1 = 0;
if ( v7 == 4 )
break;
}
cortex_free(v19);
return input_free(v2);
}

original_code:
void test_cortex_ascii(char *filename)
{
 Cortex *core = ((void *)0);
 int state = STATE_RUNNING;
 int sample, now, incr = 1000;
 int i, j, k;
 int mr, mc;
 int drawing_mode = SOM_STYLE_ACTUAL;
 int glerr;
 int iter = 0;
 char revc;
 double revcerr;
 char *alpha = "I am very happy that my reverse lookup code seems to work. "
     "It really fills me with joy that after such a long and "
     "hard amount of work, everything finally seems to be "
     "working. Let us see if the vision processor works.";
 Input *inp;
 InputResTable *irt;
 InputResolution *ires;
 Symbol *channels[10];
 int num_channels = 1;
 inp = input_init(1);
 core = cortex_init(filename);
 now = SDL_GetTicks();
 sample = now + incr;
 i = 0;
 while(state != STATE_EXIT)
 {
  channels[0] = symbol_copy(input_xlate_char(inp, alpha[i]));
  cortex_process(core, channels, num_channels, CORTEX_REQUEST_LEARN);
  state = process_events(&mr, &mc);
  switch (state)
  {
   case STATE_MOUSE_DOWN:
    irt = cortex_resolve(core, mr, mc);
    if (irt != ((void *)0))
    {
     for (j = 0; j < irt->num_inres; j++)
     {
      ires = inputrestable_input(irt, j);
      if (ires->active == TRUE)
      {
       for (k = 0; k < ires->num_time_steps; k++)
       {
        revc = input_decode_to_char(inp,
          ires->resolution[k], &revcerr);
        printf("For input %d, time step -%d: ", j, k);
        printf("char '%c' error %f\n", revc, revcerr);
       }
      }
     }
     inputrestable_destroy(irt);
    }
    break;
   case STATE_QUALITY:
    drawing_mode = SOM_STYLE_QUALITY;
    break;
   case STATE_ACTUAL:
    drawing_mode = SOM_STYLE_ACTUAL;
    break;
   default:
    ;
  }
  if (now > sample)
  {
   glClear(0x00004000 | 0x00000100);
   if (drawing_mode == SOM_STYLE_QUALITY)
   {
    cortex_draw(core, SOM_STYLE_QUALITY);
   }
   else if (drawing_mode == SOM_STYLE_ACTUAL)
   {
    cortex_draw(core, SOM_STYLE_ACTUAL);
   }
   SDL_GL_SwapBuffers();
   sample = now + incr;
   printf("Glyphs per second: %d\n", iter);
   iter = 0;
  }
  now = SDL_GetTicks();
  glerr = glGetError();
  if (glerr != 0)
  {
   printf("Opengl Error: %s\n", gluErrorString(glerr));
  }
  i++;
  if (!(i%strlen(alpha))) {
   i = 0;
  }
  iter++;
 }
 cortex_free(core);
 input_free(inp);
}

canonical_original_code:
void test_cortex_ascii(char *filename)
{
 struct Cortex_s *core = ((void *)0);
 int state = STATE_RUNNING;
 int sample; int now; int incr = 1000;
 int i; int j; int k;
 int mr; int mc;
 int drawing_mode = SOM_STYLE_ACTUAL;
 int glerr;
 int iter = 0;
 char revc;
 double revcerr;
 char *alpha = "I am very happy that my reverse lookup code seems to work. "
     "It really fills me with joy that after such a long and "
     "hard amount of work, everything finally seems to be "
     "working. Let us see if the vision processor works.";
 struct Input_s *inp;
 struct InputResTable_s *irt;
 struct InputResolution_s *ires;
 struct Symbol_s *channels[10];
 int num_channels = 1;
 inp = input_init(1);
 core = cortex_init(filename);
 now = SDL_GetTicks();
 sample = now + incr;
 i = 0;
 while(state != STATE_EXIT)
 {
  channels[0] = symbol_copy(input_xlate_char(inp, alpha[i]));
  cortex_process(core, channels, num_channels, CORTEX_REQUEST_LEARN);
  state = process_events(&mr, &mc);
  switch (state)
  {
   case STATE_MOUSE_DOWN:
    irt = cortex_resolve(core, mr, mc);
    if (irt != ((void *)0))
    {
     for (j = 0; j < irt->num_inres; j++)
     {
      ires = inputrestable_input(irt, j);
      if (ires->active == TRUE)
      {
       for (k = 0; k < ires->num_time_steps; k++)
       {
        revc = input_decode_to_char(inp,
          ires->resolution[k], &revcerr);
        printf("For input %d, time step -%d: ", j, k);
        printf("char '%c' error %f\n", revc, revcerr);
       }
      }
     }
     inputrestable_destroy(irt);
    }
    break;
   case STATE_QUALITY:
    drawing_mode = SOM_STYLE_QUALITY;
    break;
   case STATE_ACTUAL:
    drawing_mode = SOM_STYLE_ACTUAL;
    break;
   default:
    ;
  }
  if (now > sample)
  {
   glClear(0x00004000 | 0x00000100);
   if (drawing_mode == SOM_STYLE_QUALITY)
   {
    cortex_draw(core, SOM_STYLE_QUALITY);
   }
   else if (drawing_mode == SOM_STYLE_ACTUAL)
   {
    cortex_draw(core, SOM_STYLE_ACTUAL);
   }
   SDL_GL_SwapBuffers();
   sample = now + incr;
   printf("Glyphs per second: %d\n", iter);
   iter = 0;
  }
  now = SDL_GetTicks();
  glerr = glGetError();
  if (glerr != 0)
  {
   printf("Opengl Error: %s\n", gluErrorString(glerr));
  }
  i++;
  if (!(i%strlen(alpha))) {
   i = 0;
  }
  iter++;
 }
 cortex_free(core);
 input_free(inp);
}

variable_types:
filename
char *

variable_types: struct Cortex_s { int num_sec; struct Section_s { int serial_id; char *name; struct SOM_s { int mode; int bmu_row; struct SOMDesc_s { unsigned short dim; unsigned int train_iter; unsigned int rows; unsigned int cols; float (*radius_func)(struct SOM_s *s); } sd; int current_iter; float initial_radius; float half_life; struct Symbol_s { unsigned short dim; float vec[1]; } **neuron; float final_computation; float max_dist; float *qmap; } *som; int x; unsigned int mode; unsigned int state; struct Receptor_s { int num_slot; struct Slot_s { struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; } *iq; int parent; int parent_kind; } *slot; } receptor; struct Emitter_s { int num_con; struct Connection_s { int section_id; int slot; } *con; } emitter; struct SecDisp_s { int learn_row; } secdisp; } *sec; int num_input; struct CortexInput_s { int serial_id; char *name; int dim; struct Symbol_s *sym; struct Emitter_s emitter; } *input; int num_exec; int *exec; int num_outchan; struct CortexOutputChannel_s { int serial_id; char *name; } *outchan; int num_outmap; struct CortexOutputMapping_s { int sec_id; int ochan_id; } *outmap; struct ReverseTable_s { int num_roots; struct ObservationTable_s { int serial_id; int num_obs; struct Observation_s { int serial_id; int obs; } *ob; } *root; } rt; struct WaveTable_s { int num_sec; struct WaveFront_s { int serial_id; int active; int needed_observations; int num_observations; struct ViewPoint_s { int num_sym; struct Symbol_s **sym; struct ViewPoint_s *next; } *views; } *wfs; } wt; } *

variable_types: state int

variable_types: sample int

variable_types: now int

variable_types: incr int

variable_types: j int

variable_types: k int

variable_types: mr int

variable_types: mc int

variable_types: glerr int

variable_types: iter int

variable_types: revc char

variable_types: revcerr double

variable_types:
alpha
char *

variable_types: struct Input_s { int dim; int printable; struct XlateTable_s { char c; struct Symbol_s { unsigned short dim; float vec[1]; } *sym; } xlt[256]; } *

variable_types: struct InputResTable_s { int num_inres; struct InputResolution_s { int serial_id; int active; int num_time_steps; struct Symbol_s { unsigned short dim; float vec[1]; } **resolution; } *inres; } *

variable_types: struct Symbol_s { unsigned short dim; float vec[1]; } *[10]

user_defined_types: struct Cortex_s { int num_sec; struct Section_s *sec; int num_input; struct CortexInput_s *input; int num_exec; int *exec; int num_outchan; struct CortexOutputChannel_s *outchan; int num_outmap; struct CortexOutputMapping_s *outmap; struct ReverseTable_s rt; struct WaveTable_s wt; }

user_defined_types: struct Input_s { int dim; int printable; struct XlateTable_s xlt[256]; }

user_defined_types: struct InputResTable_s { int num_inres; struct InputResolution_s *inres; }

user_defined_types: struct InputResolution_s { int serial_id; int active; int num_time_steps; struct Symbol_s **resolution; }

user_defined_types: struct ReverseTable_s { int num_roots; struct ObservationTable_s *root; }

user_defined_types: struct WaveTable_s { int num_sec; struct WaveFront_s *wfs; }

user_defined_types: struct Section_s { int serial_id; char *name; struct SOM_s *som; int x; unsigned int mode; unsigned int state; struct Receptor_s receptor; struct Emitter_s emitter; struct SecDisp_s secdisp; }

user_defined_types: struct XlateTable_s { char c; struct Symbol_s *sym; }

user_defined_types: struct Receptor_s { int num_slot; struct Slot_s *slot; }

user_defined_types: struct Emitter_s { int num_con; struct Connection_s *con; }

user_defined_types: struct ObservationTable_s { int serial_id; int num_obs; struct Observation_s *ob; }

user_defined_types: struct WaveFront_s { int serial_id; int active; int needed_observations; int num_observations; struct ViewPoint_s *views; }

user_defined_types: struct SOM_s { int mode; int bmu_row; struct SOMDesc_s sd; int current_iter; float initial_radius; float half_life; struct Symbol_s **neuron; float final_computation; float max_dist; float *qmap; }

user_defined_types: struct Slot_s { struct IntQueue_s *iq; int parent; int parent_kind; }


decompiled_code:
__int64 test_vinput()
{
unsigned int v0; // ebp
__int64 v1; // r12
unsigned int i; // ebx

v0 = 0;
v1 = vinput_init(16LL, 16LL, 16LL, 16LL);
do
{
for ( i = 0; i != 16; ++i )
{
while ( !(unsigned int)vinput_glyph_bit(v1, 1LL, 4LL, v0, i) )
{
++i;
putchar(46);
if ( i == 16 )
goto LABEL_6;
}
putchar(35);
}
LABEL_6:
++v0;
putchar(10);
}
while ( v0 != 16 );
return vinput_destroy(v1);
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // ebp
__int64 v1; // r12
unsigned int i; // ebx

v0 = 0;
v1 = vinput_init(16LL, 16LL, 16LL, 16LL);
do
{
for ( i = 0; i != 16; ++i )
{
while ( !(unsigned int)vinput_glyph_bit(v1, 1LL, 4LL, v0, i) )
{
++i;
putchar(46);
if ( i == 16 )
goto LABEL_6;
}
putchar(35);
}
LABEL_6:
++v0;
putchar(10);
}
while ( v0 != 16 );
return vinput_destroy(v1);
}

original_code:
void test_vinput(void)
{
 VInput *vinp;
 int r, c;
 int bitval;
 vinp = vinput_init(16, 16, 16, 16);
 for (r = 0; r < 16; r++) {
  for (c = 0; c < 16; c++) {
   bitval = vinput_glyph_bit(vinp, 1, 4, r, c);
   if (bitval == 0) {
    printf(".");
   } else {
    printf("#");
   }
  }
  printf("\n");
 }
 vinput_destroy(vinp);
}

canonical_original_code:
void test_vinput()
{
 struct VInput_s *vinp;
 int r; int c;
 int bitval;
 vinp = vinput_init(16, 16, 16, 16);
 for (r = 0; r < 16; r++) {
  for (c = 0; c < 16; c++) {
   bitval = vinput_glyph_bit(vinp, 1, 4, r, c);
   if (bitval == 0) {
    printf(".");
   } else {
    printf("#");
   }
  }
  printf("\n");
 }
 vinput_destroy(vinp);
}

variable_types: struct VInput_s { int full_bit_rows; int full_bit_cols; int subimage_bit_rows; int subimage_bit_cols; int rows; int cols; unsigned char *bits; } *

variable_types: r int

variable_types: c int

variable_types: bitval int


decompiled_code:
__int64 __fastcall test_cortex_vision(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // r14
__int64 v3; // r15
int v4; // er12
void *v5; // rbp
__int64 v6; // r13
int v7; // eax
int v8; // ebp
unsigned int v9; // ebp
void *v10; // rbp
int v11; // eax
__int64 v12; // rax
unsigned int v13; // eax
const char *v14; // rax
__int64 v16; // r8
int v17; // [rsp+8h] [rbp-70h]
__int64 v18; // [rsp+8h] [rbp-70h]
unsigned int v19; // [rsp+10h] [rbp-68h]
unsigned int v20; // [rsp+14h] [rbp-64h]
__int64 v21; // [rsp+18h] [rbp-60h]
unsigned int v22; // [rsp+20h] [rbp-58h] BYREF
unsigned int v23; // [rsp+24h] [rbp-54h] BYREF
float v24; // [rsp+28h] [rbp-50h] BYREF
float v25; // [rsp+2Ch] [rbp-4Ch] BYREF
char v26[4]; // [rsp+30h] [rbp-48h] BYREF
char v27[4]; // [rsp+34h] [rbp-44h] BYREF
char v28[4]; // [rsp+38h] [rbp-40h] BYREF
char v29[60]; // [rsp+3Ch] [rbp-3Ch] BYREF

v1 = 0;
v2 = vinput_init(16LL, 16LL, 16LL, 16LL);
v3 = cortex_init(a1);
v19 = 0;
v4 = SDL_GetTicks();
v21 = 0LL;
v17 = v4 - 1;
v20 = 0;
do
{
while ( 1 )
{
v9 = v1;
v1 = (v1 + 1) % 0x90;
if ( v17 < v4 )
break;
v5 = (void *)vinput_glyph(v2, v9);
vinput_draw_glyph(v2, v5, 300LL, 300LL);
vinput_draw_glyph(v2, v5, 400LL, 300LL);
v6 = cortex_process(v3, v5, 16LL, 0LL);
free(v5);
v7 = process_events(&v22, &v23);
v8 = v7;
if ( v7 == 2 )
goto LABEL_25;
if ( v7 == 3 )
goto LABEL_22;
if ( v7 != 1 )
goto LABEL_5;
v20 = 1;
LABEL_6:
++v19;
if ( v6 )
goto LABEL_18;
v4 = SDL_GetTicks();
if ( v4 > v17 )
goto LABEL_19;
LABEL_8:
if ( v8 == 4 )
goto LABEL_21;
}
glClear(16640LL);
v10 = (void *)vinput_glyph(v2, v9);
vinput_draw_glyph(v2, v10, 300LL, 300LL);
vinput_draw_glyph(v2, v10, 400LL, 300LL);
v6 = cortex_process(v3, v10, 16LL, 0LL);
free(v10);
v11 = process_events(&v22, &v23);
v8 = v11;
switch ( v11 )
{
case 2:
LABEL_25:
v20 = 0;
v8 = 2;
break;
case 3:
LABEL_22:
printf("Clicked: %d, %d\n", v23, v22);
if ( v21 )
inputrestable_destroy(v21);
v8 = 3;
v21 = cortex_resolve(v3, v22, v23);
break;
case 1:
v20 = 1;
goto LABEL_14;
}
LABEL_5:
if ( v17 >= v4 )
goto LABEL_6;
LABEL_14:
cortex_draw(v3, v20);
if ( v21 )
vinput_draw_irt(v2, v21, 600LL, 300LL);
v12 = *(_QWORD *)(v6 + 16);
if ( *(_DWORD *)v12 == 1 )
{
symbol_get_6(*(_QWORD *)(v12 + 24), &v24, &v25, v26, v27, v28, v29);
v16 = cortex_resolve(v3, (unsigned int)(int)v24, (unsigned int)(int)v25);
if ( v16 )
{
v18 = v16;
vinput_draw_irt(v2, v16, 500LL, 300LL);
inputrestable_destroy(v18);
}
}
SDL_GL_SwapBuffers();
v17 = v4 + 1000;
printf("Glyphs per second: %d\n", v19);
v19 = 1;
LABEL_18:
cortex_output_table_free(v6);
v4 = SDL_GetTicks();
if ( v4 <= v17 )
goto LABEL_8;
LABEL_19:
v13 = glGetError();
if ( !v13 )
goto LABEL_8;
v14 = (const char *)gluErrorString(v13);
printf("Opengl Error: %s\n", v14);
}
while ( v8 != 4 );
LABEL_21:
cortex_free(v3);
return vinput_destroy(v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // r14
__int64 v3; // r15
int v4; // er12
void *v5; // rbp
__int64 v6; // r13
int v7; // eax
int v8; // ebp
unsigned int v9; // ebp
void *v10; // rbp
int v11; // eax
__int64 v12; // rax
unsigned int v13; // eax
const char *v14; // rax
__int64 v16; // r8
int v17; // [rsp+8h] [rbp-70h]
__int64 v18; // [rsp+8h] [rbp-70h]
unsigned int v19; // [rsp+10h] [rbp-68h]
unsigned int v20; // [rsp+14h] [rbp-64h]
__int64 v21; // [rsp+18h] [rbp-60h]
unsigned int v22; // [rsp+20h] [rbp-58h] BYREF
unsigned int v23; // [rsp+24h] [rbp-54h] BYREF
float v24; // [rsp+28h] [rbp-50h] BYREF
float v25; // [rsp+2Ch] [rbp-4Ch] BYREF
char v26[4]; // [rsp+30h] [rbp-48h] BYREF
char v27[4]; // [rsp+34h] [rbp-44h] BYREF
char v28[4]; // [rsp+38h] [rbp-40h] BYREF
char v29[60]; // [rsp+3Ch] [rbp-3Ch] BYREF

v1 = 0;
v2 = vinput_init(16LL, 16LL, 16LL, 16LL);
v3 = cortex_init(a1);
v19 = 0;
v4 = SDL_GetTicks();
v21 = 0LL;
v17 = v4 - 1;
v20 = 0;
do
{
while ( 1 )
{
v9 = v1;
v1 = (v1 + 1) % 0x90;
if ( v17 < v4 )
break;
v5 = (void *)vinput_glyph(v2, v9);
vinput_draw_glyph(v2, v5, 300LL, 300LL);
vinput_draw_glyph(v2, v5, 400LL, 300LL);
v6 = cortex_process(v3, v5, 16LL, 0LL);
free(v5);
v7 = func2(&v22, &v23);
v8 = v7;
if ( v7 == 2 )
goto LABEL_25;
if ( v7 == 3 )
goto LABEL_22;
if ( v7 != 1 )
goto LABEL_5;
v20 = 1;
LABEL_6:
++v19;
if ( v6 )
goto LABEL_18;
v4 = SDL_GetTicks();
if ( v4 > v17 )
goto LABEL_19;
LABEL_8:
if ( v8 == 4 )
goto LABEL_21;
}
glClear(16640LL);
v10 = (void *)vinput_glyph(v2, v9);
vinput_draw_glyph(v2, v10, 300LL, 300LL);
vinput_draw_glyph(v2, v10, 400LL, 300LL);
v6 = cortex_process(v3, v10, 16LL, 0LL);
free(v10);
v11 = func2(&v22, &v23);
v8 = v11;
switch ( v11 )
{
case 2:
LABEL_25:
v20 = 0;
v8 = 2;
break;
case 3:
LABEL_22:
printf("Clicked: %d, %d\n", v23, v22);
if ( v21 )
inputrestable_destroy(v21);
v8 = 3;
v21 = cortex_resolve(v3, v22, v23);
break;
case 1:
v20 = 1;
goto LABEL_14;
}
LABEL_5:
if ( v17 >= v4 )
goto LABEL_6;
LABEL_14:
cortex_draw(v3, v20);
if ( v21 )
vinput_draw_irt(v2, v21, 600LL, 300LL);
v12 = *(_QWORD *)(v6 + 16);
if ( *(_DWORD *)v12 == 1 )
{
symbol_get_6(*(_QWORD *)(v12 + 24), &v24, &v25, v26, v27, v28, v29);
v16 = cortex_resolve(v3, (unsigned int)(int)v24, (unsigned int)(int)v25);
if ( v16 )
{
v18 = v16;
vinput_draw_irt(v2, v16, 500LL, 300LL);
inputrestable_destroy(v18);
}
}
SDL_GL_SwapBuffers();
v17 = v4 + 1000;
printf("Glyphs per second: %d\n", v19);
v19 = 1;
LABEL_18:
cortex_output_table_free(v6);
v4 = SDL_GetTicks();
if ( v4 <= v17 )
goto LABEL_8;
LABEL_19:
v13 = glGetError();
if ( !v13 )
goto LABEL_8;
v14 = (const char *)gluErrorString(v13);
printf("Opengl Error: %s\n", v14);
}
while ( v8 != 4 );
LABEL_21:
cortex_free(v3);
return vinput_destroy(v2);
}

original_code:
void test_cortex_vision(char *filename)
{
 Cortex *core = ((void *)0);
 CortexOutputTable *ctxout = ((void *)0);
 int state = STATE_RUNNING;
 int sample, now, incr = 1000;
 int i;
 int mr, mc;
 int drawing_mode = SOM_STYLE_ACTUAL;
 int glerr;
 int iter = 0;
 int gindex;
 float ctx_row, ctx_col, row, col, n_row, n_col;
 VInput *vinp;
 InputResTable *irt = ((void *)0);
 InputResTable *self = ((void *)0);
 Symbol **channels;
 int num_channels = 16;
 vinp = vinput_init(16, 16, 16, 16);
 core = cortex_init(filename);
 now = SDL_GetTicks();
 sample = now - 1;
 i = 0;
 gindex = 0;
 while(state != STATE_EXIT)
 {
  if (now > sample)
  {
   glClear(0x00004000 | 0x00000100);
  }
  channels = vinput_glyph(vinp, gindex);
  gindex++;
  gindex %= 9 * 16;
  vinput_draw_glyph(vinp, channels, 300, 300);
  vinput_draw_glyph(vinp, channels, 400, 300);
  ctxout =
   cortex_process(core, channels, num_channels, CORTEX_REQUEST_LEARN);
  free(channels);
  state = process_events(&mr, &mc);
  switch (state)
  {
   case STATE_MOUSE_DOWN:
    printf("Clicked: %d, %d\n", mc, mr);
    if (irt != ((void *)0))
    {
     inputrestable_destroy(irt);
    }
    irt = cortex_resolve(core, mr, mc);
    break;
   case STATE_QUALITY:
    drawing_mode = SOM_STYLE_QUALITY;
    break;
   case STATE_ACTUAL:
    drawing_mode = SOM_STYLE_ACTUAL;
    break;
   default:
    ;
  }
  if (now > sample)
  {
   cortex_draw(core, drawing_mode);
   if (irt != ((void *)0))
   {
    vinput_draw_irt(vinp, irt, 600, 300);
   }
   if (ctxout->output[0].active == TRUE) {
    symbol_get_6(ctxout->output[0].osym,
     &ctx_row, &ctx_col, &row, &col, &n_row, &n_col);
    self = cortex_resolve(core, ctx_row, ctx_col);
    if (self != ((void *)0)) {
     vinput_draw_irt(vinp, self, 500, 300);
     inputrestable_destroy(self);
    }
   }
   SDL_GL_SwapBuffers();
   sample = now + incr;
   printf("Glyphs per second: %d\n", iter);
   iter = 0;
  }
  if (ctxout != ((void *)0)) {
   cortex_output_table_free(ctxout);
   ctxout = ((void *)0);
  }
  now = SDL_GetTicks();
  if (now > sample) {
   glerr = glGetError();
   if (glerr != 0)
   {
    printf("Opengl Error: %s\n", gluErrorString(glerr));
   }
  }
  iter++;
 }
 cortex_free(core);
 vinput_destroy(vinp);
}

canonical_original_code:
void test_cortex_vision(char *filename)
{
 struct Cortex_s *core = ((void *)0);
 struct CortexOutputTable_s *ctxout = ((void *)0);
 int state = STATE_RUNNING;
 int sample; int now; int incr = 1000;
 int i;
 int mr; int mc;
 int drawing_mode = SOM_STYLE_ACTUAL;
 int glerr;
 int iter = 0;
 int gindex;
 float ctx_row; float ctx_col; float row; float col; float n_row; float n_col;
 struct VInput_s *vinp;
 struct InputResTable_s *irt = ((void *)0);
 struct InputResTable_s *self = ((void *)0);
 struct Symbol_s **channels;
 int num_channels = 16;
 vinp = vinput_init(16, 16, 16, 16);
 core = cortex_init(filename);
 now = SDL_GetTicks();
 sample = now - 1;
 i = 0;
 gindex = 0;
 while(state != STATE_EXIT)
 {
  if (now > sample)
  {
   glClear(0x00004000 | 0x00000100);
  }
  channels = vinput_glyph(vinp, gindex);
  gindex++;
  gindex %= 9 * 16;
  vinput_draw_glyph(vinp, channels, 300, 300);
  vinput_draw_glyph(vinp, channels, 400, 300);
  ctxout =
   cortex_process(core, channels, num_channels, CORTEX_REQUEST_LEARN);
  free(channels);
  state = process_events(&mr, &mc);
  switch (state)
  {
   case STATE_MOUSE_DOWN:
    printf("Clicked: %d, %d\n", mc, mr);
    if (irt != ((void *)0))
    {
     inputrestable_destroy(irt);
    }
    irt = cortex_resolve(core, mr, mc);
    break;
   case STATE_QUALITY:
    drawing_mode = SOM_STYLE_QUALITY;
    break;
   case STATE_ACTUAL:
    drawing_mode = SOM_STYLE_ACTUAL;
    break;
   default:
    ;
  }
  if (now > sample)
  {
   cortex_draw(core, drawing_mode);
   if (irt != ((void *)0))
   {
    vinput_draw_irt(vinp, irt, 600, 300);
   }
   if (ctxout->output[0].active == TRUE) {
    symbol_get_6(ctxout->output[0].osym,
     &ctx_row, &ctx_col, &row, &col, &n_row, &n_col);
    self = cortex_resolve(core, ctx_row, ctx_col);
    if (self != ((void *)0)) {
     vinput_draw_irt(vinp, self, 500, 300);
     inputrestable_destroy(self);
    }
   }
   SDL_GL_SwapBuffers();
   sample = now + incr;
   printf("Glyphs per second: %d\n", iter);
   iter = 0;
  }
  if (ctxout != ((void *)0)) {
   cortex_output_table_free(ctxout);
   ctxout = ((void *)0);
  }
  now = SDL_GetTicks();
  if (now > sample) {
   glerr = glGetError();
   if (glerr != 0)
   {
    printf("Opengl Error: %s\n", gluErrorString(glerr));
   }
  }
  iter++;
 }
 cortex_free(core);
 vinput_destroy(vinp);
}

variable_types:
filename
char *

variable_types: struct Cortex_s { int num_sec; struct Section_s { int serial_id; char *name; struct SOM_s { int mode; int bmu_row; struct SOMDesc_s { unsigned short dim; unsigned int train_iter; unsigned int rows; unsigned int cols; float (*radius_func)(struct SOM_s *s); } sd; int current_iter; float initial_radius; float half_life; struct Symbol_s { unsigned short dim; float vec[1]; } **neuron; float final_computation; float max_dist; float *qmap; } *som; int x; unsigned int mode; unsigned int state; struct Receptor_s { int num_slot; struct Slot_s { struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; } *iq; int parent; int parent_kind; } *slot; } receptor; struct Emitter_s { int num_con; struct Connection_s { int section_id; int slot; } *con; } emitter; struct SecDisp_s { int learn_row; } secdisp; } *sec; int num_input; struct CortexInput_s { int serial_id; char *name; int dim; struct Symbol_s *sym; struct Emitter_s emitter; } *input; int num_exec; int *exec; int num_outchan; struct CortexOutputChannel_s { int serial_id; char *name; } *outchan; int num_outmap; struct CortexOutputMapping_s { int sec_id; int ochan_id; } *outmap; struct ReverseTable_s { int num_roots; struct ObservationTable_s { int serial_id; int num_obs; struct Observation_s { int serial_id; int obs; } *ob; } *root; } rt; struct WaveTable_s { int num_sec; struct WaveFront_s { int serial_id; int active; int needed_observations; int num_observations; struct ViewPoint_s { int num_sym; struct Symbol_s **sym; struct ViewPoint_s *next; } *views; } *wfs; } wt; } *

variable_types: struct CortexOutputTable_s { int request; int mode; int num_output; struct CortexOutput_s { int active; struct CortexOutputChannel_s { int serial_id; char *name; } ochan; struct Symbol_s { unsigned short dim; float vec[1]; } *osym; } *output; } *

variable_types: state int

variable_types: sample int

variable_types: now int

variable_types: incr int

variable_types: i int

variable_types: gindex int

variable_types: row float

variable_types: col float

user_defined_types: struct CortexOutputTable_s { int request; int mode; int num_output; struct CortexOutput_s *output; }

user_defined_types: struct VInput_s { int full_bit_rows; int full_bit_cols; int subimage_bit_rows; int subimage_bit_cols; int rows; int cols; unsigned char *bits; }

user_defined_types: struct CortexOutput_s { int active; struct CortexOutputChannel_s ochan; struct Symbol_s *osym; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi

setup_opengl_constprop_0(argc, argv, envp);
v3 = getpid();
srand48(v3);
test_turing_machine();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi

func0(argc, argv, envp);
v3 = getpid();
srand48(v3);
test_turing_machine();
exit(0);
}

original_code:
int main(int argc, char **argv)
{
 int width;
 int height;
 width = 960;
 height = 512;
 setup_opengl(width, height);
 srand48(getpid());
 test_turing_machine();
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: width int

variable_types: height int

return_type: int


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

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

original_code:
int slqline_get_slid(SLQline *slql)
{
 return slql->slid;
}

canonical_original_code:
int slqline_get_slid(struct SLQline_s *slql)
{
 return slql->slid;
}

variable_types: struct SLQline_s { int slid; int dim; int width; struct Symbol_s { unsigned short dim; float vec[1]; } **line; struct SLQline_s *next; } *

user_defined_types: struct SLQline_s { int slid; int dim; int width; struct Symbol_s **line; struct SLQline_s *next; }


decompiled_code:
__int64 __fastcall slqline_line(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
Symbol** slqline_line(SLQline *slql)
{
 return slql->line;
}

canonical_original_code:
struct Symbol_s **slqline_line(struct SLQline_s *slql)
{
 return slql->line;
}

variable_types: struct SLQline_s { int slid; int dim; int width; struct Symbol_s **line; struct SLQline_s *next; } *

return_type: struct Symbol_s { unsigned short dim; float vec[1]; } **


decompiled_code:
__int64 __fastcall slqline_get_width(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int slqline_get_width(SLQline *slql)
{
 return slql->width;
}

canonical_original_code:
int slqline_get_width(struct SLQline_s *slql)
{
 return slql->width;
}

user_defined_types: struct Symbol_s { unsigned short dim; float vec[1]; }


decompiled_code:
void __fastcall slqline_free(void *ptr)
{
_QWORD *v1; // r8
__int64 v2; // rbx

v1 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( *((int *)ptr + 2) > 0 )
{
v2 = 0LL;
do
{
if ( v1[v2] )
{
symbol_free();
v1 = (_QWORD *)*((_QWORD *)ptr + 2);
v1[v2] = 0LL;
}
++v2;
}
while ( *((_DWORD *)ptr + 2) > (int)v2 );
}
free(v1);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
_QWORD *v1; // r8
__int64 v2; // rbx

v1 = (_QWORD *)*((_QWORD *)ptr + 2);
if ( *((int *)ptr + 2) > 0 )
{
v2 = 0LL;
do
{
if ( v1[v2] )
{
symbol_free();
v1 = (_QWORD *)*((_QWORD *)ptr + 2);
v1[v2] = 0LL;
}
++v2;
}
while ( *((_DWORD *)ptr + 2) > (int)v2 );
}
free(v1);
free(ptr);
}

original_code:
void slqline_free(SLQline *slql)
{
 int i;
 for (i = 0; i < slql->width; i++)
 {
  if (slql->line[i] != ((void *)0))
  {
   symbol_free(slql->line[i]);
   slql->line[i] = ((void *)0);
  }
 }
 free(slql->line);
 slql->line = ((void *)0);
 slql->next = ((void *)0);
 free(slql);
}

canonical_original_code:
void slqline_free(struct SLQline_s *slql)
{
 int i;
 for (i = 0; i < slql->width; i++)
 {
  if (slql->line[i] != ((void *)0))
  {
   symbol_free(slql->line[i]);
   slql->line[i] = ((void *)0);
  }
 }
 free(slql->line);
 slql->line = ((void *)0);
 slql->next = ((void *)0);
 free(slql);
}


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

result = xmalloc(32LL);
*(_QWORD *)result = 0LL;
*(_DWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
return result;
}

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

result = xmalloc(32LL);
*(_QWORD *)result = 0LL;
*(_DWORD *)(result + 8) = a1;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
return result;
}

original_code:
SLQueue* slq_init(int span)
{
 SLQueue *slq = ((void *)0);
 slq = (SLQueue*)xmalloc(sizeof(SLQueue) * 1);
 slq->finished = FALSE;
 slq->count = 0;
 slq->span = span;
 slq->tail = ((void *)0);
 slq->head = ((void *)0);
 return slq;
}

canonical_original_code:
struct SLQueue_s *slq_init(int span)
{
 struct SLQueue_s *slq = ((void *)0);
 slq = (struct SLQueue_s *)xmalloc(sizeof(SLQueue) * 1);
 slq->finished = FALSE;
 slq->count = 0;
 slq->span = span;
 slq->tail = ((void *)0);
 slq->head = ((void *)0);
 return slq;
}

variable_types: span int

variable_types: struct SLQueue_s { int finished; int count; int span; struct SLQline_s { int slid; int dim; int width; struct Symbol_s { unsigned short dim; float vec[1]; } **line; struct SLQline_s *next; } *tail; struct SLQline_s *head; } *

user_defined_types: struct SLQueue_s { int finished; int count; int span; struct SLQline_s *tail; struct SLQline_s *head; }


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

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[3];
slqline_free(v3);
}
free(ptr);
}

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

v2 = (_QWORD *)*((_QWORD *)ptr + 2);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[3];
func3(v3);
}
free(ptr);
}

original_code:
void slq_free(SLQueue *slq)
{
 SLQline *curr;
 SLQline *deleted;
 curr = slq->tail;
 while(curr != ((void *)0))
 {
  deleted = curr;
  curr = curr->next;
  slqline_free(deleted);
 }
 slq->tail = ((void *)0);
 slq->head = ((void *)0);
 free(slq);
}

canonical_original_code:
void slq_free(struct SLQueue_s *slq)
{
 struct SLQline_s *curr;
 struct SLQline_s *deleted;
 curr = slq->tail;
 while(curr != ((void *)0))
 {
  deleted = curr;
  curr = curr->next;
  slqline_free(deleted);
 }
 slq->tail = ((void *)0);
 slq->head = ((void *)0);
 free(slq);
}


original_code:
void slq_enqueue(SLQueue *slq, SLQline *slql)
{
 if (slq->tail == ((void *)0))
 {
  slq->tail = slql;
  slq->head = slql;
 }
 else
 {
  slq->head->next = slql;
  slq->head = slql;
 }
 slq->count++;
}

canonical_original_code:
void slq_enqueue(struct SLQueue_s *slq, struct SLQline_s *slql)
{
 if (slq->tail == ((void *)0))
 {
  slq->tail = slql;
  slq->head = slql;
 }
 else
 {
  slq->head->next = slql;
  slq->head = slql;
 }
 slq->count++;
}

variable_types:
slql
struct SLQline_s *


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

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

original_code:
int slq_get_finished(SLQueue *slq)
{
 return slq->finished;
}

canonical_original_code:
int slq_get_finished(struct SLQueue_s *slq)
{
 return slq->finished;
}


decompiled_code:
_BOOL8 __fastcall slq_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

original_code:
int slq_empty(SLQueue *slq)
{
 if (slq->count == 0)
 {
  return TRUE;
 }
 return FALSE;
}

canonical_original_code:
int slq_empty(struct SLQueue_s *slq)
{
 if (slq->count == 0)
 {
  return TRUE;
 }
 return FALSE;
}


decompiled_code:
__int64 __fastcall slq_ready(unsigned int *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = slq_empty((__int64)a1);
result = 0LL;
if ( !v1 )
{
result = slq_get_finished(a1);
if ( (_DWORD)result != 1 )
result = (int)a1[1] > (int)a1[2];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = func9((__int64)a1);
result = 0LL;
if ( !v1 )
{
result = func8(a1);
if ( (_DWORD)result != 1 )
result = (int)a1[1] > (int)a1[2];
}
return result;
}

original_code:
int slq_ready(SLQueue *slq)
{
 if (slq_empty(slq) == TRUE)
 {
  return FALSE;
 }
 if (slq_get_finished(slq) == TRUE)
 {
  return TRUE;
 }
 if (slq->count > slq->span)
 {
  return TRUE;
 }
 return FALSE;
}

canonical_original_code:
int slq_ready(struct SLQueue_s *slq)
{
 if (slq_empty(slq) == TRUE)
 {
  return FALSE;
 }
 if (slq_get_finished(slq) == TRUE)
 {
  return TRUE;
 }
 if (slq->count > slq->span)
 {
  return TRUE;
 }
 return FALSE;
}


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

if ( !(unsigned int)slq_ready((unsigned int *)a1) )
return 0LL;
result = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(result + 24);
*(_QWORD *)(a1 + 16) = v2;
if ( !v2 )
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
--*(_DWORD *)(a1 + 4);
return result;
}

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

if ( !(unsigned int)func10((unsigned int *)a1) )
return 0LL;
result = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(result + 24);
*(_QWORD *)(a1 + 16) = v2;
if ( !v2 )
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
--*(_DWORD *)(a1 + 4);
return result;
}

original_code:
SLQline* slq_dequeue(SLQueue *slq)
{
 SLQline *slql;
 if (slq_ready(slq) == FALSE)
 {
  return ((void *)0);
 }
 slql = slq->tail;
 slq->tail = slq->tail->next;
 if (slq->tail == ((void *)0))
 {
  slq->head = ((void *)0);
 }
 slql->next = ((void *)0);
 slq->count--;
 return slql;
}

canonical_original_code:
struct SLQline_s *slq_dequeue(struct SLQueue_s *slq)
{
 struct SLQline_s *slql;
 if (slq_ready(slq) == FALSE)
 {
  return ((void *)0);
 }
 slql = slq->tail;
 slq->tail = slq->tail->next;
 if (slq->tail == ((void *)0))
 {
  slq->head = ((void *)0);
 }
 slql->next = ((void *)0);
 slq->count--;
 return slql;
}

variable_types: struct SLQueue_s { int finished; int count; int span; struct SLQline_s *tail; struct SLQline_s *head; } *

return_type: struct SLQline_s { int slid; int dim; int width; struct Symbol_s { unsigned short dim; float vec[1]; } **line; struct SLQline_s *next; } *


decompiled_code:
unsigned __int16 *__fastcall input_init(unsigned __int16 a1)
{
int v1; // er14
unsigned __int16 *v2; // rax
unsigned __int16 *v3; // r13
const unsigned __int16 **v4; // rax
const unsigned __int16 *v5; // rcx
const unsigned __int16 **v6; // r15
__int64 v7; // rsi
const unsigned __int16 *v8; // rax
__int64 v9; // rbx
int v10; // er12
int v11; // ebp
__int64 v12; // rax
float v13; // xmm0_4
float v14; // xmm0_4

v1 = 0;
v2 = (unsigned __int16 *)xmalloc(4104LL);
*(_DWORD *)v2 = a1;
v3 = v2;
*((_DWORD *)v2 + 1) = 0;
v4 = _ctype_b_loc();
v5 = *v4;
v6 = v4;
v7 = (__int64)(*v4 + 256);
v8 = *v4;
do
v1 -= ((*v8++ & 0x4000) == 0) - 1;
while ( v8 != (const unsigned __int16 *)v7 );
v9 = 0LL;
v10 = 0;
v11 = 0;
while ( 1 )
{
LOBYTE(v3[2 * v9 + 4]) = v11;
if ( (v5[v9] & 0x4000) != 0 )
break;
*(_QWORD *)&v3[2 * v9 + 8] = 0LL;
++v11;
++v9;
if ( v11 == 256 )
goto LABEL_8;
LABEL_5:
v5 = *v6;
}
++v11;
v12 = symbol_init(*v3);
v13 = (float)v10;
*(_QWORD *)&v3[2 * v9 + 8] = v12;
++v10;
++v9;
v14 = (v13 + 1.0) / (float)v1;
symbol_set_all(v12, v14);
++*((_DWORD *)v3 + 1);
if ( v11 != 256 )
goto LABEL_5;
LABEL_8:
printf("Initialized %d printable characters.\n", *((unsigned int *)v3 + 1));
return v3;
}

original_code:
Input* input_init(unsigned short dimension)
{
 int i;
 Input *inp;
 int sum;
 int count;
 inp = (Input*)xmalloc(sizeof(Input) * 1);
 inp->dim = dimension;
 inp->printable = 0;
 sum = 0;
 for(i = 0; i < 256; i++)
 {
  if (((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISprint))
  {
   sum++;
  }
 }
 count = 0;
 for(i = 0; i < 256; i++)
 {
  inp->xlt[i].c = i;
  if (((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISprint))
  {
   inp->xlt[i].sym = symbol_init(inp->dim);
   symbol_set_all(inp->xlt[i].sym,
    ((float)count+1.0) / (float)sum);
   inp->printable++;
   count++;
  }
  else
  {
   inp->xlt[i].sym = ((void *)0);
  }
 }
 printf("Initialized %d printable characters.\n", inp->printable);
 return inp;
}

canonical_original_code:
struct Input_s *input_init(unsigned short dimension)
{
 int i;
 struct Input_s *inp;
 int sum;
 int count;
 inp = (struct Input_s *)xmalloc(sizeof(Input) * 1);
 inp->dim = dimension;
 inp->printable = 0;
 sum = 0;
 for(i = 0; i < 256; i++)
 {
  if (((*__ctype_b_loc ())[(int) ((i))] & (unsigned short) _ISprint))
  {
   sum++;
  }
 }
 count = 0;
 for(i = 0; i < 256; i++)
 {
  inp->xlt[i].c = i;
  if (((*__ctype_b_loc ())[(int) ((i))] & (unsigned short) _ISprint))
  {
   inp->xlt[i].sym = symbol_init(inp->dim);
   symbol_set_all(inp->xlt[i].sym,
    ((float)count+1.0) / (float)sum);
   inp->printable++;
   count++;
  }
  else
  {
   inp->xlt[i].sym = ((void *)0);
  }
 }
 printf("Initialized %d printable characters.\n", inp->printable);
 return inp;
}

variable_types:
dimension
unsigned short

variable_types: struct Input_s { int dim; int printable; struct XlateTable_s { char c; struct Symbol_s { unsigned short dim; float vec[1]; } *sym; } xlt[256]; } *

variable_types: sum int

variable_types: count int

user_defined_types: struct Input_s { int dim; int printable; struct XlateTable_s xlt[256]; }


decompiled_code:
__int64 __fastcall input_random_choice(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rax
int v3; // edx
float v5; // [rsp+0h] [rbp-Ch]

v5 = (float)*(int *)(a1 + 4);
v1 = (unsigned int)(int)((float)((float)rand() * v5) * 4.656612873077393e-10);
if ( (int)v1 < 0 || *(_DWORD *)(a1 + 4) <= (int)v1 )
{
printf("input_random_choice(): What!?! Why isn't %d in the range of 0 to %d\n", v1, *(unsigned int *)(a1 + 4));
exit(1);
}
v2 = a1 + 16;
v3 = 0;
do
{
if ( *(_QWORD *)v2 )
{
if ( (_DWORD)v1 == v3 )
return *(_QWORD *)v2;
++v3;
}
v2 += 16LL;
}
while ( v2 != a1 + 4112 );
puts("input_random_choice(): never supposed to return NULL!");
fflush(0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rax
int v3; // edx
float v5; // [rsp+0h] [rbp-Ch]

v5 = (float)*(int *)(a1 + 4);
v1 = (unsigned int)(int)((float)((float)rand() * v5) * 4.656612873077393e-10);
if ( (int)v1 < 0 || *(_DWORD *)(a1 + 4) <= (int)v1 )
{
printf("input_random_choice(): What!?! Why isn't %d in the range of 0 to %d\n", v1, *(unsigned int *)(a1 + 4));
exit(1);
}
v2 = a1 + 16;
v3 = 0;
do
{
if ( *(_QWORD *)v2 )
{
if ( (_DWORD)v1 == v3 )
return *(_QWORD *)v2;
++v3;
}
v2 += 16LL;
}
while ( v2 != a1 + 4112 );
puts("input_random_choice(): never supposed to return NULL!");
fflush(0LL);
return 0LL;
}

original_code:
Symbol* input_random_choice(Input *inp)
{
 int i, count;
 int choice;
 choice = (int)(((float)inp->printable*rand())/(2147483647 +1.0));
 if (choice < 0 || choice >= inp->printable)
 {
  printf("input_random_choice(): What!?! Why isn't %d in the "
   "range of 0 to %d\n", choice, inp->printable);
  exit(1);
 }
 count = 0;
 for (i = 0; i < 256; i++)
 {
  if (inp->xlt[i].sym != ((void *)0) && count == choice)
  {
   return inp->xlt[i].sym;
  }
  if (inp->xlt[i].sym != ((void *)0))
  {
   count++;
  }
 }
 printf("input_random_choice(): never supposed to return NULL!\n");
 fflush(((void *)0));
 return ((void *)0);
}

canonical_original_code:
struct Symbol_s *input_random_choice(struct Input_s *inp)
{
 int i; int count;
 int choice;
 choice = (int)(((float)inp->printable*rand())/(2147483647 +1.0));
 if (choice < 0 || choice >= inp->printable)
 {
  printf("input_random_choice(): What!?! Why isn't %d in the "
   "range of 0 to %d\n", choice, inp->printable);
  exit(1);
 }
 count = 0;
 for (i = 0; i < 256; i++)
 {
  if (inp->xlt[i].sym != ((void *)0) && count == choice)
  {
   return inp->xlt[i].sym;
  }
  if (inp->xlt[i].sym != ((void *)0))
  {
   count++;
  }
 }
 printf("input_random_choice(): never supposed to return NULL!\n");
 fflush(((void *)0));
 return ((void *)0);
}

variable_types: struct Input_s { int dim; int printable; struct XlateTable_s { char c; struct Symbol_s *sym; } xlt[256]; } *

variable_types: i int

variable_types: choice int

return_type: struct Symbol_s { unsigned short dim; float vec[1]; } *


decompiled_code:
__int64 __fastcall input_random_choice_special(__int64 a1, int a2)
{
__int64 v3; // rsi

if ( a2 > 25 )
{
puts("input_random_choice_special(): num must be less than 26!");
exit(1);
}
v3 = (unsigned int)(int)((float)((float)a2 * (float)rand()) * 4.656612873077393e-10);
if ( (int)v3 < 0 || a2 <= (int)v3 )
{
printf("input_random_choice(): What!?! Why isn't %d in the range of 0 to %d\n", v3, (unsigned int)a2);
exit(1);
}
return *(_QWORD *)(a1 + 16LL * ((int)v3 + 97) + 16);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v3; // rsi

if ( a2 > 25 )
{
puts("input_random_choice_special(): num must be less than 26!");
exit(1);
}
v3 = (unsigned int)(int)((float)((float)a2 * (float)rand()) * 4.656612873077393e-10);
if ( (int)v3 < 0 || a2 <= (int)v3 )
{
printf("input_random_choice(): What!?! Why isn't %d in the range of 0 to %d\n", v3, (unsigned int)a2);
exit(1);
}
return *(_QWORD *)(a1 + 16LL * ((int)v3 + 97) + 16);
}

original_code:
Symbol* input_random_choice_special(Input *inp, int num)
{
 int choice;
 if (num >= 26)
 {
  printf("input_random_choice_special(): num must be less than 26!\n");
  exit(1);
 }
 choice = (int)(((float)num*rand())/(2147483647 +1.0));
 if (choice < 0 || choice >= num)
 {
  printf("input_random_choice(): What!?! Why isn't %d in the "
   "range of 0 to %d\n", choice, num);
  exit(1);
 }
 return inp->xlt[((int)'a') + choice].sym;
}

canonical_original_code:
struct Symbol_s *input_random_choice_special(struct Input_s *inp, int num)
{
 int choice;
 if (num >= 26)
 {
  printf("input_random_choice_special(): num must be less than 26!\n");
  exit(1);
 }
 choice = (int)(((float)num*rand())/(2147483647 +1.0));
 if (choice < 0 || choice >= num)
 {
  printf("input_random_choice(): What!?! Why isn't %d in the "
   "range of 0 to %d\n", choice, num);
  exit(1);
 }
 return inp->xlt[((int)'a') + choice].sym;
}

variable_types: num int


decompiled_code:
__int64 __fastcall input_xlate_char(__int64 a1, char a2)
{
__int64 result; // rax

result = *(_QWORD *)(16LL * a2 + a1 + 16);
if ( !result )
{
printf("input_xlate_char(): passed a nonprintable character: %c!\n", (unsigned int)a2);
exit(1);
}
return result;
}

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

result = *(_QWORD *)(16LL * a2 + a1 + 16);
if ( !result )
{
printf("input_xlate_char(): passed a nonprintable character: %c!\n", (unsigned int)a2);
exit(1);
}
return result;
}

original_code:
Symbol* input_xlate_char(Input *inp, char c)
{
 if (inp->xlt[(int)c].sym == ((void *)0))
 {
  printf("input_xlate_char(): passed a nonprintable character: %c!\n", c);
  exit(1);
 }
 return inp->xlt[(int)c].sym;
}

canonical_original_code:
struct Symbol_s *input_xlate_char(struct Input_s *inp, char c)
{
 if (inp->xlt[(int)c].sym == ((void *)0))
 {
  printf("input_xlate_char(): passed a nonprintable character: %c!\n", c);
  exit(1);
 }
 return inp->xlt[(int)c].sym;
}

variable_types: c char


original_code:
Symbol* input_decode_to_sym(Input *inp, Symbol *unk, double *error)
{
 double min_dist = 99999, max_dist = 0;
 double dist;
 int i;
 int loc = 0;
 for (i = 0; i < 256; i++)
 {
  if (inp->xlt[i].sym != ((void *)0))
  {
   dist = symbol_dist(unk, inp->xlt[i].sym);
   if (dist < min_dist)
   {
    min_dist = dist;
    loc = i;
   }
   if (dist > max_dist)
   {
    max_dist = dist;
   }
  }
 }
 *error = 1.0 - ((max_dist - min_dist) / max_dist);
 return inp->xlt[loc].sym;
}

canonical_original_code:
struct Symbol_s *input_decode_to_sym(struct Input_s *inp, struct Symbol_s *unk, double *error)
{
 double min_dist = 99999; double max_dist = 0;
 double dist;
 int i;
 int loc = 0;
 for (i = 0; i < 256; i++)
 {
  if (inp->xlt[i].sym != ((void *)0))
  {
   dist = symbol_dist(unk, inp->xlt[i].sym);
   if (dist < min_dist)
   {
    min_dist = dist;
    loc = i;
   }
   if (dist > max_dist)
   {
    max_dist = dist;
   }
  }
 }
 *error = 1.0 - ((max_dist - min_dist) / max_dist);
 return inp->xlt[loc].sym;
}

variable_types:
unk
struct Symbol_s *

variable_types:
error
double *

variable_types: dist double

variable_types: loc int


original_code:
char input_decode_to_char(Input *inp, Symbol *unk, double *error)
{
 double min_dist = 99999, max_dist = 0;
 double dist;
 int i;
 int loc = 0;
 for (i = 0; i < 256; i++)
 {
  if (inp->xlt[i].sym != ((void *)0))
  {
   dist = symbol_dist(unk, inp->xlt[i].sym);
   if (dist < min_dist)
   {
    min_dist = dist;
    loc = i;
   }
   if (dist > max_dist)
   {
    max_dist = dist;
   }
  }
 }
 *error = 1.0 - ((max_dist - min_dist) / max_dist);
 return inp->xlt[loc].c;
}

canonical_original_code:
char input_decode_to_char(struct Input_s *inp, struct Symbol_s *unk, double *error)
{
 double min_dist = 99999; double max_dist = 0;
 double dist;
 int i;
 int loc = 0;
 for (i = 0; i < 256; i++)
 {
  if (inp->xlt[i].sym != ((void *)0))
  {
   dist = symbol_dist(unk, inp->xlt[i].sym);
   if (dist < min_dist)
   {
    min_dist = dist;
    loc = i;
   }
   if (dist > max_dist)
   {
    max_dist = dist;
   }
  }
 }
 *error = 1.0 - ((max_dist - min_dist) / max_dist);
 return inp->xlt[loc].c;
}

return_type: char


decompiled_code:
void __fastcall input_free(void *ptr)
{
_QWORD *v1; // rbx

v1 = (char *)ptr + 16;
do
{
if ( *v1 )
symbol_free();
v1 += 2;
}
while ( v1 != (_QWORD *)((char *)ptr + 4112) );
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
_QWORD *v1; // rbx

v1 = (char *)ptr + 16;
do
{
if ( *v1 )
symbol_free();
v1 += 2;
}
while ( v1 != (_QWORD *)((char *)ptr + 4112) );
free(ptr);
}

original_code:
void input_free(Input *inp)
{
 int i;
 for(i = 0; i < 256; i++)
 {
  if (inp->xlt[i].sym != ((void *)0))
  {
   symbol_free(inp->xlt[i].sym);
  }
 }
 free(inp);
}

canonical_original_code:
void input_free(struct Input_s *inp)
{
 int i;
 for(i = 0; i < 256; i++)
 {
  if (inp->xlt[i].sym != ((void *)0))
  {
   symbol_free(inp->xlt[i].sym);
  }
 }
 free(inp);
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
puts("Out of memory!");
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
puts("Out of memory!");
exit(1);
}
return result;
}

original_code:
void* xmalloc(unsigned long size)
{
 void *space;
 space = malloc(size);
 if (space == ((void *)0))
 {
  printf("Out of memory!\n");
  exit(1);
 }
 return space;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
 void *space;
 space = malloc(size);
 if (space == ((void *)0))
 {
  printf("Out of memory!\n");
  exit(1);
 }
 return space;
}

variable_types:
size
unsigned long

variable_types:
space
void *

return_type: void *


readn

decompiled_code:
size_t __fastcall readn(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = nbytes;
v5 = nbytes;
if ( nbytes )
{
while ( 1 )
{
while ( 1 )
{
v6 = read(fd, buf, v5);
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

canonical_decompiled_code:
size_t __fastcall func1(int fd, void *buf, size_t nbytes)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = nbytes;
v5 = nbytes;
if ( nbytes )
{
while ( 1 )
{
while ( 1 )
{
v6 = read(fd, buf, v5);
if ( v6 >= 0 )
break;
if ( *_errno_location() != 4 )
return -1LL;
}
if ( !v6 )
break;
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3;
}
v3 -= v5;
}
return v3;
}

original_code:
ssize_t readn(int fd, void *vptr, size_t n)
{
 size_t nleft;
 ssize_t nread;
 char *ptr = ((void *)0);
 ptr = vptr;
 nleft = n;
 while (nleft > 0) {
  if ((nread = read(fd, ptr, nleft)) < 0) {
   if ((*__errno_location ()) == 4) {
    nread = 0;
   } else {
    return -1;
   }
  } else if (nread == 0) {
   break;
  }
  nleft -= nread;
  ptr += nread;
 }
 return n - nleft;
}

canonical_original_code:
long readn(int fd, void *vptr, unsigned long n)
{
 unsigned long nleft;
 long nread;
 char *ptr = ((void *)0);
 ptr = vptr;
 nleft = n;
 while (nleft > 0) {
  if ((nread = read(fd, ptr, nleft)) < 0) {
   if ((*__errno_location ()) == 4) {
    nread = 0;
   } else {
    return -1;
   }
  } else if (nread == 0) {
   break;
  }
  nleft -= nread;
  ptr += nread;
 }
 return n - nleft;
}

variable_types: fd int

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nread long

variable_types:
ptr
char *

return_type: long


original_code:
Conv* conv_init(int style, double param)
{
 int i, j;
 Conv *c = ((void *)0);
 c = (Conv*)xmalloc(sizeof(Conv) * 1);
 switch(style)
 {
  case CONV_BLUR_SMEAR:
   c->desc = "All Edge Sensitive";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double*)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   for (i = 0; i < c->rows; i++)
   {
    for (j = 0; j < c->cols; j++)
    {
     c->coef[(((i) * ((c)->cols)) + (j))] = param;
    }
   }
   c->coef[(((c->rows / 2) * ((c)->cols)) + (c->cols / 2))] = 1;
   break;
  case CONV_BLUR_LIGHT:
   c->desc = "Simple Blur";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double*)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   c->coef[(((0) * ((c)->cols)) + (0))] = param / sqrt(2.0);
   c->coef[(((0) * ((c)->cols)) + (1))] = param;
   c->coef[(((0) * ((c)->cols)) + (2))] = param / sqrt(2.0);
   c->coef[(((1) * ((c)->cols)) + (0))] = param;
   c->coef[(((1) * ((c)->cols)) + (1))] = param;
   c->coef[(((1) * ((c)->cols)) + (2))] = param;
   c->coef[(((2) * ((c)->cols)) + (0))] = param / sqrt(2.0);
   c->coef[(((2) * ((c)->cols)) + (1))] = param;
   c->coef[(((2) * ((c)->cols)) + (2))] = param / sqrt(2.0);
   break;
  case CONV_ENHANCED_DETAIL:
   c->desc = "Enhanced Detail";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double*)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   c->coef[(((0) * ((c)->cols)) + (0))] = 0;
   c->coef[(((0) * ((c)->cols)) + (1))] = -1;
   c->coef[(((0) * ((c)->cols)) + (2))] = 0;
   c->coef[(((1) * ((c)->cols)) + (0))] = -1;
   c->coef[(((1) * ((c)->cols)) + (1))] = param;
   c->coef[(((1) * ((c)->cols)) + (2))] = -1;
   c->coef[(((2) * ((c)->cols)) + (0))] = 0;
   c->coef[(((2) * ((c)->cols)) + (1))] = -1;
   c->coef[(((2) * ((c)->cols)) + (2))] = 0;
   break;
  case CONV_SOFTEN:
   c->desc = "Soften";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double*)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   c->coef[(((0) * ((c)->cols)) + (0))] = param;
   c->coef[(((0) * ((c)->cols)) + (1))] = param;
   c->coef[(((0) * ((c)->cols)) + (2))] = param;
   c->coef[(((1) * ((c)->cols)) + (0))] = param;
   c->coef[(((1) * ((c)->cols)) + (1))] = param;
   c->coef[(((1) * ((c)->cols)) + (2))] = param;
   c->coef[(((2) * ((c)->cols)) + (0))] = param;
   c->coef[(((2) * ((c)->cols)) + (1))] = param;
   c->coef[(((2) * ((c)->cols)) + (2))] = param;
   break;
  case CONV_LAPLACIAN:
   c->desc = "Laplacian";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double*)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   c->coef[(((0) * ((c)->cols)) + (0))] = -1;
   c->coef[(((0) * ((c)->cols)) + (1))] = -1;
   c->coef[(((0) * ((c)->cols)) + (2))] = -1;
   c->coef[(((1) * ((c)->cols)) + (0))] = -1;
   c->coef[(((1) * ((c)->cols)) + (1))] = param;
   c->coef[(((1) * ((c)->cols)) + (2))] = -1;
   c->coef[(((2) * ((c)->cols)) + (0))] = -1;
   c->coef[(((2) * ((c)->cols)) + (1))] = -1;
   c->coef[(((2) * ((c)->cols)) + (2))] = -1;
   break;
  case CONV_USER_DEF:
   c->desc = "User Defined";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double*)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   c->coef[(((0) * ((c)->cols)) + (0))] = 0;
   c->coef[(((0) * ((c)->cols)) + (1))] = 0;
   c->coef[(((0) * ((c)->cols)) + (2))] = 0;
   c->coef[(((1) * ((c)->cols)) + (0))] = 0;
   c->coef[(((1) * ((c)->cols)) + (1))] = 1;
   c->coef[(((1) * ((c)->cols)) + (2))] = 0;
   c->coef[(((2) * ((c)->cols)) + (0))] = 0;
   c->coef[(((2) * ((c)->cols)) + (1))] = 0;
   c->coef[(((2) * ((c)->cols)) + (2))] = 0;
   break;
  default:
   printf("convolution_init(): Unknown convolution style!\n");
   exit(1);
   break;
 };
 return c;
}

canonical_original_code:
struct Conv_s *conv_init(int style, double param)
{
 int i; int j;
 struct Conv_s *c = ((void *)0);
 c = (struct Conv_s *)xmalloc(sizeof(Conv) * 1);
 switch(style)
 {
  case CONV_BLUR_SMEAR:
   c->desc = "All Edge Sensitive";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double *)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   for (i = 0; i < c->rows; i++)
   {
    for (j = 0; j < c->cols; j++)
    {
     c->coef[(((i) * ((c)->cols)) + (j))] = param;
    }
   }
   c->coef[(((c->rows / 2) * ((c)->cols)) + (c->cols / 2))] = 1;
   break;
  case CONV_BLUR_LIGHT:
   c->desc = "Simple Blur";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double *)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   c->coef[(((0) * ((c)->cols)) + (0))] = param / sqrt(2.0);
   c->coef[(((0) * ((c)->cols)) + (1))] = param;
   c->coef[(((0) * ((c)->cols)) + (2))] = param / sqrt(2.0);
   c->coef[(((1) * ((c)->cols)) + (0))] = param;
   c->coef[(((1) * ((c)->cols)) + (1))] = param;
   c->coef[(((1) * ((c)->cols)) + (2))] = param;
   c->coef[(((2) * ((c)->cols)) + (0))] = param / sqrt(2.0);
   c->coef[(((2) * ((c)->cols)) + (1))] = param;
   c->coef[(((2) * ((c)->cols)) + (2))] = param / sqrt(2.0);
   break;
  case CONV_ENHANCED_DETAIL:
   c->desc = "Enhanced Detail";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double *)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   c->coef[(((0) * ((c)->cols)) + (0))] = 0;
   c->coef[(((0) * ((c)->cols)) + (1))] = -1;
   c->coef[(((0) * ((c)->cols)) + (2))] = 0;
   c->coef[(((1) * ((c)->cols)) + (0))] = -1;
   c->coef[(((1) * ((c)->cols)) + (1))] = param;
   c->coef[(((1) * ((c)->cols)) + (2))] = -1;
   c->coef[(((2) * ((c)->cols)) + (0))] = 0;
   c->coef[(((2) * ((c)->cols)) + (1))] = -1;
   c->coef[(((2) * ((c)->cols)) + (2))] = 0;
   break;
  case CONV_SOFTEN:
   c->desc = "Soften";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double *)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   c->coef[(((0) * ((c)->cols)) + (0))] = param;
   c->coef[(((0) * ((c)->cols)) + (1))] = param;
   c->coef[(((0) * ((c)->cols)) + (2))] = param;
   c->coef[(((1) * ((c)->cols)) + (0))] = param;
   c->coef[(((1) * ((c)->cols)) + (1))] = param;
   c->coef[(((1) * ((c)->cols)) + (2))] = param;
   c->coef[(((2) * ((c)->cols)) + (0))] = param;
   c->coef[(((2) * ((c)->cols)) + (1))] = param;
   c->coef[(((2) * ((c)->cols)) + (2))] = param;
   break;
  case CONV_LAPLACIAN:
   c->desc = "Laplacian";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double *)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   c->coef[(((0) * ((c)->cols)) + (0))] = -1;
   c->coef[(((0) * ((c)->cols)) + (1))] = -1;
   c->coef[(((0) * ((c)->cols)) + (2))] = -1;
   c->coef[(((1) * ((c)->cols)) + (0))] = -1;
   c->coef[(((1) * ((c)->cols)) + (1))] = param;
   c->coef[(((1) * ((c)->cols)) + (2))] = -1;
   c->coef[(((2) * ((c)->cols)) + (0))] = -1;
   c->coef[(((2) * ((c)->cols)) + (1))] = -1;
   c->coef[(((2) * ((c)->cols)) + (2))] = -1;
   break;
  case CONV_USER_DEF:
   c->desc = "User Defined";
   c->type = style;
   c->rows = 3;
   c->cols = 3;
   c->coef = (double *)xmalloc(sizeof(double) *
       (c->rows*c->cols));
   c->coef[(((0) * ((c)->cols)) + (0))] = 0;
   c->coef[(((0) * ((c)->cols)) + (1))] = 0;
   c->coef[(((0) * ((c)->cols)) + (2))] = 0;
   c->coef[(((1) * ((c)->cols)) + (0))] = 0;
   c->coef[(((1) * ((c)->cols)) + (1))] = 1;
   c->coef[(((1) * ((c)->cols)) + (2))] = 0;
   c->coef[(((2) * ((c)->cols)) + (0))] = 0;
   c->coef[(((2) * ((c)->cols)) + (1))] = 0;
   c->coef[(((2) * ((c)->cols)) + (2))] = 0;
   break;
  default:
   printf("convolution_init(): Unknown convolution style!\n");
   exit(1);
   break;
 };
 return c;
}

variable_types: style int

variable_types: param double

variable_types: j int

variable_types: struct Conv_s { char *desc; int type; int rows; double *coef; } *


decompiled_code:
void __fastcall conv_free(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void conv_free(Conv *c)
{
 free(c->coef);
 free(c);
}

canonical_original_code:
void conv_free(struct Conv_s *c)
{
 free(c->coef);
 free(c);
}

user_defined_types: struct Conv_s { char *desc; int type; int rows; double *coef; }


decompiled_code:
double __fastcall conv_get_rows(__int64 a1)
{
return (double)*(int *)(a1 + 12);
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1)
{
return (double)*(int *)(a1 + 12);
}

original_code:
double conv_get_rows(Conv *c)
{
 return c->rows;
}

canonical_original_code:
double conv_get_rows(struct Conv_s *c)
{
 return c->rows;
}

return_type: double


decompiled_code:
double __fastcall conv_get_cols(__int64 a1)
{
return (double)*(int *)(a1 + 16);
}

canonical_decompiled_code:
double __fastcall func3(__int64 a1)
{
return (double)*(int *)(a1 + 16);
}

original_code:
double conv_get_cols(Conv *c)
{
 return c->cols;
}

canonical_original_code:
double conv_get_cols(struct Conv_s *c)
{
 return c->cols;
}


decompiled_code:
double __fastcall conv_get_coef(int a1, int a2, __int64 a3)
{
return *(double *)(*(_QWORD *)(a3 + 24) + 8LL * (a2 + *(_DWORD *)(a3 + 16) * a1));
}

canonical_decompiled_code:
double __fastcall func4(int a1, int a2, __int64 a3)
{
return *(double *)(*(_QWORD *)(a3 + 24) + 8LL * (a2 + *(_DWORD *)(a3 + 16) * a1));
}

original_code:
double conv_get_coef(int row, int col, Conv *c)
{
 return c->coef[(((row) * ((c)->cols)) + (col))];
}

canonical_original_code:
double conv_get_coef(int row, int col, struct Conv_s *c)
{
 return c->coef[(((row) * ((c)->cols)) + (col))];
}

variable_types: row int

variable_types: col int


decompiled_code:
__int64 __fastcall conv_set_coef(int a1, int a2, __int64 a3, double a4)
{
__int64 result; // rax

result = *(_QWORD *)(a3 + 24);
*(double *)(result + 8LL * (a2 + *(_DWORD *)(a3 + 16) * a1)) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2, __int64 a3, double a4)
{
__int64 result; // rax

result = *(_QWORD *)(a3 + 24);
*(double *)(result + 8LL * (a2 + *(_DWORD *)(a3 + 16) * a1)) = a4;
return result;
}

original_code:
void conv_set_coef(int row, int col, Conv *c, double param)
{
 c->coef[(((row) * ((c)->cols)) + (col))] = param;
}

canonical_original_code:
void conv_set_coef(int row, int col, struct Conv_s *c, double param)
{
 c->coef[(((row) * ((c)->cols)) + (col))] = param;
}


original_code:
void conv_apply(SOM *s, Conv *c, double thld)
{
 int row, col;
 Symbol *sum;
 Symbol *mul;
 Symbol *candidate;
 double divisor;
 SLQueue *slq;
 SLQline *slql;
 Symbol **data;
 int i;
 int slid;
 int xrow, xcol;
 int cr, cc;
 double coef;
 double dist;
 slq = slq_init(((int)(conv_get_rows(c) / 2.0)) + 1);
 sum = symbol_init(s->sd.dim);
 mul = symbol_init(s->sd.dim);
 for(row = 0; row < s->sd.rows; row++)
 {
  slql = slqline_init(row, s->sd.cols, s->sd.dim);
  data = slqline_line(slql);
  for (col = 0; col < s->sd.cols; col++)
  {
   symbol_one(mul);
   divisor = 0;
   symbol_zero(sum);
   for (cr = 0; cr < conv_get_rows(c); cr++)
   {
    for (cc = 0; cc < conv_get_cols(c); cc++)
    {
     xrow = row - (int)(conv_get_rows(c) / 2) + cr;
     xcol = col - (int)(conv_get_cols(c) / 2) + cc;
     if ((xrow >= 0 && xrow < s->sd.rows) &&
      (xcol >= 0 && xcol < s->sd.cols))
     {
      dist = symbol_dist(
       som_symbol_ref(s, row, col),
       som_symbol_ref(s, xrow, xcol));
      if (dist <= thld)
      {
       coef = conv_get_coef(cr, cc, c);
       symbol_move(mul, som_symbol_ref(s, xrow, xcol));
       symbol_mul(mul, coef);
       symbol_add(sum, sum, mul);
       divisor += coef;
      }
     }
    }
   }
   if ( !(fabs(divisor) < (1e-13)) )
   {
    symbol_div(sum, divisor);
   }
   symbol_move(data[col], sum);
  }
  slq_enqueue(slq, slql);
  slql = ((void *)0);
  data = ((void *)0);
  while(slq_ready(slq) == TRUE)
  {
   slql = slq_dequeue(slq);
   if (slql == ((void *)0))
   {
    printf("slql shouldn't be null here!\n");
    exit(1);
   }
   data = slqline_line(slql);
   slid = slqline_get_slid(slql);
   for (i = 0; i < slqline_get_width(slql); i++)
   {
    candidate = som_symbol_ref(s, slid, i);
    symbol_move(candidate, data[i]);
   }
   slqline_free(slql);
   slql = ((void *)0);
  }
 }
 slq_set_finished(slq, TRUE);
 while(slq_ready(slq) == TRUE)
 {
  slql = slq_dequeue(slq);
  if (slql == ((void *)0))
  {
   printf("slql shouldn't be null here either!\n");
   exit(1);
  }
  data = slqline_line(slql);
  slid = slqline_get_slid(slql);
  for (i = 0; i < slqline_get_width(slql); i++)
  {
   candidate = som_symbol_ref(s, slid, i);
   symbol_move(candidate, data[i]);
  }
  slqline_free(slql);
  slql = ((void *)0);
 }
 slq_free(slq);
 symbol_free(sum);
 symbol_free(mul);
}

canonical_original_code:
void conv_apply(struct SOM_s *s, struct Conv_s *c, double thld)
{
 int row; int col;
 struct Symbol_s *sum;
 struct Symbol_s *mul;
 struct Symbol_s *candidate;
 double divisor;
 struct SLQueue_s *slq;
 struct SLQline_s *slql;
 struct Symbol_s **data;
 int i;
 int slid;
 int xrow; int xcol;
 int cr; int cc;
 double coef;
 double dist;
 slq = slq_init(((int)(conv_get_rows(c) / 2.0)) + 1);
 sum = symbol_init(s->sd.dim);
 mul = symbol_init(s->sd.dim);
 for(row = 0; row < s->sd.rows; row++)
 {
  slql = slqline_init(row, s->sd.cols, s->sd.dim);
  data = slqline_line(slql);
  for (col = 0; col < s->sd.cols; col++)
  {
   symbol_one(mul);
   divisor = 0;
   symbol_zero(sum);
   for (cr = 0; cr < conv_get_rows(c); cr++)
   {
    for (cc = 0; cc < conv_get_cols(c); cc++)
    {
     xrow = row - (int)(conv_get_rows(c) / 2) + cr;
     xcol = col - (int)(conv_get_cols(c) / 2) + cc;
     if ((xrow >= 0 && xrow < s->sd.rows) &&
      (xcol >= 0 && xcol < s->sd.cols))
     {
      dist = symbol_dist(
       som_symbol_ref(s, row, col),
       som_symbol_ref(s, xrow, xcol));
      if (dist <= thld)
      {
       coef = conv_get_coef(cr, cc, c);
       symbol_move(mul, som_symbol_ref(s, xrow, xcol));
       symbol_mul(mul, coef);
       symbol_add(sum, sum, mul);
       divisor += coef;
      }
     }
    }
   }
   if ( !(fabs(divisor) < (1e-13)) )
   {
    symbol_div(sum, divisor);
   }
   symbol_move(data[col], sum);
  }
  slq_enqueue(slq, slql);
  slql = ((void *)0);
  data = ((void *)0);
  while(slq_ready(slq) == TRUE)
  {
   slql = slq_dequeue(slq);
   if (slql == ((void *)0))
   {
    printf("slql shouldn't be null here!\n");
    exit(1);
   }
   data = slqline_line(slql);
   slid = slqline_get_slid(slql);
   for (i = 0; i < slqline_get_width(slql); i++)
   {
    candidate = som_symbol_ref(s, slid, i);
    symbol_move(candidate, data[i]);
   }
   slqline_free(slql);
   slql = ((void *)0);
  }
 }
 slq_set_finished(slq, TRUE);
 while(slq_ready(slq) == TRUE)
 {
  slql = slq_dequeue(slq);
  if (slql == ((void *)0))
  {
   printf("slql shouldn't be null here either!\n");
   exit(1);
  }
  data = slqline_line(slql);
  slid = slqline_get_slid(slql);
  for (i = 0; i < slqline_get_width(slql); i++)
  {
   candidate = som_symbol_ref(s, slid, i);
   symbol_move(candidate, data[i]);
  }
  slqline_free(slql);
  slql = ((void *)0);
 }
 slq_free(slq);
 symbol_free(sum);
 symbol_free(mul);
}

variable_types: struct SOM_s { int mode; int bmu_row; struct SOMDesc_s { unsigned short dim; unsigned int train_iter; unsigned int rows; unsigned int cols; float (*radius_func)(struct SOM_s *s); } sd; int current_iter; float initial_radius; float half_life; struct Symbol_s { unsigned short dim; float vec[1]; } **neuron; float final_computation; float max_dist; float *qmap; } *

variable_types: thld double

variable_types: divisor double

variable_types: struct SLQueue_s { int finished; int count; int span; struct SLQline_s { int slid; int dim; int width; struct Symbol_s { unsigned short dim; float vec[1]; } **line; struct SLQline_s *next; } *tail; struct SLQline_s *head; } *

variable_types: i int

variable_types: slid int

variable_types: xrow int

variable_types: xcol int

variable_types: cr int

variable_types: cc int

variable_types: coef double


decompiled_code:
void __fastcall conv_apply_easy(__int64 a1, int a2, double a3, double a4)
{
void *v4; // rbp

v4 = (void *)conv_init(a2, a3);
conv_apply(a1, (__int64)v4, a4);
conv_free(v4);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2, double a3, double a4)
{
void *v4; // rbp

v4 = (void *)func0(a2, a3);
func6(a1, (__int64)v4, a4);
func1(v4);
}

original_code:
void conv_apply_easy(SOM *som, int style, double param, double thld)
{
 Conv *c;
 c = conv_init(style, param);
 conv_apply(som, c, thld);
 conv_free(c);
}

canonical_original_code:
void conv_apply_easy(struct SOM_s *som, int style, double param, double thld)
{
 struct Conv_s *c;
 c = conv_init(style, param);
 conv_apply(som, c, thld);
 conv_free(c);
}

variable_types: style int

user_defined_types: struct SOMDesc_s { unsigned short dim; unsigned int train_iter; unsigned int rows; unsigned int cols; float (*radius_func)(struct SOM_s *s); }


original_code:
TuringMachine* turing_machine_init(int iterations)
{
 int i;
 TuringMachine *tmach = ((void *)0);
 tmach = (TuringMachine*)xmalloc(sizeof(TuringMachine) * 1);
 tmach->perceptions = xmalloc(sizeof(Symbol*) * 6);
 tmach->perceptions[0] = symbol_init(2);
 symbol_set_2(tmach->perceptions[0], 0.0, 1.0);
 tmach->perceptions[1] = symbol_init(2);
 symbol_set_2(tmach->perceptions[1], 0.0, 0.0);
 tmach->perceptions[2] = symbol_init(2);
 symbol_set_2(tmach->perceptions[2], 0.0, 0.5);
 tmach->perceptions[3] = symbol_init(2);
 symbol_set_2(tmach->perceptions[3], 1.0, 0.0);
 tmach->perceptions[4] = symbol_init(2);
 symbol_set_2(tmach->perceptions[4], 1.0, 1.0);
 tmach->perceptions[5] = symbol_init(2);
 symbol_set_2(tmach->perceptions[5], 1.0, 0.5);
 tmach->actions = xmalloc(sizeof(Symbol*) * 6);
 tmach->actions[0] = symbol_init(3);
 symbol_set_3(tmach->actions[0], 0.0, 1.0, 0.0);
 tmach->actions[1] = symbol_init(3);
 symbol_set_3(tmach->actions[1], 0.0, 0.0, 0.0);
 tmach->actions[2] = symbol_init(3);
 symbol_set_3(tmach->actions[2], 1.0, 0.5, 1.0);
 tmach->actions[3] = symbol_init(3);
 symbol_set_3(tmach->actions[3], 0.0, 1.0, 0.0);
 tmach->actions[4] = symbol_init(3);
 symbol_set_3(tmach->actions[4], 1.0, 0.0, 1.0);
 tmach->actions[5] = symbol_init(3);
 symbol_set_3(tmach->actions[5], 0.0, 1.0, 0.0);
 tmach->perception = som_init(2, iterations, 128, 128, ((void *)0));
 tmach->action = som_init(3, iterations, 128, 128, ((void *)0));
 tmach->symdex = 0;
 tmach->state = 0;
 tmach->head = (70 / 2);
 for (i = 0; i < 70; i++) {
  tmach->tape[i] = 0.5;
 }
 tmach->step = 0;
 tmach->valid = TRUE;
 return tmach;
}

canonical_original_code:
struct TuringMachine_s *turing_machine_init(int iterations)
{
 int i;
 struct TuringMachine_s *tmach = ((void *)0);
 tmach = (struct TuringMachine_s *)xmalloc(sizeof(TuringMachine) * 1);
 tmach->perceptions = xmalloc(sizeof(struct Symbol_s *) * 6);
 tmach->perceptions[0] = symbol_init(2);
 symbol_set_2(tmach->perceptions[0], 0.0, 1.0);
 tmach->perceptions[1] = symbol_init(2);
 symbol_set_2(tmach->perceptions[1], 0.0, 0.0);
 tmach->perceptions[2] = symbol_init(2);
 symbol_set_2(tmach->perceptions[2], 0.0, 0.5);
 tmach->perceptions[3] = symbol_init(2);
 symbol_set_2(tmach->perceptions[3], 1.0, 0.0);
 tmach->perceptions[4] = symbol_init(2);
 symbol_set_2(tmach->perceptions[4], 1.0, 1.0);
 tmach->perceptions[5] = symbol_init(2);
 symbol_set_2(tmach->perceptions[5], 1.0, 0.5);
 tmach->actions = xmalloc(sizeof(struct Symbol_s *) * 6);
 tmach->actions[0] = symbol_init(3);
 symbol_set_3(tmach->actions[0], 0.0, 1.0, 0.0);
 tmach->actions[1] = symbol_init(3);
 symbol_set_3(tmach->actions[1], 0.0, 0.0, 0.0);
 tmach->actions[2] = symbol_init(3);
 symbol_set_3(tmach->actions[2], 1.0, 0.5, 1.0);
 tmach->actions[3] = symbol_init(3);
 symbol_set_3(tmach->actions[3], 0.0, 1.0, 0.0);
 tmach->actions[4] = symbol_init(3);
 symbol_set_3(tmach->actions[4], 1.0, 0.0, 1.0);
 tmach->actions[5] = symbol_init(3);
 symbol_set_3(tmach->actions[5], 0.0, 1.0, 0.0);
 tmach->perception = som_init(2, iterations, 128, 128, ((void *)0));
 tmach->action = som_init(3, iterations, 128, 128, ((void *)0));
 tmach->symdex = 0;
 tmach->state = 0;
 tmach->head = (70 / 2);
 for (i = 0; i < 70; i++) {
  tmach->tape[i] = 0.5;
 }
 tmach->step = 0;
 tmach->valid = TRUE;
 return tmach;
}

variable_types: iterations int

variable_types: struct TuringMachine_s { struct Symbol_s { unsigned short dim; float vec[1]; } **perceptions; struct Symbol_s **actions; int symdex; float state; int head; float tape[70]; struct SOM_s { int mode; int bmu_row; struct SOMDesc_s { unsigned short dim; unsigned int train_iter; unsigned int rows; unsigned int cols; float (*radius_func)(struct SOM_s *s); } sd; int current_iter; float initial_radius; float half_life; struct Symbol_s **neuron; float final_computation; float max_dist; float *qmap; } *perception; struct SOM_s *action; int step; int valid; } *

user_defined_types: struct TuringMachine_s { struct Symbol_s **perceptions; struct Symbol_s **actions; int symdex; float state; int head; float tape[70]; struct SOM_s *perception; struct SOM_s *action; int step; int valid; }


decompiled_code:
void __fastcall symbol_corrupt(__int64 a1, __m128i a2, __m128i a3)
{
float v3; // er14
float v4; // ebx
float v5; // xmm0_4
int i; // ebx
float v7; // xmm0_4
__int64 v8; // rsi
float v9; // xmm2_4
float v10[7]; // [rsp+10h] [rbp-1Ch] BYREF

v3 = COERCE_FLOAT(_mm_cvtsi128_si32(a3));
v4 = COERCE_FLOAT(_mm_cvtsi128_si32(a2));
v5 = drand48();
if ( v4 > v5 )
{
for ( i = 0; (unsigned __int16)symbol_get_dim(a1) > i; ++i )
{
v9 = drand48() * v3;
symbol_get_index(a1, v10, (unsigned int)i);
if ( drand48() < 0.5 )
v7 = v10[0] - (float)(v9 * v10[0]);
else
v7 = v9 * (1.0 - v10[0]) + v10[0];
v8 = (unsigned int)i;
v10[0] = v7;
symbol_set_index(a1, v8);
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __m128i a2, __m128i a3)
{
float v3; // er14
float v4; // ebx
float v5; // xmm0_4
int i; // ebx
float v7; // xmm0_4
__int64 v8; // rsi
float v9; // xmm2_4
float v10[7]; // [rsp+10h] [rbp-1Ch] BYREF

v3 = COERCE_FLOAT(_mm_cvtsi128_si32(a3));
v4 = COERCE_FLOAT(_mm_cvtsi128_si32(a2));
v5 = drand48();
if ( v4 > v5 )
{
for ( i = 0; (unsigned __int16)symbol_get_dim(a1) > i; ++i )
{
v9 = drand48() * v3;
symbol_get_index(a1, v10, (unsigned int)i);
if ( drand48() < 0.5 )
v7 = v10[0] - (float)(v9 * v10[0]);
else
v7 = v9 * (1.0 - v10[0]) + v10[0];
v8 = (unsigned int)i;
v10[0] = v7;
symbol_set_index(a1, v8);
}
}
}

original_code:
void symbol_corrupt(float per_chance, float per_range, Symbol *sym)
{
 int i;
 float rnd;
 float val;
 rnd = drand48();
 if (rnd < per_chance) {
  for (i = 0; i < symbol_get_dim(sym); i++) {
   rnd = drand48() * per_range;
   symbol_get_index(sym, &val, i);
   if (drand48() < .5) {
    val = val - val * rnd;
   } else {
    val = val + (1.0 - val) * rnd;
   }
   symbol_set_index(sym, val, i);
  }
 }
}

canonical_original_code:
void symbol_corrupt(float per_chance, float per_range, struct Symbol_s *sym)
{
 int i;
 float rnd;
 float val;
 rnd = drand48();
 if (rnd < per_chance) {
  for (i = 0; i < symbol_get_dim(sym); i++) {
   rnd = drand48() * per_range;
   symbol_get_index(sym, &val, i);
   if (drand48() < .5) {
    val = val - val * rnd;
   } else {
    val = val + (1.0 - val) * rnd;
   }
   symbol_set_index(sym, val, i);
  }
 }
}

variable_types: struct Symbol_s { unsigned short dim; float vec[1]; } *

variable_types: rnd float

variable_types: val float


decompiled_code:
__int64 __fastcall turing_machine_train(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rbp
unsigned int v3; // er13
char v5[4]; // [rsp+8h] [rbp-30h] BYREF
char v6[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = symbol_copy(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *(int *)(a1 + 16)));
v2 = symbol_copy(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * *(int *)(a1 + 16)));
symbol_corrupt(v1, (__m128i)(unsigned int)LC6, (__m128i)(unsigned int)LC5);
symbol_corrupt(v2, (__m128i)(unsigned int)LC6, (__m128i)(unsigned int)LC5);
som_learn(*(_QWORD *)(a1 + 312), v1, v5, v6, 0LL, 128LL, 0LL, 0LL);
v3 = som_learn(*(_QWORD *)(a1 + 320), v2, v5, v6, 128LL, 128LL, 0LL, 1LL);
*(_DWORD *)(a1 + 16) = (*(_DWORD *)(a1 + 16) + 1) % 6;
symbol_free(v1);
symbol_free(v2);
return v3;
}

original_code:
int turing_machine_train(TuringMachine *tmach)
{
 int state;
 int bmu_row, bmu_col;
 Symbol *corrupted_precept = symbol_copy(tmach->perceptions[tmach->symdex]);
 Symbol *corrupted_action = symbol_copy(tmach->actions[tmach->symdex]);
 symbol_corrupt(0.10, 0.2, corrupted_precept);
 symbol_corrupt(0.10, 0.2, corrupted_action);
 som_learn(tmach->perception, corrupted_precept,
  &bmu_row, &bmu_col, 0, 128, SOM_REQUEST_LEARN, FALSE);
 state = som_learn(tmach->action, corrupted_action,
  &bmu_row, &bmu_col, 128, 128, SOM_REQUEST_LEARN, TRUE);
 tmach->symdex++;
 tmach->symdex %= 6;
 symbol_free(corrupted_precept);
 symbol_free(corrupted_action);
 return state;
}

canonical_original_code:
int turing_machine_train(struct TuringMachine_s *tmach)
{
 int state;
 int bmu_row; int bmu_col;
 struct Symbol_s *corrupted_precept = symbol_copy(tmach->perceptions[tmach->symdex]);
 struct Symbol_s *corrupted_action = symbol_copy(tmach->actions[tmach->symdex]);
 symbol_corrupt(0.10, 0.2, corrupted_precept);
 symbol_corrupt(0.10, 0.2, corrupted_action);
 som_learn(tmach->perception, corrupted_precept,
  &bmu_row, &bmu_col, 0, 128, SOM_REQUEST_LEARN, FALSE);
 state = som_learn(tmach->action, corrupted_action,
  &bmu_row, &bmu_col, 128, 128, SOM_REQUEST_LEARN, TRUE);
 tmach->symdex++;
 tmach->symdex %= 6;
 symbol_free(corrupted_precept);
 symbol_free(corrupted_action);
 return state;
}

variable_types: state int


decompiled_code:
void __fastcall turing_machine_step(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // rdx
unsigned int v4; // [rsp+0h] [rbp-2Ch] BYREF
unsigned int v5; // [rsp+4h] [rbp-28h] BYREF
int v6; // [rsp+8h] [rbp-24h] BYREF
int v7; // [rsp+Ch] [rbp-20h] BYREF
float v8[7]; // [rsp+10h] [rbp-1Ch] BYREF

if ( *(_DWORD *)(a1 + 332) )
{
puts("Execute a step.");
v1 = symbol_init(2LL);
symbol_set_2(
v1,
COERCE_DOUBLE((unsigned __int64)*(_DWORD *)(a1 + 20)),
*(float *)(a1 + 4LL * *(int *)(a1 + 24) + 28));
printf("Precept: ");
symbol_stdout(v1);
som_learn(*(_QWORD *)(a1 + 312), v1, &v4, &v5, 0LL, 128LL, 1LL, 0LL);
v2 = som_symbol_ref(*(_QWORD *)(a1 + 320), v4, v5);
symbol_get_3(v2, &v6, &v7, v8);
printf("Action: ");
symbol_stdout(v2);
v3 = *(int *)(a1 + 24);
*(_DWORD *)(a1 + 20) = v6;
*(_DWORD *)(a1 + 4 * v3 + 28) = v7;
if ( v8[0] >= 0.5 )
{
*(_DWORD *)(a1 + 24) = v3 - 1;
if ( (int)v3 - 1 >= 0 )
goto LABEL_4;
}
else
{
*(_DWORD *)(a1 + 24) = v3 + 1;
if ( (_DWORD)v3 != 69 )
{
LABEL_4:
symbol_free(v1);
++*(_DWORD *)(a1 + 328);
return;
}
}
puts("Turing machine off tape boundary.");
*(_DWORD *)(a1 + 332) = 0;
goto LABEL_4;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // rdx
unsigned int v4; // [rsp+0h] [rbp-2Ch] BYREF
unsigned int v5; // [rsp+4h] [rbp-28h] BYREF
int v6; // [rsp+8h] [rbp-24h] BYREF
int v7; // [rsp+Ch] [rbp-20h] BYREF
float v8[7]; // [rsp+10h] [rbp-1Ch] BYREF

if ( *(_DWORD *)(a1 + 332) )
{
puts("Execute a step.");
v1 = symbol_init(2LL);
symbol_set_2(
v1,
COERCE_DOUBLE((unsigned __int64)*(_DWORD *)(a1 + 20)),
*(float *)(a1 + 4LL * *(int *)(a1 + 24) + 28));
printf("Precept: ");
symbol_stdout(v1);
som_learn(*(_QWORD *)(a1 + 312), v1, &v4, &v5, 0LL, 128LL, 1LL, 0LL);
v2 = som_symbol_ref(*(_QWORD *)(a1 + 320), v4, v5);
symbol_get_3(v2, &v6, &v7, v8);
printf("Action: ");
symbol_stdout(v2);
v3 = *(int *)(a1 + 24);
*(_DWORD *)(a1 + 20) = v6;
*(_DWORD *)(a1 + 4 * v3 + 28) = v7;
if ( v8[0] >= 0.5 )
{
*(_DWORD *)(a1 + 24) = v3 - 1;
if ( (int)v3 - 1 >= 0 )
goto LABEL_4;
}
else
{
*(_DWORD *)(a1 + 24) = v3 + 1;
if ( (_DWORD)v3 != 69 )
{
LABEL_4:
symbol_free(v1);
++*(_DWORD *)(a1 + 328);
return;
}
}
puts("Turing machine off tape boundary.");
*(_DWORD *)(a1 + 332) = 0;
goto LABEL_4;
}
}

original_code:
void turing_machine_step(TuringMachine *tmach)
{
 int bmu_row, bmu_col;
 Symbol *precept = ((void *)0);
 Symbol *act = ((void *)0);
 float new_state, write_value, head_move;
 if (tmach->valid == FALSE) {
  return;
 }
 printf("Execute a step.\n");
 precept = symbol_init(2);
 symbol_set_2(precept, tmach->state, tmach->tape[tmach->head]);
 printf("Precept: ");
 symbol_stdout(precept);
 som_learn(tmach->perception, precept,
  &bmu_row, &bmu_col, 0, 128, SOM_REQUEST_CLASSIFY, FALSE);
 act = som_symbol_ref(tmach->action, bmu_row, bmu_col);
 symbol_get_3(act, &new_state, &write_value, &head_move);
 printf("Action: ");
 symbol_stdout(act);
 tmach->state = new_state;
 tmach->tape[tmach->head] = write_value;
 if (head_move < .5) {
  tmach->head++;
  if (tmach->head == 70) {
   printf("Turing machine off tape boundary.\n");
   tmach->valid = FALSE;
  }
 } else {
  tmach->head--;
  if (tmach->head < 0) {
   printf("Turing machine off tape boundary.\n");
   tmach->valid = FALSE;
  }
 }
 symbol_free(precept);
 tmach->step++;
}

canonical_original_code:
void turing_machine_step(struct TuringMachine_s *tmach)
{
 int bmu_row; int bmu_col;
 struct Symbol_s *precept = ((void *)0);
 struct Symbol_s *act = ((void *)0);
 float new_state; float write_value; float head_move;
 if (tmach->valid == FALSE) {
  return;
 }
 printf("Execute a step.\n");
 precept = symbol_init(2);
 symbol_set_2(precept, tmach->state, tmach->tape[tmach->head]);
 printf("Precept: ");
 symbol_stdout(precept);
 som_learn(tmach->perception, precept,
  &bmu_row, &bmu_col, 0, 128, SOM_REQUEST_CLASSIFY, FALSE);
 act = som_symbol_ref(tmach->action, bmu_row, bmu_col);
 symbol_get_3(act, &new_state, &write_value, &head_move);
 printf("Action: ");
 symbol_stdout(act);
 tmach->state = new_state;
 tmach->tape[tmach->head] = write_value;
 if (head_move < .5) {
  tmach->head++;
  if (tmach->head == 70) {
   printf("Turing machine off tape boundary.\n");
   tmach->valid = FALSE;
  }
 } else {
  tmach->head--;
  if (tmach->head < 0) {
   printf("Turing machine off tape boundary.\n");
   tmach->valid = FALSE;
  }
 }
 symbol_free(precept);
 tmach->step++;
}


decompiled_code:
void __fastcall turing_machine_free(void *ptr)
{
__int64 i; // rbx
__int64 v3; // rdi

for ( i = 0LL; i != 48; i += 8LL )
{
symbol_free(*(_QWORD *)(*(_QWORD *)ptr + i));
v3 = *(_QWORD *)(*((_QWORD *)ptr + 1) + i);
symbol_free(v3);
}
free(*(void **)ptr);
free(*((void **)ptr + 1));
som_free(*((_QWORD *)ptr + 39));
som_free(*((_QWORD *)ptr + 40));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
__int64 i; // rbx
__int64 v3; // rdi

for ( i = 0LL; i != 48; i += 8LL )
{
symbol_free(*(_QWORD *)(*(_QWORD *)ptr + i));
v3 = *(_QWORD *)(*((_QWORD *)ptr + 1) + i);
symbol_free(v3);
}
free(*(void **)ptr);
free(*((void **)ptr + 1));
som_free(*((_QWORD *)ptr + 39));
som_free(*((_QWORD *)ptr + 40));
free(ptr);
}

original_code:
void turing_machine_free(TuringMachine *tmach)
{
 int i;
 for (i = 0; i < 6; i++) {
  symbol_free(tmach->perceptions[i]);
  symbol_free(tmach->actions[i]);
 }
 free(tmach->perceptions);
 free(tmach->actions);
 som_free(tmach->perception);
 som_free(tmach->action);
 free(tmach);
}

canonical_original_code:
void turing_machine_free(struct TuringMachine_s *tmach)
{
 int i;
 for (i = 0; i < 6; i++) {
  symbol_free(tmach->perceptions[i]);
  symbol_free(tmach->actions[i]);
 }
 free(tmach->perceptions);
 free(tmach->actions);
 som_free(tmach->perception);
 som_free(tmach->action);
 free(tmach);
}


original_code:
void turing_machine_stdout(TuringMachine *tmach)
{
 int i;
 printf("---] Step %d\n", tmach->step);
 printf("State: %f\n", tmach->state);
 for (i = 0; i < 70; i++) {
  if (tmach->tape[i] >= 0 && tmach->tape[i] < .25) {
   printf("0");
  }
  if (tmach->tape[i] >= .25 && tmach->tape[i] < .75) {
   printf(".");
  }
  if (tmach->tape[i] >= .75) {
   printf("1");
  }
 }
 printf("\n");
 for (i = 0; i < 70; i++) {
  if (i == tmach->head) {
   printf("^");
  } else {
   printf(" ");
  }
 }
 printf("\n");
}

canonical_original_code:
void turing_machine_stdout(struct TuringMachine_s *tmach)
{
 int i;
 printf("---] Step %d\n", tmach->step);
 printf("State: %f\n", tmach->state);
 for (i = 0; i < 70; i++) {
  if (tmach->tape[i] >= 0 && tmach->tape[i] < .25) {
   printf("0");
  }
  if (tmach->tape[i] >= .25 && tmach->tape[i] < .75) {
   printf(".");
  }
  if (tmach->tape[i] >= .75) {
   printf("1");
  }
 }
 printf("\n");
 for (i = 0; i < 70; i++) {
  if (i == tmach->head) {
   printf("^");
  } else {
   printf(" ");
  }
 }
 printf("\n");
}


decompiled_code:
void test_turing_machine()
{
unsigned int v0; // er13
int v1; // er12
__int64 v2; // r14
int v3; // ebp
int v4; // er15
int v5; // eax
int v6; // ebx
unsigned int v7; // eax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
unsigned int v11; // eax
const char *v12; // rax
unsigned int v13; // [rsp+Ch] [rbp-4Ch] BYREF
unsigned int v14; // [rsp+10h] [rbp-48h] BYREF
float v15; // [rsp+14h] [rbp-44h] BYREF
float v16; // [rsp+18h] [rbp-40h] BYREF
int v17[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v0 = 0;
v1 = 0;
v2 = turing_machine_init(0x186A0u);
v3 = SDL_GetTicks();
v4 = v3 - 1;
turing_machine_stdout(v2);
do
{
while ( 1 )
{
if ( v4 < v3 || v1 == 1 )
glClear(16640LL);
v5 = process_events(&v13, &v14);
v6 = v5;
if ( v5 == 2 )
{
v0 = 0;
LABEL_4:
v1 = turing_machine_train(v2);
break;
}
if ( v5 != 3 )
{
if ( v5 == 1 )
v0 = 1;
goto LABEL_4;
}
printf("Clicked: %d, %d\n", v14, v13);
v1 = turing_machine_train(v2);
v7 = v14;
if ( v14 <= 0x7F )
{
if ( v13 > 0x7F )
break;
printf("Perception symbol: ");
v8 = som_symbol_ref(*(_QWORD *)(v2 + 312), v13, v14);
symbol_get_2(v8, &v15, &v16);
printf("<state=%f, head=%f>\n", v15, v16);
printf(" Associated request: ");
v9 = som_symbol_ref(*(_QWORD *)(v2 + 320), v13, v14 + 128);
symbol_get_3(v9, &v15, &v16, v17);
printf("<state=%f, write=%f, move=%f>\n", v15, v16, *(float *)v17);
v7 = v14;
}
if ( v7 - 128 > 0x7F || v13 > 0x7F )
break;
printf("Action symbol: ");
v10 = som_symbol_ref(*(_QWORD *)(v2 + 320), v13, v14 - 128);
symbol_get_3(v10, &v15, &v16, v17);
printf("<state=%f, write=%f, move=%f>\n", v15, v16, *(float *)v17);
if ( v1 == 1 )
goto LABEL_18;
LABEL_6:
if ( v4 < v3 )
goto LABEL_21;
v3 = SDL_GetTicks();
if ( v6 == 4 )
goto LABEL_24;
}
if ( v1 != 1 )
goto LABEL_6;
LABEL_18:
turing_machine_step(v2);
if ( *(_DWORD *)(v2 + 332) == 1 )
turing_machine_stdout(v2);
usleep(0x1F4u);
LABEL_21:
som_draw(*(_QWORD *)(v2 + 312), v0, 0LL, 0LL);
som_draw(*(_QWORD *)(v2 + 320), v0, 128LL, 0LL);
v11 = glGetError();
if ( v11 )
{
v12 = (const char *)gluErrorString(v11);
printf("Opengl Error: %s\n", v12);
}
SDL_GL_SwapBuffers();
v4 = v3 + 1000;
v3 = SDL_GetTicks();
}
while ( v6 != 4 );
LABEL_24:
turing_machine_free((void *)v2);
}

canonical_decompiled_code:
void func6()
{
unsigned int v0; // er13
int v1; // er12
__int64 v2; // r14
int v3; // ebp
int v4; // er15
int v5; // eax
int v6; // ebx
unsigned int v7; // eax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
unsigned int v11; // eax
const char *v12; // rax
unsigned int v13; // [rsp+Ch] [rbp-4Ch] BYREF
unsigned int v14; // [rsp+10h] [rbp-48h] BYREF
float v15; // [rsp+14h] [rbp-44h] BYREF
float v16; // [rsp+18h] [rbp-40h] BYREF
int v17[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v0 = 0;
v1 = 0;
v2 = func0(0x186A0u);
v3 = SDL_GetTicks();
v4 = v3 - 1;
func5(v2);
do
{
while ( 1 )
{
if ( v4 < v3 || v1 == 1 )
glClear(16640LL);
v5 = process_events(&v13, &v14);
v6 = v5;
if ( v5 == 2 )
{
v0 = 0;
LABEL_4:
v1 = func2(v2);
break;
}
if ( v5 != 3 )
{
if ( v5 == 1 )
v0 = 1;
goto LABEL_4;
}
printf("Clicked: %d, %d\n", v14, v13);
v1 = func2(v2);
v7 = v14;
if ( v14 <= 0x7F )
{
if ( v13 > 0x7F )
break;
printf("Perception symbol: ");
v8 = som_symbol_ref(*(_QWORD *)(v2 + 312), v13, v14);
symbol_get_2(v8, &v15, &v16);
printf("<state=%f, head=%f>\n", v15, v16);
printf(" Associated request: ");
v9 = som_symbol_ref(*(_QWORD *)(v2 + 320), v13, v14 + 128);
symbol_get_3(v9, &v15, &v16, v17);
printf("<state=%f, write=%f, move=%f>\n", v15, v16, *(float *)v17);
v7 = v14;
}
if ( v7 - 128 > 0x7F || v13 > 0x7F )
break;
printf("Action symbol: ");
v10 = som_symbol_ref(*(_QWORD *)(v2 + 320), v13, v14 - 128);
symbol_get_3(v10, &v15, &v16, v17);
printf("<state=%f, write=%f, move=%f>\n", v15, v16, *(float *)v17);
if ( v1 == 1 )
goto LABEL_18;
LABEL_6:
if ( v4 < v3 )
goto LABEL_21;
v3 = SDL_GetTicks();
if ( v6 == 4 )
goto LABEL_24;
}
if ( v1 != 1 )
goto LABEL_6;
LABEL_18:
func3(v2);
if ( *(_DWORD *)(v2 + 332) == 1 )
func5(v2);
usleep(0x1F4u);
LABEL_21:
som_draw(*(_QWORD *)(v2 + 312), v0, 0LL, 0LL);
som_draw(*(_QWORD *)(v2 + 320), v0, 128LL, 0LL);
v11 = glGetError();
if ( v11 )
{
v12 = (const char *)gluErrorString(v11);
printf("Opengl Error: %s\n", v12);
}
SDL_GL_SwapBuffers();
v4 = v3 + 1000;
v3 = SDL_GetTicks();
}
while ( v6 != 4 );
LABEL_24:
func4((void *)v2);
}

original_code:
void test_turing_machine(void)
{
 int state = STATE_RUNNING;
 int tmach_state = SOM_LEARNING;
 int drawing_mode = SOM_STYLE_ACTUAL;
 int sample, now, incr = 1000;
 int mr, mc;
 int iter;
 int glerr;
 TuringMachine *tmach = turing_machine_init(100000);
 Symbol *lookup = ((void *)0);
 float val0, val1, val2;
 now = SDL_GetTicks();
 sample = now - 1;
 iter = 0;
 turing_machine_stdout(tmach);
 while(state != STATE_EXIT)
 {
  if (now > sample || tmach_state == SOM_CLASSIFYING)
  {
   glClear(0x00004000 | 0x00000100);
  }
  state = process_events(&mr, &mc);
  switch (state)
  {
   case STATE_MOUSE_DOWN:
    printf("Clicked: %d, %d\n", mc, mr);
    break;
   case STATE_QUALITY:
    drawing_mode = SOM_STYLE_QUALITY;
    break;
   case STATE_ACTUAL:
    drawing_mode = SOM_STYLE_ACTUAL;
    break;
   default:
    ;
  }
  tmach_state = turing_machine_train(tmach);
  if (state == STATE_MOUSE_DOWN) {
   if (mc >= 0 && mc < 128 && mr >= 0 && mr < 128) {
    printf("Perception symbol: ");
    lookup = som_symbol_ref(tmach->perception, mr, mc);
    symbol_get_2(lookup, &val0, &val1);
    printf("<state=%f, head=%f>\n", val0, val1);
    printf("  Associated request: ");
    lookup = som_symbol_ref(tmach->action, mr, mc + 128);
    symbol_get_3(lookup, &val0, &val1, &val2);
    printf("<state=%f, write=%f, move=%f>\n", val0, val1, val2);
   }
   if (mc >= 128 && mc < 256 && mr >= 0 && mr < 128) {
    printf("Action symbol: ");
    lookup = som_symbol_ref(tmach->action, mr, mc - 128);
    symbol_get_3(lookup, &val0, &val1, &val2);
    printf("<state=%f, write=%f, move=%f>\n", val0, val1, val2);
   }
  }
  if (tmach_state == SOM_CLASSIFYING) {
   turing_machine_step(tmach);
   if (tmach->valid == TRUE) {
    turing_machine_stdout(tmach);
   }
   usleep(500);
  }
  if (now > sample || tmach_state == SOM_CLASSIFYING)
  {
   som_draw(tmach->perception, drawing_mode, 0, 0);
   som_draw(tmach->action, drawing_mode, 128, 0);
   glerr = glGetError();
   if (glerr != 0) {
    printf("Opengl Error: %s\n", gluErrorString(glerr));
   }
   SDL_GL_SwapBuffers();
   sample = now + incr;
   iter = 0;
  }
  now = SDL_GetTicks();
  iter++;
 }
 turing_machine_free(tmach);
}

canonical_original_code:
void test_turing_machine()
{
 int state = STATE_RUNNING;
 int tmach_state = SOM_LEARNING;
 int drawing_mode = SOM_STYLE_ACTUAL;
 int sample; int now; int incr = 1000;
 int mr; int mc;
 int iter;
 int glerr;
 struct TuringMachine_s *tmach = turing_machine_init(100000);
 struct Symbol_s *lookup = ((void *)0);
 float val0; float val1; float val2;
 now = SDL_GetTicks();
 sample = now - 1;
 iter = 0;
 turing_machine_stdout(tmach);
 while(state != STATE_EXIT)
 {
  if (now > sample || tmach_state == SOM_CLASSIFYING)
  {
   glClear(0x00004000 | 0x00000100);
  }
  state = process_events(&mr, &mc);
  switch (state)
  {
   case STATE_MOUSE_DOWN:
    printf("Clicked: %d, %d\n", mc, mr);
    break;
   case STATE_QUALITY:
    drawing_mode = SOM_STYLE_QUALITY;
    break;
   case STATE_ACTUAL:
    drawing_mode = SOM_STYLE_ACTUAL;
    break;
   default:
    ;
  }
  tmach_state = turing_machine_train(tmach);
  if (state == STATE_MOUSE_DOWN) {
   if (mc >= 0 && mc < 128 && mr >= 0 && mr < 128) {
    printf("Perception symbol: ");
    lookup = som_symbol_ref(tmach->perception, mr, mc);
    symbol_get_2(lookup, &val0, &val1);
    printf("<state=%f, head=%f>\n", val0, val1);
    printf("  Associated request: ");
    lookup = som_symbol_ref(tmach->action, mr, mc + 128);
    symbol_get_3(lookup, &val0, &val1, &val2);
    printf("<state=%f, write=%f, move=%f>\n", val0, val1, val2);
   }
   if (mc >= 128 && mc < 256 && mr >= 0 && mr < 128) {
    printf("Action symbol: ");
    lookup = som_symbol_ref(tmach->action, mr, mc - 128);
    symbol_get_3(lookup, &val0, &val1, &val2);
    printf("<state=%f, write=%f, move=%f>\n", val0, val1, val2);
   }
  }
  if (tmach_state == SOM_CLASSIFYING) {
   turing_machine_step(tmach);
   if (tmach->valid == TRUE) {
    turing_machine_stdout(tmach);
   }
   usleep(500);
  }
  if (now > sample || tmach_state == SOM_CLASSIFYING)
  {
   som_draw(tmach->perception, drawing_mode, 0, 0);
   som_draw(tmach->action, drawing_mode, 128, 0);
   glerr = glGetError();
   if (glerr != 0) {
    printf("Opengl Error: %s\n", gluErrorString(glerr));
   }
   SDL_GL_SwapBuffers();
   sample = now + incr;
   iter = 0;
  }
  now = SDL_GetTicks();
  iter++;
 }
 turing_machine_free(tmach);
}

variable_types: sample int

variable_types: now int

variable_types: incr int

variable_types: mr int

variable_types: mc int

variable_types: iter int

variable_types: glerr int


pochisq

variable_types: ax double

variable_types: df int

variable_types: x double

variable_types: a double

variable_types: y double

variable_types: s double

variable_types: e double

variable_types: c double

variable_types: z double

variable_types: even int


decompiled_code:
double __fastcall rt_log2(double a1)
{
return log10(a1) * 3.321928094887362;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
return log10(a1) * 3.321928094887362;
}

original_code:
static double rt_log2(double x)
{
    return 3.32192809488736234787 * log10(x);
}